Skip to content
Snippets Groups Projects
Commit 082b5fe1 authored by clc5q's avatar clc5q
Browse files

Set up abstract and IDA Pro classes for instruction operands.

Former-commit-id: fa3fa9efcba5cac1b29354ca0c4b7b0f2c608e21
parent 74a5a165
No related branches found
No related tags found
No related merge requests found
......@@ -19,11 +19,13 @@ include/interfaces/abstract/STARSFunction.h -text
include/interfaces/abstract/STARSInstruction.h -text
include/interfaces/abstract/STARSInstructionID.h -text
include/interfaces/abstract/STARSInterface.h -text
include/interfaces/abstract/STARSOp.h -text
include/interfaces/abstract/STARSSegment.h -text
include/interfaces/abstract/all.h -text
include/interfaces/idapro/STARSFunction.h -text
include/interfaces/idapro/STARSInstruction.h -text
include/interfaces/idapro/STARSInterface.h -text
include/interfaces/idapro/STARSOp.h -text
include/interfaces/idapro/STARSSegment.h -text
include/interfaces/idapro/all.h -text
/install-sh -text
......@@ -49,6 +51,7 @@ src/interfaces/abstract/STARSInstruction.cpp -text
src/interfaces/idapro/Makefile.in -text
src/interfaces/idapro/STARSFunction.cpp -text
src/interfaces/idapro/STARSIDAInstruction.cpp -text
src/interfaces/idapro/STARSIDAOp.cpp -text
src/interfaces/idapro/STARSInterface.cpp -text
src/interfaces/irdb/Makefile.in -text
tests/commit/busybox.psexe -text
......
......@@ -659,6 +659,7 @@ private:
SMPBasicBlock *BasicBlock; // basic block containing this instruction
insn_t SMPcmd; // copy of 'cmd' for this instruction
STARS_InstructionID_t STARS_ID; // instruction ID; could be IDA Pro address or IRDB inst ID
STARS_Instruction_t *STARSInstPtr; // pointer to either STARS_IDA_Instruction_t or STARS_IRDB_Instruction_t
uint32 features; // Canonical features for SMPcmd
SMPitype type; // Data flow analysis category
int OptType; // Optimization category (see OptCategory[])
......
#ifndef STARSOp_h
#define STARSOp_h
#include <stdint.h>
#include <assert.h>
#include <map>
class STARS_op_t
{
public:
// Constructors
STARS_op_t();
// Operators
virtual bool operator<(const STARS_op_t &rOp) const = 0;
// Get methods
virtual uintptr_t GetAddr(void) const = 0;
virtual unsigned char GetType(void) const = 0; // Get type o_reg, o_displ, etc.
virtual uint16 GetReg(void) const = 0; // Get reg field of operand, whether it is an addressing reg or directly used reg in register operand
virtual char GetSIB(void) const = 0; // Get x86 SIB byte (dense encoding of base reg, index reg, and scale factor)
virtual char GetSpecFlag4(void) const = 0; // Get specflag4 byte, used to hold a copy of the auxpref byte in x86-64 programs.
virtual uintptr_t GetImmedValue(void) const = 0; // Get value field for immediate operands; uint32 for x86-32, uint64 for x86-64
// Set methods
virtual void SetSpecFlag4(char value) = 0;
virtual void SetBitInSpecFlag4(char value) = 0; // OR in the value to set a bit
// Query methods
virtual bool IsRegOp(void) const = 0;
virtual bool IsVoidOp(void) const = 0;
virtual bool IsMemDisplacementOp(void) const = 0;
virtual bool IsStaticMemOp(void) const = 0;
virtual bool IsMemNoDisplacementOp(void) const = 0;
virtual bool HasSIBByte(void) const = 0;
};
#endif
......@@ -6,4 +6,5 @@
#include <interfaces/abstract/STARSFunction.h>
#include <interfaces/abstract/STARSInstructionID.h>
#include <interfaces/abstract/STARSInstruction.h>
#include <interfaces/abstract/STARSOp.h>
......@@ -4,6 +4,7 @@
#include <pro.h>
#include <ua.hpp>
#include "interfaces/SMPDBInterface.h"
#include "interfaces/idapro/all.h"
// struct to hold items that mimic the IDA Pro type insn_t.
struct STARS_IDA_insn_t
......@@ -57,7 +58,7 @@ struct STARS_IDA_insn_t
char insnpref; // processor dependent field
// Information about instruction operands.
op_t Operands[UA_MAXOP];
STARS_IDA_op_t *Operands[UA_MAXOP];
char flags; // instruction flags
......@@ -68,11 +69,11 @@ class STARS_IDA_Instruction_t : public STARS_Instruction_t
public:
STARS_IDA_Instruction_t(const STARS_InstructionID_t& p_id) : STARS_Instruction_t(p_id) {};
STARS_InstructionID_t GetNextInstructionID();
STARS_InstructionID_t GetTargetInstructionID();
STARS_InstructionID_t GetNextInstructionID(void);
STARS_InstructionID_t GetTargetInstructionID(void);
bool STARS_GetCmd(void);
inline uint32 GetFeatures(void) const { return STARSfeatures; };
inline bool IsRegOpnd(size_t OpndNum) const { return (STARScmd.Operands[OpndNum].type == o_reg); };
inline bool IsRegOpnd(size_t OpndNum) const { return (STARScmd.Operands[OpndNum]->GetType() == o_reg); };
#if 0
STARSOpndTypePtr GetOpnd(size_t OpndNum);
STARSOpndTypePtr MakeVoidOpnd(void);
......
#ifndef STARS_IDA_op_h
#define STARS_IDA_op_h
#include <stdint.h>
#include <pro.h>
#include <ua.hpp>
class STARS_IDA_op_t : public STARS_op_t
{
public:
// Constructors
STARS_IDA_op_t(op_t IDAOp) : m_Opnd(IDAOp) {};
// Operators
bool operator<(const STARS_op_t &rOp) const;
// Get methods
uintptr_t GetAddr(void) const { return m_Opnd.addr; };
unsigned char GetType(void) const { return m_Opnd.type; };
uint16 GetReg(void) const { return m_Opnd.reg; };
char GetSIB(void) const { return m_Opnd.sib; }; // Get x86 SIB byte (dense encoding of base reg, index reg, and scale factor)
char GetSpecFlag4(void) const {return m_Opnd.specflag4; }; // Get specflag4 byte, used to hold a copy of the auxpref byte in x86-64 programs.
uintptr_t GetImmedValue(void) const {return m_Opnd.value; }; // Get value field for immediate operands; uint32 for x86-32, uint64 for x86-64
// Set methods
void SetSpecFlag4(char value) { m_Opnd.specflag4 = value; };
void SetBitInSpecFlag4(char value) { m_Opnd.specflag4 |= value; };
// Query methods
bool IsRegOp(void) const { return (m_Opnd.type == o_reg); };
bool IsVoidOp(void) const { return (m_Opnd.type == o_void); };
bool IsMemDisplacementOp(void) const { return (m_Opnd.type == o_displ); };
bool IsStaticMemOp(void) const { return (m_Opnd.type == o_mem); };
bool IsMemNoDisplacementOp(void) const { return (m_Opnd.type == o_phrase); };
bool HasSIBByte(void) const { return (m_Opnd.hasSIB != 0); };
protected:
op_t m_Opnd;
};
#endif
......@@ -21,4 +21,5 @@
#include <interfaces/idapro/STARSFunction.h>
#include <interfaces/idapro/STARSInterface.h>
#include <interfaces/idapro/STARSInstruction.h>
#include <interfaces/idapro/STARSOp.h>
......@@ -1551,9 +1551,11 @@ SMPInstr::SMPInstr(ea_t addr) : STARS_ID((uintptr_t) addr) {
this->OptType = 0;
this->address = addr;
this->StackPtrOffset = 0;
// We do not store the pointer returned by the following allocation because
// we can look it up later via the STARS_ID member.
STARS_IDA_Instruction_t* TempPtr = new STARS_IDA_Instruction_t(this->STARS_ID);
#ifdef STARS_IDA_INTERFACE
this->STARSInstPtr = new STARS_IDA_Instruction_t(this->STARS_ID);
#else
this->STARSInstPtr = new STARS_IRDB_Instruction_t(this->STARS_ID);
#endif
#if 0
this->ResetGoodRTL();
this->ResetJumpTarget();
......
OBJS=STARSFunction.o STARSInterface.o STARSIDAInstruction.o
OBJS=STARSFunction.o STARSInterface.o STARSIDAInstruction.o STARSIDAOp.o
CXX=@CXX@
LD=@LD@
EXTRA_CXXFLAGS=@EXTRA_CXXFLAGS@
......
#include <assert.h>
#include "base/SMPDataFlowAnalysis.h"
#include "base/SMPStaticAnalyzer.h"
......@@ -20,7 +21,8 @@ STARS_InstructionID_t STARS_IDA_Instruction_t::GetNextInstructionID(void)
};
STARS_InstructionID_t STARS_IDA_Instruction_t::GetTargetInstructionID(void) {
STARS_ea_t TargetAddr = this->STARScmd.Operands[0].addr;
assert(NULL != this->STARScmd.Operands[0]);
STARS_ea_t TargetAddr = this->STARScmd.Operands[0]->GetAddr();
return STARS_InstructionID_t(TargetAddr);
}
......@@ -57,18 +59,19 @@ bool STARS_IDA_Instruction_t::STARS_GetCmd(void) {
this->STARSfeatures = cmd.get_canon_feature();
for (int i = 0; i < UA_MAXOP; ++i) {
this->STARScmd.Operands[i].specflag4 = 0;
this->STARScmd.Operands[i] = new STARS_IDA_op_t(cmd.Operands[i]);
this->STARScmd.Operands[i]->SetSpecFlag4(0);
#ifdef __EA64__
if (STARS_ISA_Bitwidth == 64) {
// Copy the cmd.rex prefix into the op_t.specflag4 field for each operand
// that has a SIB byte.
this->STARScmd.Operands[i].specflag4 = this->STARScmd.rex;
this->STARScmd.Operands[i]->SetSpecFlag4(this->STARScmd.rex);
}
#endif
// See comments on STARS_VEXPR and STARS_VSIB in SMPDataFlowAnalysis.h.
// These bits do not (as of IDA Pro 6.4) conflict with cmd.rex bits.
if ((cmd.auxpref & aux_vexpr) != 0) {
this->STARScmd.Operands[i].specflag4 |= STARS_VEXPR;
this->STARScmd.Operands[i]->SetBitInSpecFlag4(STARS_VEXPR);
}
switch (this->STARScmd.itype) {
......@@ -80,7 +83,7 @@ bool STARS_IDA_Instruction_t::STARS_GetCmd(void) {
case NN_vpgatherdq:
case NN_vpgatherqd:
case NN_vpgatherqq:
this->STARScmd.Operands[i].specflag4 |= STARS_VSIB;
this->STARScmd.Operands[i]->SetBitInSpecFlag4(STARS_VSIB);
default:
;
}
......
#include <pro.h>
#include <ua.hpp>
#include "base/SMPDataFlowAnalysis.h"
#include "base/SMPStaticAnalyzer.h"
#include "interfaces/SMPDBInterface.h"
#include "interfaces/abstract/all.h"
#include "interfaces/idapro/all.h"
bool STARS_IDA_op_t::operator<(const STARS_op_t &rOp) const {
unsigned char Type1 = this->GetType();
unsigned char Type2 = rOp.GetType();
if (Type1 != Type2)
return (Type1 < Type2);
switch (Type1) {
case o_void: return false;
case o_reg: return MDLessReg(this->GetReg(), rOp.GetReg());
case o_mem: return (this->GetAddr() < rOp.GetAddr());
case o_phrase: if (this->HasSIBByte() && rOp.HasSIBByte()) return ((this->GetSIB() < rOp.GetSIB()) || ((this->GetSIB() == rOp.GetSIB()) && (this->GetSpecFlag4() < rOp.GetSpecFlag4())));
else if (rOp.HasSIBByte()) return true; // no SIB < has SIB
else if (this->HasSIBByte()) return false; // no SIB < has SIB
else return MDLessReg(this->GetReg(), rOp.GetReg()); // no SIB bytes
case o_displ: if (this->HasSIBByte() && rOp.HasSIBByte())
return ((this->GetSIB() < rOp.GetSIB())
|| ((this->GetSIB() == rOp.GetSIB())
&& ((this->GetAddr() < rOp.GetAddr()) || ((this->GetAddr() == rOp.GetAddr()) && (this->GetSpecFlag4() < rOp.GetSpecFlag4())))));
else if (rOp.HasSIBByte()) return true; // no SIB < has SIB
else if (this->HasSIBByte()) return false; // no SIB < has SIB
else return ((this->GetAddr() < rOp.GetAddr())
|| ((this->GetAddr() == rOp.GetAddr()) && MDLessReg(this->GetReg(), rOp.GetReg()))); // no SIB bytes
case o_imm: return (this->GetImmedValue() < rOp.GetImmedValue());
case o_far: // fall through to o_near case
case o_near: return (this->GetAddr() < rOp.GetAddr());
case o_trreg: // fall through
case o_dbreg: // fall through
case o_crreg: // fall through
case o_fpreg: // fall through
case o_mmxreg: // fall through
case o_xmmreg: return (this->GetReg() < rOp.GetReg()); // no subword regs to deal with, don't need MDLessReg()
default: msg("ERROR: Unknown operand type in LessOp.\n"); return false;
}; // end switch (Opnd1.type)
}; // end of operator less-than
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment