diff --git a/pybfd3/bfd.c b/pybfd3/bfd.c index df1179c..f66d1ca 100644 --- a/pybfd3/bfd.c +++ b/pybfd3/bfd.c @@ -4,6 +4,8 @@ // Copyright (c) 2013 Groundworks Technologies // +// In order to use '#' variant of formats, we must define this on python >= 3.10 +#define PY_SSIZE_T_CLEAN #include #include diff --git a/pybfd3/bfd_headers.h b/pybfd3/bfd_headers.h index c50fc24..e988550 100644 --- a/pybfd3/bfd_headers.h +++ b/pybfd3/bfd_headers.h @@ -35,3 +35,7 @@ enum PYBFD3_DISASM_CALLBACK_RESULT { }; #endif /* PYBFD3_HEADERS */ + +#ifndef BFD_VMA_FMT +#define BFD_VMA_FMT PRIx64 +#endif diff --git a/pybfd3/opcodes.c b/pybfd3/opcodes.c index dbd94a5..ebc4442 100644 --- a/pybfd3/opcodes.c +++ b/pybfd3/opcodes.c @@ -4,6 +4,9 @@ // Copyright (c) 2013 Groundworks Technologies // +// In order to use '#' variant of formats, we must define this on python >= 3.10 +#define PY_SSIZE_T_CLEAN + #include #include @@ -95,6 +98,17 @@ get_disassemble_function( unsigned long long ull_arch, return (disassembler_ftype)NULL; } +#ifdef PYBFD3_LIBBFD_INIT_DISASM_INFO_FOUR_ARGS_SIGNATURE +// bpftrace no operation fprintf for init_disassemble_info +static int fprintf_styled_nop(void *out __attribute__((unused)), + enum disassembler_style s __attribute__((unused)), + const char *fmt __attribute__((unused)), + ...) +{ + return 0; +} +#endif + // // Name : initialize_opcodes // @@ -123,8 +137,13 @@ initialize_opcodes() memset(pdisasm_ptr, 0, sizeof(disassembler_pointer)); // Zero out structure members - init_disassemble_info(&pdisasm_ptr->dinfo, &pdisasm_ptr->sfile, - (fprintf_ftype)__disassemle_printf); + #ifdef PYBFD3_LIBBFD_INIT_DISASM_INFO_FOUR_ARGS_SIGNATURE + init_disassemble_info(&pdisasm_ptr->dinfo, &pdisasm_ptr->sfile, + (fprintf_ftype)__disassemle_printf, fprintf_styled_nop); + #else + init_disassemble_info(&pdisasm_ptr->dinfo, &pdisasm_ptr->sfile, + (fprintf_ftype)__disassemle_printf); + #endif pdisasm_ptr->pfn_disassemble = NULL; @@ -471,8 +490,11 @@ start_smart_disassemble(disassembler_pointer* pdisasm_ptr, unsigned long offset, offset += n; // update the offset for the next disassemble operation. disassembled_bytes += n; // keep track of the number of bytes // processed. - - py_result = PyEval_CallObject(callback, py_args); + #if PY_VERSION_HEX >= 0x03090000 + py_result = PyObject_Call(callback, py_args, NULL); + #else + py_result = PyEval_CallObject(callback, py_args); + #endif Py_XDECREF(py_args); if (!py_result) { diff --git a/pybfd3/test_init_disassemble_info.c b/pybfd3/test_init_disassemble_info.c new file mode 100644 index 0000000..48e4bef --- /dev/null +++ b/pybfd3/test_init_disassemble_info.c @@ -0,0 +1,8 @@ +#define PACKAGE "pybfd3" +#define PACKAGE_VERSION "0.1.5" + +#include +int main(void) { + init_disassemble_info(NULL, NULL, NULL); + return 0; +} \ No newline at end of file diff --git a/setup.py b/setup.py index b095fb7..d127499 100644 --- a/setup.py +++ b/setup.py @@ -223,19 +223,29 @@ def generate_source_files( self ): self.with_static_binutils == None) source_bfd_archs_c = generate_supported_architectures_source(supported_archs, supported_machines) + macros = [] print("[+] Testing for print_insn_i386...") try: objects = self.compiler.compile( [os.path.join(PACKAGE_DIR, "test_print_insn_i386.c"), ], include_dirs = [self.includes,], ) - if len(objects) > 0: - macros = None - else: + if len(objects) == 0: macros = [("PYBFD3_BFD_GE_2_29", None)] except: macros = [("PYBFD3_BFD_GE_2_29", None)] + print("[+] Testing for init_disassemble_info...") + try: + objects = self.compiler.compile( + [os.path.join(PACKAGE_DIR, "test_init_disassemble_info.c"), ], + include_dirs = [self.includes,], + ) + if len(objects) == 0: + macros.append(("PYBFD3_LIBBFD_INIT_DISASM_INFO_FOUR_ARGS_SIGNATURE", None)) + except: + macros.append(("PYBFD3_LIBBFD_INIT_DISASM_INFO_FOUR_ARGS_SIGNATURE", None)) + print("[+] Generating .C files...") gen_file = os.path.join(PACKAGE_DIR, "gen_bfd_archs.c") with io.open(gen_file, "w+") as fd: