ROSE  0.9.11.42
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 namespace AllowParallelEdges {
32 enum Type {
33  NO,
34  YES
35 };
36 } // namespace
37 
39 enum VertexType {
47 };
48 
50 enum EdgeType {
71 };
72 
74 enum Confidence {
77 };
78 
83 };
84 
95 
102 
110 
123 
124 private:
125  friend class boost::serialization::access;
126 
127  template<class S>
128  void serialize(S &s, unsigned version) {
129  s & BOOST_SERIALIZATION_NVP(allowEmptyGlobalBlock);
130  s & BOOST_SERIALIZATION_NVP(allowFunctionWithNoBasicBlocks);
131  s & BOOST_SERIALIZATION_NVP(allowEmptyBasicBlocks);
132  s & BOOST_SERIALIZATION_NVP(copyAllInstructions);
133  }
134 
135 public:
138  : allowEmptyGlobalBlock(false), allowFunctionWithNoBasicBlocks(false), allowEmptyBasicBlocks(false),
139  copyAllInstructions(true) {}
140 
147  s.allowEmptyGlobalBlock = false;
149  s.allowEmptyBasicBlocks = false;
150  s.copyAllInstructions = true;
151  return s;
152  }
153 
161  s.allowEmptyGlobalBlock = true;
163  s.allowEmptyBasicBlocks = true;
164  s.copyAllInstructions = true; // true keeps the AST a tree instead of a lattice
165  return s;
166  }
167 };
168 
170 // Settings. All settings must act like properties, which means the following:
171 // 1. Each setting must have a name that does not begin with a verb.
172 // 2. Each setting must have a command-line switch to manipulate it.
173 // 3. Each setting must have a method that queries the property (same name as the property and taking no arguments).
174 // 4. Each setting must have a modifier method (same name as property but takes a value and returns void)
176 
188 };
189 
217  std::string linker;
228  : deExecuteZerosThreshold(0), deExecuteZerosLeaveAtFront(16), deExecuteZerosLeaveAtBack(1),
229  memoryDataAdjustment(DATA_IS_INITIALIZED), memoryIsExecutable(false), linkObjectFiles(true),
230  linkStaticArchives(true), linker("ld -o %o --unresolved-symbols=ignore-all --whole-archive %f") {}
231 
232 private:
233  friend class boost::serialization::access;
234 
235  template<class S>
236  void serialize(S &s, unsigned version) {
237  s & BOOST_SERIALIZATION_NVP(deExecuteZerosThreshold);
238  s & BOOST_SERIALIZATION_NVP(deExecuteZerosLeaveAtFront);
239  s & BOOST_SERIALIZATION_NVP(deExecuteZerosLeaveAtBack);
240  s & BOOST_SERIALIZATION_NVP(memoryDataAdjustment);
241  s & BOOST_SERIALIZATION_NVP(memoryIsExecutable);
242  }
243 };
244 
249  std::string isaName;
253 private:
254  friend class boost::serialization::access;
255 
256  template<class S>
257  void serialize(S &s, unsigned version) {
258  s & BOOST_SERIALIZATION_NVP(isaName);
259  }
260 };
261 
272 };
273 
285 private:
286  friend class boost::serialization::access;
287 
288  template<class S>
289  void serialize(S &s, const unsigned /*version*/) {
290  s & BOOST_SERIALIZATION_NVP(usingSemantics);
291  s & BOOST_SERIALIZATION_NVP(checkingCallBranch);
292  s & BOOST_SERIALIZATION_NVP(basicBlockSemanticsAutoDrop);
293  }
294 
295 public:
297  : usingSemantics(false), checkingCallBranch(false), basicBlockSemanticsAutoDrop(true) {}
298 };
299 
309  std::vector<rose_addr_t> startingVas;
352  boost::filesystem::path syscallHeader;
355 private:
356  friend class boost::serialization::access;
357 
358  template<class S>
359  void serialize(S &s, unsigned version) {
360  s & BOOST_SERIALIZATION_NVP(base);
361  s & BOOST_SERIALIZATION_NVP(startingVas);
362  s & BOOST_SERIALIZATION_NVP(followingGhostEdges);
363  s & BOOST_SERIALIZATION_NVP(discontiguousBlocks);
364  s & BOOST_SERIALIZATION_NVP(maxBasicBlockSize);
365  s & BOOST_SERIALIZATION_NVP(findingFunctionPadding);
366  s & BOOST_SERIALIZATION_NVP(findingDeadCode);
367  s & BOOST_SERIALIZATION_NVP(peScramblerDispatcherVa);
368  if (version >= 2) {
369  s & BOOST_SERIALIZATION_NVP(findingIntraFunctionCode);
370  } else {
371  bool temp = false;
372  if (S::is_saving::value)
373  temp = findingIntraFunctionCode > 0;
374  s & boost::serialization::make_nvp("findingIntraFunctionCode", temp);
375  if (S::is_loading::value)
376  findingIntraFunctionCode = temp ? 10 : 0; // arbitrary number of passes
377  }
378  s & BOOST_SERIALIZATION_NVP(findingIntraFunctionData);
379  s & BOOST_SERIALIZATION_NVP(findingInterFunctionCalls);
380  if (version >= 4)
381  s & BOOST_SERIALIZATION_NVP(findingFunctionCallFunctions);
382  if (version >= 5) {
383  s & BOOST_SERIALIZATION_NVP(findingEntryFunctions);
384  s & BOOST_SERIALIZATION_NVP(findingErrorFunctions);
385  s & BOOST_SERIALIZATION_NVP(findingImportFunctions);
386  s & BOOST_SERIALIZATION_NVP(findingExportFunctions);
387  s & BOOST_SERIALIZATION_NVP(findingSymbolFunctions);
388  }
389  s & BOOST_SERIALIZATION_NVP(interruptVector);
390  s & BOOST_SERIALIZATION_NVP(doingPostAnalysis);
391  s & BOOST_SERIALIZATION_NVP(doingPostFunctionMayReturn);
392  s & BOOST_SERIALIZATION_NVP(doingPostFunctionStackDelta);
393  s & BOOST_SERIALIZATION_NVP(doingPostCallingConvention);
394  s & BOOST_SERIALIZATION_NVP(doingPostFunctionNoop);
395  s & BOOST_SERIALIZATION_NVP(functionReturnAnalysis);
396  if (version >= 3)
397  s & BOOST_SERIALIZATION_NVP(functionReturnAnalysisMaxSorts);
398  s & BOOST_SERIALIZATION_NVP(findingDataFunctionPointers);
399  s & BOOST_SERIALIZATION_NVP(findingCodeFunctionPointers);
400  s & BOOST_SERIALIZATION_NVP(findingThunks);
401  s & BOOST_SERIALIZATION_NVP(splittingThunks);
402  s & BOOST_SERIALIZATION_NVP(semanticMemoryParadigm);
403  s & BOOST_SERIALIZATION_NVP(namingConstants);
404  s & BOOST_SERIALIZATION_NVP(namingStrings);
405  s & BOOST_SERIALIZATION_NVP(demangleNames);
406  if (version >= 1) {
407  s & BOOST_SERIALIZATION_NVP(namingSyscalls);
408 
409  // There is no support for boost::filesystem serialization due to arguments by the maintainers over who has
410  // responsibility, so we do it the hard way.
411  std::string temp;
412  if (S::is_saving::value)
413  temp = syscallHeader.string();
414  s & boost::serialization::make_nvp("syscallHeader", temp);
415  if (S::is_loading::value)
416  syscallHeader = temp;
417  }
418  }
419 
420 public:
421  PartitionerSettings()
422  : followingGhostEdges(false), discontiguousBlocks(true), maxBasicBlockSize(0), findingFunctionPadding(true),
423  findingDeadCode(true), peScramblerDispatcherVa(0), findingIntraFunctionCode(10), findingIntraFunctionData(true),
424  findingInterFunctionCalls(true), findingFunctionCallFunctions(true), findingEntryFunctions(true),
425  findingErrorFunctions(true), findingImportFunctions(true), findingExportFunctions(true), findingSymbolFunctions(true),
426  doingPostAnalysis(true), doingPostFunctionMayReturn(true), doingPostFunctionStackDelta(true),
427  doingPostCallingConvention(false), doingPostFunctionNoop(false), functionReturnAnalysis(MAYRETURN_DEFAULT_YES),
428  functionReturnAnalysisMaxSorts(50), findingDataFunctionPointers(false), findingCodeFunctionPointers(false),
429  findingThunks(true), splittingThunks(false), semanticMemoryParadigm(LIST_BASED_MEMORY), namingConstants(true),
430  namingStrings(true), namingSyscalls(true), demangleNames(true) {}
431 };
432 
433 // BOOST_CLASS_VERSION(PartitionerSettings, 1); -- see end of file (cannot be in a namespace)
434 
440  std::vector<std::string> configurationNames;
441  bool exitOnError;
444  : exitOnError(true) {}
445 
446 private:
447  friend class boost::serialization::access;
448 
449  template<class S>
450  void serialize(S &s, unsigned version) {
451  s & BOOST_SERIALIZATION_NVP(configurationNames);
452  s & BOOST_SERIALIZATION_NVP(exitOnError);
453  }
454 };
455 
456 // Additional declarations w/out definitions yet.
457 class Partitioner;
458 class Function;
460 class BasicBlock;
462 class DataBlock;
464 class ThunkPredicates;
466 
467 } // namespace
468 } // namespace
469 } // namespace
470 
471 // Class versions must be at global scope
473 
474 #endif
bool findingInterFunctionCalls
Look for function calls between functions.
Definition: BasicTypes.h:329
Edge is a function call transfer.
Definition: BasicTypes.h:62
bool splittingThunks
Split thunks into their own separate functions.
Definition: BasicTypes.h:347
bool memoryIsExecutable
Determines whether all of memory should be made executable.
Definition: BasicTypes.h:209
bool linkStaticArchives
Link static libraries before parsing.
Definition: BasicTypes.h:216
Settings for controling the engine behavior.
Definition: BasicTypes.h:439
std::vector< rose_addr_t > startingVas
Addresses at which to start recursive disassembly.
Definition: BasicTypes.h:309
bool findingExportFunctions
Create functions at export addresses.
Definition: BasicTypes.h:334
MemoryDataAdjustment
How the partitioner should globally treat memory.
Definition: BasicTypes.h:178
bool findingDataFunctionPointers
Look for function pointers in static data.
Definition: BasicTypes.h:344
Assume a function returns if the may-return analysis cannot decide whether it may return...
Definition: BasicTypes.h:264
Allow parallel edges, so each edge has a unit count.
Definition: BasicTypes.h:34
std::string isaName
Name of the instruction set architecture.
Definition: BasicTypes.h:249
bool doingPostFunctionStackDelta
Run function-stack-delta analysis if doingPostAnalysis is set?
Definition: BasicTypes.h:339
EdgeType
Partitioner control flow edge types.
Definition: BasicTypes.h:50
rose_addr_t peScramblerDispatcherVa
Run the PeDescrambler module if non-zero.
Definition: BasicTypes.h:326
Settings that control the disassembler.
Definition: BasicTypes.h:248
Treat all memory as if it were initialized.
Definition: BasicTypes.h:181
size_t deExecuteZerosLeaveAtBack
Number of bytes at the end of each zero area to leave unaffected.
Definition: BasicTypes.h:203
bool copyAllInstructions
Whether to allow shared instructions in the AST.
Definition: BasicTypes.h:122
Special vertex destination for indeterminate edges.
Definition: BasicTypes.h:42
static AstConstructionSettings permissive()
Default permissive settings.
Definition: BasicTypes.h:159
Enum type for allowing parallel edges.
Definition: BasicTypes.h:33
Settings that directly control a partitioner.
Definition: BasicTypes.h:277
bool doingPostFunctionNoop
Find and name functions that are effectively no-ops.
Definition: BasicTypes.h:341
Assume that all functions return without ever running the may-return analysis.
Definition: BasicTypes.h:268
bool namingSyscalls
Give names (comments) to system calls if possible.
Definition: BasicTypes.h:351
bool followingGhostEdges
Should ghost edges be followed during disassembly? A ghost edge is a CFG edge that is apparent from t...
Definition: BasicTypes.h:312
Main namespace for the ROSE library.
bool doingPostCallingConvention
Run calling-convention analysis if doingPostAnalysis is set?
Definition: BasicTypes.h:340
Settings for loading specimens.
Definition: BasicTypes.h:193
bool linkObjectFiles
Link object files before parsing.
Definition: BasicTypes.h:215
VertexType
Partitioner control flow vertex types.
Definition: BasicTypes.h:39
Settings that control building the AST.
Definition: BasicTypes.h:89
static AstConstructionSettings strict()
Default strict settings.
Definition: BasicTypes.h:145
bool discontiguousBlocks
Should basic blocks be allowed to be discontiguous.
Definition: BasicTypes.h:319
bool allowEmptyGlobalBlock
Whether to allow an empty global block.
Definition: BasicTypes.h:94
Reference-counting smart pointer.
Definition: SharedPointer.h:67
bool namingStrings
Give labels to constants that are string literal addresses.
Definition: BasicTypes.h:350
size_t functionReturnAnalysisMaxSorts
Number of times functions are sorted before using unsorted lists.
Definition: BasicTypes.h:343
Sawyer::SharedPointer< Function > FunctionPtr
Shared-ownership pointer for function.
Definition: BasicTypes.h:458
FunctionReturnAnalysis functionReturnAnalysis
How to run the function may-return analysis.
Definition: BasicTypes.h:342
bool demangleNames
Run all names through a demangling step.
Definition: BasicTypes.h:353
std::vector< std::string > configurationNames
List of configuration files and/or directories.
Definition: BasicTypes.h:440
bool doingPostFunctionMayReturn
Run function-may-return analysis if doingPostAnalysis is set?
Definition: BasicTypes.h:338
The special "undiscovered" vertex.
Definition: BasicTypes.h:41
bool findingErrorFunctions
Create functions from error handling and exception information.
Definition: BasicTypes.h:332
The value is an assumption without any proof.
Definition: BasicTypes.h:75
Settings that control the engine partitioning.
Definition: BasicTypes.h:307
Confidence
How sure are we of something.
Definition: BasicTypes.h:74
bool doingPostAnalysis
Perform enabled post-partitioning analyses?
Definition: BasicTypes.h:337
size_t findingIntraFunctionCode
Suck up unused addresses as intra-function code (number of passes).
Definition: BasicTypes.h:327
Do not make any global changes to the memory map.
Definition: BasicTypes.h:187
bool findingThunks
Look for common thunk patterns in undiscovered areas.
Definition: BasicTypes.h:346
bool findingImportFunctions
Create functions at import addresses.
Definition: BasicTypes.h:333
A basic block or placeholder for a basic block.
Definition: BasicTypes.h:40
SemanticMemoryParadigm
Organization of semantic memory.
Definition: BasicTypes.h:80
Edge is a function return from the call site.
Definition: BasicTypes.h:56
Normal control flow edge, nothing special.
Definition: BasicTypes.h:51
MemoryDataAdjustment memoryDataAdjustment
How to globally adjust memory segment access bits for data areas.
Definition: BasicTypes.h:205
FunctionReturnAnalysis
Controls whether the function may-return analysis runs.
Definition: BasicTypes.h:263
size_t deExecuteZerosLeaveAtFront
Number of bytes at the beginning of each zero area to leave unaffected.
Definition: BasicTypes.h:201
The value was somehow proved.
Definition: BasicTypes.h:76
bool findingEntryFunctions
Create functions at the program entry point(s).
Definition: BasicTypes.h:331
bool findingDeadCode
Look for unreachable basic blocks?
Definition: BasicTypes.h:325
SemanticMemoryParadigm semanticMemoryParadigm
Container used for semantic memory states.
Definition: BasicTypes.h:348
bool checkingCallBranch
Check for situations where CALL is used as a branch.
Definition: BasicTypes.h:282
bool allowEmptyBasicBlocks
Whether to allow a basic block to be empty.
Definition: BasicTypes.h:109
bool usingSemantics
Whether instruction semantics are used.
Definition: BasicTypes.h:278
Treat all memory as if it were constant.
Definition: BasicTypes.h:179
bool findingSymbolFunctions
Create functions according to symbol tables.
Definition: BasicTypes.h:335
bool exitOnError
If true, emit error message and exit non-zero, else throw.
Definition: BasicTypes.h:441
bool basicBlockSemanticsAutoDrop
Conserve memory by dropping semantics for attached basic blocks.
Definition: BasicTypes.h:283
Assume a function cannot return if the may-return analysis cannot decide whether it may return...
Definition: BasicTypes.h:266
bool namingConstants
Give names to constants by calling Modules::nameConstants.
Definition: BasicTypes.h:349
size_t deExecuteZerosThreshold
Size threshold for removing execute permission from zero data.
Definition: BasicTypes.h:194
bool findingCodeFunctionPointers
Look for function pointers in instructions.
Definition: BasicTypes.h:345
Special vertex destination for non-existing basic blocks.
Definition: BasicTypes.h:43
bool findingIntraFunctionData
Suck up unused addresses as intra-function data.
Definition: BasicTypes.h:328
Assume that a function cannot return without ever running the may-return analysis.
Definition: BasicTypes.h:270
bool allowFunctionWithNoBasicBlocks
Whether to allow functions with no basic blocks.
Definition: BasicTypes.h:101
AddressInterval interruptVector
Table of interrupt handling functions.
Definition: BasicTypes.h:336
bool findingFunctionPadding
Look for padding before each function entry point?
Definition: BasicTypes.h:324
std::string linker
Command to run to link object and archives.
Definition: BasicTypes.h:217
bool findingFunctionCallFunctions
Create functions from function calls.
Definition: BasicTypes.h:330
size_t maxBasicBlockSize
Maximum basic block size.
Definition: BasicTypes.h:323
boost::filesystem::path syscallHeader
Name of header file containing system call numbers.
Definition: BasicTypes.h:352