From d17307e74d48aecf7132a85609fa372c4b78818c Mon Sep 17 00:00:00 2001 From: Peace-Maker Date: Mon, 5 Jun 2023 15:06:12 +0200 Subject: [PATCH 1/3] Fix Python Bindings after changes to cs_detail #2034 changed the `regs_read` array size and added a new `writeback` element to the cs_detail struct. Those changes weren't reflected in the Python bindings causing details to be missing. --- bindings/python/capstone/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bindings/python/capstone/__init__.py b/bindings/python/capstone/__init__.py index 71cae77e1a..b4123c0666 100755 --- a/bindings/python/capstone/__init__.py +++ b/bindings/python/capstone/__init__.py @@ -407,12 +407,13 @@ class _cs_arch(ctypes.Union): class _cs_detail(ctypes.Structure): _fields_ = ( - ('regs_read', ctypes.c_uint16 * 16), + ('regs_read', ctypes.c_uint16 * 20), ('regs_read_count', ctypes.c_ubyte), ('regs_write', ctypes.c_uint16 * 20), ('regs_write_count', ctypes.c_ubyte), ('groups', ctypes.c_ubyte * 8), ('groups_count', ctypes.c_ubyte), + ('writeback', ctypes.c_bool), ('arch', _cs_arch), ) From dc7d2be7c337568ba7a8f12c703a4c2b261e17b9 Mon Sep 17 00:00:00 2001 From: Peace-Maker Date: Mon, 5 Jun 2023 15:08:32 +0200 Subject: [PATCH 2/3] Fix TriCore Python bindings The structs were out of sync and were missing a few elements. The `update_flags` element wasn't exposed at all. --- bindings/python/capstone/__init__.py | 2 +- bindings/python/capstone/tricore.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/bindings/python/capstone/__init__.py b/bindings/python/capstone/__init__.py index b4123c0666..1bd9934b9d 100755 --- a/bindings/python/capstone/__init__.py +++ b/bindings/python/capstone/__init__.py @@ -728,7 +728,7 @@ def __gen_detail(self): elif arch == CS_ARCH_RISCV: (self.operands) = riscv.get_arch_info(self._raw.detail.contents.arch.riscv) elif arch == CS_ARCH_TRICORE: - (self.operands) = riscv.get_arch_info(self._raw.detail.contents.arch.tricore) + (self.update_flags, self.operands) = tricore.get_arch_info(self._raw.detail.contents.arch.tricore) def __getattr__(self, name): diff --git a/bindings/python/capstone/tricore.py b/bindings/python/capstone/tricore.py index 53ba251e8d..9a48a9f795 100644 --- a/bindings/python/capstone/tricore.py +++ b/bindings/python/capstone/tricore.py @@ -1,6 +1,7 @@ # Capstone Python bindings, by billow -import ctypes, copy +import ctypes +from . import copy_ctypes_list from .tricore_const import * class TriCoreOpMem(ctypes.Structure): @@ -22,6 +23,7 @@ class TriCoreOp(ctypes.Structure): _fields_ = ( ('type', ctypes.c_uint), ('value', TriCoreOpValue), + ('access', ctypes.c_uint8) ) @property @@ -42,4 +44,8 @@ class CsTriCore(ctypes.Structure): _fields_ = ( ('op_count', ctypes.c_uint8), ('operands', TriCoreOp * 8), + ('update_flags', ctypes.c_bool), ) + +def get_arch_info(a): + return (a.update_flags, copy_ctypes_list(a.operands[:a.op_count])) From 1da1cbf72d8de96bb3bb03e332f874a4c758739f Mon Sep 17 00:00:00 2001 From: Peace-Maker Date: Mon, 5 Jun 2023 15:09:45 +0200 Subject: [PATCH 3/3] Fix RISCV Python bindings The structs had changed and the `need_effective_addr` element wasn't exposed. --- bindings/python/capstone/__init__.py | 2 +- bindings/python/capstone/riscv.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bindings/python/capstone/__init__.py b/bindings/python/capstone/__init__.py index 1bd9934b9d..b3ffc1bfe1 100755 --- a/bindings/python/capstone/__init__.py +++ b/bindings/python/capstone/__init__.py @@ -726,7 +726,7 @@ def __gen_detail(self): elif arch == CS_ARCH_BPF: (self.operands) = bpf.get_arch_info(self._raw.detail.contents.arch.bpf) elif arch == CS_ARCH_RISCV: - (self.operands) = riscv.get_arch_info(self._raw.detail.contents.arch.riscv) + (self.need_effective_addr, self.operands) = riscv.get_arch_info(self._raw.detail.contents.arch.riscv) elif arch == CS_ARCH_TRICORE: (self.update_flags, self.operands) = tricore.get_arch_info(self._raw.detail.contents.arch.tricore) diff --git a/bindings/python/capstone/riscv.py b/bindings/python/capstone/riscv.py index 6e33a75f7e..ca09db61f3 100644 --- a/bindings/python/capstone/riscv.py +++ b/bindings/python/capstone/riscv.py @@ -7,7 +7,7 @@ # define the API class RISCVOpMem(ctypes.Structure): _fields_ = ( - ('base', ctypes.c_uint8), + ('base', ctypes.c_uint), ('disp', ctypes.c_int64), ) @@ -39,11 +39,11 @@ def mem(self): class CsRISCV(ctypes.Structure): _fields_ = ( - ('need_effective_addr', ctypes.c_bool), + ('need_effective_addr', ctypes.c_bool), ('op_count', ctypes.c_uint8), ('operands', RISCVOp * 8), ) def get_arch_info(a): - return (copy_ctypes_list(a.operands[:a.op_count])) + return (a.need_effective_addr, copy_ctypes_list(a.operands[:a.op_count]))