Skip to content

Commit

Permalink
invoke from_buffer only for writeable interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
huettenhain committed Nov 12, 2021
1 parent d59c50f commit 684187a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions bindings/python/capstone/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,8 +1099,9 @@ def disasm(self, code, offset, count=0):
print(code)'''
# Pass a bytearray by reference
size = len(code)
if isinstance(code, (bytearray, memoryview)):
code = ctypes.byref(ctypes.c_char.from_buffer(code))
view = memoryview(code)
if not view.readonly:
code = ctypes.byref(ctypes.c_char.from_buffer(view))
res = _cs.cs_disasm(self.csh, code, size, offset, count, ctypes.byref(all_insn))
if res > 0:
try:
Expand All @@ -1127,8 +1128,9 @@ def disasm_lite(self, code, offset, count=0):
all_insn = ctypes.POINTER(_cs_insn)()
size = len(code)
# Pass a bytearray by reference
if isinstance(code, (bytearray, memoryview) ):
code = ctypes.byref(ctypes.c_char.from_buffer(code))
view = memoryview(code)
if not view.readonly:
code = ctypes.byref(ctypes.c_char.from_buffer(view))
res = _cs.cs_disasm(self.csh, code, size, offset, count, ctypes.byref(all_insn))
if res > 0:
try:
Expand Down

0 comments on commit 684187a

Please sign in to comment.