ROSE  0.11.2.0
FunctionInfo.h
1 #ifndef FUNCTION_INFO_H
2 #define FUNCTION_INFO_H
3 #include <rosePublicConfig.h>
4 #ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT
5 
6 #include <BinaryAstHash.h>
7 #include "Combinatorics.h"
8 #include <Partitioner2/Partitioner.h>
9 #include <Partitioner2/Function.h>
18 namespace LibraryIdentification
19 {
25  {
26  public:
40  FunctionInfo(const std::string& ifuncName, const std::string& ifuncHash, const std::string& ilibHash) :
41  funcName(ifuncName), funcHash(ifuncHash), libHash(ilibHash), binaryFunction() {};
42 
60  funcName(function->name()), libHash(ilibHash), binaryFunction(function)
61  {
62  initializeHash(partitioner, function);
63  }
64 
65 
81  funcName(function->name()), libHash(), binaryFunction(function)
82  {
83  initializeHash(partitioner, function);
84  }
85 
102  funcName(function->name()), libHash(libInfo.libHash), binaryFunction(function)
103  {
104  initializeHash(partitioner, function);
105  }
106 
116  FunctionInfo(const std::string& ifuncHash) :
117  funcName(""), funcHash(ifuncHash), libHash(""), binaryFunction() {};
118 
129  FunctionInfo(const std::string& ifuncHash, Rose::BinaryAnalysis::Partitioner2::Function::Ptr function) :
130  funcHash(ifuncHash), libHash(""), binaryFunction(function) {
131  if(function != 0) {
132  funcName = function->name();
133  }
134  };
135 
136  friend bool operator<(const FunctionInfo& lhs, const FunctionInfo& rhs)
137  {
138  return lhs.funcHash < rhs.funcHash;
139  }
140 
141  bool operator==(const FunctionInfo& rhs)
142  {
143  if(funcName == rhs.funcName &&
144  funcHash == rhs.funcHash &&
145  libHash == rhs.libHash)
146  {
147  return true;
148  }
149  return false;
150 
151  }
152 
153 
154 
155  //@brief The name of the function
156  std::string funcName;
157 
158  //@brief A hash that should uniquely identify the function
159  std::string funcHash;
160 
161  //@brief A hash that should uniquely identify the library the
162  //function belongs to. It should already be in the database.
163  std::string libHash;
164 
165  //@brief A pointer to the binary version of this function IF
166  //IT'S AVAILIBLE. THIS IS LIKELY TO BE NULL
168 
169  static std::string getHash(const Rose::BinaryAnalysis::Partitioner2::Partitioner& partitioner, Rose::BinaryAnalysis::Partitioner2::Function::Ptr function)
170  {
171  boost::shared_ptr<Rose::Combinatorics::Hasher> hasher = Rose::Combinatorics::Hasher::HasherFactory::Instance().createHasher("SHA256");
172  Rose::BinaryAnalysis::AstHash astHash(hasher);
173 
174  const std::set<rose_addr_t>& basicBlocks = function->basicBlockAddresses();
175 
176  for(std::set<rose_addr_t>::const_iterator bbIt = basicBlocks.begin(); bbIt != basicBlocks.end(); ++bbIt)
177  {
179  ROSE_ASSERT(bb != NULL);
180  astHash.appendBasicBlock(bb);
181 
182  }
183 
184  return hasher->toString();
185  }
186 
187 
188  private:
190  { //Ordered set, so it should always be the same order...
191  funcHash = getHash(partitioner, function);
192 
193  }
194 
195  };
196 
197 }
198 
199 #endif
200 #endif
FunctionInfo(const std::string &ifuncHash, Rose::BinaryAnalysis::Partitioner2::Function::Ptr function)
FunctionInfo.
Definition: FunctionInfo.h:129
class FunctionInfo Combines all the information to uniquely identify a single function in one object...
Definition: FunctionInfo.h:24
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:80
FunctionInfo(const Rose::BinaryAnalysis::Partitioner2::Partitioner &partitioner, Rose::BinaryAnalysis::Partitioner2::Function::Ptr function, const std::string &ilibHash)
FunctionInfo.
Definition: FunctionInfo.h:59
static HasherFactory & Instance()
Returns a reference to the HasherFactory singleton.
A simple traversal that builds up a hash code for the AST.
Definition: BinaryAstHash.h:31
FunctionInfo(const Rose::BinaryAnalysis::Partitioner2::Partitioner &partitioner, Rose::BinaryAnalysis::Partitioner2::Function::Ptr function, LibraryInfo &libInfo)
FunctionInfo.
Definition: FunctionInfo.h:101
boost::shared_ptr< Hasher > createHasher(const std::string &hashType) const
Creates a registered Hasher by type from the map.
FunctionInfo(const std::string &ifuncName, const std::string &ifuncHash, const std::string &ilibHash)
FunctionInfo.
Definition: FunctionInfo.h:40
Partitions instructions into basic blocks and functions.
Definition: Partitioner.h:322
FunctionInfo(const std::string &ifuncHash)
FunctionInfo.
Definition: FunctionInfo.h:116