ROSE  0.11.2.0
LibraryInfo.h
1 #ifndef LIBRARY_INFO_H
2 #define LIBRARY_INFO_H
3 #include <rosePublicConfig.h>
4 #ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT
5 
6 #include <BinaryAstHash.h>
7 #include <time.h>
8 #include "Combinatorics.h"
9 
18 namespace LibraryIdentification
19 {
20  const std::string unknownLibraryName = "UNKNOWN";
21  const std::string multiLibraryName = "MULTIPLE_LIBS";
22 
23 
25  {
26  public:
41  LibraryInfo(const std::string& ilibName, const std::string& ilibVersion, const std::string& ilibHash, const std::string& iarchitecture) :
42  libName(ilibName), libVersion(ilibVersion), libHash(ilibHash), architecture(iarchitecture) {
43  analysisTime = time(NULL);
44  };
45 
46 
64  /* LibraryInfo(const std::string& ilibName, const std::string& ilibVersion, SgAsmGenericFile* libraryFile) :
65  libName(ilibName), libVersion(ilibVersion)
66  {
67  SgAsmGenericHeader* genericHeader = libraryFile->get_header(SgAsmExecutableFileFormat::ExecFamily::FAMILY_ELF);
68  SgAsmElfFileHeader* elfHeader = dynamic_cast<SgAsmElfFileHeader*>(genericHeader);
69  ASSERT_require(elfHeader != NULL);
70 
71  //Get the architecture
72  //SgAsmExecutableFileFormat::InsSetArchitecture enumArchitecture = elfHeader->get_isa();
73  architecture = "x86"; //stringify::SgAsmExecutableFileFormat::InsSetArchitecture(enumArchitecture);
74 
75  //Generate hash of library contents
76  //Should make the hash optional via factory method in Combinatorics.h
77  Rose::Combinatorics::HasherFnv fnvHash;
78 
79  SgFileContentList content = libraryFile->content();
80  fnvHash.append(&content[0], content.size());
81  libHash = fnvHash.toString();
82  }
83  */
92  LibraryInfo(const std::string& ilibHash) : libName(unknownLibraryName), libVersion(unknownLibraryName), libHash(ilibHash), architecture(unknownLibraryName) { };
93 
94 
100  friend bool operator<(const LibraryInfo& lhs,const LibraryInfo& rhs)
101  {
102  return lhs.libHash < rhs.libHash;
103  }
104 
105 
113  {
114  return LibraryInfo(unknownLibraryName, unknownLibraryName, unknownLibraryName, unknownLibraryName);
115  };
116 
126  {
127  return LibraryInfo(multiLibraryName, multiLibraryName, multiLibraryName, multiLibraryName);
128  };
129 
130 
136  std::string toString()
137  {
138  return libName + "." + libVersion;
139  }
140 
141 
142 
143  // TODO: add accessors
144  // private:
145  //@brief The name of the library
146  std::string libName;
147 
148  //@brief The version of the library
149  std::string libVersion;
150 
151  //@brief A hash that should uniquely identify the library
152  std::string libHash;
153 
154  //@brief Enumeration of instruction set library was build for
155  std::string architecture;
156 
157  //@brief The time when this library was processed
158  time_t analysisTime;
159 
160  };
161 
162 }
163 
164 #endif
165 #endif
friend bool operator<(const LibraryInfo &lhs, const LibraryInfo &rhs)
operator<
Definition: LibraryInfo.h:100
std::string toString()
toString
Definition: LibraryInfo.h:136
static LibraryInfo getMultiLibraryInfo()
getMultiLibraryInfo
Definition: LibraryInfo.h:125
static LibraryInfo getUnknownLibraryInfo()
getUnknownLibraryInfo
Definition: LibraryInfo.h:112
LibraryInfo(const std::string &ilibName, const std::string &ilibVersion, const std::string &ilibHash, const std::string &iarchitecture)
LibraryInfo.
Definition: LibraryInfo.h:41
LibraryInfo(const std::string &ilibHash)
LibraryInfo.
Definition: LibraryInfo.h:92