libraryIdentification.h

Go to the documentation of this file.
00001 #ifndef LIBRARY_IDENTIFICATION_H
00002 #define LIBRARY_IDENTIFICATION_H
00003 
00004 #include "sqlite3x.h"
00005 
00006 // #include "functionIdentification.h"
00007 // #include "rose.h"
00008 // #include "libraryIdentification.h"
00009 
00010 namespace LibraryIdentification
00011    {
00012   // This is an implementation of Fast Library Identification and Recognition Technology
00013      void generateLibraryIdentificationDataBase    ( std::string databaseName, SgProject* project );
00014      void matchAgainstLibraryIdentificationDataBase( std::string databaseName, SgProject* project );
00015 
00016   // Low level factored code to support generateLibraryIdentificationDataBase() and 
00017   // matchAgainstLibraryIdentificationDataBase() interface functions.
00018      void libraryIdentificationDataBaseSupport( std::string databaseName, SgProject* project, bool generate_database );
00019 
00020   // Debugging support
00021      void testForDuplicateEntries( const std::vector<SgUnsignedCharList> & functionOpcodeList );
00022 
00023      class library_handle
00024         {
00025           public:
00026                std::string filename;
00027                std::string function_name;
00028                size_t begin;
00029                size_t end;
00030 
00031                library_handle() {}              
00032         };
00033 
00034   // Copied from Andreas' code in functionIdentification.h
00035      class FunctionIdentification
00036      {
00037        public:
00038 
00039          FunctionIdentification(std::string dbName);
00040 
00041          //Make sure that all the tables are defined in the function identification
00042          //database
00043          void createTables();
00044 
00045          //Add an entry to store the pair <library_handle,string> in the database
00046          void set_function_match( const library_handle & handle, const std::string s );
00047          void set_function_match( const library_handle & handle, const SgUnsignedCharList & opcode_vector);
00048          void set_function_match( const library_handle & handle, const unsigned char* str, size_t str_length );
00049 
00050       // Return the library_handle matching string from the database. bool false
00051       // is returned if no such match was found, true otherwise.
00052       // This can't be const (some sqlite problem).
00053          bool get_function_match(library_handle & handle, const std::string s ) const;
00054 
00055       // Make these const functions, since they are ment to be const.
00056          bool get_function_match(library_handle & handle, const SgUnsignedCharList & opcode_vector) const;
00057          bool get_function_match(library_handle & handle, const unsigned char* str, size_t str_length );
00058 
00059        private:
00060          std::string database_name;
00061 
00062       // SQLite database handle
00063          sqlite3x::sqlite3_connection con;
00064      };
00065 
00066   // Add an entry to store the pair <library_handle,string> in the database
00067      void set_function_match( const library_handle & handle, const std::string & data );
00068 
00069   // Return the library_handle matching string from the database. bool false
00070   // is returned if no such match was found, true otherwise.
00071      bool get_function_match( library_handle & handle, const std::string & data );
00072 
00073      class FlattenAST: public AstSimpleProcessing
00074         {
00075           public:
00076             // Save flattended AST in reference initialized at construction.
00077                SgUnsignedCharList & data;
00078 
00079                size_t startAddress;
00080                size_t endAddress;
00081 
00082                FlattenAST(SgUnsignedCharList & s) : data(s),startAddress(0),endAddress(0) {}
00083 
00084                void visit(SgNode* n);
00085         };
00086 
00087   // DQ (7/11/2009): We need to use a synthesized attribute to gather the list of bit ranges 
00088      class FlattenAST_SynthesizedAttribute
00089         {
00090           public:
00091             // Save the list of ranges of where offsets are stored in each instruction's opcode (used to represent immediates).
00092                std::vector<std::pair<unsigned char,unsigned char> > rangeList;
00093         };
00094 
00095   // DQ (7/11/2009): We need to use a synthesized attribute to gather the list of bit ranges form any nested 
00096   // SgAsmExpression IR nodes where the opcode stores values (offsets) used to store immediate values (coded 
00097   // values in the instruction's op-codes.
00098      class FlattenAST_AndResetImmediateValues: public AstBottomUpProcessing<FlattenAST_SynthesizedAttribute>
00099         {
00100           public:
00101             // Save flattended AST in reference initialized at construction.
00102                SgUnsignedCharList & data;
00103 
00104                size_t startAddress;
00105                size_t endAddress;
00106 
00107                FlattenAST_AndResetImmediateValues(SgUnsignedCharList & s) : data(s),startAddress(0),endAddress(0) {}
00108 
00109                FlattenAST_SynthesizedAttribute evaluateSynthesizedAttribute ( SgNode* n, SynthesizedAttributesList childAttributes );
00110         };
00111 
00113      SgUnsignedCharList generateOpCodeVector(SgAsmInterpretation* asmInterpretation, SgNode* node, size_t & startOffset, size_t & endOffset);
00114 
00115      void write_database ( FunctionIdentification & ident, const std::string & fileName, const std::string & functionName, size_t startOffset, size_t endOffset, const SgUnsignedCharList & s );
00116      bool match_database ( const FunctionIdentification & ident, std::string & fileName, std::string & functionName, size_t & startOffset, size_t & endOffset, const SgUnsignedCharList & s );
00117 
00118 #if 0
00120       void set_function_match( library_handle, std::string );
00121 
00124       bool get_function_match(library_handle&, std::string);
00125 #endif
00126 
00127    }
00128 #endif

Generated on Sat May 19 00:53:06 2012 for ROSE by  doxygen 1.4.7