ROSE  0.9.11.56
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 {
18  const std::string unknownLibraryName = "UNKNOWN";
19  const std::string multiLibraryName = "MULTIPLE_LIBS";
20 
21 
23  {
24  public:
39  LibraryInfo(const std::string& ilibName, const std::string& ilibVersion, const std::string& ilibHash, const std::string& iarchitecture) :
40  libName(ilibName), libVersion(ilibVersion), libHash(ilibHash), architecture(iarchitecture) {
41  analysisTime = time(NULL);
42  };
43 
44 
62  /* LibraryInfo(const std::string& ilibName, const std::string& ilibVersion, SgAsmGenericFile* libraryFile) :
63  libName(ilibName), libVersion(ilibVersion)
64  {
65  SgAsmGenericHeader* genericHeader = libraryFile->get_header(SgAsmExecutableFileFormat::ExecFamily::FAMILY_ELF);
66  SgAsmElfFileHeader* elfHeader = dynamic_cast<SgAsmElfFileHeader*>(genericHeader);
67  ASSERT_require(elfHeader != NULL);
68 
69  //Get the architecture
70  //SgAsmExecutableFileFormat::InsSetArchitecture enumArchitecture = elfHeader->get_isa();
71  architecture = "x86"; //stringify::SgAsmExecutableFileFormat::InsSetArchitecture(enumArchitecture);
72 
73  //Generate hash of library contents
74  //Should make the hash optional via factory method in Combinatorics.h
75  Rose::Combinatorics::HasherFnv fnvHash;
76 
77  SgFileContentList content = libraryFile->content();
78  fnvHash.append(&content[0], content.size());
79  libHash = fnvHash.toString();
80  }
81  */
90  LibraryInfo(const std::string& ilibHash) : libName(unknownLibraryName), libVersion(unknownLibraryName), libHash(ilibHash), architecture(unknownLibraryName) { };
91 
92 
98  friend bool operator<(const LibraryInfo& lhs,const LibraryInfo& rhs)
99  {
100  return lhs.libHash < rhs.libHash;
101  }
102 
103 
111  {
112  return LibraryInfo(unknownLibraryName, unknownLibraryName, unknownLibraryName, unknownLibraryName);
113  };
114 
124  {
125  return LibraryInfo(multiLibraryName, multiLibraryName, multiLibraryName, multiLibraryName);
126  };
127 
128 
134  std::string toString()
135  {
136  return libName + "." + libVersion;
137  }
138 
139 
140 
141  // TODO: add accessors
142  // private:
143  //@brief The name of the library
144  std::string libName;
145 
146  //@brief The version of the library
147  std::string libVersion;
148 
149  //@brief A hash that should uniquely identify the library
150  std::string libHash;
151 
152  //@brief Enumeration of instruction set library was build for
153  std::string architecture;
154 
155  //@brief The time when this library was processed
156  time_t analysisTime;
157 
158  };
159 
160 }
161 
162 
163 
164 #endif //LIBRARY_INFO
friend bool operator<(const LibraryInfo &lhs, const LibraryInfo &rhs)
operator<
Definition: LibraryInfo.h:98
std::string toString()
toString
Definition: LibraryInfo.h:134
static LibraryInfo getMultiLibraryInfo()
getMultiLibraryInfo
Definition: LibraryInfo.h:123
static LibraryInfo getUnknownLibraryInfo()
getUnknownLibraryInfo
Definition: LibraryInfo.h:110
LibraryInfo(const std::string &ilibName, const std::string &ilibVersion, const std::string &ilibHash, const std::string &iarchitecture)
LibraryInfo.
Definition: LibraryInfo.h:39
LibraryInfo(const std::string &ilibHash)
LibraryInfo.
Definition: LibraryInfo.h:90