ROSE  0.9.10.89
Engine.h
1 #ifndef ROSE_Partitioner2_Engine_H
2 #define ROSE_Partitioner2_Engine_H
3 
4 #include <BinaryLoader.h>
5 #include <boost/noncopyable.hpp>
6 #include <Disassembler.h>
7 #include <FileSystem.h>
8 #include <Partitioner2/Function.h>
9 #include <Partitioner2/Partitioner.h>
10 #include <Partitioner2/Utility.h>
11 #include <Progress.h>
12 #include <Sawyer/DistinctList.h>
13 
14 #ifdef ROSE_ENABLE_PYTHON_API
15 #undef slots // stupid Qt pollution
16 #include <boost/python.hpp>
17 #endif
18 
19 namespace Rose {
20 namespace BinaryAnalysis {
21 namespace Partitioner2 {
22 
106 class ROSE_DLL_API Engine: private boost::noncopyable {
107 public:
111  struct Settings {
118  private:
119  friend class boost::serialization::access;
120 
121  template<class S>
122  void serialize(S &s, unsigned version) {
123  s & loader & disassembler & partitioner & engine & astConstruction;
124  }
125  };
126 
128  // Internal data structures
130 private:
131  // Engine callback for handling instructions added to basic blocks. This is called when a basic block is discovered,
132  // before it's attached to a partitioner, so it shouldn't really be modifying any state in the engine, but rather only
133  // preparing the basic block to be processed.
134  class BasicBlockFinalizer: public BasicBlockCallback {
135  typedef Sawyer::Container::Map<rose_addr_t /*target*/, std::vector<rose_addr_t> /*sources*/> WorkList;
136  public:
137  static Ptr instance() { return Ptr(new BasicBlockFinalizer); }
138  virtual bool operator()(bool chain, const Args &args) ROSE_OVERRIDE;
139  private:
140  void fixFunctionReturnEdge(const Args&);
141  void fixFunctionCallEdges(const Args&);
142  void addPossibleIndeterminateEdge(const Args&);
143  };
144 
145  // Basic blocks that need to be worked on next. These lists are adjusted whenever a new basic block (or placeholder) is
146  // inserted or erased from the CFG.
147  class BasicBlockWorkList: public CfgAdjustmentCallback {
148  // The following lists are used for adding outgoing E_CALL_RETURN edges to basic blocks based on whether the basic
149  // block is a call to a function that might return. When a new basic block is inserted into the CFG (or a previous
150  // block is removed, modified, and re-inserted), the operator() is called and conditionally inserts the block into the
151  // "pendingCallReturn" list (if the block is a function call that lacks an E_CALL_RETURN edge and the function is known
152  // to return or the analysis was incomplete).
153  //
154  // When we run out of other ways to create basic blocks, we process the pendingCallReturn list from back to front. If
155  // the back block (which gets popped) has a positive may-return result then an E_CALL_RETURN edge is added to the CFG
156  // and the normal recursive BB discovery is resumed. Otherwise if the analysis is incomplete the basic block is moved
157  // to the processedCallReturn list. The entire pendingCallReturn list is processed before proceeding.
158  //
159  // If there is no more pendingCallReturn work to be done, then the processedCallReturn blocks are moved to the
160  // finalCallReturn list and finalCallReturn is sorted by approximate CFG height (i.e., leafs first). The contents
161  // of the finalCallReturn list is then analyzed and the result (or the default may-return value for failed analyses)
162  // is used to decide whether a new CFG edge should be created, possibly adding new basic block addresses to the
163  // list of undiscovered blocks.
164  //
165  Sawyer::Container::DistinctList<rose_addr_t> pendingCallReturn_; // blocks that might need an E_CALL_RETURN edge
166  Sawyer::Container::DistinctList<rose_addr_t> processedCallReturn_; // call sites whose may-return was indeterminate
167  Sawyer::Container::DistinctList<rose_addr_t> finalCallReturn_; // indeterminate call sites awaiting final analysis
168 
169  Sawyer::Container::DistinctList<rose_addr_t> undiscovered_; // undiscovered basic block list (last-in-first-out)
170  Engine *engine_; // engine to which this callback belongs
171  size_t maxSorts_; // max sorts before using unsorted lists
172  protected:
173  BasicBlockWorkList(Engine *engine, size_t maxSorts): engine_(engine), maxSorts_(maxSorts) {}
174  public:
176  static Ptr instance(Engine *engine, size_t maxSorts) { return Ptr(new BasicBlockWorkList(engine, maxSorts)); }
177  virtual bool operator()(bool chain, const AttachedBasicBlock &args) ROSE_OVERRIDE;
178  virtual bool operator()(bool chain, const DetachedBasicBlock &args) ROSE_OVERRIDE;
179  Sawyer::Container::DistinctList<rose_addr_t>& pendingCallReturn() { return pendingCallReturn_; }
180  Sawyer::Container::DistinctList<rose_addr_t>& processedCallReturn() { return processedCallReturn_; }
181  Sawyer::Container::DistinctList<rose_addr_t>& finalCallReturn() { return finalCallReturn_; }
182  Sawyer::Container::DistinctList<rose_addr_t>& undiscovered() { return undiscovered_; }
183  void moveAndSortCallReturn(const Partitioner&);
184  };
185 
186  // A work list providing constants from instructions that are part of the CFG.
187  class CodeConstants: public CfgAdjustmentCallback {
188  public:
190 
191  private:
192  std::set<rose_addr_t> toBeExamined_; // instructions waiting to be examined
193  std::set<rose_addr_t> wasExamined_; // instructions we've already examined
194  rose_addr_t inProgress_; // instruction that is currently in progress
195  std::vector<rose_addr_t> constants_; // constants for the instruction in progress
196 
197  protected:
198  CodeConstants(): inProgress_(0) {}
199 
200  public:
201  static Ptr instance() { return Ptr(new CodeConstants); }
202 
203  // Possibly insert more instructions into the work list when a basic block is added to the CFG
204  virtual bool operator()(bool chain, const AttachedBasicBlock &attached) ROSE_OVERRIDE;
205 
206  // Possibly remove instructions from the worklist when a basic block is removed from the CFG
207  virtual bool operator()(bool chain, const DetachedBasicBlock &detached) ROSE_OVERRIDE;
208 
209  // Return the next available constant if any.
210  Sawyer::Optional<rose_addr_t> nextConstant(const Partitioner &partitioner);
211 
212  // Address of instruction being examined.
213  rose_addr_t inProgress() const { return inProgress_; }
214  };
215 
217  // Data members
219 private:
220  Settings settings_; // Settings for the partitioner.
221  SgAsmInterpretation *interp_; // interpretation set by loadSpecimen
222  BinaryLoader *binaryLoader_; // how to remap, link, and fixup
223  Disassembler *disassembler_; // not ref-counted yet, but don't destroy it since user owns it
224  MemoryMap::Ptr map_; // memory map initialized by load()
225  BasicBlockWorkList::Ptr basicBlockWorkList_; // what blocks to work on next
226  CodeConstants::Ptr codeFunctionPointers_; // generates constants that are found in instruction ASTs
227  Progress::Ptr progress_; // optional progress reporting
228 
230  // Constructors
232 public:
235  : interp_(NULL), binaryLoader_(NULL), disassembler_(NULL),
236  basicBlockWorkList_(BasicBlockWorkList::instance(this, settings_.partitioner.functionReturnAnalysisMaxSorts)),
237  progress_(Progress::instance()) {
238  init();
239  }
240 
242  explicit Engine(const Settings &settings)
243  : settings_(settings), interp_(NULL), binaryLoader_(NULL), disassembler_(NULL),
244  basicBlockWorkList_(BasicBlockWorkList::instance(this, settings_.partitioner.functionReturnAnalysisMaxSorts)),
245  progress_(Progress::instance()) {
246  init();
247  }
248 
249  virtual ~Engine() {}
250 
252  // The very top-level use case
254 public:
279  SgAsmBlock* frontend(int argc, char *argv[],
280  const std::string &purpose, const std::string &description);
281  virtual SgAsmBlock* frontend(const std::vector<std::string> &args,
282  const std::string &purpose, const std::string &description);
285  // Basic top-level steps
288 public:
294  void reset();
295 
322  Sawyer::CommandLine::ParserResult parseCommandLine(int argc, char *argv[],
323  const std::string &purpose, const std::string &description) /*final*/;
324  virtual Sawyer::CommandLine::ParserResult parseCommandLine(const std::vector<std::string> &args,
325  const std::string &purpose, const std::string &description);
347  virtual SgAsmInterpretation* parseContainers(const std::vector<std::string> &fileNames);
348  SgAsmInterpretation* parseContainers(const std::string &fileName) /*final*/;
371  virtual MemoryMap::Ptr loadSpecimens(const std::vector<std::string> &fileNames = std::vector<std::string>());
372  MemoryMap::Ptr loadSpecimens(const std::string &fileName) /*final*/;
394  virtual Partitioner partition(const std::vector<std::string> &fileNames = std::vector<std::string>());
395  Partitioner partition(const std::string &fileName) /*final*/;
412  SgAsmBlock* buildAst(const std::vector<std::string> &fileNames = std::vector<std::string>()) /*final*/;
413  SgAsmBlock* buildAst(const std::string &fileName) /*final*/;
416  // Command-line parsing
418  //
419  // top-level: parseCommandLine
421 public:
423  virtual Sawyer::CommandLine::SwitchGroup loaderSwitches();
424 
426  virtual Sawyer::CommandLine::SwitchGroup disassemblerSwitches();
427 
429  virtual Sawyer::CommandLine::SwitchGroup partitionerSwitches();
430 
432  virtual Sawyer::CommandLine::SwitchGroup engineSwitches();
433 
435  virtual Sawyer::CommandLine::SwitchGroup astConstructionSwitches();
436 
438  static std::string specimenNameDocumentation();
439 
451  virtual Sawyer::CommandLine::Parser commandLineParser(const std::string &purpose, const std::string &description);
452 
459  virtual void checkSettings();
460 
462  // Container parsing
463  //
464  // top-level: parseContainers
466 public:
471  virtual bool isNonContainer(const std::string&);
472 
478  virtual bool areContainersParsed() const;
479 
481  // Load specimens
482  //
483  // top-level: loadSpecimens
485 public:
489  virtual bool areSpecimensLoaded() const;
490 
506  virtual BinaryLoader *obtainLoader(BinaryLoader *hint=NULL);
507 
513  virtual void loadContainers(const std::vector<std::string> &fileNames);
514 
519  virtual void loadNonContainers(const std::vector<std::string> &names);
520 
524  virtual void adjustMemoryMap();
525 
534  MemoryMap::Ptr memoryMap() const /*final*/ { return map_; }
535  virtual void memoryMap(const MemoryMap::Ptr &m) { map_ = m; }
539  // Disassembler
542 public:
559  virtual Disassembler* obtainDisassembler(Disassembler *hint=NULL);
563  // Partitioner high-level functions
565  //
566  // top-level: partition
568 public:
570  virtual void checkCreatePartitionerPrerequisites() const;
571 
578  virtual Partitioner createBarePartitioner();
579 
585  virtual Partitioner createGenericPartitioner();
586 
591  virtual Partitioner createTunedPartitioner();
592 
597  virtual Partitioner createPartitionerFromAst(SgAsmInterpretation*);
598 
603  virtual Partitioner createPartitioner();
604 
608  virtual void runPartitionerInit(Partitioner&);
609 
613  virtual void runPartitionerRecursive(Partitioner&);
614 
619  virtual void runPartitionerFinal(Partitioner&);
620 
626  virtual void runPartitioner(Partitioner&);
627 
628 
630  // Partitioner mid-level functions
631  //
632  // These are the functions called by the partitioner high-level stuff. These are sometimes overridden in subclasses,
633  // although it is more likely that the high-level stuff is overridden.
635 public:
640  virtual void labelAddresses(Partitioner&);
641 
645  virtual std::vector<DataBlock::Ptr> makeConfiguredDataBlocks(Partitioner&, const Configuration&);
646 
650  virtual std::vector<Function::Ptr> makeConfiguredFunctions(Partitioner&, const Configuration&);
651 
658  virtual std::vector<Function::Ptr> makeEntryFunctions(Partitioner&, SgAsmInterpretation*);
659 
666  virtual std::vector<Function::Ptr> makeErrorHandlingFunctions(Partitioner&, SgAsmInterpretation*);
667 
677  virtual std::vector<Function::Ptr> makeImportFunctions(Partitioner&, SgAsmInterpretation*);
678 
685  virtual std::vector<Function::Ptr> makeExportFunctions(Partitioner&, SgAsmInterpretation*);
686 
693  virtual std::vector<Function::Ptr> makeSymbolFunctions(Partitioner&, SgAsmInterpretation*);
694 
702  virtual std::vector<Function::Ptr> makeContainerFunctions(Partitioner&, SgAsmInterpretation*);
703 
710  virtual std::vector<Function::Ptr> makeInterruptVectorFunctions(Partitioner&, const AddressInterval &vector);
711 
716  virtual std::vector<Function::Ptr> makeUserFunctions(Partitioner&, const std::vector<rose_addr_t>&);
717 
724  virtual void discoverBasicBlocks(Partitioner&);
725 
737  virtual Function::Ptr makeNextDataReferencedFunction(const Partitioner&, rose_addr_t &startVa /*in,out*/);
738 
752  virtual Function::Ptr makeNextCodeReferencedFunction(const Partitioner&);
753 
760  virtual std::vector<Function::Ptr> makeCalledFunctions(Partitioner&);
761 
774  virtual std::vector<Function::Ptr> makeNextPrologueFunction(Partitioner&, rose_addr_t startVa);
775 
794  virtual std::vector<Function::Ptr>
795  makeFunctionFromInterFunctionCalls(Partitioner &partitioner, rose_addr_t &startVa /*in,out*/);
796 
803  virtual void discoverFunctions(Partitioner&);
804 
819  virtual std::set<rose_addr_t> attachDeadCodeToFunction(Partitioner&, const Function::Ptr&, size_t maxIterations=size_t(-1));
820 
828  virtual DataBlock::Ptr attachPaddingToFunction(Partitioner&, const Function::Ptr&);
829 
834  virtual std::vector<DataBlock::Ptr> attachPaddingToFunctions(Partitioner&);
835 
846  virtual size_t attachAllSurroundedCodeToFunctions(Partitioner&);
847 
855  virtual size_t attachSurroundedCodeToFunctions(Partitioner&);
856 
861  virtual void attachBlocksToFunctions(Partitioner&);
862 
869  virtual std::set<rose_addr_t> attachDeadCodeToFunctions(Partitioner&, size_t maxIterations=size_t(-1));
870 
880  virtual std::vector<DataBlock::Ptr> attachSurroundedDataToFunctions(Partitioner&);
881 
887  virtual void updateAnalysisResults(Partitioner&);
888 
889 
891  // Partitioner low-level functions
892  //
893  // These are functions that a subclass seldom overrides, and maybe even shouldn't override because of their complexity or
894  // the way the interact with one another.
896 public:
907  virtual bool makeNextCallReturnEdge(Partitioner&, boost::logic::tribool assumeCallReturns);
908 
914  virtual BasicBlock::Ptr makeNextBasicBlockFromPlaceholder(Partitioner&);
915 
930  virtual BasicBlock::Ptr makeNextBasicBlock(Partitioner&);
931 
932 
934  // Build AST
936 public:
937  // Used internally by ROSE's ::frontend disassemble instructions to build the AST that goes under each SgAsmInterpretation.
938  static void disassembleForRoseFrontend(SgAsmInterpretation*);
939 
940 
942  // Settings and properties
944 public:
951  const Settings& settings() const /*final*/ { return settings_; }
952  Settings& settings() /*final*/ { return settings_; }
963  bool exitOnError() const /*final*/ { return settings_.engine.exitOnError; }
964  virtual void exitOnError(bool b) { settings_.engine.exitOnError = b; }
972  Progress::Ptr progress() const /*final*/ { return progress_; }
973  virtual void progress(const Progress::Ptr &progress) { progress_ = progress; }
983  SgAsmInterpretation* interpretation() const /*final*/ { return interp_; }
984  virtual void interpretation(SgAsmInterpretation *interp) { interp_ = interp; }
993  BinaryLoader* binaryLoader() const /*final*/ { return binaryLoader_; }
994  virtual void binaryLoader(BinaryLoader *loader) { binaryLoader_ = loader; }
1007  size_t deExecuteZerosThreshold() const /*final*/ { return settings_.loader.deExecuteZerosThreshold; }
1008  virtual void deExecuteZerosThreshold(size_t n) { settings_.loader.deExecuteZerosThreshold = n; }
1009  size_t deExecuteZerosLeaveAtFront() const /*final*/ { return settings_.loader.deExecuteZerosLeaveAtFront; }
1010  virtual void deExecuteZerosLeaveAtFront(size_t n) { settings_.loader.deExecuteZerosLeaveAtFront = n; }
1011  size_t deExecuteZerosLeaveAtBack() const /*final*/ { return settings_.loader.deExecuteZerosLeaveAtBack; }
1012  virtual void deExecuteZerosLeaveAtBack(size_t n) { settings_.loader.deExecuteZerosLeaveAtBack = n; }
1027  MemoryDataAdjustment memoryDataAdjustment() const /*final*/ { return settings_.loader.memoryDataAdjustment; }
1028  virtual void memoryDataAdjustment(MemoryDataAdjustment x) { settings_.loader.memoryDataAdjustment = x; }
1038  bool memoryIsExecutable() const /*final*/ { return settings_.loader.memoryIsExecutable; }
1039  virtual void memoryIsExecutable(bool b) { settings_.loader.memoryIsExecutable = b; }
1051  bool linkObjectFiles() const /*final*/ { return settings_.loader.linkObjectFiles; }
1052  virtual void linkObjectFiles(bool b) { settings_.loader.linkObjectFiles = b; }
1064  bool linkStaticArchives() const /*final*/ { return settings_.loader.linkStaticArchives; }
1065  virtual void linkStaticArchives(bool b) { settings_.loader.linkStaticArchives = b; }
1076  const std::string& linkerCommand() const /*final*/ { return settings_.loader.linker; }
1077  virtual void linkerCommand(const std::string &cmd) { settings_.loader.linker = cmd; }
1086  Disassembler *disassembler() const /*final*/ { return disassembler_; }
1087  virtual void disassembler(Disassembler *d) { disassembler_ = d; }
1096  const std::string& isaName() const /*final*/ { return settings_.disassembler.isaName; }
1097  virtual void isaName(const std::string &s) { settings_.disassembler.isaName = s; }
1106  const std::vector<rose_addr_t>& startingVas() const /*final*/ { return settings_.partitioner.startingVas; }
1107  std::vector<rose_addr_t>& startingVas() /*final*/ { return settings_.partitioner.startingVas; }
1116  bool usingSemantics() const /*final*/ { return settings_.partitioner.base.usingSemantics; }
1117  virtual void usingSemantics(bool b) { settings_.partitioner.base.usingSemantics = b; }
1126  SemanticMemoryParadigm semanticMemoryParadigm() const /*final*/ { return settings_.partitioner.semanticMemoryParadigm; }
1127  virtual void semanticMemoryParadigm(SemanticMemoryParadigm p) { settings_.partitioner.semanticMemoryParadigm = p; }
1138  bool followingGhostEdges() const /*final*/ { return settings_.partitioner.followingGhostEdges; }
1139  virtual void followingGhostEdges(bool b) { settings_.partitioner.followingGhostEdges = b; }
1149  bool discontiguousBlocks() const /*final*/ { return settings_.partitioner.discontiguousBlocks; }
1150  virtual void discontiguousBlocks(bool b) { settings_.partitioner.discontiguousBlocks = b; }
1160  size_t maxBasicBlockSize() const /*final*/ { return settings_.partitioner.maxBasicBlockSize; }
1161  virtual void maxBasicBlockSize(size_t n) { settings_.partitioner.maxBasicBlockSize = n; }
1170  bool findingFunctionPadding() const /*final*/ { return settings_.partitioner.findingFunctionPadding; }
1171  virtual void findingFunctionPadding(bool b) { settings_.partitioner.findingFunctionPadding = b; }
1180  bool findingThunks() const /*final*/ { return settings_.partitioner.findingThunks; }
1181  virtual void findingThunks(bool b) { settings_.partitioner.findingThunks = b; }
1190  bool splittingThunks() const /*final*/ { return settings_.partitioner.splittingThunks; }
1191  virtual void splittingThunks(bool b) { settings_.partitioner.splittingThunks = b; }
1200  bool findingDeadCode() const /*final*/ { return settings_.partitioner.findingDeadCode; }
1201  virtual void findingDeadCode(bool b) { settings_.partitioner.findingDeadCode = b; }
1210  rose_addr_t peScramblerDispatcherVa() const /*final*/ { return settings_.partitioner.peScramblerDispatcherVa; }
1211  virtual void peScramblerDispatcherVa(rose_addr_t va) { settings_.partitioner.peScramblerDispatcherVa = va; }
1221  size_t findingIntraFunctionCode() const /*final*/ { return settings_.partitioner.findingIntraFunctionCode; }
1222  virtual void findingIntraFunctionCode(size_t n) { settings_.partitioner.findingIntraFunctionCode = n; }
1231  bool findingIntraFunctionData() const /*final*/ { return settings_.partitioner.findingIntraFunctionData; }
1232  virtual void findingIntraFunctionData(bool b) { settings_.partitioner.findingIntraFunctionData = b; }
1241  const AddressInterval& interruptVector() const /*final*/ { return settings_.partitioner.interruptVector; }
1242  virtual void interruptVector(const AddressInterval &i) { settings_.partitioner.interruptVector = i; }
1251  bool doingPostAnalysis() const /*final*/ { return settings_.partitioner.doingPostAnalysis; }
1252  virtual void doingPostAnalysis(bool b) { settings_.partitioner.doingPostAnalysis = b; }
1260  bool doingPostFunctionMayReturn() const /*final*/ { return settings_.partitioner.doingPostFunctionMayReturn; }
1261  virtual void doingPostFunctionMayReturn(bool b) { settings_.partitioner.doingPostFunctionMayReturn = b; }
1269  bool doingPostFunctionStackDelta() const /*final*/ { return settings_.partitioner.doingPostFunctionStackDelta; }
1270  virtual void doingPostFunctionStackDelta(bool b) { settings_.partitioner.doingPostFunctionStackDelta = b; }
1278  bool doingPostCallingConvention() const /*final*/ { return settings_.partitioner.doingPostCallingConvention; }
1279  virtual void doingPostCallingConvention(bool b) { settings_.partitioner.doingPostCallingConvention = b; }
1288  bool doingPostFunctionNoop() const /*final*/ { return settings_.partitioner.doingPostFunctionNoop; }
1289  virtual void doingPostFunctionNoop(bool b) { settings_.partitioner.doingPostFunctionNoop = b; }
1298  FunctionReturnAnalysis functionReturnAnalysis() const /*final*/ { return settings_.partitioner.functionReturnAnalysis; }
1299  virtual void functionReturnAnalysis(FunctionReturnAnalysis x) { settings_.partitioner.functionReturnAnalysis = x; }
1314  size_t functionReturnAnalysisMaxSorts() const /*final*/ { return settings_.partitioner.functionReturnAnalysisMaxSorts; }
1315  virtual void functionReturnAnalysisMaxSorts(size_t n) { settings_.partitioner.functionReturnAnalysisMaxSorts = n; }
1324  bool findingInterFunctionCalls() const /*final*/ { return settings_.partitioner.findingInterFunctionCalls; }
1325  virtual void findingInterFunctionCalls(bool b) { settings_.partitioner.findingInterFunctionCalls = b; }
1334  bool findingDataFunctionPointers() const /*final*/ { return settings_.partitioner.findingDataFunctionPointers; }
1335  virtual void findingDataFunctionPointers(bool b) { settings_.partitioner.findingDataFunctionPointers = b; }
1344  bool findingCodeFunctionPointers() const /*final*/ { return settings_.partitioner.findingCodeFunctionPointers; }
1345  virtual void findingCodeFunctionPointers(bool b) { settings_.partitioner.findingCodeFunctionPointers = b; }
1353  bool checkingCallBranch() const /*final*/ { return settings_.partitioner.base.checkingCallBranch; }
1354  virtual void checkingCallBranch(bool b) { settings_.partitioner.base.checkingCallBranch = b; }
1368  bool basicBlockSemanticsAutoDrop() const /*final*/ { return settings_.partitioner.base.basicBlockSemanticsAutoDrop; }
1369  void basicBlockSemanticsAutoDrop(bool b) { settings_.partitioner.base.basicBlockSemanticsAutoDrop = b; }
1377  const std::vector<std::string>& configurationNames() /*final*/ const { return settings_.engine.configurationNames; }
1378  std::vector<std::string>& configurationNames() /*final*/ { return settings_.engine.configurationNames; }
1386  bool namingConstants() const /*final*/ { return settings_.partitioner.namingConstants; }
1387  virtual void namingConstants(bool b) { settings_.partitioner.namingConstants = b; }
1395  bool namingStrings() const /*final*/ { return settings_.partitioner.namingStrings; }
1396  virtual void namingStrings(bool b) { settings_.partitioner.namingStrings = b; }
1405  bool namingSystemCalls() const /*final*/ { return settings_.partitioner.namingSyscalls; }
1406  virtual void namingSystemCalls(bool b) { settings_.partitioner.namingSyscalls = b; }
1416  const boost::filesystem::path& systemCallHeader() const /*final*/ { return settings_.partitioner.syscallHeader; }
1417  virtual void systemCallHeader(const boost::filesystem::path &filename) { settings_.partitioner.syscallHeader = filename; }
1426  bool demangleNames() const /*final*/ { return settings_.partitioner.demangleNames; }
1427  virtual void demangleNames(bool b) { settings_.partitioner.demangleNames = b; }
1436  bool astAllowEmptyGlobalBlock() const /*final*/ { return settings_.astConstruction.allowEmptyGlobalBlock; }
1437  virtual void astAllowEmptyGlobalBlock(bool b) { settings_.astConstruction.allowEmptyGlobalBlock = b; }
1446  bool astAllowFunctionWithNoBasicBlocks() const /*final*/ {
1447  return settings_.astConstruction.allowFunctionWithNoBasicBlocks;
1448  }
1449  virtual void astAllowFunctionWithNoBasicBlocks(bool b) {
1450  settings_.astConstruction.allowFunctionWithNoBasicBlocks = b;
1451  }
1460  bool astAllowEmptyBasicBlock() const /*final*/ { return settings_.astConstruction.allowEmptyBasicBlocks; }
1461  virtual void astAllowEmptyBasicBlock(bool b) { settings_.astConstruction.allowEmptyBasicBlocks = b; }
1473  bool astCopyAllInstructions() const /*final*/ { return settings_.astConstruction.copyAllInstructions; }
1474  virtual void astCopyAllInstructions(bool b) { settings_.astConstruction.copyAllInstructions = b; }
1477  // Python API support functions
1480 #ifdef ROSE_ENABLE_PYTHON_API
1481 
1482  // Similar to frontend, but returns a partitioner rather than an AST since the Python API doesn't yet support ASTs.
1483  Partitioner pythonParseVector(boost::python::list &pyArgs, const std::string &purpose, const std::string &description);
1484  Partitioner pythonParseSingle(const std::string &specimen, const std::string &purpose, const std::string &description);
1485 
1486 #endif
1487 
1489  // Internal stuff
1491 private:
1492  void init();
1493 };
1494 
1495 } // namespace
1496 } // namespace
1497 } // namespace
1498 
1499 #endif
size_t maxBasicBlockSize() const
Property: Maximum size for basic blocks.
Definition: Engine.h:1160
const Settings & settings() const
Property: All settings.
Definition: Engine.h:951
bool doingPostFunctionStackDelta() const
Property: Whether to run the function stack delta analysis.
Definition: Engine.h:1269
virtual void linkObjectFiles(bool b)
Property: Link object files.
Definition: Engine.h:1052
virtual void memoryIsExecutable(bool b)
Property: Global adjustment to executability.
Definition: Engine.h:1039
virtual void systemCallHeader(const boost::filesystem::path &filename)
Property: Header file in which system calls are defined.
Definition: Engine.h:1417
size_t findingIntraFunctionCode() const
Property: Whether to find intra-function code.
Definition: Engine.h:1221
virtual void disassembler(Disassembler *d)
Property: Disassembler.
Definition: Engine.h:1087
bool checkingCallBranch() const
Property: Whether to look for function calls used as branches.
Definition: Engine.h:1353
virtual void maxBasicBlockSize(size_t n)
Property: Maximum size for basic blocks.
Definition: Engine.h:1161
Settings for controling the engine behavior.
Definition: BasicTypes.h:415
virtual void namingStrings(bool b)
Property: Give names to string literal addresses.
Definition: Engine.h:1396
MemoryDataAdjustment
How the partitioner should globally treat memory.
Definition: BasicTypes.h:170
bool findingInterFunctionCalls() const
Property: Whether to search for function calls between exiting functions.
Definition: Engine.h:1324
Instruction basic block.
Progress::Ptr progress() const
Property: progress reporting.
Definition: Engine.h:972
Base class for adjusting basic blocks during discovery.
Definition: Modules.h:38
virtual void followingGhostEdges(bool b)
Property: Whether to follow ghost edges.
Definition: Engine.h:1139
virtual void interruptVector(const AddressInterval &i)
Property: Location of machine interrupt vector.
Definition: Engine.h:1242
virtual void astCopyAllInstructions(bool b)
Property: Whether to copy instructions when building the AST.
Definition: Engine.h:1474
bool namingStrings() const
Property: Give names to string literal addresses.
Definition: Engine.h:1395
bool findingDeadCode() const
Property: Whether to find dead code.
Definition: Engine.h:1200
virtual void findingCodeFunctionPointers(bool b)
Property: Whether to search existing instructions for function pointers.
Definition: Engine.h:1345
size_t functionReturnAnalysisMaxSorts() const
Property: Maximum number of function may-return sorting operations.
Definition: Engine.h:1314
const std::vector< std::string > & configurationNames() const
Property: Configuration files.
Definition: Engine.h:1377
virtual void doingPostFunctionNoop(bool b)
Property: Whether to run no-op function analysis.
Definition: Engine.h:1289
Settings that control the disassembler.
Definition: BasicTypes.h:240
Base class for engines driving the partitioner.
Definition: Engine.h:106
Engine(const Settings &settings)
Construct engine with settings.
Definition: Engine.h:242
The result from parsing a command line.
bool namingConstants() const
Property: Give names to constants.
Definition: Engine.h:1386
Disassembler * disassembler() const
Property: Disassembler.
Definition: Engine.h:1086
virtual void exitOnError(bool b)
Property: Error handling.
Definition: Engine.h:964
virtual void peScramblerDispatcherVa(rose_addr_t va)
Property: PE-Scrambler dispatcher address.
Definition: Engine.h:1211
SemanticMemoryParadigm semanticMemoryParadigm() const
Property: Type of container for semantic memory.
Definition: Engine.h:1126
List of things to work on.
Definition: WorkLists.h:58
FunctionReturnAnalysis functionReturnAnalysis() const
Property: Whether to run the function may-return analysis.
Definition: Engine.h:1298
size_t deExecuteZerosLeaveAtBack() const
Property: when to remove execute permission from zero bytes.
Definition: Engine.h:1011
const std::string & isaName() const
Property: Instruction set architecture name.
Definition: Engine.h:1096
virtual void findingIntraFunctionData(bool b)
Property: Whether to find intra-function data.
Definition: Engine.h:1232
Settings & settings()
Property: All settings.
Definition: Engine.h:952
A collection of related switch declarations.
MemoryDataAdjustment memoryDataAdjustment() const
Property: Global adjustments to memory map data access bits.
Definition: Engine.h:1027
bool linkObjectFiles() const
Property: Link object files.
Definition: Engine.h:1051
virtual void findingDataFunctionPointers(bool b)
Property: Whether to search static data for function pointers.
Definition: Engine.h:1335
virtual void isaName(const std::string &s)
Property: Instruction set architecture name.
Definition: Engine.h:1097
virtual void memoryMap(const MemoryMap::Ptr &m)
Property: memory map.
Definition: Engine.h:535
Main namespace for the ROSE library.
Settings for loading specimens.
Definition: BasicTypes.h:185
Settings that control building the AST.
Definition: BasicTypes.h:81
bool followingGhostEdges() const
Property: Whether to follow ghost edges.
Definition: Engine.h:1138
bool demangleNames() const
Property: Demangle names.
Definition: Engine.h:1426
bool astAllowEmptyGlobalBlock() const
Property: Whether to allow empty global block in the AST.
Definition: Engine.h:1436
bool findingFunctionPadding() const
Property: Whether to find function padding.
Definition: Engine.h:1170
bool doingPostCallingConvention() const
Property: Whether to run calling-convention analysis.
Definition: Engine.h:1278
bool discontiguousBlocks() const
Property: Whether to allow discontiguous basic blocks.
Definition: Engine.h:1149
virtual void namingConstants(bool b)
Property: Give names to constants.
Definition: Engine.h:1387
bool findingIntraFunctionData() const
Property: Whether to find intra-function data.
Definition: Engine.h:1231
virtual void findingIntraFunctionCode(size_t n)
Property: Whether to find intra-function code.
Definition: Engine.h:1222
virtual void astAllowEmptyGlobalBlock(bool b)
Property: Whether to allow empty global block in the AST.
Definition: Engine.h:1437
bool memoryIsExecutable() const
Property: Global adjustment to executability.
Definition: Engine.h:1038
bool doingPostFunctionMayReturn() const
Property: Whether to run the function may-return analysis.
Definition: Engine.h:1260
virtual void doingPostFunctionStackDelta(bool b)
Property: Whether to run the function stack delta analysis.
Definition: Engine.h:1270
virtual void findingThunks(bool b)
Property: Whether to find thunk patterns.
Definition: Engine.h:1181
virtual void usingSemantics(bool b)
Property: Whether to use instruction semantics.
Definition: Engine.h:1117
virtual void findingFunctionPadding(bool b)
Property: Whether to find function padding.
Definition: Engine.h:1171
size_t deExecuteZerosLeaveAtFront() const
Property: when to remove execute permission from zero bytes.
Definition: Engine.h:1009
bool astAllowFunctionWithNoBasicBlocks() const
Property: Whether to allow empty functions in the AST.
Definition: Engine.h:1446
bool namingSystemCalls() const
Property: Give names to system calls.
Definition: Engine.h:1405
virtual void astAllowEmptyBasicBlock(bool b)
Property: Whether to allow empty basic blocks in the AST.
Definition: Engine.h:1461
The parser for a program command line.
virtual void semanticMemoryParadigm(SemanticMemoryParadigm p)
Property: Type of container for semantic memory.
Definition: Engine.h:1127
virtual void interpretation(SgAsmInterpretation *interp)
Property: interpretation.
Definition: Engine.h:984
const AddressInterval & interruptVector() const
Property: Location of machine interrupt vector.
Definition: Engine.h:1241
Settings that control the engine partitioning.
Definition: BasicTypes.h:299
virtual void deExecuteZerosLeaveAtBack(size_t n)
Property: when to remove execute permission from zero bytes.
Definition: Engine.h:1012
std::vector< std::string > & configurationNames()
Property: Configuration files.
Definition: Engine.h:1378
bool findingDataFunctionPointers() const
Property: Whether to search static data for function pointers.
Definition: Engine.h:1334
DisassemblerSettings disassembler
Settings for creating the disassembler.
Definition: Engine.h:113
SemanticMemoryParadigm
Organization of semantic memory.
Definition: BasicTypes.h:72
virtual void findingDeadCode(bool b)
Property: Whether to find dead code.
Definition: Engine.h:1201
bool findingCodeFunctionPointers() const
Property: Whether to search existing instructions for function pointers.
Definition: Engine.h:1344
virtual void deExecuteZerosThreshold(size_t n)
Property: when to remove execute permission from zero bytes.
Definition: Engine.h:1008
FunctionReturnAnalysis
Controls whether the function may-return analysis runs.
Definition: BasicTypes.h:255
SgAsmInterpretation * interpretation() const
Property: interpretation.
Definition: Engine.h:983
virtual void checkingCallBranch(bool b)
Property: Whether to look for function calls used as branches.
Definition: Engine.h:1354
AstConstructionSettings astConstruction
Settings for constructing the AST.
Definition: Engine.h:116
bool astCopyAllInstructions() const
Property: Whether to copy instructions when building the AST.
Definition: Engine.h:1473
size_t deExecuteZerosThreshold() const
Property: when to remove execute permission from zero bytes.
Definition: Engine.h:1007
virtual void demangleNames(bool b)
Property: Demangle names.
Definition: Engine.h:1427
bool doingPostAnalysis() const
Property: Whether to perform post-partitioning analysis steps.
Definition: Engine.h:1251
bool usingSemantics() const
Property: Whether to use instruction semantics.
Definition: Engine.h:1116
void basicBlockSemanticsAutoDrop(bool b)
Property: Automatically drop semantics for attached basic blocks.
Definition: Engine.h:1369
MemoryMap::Ptr memoryMap() const
Property: memory map.
Definition: Engine.h:534
bool exitOnError() const
Property: Error handling.
Definition: Engine.h:963
bool doingPostFunctionNoop() const
Property: Whether to run no-op function analysis.
Definition: Engine.h:1288
const boost::filesystem::path & systemCallHeader() const
Property: Header file in which system calls are defined.
Definition: Engine.h:1416
A general, thread-safe way to report progress made on some task.
Definition: Progress.h:164
virtual void splittingThunks(bool b)
Property: Whether to split thunk instructions into mini functions.
Definition: Engine.h:1191
virtual void astAllowFunctionWithNoBasicBlocks(bool b)
Property: Whether to allow empty functions in the AST.
Definition: Engine.h:1449
bool linkStaticArchives() const
Property: Link library archives.
Definition: Engine.h:1064
bool astAllowEmptyBasicBlock() const
Property: Whether to allow empty basic blocks in the AST.
Definition: Engine.h:1460
virtual void deExecuteZerosLeaveAtFront(size_t n)
Property: when to remove execute permission from zero bytes.
Definition: Engine.h:1010
Base class for loading a static or dynamic object.
Definition: BinaryLoader.h:48
rose_addr_t peScramblerDispatcherVa() const
Property: PE-Scrambler dispatcher address.
Definition: Engine.h:1210
virtual void binaryLoader(BinaryLoader *loader)
Property: binary loader.
Definition: Engine.h:994
virtual void linkerCommand(const std::string &cmd)
Property: Linker command.
Definition: Engine.h:1077
virtual void findingInterFunctionCalls(bool b)
Property: Whether to search for function calls between exiting functions.
Definition: Engine.h:1325
PartitionerSettings partitioner
Settings for creating a partitioner.
Definition: Engine.h:114
LoaderSettings loader
Settings used during specimen loading.
Definition: Engine.h:112
virtual void doingPostCallingConvention(bool b)
Property: Whether to run calling-convention analysis.
Definition: Engine.h:1279
virtual void namingSystemCalls(bool b)
Property: Give names to system calls.
Definition: Engine.h:1406
virtual void discontiguousBlocks(bool b)
Property: Whether to allow discontiguous basic blocks.
Definition: Engine.h:1150
bool findingThunks() const
Property: Whether to find thunk patterns.
Definition: Engine.h:1180
Partitions instructions into basic blocks and functions.
Definition: Partitioner.h:293
virtual void doingPostFunctionMayReturn(bool b)
Property: Whether to run the function may-return analysis.
Definition: Engine.h:1261
Virtual base class for instruction disassemblers.
Definition: Disassembler.h:42
Represents an interpretation of a binary container.
virtual void functionReturnAnalysis(FunctionReturnAnalysis x)
Property: Whether to run the function may-return analysis.
Definition: Engine.h:1299
EngineSettings engine
Settings that control engine behavior.
Definition: Engine.h:115
const std::vector< rose_addr_t > & startingVas() const
Property: Starting addresses for disassembly.
Definition: Engine.h:1106
bool basicBlockSemanticsAutoDrop() const
Property: Automatically drop semantics for attached basic blocks.
Definition: Engine.h:1368
virtual void linkStaticArchives(bool b)
Property: Link library archives.
Definition: Engine.h:1065
Container associating values with keys.
Definition: Sawyer/Map.h:66
virtual void functionReturnAnalysisMaxSorts(size_t n)
Property: Maximum number of function may-return sorting operations.
Definition: Engine.h:1315
std::vector< rose_addr_t > & startingVas()
Property: Starting addresses for disassembly.
Definition: Engine.h:1107
virtual void doingPostAnalysis(bool b)
Property: Whether to perform post-partitioning analysis steps.
Definition: Engine.h:1252
virtual void progress(const Progress::Ptr &progress)
Property: progress reporting.
Definition: Engine.h:973
BinaryLoader * binaryLoader() const
Property: binary loader.
Definition: Engine.h:993
Sawyer::SharedPointer< Progress > Ptr
Progress objects are reference counted.
Definition: Progress.h:167
virtual void memoryDataAdjustment(MemoryDataAdjustment x)
Property: Global adjustments to memory map data access bits.
Definition: Engine.h:1028
Holds configuration information.
Definition: Config.h:210
const std::string & linkerCommand() const
Property: Linker command.
Definition: Engine.h:1076
bool splittingThunks() const
Property: Whether to split thunk instructions into mini functions.
Definition: Engine.h:1190