00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __RoseBin_Emulate__
00009 #define __RoseBin_Emulate__
00010
00011 #include "RoseBin_DataFlowAbstract.h"
00012
00013 class RoseBin_Emulate : public RoseBin_DataFlowAbstract{
00014 private:
00015
00016 rose_hash::unordered_map <uint64_t, uint64_t> memory;
00017
00018 uint64_t rax;
00019 uint64_t rbx;
00020 uint64_t rcx;
00021 uint64_t rdx;
00022 uint64_t rdi;
00023 uint64_t rsi;
00024 uint64_t rsp;
00025 uint64_t rbp;
00026
00027 bool ZF;
00028
00029
00030 bool isCode64bit;
00031
00032 void assignMemory(uint64_t position, uint64_t value);
00033 uint64_t getMemory(uint64_t position);
00034
00035
00036
00037 void assignRegister(std::pair<X86RegisterClass, int> code,
00038 RoseBin_support::X86PositionInRegister pos,
00039 uint8_t &b_val,
00040 uint16_t &w_val,
00041 uint32_t &dw_val,
00042 uint64_t &qw_val);
00043
00044 void assignRegister(std::pair<X86RegisterClass, int> code,
00045 uint64_t &qw_val);
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 void clearRegisters();
00056 uint64_t getRegister(std::pair<X86RegisterClass, int> code);
00057
00058 std::string printRegister(std::string text, uint64_t reg);
00059
00060 uint64_t getRandomValue(int val);
00061
00062
00063 void getRegister_val(std::pair<X86RegisterClass, int> code,
00064 RoseBin_support::X86PositionInRegister pos,
00065 uint8_t &b_val,
00066 uint16_t &w_val,
00067 uint32_t &dw_val,
00068 uint64_t &qw_val);
00069
00070 void getRegister_val(std::pair<X86RegisterClass, int> code,
00071 RoseBin_support::X86PositionInRegister pos,
00072 uint64_t &qw_val);
00073
00074
00075
00076 public:
00077
00078 RoseBin_Emulate(GraphAlgorithms* algo):RoseBin_DataFlowAbstract(algo) {}
00079 ~RoseBin_Emulate() {}
00080
00081 bool run(std::string& name, SgGraphNode* node, SgGraphNode* before);
00082 std::string evaluateRegisters();
00083 bool evaluateInstruction( SgAsmx86Instruction* inst, std::string& operands) ;
00084
00085 bool runEdge( SgGraphNode* node, SgGraphNode* next) {
00086 return false;
00087 }
00088
00089 void init(RoseBin_Graph* vg) {
00090 vizzGraph = vg;
00091 rax = 0xFFFFFFFF;
00092 rbx = 0xFFFFFFFF;
00093 rcx = 0xFFFFFFFF;
00094 rdx = 0xFFFFFFFF;
00095 rdi = 0xFFFFFFFF;
00096 rsi = 0xFFFFFFFF;
00097 rsp = 0xFFFFFFFF;
00098 rbp = 0xFFFFFFFF;
00099 isCode64bit=false;
00100 ZF=false;
00101 }
00102
00103 };
00104
00105 #endif
00106