diff --git a/arch/AArch64/mapping.c b/arch/AArch64/mapping.c index b4b2e3d0..f4a1eb5c 100644 --- a/arch/AArch64/mapping.c +++ b/arch/AArch64/mapping.c @@ -436,7 +436,7 @@ static name_map reg_name_maps[] = { { ARM64_REG_Q31_Q0_Q1_Q2, "q31_q0_q1_q2"}, }; -char *AArch64_reg_name(unsigned int reg) +char *AArch64_reg_name(csh handle, unsigned int reg) { if (reg >= ARM64_REG_MAX) return NULL; @@ -3684,7 +3684,7 @@ static name_map alias_insn_name_maps[] = { { ARM64_INS_NEGS, "negs" }, }; -char *AArch64_insn_name(unsigned int id) +char *AArch64_insn_name(csh handle, unsigned int id) { if (id >= ARM64_INS_MAX) return NULL; diff --git a/arch/AArch64/mapping.h b/arch/AArch64/mapping.h index 5e0f3141..359a17b7 100644 --- a/arch/AArch64/mapping.h +++ b/arch/AArch64/mapping.h @@ -8,7 +8,7 @@ #include "../../include/arm64.h" // return name of regiser in friendly string -char *AArch64_reg_name(unsigned int reg); +char *AArch64_reg_name(csh handle, unsigned int reg); // given internal insn id, return public instruction info void AArch64_get_insn_id(cs_insn *insn, unsigned int id); @@ -16,7 +16,7 @@ void AArch64_get_insn_id(cs_insn *insn, unsigned int id); // given public insn id, return internal instruction ID unsigned int AArch64_get_insn_id2(unsigned int id); -char *AArch64_insn_name(unsigned int id); +char *AArch64_insn_name(csh handle, unsigned int id); // map instruction name to public instruction ID arm64_reg AArch64_map_insn(char *name); diff --git a/arch/ARM/mapping.c b/arch/ARM/mapping.c index bb94fdd2..73a8dd92 100644 --- a/arch/ARM/mapping.c +++ b/arch/ARM/mapping.c @@ -125,7 +125,7 @@ static name_map reg_name_maps[] = { { ARM_REG_S31, "s31"}, }; -char *ARM_reg_name(unsigned int reg) +char *ARM_reg_name(csh handle, unsigned int reg) { if (reg >= ARM_REG_MAX) return NULL; @@ -2763,7 +2763,7 @@ static name_map insn_name_maps[] = { { ARM_INS_PUSH, "push" }, }; -char *ARM_insn_name(unsigned int id) +char *ARM_insn_name(csh handle, unsigned int id) { if (id >= ARM_INS_MAX) return NULL; diff --git a/arch/ARM/mapping.h b/arch/ARM/mapping.h index 6f1ff245..63be9cb2 100644 --- a/arch/ARM/mapping.h +++ b/arch/ARM/mapping.h @@ -9,7 +9,7 @@ #include "../../utils.h" // return name of regiser in friendly string -char *ARM_reg_name(unsigned int reg); +char *ARM_reg_name(csh handle, unsigned int reg); // given internal insn id, return public instruction ID void ARM_get_insn_id(cs_insn *insn, unsigned int id); @@ -17,7 +17,7 @@ void ARM_get_insn_id(cs_insn *insn, unsigned int id); // given public insn id, return internal instruction info unsigned int ARM_get_insn_id2(unsigned int id); -char *ARM_insn_name(unsigned int id); +char *ARM_insn_name(csh handle, unsigned int id); // map instruction name to instruction ID arm_reg ARM_map_insn(char *name); diff --git a/arch/Mips/mapping.c b/arch/Mips/mapping.c index a27de387..2fc32e5a 100644 --- a/arch/Mips/mapping.c +++ b/arch/Mips/mapping.c @@ -173,7 +173,7 @@ static name_map reg_name_maps[] = { { MIPS_REG_W31, "w31"}, }; -char *Mips_reg_name(unsigned int reg) +char *Mips_reg_name(csh handle, unsigned int reg) { if (reg >= MIPS_REG_MAX) return NULL; @@ -1916,7 +1916,7 @@ static name_map alias_insn_names[] = { { MIPS_INS_BC1F, "bc1f" }, }; -char *Mips_insn_name(unsigned int id) +char *Mips_insn_name(csh handle, unsigned int id) { if (id >= MIPS_INS_MAX) return NULL; diff --git a/arch/Mips/mapping.h b/arch/Mips/mapping.h index 5a4441e9..e4dcfc42 100644 --- a/arch/Mips/mapping.h +++ b/arch/Mips/mapping.h @@ -8,7 +8,7 @@ #include "../../include/mips.h" // return name of regiser in friendly string -char *Mips_reg_name(unsigned int reg); +char *Mips_reg_name(csh handle, unsigned int reg); // given internal insn id, return public instruction info void Mips_get_insn_id(cs_insn *insn, unsigned int id); @@ -17,7 +17,7 @@ void Mips_get_insn_id(cs_insn *insn, unsigned int id); unsigned int Mips_get_insn_id2(unsigned int id); // given public insn id, return internal insn id -char *Mips_insn_name(unsigned int id); +char *Mips_insn_name(csh handle, unsigned int id); // map instruction name to instruction ID mips_reg Mips_map_insn(char *name); diff --git a/arch/X86/X86ATTInstPrinter.c b/arch/X86/X86ATTInstPrinter.c index e78ef74a..2df03347 100644 --- a/arch/X86/X86ATTInstPrinter.c +++ b/arch/X86/X86ATTInstPrinter.c @@ -147,7 +147,7 @@ static void printMemOffs8(MCInst *MI, unsigned OpNo, SStream *O) // If this has a segment register, print it. // this is a hack. will fix it later if (MI->pub_insn.x86.segment) { - SStream_concat(O, "%%%s:", X86_reg_name(MI->pub_insn.x86.segment)); + SStream_concat(O, "%%%s:", X86_reg_name(1, MI->pub_insn.x86.segment)); } printMemOffset(MI, OpNo, O); @@ -158,7 +158,7 @@ static void printMemOffs16(MCInst *MI, unsigned OpNo, SStream *O) // If this has a segment register, print it. // this is a hack. will fix it later if (MI->pub_insn.x86.segment) { - SStream_concat(O, "%%%s:", X86_reg_name(MI->pub_insn.x86.segment)); + SStream_concat(O, "%%%s:", X86_reg_name(1, MI->pub_insn.x86.segment)); } printMemOffset(MI, OpNo, O); @@ -169,7 +169,7 @@ static void printMemOffs32(MCInst *MI, unsigned OpNo, SStream *O) // If this has a segment register, print it. // this is a hack. will fix it later if (MI->pub_insn.x86.segment) { - SStream_concat(O, "%%%s:", X86_reg_name(MI->pub_insn.x86.segment)); + SStream_concat(O, "%%%s:", X86_reg_name(1, MI->pub_insn.x86.segment)); } printMemOffset(MI, OpNo, O); diff --git a/arch/X86/X86IntelInstPrinter.c b/arch/X86/X86IntelInstPrinter.c index 875293e3..5f55f3d8 100644 --- a/arch/X86/X86IntelInstPrinter.c +++ b/arch/X86/X86IntelInstPrinter.c @@ -146,7 +146,7 @@ static void printMemOffs8(MCInst *MI, unsigned OpNo, SStream *O) // If this has a segment register, print it. // this is a hack. will fix it later if (MI->pub_insn.x86.segment) { - SStream_concat(O, "%s:", X86_reg_name(MI->pub_insn.x86.segment)); + SStream_concat(O, "%s:", X86_reg_name(1, MI->pub_insn.x86.segment)); } printMemOffset(MI, OpNo, O); @@ -159,7 +159,7 @@ static void printMemOffs16(MCInst *MI, unsigned OpNo, SStream *O) // If this has a segment register, print it. // this is a hack. will fix it later if (MI->pub_insn.x86.segment) { - SStream_concat(O, "%s:", X86_reg_name(MI->pub_insn.x86.segment)); + SStream_concat(O, "%s:", X86_reg_name(1, MI->pub_insn.x86.segment)); } printMemOffset(MI, OpNo, O); @@ -173,7 +173,7 @@ static void printMemOffs32(MCInst *MI, unsigned OpNo, SStream *O) // If this has a segment register, print it. // this is a hack. will fix it later if (MI->pub_insn.x86.segment) { - SStream_concat(O, "%s:", X86_reg_name(MI->pub_insn.x86.segment)); + SStream_concat(O, "%s:", X86_reg_name(1, MI->pub_insn.x86.segment)); } printMemOffset(MI, OpNo, O); diff --git a/arch/X86/mapping.c b/arch/X86/mapping.c index 6ee90d0d..4af6ce4a 100644 --- a/arch/X86/mapping.c +++ b/arch/X86/mapping.c @@ -7,6 +7,7 @@ #include "X86DisassemblerDecoder.h" #include "../../utils.h" +#include "../../cs_priv.h" #include "../../include/x86.h" static x86_reg sib_base_map[] = { @@ -65,6 +66,7 @@ x86_reg x86_map_segment(int r) static name_map reg_name_maps[] = { { X86_REG_INVALID, NULL }, + { X86_REG_AH, "ah" }, { X86_REG_AL, "al" }, { X86_REG_AX, "ax" }, @@ -299,11 +301,20 @@ static name_map reg_name_maps[] = { { X86_REG_R15W, "r15w" }, }; -char *X86_reg_name(unsigned int reg) +char *X86_reg_name(csh handle, unsigned int reg) { + cs_struct *ud = (cs_struct *)handle; + if (reg >= X86_REG_MAX) return NULL; + if (reg == X86_REG_EFLAGS) { + if (ud->mode & CS_MODE_32) + return "eflags"; + if (ud->mode & CS_MODE_64) + return "rflags"; + } + return reg_name_maps[reg].name; } @@ -1568,7 +1579,7 @@ static name_map insn_name_maps[] = { { X86_INS_XTEST, "xtest" }, }; -char *X86_insn_name(unsigned int id) +char *X86_insn_name(csh handle, unsigned int id) { if (id >= X86_INS_MAX) return NULL; diff --git a/arch/X86/mapping.h b/arch/X86/mapping.h index f1e11e7d..15ca133e 100644 --- a/arch/X86/mapping.h +++ b/arch/X86/mapping.h @@ -20,13 +20,13 @@ x86_reg x86_map_segment(int r); x86_reg x86_map_regname(char *reg); // return name of regiser in friendly string -char *X86_reg_name(unsigned int reg); +char *X86_reg_name(csh handle, unsigned int reg); // given internal insn id, return public instruction info void X86_get_insn_id(cs_insn *insn, unsigned int id); // return insn name, given insn id -char *X86_insn_name(unsigned int id); +char *X86_insn_name(csh handle, unsigned int id); // return insn id, given insn mnemonic x86_reg X86_map_insn(char *mnem); diff --git a/cs.c b/cs.c index ae400c8b..75ef9b9c 100644 --- a/cs.c +++ b/cs.c @@ -383,7 +383,7 @@ char *cs_reg_name(csh ud, unsigned int reg) return NULL; } - return handle->reg_name(reg); + return handle->reg_name(ud, reg); } char *cs_insn_name(csh ud, unsigned int insn) @@ -394,7 +394,7 @@ char *cs_insn_name(csh ud, unsigned int insn) return NULL; } - return handle->insn_name(insn); + return handle->insn_name(ud, insn); } static bool arr_exist(unsigned int *arr, int max, unsigned int id) diff --git a/cs_priv.h b/cs_priv.h index 014e983e..7b72dd5d 100644 --- a/cs_priv.h +++ b/cs_priv.h @@ -17,7 +17,7 @@ typedef void (*PostPrinter_t)(unsigned int insn, cs_insn *, char *mnem); typedef bool (*Disasm_t)(csh handle, unsigned char *code, size_t code_len, MCInst *instr, uint16_t *size, uint64_t address, void *info); -typedef char *(*GetName_t)(unsigned int reg); +typedef char *(*GetName_t)(csh handle, unsigned int reg); typedef void (*GetID_t)(cs_insn *insn, unsigned int id);