Python源码示例:idaapi.netnode()
示例1
def on_open():
global auto_wait
global fhash
print('revsync: file opened:', idaapi.get_root_filename())
netnode.create(NETNODE_NAME)
try: fhash = netnode.getblob(0, 'I').decode('ascii')
except: fhash = None
if not fhash:
fhash = read_fhash()
try: ret = netnode.setblob(fhash.encode('ascii'), 0, 'I')
except: print('saving fhash failed, this will probably break revsync')
if auto_is_ok():
on_load()
auto_wait = False
else:
auto_wait = True
print('revsync: waiting for auto analysis')
if not hasattr(IDP_Hooks, 'auto_empty_finally'):
idaapi.register_timer(1000, wait_for_analysis)
示例2
def repr(cls, nodeidx):
res = []
try:
l1 = max(len(key or '') for key in cls.fiter(nodeidx))
l2 = max(len("{!r}".format(cls.get(nodeidx, key))) for key in cls.fiter(nodeidx))
except ValueError:
l1, l2 = 0, 2
for i, key in enumerate(cls.fiter(nodeidx)):
value = "{:<{:d}s} : str={!r}, buffer={!r}, int={:#x}({:d})".format("{!r}".format(cls.get(nodeidx, key)), l2, cls.get(nodeidx, key, str), cls.get(nodeidx, key, buffer), cls.get(nodeidx, key, int), cls.get(nodeidx, key, int))
res.append("[{:d}] {:<{:d}s} -> {:s}".format(i, key, l1, value))
if not res:
raise internal.exceptions.MissingTypeOrAttribute(u"{:s}.repr({:#x}) : The specified node ({:x}) does not have any hashvals.".format('.'.join(('internal', __name__, cls.__name__)), nodeidx, nodeidx))
return '\n'.join(res)
# FIXME: implement a file-allocation-table based filesystem using the netnode wrappers defined above
示例3
def __init__(self):
self.__penode = idaapi.netnode()
self.__penode.create(peutils_t.PE_NODE)
示例4
def __init__(self, netnode_name=OUR_NETNODE):
self._netnode_name = netnode_name
# self._n = idaapi.netnode(netnode_name, namelen=0, do_create=True)
self._n = idaapi.netnode(netnode_name, 0, True)
示例5
def kill(self):
self._n.kill()
self._n = idaapi.netnode(self._netnode_name, 0, True)
示例6
def _paint_instructions(self, instructions):
"""
Paint instruction level coverage defined by the current database mapping.
NOTE: we now use 'streaming' mode for instructions rather than this.
"""
color = struct.pack("I", self.palette.coverage_paint+1)
for address in instructions:
set_abits(address, 0x40000)
nn = netnode(address)
nn.supset(20, color, 'A')
self._painted_instructions |= set(instructions)
self._action_complete.set()
示例7
def cached_fhash():
return netnode.getblob(0, 'I').decode('ascii')
示例8
def publish(data, **kwargs):
if not auto_is_ok():
return
if fhash == netnode.getblob(0, 'I').decode('ascii'):
client.publish(fhash, data, **kwargs)
### IDA Hook Classes ###
示例9
def range(cls):
this = netnode.new()
ok, start = netnode.start(this), netnode.index(this)
if not ok: raise internal.exceptions.NetNodeNotFoundError(u"{:s}.range() : Unable to find first node.".format('.'.join(('internal', __name__, cls.__name__))))
ok, end = netnode.end(this), netnode.index(this)
if not ok: raise internal.exceptions.NetNodeNotFoundError(u"{:s}.range() : Unable to find end node.".format('.'.join(('internal', __name__, cls.__name__))))
return start, end
示例10
def renumerate(cls):
start, end = cls.range()
this = netnode.new()
ok = netnode.end(this)
if not ok:
raise internal.exceptions.NetNodeNotFoundError(u"{:s}.renumerate() : Unable to find the end node.".format('.'.join(('internal', __name__, cls.__name__))))
yield end, netnode.new(end)
while end != start:
ok = netnode.prev(this)
if not ok: break
end = netnode.index(this)
yield end, netnode.new(end)
return
示例11
def fenumerate(cls):
start, end = cls.range()
this = netnode.new()
ok = netnode.start(this)
if not ok:
raise internal.exceptions.NetNodeNotFoundError(u"{:s}.fenumerate() : Unable to find the start node.".format('.'.join(('internal', __name__, cls.__name__))))
yield start, netnode.new(start)
while start != end:
ok = netnode.next(this)
if not ok: break
start = netnode.index(this)
yield start, netnode.new(start)
return
示例12
def falt(cls, node):
for res in cls.valfiter(node, netnode.altfirst, netnode.altlast, netnode.altnext, netnode.altval):
yield res
return
示例13
def ralt(cls, node):
for res in cls.valriter(node, netnode.altfirst, netnode.altprev, netnode.altnext, netnode.altval):
yield res
return
示例14
def rsup(cls, node):
for res in cls.valriter(node, netnode.supfirst, netnode.supprev, netnode.supnext, netnode.supval):
yield res
return
示例15
def fhash(cls, node):
for res in cls.hfiter(node, netnode.hashfirst, netnode.hashlast, netnode.hashnext, netnode.hashval):
yield res
return
示例16
def rhash(cls, node):
for res in cls.hriter(node, netnode.hashfirst, netnode.hashprev, netnode.hashnext, netnode.hashval):
yield res
return
示例17
def fchar(cls, node):
for res in cls.valfiter(node, netnode.charfirst, netnode.charlast, netnode.charnext, netnode.charval):
yield res
return
示例18
def rchar(cls, node):
for res in cls.valriter(node, netnode.charfirst, netnode.charprev, netnode.charnext, netnode.charval):
yield res
return
示例19
def get(name):
if isinstance(name, six.integer_types):
node = netnode.new(name)
return netnode.index(node)
res = internal.utils.string.to(name)
node = netnode.new(res, len(res), False)
return netnode.index(node)
示例20
def remove(nodeidx):
node = netnode.new(nodeidx)
return netnode.kill(node)
### node name
示例21
def get(cls, nodeidx):
node = netnode.new(nodeidx)
res = netnode.name(node)
return internal.utils.string.of(res)
示例22
def set(cls, nodeidx, string):
node = netnode.new(nodeidx)
res = internal.utils.string.to(string)
return netnode.rename(node, res)
### node value (?)
示例23
def exists(cls, nodeidx):
node = netnode.new(nodeidx)
return netnode.value_exists(node)
示例24
def set(cls, nodeidx, value):
node = netnode.new(nodeidx)
if isinstance(value, bytes):
return netnode.set(node, value)
elif isinstance(value, six.integer_types):
return netnode.set_long(node, value)
raise internal.exceptions.InvalidTypeOrValueError(u"{:s}.set({:#x}, {!r}) : An unsupported type ({!r}) was specified for the netnode's value.".format('.'.join(('internal', __name__, cls.__name__)), nodeidx, value, value.__class__))
示例25
def remove(cls, nodeidx, value):
node = netnode.new(nodeidx)
return netnode.delvalue(node)
示例26
def get(cls, nodeidx, tag, start=0):
node = netnode.new(nodeidx)
sz = netnode.blobsize(node, start, tag)
res = netnode.getblob(node, start, tag)
return None if res is None else res[:sz]
示例27
def set(cls, nodeidx, tag, value, start=0):
node = netnode.new(nodeidx)
return netnode.setblob(node, value, start, tag)
示例28
def remove(cls, nodeidx, tag, start=0):
node = netnode.new(nodeidx)
return netnode.delblob(node, start, tag)
示例29
def get(cls, nodeidx, idx):
node = netnode.new(nodeidx)
return netnode.altval(node, idx)
示例30
def set(cls, nodeidx, idx, value):
node = netnode.new(nodeidx)
return netnode.altset(node, idx, value)