1 #ifndef ROSE_Partitioner2_BasicTypes_H
2 #define ROSE_Partitioner2_BasicTypes_H
4 #include <boost/serialization/access.hpp>
5 #include <boost/serialization/nvp.hpp>
6 #include <string>
7 #include <vector>
9 // Define this as one if you want extra invariant checks that are quite expensive, or define as zero. This only makes a
10 // difference if NDEBUG and SAWYER_NDEBUG are both undefined--if either one of them are defined then no expensive (or
11 // inexpensive) checks are performed.
14 namespace Rose {
15 namespace BinaryAnalysis {
16 namespace Partitioner2 {
19 enum VertexType {
27 };
30 enum EdgeType {
51 };
54 enum Confidence {
57 };
63 };
104 private:
105  friend class boost::serialization::access;
107  template<class S>
108  void serialize(S &s, unsigned version) {
109  s & allowEmptyGlobalBlock & allowFunctionWithNoBasicBlocks & allowEmptyBasicBlocks & copyAllInstructions;
110  }
112 public:
115  : allowEmptyGlobalBlock(false), allowFunctionWithNoBasicBlocks(false), allowEmptyBasicBlocks(false),
116  copyAllInstructions(true) {}
124  s.allowEmptyGlobalBlock = false;
126  s.allowEmptyBasicBlocks = false;
127  s.copyAllInstructions = true;
128  return s;
129  }
138  s.allowEmptyGlobalBlock = true;
140  s.allowEmptyBasicBlocks = true;
141  s.copyAllInstructions = true; // true keeps the AST a tree instead of a lattice
142  return s;
143  }
144 };
147 // Settings. All settings must act like properties, which means the following:
148 // 1. Each setting must have a name that does not begin with a verb.
149 // 2. Each setting must have a command-line switch to manipulate it.
150 // 3. Each setting must have a method that queries the property (same name as the property and taking no arguments).
151 // 4. Each setting must have a modifier method (same name as property but takes a value and returns void)
165 };
194  std::string linker;
205  : deExecuteZerosThreshold(0), deExecuteZerosLeaveAtFront(16), deExecuteZerosLeaveAtBack(1),
206  memoryDataAdjustment(DATA_IS_INITIALIZED), memoryIsExecutable(false), linkObjectFiles(true),
207  linkStaticArchives(true), linker("ld -o %o --unresolved-symbols=ignore-all --whole-archive %f") {}
209 private:
210  friend class boost::serialization::access;
212  template<class S>
213  void serialize(S &s, unsigned version) {
214  s & deExecuteZerosThreshold & deExecuteZerosLeaveAtFront & deExecuteZerosLeaveAtBack;
215  s & memoryDataAdjustment & memoryIsExecutable;
216  }
217 };
223  std::string isaName;
227 private:
228  friend class boost::serialization::access;
230  template<class S>
231  void serialize(S &s, unsigned version) {
232  s & isaName;
233  }
234 };
246 };
259 private:
260  friend class boost::serialization::access;
262  template<class S>
263  void serialize(S &s, const unsigned /*version*/) {
264  s & BOOST_SERIALIZATION_NVP(usingSemantics);
265  s & BOOST_SERIALIZATION_NVP(checkingCallBranch);
266  s & BOOST_SERIALIZATION_NVP(basicBlockSemanticsAutoDrop);
267  }
269 public:
271  : usingSemantics(false), checkingCallBranch(false), basicBlockSemanticsAutoDrop(true) {}
272 };
283  std::vector<rose_addr_t> startingVas;
320 private:
321  friend class boost::serialization::access;
323  template<class S>
324  void serialize(S &s, unsigned version) {
325  s & base;
326  s & startingVas;
329  s & maxBasicBlockSize;
331  s & findingDeadCode;
336  s & interruptVector;
337  s & doingPostAnalysis;
345  s & findingThunks;
346  s & splittingThunks;
348  s & namingConstants;
349  s & namingStrings;
350  }
352 public:
354  : followingGhostEdges(false), discontiguousBlocks(true), maxBasicBlockSize(0), findingFunctionPadding(true),
355  findingDeadCode(true), peScramblerDispatcherVa(0), findingIntraFunctionCode(true), findingIntraFunctionData(true),
356  findingInterFunctionCalls(true), doingPostAnalysis(true), doingPostFunctionMayReturn(true),
357  doingPostFunctionStackDelta(true), doingPostCallingConvention(false), doingPostFunctionNoop(false),
358  functionReturnAnalysis(MAYRETURN_DEFAULT_YES), findingDataFunctionPointers(false), findingCodeFunctionPointers(false),
359  findingThunks(true), splittingThunks(false), semanticMemoryParadigm(LIST_BASED_MEMORY), namingConstants(true),
360  namingStrings(true), demangleNames(true) {}
361 };
368  std::vector<std::string> configurationNames;
369  bool exitOnError;
372  : exitOnError(true) {}
374 private:
375  friend class boost::serialization::access;
377  template<class S>
378  void serialize(S &s, unsigned version) {
379  s & configurationNames;
380  s & exitOnError;
381  }
382 };
384 // Additional declarations w/out definitions yet.
385 class Partitioner;
386 class Function;
388 class BasicBlock;
390 class DataBlock;
393 } // namespace
394 } // namespace
395 } // namespace
397 #endif
bool findingInterFunctionCalls
Look for function calls between functions.
Definition: BasicTypes.h:303
Edge is a function call transfer.
Definition: BasicTypes.h:42
bool splittingThunks
Split thunks into their own separate functions.
Definition: BasicTypes.h:314
bool memoryIsExecutable
Determines whether all of memory should be made executable.
Definition: BasicTypes.h:186
bool linkStaticArchives
Link static libraries before parsing.
Definition: BasicTypes.h:193
Settings for controling the engine behavior.
Definition: BasicTypes.h:367
std::vector< rose_addr_t > startingVas
Addresses at which to start recursive disassembly.
Definition: BasicTypes.h:283
How the partitioner should globally treat memory.
Definition: BasicTypes.h:155
bool findingDataFunctionPointers
Look for function pointers in static data.
Definition: BasicTypes.h:311
Assume a function returns if the may-return analysis cannot decide whether it may return...
Definition: BasicTypes.h:238
std::string isaName
Name of the instruction set architecture.
Definition: BasicTypes.h:223
bool doingPostFunctionStackDelta
Run function-stack-delta analysis if doingPostAnalysis is set?
Definition: BasicTypes.h:307
Partitioner control flow edge types.
Definition: BasicTypes.h:30
rose_addr_t peScramblerDispatcherVa
Run the PeDescrambler module if non-zero.
Definition: BasicTypes.h:300
Settings that control the disassembler.
Definition: BasicTypes.h:222
Treat all memory as if it were initialized.
Definition: BasicTypes.h:158
size_t deExecuteZerosLeaveAtBack
Number of bytes at the end of each zero area to leave unaffected.
Definition: BasicTypes.h:180
bool copyAllInstructions
Whether to allow shared instructions in the AST.
Definition: BasicTypes.h:102
Special vertex destination for indeterminate edges.
Definition: BasicTypes.h:22
static AstConstructionSettings permissive()
Default permissive settings.
Definition: BasicTypes.h:136
Settings that directly control a partitioner.
Definition: BasicTypes.h:251
bool doingPostFunctionNoop
Find and name functions that are effectively no-ops.
Definition: BasicTypes.h:309
Assume that all functions return without ever running the may-return analysis.
Definition: BasicTypes.h:242
bool findingIntraFunctionCode
Suck up unused addresses as intra-function code.
Definition: BasicTypes.h:301
bool followingGhostEdges
Should ghost edges be followed during disassembly? A ghost edge is a CFG edge that is apparent from t...
Definition: BasicTypes.h:286
Main namespace for the ROSE library.
bool doingPostCallingConvention
Run calling-convention analysis if doingPostAnalysis is set?
Definition: BasicTypes.h:308
Settings for loading specimens.
Definition: BasicTypes.h:170
bool linkObjectFiles
Link object files before parsing.
Definition: BasicTypes.h:192
Partitioner control flow vertex types.
Definition: BasicTypes.h:19
Settings that control building the AST.
Definition: BasicTypes.h:69
static AstConstructionSettings strict()
Default strict settings.
Definition: BasicTypes.h:122
bool discontiguousBlocks
Should basic blocks be allowed to be discontiguous.
Definition: BasicTypes.h:293
bool allowEmptyGlobalBlock
Whether to allow an empty global block.
Definition: BasicTypes.h:74
bool namingStrings
Give labels to constants that are string literal addresses.
Definition: BasicTypes.h:317
Sawyer::SharedPointer< Function > FunctionPtr
Shared-ownership pointer for function.
Definition: BasicTypes.h:386
FunctionReturnAnalysis functionReturnAnalysis
How to run the function may-return analysis.
Definition: BasicTypes.h:310
bool demangleNames
Run all names through a demangling step.
Definition: BasicTypes.h:318
std::vector< std::string > configurationNames
List of configuration files and/or directories.
Definition: BasicTypes.h:368
bool doingPostFunctionMayReturn
Run function-may-return analysis if doingPostAnalysis is set?
Definition: BasicTypes.h:306
The special "undiscovered" vertex.
Definition: BasicTypes.h:21
The value is an assumption without any proof.
Definition: BasicTypes.h:55
Settings that control the engine partitioning.
Definition: BasicTypes.h:281
How sure are we of something.
Definition: BasicTypes.h:54
bool doingPostAnalysis
Perform enabled post-partitioning analyses?
Definition: BasicTypes.h:305
Do not make any global changes to the memory map.
Definition: BasicTypes.h:164
bool findingThunks
Look for common thunk patterns in undiscovered areas.
Definition: BasicTypes.h:313
A basic block or placeholder for a basic block.
Definition: BasicTypes.h:20
Organization of semantic memory.
Definition: BasicTypes.h:60
Edge is a function return from the call site.
Definition: BasicTypes.h:36
Normal control flow edge, nothing special.
Definition: BasicTypes.h:31
MemoryDataAdjustment memoryDataAdjustment
How to globally adjust memory segment access bits for data areas.
Definition: BasicTypes.h:182
Controls whether the function may-return analysis runs.
Definition: BasicTypes.h:237
size_t deExecuteZerosLeaveAtFront
Number of bytes at the beginning of each zero area to leave unaffected.
Definition: BasicTypes.h:178
The value was somehow proved.
Definition: BasicTypes.h:56
bool findingDeadCode
Look for unreachable basic blocks?
Definition: BasicTypes.h:299
SemanticMemoryParadigm semanticMemoryParadigm
Container used for semantic memory states.
Definition: BasicTypes.h:315
bool checkingCallBranch
Check for situations where CALL is used as a branch.
Definition: BasicTypes.h:256
bool allowEmptyBasicBlocks
Whether to allow a basic block to be empty.
Definition: BasicTypes.h:89
bool usingSemantics
Whether instruction semantics are used.
Definition: BasicTypes.h:252
Treat all memory as if it were constant.
Definition: BasicTypes.h:156
bool exitOnError
If true, emit error message and exit non-zero, else throw.
Definition: BasicTypes.h:369
bool basicBlockSemanticsAutoDrop
Conserve memory by dropping semantics for attached basic blocks.
Definition: BasicTypes.h:257
Assume a function cannot return if the may-return analysis cannot decide whether it may return...
Definition: BasicTypes.h:240
bool namingConstants
Give names to constants by calling Modules::nameConstants.
Definition: BasicTypes.h:316
size_t deExecuteZerosThreshold
Size threshold for removing execute permission from zero data.
Definition: BasicTypes.h:171
bool findingCodeFunctionPointers
Look for function pointers in instructions.
Definition: BasicTypes.h:312
Special vertex destination for non-existing basic blocks.
Definition: BasicTypes.h:23
bool findingIntraFunctionData
Suck up unused addresses as intra-function data.
Definition: BasicTypes.h:302
Assume that a function cannot return without ever running the may-return analysis.
Definition: BasicTypes.h:244
bool allowFunctionWithNoBasicBlocks
Whether to allow functions with no basic blocks.
Definition: BasicTypes.h:81
AddressInterval interruptVector
Table of interrupt handling functions.
Definition: BasicTypes.h:304
bool findingFunctionPadding
Look for padding before each function entry point?
Definition: BasicTypes.h:298
std::string linker
Command to run to link object and archives.
Definition: BasicTypes.h:194
size_t maxBasicBlockSize
Maximum basic block size.
Definition: BasicTypes.h:297