Skip to content

Commit

Permalink
Error checking improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
John Detter committed Jun 20, 2016
1 parent 60f1779 commit 476d083
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 32 deletions.
9 changes: 0 additions & 9 deletions common/src/arch-x86.C
Original file line number Diff line number Diff line change
Expand Up @@ -8210,15 +8210,6 @@ ia32_instruction& ia32_decode(unsigned int capa, const unsigned char* addr, ia32
return instruct;
}

/* Set the amount of prefix bytes */
if(instruct.loc)
{
instruct.loc->num_prefixes = pref.getCount();
}

/* Adjust the instruction size for the prefixes */
instruct.size = pref.getCount();

/* Skip the prefixes so that we don't decode them again */
addr += instruct.size;

Expand Down
51 changes: 28 additions & 23 deletions common/src/arch-x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,21 +409,16 @@ enum AMD64_REG_NUMBERS {
#define POP_EBI (0x5e)
#define POP_EDI (0x5f)


#define PUSHAD (0x60)
#define POPAD (0x61)




#define JE_R8 (0x74)
#define JNE_R8 (0x75)
#define JL_R8 (0x7C)
#define JLE_R8 (0x7E)
#define JG_R8 (0x7F)
#define JGE_R8 (0x7D)


#define MOVREGMEM_REG (0x8b)
#define MOV_R8_TO_RM8 (0x88) //move r8 to r/m8
#define MOV_R16_TO_RM16 (0x89) //move r16 to r/m16
Expand All @@ -432,20 +427,12 @@ enum AMD64_REG_NUMBERS {
#define MOV_RM16_TO_R16 (0x8b)
#define MOV_RM32_TO_R32 (0x8b)



#define NOP (0x90)
#define PUSHFD (0x9C)
#define POPFD (0x9D)


#define JCXZ (0xE3)






#define FSAVE (0x9BDD)
#define FSAVE_OP (6)

Expand All @@ -468,7 +455,6 @@ enum {
RepGroup = 0
};


#ifndef VEX_PREFIX_MASKS
#define VEX_PREFIX_MASKS

Expand Down Expand Up @@ -800,7 +786,6 @@ enum sizehacks {
shREPNESCAS
};


struct ia32_condition
{
bool is;
Expand All @@ -811,9 +796,6 @@ struct ia32_condition
void set(int _tttn) { is = true; tttn = _tttn; }
};

bool ia32_decode_prefixes(const unsigned char* addr, ia32_instruction& insn);


struct ia32_operand { // operand as given in Intel book tables
unsigned int admet; // addressing method
unsigned int optype; // operand type;
Expand Down Expand Up @@ -861,7 +843,7 @@ class ia32_instruction
friend bool ia32_decode_prefixes(const unsigned char* addr, ia32_instruction& insn);
friend COMMON_EXPORT ia32_instruction& ia32_decode(unsigned int capa, const unsigned char* addr,
ia32_instruction& instruct);
friend COMMON_EXPORT int ia32_decode_opcode(unsigned int capa,
friend int ia32_decode_opcode(unsigned int capa,
const unsigned char* addr, ia32_instruction& instruct,
ia32_entry** gotit_ret);
friend unsigned int ia32_decode_operands (const ia32_prefixes& pref, const ia32_entry& gotit,
Expand Down Expand Up @@ -919,19 +901,42 @@ class ia32_instruction
#define IA32_DECODE_PREFIXES (1<<0)
#define IA32_DECODE_MNEMONICS (1<<1)
#define IA32_DECODE_OPERANDS (1<<2)
#define IA32_DECODE_JMPS (1<<3)
#define IA32_DECODE_JMPS (1<<3)
#define IA32_DECODE_MEMACCESS (1<<4)
#define IA32_DECODE_CONDITION (1<<5)

#define IA32_FULL_DECODER (IA32_DECODE_PREFIXES | IA32_DECODE_MNEMONICS | IA32_DECODE_OPERANDS | IA32_DECODE_JMPS | IA32_DECODE_MEMACCESS | IA32_DECODE_CONDITION)
#define IA32_FULL_DECODER (IA32_DECODE_PREFIXES \
| IA32_DECODE_MNEMONICS \
| IA32_DECODE_OPERANDS \
| IA32_DECODE_JMPS \
| IA32_DECODE_MEMACCESS \
| IA32_DECODE_CONDITION)
#define IA32_SIZE_DECODER 0

COMMON_EXPORT ia32_instruction& ia32_decode(unsigned int capabilities,
const unsigned char* addr, ia32_instruction&);
/* TODO: documentation*/
COMMON_EXPORT bool ia32_decode_prefixes(const unsigned char* addr, ia32_instruction& insn);

/**
* Decode just the opcode of the given instruction. This implies that
* ia32_decode_prefixes has already been called on the given instruction
* and addr has been moved past the prefix bytes. Returns zero on success,
* non zero otherwise.
*/
COMMON_EXPORT int ia32_decode_opcode(unsigned int capa,
const unsigned char* addr, ia32_instruction& instruct,
ia32_entry** gotit_ret);

/**
* Do a complete decoding of the instruction at the given address. This
* function calls ia32_decode_prefixes, ia32_decode_opcode and
* ia32_decode_operands. Returns zero on success, non zero otherwise.
* When there is a decoding failure, the state of the given instruction
* is not defined. capabilities is a mask of the above flags (IA32_DECODE_*).
* The mask determines what part of the instruction should be decoded.
*/
COMMON_EXPORT ia32_instruction& ia32_decode(unsigned int capabilities,
const unsigned char* addr, ia32_instruction&);


enum dynamic_call_address_mode {
REGISTER_DIRECT, REGISTER_INDIRECT,
Expand Down

0 comments on commit 476d083

Please sign in to comment.