ROSE  0.9.9.109
libraryIdentification.h
1 #ifndef LIBRARY_IDENTIFICATION_H
2 #define LIBRARY_IDENTIFICATION_H
3 
4 #include "sqlite3x.h"
5 
6 // #include "functionIdentification.h"
7 // #include "rose.h"
8 // #include "libraryIdentification.h"
9 
10 namespace LibraryIdentification
11  {
12  // This is an implementation of Fast Library Identification and Recognition Technology
13  void generateLibraryIdentificationDataBase ( std::string databaseName, SgProject* project );
14  void matchAgainstLibraryIdentificationDataBase( std::string databaseName, SgProject* project );
15 
16  // Low level factored code to support generateLibraryIdentificationDataBase() and
17  // matchAgainstLibraryIdentificationDataBase() interface functions.
18  void libraryIdentificationDataBaseSupport( std::string databaseName, SgProject* project, bool generate_database );
19 
20  // Debugging support
21  void testForDuplicateEntries( const std::vector<SgUnsignedCharList> & functionOpcodeList );
22 
24  {
25  public:
26  std::string filename;
27  std::string function_name;
28  size_t begin;
29  size_t end;
30 
31  library_handle() {}
32  };
33 
34  // Copied from Andreas' code in functionIdentification.h
36  {
37  public:
38 
39  FunctionIdentification(std::string dbName);
40 
41  //Make sure that all the tables are defined in the function identification
42  //database
43  void createTables();
44 
45  //Add an entry to store the pair <library_handle,string> in the database
46  void set_function_match( const library_handle & handle, const std::string s );
47  void set_function_match( const library_handle & handle, const SgUnsignedCharList & opcode_vector);
48  void set_function_match( const library_handle & handle, const unsigned char* str, size_t str_length );
49 
50  // Return the library_handle matching string from the database. bool false
51  // is returned if no such match was found, true otherwise.
52  // This can't be const (some sqlite problem).
53  bool get_function_match(library_handle & handle, const std::string s ) const;
54 
55  // Make these const functions, since they are ment to be const.
56  bool get_function_match(library_handle & handle, const SgUnsignedCharList & opcode_vector) const;
57  bool get_function_match(library_handle & handle, const unsigned char* str, size_t str_length );
58 
59  private:
60  std::string database_name;
61 
62  // SQLite database handle
63  sqlite3x::sqlite3_connection con;
64  };
65 
66  // Add an entry to store the pair <library_handle,string> in the database
67  void set_function_match( const library_handle & handle, const std::string & data );
68 
69  // Return the library_handle matching string from the database. bool false
70  // is returned if no such match was found, true otherwise.
71  bool get_function_match( library_handle & handle, const std::string & data );
72 
74  {
75  public:
76  // Save flattended AST in reference initialized at construction.
77  SgUnsignedCharList & data;
78 
79  size_t startAddress;
80  size_t endAddress;
81 
82  FlattenAST(SgUnsignedCharList & s) : data(s),startAddress(0),endAddress(0) {}
83 
84  void visit(SgNode* n);
85  };
86 
87  // DQ (7/11/2009): We need to use a synthesized attribute to gather the list of bit ranges
89  {
90  public:
91  // Save the list of ranges of where offsets are stored in each instruction's opcode (used to represent immediates).
92  std::vector<std::pair<unsigned char,unsigned char> > rangeList;
93  };
94 
95  // DQ (7/11/2009): We need to use a synthesized attribute to gather the list of bit ranges form any nested
96  // SgAsmExpression IR nodes where the opcode stores values (offsets) used to store immediate values (coded
97  // values in the instruction's op-codes.
98  class FlattenAST_AndResetImmediateValues: public AstBottomUpProcessing<FlattenAST_SynthesizedAttribute>
99  {
100  public:
101  // Save flattended AST in reference initialized at construction.
102  SgUnsignedCharList & data;
103 
104  size_t startAddress;
105  size_t endAddress;
106 
107  FlattenAST_AndResetImmediateValues(SgUnsignedCharList & s) : data(s),startAddress(0),endAddress(0) {}
108 
110  };
111 
113  SgUnsignedCharList generateOpCodeVector(SgAsmInterpretation* asmInterpretation, SgNode* node, size_t & startOffset, size_t & endOffset);
114 
115  void write_database ( FunctionIdentification & ident, const std::string & fileName, const std::string & functionName, size_t startOffset, size_t endOffset, const SgUnsignedCharList & s );
116  bool match_database ( const FunctionIdentification & ident, std::string & fileName, std::string & functionName, size_t & startOffset, size_t & endOffset, const SgUnsignedCharList & s );
117 
118 #if 0
119  void set_function_match( library_handle, std::string );
121 
124  bool get_function_match(library_handle&, std::string);
125 #endif
126 
127  }
128 #endif
Class for traversing the AST.
FlattenAST_SynthesizedAttribute evaluateSynthesizedAttribute(SgNode *n, SynthesizedAttributesList childAttributes)
pure virtual function which must be implemented to compute the synthesized attribute at a node...
Attribute Evaluator for synthesized attributes.
void visit(SgNode *n)
this method is called at every traversed node.
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:8322
This class represents a source project, with a list of SgFile objects and global information about th...
Represents an interpretation of a binary container.