diff --git a/libr/asm/p/asm_x86_cs.c b/libr/asm/p/asm_x86_cs.c index e61de39802..eaee7ed2b6 100644 --- a/libr/asm/p/asm_x86_cs.c +++ b/libr/asm/p/asm_x86_cs.c @@ -56,6 +56,9 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } else { cs_option (cd, CS_OPT_DETAIL, CS_OPT_OFF); } + // always unsigned immediates (kernel addresses) + // maybe r2 should have an option for this too? + cs_option (cd, CS_OPT_UNSIGNED, CS_OPT_ON); if (a->syntax == R_ASM_SYNTAX_MASM) { #if CS_API_MAJOR >= 4 cs_option (cd, CS_OPT_SYNTAX, CS_OPT_SYNTAX_MASM); diff --git a/shlr/capstone-patches/honor-unsigned.patch b/shlr/capstone-patches/honor-unsigned.patch new file mode 100644 index 0000000000..d3506c0f7f --- /dev/null +++ b/shlr/capstone-patches/honor-unsigned.patch @@ -0,0 +1,77 @@ +commit e0f1649e528269c2c99412cf7c64922ec8fd3f5e +Author: pancake +Date: Thu Jun 15 09:36:09 2017 +0200 + + Honor CS_OPT_UNSIGNED on x86 and add cstool -u + +diff --git a/arch/X86/X86IntelInstPrinter.c b/arch/X86/X86IntelInstPrinter.c +index 5ea5835d..25ba93ed 100644 +--- a/arch/X86/X86IntelInstPrinter.c ++++ b/arch/X86/X86IntelInstPrinter.c +@@ -444,7 +444,7 @@ static void _printOperand(MCInst *MI, unsigned OpNo, SStream *O) + printRegName(O, MCOperand_getReg(Op)); + } else if (MCOperand_isImm(Op)) { + int64_t imm = MCOperand_getImm(Op); +- printImm(MI->csh->syntax, O, imm, false); ++ printImm(MI->csh->syntax, O, imm, MI->csh->imm_unsigned); + } + } + +@@ -887,7 +887,7 @@ static void printOperand(MCInst *MI, unsigned OpNo, SStream *O) + // printf(">>> id = %u\n", MI->flat_insn->id); + switch(MI->flat_insn->id) { + default: +- printImm(MI->csh->syntax, O, imm, false); ++ printImm(MI->csh->syntax, O, imm, MI->csh->imm_unsigned); + break; + + case X86_INS_MOVABS: +diff --git a/cstool/cstool.c b/cstool/cstool.c +index ef88ccb9..ca430c32 100644 +--- a/cstool/cstool.c ++++ b/cstool/cstool.c +@@ -72,7 +72,7 @@ static uint8_t *preprocess(char *code, size_t *size) + static void usage(char *prog) + { + printf("Cstool for Capstone Disassembler Engine v%u.%u.%u\n\n", CS_VERSION_MAJOR, CS_VERSION_MINOR, CS_VERSION_EXTRA); +- printf("Syntax: %s [-d] [start-address-in-hex-format]\n", prog); ++ printf("Syntax: %s [-u|-d] [start-address-in-hex-format]\n", prog); + printf("\nThe following options are supported:\n"); + + if (cs_support(CS_ARCH_X86)) { +@@ -144,18 +144,23 @@ int main(int argc, char **argv) + cs_mode md; + cs_arch arch; + bool detail_flag = false; ++ bool unsigned_flag = false; + + if (argc != 3 && argc != 4 && argc != 5) { + usage(argv[0]); + return -1; + } + +- if (!strcmp(argv[1], "-d")) { ++ if (!strcmp(argv[1], "-d") || !strcmp(argv[1], "-u")) { + if (argc == 3) { + usage(argv[0]); + return -1; + } +- detail_flag = true; ++ if (argv[1][1] == 'd') { ++ detail_flag = true; ++ } else { ++ unsigned_flag = true; ++ } + mode = argv[2]; + assembly = preprocess(argv[3], &size); + if (argc == 5) { +@@ -345,6 +350,9 @@ int main(int argc, char **argv) + if (detail_flag) { + cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON); + } ++ if (unsigned_flag) { ++ cs_option(handle, CS_OPT_UNSIGNED, CS_OPT_ON); ++ } + + count = cs_disasm(handle, assembly, size, address, 0, &insn); + if (count > 0) { diff --git a/shlr/capstone-patches/ut64.patch b/shlr/capstone-patches/ut64.patch deleted file mode 100644 index a62406a0a8..0000000000 --- a/shlr/capstone-patches/ut64.patch +++ /dev/null @@ -1,18 +0,0 @@ -diff --git a/arch/X86/X86IntelInstPrinter.c b/arch/X86/X86IntelInstPrinter.c -index 57778a7..ad62378 100644 ---- a/arch/X86/X86IntelInstPrinter.c -+++ b/arch/X86/X86IntelInstPrinter.c -@@ -421,11 +421,8 @@ static void printImm(int syntax, SStream *O, int64_t imm, bool positive) - if (imm < 0) { - if (imm == 0x8000000000000000LL) // imm == -imm - SStream_concat0(O, "0x8000000000000000"); -- else if (imm < -HEX_THRESHOLD) -- SStream_concat(O, "-0x%"PRIx64, -imm); -- else -- SStream_concat(O, "-%"PRIu64, -imm); -- -+ else -+ SStream_concat(O, "0x%"PRIx64, imm); - } else { - if (imm > HEX_THRESHOLD) - SStream_concat(O, "0x%"PRIx64, imm);