ROSE  0.11.82.0
libraryIdentification.h
1 #ifndef LIBRARY_IDENTIFICATION_H
2 #define LIBRARY_IDENTIFICATION_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_LIBRARY_IDENTIFICATION
5 
6 #include "LibraryInfo.h"
7 #include "FunctionInfo.h"
8 
9 // Deprecated [Robb Matzke 2022-01-20]: because its not in the ::Rose namespace.
10 //
11 // Identification and recognition of library functions.
12 //
13 // This namespace encapsulates functions for FLIRT-like (Fast Library Identification and Recognition Technology) functionality
14 // for ROSE binary analysis.
15 namespace LibraryIdentification {
16 
17 // Deprecated [Robb Matzke 2022-01-20]: because name violates convention
18 enum DUPLICATE_OPTION {
19  UNKNOWN,
20  COMBINE, // Allow both hashes to exist.
21  REPLACE, // Replace the old function with this new function. This will eliminate ALL old functions with the same hash.
22  NO_ADD // Do not add the function, leave the old functions in the database.
23 };
24 
25 // Deprecated [Robb Matzke 2022-01-20]
26 //
27 // Mapping from library to information about contained functions.
28 //
29 // This is used as the type to list which functions are found in which libraries from @ref matchLibraryIdentificationDataBase.
30 //
31 // Functions that are not found in any library, will be placed in the "UNKNOWN" bin.
32 typedef std::map<LibraryInfo, std::set<FunctionInfo> > LibToFuncsMap;
33 
34 // Deprecated [Robb Matzke 2022-01-20]
35 //
36 // Hash library functions and insert into database.
37 //
38 // This function takes a binary specimen (presumeably a library) and hashes every function, in it. It then inserts the
39 // library and functions into a new SQLite database. If the specimen contains debug information, the resulting database will
40 // contain information that can later identify functions in stripped libraries.
41 //
42 // @param[in] databaseName Filename of the database to create/access
43 // @param[in] libraryName Library names cannot be discovered from all library types, so pass in name.
44 // @param[in] libraryVersion Library version, same problem
45 // @param[in] libraryHash Unique hash identifing the libary. Partitioner can't generate it
46 // @param[in] partitioner The main ROSE binary anlysis object, contains all functions, code, etc.
47 // @param[in] dupOption tells what to do with duplicate functions
48 void generateLibraryIdentificationDataBase(const std::string& databaseName,
49  const std::string& libraryName,
50  const std::string& libraryVersion,
51  const std::string& libraryHash,
53  enum DUPLICATE_OPTION dupOption = COMBINE)
54  ROSE_DEPRECATED("use Rose::BinaryAnalysis::LibraryIdentification::insertLibrary instead");
55 
56 // Deprecated [Robb Matzke 2022-01-20]
57 //
58 // Attempt to match specimen functions to database functions.
59 //
60 // This function attempts to match functions in a binary specimen to library functions in the database. It will attempt to
61 // match every function defined in the project to a library function.
62 //
63 // It returns a LibToFuncsMap that contains every function defined in the project in the following form:
64 // Library->set(Function). Functions that could not be matched in the database are found in the "UNKNOWN" library.
65 //
66 // @param[in] databaseName Filename of the database to create/access
67 // @param[in] partitioner Binary partitioner has the functions to write or find
68 // @return libToFuncsMap Libraries->set(Functions) unmatched functions under "UNKNOWN", multimatched functions returned in
69 // "MULTIPLE_LIBS"
70 LibToFuncsMap matchLibraryIdentificationDataBase(const std::string& databaseName,
71  const Rose::BinaryAnalysis::Partitioner2::Partitioner& partitioner)
72  ROSE_DEPRECATED("use Rose::BinaryAnalysis::LibraryIdentification::search in a loop instead");
73 
74 // Deprecated [Robb Matzke 2022-01-20]: but not marked as such because the implementations of the two functions above still
75 // depend on it.
76 //
77 // Private helper function for adding idents to the libToFuncsMap.
78 void insertFunctionToMap(LibToFuncsMap& libToFuncsMap, // the map to insert into
79  const LibraryInfo& libraryInfo, // library to insert as key
80  const FunctionInfo& functionInfo); // function to insert as key
81 
82 } // namespace
83 
84 #endif
85 #endif
STL namespace.
Main namespace for the ROSE library.
Partitions instructions into basic blocks and functions.
Definition: Partitioner.h:289
const char * DUPLICATE_OPTION(int64_t)
Convert LibraryIdentification::DUPLICATE_OPTION enum constant to a string.