Skip to content
Merged
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
16 changes: 8 additions & 8 deletions bindings/python/capstone/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,11 +1053,11 @@ def disasm(self, code, offset, count=0):
print(code)
code = code.encode()
print(code)'''
# Hi, Hacker! Unicorn's memory accessors give you back bytearrays, but they
# cause TypeErrors when you hand them into Capstone.
# Pass a bytearray by reference
size = len(code)
if isinstance(code, bytearray):
code = bytes(code)
res = _cs.cs_disasm(self.csh, code, len(code), offset, count, ctypes.byref(all_insn))
code = ctypes.byref(ctypes.c_char.from_buffer(code))
res = _cs.cs_disasm(self.csh, code, size, offset, count, ctypes.byref(all_insn))
if res > 0:
try:
for i in range(res):
Expand All @@ -1081,11 +1081,11 @@ def disasm_lite(self, code, offset, count=0):
raise CsError(CS_ERR_DIET)

all_insn = ctypes.POINTER(_cs_insn)()
# Hi, Hacker! Unicorn's memory accessors give you back bytearrays, but they
# cause TypeErrors when you hand them into Capstone.
size = len(code)
# Pass a bytearray by reference
if isinstance(code, bytearray):
code = bytes(code)
res = _cs.cs_disasm(self.csh, code, len(code), offset, count, ctypes.byref(all_insn))
code = ctypes.byref(ctypes.c_char.from_buffer(code))
res = _cs.cs_disasm(self.csh, code, size, offset, count, ctypes.byref(all_insn))
if res > 0:
try:
for i in range(res):
Expand Down