Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions bindings/python/capstone.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
break
except OSError:
pass
if _found == False:
if not _found:
# try loading from default paths
for _lib in _all_libs:
try:
Expand All @@ -69,7 +69,7 @@
except OSError:
pass

if _found == False:
if not _found:
# last try: loading from python lib directory
_lib_path = distutils.sysconfig.get_python_lib()
for _lib in _all_libs:
Expand All @@ -81,7 +81,7 @@
break
except OSError:
pass
if _found == False:
if not _found:
raise ImportError("ERROR: fail to load the dynamic library.")


Expand Down Expand Up @@ -144,7 +144,7 @@ def cs_disasm_quick(arch, mode, code, offset, count = 0):


# Python-style class to disasm code
class cs_insn:
class cs_insn(object):
def __init__(self, csh, all_info, arch):
def create_list(rawlist):
fl = []
Expand All @@ -159,7 +159,7 @@ def create_list(rawlist):
self.size = all_info.size
self.mnemonic = all_info.mnemonic
self.operands = all_info.operands
self.regs_read = create_list(all_info.regs_read)
self.regs_read = create_list(all_info.regs_read) # [reg for reg in all_info.regs_read if reg != 0] XXX ?
self.regs_write = create_list(all_info.regs_write)
self.groups = create_list(all_info.groups)

Expand Down Expand Up @@ -203,6 +203,7 @@ def reg_write(self, reg_id):
raise ValueError("Error: Failed to initialize!")
return _cs.cs_reg_write(self.csh, self.raw_insn, reg_id)

# pythonic would be: len(insn.operands)
def op_count(self, op_type):
if self.csh is None:
raise ValueError("Error: Failed to initialize!")
Expand All @@ -214,7 +215,7 @@ def op_index(self, op_type, position):
return _cs.cs_op_index(self.csh, self.raw_insn, op_type, position)


class cs:
class cs(object):
def __init__(self, arch, mode):
self.arch, self.mode = arch, mode
self.csh = ctypes.c_uint64()
Expand All @@ -223,6 +224,7 @@ def __init__(self, arch, mode):
raise ValueError("Error: Wrong arch or mode")
self.csh = None

# this might be a massive memory leak in Python, if '
def __del__(self):
if self.csh:
_cs.cs_close(self.csh)
Expand Down