ROSE  0.9.10.47
LibraryInfo.h
1 #ifndef LIBRARY_INFO_H
2 #define LIBRARY_INFO_H
3 
4 #include <BinaryAstHash.h>
5 #include <time.h>
6 #include "Combinatorics.h"
7 
16 namespace LibraryIdentification
17 {
19  {
20  public:
35  LibraryInfo(const std::string& ilibName, const std::string& ilibVersion, const std::string& ilibHash, SgAsmExecutableFileFormat::InsSetArchitecture iarchitecture) :
36  libName(ilibName), libVersion(ilibVersion), libHash(ilibHash), architecture(iarchitecture) {
37  analysisTime = time(NULL);
38  };
39 
40 
56  LibraryInfo(const std::string& ilibName, const std::string& ilibVersion, SgAsmGenericFile* libraryFile) :
57  libName(ilibName), libVersion(ilibVersion)
58  {
59  SgAsmGenericHeader* genericHeader = libraryFile->get_header(SgAsmExecutableFileFormat::ExecFamily::FAMILY_ELF);
60  SgAsmElfFileHeader* elfHeader = dynamic_cast<SgAsmElfFileHeader*>(genericHeader);
61  ASSERT_require(elfHeader != NULL);
62 
63  //TODO: Check that we have a name and version, if not, see if
64  //the library is dynamic and they can be discovered
65 
66 
67  //Get the architecture
68  architecture = elfHeader->get_isa();
69 
70  //Generate hash of library contents
71  //Should make the hash optional via factory method in Combinatorics.h
73 
74  SgFileContentList content = libraryFile->content();
75  fnvHash.append(&content[0], content.size());
76  libHash = fnvHash.toString();
77  }
78 
87  LibraryInfo(const std::string& ilibHash) : libHash(ilibHash) { };
88 
89 
90  friend bool operator<(const LibraryInfo& lhs,const LibraryInfo& rhs)
91  {
92  return lhs.libHash < rhs.libHash;
93  }
94 
95 
103  {
104  return LibraryInfo("UNKNOWN", "UNKNOWN", "UNKNOWN", SgAsmExecutableFileFormat::InsSetArchitecture::ISA_UNSPECIFIED);
105  };
106 
107 
108 
109 
110  // TODO: add accessors
111  // private:
112  //@brief The name of the library
113  std::string libName;
114 
115  //@brief The version of the library
116  std::string libVersion;
117 
118  //@brief A hash that should uniquely identify the library
119  std::string libHash;
120 
121  //@brief Enumeration of instruction set library was build for
123 
124  //@brief The time when this library was processed
125  time_t analysisTime;
126 
127  };
128 
129 }
130 
131 
132 
133 #endif //LIBRARY_INFO
const SgFileContentList & content()
Property: Entire file contents.
Represents the file header of an ELF binary container.
SgAsmGenericFormat::InsSetArchitecture get_isa() const
Property: Machine for which this header and its sections, etc.
InsSetArchitecture
Instruction sets organized by families.
static LibraryInfo getUnknownLibraryInfo()
getUnknownLibraryInfo
Definition: LibraryInfo.h:102
Fowler-Noll-Vo hashing using the Hasher interface.
Base class for container file headers.
static std::string toString(const Digest &)
Convert a digest to a hexadecimal string.
LibraryInfo(const std::string &ilibName, const std::string &ilibVersion, SgAsmGenericFile *libraryFile)
LibraryInfo.
Definition: LibraryInfo.h:56
LibraryInfo(const std::string &ilibName, const std::string &ilibVersion, const std::string &ilibHash, SgAsmExecutableFileFormat::InsSetArchitecture iarchitecture)
LibraryInfo.
Definition: LibraryInfo.h:35
void append(const uint8_t *message, size_t messageSize)
Insert data into the digest.
LibraryInfo(const std::string &ilibHash)
LibraryInfo.
Definition: LibraryInfo.h:87
Base class for binary files.
SgAsmGenericHeader * get_header(SgAsmGenericFormat::ExecFamily)
Returns the header for the specified format.