ROSE  0.9.10.103
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/ModulesLinux.h>
10 #include <Partitioner2/Partitioner.h>
11 #include <Partitioner2/Utility.h>
12 #include <Progress.h>
13 #include <Sawyer/DistinctList.h>
14 
15 #ifdef ROSE_ENABLE_PYTHON_API
16 #undef slots // stupid Qt pollution
17 #include <boost/python.hpp>
18 #endif
19 
20 namespace Rose {
21 namespace BinaryAnalysis {
22 namespace Partitioner2 {
23 
107 class ROSE_DLL_API Engine: private boost::noncopyable {
108 public:
112  struct Settings {
119  private:
120  friend class boost::serialization::access;
121 
122  template<class S>
123  void serialize(S &s, unsigned version) {
124  s & loader & disassembler & partitioner & engine & astConstruction;
125  }
126  };
127 
129  // Internal data structures
131 private:
132  // Engine callback for handling instructions added to basic blocks. This is called when a basic block is discovered,
133  // before it's attached to a partitioner, so it shouldn't really be modifying any state in the engine, but rather only
134  // preparing the basic block to be processed.
135  class BasicBlockFinalizer: public BasicBlockCallback {
136  typedef Sawyer::Container::Map<rose_addr_t /*target*/, std::vector<rose_addr_t> /*sources*/> WorkList;
137  public:
138  static Ptr instance() { return Ptr(new BasicBlockFinalizer); }
139  virtual bool operator()(bool chain, const Args &args) ROSE_OVERRIDE;
140  private:
141  void fixFunctionReturnEdge(const Args&);
142  void fixFunctionCallEdges(const Args&);
143  void addPossibleIndeterminateEdge(const Args&);
144  };
145 
146  // Basic blocks that need to be worked on next. These lists are adjusted whenever a new basic block (or placeholder) is
147  // inserted or erased from the CFG.
148  class BasicBlockWorkList: public CfgAdjustmentCallback {
149  // The following lists are used for adding outgoing E_CALL_RETURN edges to basic blocks based on whether the basic
150  // block is a call to a function that might return. When a new basic block is inserted into the CFG (or a previous
151  // block is removed, modified, and re-inserted), the operator() is called and conditionally inserts the block into the
152  // "pendingCallReturn" list (if the block is a function call that lacks an E_CALL_RETURN edge and the function is known
153  // to return or the analysis was incomplete).
154  //
155  // When we run out of other ways to create basic blocks, we process the pendingCallReturn list from back to front. If
156  // the back block (which gets popped) has a positive may-return result then an E_CALL_RETURN edge is added to the CFG
157  // and the normal recursive BB discovery is resumed. Otherwise if the analysis is incomplete the basic block is moved
158  // to the processedCallReturn list. The entire pendingCallReturn list is processed before proceeding.
159  //
160  // If there is no more pendingCallReturn work to be done, then the processedCallReturn blocks are moved to the
161  // finalCallReturn list and finalCallReturn is sorted by approximate CFG height (i.e., leafs first). The contents
162  // of the finalCallReturn list is then analyzed and the result (or the default may-return value for failed analyses)
163  // is used to decide whether a new CFG edge should be created, possibly adding new basic block addresses to the
164  // list of undiscovered blocks.
165  //
166  Sawyer::Container::DistinctList<rose_addr_t> pendingCallReturn_; // blocks that might need an E_CALL_RETURN edge
167  Sawyer::Container::DistinctList<rose_addr_t> processedCallReturn_; // call sites whose may-return was indeterminate
168  Sawyer::Container::DistinctList<rose_addr_t> finalCallReturn_; // indeterminate call sites awaiting final analysis
169 
170  Sawyer::Container::DistinctList<rose_addr_t> undiscovered_; // undiscovered basic block list (last-in-first-out)
171  Engine *engine_; // engine to which this callback belongs
172  size_t maxSorts_; // max sorts before using unsorted lists
173  protected:
174  BasicBlockWorkList(Engine *engine, size_t maxSorts): engine_(engine), maxSorts_(maxSorts) {}
175  public:
177  static Ptr instance(Engine *engine, size_t maxSorts) { return Ptr(new BasicBlockWorkList(engine, maxSorts)); }
178  virtual bool operator()(bool chain, const AttachedBasicBlock &args) ROSE_OVERRIDE;
179  virtual bool operator()(bool chain, const DetachedBasicBlock &args) ROSE_OVERRIDE;
180  Sawyer::Container::DistinctList<rose_addr_t>& pendingCallReturn() { return pendingCallReturn_; }
181  Sawyer::Container::DistinctList<rose_addr_t>& processedCallReturn() { return processedCallReturn_; }
182  Sawyer::Container::DistinctList<rose_addr_t>& finalCallReturn() { return finalCallReturn_; }
183  Sawyer::Container::DistinctList<rose_addr_t>& undiscovered() { return undiscovered_; }
184  void moveAndSortCallReturn(const Partitioner&);
185  };
186 
187  // A work list providing constants from instructions that are part of the CFG.
188  class CodeConstants: public CfgAdjustmentCallback {
189  public:
191 
192  private:
193  std::set<rose_addr_t> toBeExamined_; // instructions waiting to be examined
194  std::set<rose_addr_t> wasExamined_; // instructions we've already examined
195  rose_addr_t inProgress_; // instruction that is currently in progress
196  std::vector<rose_addr_t> constants_; // constants for the instruction in progress
197 
198  protected:
199  CodeConstants(): inProgress_(0) {}
200 
201  public:
202  static Ptr instance() { return Ptr(new CodeConstants); }
203 
204  // Possibly insert more instructions into the work list when a basic block is added to the CFG
205  virtual bool operator()(bool chain, const AttachedBasicBlock &attached) ROSE_OVERRIDE;
206 
207  // Possibly remove instructions from the worklist when a basic block is removed from the CFG
208  virtual bool operator()(bool chain, const DetachedBasicBlock &detached) ROSE_OVERRIDE;
209 
210  // Return the next available constant if any.
211  Sawyer::Optional<rose_addr_t> nextConstant(const Partitioner &partitioner);
212 
213  // Address of instruction being examined.
214  rose_addr_t inProgress() const { return inProgress_; }
215  };
216 
218  // Data members
220 private:
221  Settings settings_; // Settings for the partitioner.
222  SgAsmInterpretation *interp_; // interpretation set by loadSpecimen
223  BinaryLoader *binaryLoader_; // how to remap, link, and fixup
224  Disassembler *disassembler_; // not ref-counted yet, but don't destroy it since user owns it
225  MemoryMap::Ptr map_; // memory map initialized by load()
226  BasicBlockWorkList::Ptr basicBlockWorkList_; // what blocks to work on next
227  CodeConstants::Ptr codeFunctionPointers_; // generates constants that are found in instruction ASTs
228  Progress::Ptr progress_; // optional progress reporting
229  ModulesLinux::LibcStartMain::Ptr libcStartMain_; // looking for "main" by analyzing libc_start_main?
230 
232  // Constructors
234 public:
237  : interp_(NULL), binaryLoader_(NULL), disassembler_(NULL),
238  basicBlockWorkList_(BasicBlockWorkList::instance(this, settings_.partitioner.functionReturnAnalysisMaxSorts)),
239  progress_(Progress::instance()) {
240  init();
241  }
242 
244  explicit Engine(const Settings &settings)
245  : settings_(settings), interp_(NULL), binaryLoader_(NULL), disassembler_(NULL),
246  basicBlockWorkList_(BasicBlockWorkList::instance(this, settings_.partitioner.functionReturnAnalysisMaxSorts)),
247  progress_(Progress::instance()) {
248  init();
249  }
250 
251  virtual ~Engine() {}
252 
254  // The very top-level use case
256 public:
281  SgAsmBlock* frontend(int argc, char *argv[],
282  const std::string &purpose, const std::string &description);
283  virtual SgAsmBlock* frontend(const std::vector<std::string> &args,
284  const std::string &purpose, const std::string &description);
287  // Basic top-level steps
290 public:
296  void reset();
297 
324  Sawyer::CommandLine::ParserResult parseCommandLine(int argc, char *argv[],
325  const std::string &purpose, const std::string &description) /*final*/;
326  virtual Sawyer::CommandLine::ParserResult parseCommandLine(const std::vector<std::string> &args,
327  const std::string &purpose, const std::string &description);
349  virtual SgAsmInterpretation* parseContainers(const std::vector<std::string> &fileNames);
350  SgAsmInterpretation* parseContainers(const std::string &fileName) /*final*/;
373  virtual MemoryMap::Ptr loadSpecimens(const std::vector<std::string> &fileNames = std::vector<std::string>());
374  MemoryMap::Ptr loadSpecimens(const std::string &fileName) /*final*/;
396  virtual Partitioner partition(const std::vector<std::string> &fileNames = std::vector<std::string>());
397  Partitioner partition(const std::string &fileName) /*final*/;
414  SgAsmBlock* buildAst(const std::vector<std::string> &fileNames = std::vector<std::string>()) /*final*/;
415  SgAsmBlock* buildAst(const std::string &fileName) /*final*/;
418  // Command-line parsing
420  //
421  // top-level: parseCommandLine
423 public:
425  virtual Sawyer::CommandLine::SwitchGroup loaderSwitches();
426 
428  virtual Sawyer::CommandLine::SwitchGroup disassemblerSwitches();
429 
431  virtual Sawyer::CommandLine::SwitchGroup partitionerSwitches();
432 
434  virtual Sawyer::CommandLine::SwitchGroup engineSwitches();
435 
437  virtual Sawyer::CommandLine::SwitchGroup astConstructionSwitches();
438 
440  static std::string specimenNameDocumentation();
441 
453  virtual Sawyer::CommandLine::Parser commandLineParser(const std::string &purpose, const std::string &description);
454 
461  virtual void checkSettings();
462 
464  // Container parsing
465  //
466  // top-level: parseContainers
468 public:
473  virtual bool isNonContainer(const std::string&);
474 
480  virtual bool areContainersParsed() const;
481 
483  // Load specimens
484  //
485  // top-level: loadSpecimens
487 public:
491  virtual bool areSpecimensLoaded() const;
492 
508  virtual BinaryLoader *obtainLoader(BinaryLoader *hint=NULL);
509 
515  virtual void loadContainers(const std::vector<std::string> &fileNames);
516 
521  virtual void loadNonContainers(const std::vector<std::string> &names);
522 
526  virtual void adjustMemoryMap();
527 
536  MemoryMap::Ptr memoryMap() const /*final*/ { return map_; }
537  virtual void memoryMap(const MemoryMap::Ptr &m) { map_ = m; }
541  // Disassembler
544 public:
561  virtual Disassembler* obtainDisassembler(Disassembler *hint=NULL);
565  // Partitioner high-level functions
567  //
568  // top-level: partition
570 public:
572  virtual void checkCreatePartitionerPrerequisites() const;
573 
580  virtual Partitioner createBarePartitioner();
581 
587  virtual Partitioner createGenericPartitioner();
588 
593  virtual Partitioner createTunedPartitioner();
594 
599  virtual Partitioner createPartitionerFromAst(SgAsmInterpretation*);
600 
605  virtual Partitioner createPartitioner();
606 
610  virtual void runPartitionerInit(Partitioner&);
611 
615  virtual void runPartitionerRecursive(Partitioner&);
616 
621  virtual void runPartitionerFinal(Partitioner&);
622 
628  virtual void runPartitioner(Partitioner&);
629 
630 
632  // Partitioner mid-level functions
633  //
634  // These are the functions called by the partitioner high-level stuff. These are sometimes overridden in subclasses,
635  // although it is more likely that the high-level stuff is overridden.
637 public:
642  virtual void labelAddresses(Partitioner&);
643 
647  virtual std::vector<DataBlock::Ptr> makeConfiguredDataBlocks(Partitioner&, const Configuration&);
648 
652  virtual std::vector<Function::Ptr> makeConfiguredFunctions(Partitioner&, const Configuration&);
653 
660  virtual std::vector<Function::Ptr> makeEntryFunctions(Partitioner&, SgAsmInterpretation*);
661 
668  virtual std::vector<Function::Ptr> makeErrorHandlingFunctions(Partitioner&, SgAsmInterpretation*);
669 
679  virtual std::vector<Function::Ptr> makeImportFunctions(Partitioner&, SgAsmInterpretation*);
680 
687  virtual std::vector<Function::Ptr> makeExportFunctions(Partitioner&, SgAsmInterpretation*);
688 
695  virtual std::vector<Function::Ptr> makeSymbolFunctions(Partitioner&, SgAsmInterpretation*);
696 
704  virtual std::vector<Function::Ptr> makeContainerFunctions(Partitioner&, SgAsmInterpretation*);
705 
712  virtual std::vector<Function::Ptr> makeInterruptVectorFunctions(Partitioner&, const AddressInterval &vector);
713 
718  virtual std::vector<Function::Ptr> makeUserFunctions(Partitioner&, const std::vector<rose_addr_t>&);
719 
726  virtual void discoverBasicBlocks(Partitioner&);
727 
739  virtual Function::Ptr makeNextDataReferencedFunction(const Partitioner&, rose_addr_t &startVa /*in,out*/);
740 
754  virtual Function::Ptr makeNextCodeReferencedFunction(const Partitioner&);
755 
762  virtual std::vector<Function::Ptr> makeCalledFunctions(Partitioner&);
763 
776  virtual std::vector<Function::Ptr> makeNextPrologueFunction(Partitioner&, rose_addr_t startVa);
777 
796  virtual std::vector<Function::Ptr>
797  makeFunctionFromInterFunctionCalls(Partitioner &partitioner, rose_addr_t &startVa /*in,out*/);
798 
805  virtual void discoverFunctions(Partitioner&);
806 
821  virtual std::set<rose_addr_t> attachDeadCodeToFunction(Partitioner&, const Function::Ptr&, size_t maxIterations=size_t(-1));
822 
830  virtual DataBlock::Ptr attachPaddingToFunction(Partitioner&, const Function::Ptr&);
831 
836  virtual std::vector<DataBlock::Ptr> attachPaddingToFunctions(Partitioner&);
837 
848  virtual size_t attachAllSurroundedCodeToFunctions(Partitioner&);
849 
857  virtual size_t attachSurroundedCodeToFunctions(Partitioner&);
858 
863  virtual void attachBlocksToFunctions(Partitioner&);
864 
871  virtual std::set<rose_addr_t> attachDeadCodeToFunctions(Partitioner&, size_t maxIterations=size_t(-1));
872 
882  virtual std::vector<DataBlock::Ptr> attachSurroundedDataToFunctions(Partitioner&);
883 
889  virtual void updateAnalysisResults(Partitioner&);
890 
891 
893  // Partitioner low-level functions
894  //
895  // These are functions that a subclass seldom overrides, and maybe even shouldn't override because of their complexity or
896  // the way the interact with one another.
898 public:
909  virtual bool makeNextCallReturnEdge(Partitioner&, boost::logic::tribool assumeCallReturns);
910 
916  virtual BasicBlock::Ptr makeNextBasicBlockFromPlaceholder(Partitioner&);
917 
932  virtual BasicBlock::Ptr makeNextBasicBlock(Partitioner&);
933 
934 
936  // Build AST
938 public:
939  // Used internally by ROSE's ::frontend disassemble instructions to build the AST that goes under each SgAsmInterpretation.
940  static void disassembleForRoseFrontend(SgAsmInterpretation*);
941 
942 
944  // Settings and properties
946 public:
953  const Settings& settings() const /*final*/ { return settings_; }
954  Settings& settings() /*final*/ { return settings_; }
965  bool exitOnError() const /*final*/ { return settings_.engine.exitOnError; }
966  virtual void exitOnError(bool b) { settings_.engine.exitOnError = b; }
974  Progress::Ptr progress() const /*final*/ { return progress_; }
975  virtual void progress(const Progress::Ptr &progress) { progress_ = progress; }
985  SgAsmInterpretation* interpretation() const /*final*/ { return interp_; }
986  virtual void interpretation(SgAsmInterpretation *interp) { interp_ = interp; }
995  BinaryLoader* binaryLoader() const /*final*/ { return binaryLoader_; }
996  virtual void binaryLoader(BinaryLoader *loader) { binaryLoader_ = loader; }
1009  size_t deExecuteZerosThreshold() const /*final*/ { return settings_.loader.deExecuteZerosThreshold; }
1010  virtual void deExecuteZerosThreshold(size_t n) { settings_.loader.deExecuteZerosThreshold = n; }
1011  size_t deExecuteZerosLeaveAtFront() const /*final*/ { return settings_.loader.deExecuteZerosLeaveAtFront; }
1012  virtual void deExecuteZerosLeaveAtFront(size_t n) { settings_.loader.deExecuteZerosLeaveAtFront = n; }
1013  size_t deExecuteZerosLeaveAtBack() const /*final*/ { return settings_.loader.deExecuteZerosLeaveAtBack; }
1014  virtual void deExecuteZerosLeaveAtBack(size_t n) { settings_.loader.deExecuteZerosLeaveAtBack = n; }
1029  MemoryDataAdjustment memoryDataAdjustment() const /*final*/ { return settings_.loader.memoryDataAdjustment; }
1030  virtual void memoryDataAdjustment(MemoryDataAdjustment x) { settings_.loader.memoryDataAdjustment = x; }
1040  bool memoryIsExecutable() const /*final*/ { return settings_.loader.memoryIsExecutable; }
1041  virtual void memoryIsExecutable(bool b) { settings_.loader.memoryIsExecutable = b; }
1053  bool linkObjectFiles() const /*final*/ { return settings_.loader.linkObjectFiles; }
1054  virtual void linkObjectFiles(bool b) { settings_.loader.linkObjectFiles = b; }
1066  bool linkStaticArchives() const /*final*/ { return settings_.loader.linkStaticArchives; }
1067  virtual void linkStaticArchives(bool b) { settings_.loader.linkStaticArchives = b; }
1078  const std::string& linkerCommand() const /*final*/ { return settings_.loader.linker; }
1079  virtual void linkerCommand(const std::string &cmd) { settings_.loader.linker = cmd; }
1088  Disassembler *disassembler() const /*final*/ { return disassembler_; }
1089  virtual void disassembler(Disassembler *d) { disassembler_ = d; }
1098  const std::string& isaName() const /*final*/ { return settings_.disassembler.isaName; }
1099  virtual void isaName(const std::string &s) { settings_.disassembler.isaName = s; }
1108  const std::vector<rose_addr_t>& startingVas() const /*final*/ { return settings_.partitioner.startingVas; }
1109  std::vector<rose_addr_t>& startingVas() /*final*/ { return settings_.partitioner.startingVas; }
1118  bool usingSemantics() const /*final*/ { return settings_.partitioner.base.usingSemantics; }
1119  virtual void usingSemantics(bool b) { settings_.partitioner.base.usingSemantics = b; }
1128  SemanticMemoryParadigm semanticMemoryParadigm() const /*final*/ { return settings_.partitioner.semanticMemoryParadigm; }
1129  virtual void semanticMemoryParadigm(SemanticMemoryParadigm p) { settings_.partitioner.semanticMemoryParadigm = p; }
1140  bool followingGhostEdges() const /*final*/ { return settings_.partitioner.followingGhostEdges; }
1141  virtual void followingGhostEdges(bool b) { settings_.partitioner.followingGhostEdges = b; }
1151  bool discontiguousBlocks() const /*final*/ { return settings_.partitioner.discontiguousBlocks; }
1152  virtual void discontiguousBlocks(bool b) { settings_.partitioner.discontiguousBlocks = b; }
1162  size_t maxBasicBlockSize() const /*final*/ { return settings_.partitioner.maxBasicBlockSize; }
1163  virtual void maxBasicBlockSize(size_t n) { settings_.partitioner.maxBasicBlockSize = n; }
1172  bool findingFunctionPadding() const /*final*/ { return settings_.partitioner.findingFunctionPadding; }
1173  virtual void findingFunctionPadding(bool b) { settings_.partitioner.findingFunctionPadding = b; }
1182  bool findingThunks() const /*final*/ { return settings_.partitioner.findingThunks; }
1183  virtual void findingThunks(bool b) { settings_.partitioner.findingThunks = b; }
1192  bool splittingThunks() const /*final*/ { return settings_.partitioner.splittingThunks; }
1193  virtual void splittingThunks(bool b) { settings_.partitioner.splittingThunks = b; }
1202  bool findingDeadCode() const /*final*/ { return settings_.partitioner.findingDeadCode; }
1203  virtual void findingDeadCode(bool b) { settings_.partitioner.findingDeadCode = b; }
1212  rose_addr_t peScramblerDispatcherVa() const /*final*/ { return settings_.partitioner.peScramblerDispatcherVa; }
1213  virtual void peScramblerDispatcherVa(rose_addr_t va) { settings_.partitioner.peScramblerDispatcherVa = va; }
1223  size_t findingIntraFunctionCode() const /*final*/ { return settings_.partitioner.findingIntraFunctionCode; }
1224  virtual void findingIntraFunctionCode(size_t n) { settings_.partitioner.findingIntraFunctionCode = n; }
1233  bool findingIntraFunctionData() const /*final*/ { return settings_.partitioner.findingIntraFunctionData; }
1234  virtual void findingIntraFunctionData(bool b) { settings_.partitioner.findingIntraFunctionData = b; }
1243  const AddressInterval& interruptVector() const /*final*/ { return settings_.partitioner.interruptVector; }
1244  virtual void interruptVector(const AddressInterval &i) { settings_.partitioner.interruptVector = i; }
1253  bool doingPostAnalysis() const /*final*/ { return settings_.partitioner.doingPostAnalysis; }
1254  virtual void doingPostAnalysis(bool b) { settings_.partitioner.doingPostAnalysis = b; }
1262  bool doingPostFunctionMayReturn() const /*final*/ { return settings_.partitioner.doingPostFunctionMayReturn; }
1263  virtual void doingPostFunctionMayReturn(bool b) { settings_.partitioner.doingPostFunctionMayReturn = b; }
1271  bool doingPostFunctionStackDelta() const /*final*/ { return settings_.partitioner.doingPostFunctionStackDelta; }
1272  virtual void doingPostFunctionStackDelta(bool b) { settings_.partitioner.doingPostFunctionStackDelta = b; }
1280  bool doingPostCallingConvention() const /*final*/ { return settings_.partitioner.doingPostCallingConvention; }
1281  virtual void doingPostCallingConvention(bool b) { settings_.partitioner.doingPostCallingConvention = b; }
1290  bool doingPostFunctionNoop() const /*final*/ { return settings_.partitioner.doingPostFunctionNoop; }
1291  virtual void doingPostFunctionNoop(bool b) { settings_.partitioner.doingPostFunctionNoop = b; }
1300  FunctionReturnAnalysis functionReturnAnalysis() const /*final*/ { return settings_.partitioner.functionReturnAnalysis; }
1301  virtual void functionReturnAnalysis(FunctionReturnAnalysis x) { settings_.partitioner.functionReturnAnalysis = x; }
1316  size_t functionReturnAnalysisMaxSorts() const /*final*/ { return settings_.partitioner.functionReturnAnalysisMaxSorts; }
1317  virtual void functionReturnAnalysisMaxSorts(size_t n) { settings_.partitioner.functionReturnAnalysisMaxSorts = n; }
1326  bool findingInterFunctionCalls() const /*final*/ { return settings_.partitioner.findingInterFunctionCalls; }
1327  virtual void findingInterFunctionCalls(bool b) { settings_.partitioner.findingInterFunctionCalls = b; }
1336  bool findingDataFunctionPointers() const /*final*/ { return settings_.partitioner.findingDataFunctionPointers; }
1337  virtual void findingDataFunctionPointers(bool b) { settings_.partitioner.findingDataFunctionPointers = b; }
1346  bool findingCodeFunctionPointers() const /*final*/ { return settings_.partitioner.findingCodeFunctionPointers; }
1347  virtual void findingCodeFunctionPointers(bool b) { settings_.partitioner.findingCodeFunctionPointers = b; }
1355  bool checkingCallBranch() const /*final*/ { return settings_.partitioner.base.checkingCallBranch; }
1356  virtual void checkingCallBranch(bool b) { settings_.partitioner.base.checkingCallBranch = b; }
1370  bool basicBlockSemanticsAutoDrop() const /*final*/ { return settings_.partitioner.base.basicBlockSemanticsAutoDrop; }
1371  void basicBlockSemanticsAutoDrop(bool b) { settings_.partitioner.base.basicBlockSemanticsAutoDrop = b; }
1379  const std::vector<std::string>& configurationNames() /*final*/ const { return settings_.engine.configurationNames; }
1380  std::vector<std::string>& configurationNames() /*final*/ { return settings_.engine.configurationNames; }
1388  bool namingConstants() const /*final*/ { return settings_.partitioner.namingConstants; }
1389  virtual void namingConstants(bool b) { settings_.partitioner.namingConstants = b; }
1397  bool namingStrings() const /*final*/ { return settings_.partitioner.namingStrings; }
1398  virtual void namingStrings(bool b) { settings_.partitioner.namingStrings = b; }
1407  bool namingSystemCalls() const /*final*/ { return settings_.partitioner.namingSyscalls; }
1408  virtual void namingSystemCalls(bool b) { settings_.partitioner.namingSyscalls = b; }
1418  const boost::filesystem::path& systemCallHeader() const /*final*/ { return settings_.partitioner.syscallHeader; }
1419  virtual void systemCallHeader(const boost::filesystem::path &filename) { settings_.partitioner.syscallHeader = filename; }
1428  bool demangleNames() const /*final*/ { return settings_.partitioner.demangleNames; }
1429  virtual void demangleNames(bool b) { settings_.partitioner.demangleNames = b; }
1438  bool astAllowEmptyGlobalBlock() const /*final*/ { return settings_.astConstruction.allowEmptyGlobalBlock; }
1439  virtual void astAllowEmptyGlobalBlock(bool b) { settings_.astConstruction.allowEmptyGlobalBlock = b; }
1448  bool astAllowFunctionWithNoBasicBlocks() const /*final*/ {
1449  return settings_.astConstruction.allowFunctionWithNoBasicBlocks;
1450  }
1451  virtual void astAllowFunctionWithNoBasicBlocks(bool b) {
1452  settings_.astConstruction.allowFunctionWithNoBasicBlocks = b;
1453  }
1462  bool astAllowEmptyBasicBlock() const /*final*/ { return settings_.astConstruction.allowEmptyBasicBlocks; }
1463  virtual void astAllowEmptyBasicBlock(bool b) { settings_.astConstruction.allowEmptyBasicBlocks = b; }
1475  bool astCopyAllInstructions() const /*final*/ { return settings_.astConstruction.copyAllInstructions; }
1476  virtual void astCopyAllInstructions(bool b) { settings_.astConstruction.copyAllInstructions = b; }
1479  // Python API support functions
1482 #ifdef ROSE_ENABLE_PYTHON_API
1483 
1484  // Similar to frontend, but returns a partitioner rather than an AST since the Python API doesn't yet support ASTs.
1485  Partitioner pythonParseVector(boost::python::list &pyArgs, const std::string &purpose, const std::string &description);
1486  Partitioner pythonParseSingle(const std::string &specimen, const std::string &purpose, const std::string &description);
1487 
1488 #endif
1489 
1491  // Internal stuff
1493 private:
1494  void init();
1495 };
1496 
1497 } // namespace
1498 } // namespace
1499 } // namespace
1500 
1501 #endif
size_t maxBasicBlockSize() const
Property: Maximum size for basic blocks.
Definition: Engine.h:1162
const Settings & settings() const
Property: All settings.
Definition: Engine.h:953
bool doingPostFunctionStackDelta() const
Property: Whether to run the function stack delta analysis.
Definition: Engine.h:1271
virtual void linkObjectFiles(bool b)
Property: Link object files.
Definition: Engine.h:1054
virtual void memoryIsExecutable(bool b)
Property: Global adjustment to executability.
Definition: Engine.h:1041
virtual void systemCallHeader(const boost::filesystem::path &filename)
Property: Header file in which system calls are defined.
Definition: Engine.h:1419
size_t findingIntraFunctionCode() const
Property: Whether to find intra-function code.
Definition: Engine.h:1223
virtual void disassembler(Disassembler *d)
Property: Disassembler.
Definition: Engine.h:1089
bool checkingCallBranch() const
Property: Whether to look for function calls used as branches.
Definition: Engine.h:1355
virtual void maxBasicBlockSize(size_t n)
Property: Maximum size for basic blocks.
Definition: Engine.h:1163
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:1398
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:1326
Instruction basic block.
Progress::Ptr progress() const
Property: progress reporting.
Definition: Engine.h:974
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:1141
virtual void interruptVector(const AddressInterval &i)
Property: Location of machine interrupt vector.
Definition: Engine.h:1244
virtual void astCopyAllInstructions(bool b)
Property: Whether to copy instructions when building the AST.
Definition: Engine.h:1476
bool namingStrings() const
Property: Give names to string literal addresses.
Definition: Engine.h:1397
bool findingDeadCode() const
Property: Whether to find dead code.
Definition: Engine.h:1202
virtual void findingCodeFunctionPointers(bool b)
Property: Whether to search existing instructions for function pointers.
Definition: Engine.h:1347
size_t functionReturnAnalysisMaxSorts() const
Property: Maximum number of function may-return sorting operations.
Definition: Engine.h:1316
const std::vector< std::string > & configurationNames() const
Property: Configuration files.
Definition: Engine.h:1379
virtual void doingPostFunctionNoop(bool b)
Property: Whether to run no-op function analysis.
Definition: Engine.h:1291
Settings that control the disassembler.
Definition: BasicTypes.h:240
Base class for engines driving the partitioner.
Definition: Engine.h:107
Engine(const Settings &settings)
Construct engine with settings.
Definition: Engine.h:244
The result from parsing a command line.
bool namingConstants() const
Property: Give names to constants.
Definition: Engine.h:1388
Disassembler * disassembler() const
Property: Disassembler.
Definition: Engine.h:1088
virtual void exitOnError(bool b)
Property: Error handling.
Definition: Engine.h:966
virtual void peScramblerDispatcherVa(rose_addr_t va)
Property: PE-Scrambler dispatcher address.
Definition: Engine.h:1213
SemanticMemoryParadigm semanticMemoryParadigm() const
Property: Type of container for semantic memory.
Definition: Engine.h:1128
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:1300
size_t deExecuteZerosLeaveAtBack() const
Property: when to remove execute permission from zero bytes.
Definition: Engine.h:1013
const std::string & isaName() const
Property: Instruction set architecture name.
Definition: Engine.h:1098
virtual void findingIntraFunctionData(bool b)
Property: Whether to find intra-function data.
Definition: Engine.h:1234
Settings & settings()
Property: All settings.
Definition: Engine.h:954
A collection of related switch declarations.
MemoryDataAdjustment memoryDataAdjustment() const
Property: Global adjustments to memory map data access bits.
Definition: Engine.h:1029
bool linkObjectFiles() const
Property: Link object files.
Definition: Engine.h:1053
virtual void findingDataFunctionPointers(bool b)
Property: Whether to search static data for function pointers.
Definition: Engine.h:1337
Sawyer::SharedPointer< LibcStartMain > Ptr
Shared ownership pointer to LibcStartMain callback.
Definition: ModulesLinux.h:43
virtual void isaName(const std::string &s)
Property: Instruction set architecture name.
Definition: Engine.h:1099
virtual void memoryMap(const MemoryMap::Ptr &m)
Property: memory map.
Definition: Engine.h:537
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:1140
bool demangleNames() const
Property: Demangle names.
Definition: Engine.h:1428
bool astAllowEmptyGlobalBlock() const
Property: Whether to allow empty global block in the AST.
Definition: Engine.h:1438
bool findingFunctionPadding() const
Property: Whether to find function padding.
Definition: Engine.h:1172
bool doingPostCallingConvention() const
Property: Whether to run calling-convention analysis.
Definition: Engine.h:1280
bool discontiguousBlocks() const
Property: Whether to allow discontiguous basic blocks.
Definition: Engine.h:1151
virtual void namingConstants(bool b)
Property: Give names to constants.
Definition: Engine.h:1389
bool findingIntraFunctionData() const
Property: Whether to find intra-function data.
Definition: Engine.h:1233
virtual void findingIntraFunctionCode(size_t n)
Property: Whether to find intra-function code.
Definition: Engine.h:1224
virtual void astAllowEmptyGlobalBlock(bool b)
Property: Whether to allow empty global block in the AST.
Definition: Engine.h:1439
bool memoryIsExecutable() const
Property: Global adjustment to executability.
Definition: Engine.h:1040
bool doingPostFunctionMayReturn() const
Property: Whether to run the function may-return analysis.
Definition: Engine.h:1262
virtual void doingPostFunctionStackDelta(bool b)
Property: Whether to run the function stack delta analysis.
Definition: Engine.h:1272
virtual void findingThunks(bool b)
Property: Whether to find thunk patterns.
Definition: Engine.h:1183
virtual void usingSemantics(bool b)
Property: Whether to use instruction semantics.
Definition: Engine.h:1119
virtual void findingFunctionPadding(bool b)
Property: Whether to find function padding.
Definition: Engine.h:1173
size_t deExecuteZerosLeaveAtFront() const
Property: when to remove execute permission from zero bytes.
Definition: Engine.h:1011
bool astAllowFunctionWithNoBasicBlocks() const
Property: Whether to allow empty functions in the AST.
Definition: Engine.h:1448
bool namingSystemCalls() const
Property: Give names to system calls.
Definition: Engine.h:1407
virtual void astAllowEmptyBasicBlock(bool b)
Property: Whether to allow empty basic blocks in the AST.
Definition: Engine.h:1463
The parser for a program command line.
virtual void semanticMemoryParadigm(SemanticMemoryParadigm p)
Property: Type of container for semantic memory.
Definition: Engine.h:1129
virtual void interpretation(SgAsmInterpretation *interp)
Property: interpretation.
Definition: Engine.h:986
const AddressInterval & interruptVector() const
Property: Location of machine interrupt vector.
Definition: Engine.h:1243
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:1014
std::vector< std::string > & configurationNames()
Property: Configuration files.
Definition: Engine.h:1380
bool findingDataFunctionPointers() const
Property: Whether to search static data for function pointers.
Definition: Engine.h:1336
DisassemblerSettings disassembler
Settings for creating the disassembler.
Definition: Engine.h:114
SemanticMemoryParadigm
Organization of semantic memory.
Definition: BasicTypes.h:72
virtual void findingDeadCode(bool b)
Property: Whether to find dead code.
Definition: Engine.h:1203
bool findingCodeFunctionPointers() const
Property: Whether to search existing instructions for function pointers.
Definition: Engine.h:1346
virtual void deExecuteZerosThreshold(size_t n)
Property: when to remove execute permission from zero bytes.
Definition: Engine.h:1010
FunctionReturnAnalysis
Controls whether the function may-return analysis runs.
Definition: BasicTypes.h:255
SgAsmInterpretation * interpretation() const
Property: interpretation.
Definition: Engine.h:985
virtual void checkingCallBranch(bool b)
Property: Whether to look for function calls used as branches.
Definition: Engine.h:1356
AstConstructionSettings astConstruction
Settings for constructing the AST.
Definition: Engine.h:117
bool astCopyAllInstructions() const
Property: Whether to copy instructions when building the AST.
Definition: Engine.h:1475
size_t deExecuteZerosThreshold() const
Property: when to remove execute permission from zero bytes.
Definition: Engine.h:1009
virtual void demangleNames(bool b)
Property: Demangle names.
Definition: Engine.h:1429
bool doingPostAnalysis() const
Property: Whether to perform post-partitioning analysis steps.
Definition: Engine.h:1253
bool usingSemantics() const
Property: Whether to use instruction semantics.
Definition: Engine.h:1118
void basicBlockSemanticsAutoDrop(bool b)
Property: Automatically drop semantics for attached basic blocks.
Definition: Engine.h:1371
MemoryMap::Ptr memoryMap() const
Property: memory map.
Definition: Engine.h:536
bool exitOnError() const
Property: Error handling.
Definition: Engine.h:965
bool doingPostFunctionNoop() const
Property: Whether to run no-op function analysis.
Definition: Engine.h:1290
const boost::filesystem::path & systemCallHeader() const
Property: Header file in which system calls are defined.
Definition: Engine.h:1418
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:1193
virtual void astAllowFunctionWithNoBasicBlocks(bool b)
Property: Whether to allow empty functions in the AST.
Definition: Engine.h:1451
bool linkStaticArchives() const
Property: Link library archives.
Definition: Engine.h:1066
bool astAllowEmptyBasicBlock() const
Property: Whether to allow empty basic blocks in the AST.
Definition: Engine.h:1462
virtual void deExecuteZerosLeaveAtFront(size_t n)
Property: when to remove execute permission from zero bytes.
Definition: Engine.h:1012
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:1212
virtual void binaryLoader(BinaryLoader *loader)
Property: binary loader.
Definition: Engine.h:996
virtual void linkerCommand(const std::string &cmd)
Property: Linker command.
Definition: Engine.h:1079
virtual void findingInterFunctionCalls(bool b)
Property: Whether to search for function calls between exiting functions.
Definition: Engine.h:1327
PartitionerSettings partitioner
Settings for creating a partitioner.
Definition: Engine.h:115
LoaderSettings loader
Settings used during specimen loading.
Definition: Engine.h:113
virtual void doingPostCallingConvention(bool b)
Property: Whether to run calling-convention analysis.
Definition: Engine.h:1281
virtual void namingSystemCalls(bool b)
Property: Give names to system calls.
Definition: Engine.h:1408
virtual void discontiguousBlocks(bool b)
Property: Whether to allow discontiguous basic blocks.
Definition: Engine.h:1152
bool findingThunks() const
Property: Whether to find thunk patterns.
Definition: Engine.h:1182
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:1263
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:1301
EngineSettings engine
Settings that control engine behavior.
Definition: Engine.h:116
const std::vector< rose_addr_t > & startingVas() const
Property: Starting addresses for disassembly.
Definition: Engine.h:1108
bool basicBlockSemanticsAutoDrop() const
Property: Automatically drop semantics for attached basic blocks.
Definition: Engine.h:1370
virtual void linkStaticArchives(bool b)
Property: Link library archives.
Definition: Engine.h:1067
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:1317
std::vector< rose_addr_t > & startingVas()
Property: Starting addresses for disassembly.
Definition: Engine.h:1109
virtual void doingPostAnalysis(bool b)
Property: Whether to perform post-partitioning analysis steps.
Definition: Engine.h:1254
virtual void progress(const Progress::Ptr &progress)
Property: progress reporting.
Definition: Engine.h:975
BinaryLoader * binaryLoader() const
Property: binary loader.
Definition: Engine.h:995
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:1030
Holds configuration information.
Definition: Config.h:210
const std::string & linkerCommand() const
Property: Linker command.
Definition: Engine.h:1078
bool splittingThunks() const
Property: Whether to split thunk instructions into mini functions.
Definition: Engine.h:1192