From ef709f027272bba139e882fdebc8f00c4a23bab6 Mon Sep 17 00:00:00 2001 From: Nguyen Anh Quynh Date: Tue, 31 Dec 2013 22:55:27 +0800 Subject: [PATCH] python: cs_disasm*() now use generator rather than a list to return disassembled instructions. suggested by Mario Vilas. --- bindings/python/capstone/capstone.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/bindings/python/capstone/capstone.py b/bindings/python/capstone/capstone.py index 5add33b8c..9a0492d6f 100644 --- a/bindings/python/capstone/capstone.py +++ b/bindings/python/capstone/capstone.py @@ -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 -