ROSE  0.9.10.91
BasicTypes.h
1 #ifndef ROSE_Partitioner2_BasicTypes_H
2 #define ROSE_Partitioner2_BasicTypes_H
3 
4 #include <boost/filesystem.hpp>
5 #include <boost/serialization/access.hpp>
6 #include <boost/serialization/nvp.hpp>
7 #include <boost/serialization/version.hpp>
8 #include <string>
9 #include <vector>
10 
11 // Define this as one if you want extra invariant checks that are quite expensive, or define as zero. This only makes a
12 // difference if NDEBUG and SAWYER_NDEBUG are both undefined--if either one of them are defined then no expensive (or
13 // inexpensive) checks are performed.
14 #define ROSE_PARTITIONER_EXPENSIVE_CHECKS 0
15 
16 namespace Rose {
17 namespace BinaryAnalysis {
18 namespace Partitioner2 {
19 
21 namespace Precision {
22 enum Level {
23  LOW,
27 };
28 } // namespace
29 
31 enum VertexType {
39 };
40 
42 enum EdgeType {
63 };
64 
66 enum Confidence {
69 };
70 
75 };
76 
87 
94 
102 
115 
116 private:
117  friend class boost::serialization::access;
118 
119  template<class S>
120  void serialize(S &s, unsigned version) {
121  s & BOOST_SERIALIZATION_NVP(allowEmptyGlobalBlock);
122  s & BOOST_SERIALIZATION_NVP(allowFunctionWithNoBasicBlocks);
123  s & BOOST_SERIALIZATION_NVP(allowEmptyBasicBlocks);
124  s & BOOST_SERIALIZATION_NVP(copyAllInstructions);
125  }
126 
127 public:
130  : allowEmptyGlobalBlock(false), allowFunctionWithNoBasicBlocks(false), allowEmptyBasicBlocks(false),
131  copyAllInstructions(true) {}
132 
139  s.allowEmptyGlobalBlock = false;
141  s.allowEmptyBasicBlocks = false;
142  s.copyAllInstructions = true;
143  return s;
144  }
145 
153  s.allowEmptyGlobalBlock = true;
155  s.allowEmptyBasicBlocks = true;
156  s.copyAllInstructions = true; // true keeps the AST a tree instead of a lattice
157  return s;
158  }
159 };
160 
162 // Settings. All settings must act like properties, which means the following:
163 // 1. Each setting must have a name that does not begin with a verb.
164 // 2. Each setting must have a command-line switch to manipulate it.
165 // 3. Each setting must have a method that queries the property (same name as the property and taking no arguments).
166 // 4. Each setting must have a modifier method (same name as property but takes a value and returns void)
168 
180 };
181 
209  std::string linker;
220  : deExecuteZerosThreshold(0), deExecuteZerosLeaveAtFront(16), deExecuteZerosLeaveAtBack(1),
221  memoryDataAdjustment(DATA_IS_INITIALIZED), memoryIsExecutable(false), linkObjectFiles(true),
222  linkStaticArchives(true), linker("ld -o %o --unresolved-symbols=ignore-all --whole-archive %f") {}
223 
224 private:
225  friend class boost::serialization::access;
226 
227  template<class S>
228  void serialize(S &s, unsigned version) {
229  s & BOOST_SERIALIZATION_NVP(deExecuteZerosThreshold);
230  s & BOOST_SERIALIZATION_NVP(deExecuteZerosLeaveAtFront);
231  s & BOOST_SERIALIZATION_NVP(deExecuteZerosLeaveAtBack);
232  s & BOOST_SERIALIZATION_NVP(memoryDataAdjustment);
233  s & BOOST_SERIALIZATION_NVP(memoryIsExecutable);
234  }
235 };
236 
241  std::string isaName;
245 private:
246  friend class boost::serialization::access;
247 
248  template<class S>
249  void serialize(S &s, unsigned version) {
250  s & BOOST_SERIALIZATION_NVP(isaName);
251  }
252 };
253 
264 };
265 
277 private:
278  friend class boost::serialization::access;
279 
280  template<class S>
281  void serialize(S &s, const unsigned /*version*/) {
282  s & BOOST_SERIALIZATION_NVP(usingSemantics);
283  s & BOOST_SERIALIZATION_NVP(checkingCallBranch);
284  s & BOOST_SERIALIZATION_NVP(basicBlockSemanticsAutoDrop);
285  }
286 
287 public:
289  : usingSemantics(false), checkingCallBranch(false), basicBlockSemanticsAutoDrop(true) {}
290 };
291 
301  std::vector<rose_addr_t> startingVas;
338  boost::filesystem::path syscallHeader;
341 private:
342  friend class boost::serialization::access;
343 
344  template<class S>
345  void serialize(S &s, unsigned version) {
346  s & BOOST_SERIALIZATION_NVP(base);
347  s & BOOST_SERIALIZATION_NVP(startingVas);
348  s & BOOST_SERIALIZATION_NVP(followingGhostEdges);
349  s & BOOST_SERIALIZATION_NVP(discontiguousBlocks);
350  s & BOOST_SERIALIZATION_NVP(maxBasicBlockSize);
351  s & BOOST_SERIALIZATION_NVP(findingFunctionPadding);
352  s & BOOST_SERIALIZATION_NVP(findingDeadCode);
353  s & BOOST_SERIALIZATION_NVP(peScramblerDispatcherVa);
354  if (version >= 2) {
355  s & BOOST_SERIALIZATION_NVP(findingIntraFunctionCode);
356  } else {
357  bool temp = false;
358  if (S::is_saving::value)
359  temp = findingIntraFunctionCode > 0;
360  s & boost::serialization::make_nvp("findingIntraFunctionCode", temp);
361  if (S::is_loading::value)
362  findingIntraFunctionCode = temp ? 10 : 0; // arbitrary number of passes
363  }
364  s & BOOST_SERIALIZATION_NVP(findingIntraFunctionData);
365  s & BOOST_SERIALIZATION_NVP(findingInterFunctionCalls);
366  s & BOOST_SERIALIZATION_NVP(interruptVector);
367  s & BOOST_SERIALIZATION_NVP(doingPostAnalysis);
368  s & BOOST_SERIALIZATION_NVP(doingPostFunctionMayReturn);
369  s & BOOST_SERIALIZATION_NVP(doingPostFunctionStackDelta);
370  s & BOOST_SERIALIZATION_NVP(doingPostCallingConvention);
371  s & BOOST_SERIALIZATION_NVP(doingPostFunctionNoop);
372  s & BOOST_SERIALIZATION_NVP(functionReturnAnalysis);
373  if (version >= 3)
374  s & BOOST_SERIALIZATION_NVP(functionReturnAnalysisMaxSorts);
375  s & BOOST_SERIALIZATION_NVP(findingDataFunctionPointers);
376  s & BOOST_SERIALIZATION_NVP(findingCodeFunctionPointers);
377  s & BOOST_SERIALIZATION_NVP(findingThunks);
378  s & BOOST_SERIALIZATION_NVP(splittingThunks);
379  s & BOOST_SERIALIZATION_NVP(semanticMemoryParadigm);
380  s & BOOST_SERIALIZATION_NVP(namingConstants);
381  s & BOOST_SERIALIZATION_NVP(namingStrings);
382  s & BOOST_SERIALIZATION_NVP(demangleNames);
383  if (version >= 1) {
384  s & BOOST_SERIALIZATION_NVP(namingSyscalls);
385 
386  // There is no support for boost::filesystem serialization due to arguments by the maintainers over who has
387  // responsibility, so we do it the hard way.
388  std::string temp;
389  if (S::is_saving::value)
390  temp = syscallHeader.string();
391  s & boost::serialization::make_nvp("syscallHeader", temp);
392  if (S::is_loading::value)
393  syscallHeader = temp;
394  }
395  }
396 
397 public:
398  PartitionerSettings()
399  : followingGhostEdges(false), discontiguousBlocks(true), maxBasicBlockSize(0), findingFunctionPadding(true),
400  findingDeadCode(true), peScramblerDispatcherVa(0), findingIntraFunctionCode(10), findingIntraFunctionData(true),
401  findingInterFunctionCalls(true), doingPostAnalysis(true), doingPostFunctionMayReturn(true),
402  doingPostFunctionStackDelta(true), doingPostCallingConvention(false), doingPostFunctionNoop(false),
403  functionReturnAnalysis(MAYRETURN_DEFAULT_YES), functionReturnAnalysisMaxSorts(50), findingDataFunctionPointers(false),
404  findingCodeFunctionPointers(false), findingThunks(true), splittingThunks(false),
405  semanticMemoryParadigm(LIST_BASED_MEMORY), namingConstants(true), namingStrings(true), namingSyscalls(true),
406  demangleNames(true) {}
407 };
408 
409 // BOOST_CLASS_VERSION(PartitionerSettings, 1); -- see end of file (cannot be in a namespace)
410 
416  std::vector<std::string> configurationNames;
417  bool exitOnError;
420  : exitOnError(true) {}
421 
422 private:
423  friend class boost::serialization::access;
424 
425  template<class S>
426  void serialize(S &s, unsigned version) {
427  s & BOOST_SERIALIZATION_NVP(configurationNames);
428  s & BOOST_SERIALIZATION_NVP(exitOnError);
429  }
430 };
431 
432 // Additional declarations w/out definitions yet.
433 class Partitioner;
434 class Function;
436 class BasicBlock;
438 class DataBlock;
440 
441 } // namespace
442 } // namespace
443 } // namespace
444 
445 // Class versions must be at global scope
447 
448 #endif
bool findingInterFunctionCalls
Look for function calls between functions.
Definition: BasicTypes.h:321
Edge is a function call transfer.
Definition: BasicTypes.h:54
bool splittingThunks
Split thunks into their own separate functions.
Definition: BasicTypes.h:333
bool memoryIsExecutable
Determines whether all of memory should be made executable.
Definition: BasicTypes.h:201
bool linkStaticArchives
Link static libraries before parsing.
Definition: BasicTypes.h:208
Settings for controling the engine behavior.
Definition: BasicTypes.h:415
std::vector< rose_addr_t > startingVas
Addresses at which to start recursive disassembly.
Definition: BasicTypes.h:301
MemoryDataAdjustment
How the partitioner should globally treat memory.
Definition: BasicTypes.h:170
bool findingDataFunctionPointers
Look for function pointers in static data.
Definition: BasicTypes.h:330
Assume a function returns if the may-return analysis cannot decide whether it may return...
Definition: BasicTypes.h:256
std::string isaName
Name of the instruction set architecture.
Definition: BasicTypes.h:241
bool doingPostFunctionStackDelta
Run function-stack-delta analysis if doingPostAnalysis is set?
Definition: BasicTypes.h:325
EdgeType
Partitioner control flow edge types.
Definition: BasicTypes.h:42
rose_addr_t peScramblerDispatcherVa
Run the PeDescrambler module if non-zero.
Definition: BasicTypes.h:318
Settings that control the disassembler.
Definition: BasicTypes.h:240
Treat all memory as if it were initialized.
Definition: BasicTypes.h:173
size_t deExecuteZerosLeaveAtBack
Number of bytes at the end of each zero area to leave unaffected.
Definition: BasicTypes.h:195
bool copyAllInstructions
Whether to allow shared instructions in the AST.
Definition: BasicTypes.h:114
Special vertex destination for indeterminate edges.
Definition: BasicTypes.h:34
static AstConstructionSettings permissive()
Default permissive settings.
Definition: BasicTypes.h:151
Settings that directly control a partitioner.
Definition: BasicTypes.h:269
bool doingPostFunctionNoop
Find and name functions that are effectively no-ops.
Definition: BasicTypes.h:327
Assume that all functions return without ever running the may-return analysis.
Definition: BasicTypes.h:260
bool namingSyscalls
Give names (comments) to system calls if possible.
Definition: BasicTypes.h:337
bool followingGhostEdges
Should ghost edges be followed during disassembly? A ghost edge is a CFG edge that is apparent from t...
Definition: BasicTypes.h:304
Main namespace for the ROSE library.
bool doingPostCallingConvention
Run calling-convention analysis if doingPostAnalysis is set?
Definition: BasicTypes.h:326
Settings for loading specimens.
Definition: BasicTypes.h:185
bool linkObjectFiles
Link object files before parsing.
Definition: BasicTypes.h:207
VertexType
Partitioner control flow vertex types.
Definition: BasicTypes.h:31
Settings that control building the AST.
Definition: BasicTypes.h:81
static AstConstructionSettings strict()
Default strict settings.
Definition: BasicTypes.h:137
bool discontiguousBlocks
Should basic blocks be allowed to be discontiguous.
Definition: BasicTypes.h:311
bool allowEmptyGlobalBlock
Whether to allow an empty global block.
Definition: BasicTypes.h:86
bool namingStrings
Give labels to constants that are string literal addresses.
Definition: BasicTypes.h:336
size_t functionReturnAnalysisMaxSorts
Number of times functions are sorted before using unsorted lists.
Definition: BasicTypes.h:329
Sawyer::SharedPointer< Function > FunctionPtr
Shared-ownership pointer for function.
Definition: BasicTypes.h:434
FunctionReturnAnalysis functionReturnAnalysis
How to run the function may-return analysis.
Definition: BasicTypes.h:328
bool demangleNames
Run all names through a demangling step.
Definition: BasicTypes.h:339
std::vector< std::string > configurationNames
List of configuration files and/or directories.
Definition: BasicTypes.h:416
bool doingPostFunctionMayReturn
Run function-may-return analysis if doingPostAnalysis is set?
Definition: BasicTypes.h:324
The special "undiscovered" vertex.
Definition: BasicTypes.h:33
The value is an assumption without any proof.
Definition: BasicTypes.h:67
Settings that control the engine partitioning.
Definition: BasicTypes.h:299
Confidence
How sure are we of something.
Definition: BasicTypes.h:66
bool doingPostAnalysis
Perform enabled post-partitioning analyses?
Definition: BasicTypes.h:323
size_t findingIntraFunctionCode
Suck up unused addresses as intra-function code (number of passes).
Definition: BasicTypes.h:319
Do not make any global changes to the memory map.
Definition: BasicTypes.h:179
bool findingThunks
Look for common thunk patterns in undiscovered areas.
Definition: BasicTypes.h:332
A basic block or placeholder for a basic block.
Definition: BasicTypes.h:32
SemanticMemoryParadigm
Organization of semantic memory.
Definition: BasicTypes.h:72
Edge is a function return from the call site.
Definition: BasicTypes.h:48
Normal control flow edge, nothing special.
Definition: BasicTypes.h:43
MemoryDataAdjustment memoryDataAdjustment
How to globally adjust memory segment access bits for data areas.
Definition: BasicTypes.h:197
FunctionReturnAnalysis
Controls whether the function may-return analysis runs.
Definition: BasicTypes.h:255
size_t deExecuteZerosLeaveAtFront
Number of bytes at the beginning of each zero area to leave unaffected.
Definition: BasicTypes.h:193
The value was somehow proved.
Definition: BasicTypes.h:68
bool findingDeadCode
Look for unreachable basic blocks?
Definition: BasicTypes.h:317
SemanticMemoryParadigm semanticMemoryParadigm
Container used for semantic memory states.
Definition: BasicTypes.h:334
bool checkingCallBranch
Check for situations where CALL is used as a branch.
Definition: BasicTypes.h:274
bool allowEmptyBasicBlocks
Whether to allow a basic block to be empty.
Definition: BasicTypes.h:101
bool usingSemantics
Whether instruction semantics are used.
Definition: BasicTypes.h:270
Treat all memory as if it were constant.
Definition: BasicTypes.h:171
bool exitOnError
If true, emit error message and exit non-zero, else throw.
Definition: BasicTypes.h:417
bool basicBlockSemanticsAutoDrop
Conserve memory by dropping semantics for attached basic blocks.
Definition: BasicTypes.h:275
Assume a function cannot return if the may-return analysis cannot decide whether it may return...
Definition: BasicTypes.h:258
bool namingConstants
Give names to constants by calling Modules::nameConstants.
Definition: BasicTypes.h:335
size_t deExecuteZerosThreshold
Size threshold for removing execute permission from zero data.
Definition: BasicTypes.h:186
bool findingCodeFunctionPointers
Look for function pointers in instructions.
Definition: BasicTypes.h:331
Special vertex destination for non-existing basic blocks.
Definition: BasicTypes.h:35
bool findingIntraFunctionData
Suck up unused addresses as intra-function data.
Definition: BasicTypes.h:320
Assume that a function cannot return without ever running the may-return analysis.
Definition: BasicTypes.h:262
bool allowFunctionWithNoBasicBlocks
Whether to allow functions with no basic blocks.
Definition: BasicTypes.h:93
AddressInterval interruptVector
Table of interrupt handling functions.
Definition: BasicTypes.h:322
bool findingFunctionPadding
Look for padding before each function entry point?
Definition: BasicTypes.h:316
std::string linker
Command to run to link object and archives.
Definition: BasicTypes.h:209
size_t maxBasicBlockSize
Maximum basic block size.
Definition: BasicTypes.h:315
boost::filesystem::path syscallHeader
Name of header file containing system call numbers.
Definition: BasicTypes.h:338