x86: map EFLAGS to string of 'flags', 'eflags' or 'rflags' depending on current CS_MODE

This commit is contained in:
Nguyen Anh Quynh 2013-12-09 10:26:18 +08:00
parent bdaf3b5089
commit a253c7a8e8
12 changed files with 36 additions and 25 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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);

4
cs.c
View File

@ -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)

View File

@ -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);