mirror of
https://github.com/capstone-engine/capstone.git
synced 2024-11-27 15:30:33 +00:00
python: cs_disasm*() now use generator rather than a list to return disassembled instructions. suggested by Mario Vilas.
This commit is contained in:
parent
19b0de3c8d
commit
ef709f0272
@ -242,15 +242,15 @@ def cs_disasm_quick(arch, mode, code, offset, count = 0):
|
||||
if status != CS_ERR_OK:
|
||||
raise CsError(status)
|
||||
|
||||
insns = []
|
||||
all_insn = ctypes.POINTER(_cs_insn)()
|
||||
res = _cs.cs_disasm_ex(csh, code, len(code), offset, count, ctypes.byref(all_insn))
|
||||
if res > 0:
|
||||
for i in xrange(res):
|
||||
insns.append(CsInsn(_dummy_cs(csh, arch), all_insn[i]))
|
||||
yield CsInsn(_dummy_cs(csh, arch), all_insn[i])
|
||||
|
||||
_cs.cs_free(all_insn, res)
|
||||
else:
|
||||
yield []
|
||||
status = _cs.cs_errno(csh)
|
||||
if status != CS_ERR_OK:
|
||||
raise CsError(status)
|
||||
@ -259,7 +259,6 @@ def cs_disasm_quick(arch, mode, code, offset, count = 0):
|
||||
if status != CS_ERR_OK:
|
||||
raise CsError(status)
|
||||
|
||||
return insns
|
||||
|
||||
# Python-style class to disasm code
|
||||
class CsInsn(object):
|
||||
@ -400,17 +399,15 @@ class Cs(object):
|
||||
self._mode = opt
|
||||
|
||||
def disasm(self, code, offset, count = 0):
|
||||
insns = []
|
||||
all_insn = ctypes.POINTER(_cs_insn)()
|
||||
res = _cs.cs_disasm_ex(self.csh, code, len(code), offset, count, ctypes.byref(all_insn))
|
||||
if res > 0:
|
||||
for i in xrange(res):
|
||||
insns.append(CsInsn(self, all_insn[i]))
|
||||
yield CsInsn(self, all_insn[i])
|
||||
_cs.cs_free(all_insn, res)
|
||||
else:
|
||||
yield []
|
||||
status = _cs.cs_errno(self.csh)
|
||||
if status != CS_ERR_OK:
|
||||
raise CsError(status)
|
||||
|
||||
return insns
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user