ROSE  0.9.10.168
FunctionInfo.h
1 #ifndef FUNCTION_INFO_H
2 #define FUNCTION_INFO_H
3 
4 #include <BinaryAstHash.h>
5 #include "Combinatorics.h"
6 #include <Partitioner2/Partitioner.h>
7 #include <Partitioner2/Function.h>
16 namespace LibraryIdentification
17 {
23  {
24  public:
38  FunctionInfo(const std::string& ifuncName, const std::string& ifuncHash, const std::string& ilibHash) :
39  funcName(ifuncName), funcHash(ifuncHash), libHash(ilibHash), binaryFunction() {};
40 
58  funcName(function->name()), libHash(ilibHash), binaryFunction(function)
59  {
60  initializeHash(partitioner, function);
61  }
62 
63 
79  funcName(function->name()), libHash(), binaryFunction(function)
80  {
81  initializeHash(partitioner, function);
82  }
83 
100  funcName(function->name()), libHash(libInfo.libHash), binaryFunction(function)
101  {
102  initializeHash(partitioner, function);
103  }
104 
114  FunctionInfo(const std::string& ifuncHash) :
115  funcName(""), funcHash(ifuncHash), libHash(""), binaryFunction() {};
116 
127  FunctionInfo(const std::string& ifuncHash, Rose::BinaryAnalysis::Partitioner2::Function::Ptr function) :
128  funcHash(ifuncHash), libHash(""), binaryFunction(function) {
129  if(function != 0) {
130  funcName = function->name();
131  }
132  };
133 
134  friend bool operator<(const FunctionInfo& lhs, const FunctionInfo& rhs)
135  {
136  return lhs.funcHash < rhs.funcHash;
137  }
138 
139  bool operator==(const FunctionInfo& rhs)
140  {
141  if(funcName == rhs.funcName &&
142  funcHash == rhs.funcHash &&
143  libHash == rhs.libHash)
144  {
145  return true;
146  }
147  return false;
148 
149  }
150 
151 
152 
153  //@brief The name of the function
154  std::string funcName;
155 
156  //@brief A hash that should uniquely identify the function
157  std::string funcHash;
158 
159  //@brief A hash that should uniquely identify the library the
160  //function belongs to. It should already be in the database.
161  std::string libHash;
162 
163  //@brief A pointer to the binary version of this function IF
164  //IT'S AVAILIBLE. THIS IS LIKELY TO BE NULL
166 
167  static std::string getHash(const Rose::BinaryAnalysis::Partitioner2::Partitioner& partitioner, Rose::BinaryAnalysis::Partitioner2::Function::Ptr function)
168  {
170  Rose::Combinatorics::Hasher& hasher = dynamic_cast<Rose::Combinatorics::Hasher&>(fnv);
171  Rose::BinaryAnalysis::AstHash astHash(hasher);
172 
173  const std::set<rose_addr_t>& basicBlocks = function->basicBlockAddresses();
174 
175  for(std::set<rose_addr_t>::const_iterator bbIt = basicBlocks.begin(); bbIt != basicBlocks.end(); ++bbIt)
176  {
178  ROSE_ASSERT(bb != NULL);
179  astHash.appendBasicBlock(bb);
180 
181  }
182 
183  return fnv.toString();
184  }
185 
186 
187  private:
189  { //Ordered set, so it should always be the same order...
190  funcHash = getHash(partitioner, function);
191 
192  }
193 
194  };
195 
196 }
197 
198 
199 
200 #endif //FUNCTION_INFO
FunctionInfo(const std::string &ifuncHash, Rose::BinaryAnalysis::Partitioner2::Function::Ptr function)
FunctionInfo.
Definition: FunctionInfo.h:127
class FunctionInfo Combines all the information to uniquely identify a single function in one object...
Definition: FunctionInfo.h:22
BasicBlock::Ptr basicBlockExists(rose_addr_t startVa) const
Determines whether a discovered basic block exists in the CFG/AUM.
FunctionInfo(const Rose::BinaryAnalysis::Partitioner2::Partitioner &partitioner, Rose::BinaryAnalysis::Partitioner2::Function::Ptr function)
FunctionInfo.
Definition: FunctionInfo.h:78
Reference-counting smart pointer.
Definition: SharedPointer.h:34
Fowler-Noll-Vo hashing using the Hasher interface.
static std::string toString(const Digest &)
Convert a digest to a hexadecimal string.
FunctionInfo(const Rose::BinaryAnalysis::Partitioner2::Partitioner &partitioner, Rose::BinaryAnalysis::Partitioner2::Function::Ptr function, const std::string &ilibHash)
FunctionInfo.
Definition: FunctionInfo.h:57
A simple traversal that builds up a hash code for the AST.
Definition: BinaryAstHash.h:29
FunctionInfo(const Rose::BinaryAnalysis::Partitioner2::Partitioner &partitioner, Rose::BinaryAnalysis::Partitioner2::Function::Ptr function, LibraryInfo &libInfo)
FunctionInfo.
Definition: FunctionInfo.h:99
FunctionInfo(const std::string &ifuncName, const std::string &ifuncHash, const std::string &ilibHash)
FunctionInfo.
Definition: FunctionInfo.h:38
Partitions instructions into basic blocks and functions.
Definition: Partitioner.h:293
FunctionInfo(const std::string &ifuncHash)
FunctionInfo.
Definition: FunctionInfo.h:114