00001 #ifndef LIBRARY_IDENTIFICATION_H
00002 #define LIBRARY_IDENTIFICATION_H
00003
00004 #include "sqlite3x.h"
00005
00006
00007
00008
00009
00010 namespace LibraryIdentification
00011 {
00012
00013 void generateLibraryIdentificationDataBase ( std::string databaseName, SgProject* project );
00014 void matchAgainstLibraryIdentificationDataBase( std::string databaseName, SgProject* project );
00015
00016
00017
00018 void libraryIdentificationDataBaseSupport( std::string databaseName, SgProject* project, bool generate_database );
00019
00020
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
00035 class FunctionIdentification
00036 {
00037 public:
00038
00039 FunctionIdentification(std::string dbName);
00040
00041
00042
00043 void createTables();
00044
00045
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
00051
00052
00053 bool get_function_match(library_handle & handle, const std::string s ) const;
00054
00055
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
00063 sqlite3x::sqlite3_connection con;
00064 };
00065
00066
00067 void set_function_match( const library_handle & handle, const std::string & data );
00068
00069
00070
00071 bool get_function_match( library_handle & handle, const std::string & data );
00072
00073 class FlattenAST: public AstSimpleProcessing
00074 {
00075 public:
00076
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
00088 class FlattenAST_SynthesizedAttribute
00089 {
00090 public:
00091
00092 std::vector<std::pair<unsigned char,unsigned char> > rangeList;
00093 };
00094
00095
00096
00097
00098 class FlattenAST_AndResetImmediateValues: public AstBottomUpProcessing<FlattenAST_SynthesizedAttribute>
00099 {
00100 public:
00101
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