Update __init__.py (#1453)
Pass bytearrays by reference instead of copying to bytes.
This commit is contained in:
parent
d861c5fdeb
commit
e07c1dd116
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue