00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __RoseBin_CompareAnalysis__
00010 #define __RoseBin_CompareAnalysis__
00011
00012
00013 #include <stdio.h>
00014 #include <iostream>
00015
00016 #include "RoseBin_support.h"
00017 #include "MyAstAttribute.h"
00018
00019 class RoseBin_CompareAnalysis : public AstSimpleProcessing{
00020 private:
00021 SgProject* project;
00022 SgAsmNode* globalBin;
00023
00024 bool main_prolog_end;
00025 std::string attributeName;
00026
00027
00028
00029
00030
00031
00032
00033 typedef std::map<std::string, std::pair<std::string,
00034 SgAsmValueExpression* > > local_vars_type;
00035 local_vars_type local_vars;
00036
00037 typedef std::map<std::string, std::pair<SgFunctionDeclaration*,
00038 SgAsmFunction*> > function_map_type;
00039 function_map_type function_map;
00040
00041 std::map<std::string, SgAsmFunction*> bin_funcs;
00042
00043 std::stack<SgExpression*> srcNodesTodo;
00044
00045
00046 MyAstAttribute* createAttribute(int val);
00047
00048
00049 int match_statements(int array_src_length,
00050 int array_bin_length,
00051 SgNode* src_statements[],
00052 SgAsmNode* bin_statements[],
00053 std::string *output);
00054
00055
00056 bool tookSrcNodeFromStack;
00057
00058 std::string resolveRegister(const RegisterDescriptor ®);
00059
00060 SgAsmValueExpression* valExp;
00061 SgAsmx86RegisterReferenceExpression* refExp_Left;
00062 SgAsmx86RegisterReferenceExpression* refExp_Right;
00063
00064
00065
00066
00067
00068 bool isFunctionCall(SgNode* srcNode,
00069 SgAsmNode* binNode,
00070 std::string *output,
00071 int &nodes_matched);
00072
00073 bool isReturnStmt(SgNode* srcNode,
00074 SgAsmNode* binNode,
00075 std::string *output,
00076 int &nodes_matched);
00077
00078 bool isVariableDeclaration(SgNode* srcNode,
00079 SgAsmNode* binNode,
00080 std::string *output,
00081 int &nodes_matched,
00082 int array_bin_length,
00083 int &bin_count,
00084 SgNode* src_statements[],
00085 SgAsmNode* bin_statements[],
00086 bool &increase_source);
00087
00088 bool isAssignOp(SgNode* srcNode,
00089 SgAsmNode* binNode,
00090 std::string *output,
00091 int &nodes_matched,
00092 int array_bin_length,
00093 int array_src_length,
00094 int &bin_count,
00095 int src_count,
00096 SgNode* src_statements[],
00097 SgAsmNode* bin_statements[],
00098 bool &increase_source);
00099
00100 bool isSgPlusPlus(SgNode* srcNode,
00101 SgAsmNode* binNode,
00102 std::string *output,
00103 int &nodes_matched);
00104
00105 std::string checkVariable(SgAsmValueExpression* rhs);
00106 void storeVariable(std::string val, std::string name,
00107 SgAsmValueExpression* binval);
00108
00109 std::string getVariableName(std::string val);
00110 SgAsmValueExpression* getVariableType(std::string val);
00111
00112
00113
00114 bool handleSourceExpression(SgExpression* expr,
00115 SgNode* src_statements[],
00116 SgAsmNode* bin_statements[],
00117 std::string *output,
00118 int &bin_count,
00119 int src_count,
00120 int &nodes_matched,
00121 int array_bin_length,
00122 int array_src_length,
00123 SgAssignOp* assign,
00124 bool dont_increase_bool_count);
00125
00126 SgExpression* isExpression( SgExpression* expr,
00127 SgNode* src_statements[],
00128 SgAsmNode* bin_statements[],
00129 std::string *output,
00130 int &bin_count,
00131 int src_count,
00132 int &nodes_matched,
00133 int array_bin_length,
00134 int array_src_length,
00135 bool& keep_binary_node);
00136
00137 std::string last_src_variable_left;
00138
00139 std::string resolve_binaryInstruction(SgAsmInstruction* mov,
00140 std::string *left,
00141 std::string *right,
00142 std::string varName);
00143
00144 bool existsVariable(std::string value);
00145
00146 bool isAnExpression(SgExpression* expr);
00147
00148 void pushOnStack(SgExpression* expr);
00149
00150 void resolve_bin_vardecl_or_assignment(bool &isVarDecl0,
00151 bool &isVarDecl1,
00152 bool &isAssign0,
00153 bool &isAssign1,
00154 SgAsmx86Instruction* mov
00155 );
00156
00157 public:
00158
00159
00160 RoseBin_CompareAnalysis(SgProject *pr, SgAsmNode* global);
00161
00162
00163 void visit(SgNode* node);
00164
00165
00166 void run();
00167
00168
00169
00170 void create_map_functions();
00171
00172
00173
00174 void checkFunctions(std::string name,
00175 SgFunctionDeclaration* funcDecl,
00176 SgAsmFunction* binDecl);
00177
00178
00179 bool instruction_filter(SgAsmStatement* stat, std::string name,
00180 std::string *output);
00181
00182
00183 };
00184
00185 #endif
00186