def decompile(cls, ea):
'''(UNSTABLE) Returns the decompiled code of the basic-block at the address ``ea``.'''
source = idaapi.decompile(ea)
res = map(functools.partial(operator.__getitem__, source.eamap), cls.iterate(ea))
res = itertools.chain(*res)
formatted = reduce(lambda t,c: t if t[-1].ea == c.ea else t+[c], res, [next(res)])
res = []
# FIXME: pretty damn unstable
try:
for fmt in formatted:
res.append( fmt.print1(source.__deref__()) )
except TypeError: pass
return '\n'.join(map(idaapi.tag_remove,res))
# function frame attributes
# FIXME: put these in their own object and replace them with aliases
python类__getitem__()的实例源码
def decompile(cls, ea):
'''(UNSTABLE) Returns the decompiled code of the basic-block at the address ``ea``.'''
source = idaapi.decompile(ea)
res = map(functools.partial(operator.__getitem__, source.eamap), cls.iterate(ea))
res = itertools.chain(*res)
formatted = reduce(lambda t,c: t if t[-1].ea == c.ea else t+[c], res, [next(res)])
res = []
# FIXME: This is pretty damn unstable in my tests.
try:
for fmt in formatted:
res.append( fmt.print1(source.__deref__()) )
except TypeError: pass
return '\n'.join(map(idaapi.tag_remove,res))
# function frame attributes
# FIXME: put these in their own object and replace them with aliases
def decompile(cls, ea):
'''(UNSTABLE) Returns the decompiled code of the basic-block at the address ``ea``.'''
source = idaapi.decompile(ea)
res = map(functools.partial(operator.__getitem__, source.eamap), cls.iterate(ea))
res = itertools.chain(*res)
formatted = reduce(lambda t,c: t if t[-1].ea == c.ea else t+[c], res, [next(res)])
res = []
# FIXME: pretty damn unstable
try:
for fmt in formatted:
res.append( fmt.print1(source.__deref__()) )
except TypeError: pass
return '\n'.join(map(idaapi.tag_remove,res))
# function frame attributes
# FIXME: put these in their own object and replace them with aliases
def decompile(cls, ea):
'''(UNSTABLE) Returns the decompiled code of the basic-block at the address ``ea``.'''
source = idaapi.decompile(ea)
res = map(functools.partial(operator.__getitem__, source.eamap), cls.iterate(ea))
res = itertools.chain(*res)
formatted = reduce(lambda t,c: t if t[-1].ea == c.ea else t+[c], res, [next(res)])
res = []
# FIXME: pretty damn unstable
try:
for fmt in formatted:
res.append( fmt.print1(source.__deref__()) )
except TypeError: pass
return '\n'.join(map(idaapi.tag_remove,res))
# function frame attributes
# FIXME: put these in their own object and replace them with aliases
def decompile(cls, ea):
'''(UNSTABLE) Returns the decompiled code of the basic-block at the address ``ea``.'''
source = idaapi.decompile(ea)
res = map(functools.partial(operator.__getitem__, source.eamap), cls.iterate(ea))
res = itertools.chain(*res)
formatted = reduce(lambda t,c: t if t[-1].ea == c.ea else t+[c], res, [next(res)])
res = []
# FIXME: This is pretty damn unstable in my tests.
try:
for fmt in formatted:
res.append( fmt.print1(source.__deref__()) )
except TypeError: pass
return '\n'.join(map(idaapi.tag_remove,res))
# function frame attributes
# FIXME: put these in their own object and replace them with aliases
def decompile(cls, ea):
'''(UNSTABLE) Returns the decompiled code of the basic-block at the address ``ea``.'''
source = idaapi.decompile(ea)
res = map(functools.partial(operator.__getitem__, source.eamap), cls.iterate(ea))
res = itertools.chain(*res)
formatted = reduce(lambda t,c: t if t[-1].ea == c.ea else t+[c], res, [next(res)])
res = []
# FIXME: pretty damn unstable
try:
for fmt in formatted:
res.append( fmt.print1(source.__deref__()) )
except TypeError: pass
return '\n'.join(map(idaapi.tag_remove,res))
# function frame attributes
# FIXME: put these in their own object and replace them with aliases
def testIReadMapping(self, inst, state, absent):
for key in state:
self.assertEqual(inst[key], state[key])
self.assertEqual(inst.get(key, None), state[key])
self.failUnless(key in inst)
for key in absent:
self.assertEqual(inst.get(key, None), None)
self.assertEqual(inst.get(key), None)
self.assertEqual(inst.get(key, self), self)
self.assertRaises(KeyError, __getitem__, inst, key)
def testIReadMapping(self, inst, state, absent):
for key in state:
self.assertEqual(inst[key], state[key])
self.assertEqual(inst.get(key, None), state[key])
self.failUnless(key in inst)
for key in absent:
self.assertEqual(inst.get(key, None), None)
self.assertEqual(inst.get(key), None)
self.assertEqual(inst.get(key, self), self)
self.assertRaises(KeyError, __getitem__, inst, key)
def testIReadMapping(self, inst, state, absent):
for key in state:
self.assertEqual(inst[key], state[key])
self.assertEqual(inst.get(key, None), state[key])
self.assertTrue(key in inst)
for key in absent:
self.assertEqual(inst.get(key, None), None)
self.assertEqual(inst.get(key), None)
self.assertEqual(inst.get(key, self), self)
self.assertRaises(KeyError, __getitem__, inst, key)
def _calculate_(self, offset):
res = self.new(self._object_).a
res = reduce(operator.__getitem__, self._path_, res)
return offset - res.getoffset()
def next(self):
'''Follow the next pointer to the next header entry.'''
if self['next'].int():
return reduce(operator.__getitem__, self._path_, self['next'].d.l)
raise ValueError("{:s} : Unable to navigate to next pointer : 0x{:x}".format(self['next'].int()))
def previous(self):
'''Follow the previous pointer to the previous header entry.'''
if self['previous'].int():
return reduce(operator.__getitem__, self._path_, self['previous'].d.l)
raise ValueError("{:s} : Unable to navigate to previous pointer : 0x{:x}".format(self['previous'].int()))
def _walk(self, direction):
'''Yield all the elements in the specified direction.'''
yield self
res = direction(self)
while res.int():
res = res.d
res = reduce(operator.__getitem__, self._path_, res.l)
yield res
res = direction(res)
return
# FIXME: make sure that these return each and every header
def summary(self):
mapper = ['.', 'X']
return str().join(map(mapper.__getitem__, self.iterate()))
def testIReadMapping(self, inst, state, absent):
for key in state:
self.assertEqual(inst[key], state[key])
self.assertEqual(inst.get(key, None), state[key])
self.assertTrue(key in inst)
for key in absent:
self.assertEqual(inst.get(key, None), None)
self.assertEqual(inst.get(key), None)
self.assertEqual(inst.get(key, self), self)
self.assertRaises(KeyError, __getitem__, inst, key)
def fromStr(cls, string):
'''Convert string representation of SynchDomain enum e.g.
'SynchDomain.Time' to SynchDomain objects. It also works with just
domain strings like 'Time'. The following expressions are True:
SynchDomain.fromStr(str(SynchDomain.Time)) == SynchDomain.Time
SynchDomain.fromStr('Time') == SynchDomain.Time
'''
domain = string.split('.')
if len(domain) == 1:
return __getitem__(cls, domain[0])
elif len(domain) == 2:
return __getitem__(cls, domain[1])
else:
raise ValueError('Can not convert %s to SynchDomain' % string)