import
math
import
idaapi
import
idc
try
:
class
Kp_Menu_Context(idaapi.action_handler_t):
def
__init__(
self
):
idaapi.action_handler_t.__init__(
self
)
@
classmethod
def
get_name(
self
):
return
self
.__name__
@
classmethod
def
get_label(
self
):
return
self
.label
@
classmethod
def
register(
self
, plugin, label):
self
.plugin
=
plugin
self
.label
=
label
instance
=
self
()
return
idaapi.register_action(idaapi.action_desc_t(
self
.get_name(),
instance.get_label(),
instance
))
@
classmethod
def
unregister(
self
):
idaapi.unregister_action(
self
.get_name())
@
classmethod
def
activate(
self
, ctx):
return
1
@
classmethod
def
update(
self
, ctx):
if
ctx.form_type
=
=
idaapi.BWN_DISASM:
return
idaapi.AST_ENABLE_FOR_FORM
return
idaapi.AST_DISABLE_FOR_FORM
class
Searcher(Kp_Menu_Context):
def
activate(
self
, ctx):
self
.plugin.search()
return
1
except
:
pass
class
GetOffsetInfo_Plugin_t(idaapi.plugin_t):
comment
=
"GetOffset By IBinary"
help
=
"todo"
wanted_name
=
"GetOffset"
wanted_hotkey
=
"ALT+/"
flags
=
idaapi.PLUGIN_KEEP
def
init(
self
):
try
:
print
(
"GetOffset By IBinary"
)
Searcher.register(
self
,
"GetOffset"
)
except
:
pass
return
idaapi.PLUGIN_KEEP
def
term(
self
):
pass
def
printAvd(slef):
print
(
100
*
"-"
)
def
formatByte(
self
,ea):
return
" "
+
"{:02X}"
.
format
(idc.get_wide_byte(ea))
def
calcStr(
self
,ea, endcount):
hstr
=
""
firstByte
=
self
.formatByte(ea)
hstr
+
=
self
.formatByte(ea)
hstr
=
hstr
+
self
.formatByte(ea
+
1
)
if
(firstByte
=
=
"FF"
or
firstByte
=
=
"66"
or
firstByte
=
=
"67"
)
else
hstr
hstr
=
hstr
+
math.ceil(endcount
-
len
(hstr)
/
2
)
*
" ??"
if
endcount >
=
2
else
hstr
return
hstr
def
extractCode(
self
):
self
.printAvd()
result
=
""
szIdbName
=
idc.get_idb_path();
szIdbName
=
szIdbName[szIdbName.rfind(
"\\"
)
+
1
:
-
4
];
base
=
idaapi.get_imagebase();
here
=
idc.here();
offset
=
here
-
base;
functionName
=
idc.get_func_name(here);
print
(
"functionName %s Address:0x%x Offset:0x%x ImageBase:0x%x "
%
(functionName,here, offset,base))
print
(
"Rva = %s+0x%x x64dbgCtrl+G = %s.0+0x%x "
%
(szIdbName,offset,szIdbName,offset))
self
.printAvd()
return
result
def
run(
self
, arg):
if
(idc.BADADDR !
=
idc.here()):
copyContent
=
self
.extractCode();
print
(copyContent)
def
PLUGIN_ENTRY():
return
GetOffsetInfo_Plugin_t();