mirror of
https://gitlab.com/qemu-project/capstone.git
synced 2025-09-17 02:01:15 +08:00
x86: calculate op_size properly in special cases regarding rax, eax, ax, al registers
This commit is contained in:
@ -446,8 +446,11 @@ void X86_ATT_printInst(MCInst *MI, SStream *OS, void *info)
|
||||
// so we have to handle that case to not miss the first op.
|
||||
char lastop[32];
|
||||
get_last_op(OS->buffer, lastop);
|
||||
char *acc_regs[] = {"rax", "eax", "ax", "al", NULL};
|
||||
if (lastop[0] == '%' && str_in_list(acc_regs, lastop+1)) {
|
||||
char *acc_regs[] = {"al", "ax", "eax", "rax", NULL};
|
||||
int post;
|
||||
if (lastop[0] == '%' && ((post = str_in_list(acc_regs, lastop+1)) != -1)) {
|
||||
// set operand size following register size
|
||||
MI->pub_insn.x86.op_size = 1 << post;
|
||||
// this is one of the registers AL, AX, EAX, RAX
|
||||
// canonicalize the register name first
|
||||
//int i;
|
||||
|
@ -1676,8 +1676,6 @@ static int readOperands(struct InternalInstruction* insn)
|
||||
int hasVVVV, needVVVV;
|
||||
int sawRegImm = 0;
|
||||
|
||||
//printf(">>> readOperands()\n");
|
||||
|
||||
/* If non-zero vvvv specified, need to make sure one of the operands
|
||||
uses it. */
|
||||
hasVVVV = !readVVVV(insn);
|
||||
|
@ -231,8 +231,11 @@ void X86_Intel_printInst(MCInst *MI, SStream *O, void *Info)
|
||||
|
||||
char tmp[64];
|
||||
if (get_first_op(O->buffer, tmp)) {
|
||||
char *acc_regs[] = {"rax", "eax", "ax", "al", NULL};
|
||||
if (tmp[0] != 0 && str_in_list(acc_regs, tmp)) {
|
||||
int post;
|
||||
char *acc_regs[] = {"al", "ax", "eax", "rax", NULL};
|
||||
if (tmp[0] != 0 && ((post = str_in_list(acc_regs, tmp)) != -1)) {
|
||||
// set operand size following register size
|
||||
MI->pub_insn.x86.op_size = 1 << post;
|
||||
// tmp is a register
|
||||
if (MI->pub_insn.x86.operands[0].type != X86_OP_INVALID &&
|
||||
MI->pub_insn.x86.operands[0].type != X86_OP_REG) {
|
||||
|
13
utils.c
13
utils.c
@ -5,16 +5,19 @@
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
// check to see if a string exists in a list of string ...
|
||||
bool str_in_list(char **list, char *s)
|
||||
// return the position of a string in a list of strings
|
||||
// or -1 if given string is not in the list
|
||||
int str_in_list(char **list, char *s)
|
||||
{
|
||||
char **l;
|
||||
|
||||
for(l = list; *l; l++)
|
||||
int c = 0;
|
||||
for(l = list; *l; c++, l++) {
|
||||
if (!strcasecmp(*l, s))
|
||||
return true;
|
||||
return c;
|
||||
}
|
||||
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// binary searching
|
||||
|
4
utils.h
4
utils.h
@ -25,7 +25,9 @@ typedef struct insn_map {
|
||||
bool indirect_branch; // indirect branch instruction?
|
||||
} insn_map;
|
||||
|
||||
bool str_in_list(char **list, char *s);
|
||||
// return the position of a string in a list of strings
|
||||
// or -1 if given string is not in the list
|
||||
int str_in_list(char **list, char *s);
|
||||
|
||||
// binary searching in @m, given its size in @max, and @id
|
||||
int insn_find(insn_map *m, unsigned int max, unsigned int id);
|
||||
|
Reference in New Issue
Block a user