Update __init__.py (#1453)

Pass bytearrays by reference instead of copying to bytes.
This commit is contained in:
ChrisDenton 2019-04-03 04:40:36 +01:00 committed by Nguyen Anh Quynh
parent d861c5fdeb
commit e07c1dd116
1 changed files with 8 additions and 8 deletions

View File

@ -1073,11 +1073,11 @@ class Cs(object):
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):
@ -1101,11 +1101,11 @@ class Cs(object):
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):