From 9413509982e40809a773eb9cd0de956be8779a76 Mon Sep 17 00:00:00 2001 From: Richo Healey Date: Wed, 5 Oct 2016 22:47:40 -0700 Subject: [PATCH] Workaround unicorn handing back bytearrays --- bindings/python/capstone/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bindings/python/capstone/__init__.py b/bindings/python/capstone/__init__.py index 1dcbad3da..8b32c3ae8 100644 --- a/bindings/python/capstone/__init__.py +++ b/bindings/python/capstone/__init__.py @@ -843,6 +843,10 @@ class Cs(object): print(code) code = code.encode() print(code)''' + # Hack, unicorn's memory accessors give you back bytearrays, but they + # cause TypeErrors when you hand them into Capstone. + if isinstance(code, bytearray): + code = bytes(code) res = _cs.cs_disasm(self.csh, code, len(code), offset, count, ctypes.byref(all_insn)) if res > 0: try: