ROSE  0.9.10.230
Engine.h
1 #ifndef ROSE_Partitioner2_Engine_H
2 #define ROSE_Partitioner2_Engine_H
3 
4 #include <BinaryLoader.h>
5 #include <BinarySerialIo.h>
6 #include <boost/noncopyable.hpp>
7 #include <Disassembler.h>
8 #include <FileSystem.h>
9 #include <Partitioner2/Function.h>
10 #include <Partitioner2/ModulesLinux.h>
11 #include <Partitioner2/Partitioner.h>
12 #include <Partitioner2/Thunk.h>
13 #include <Partitioner2/Utility.h>
14 #include <Progress.h>
15 #include <RoseException.h>
16 #include <Sawyer/DistinctList.h>
17 #include <stdexcept>
18 
19 #ifdef ROSE_ENABLE_PYTHON_API
20 #undef slots // stupid Qt pollution
21 #include <boost/python.hpp>
22 #endif
23 
24 namespace Rose {
25 namespace BinaryAnalysis {
26 namespace Partitioner2 {
27 
111 class ROSE_DLL_API Engine: private boost::noncopyable {
112 public:
116  struct Settings {
123  private:
124  friend class boost::serialization::access;
125 
126  template<class S>
127  void serialize(S &s, unsigned version) {
128  s & loader & disassembler & partitioner & engine & astConstruction;
129  }
130  };
131 
133  class Exception: public Rose::Exception {
134  public:
135  Exception(const std::string &mesg)
136  : Rose::Exception(mesg) {}
137  ~Exception() throw () {}
138  };
139 
141  // Internal data structures
143 private:
144  // Engine callback for handling instructions added to basic blocks. This is called when a basic block is discovered,
145  // before it's attached to a partitioner, so it shouldn't really be modifying any state in the engine, but rather only
146  // preparing the basic block to be processed.
147  class BasicBlockFinalizer: public BasicBlockCallback {
148  typedef Sawyer::Container::Map<rose_addr_t /*target*/, std::vector<rose_addr_t> /*sources*/> WorkList;
149  public:
150  static Ptr instance() { return Ptr(new BasicBlockFinalizer); }
151  virtual bool operator()(bool chain, const Args &args) ROSE_OVERRIDE;
152  private:
153  void fixFunctionReturnEdge(const Args&);
154  void fixFunctionCallEdges(const Args&);
155  void addPossibleIndeterminateEdge(const Args&);
156  };
157 
158  // Basic blocks that need to be worked on next. These lists are adjusted whenever a new basic block (or placeholder) is
159  // inserted or erased from the CFG.
160  class BasicBlockWorkList: public CfgAdjustmentCallback {
161  // The following lists are used for adding outgoing E_CALL_RETURN edges to basic blocks based on whether the basic
162  // block is a call to a function that might return. When a new basic block is inserted into the CFG (or a previous
163  // block is removed, modified, and re-inserted), the operator() is called and conditionally inserts the block into the
164  // "pendingCallReturn" list (if the block is a function call that lacks an E_CALL_RETURN edge and the function is known
165  // to return or the analysis was incomplete).
166  //
167  // When we run out of other ways to create basic blocks, we process the pendingCallReturn list from back to front. If
168  // the back block (which gets popped) has a positive may-return result then an E_CALL_RETURN edge is added to the CFG
169  // and the normal recursive BB discovery is resumed. Otherwise if the analysis is incomplete the basic block is moved
170  // to the processedCallReturn list. The entire pendingCallReturn list is processed before proceeding.
171  //
172  // If there is no more pendingCallReturn work to be done, then the processedCallReturn blocks are moved to the
173  // finalCallReturn list and finalCallReturn is sorted by approximate CFG height (i.e., leafs first). The contents
174  // of the finalCallReturn list is then analyzed and the result (or the default may-return value for failed analyses)
175  // is used to decide whether a new CFG edge should be created, possibly adding new basic block addresses to the
176  // list of undiscovered blocks.
177  //
178  Sawyer::Container::DistinctList<rose_addr_t> pendingCallReturn_; // blocks that might need an E_CALL_RETURN edge
179  Sawyer::Container::DistinctList<rose_addr_t> processedCallReturn_; // call sites whose may-return was indeterminate
180  Sawyer::Container::DistinctList<rose_addr_t> finalCallReturn_; // indeterminate call sites awaiting final analysis
181 
182  Sawyer::Container::DistinctList<rose_addr_t> undiscovered_; // undiscovered basic block list (last-in-first-out)
183  Engine *engine_; // engine to which this callback belongs
184  size_t maxSorts_; // max sorts before using unsorted lists
185  protected:
186  BasicBlockWorkList(Engine *engine, size_t maxSorts): engine_(engine), maxSorts_(maxSorts) {}
187  public:
189  static Ptr instance(Engine *engine, size_t maxSorts) { return Ptr(new BasicBlockWorkList(engine, maxSorts)); }
190  virtual bool operator()(bool chain, const AttachedBasicBlock &args) ROSE_OVERRIDE;
191  virtual bool operator()(bool chain, const DetachedBasicBlock &args) ROSE_OVERRIDE;
192  Sawyer::Container::DistinctList<rose_addr_t>& pendingCallReturn() { return pendingCallReturn_; }
193  Sawyer::Container::DistinctList<rose_addr_t>& processedCallReturn() { return processedCallReturn_; }
194  Sawyer::Container::DistinctList<rose_addr_t>& finalCallReturn() { return finalCallReturn_; }
195  Sawyer::Container::DistinctList<rose_addr_t>& undiscovered() { return undiscovered_; }
196  void moveAndSortCallReturn(const Partitioner&);
197  };
198 
199  // A work list providing constants from instructions that are part of the CFG.
200  class CodeConstants: public CfgAdjustmentCallback {
201  public:
203 
204  private:
205  std::set<rose_addr_t> toBeExamined_; // instructions waiting to be examined
206  std::set<rose_addr_t> wasExamined_; // instructions we've already examined
207  rose_addr_t inProgress_; // instruction that is currently in progress
208  std::vector<rose_addr_t> constants_; // constants for the instruction in progress
209 
210  protected:
211  CodeConstants(): inProgress_(0) {}
212 
213  public:
214  static Ptr instance() { return Ptr(new CodeConstants); }
215 
216  // Possibly insert more instructions into the work list when a basic block is added to the CFG
217  virtual bool operator()(bool chain, const AttachedBasicBlock &attached) ROSE_OVERRIDE;
218 
219  // Possibly remove instructions from the worklist when a basic block is removed from the CFG
220  virtual bool operator()(bool chain, const DetachedBasicBlock &detached) ROSE_OVERRIDE;
221 
222  // Return the next available constant if any.
223  Sawyer::Optional<rose_addr_t> nextConstant(const Partitioner &partitioner);
224 
225  // Address of instruction being examined.
226  rose_addr_t inProgress() const { return inProgress_; }
227  };
228 
230  // Data members
232 private:
233  Settings settings_; // Settings for the partitioner.
234  SgAsmInterpretation *interp_; // interpretation set by loadSpecimen
235  BinaryLoader::Ptr binaryLoader_; // how to remap, link, and fixup
236  Disassembler *disassembler_; // not ref-counted yet, but don't destroy it since user owns it
237  MemoryMap::Ptr map_; // memory map initialized by load()
238  BasicBlockWorkList::Ptr basicBlockWorkList_; // what blocks to work on next
239  CodeConstants::Ptr codeFunctionPointers_; // generates constants that are found in instruction ASTs
240  Progress::Ptr progress_; // optional progress reporting
241  ModulesLinux::LibcStartMain::Ptr libcStartMain_; // looking for "main" by analyzing libc_start_main?
242  ThunkPredicates::Ptr functionMatcherThunks_; // predicates to find thunks when looking for functions
243  ThunkPredicates::Ptr functionSplittingThunks_; // predicates for splitting thunks from front of functions
244 
246  // Constructors
248 public:
251  : interp_(NULL), disassembler_(NULL),
252  basicBlockWorkList_(BasicBlockWorkList::instance(this, settings_.partitioner.functionReturnAnalysisMaxSorts)),
253  progress_(Progress::instance()) {
254  init();
255  }
256 
258  explicit Engine(const Settings &settings)
259  : settings_(settings), interp_(NULL), disassembler_(NULL),
260  basicBlockWorkList_(BasicBlockWorkList::instance(this, settings_.partitioner.functionReturnAnalysisMaxSorts)),
261  progress_(Progress::instance()) {
262  init();
263  }
264 
265  virtual ~Engine() {}
266 
268  // The very top-level use case
270 public:
295  SgAsmBlock* frontend(int argc, char *argv[],
296  const std::string &purpose, const std::string &description);
297  virtual SgAsmBlock* frontend(const std::vector<std::string> &args,
298  const std::string &purpose, const std::string &description);
301  // Basic top-level steps
304 public:
310  void reset();
311 
338  Sawyer::CommandLine::ParserResult parseCommandLine(int argc, char *argv[],
339  const std::string &purpose, const std::string &description) /*final*/;
340  virtual Sawyer::CommandLine::ParserResult parseCommandLine(const std::vector<std::string> &args,
341  const std::string &purpose, const std::string &description);
363  virtual SgAsmInterpretation* parseContainers(const std::vector<std::string> &fileNames);
364  SgAsmInterpretation* parseContainers(const std::string &fileName) /*final*/;
387  virtual MemoryMap::Ptr loadSpecimens(const std::vector<std::string> &fileNames = std::vector<std::string>());
388  MemoryMap::Ptr loadSpecimens(const std::string &fileName) /*final*/;
410  virtual Partitioner partition(const std::vector<std::string> &fileNames = std::vector<std::string>());
411  Partitioner partition(const std::string &fileName) /*final*/;
428  SgAsmBlock* buildAst(const std::vector<std::string> &fileNames = std::vector<std::string>()) /*final*/;
429  SgAsmBlock* buildAst(const std::string &fileName) /*final*/;
437  virtual void savePartitioner(const Partitioner&, const boost::filesystem::path&, SerialIo::Format fmt = SerialIo::BINARY);
438 
443  virtual Partitioner loadPartitioner(const boost::filesystem::path&, SerialIo::Format fmt = SerialIo::BINARY);
444 
446  // Command-line parsing
447  //
448  // top-level: parseCommandLine
450 public:
452  virtual Sawyer::CommandLine::SwitchGroup loaderSwitches();
453 
455  virtual Sawyer::CommandLine::SwitchGroup disassemblerSwitches();
456 
458  virtual Sawyer::CommandLine::SwitchGroup partitionerSwitches();
459 
461  virtual Sawyer::CommandLine::SwitchGroup engineSwitches();
462 
464  virtual Sawyer::CommandLine::SwitchGroup astConstructionSwitches();
465 
467  static std::string specimenNameDocumentation();
468 
480  virtual Sawyer::CommandLine::Parser commandLineParser(const std::string &purpose, const std::string &description);
481 
488  virtual void checkSettings();
489 
491  // Container parsing
492  //
493  // top-level: parseContainers
495 public:
500  virtual bool isRbaFile(const std::string&);
501 
506  virtual bool isNonContainer(const std::string&);
507 
513  virtual bool areContainersParsed() const;
514 
516  // Load specimens
517  //
518  // top-level: loadSpecimens
520 public:
524  virtual bool areSpecimensLoaded() const;
525 
541  virtual BinaryLoader::Ptr obtainLoader(const BinaryLoader::Ptr &hint = BinaryLoader::Ptr());
542 
548  virtual void loadContainers(const std::vector<std::string> &fileNames);
549 
554  virtual void loadNonContainers(const std::vector<std::string> &names);
555 
559  virtual void adjustMemoryMap();
560 
569  MemoryMap::Ptr memoryMap() const /*final*/ { return map_; }
570  virtual void memoryMap(const MemoryMap::Ptr &m) { map_ = m; }
574  // Disassembler
577 public:
594  virtual Disassembler* obtainDisassembler(Disassembler *hint=NULL);
598  // Partitioner high-level functions
600  //
601  // top-level: partition
603 public:
605  virtual void checkCreatePartitionerPrerequisites() const;
606 
613  virtual Partitioner createBarePartitioner();
614 
620  virtual Partitioner createGenericPartitioner();
621 
626  virtual Partitioner createTunedPartitioner();
627 
632  virtual Partitioner createPartitionerFromAst(SgAsmInterpretation*);
633 
638  virtual Partitioner createPartitioner();
639 
643  virtual void runPartitionerInit(Partitioner&);
644 
648  virtual void runPartitionerRecursive(Partitioner&);
649 
654  virtual void runPartitionerFinal(Partitioner&);
655 
661  virtual void runPartitioner(Partitioner&);
662 
663 
665  // Partitioner mid-level functions
666  //
667  // These are the functions called by the partitioner high-level stuff. These are sometimes overridden in subclasses,
668  // although it is more likely that the high-level stuff is overridden.
670 public:
675  virtual void labelAddresses(Partitioner&);
676 
680  virtual std::vector<DataBlock::Ptr> makeConfiguredDataBlocks(Partitioner&, const Configuration&);
681 
685  virtual std::vector<Function::Ptr> makeConfiguredFunctions(Partitioner&, const Configuration&);
686 
693  virtual std::vector<Function::Ptr> makeEntryFunctions(Partitioner&, SgAsmInterpretation*);
694 
701  virtual std::vector<Function::Ptr> makeErrorHandlingFunctions(Partitioner&, SgAsmInterpretation*);
702 
712  virtual std::vector<Function::Ptr> makeImportFunctions(Partitioner&, SgAsmInterpretation*);
713 
720  virtual std::vector<Function::Ptr> makeExportFunctions(Partitioner&, SgAsmInterpretation*);
721 
728  virtual std::vector<Function::Ptr> makeSymbolFunctions(Partitioner&, SgAsmInterpretation*);
729 
737  virtual std::vector<Function::Ptr> makeContainerFunctions(Partitioner&, SgAsmInterpretation*);
738 
745  virtual std::vector<Function::Ptr> makeInterruptVectorFunctions(Partitioner&, const AddressInterval &vector);
746 
751  virtual std::vector<Function::Ptr> makeUserFunctions(Partitioner&, const std::vector<rose_addr_t>&);
752 
759  virtual void discoverBasicBlocks(Partitioner&);
760 
772  virtual Function::Ptr makeNextDataReferencedFunction(const Partitioner&, rose_addr_t &startVa /*in,out*/);
773 
787  virtual Function::Ptr makeNextCodeReferencedFunction(const Partitioner&);
788 
795  virtual std::vector<Function::Ptr> makeCalledFunctions(Partitioner&);
796 
809  virtual std::vector<Function::Ptr> makeNextPrologueFunction(Partitioner&, rose_addr_t startVa);
810 
829  virtual std::vector<Function::Ptr>
830  makeFunctionFromInterFunctionCalls(Partitioner &partitioner, rose_addr_t &startVa /*in,out*/);
831 
838  virtual void discoverFunctions(Partitioner&);
839 
854  virtual std::set<rose_addr_t> attachDeadCodeToFunction(Partitioner&, const Function::Ptr&, size_t maxIterations=size_t(-1));
855 
863  virtual DataBlock::Ptr attachPaddingToFunction(Partitioner&, const Function::Ptr&);
864 
869  virtual std::vector<DataBlock::Ptr> attachPaddingToFunctions(Partitioner&);
870 
881  virtual size_t attachAllSurroundedCodeToFunctions(Partitioner&);
882 
890  virtual size_t attachSurroundedCodeToFunctions(Partitioner&);
891 
896  virtual void attachBlocksToFunctions(Partitioner&);
897 
904  virtual std::set<rose_addr_t> attachDeadCodeToFunctions(Partitioner&, size_t maxIterations=size_t(-1));
905 
915  virtual std::vector<DataBlock::Ptr> attachSurroundedDataToFunctions(Partitioner&);
916 
922  virtual void updateAnalysisResults(Partitioner&);
923 
924 
926  // Partitioner low-level functions
927  //
928  // These are functions that a subclass seldom overrides, and maybe even shouldn't override because of their complexity or
929  // the way the interact with one another.
931 public:
942  virtual bool makeNextCallReturnEdge(Partitioner&, boost::logic::tribool assumeCallReturns);
943 
949  virtual BasicBlock::Ptr makeNextBasicBlockFromPlaceholder(Partitioner&);
950 
965  virtual BasicBlock::Ptr makeNextBasicBlock(Partitioner&);
966 
967 
969  // Build AST
971 public:
972  // Used internally by ROSE's ::frontend disassemble instructions to build the AST that goes under each SgAsmInterpretation.
973  static void disassembleForRoseFrontend(SgAsmInterpretation*);
974 
975 
977  // Settings and properties
979 public:
986  const Settings& settings() const /*final*/ { return settings_; }
987  Settings& settings() /*final*/ { return settings_; }
998  bool exitOnError() const /*final*/ { return settings_.engine.exitOnError; }
999  virtual void exitOnError(bool b) { settings_.engine.exitOnError = b; }
1007  Progress::Ptr progress() const /*final*/ { return progress_; }
1008  virtual void progress(const Progress::Ptr &progress) { progress_ = progress; }
1018  SgAsmInterpretation* interpretation() const /*final*/ { return interp_; }
1019  virtual void interpretation(SgAsmInterpretation *interp) { interp_ = interp; }
1028  BinaryLoader::Ptr binaryLoader() const /*final*/ { return binaryLoader_; }
1029  virtual void binaryLoader(const BinaryLoader::Ptr &loader) { binaryLoader_ = loader; }
1042  size_t deExecuteZerosThreshold() const /*final*/ { return settings_.loader.deExecuteZerosThreshold; }
1043  virtual void deExecuteZerosThreshold(size_t n) { settings_.loader.deExecuteZerosThreshold = n; }
1044  size_t deExecuteZerosLeaveAtFront() const /*final*/ { return settings_.loader.deExecuteZerosLeaveAtFront; }
1045  virtual void deExecuteZerosLeaveAtFront(size_t n) { settings_.loader.deExecuteZerosLeaveAtFront = n; }
1046  size_t deExecuteZerosLeaveAtBack() const /*final*/ { return settings_.loader.deExecuteZerosLeaveAtBack; }
1047  virtual void deExecuteZerosLeaveAtBack(size_t n) { settings_.loader.deExecuteZerosLeaveAtBack = n; }
1062  MemoryDataAdjustment memoryDataAdjustment() const /*final*/ { return settings_.loader.memoryDataAdjustment; }
1063  virtual void memoryDataAdjustment(MemoryDataAdjustment x) { settings_.loader.memoryDataAdjustment = x; }
1073  bool memoryIsExecutable() const /*final*/ { return settings_.loader.memoryIsExecutable; }
1074  virtual void memoryIsExecutable(bool b) { settings_.loader.memoryIsExecutable = b; }
1086  bool linkObjectFiles() const /*final*/ { return settings_.loader.linkObjectFiles; }
1087  virtual void linkObjectFiles(bool b) { settings_.loader.linkObjectFiles = b; }
1099  bool linkStaticArchives() const /*final*/ { return settings_.loader.linkStaticArchives; }
1100  virtual void linkStaticArchives(bool b) { settings_.loader.linkStaticArchives = b; }
1111  const std::string& linkerCommand() const /*final*/ { return settings_.loader.linker; }
1112  virtual void linkerCommand(const std::string &cmd) { settings_.loader.linker = cmd; }
1121  Disassembler *disassembler() const /*final*/ { return disassembler_; }
1122  virtual void disassembler(Disassembler *d) { disassembler_ = d; }
1131  const std::string& isaName() const /*final*/ { return settings_.disassembler.isaName; }
1132  virtual void isaName(const std::string &s) { settings_.disassembler.isaName = s; }
1141  const std::vector<rose_addr_t>& startingVas() const /*final*/ { return settings_.partitioner.startingVas; }
1142  std::vector<rose_addr_t>& startingVas() /*final*/ { return settings_.partitioner.startingVas; }
1151  bool usingSemantics() const /*final*/ { return settings_.partitioner.base.usingSemantics; }
1152  virtual void usingSemantics(bool b) { settings_.partitioner.base.usingSemantics = b; }
1161  SemanticMemoryParadigm semanticMemoryParadigm() const /*final*/ { return settings_.partitioner.semanticMemoryParadigm; }
1162  virtual void semanticMemoryParadigm(SemanticMemoryParadigm p) { settings_.partitioner.semanticMemoryParadigm = p; }
1173  bool followingGhostEdges() const /*final*/ { return settings_.partitioner.followingGhostEdges; }
1174  virtual void followingGhostEdges(bool b) { settings_.partitioner.followingGhostEdges = b; }
1184  bool discontiguousBlocks() const /*final*/ { return settings_.partitioner.discontiguousBlocks; }
1185  virtual void discontiguousBlocks(bool b) { settings_.partitioner.discontiguousBlocks = b; }
1195  size_t maxBasicBlockSize() const /*final*/ { return settings_.partitioner.maxBasicBlockSize; }
1196  virtual void maxBasicBlockSize(size_t n) { settings_.partitioner.maxBasicBlockSize = n; }
1205  bool findingFunctionPadding() const /*final*/ { return settings_.partitioner.findingFunctionPadding; }
1206  virtual void findingFunctionPadding(bool b) { settings_.partitioner.findingFunctionPadding = b; }
1215  bool findingThunks() const /*final*/ { return settings_.partitioner.findingThunks; }
1216  virtual void findingThunks(bool b) { settings_.partitioner.findingThunks = b; }
1227  ThunkPredicates::Ptr functionMatcherThunks() const /*final*/ { return functionMatcherThunks_; }
1228  virtual void functionMatcherThunks(const ThunkPredicates::Ptr &p) { functionMatcherThunks_ = p; }
1237  bool splittingThunks() const /*final*/ { return settings_.partitioner.splittingThunks; }
1238  virtual void splittingThunks(bool b) { settings_.partitioner.splittingThunks = b; }
1249  ThunkPredicates::Ptr functionSplittingThunks() const /*final*/ { return functionSplittingThunks_; }
1250  virtual void functionSplittingThunks(const ThunkPredicates::Ptr &p) { functionSplittingThunks_ = p; }
1259  bool findingDeadCode() const /*final*/ { return settings_.partitioner.findingDeadCode; }
1260  virtual void findingDeadCode(bool b) { settings_.partitioner.findingDeadCode = b; }
1269  rose_addr_t peScramblerDispatcherVa() const /*final*/ { return settings_.partitioner.peScramblerDispatcherVa; }
1270  virtual void peScramblerDispatcherVa(rose_addr_t va) { settings_.partitioner.peScramblerDispatcherVa = va; }
1280  size_t findingIntraFunctionCode() const /*final*/ { return settings_.partitioner.findingIntraFunctionCode; }
1281  virtual void findingIntraFunctionCode(size_t n) { settings_.partitioner.findingIntraFunctionCode = n; }
1290  bool findingIntraFunctionData() const /*final*/ { return settings_.partitioner.findingIntraFunctionData; }
1291  virtual void findingIntraFunctionData(bool b) { settings_.partitioner.findingIntraFunctionData = b; }
1300  const AddressInterval& interruptVector() const /*final*/ { return settings_.partitioner.interruptVector; }
1301  virtual void interruptVector(const AddressInterval &i) { settings_.partitioner.interruptVector = i; }
1310  bool doingPostAnalysis() const /*final*/ { return settings_.partitioner.doingPostAnalysis; }
1311  virtual void doingPostAnalysis(bool b) { settings_.partitioner.doingPostAnalysis = b; }
1319  bool doingPostFunctionMayReturn() const /*final*/ { return settings_.partitioner.doingPostFunctionMayReturn; }
1320  virtual void doingPostFunctionMayReturn(bool b) { settings_.partitioner.doingPostFunctionMayReturn = b; }
1328  bool doingPostFunctionStackDelta() const /*final*/ { return settings_.partitioner.doingPostFunctionStackDelta; }
1329  virtual void doingPostFunctionStackDelta(bool b) { settings_.partitioner.doingPostFunctionStackDelta = b; }
1337  bool doingPostCallingConvention() const /*final*/ { return settings_.partitioner.doingPostCallingConvention; }
1338  virtual void doingPostCallingConvention(bool b) { settings_.partitioner.doingPostCallingConvention = b; }
1347  bool doingPostFunctionNoop() const /*final*/ { return settings_.partitioner.doingPostFunctionNoop; }
1348  virtual void doingPostFunctionNoop(bool b) { settings_.partitioner.doingPostFunctionNoop = b; }
1357  FunctionReturnAnalysis functionReturnAnalysis() const /*final*/ { return settings_.partitioner.functionReturnAnalysis; }
1358  virtual void functionReturnAnalysis(FunctionReturnAnalysis x) { settings_.partitioner.functionReturnAnalysis = x; }
1373  size_t functionReturnAnalysisMaxSorts() const /*final*/ { return settings_.partitioner.functionReturnAnalysisMaxSorts; }
1374  virtual void functionReturnAnalysisMaxSorts(size_t n) { settings_.partitioner.functionReturnAnalysisMaxSorts = n; }
1383  bool findingInterFunctionCalls() const /*final*/ { return settings_.partitioner.findingInterFunctionCalls; }
1384  virtual void findingInterFunctionCalls(bool b) { settings_.partitioner.findingInterFunctionCalls = b; }
1393  bool findingFunctionCallFunctions() const /*final*/ { return settings_.partitioner.findingFunctionCallFunctions; }
1394  virtual void findingFunctionCallFunctions(bool b) { settings_.partitioner.findingFunctionCallFunctions = b; }
1402  bool findingEntryFunctions() const /*final*/ { return settings_.partitioner.findingEntryFunctions; }
1403  virtual void findingEntryFunctions(bool b) { settings_.partitioner.findingEntryFunctions = b; }
1412  bool findingErrorFunctions() const /*final*/ { return settings_.partitioner.findingErrorFunctions; }
1413  virtual void findingErrorFunctions(bool b) { settings_.partitioner.findingErrorFunctions = b; }
1422  bool findingImportFunctions() const /*final*/ { return settings_.partitioner.findingImportFunctions; }
1423  virtual void findingImportFunctions(bool b) { settings_.partitioner.findingImportFunctions = b; }
1432  bool findingExportFunctions() const /*final*/ { return settings_.partitioner.findingExportFunctions; }
1433  virtual void findingExportFunctions(bool b) { settings_.partitioner.findingExportFunctions = b; }
1442  bool findingSymbolFunctions() const /*final*/ { return settings_.partitioner.findingSymbolFunctions; }
1443  virtual void findingSymbolFunctions(bool b) { settings_.partitioner.findingSymbolFunctions = b; }
1452  bool findingDataFunctionPointers() const /*final*/ { return settings_.partitioner.findingDataFunctionPointers; }
1453  virtual void findingDataFunctionPointers(bool b) { settings_.partitioner.findingDataFunctionPointers = b; }
1462  bool findingCodeFunctionPointers() const /*final*/ { return settings_.partitioner.findingCodeFunctionPointers; }
1463  virtual void findingCodeFunctionPointers(bool b) { settings_.partitioner.findingCodeFunctionPointers = b; }
1471  bool checkingCallBranch() const /*final*/ { return settings_.partitioner.base.checkingCallBranch; }
1472  virtual void checkingCallBranch(bool b) { settings_.partitioner.base.checkingCallBranch = b; }
1486  bool basicBlockSemanticsAutoDrop() const /*final*/ { return settings_.partitioner.base.basicBlockSemanticsAutoDrop; }
1487  void basicBlockSemanticsAutoDrop(bool b) { settings_.partitioner.base.basicBlockSemanticsAutoDrop = b; }
1495  const std::vector<std::string>& configurationNames() /*final*/ const { return settings_.engine.configurationNames; }
1496  std::vector<std::string>& configurationNames() /*final*/ { return settings_.engine.configurationNames; }
1504  bool namingConstants() const /*final*/ { return settings_.partitioner.namingConstants; }
1505  virtual void namingConstants(bool b) { settings_.partitioner.namingConstants = b; }
1513  bool namingStrings() const /*final*/ { return settings_.partitioner.namingStrings; }
1514  virtual void namingStrings(bool b) { settings_.partitioner.namingStrings = b; }
1523  bool namingSystemCalls() const /*final*/ { return settings_.partitioner.namingSyscalls; }
1524  virtual void namingSystemCalls(bool b) { settings_.partitioner.namingSyscalls = b; }
1534  const boost::filesystem::path& systemCallHeader() const /*final*/ { return settings_.partitioner.syscallHeader; }
1535  virtual void systemCallHeader(const boost::filesystem::path &filename) { settings_.partitioner.syscallHeader = filename; }
1544  bool demangleNames() const /*final*/ { return settings_.partitioner.demangleNames; }
1545  virtual void demangleNames(bool b) { settings_.partitioner.demangleNames = b; }
1554  bool astAllowEmptyGlobalBlock() const /*final*/ { return settings_.astConstruction.allowEmptyGlobalBlock; }
1555  virtual void astAllowEmptyGlobalBlock(bool b) { settings_.astConstruction.allowEmptyGlobalBlock = b; }
1564  bool astAllowFunctionWithNoBasicBlocks() const /*final*/ {
1565  return settings_.astConstruction.allowFunctionWithNoBasicBlocks;
1566  }
1567  virtual void astAllowFunctionWithNoBasicBlocks(bool b) {
1568  settings_.astConstruction.allowFunctionWithNoBasicBlocks = b;
1569  }
1578  bool astAllowEmptyBasicBlock() const /*final*/ { return settings_.astConstruction.allowEmptyBasicBlocks; }
1579  virtual void astAllowEmptyBasicBlock(bool b) { settings_.astConstruction.allowEmptyBasicBlocks = b; }
1591  bool astCopyAllInstructions() const /*final*/ { return settings_.astConstruction.copyAllInstructions; }
1592  virtual void astCopyAllInstructions(bool b) { settings_.astConstruction.copyAllInstructions = b; }
1595  // Python API support functions
1598 #ifdef ROSE_ENABLE_PYTHON_API
1599 
1600  // Similar to frontend, but returns a partitioner rather than an AST since the Python API doesn't yet support ASTs.
1601  Partitioner pythonParseVector(boost::python::list &pyArgs, const std::string &purpose, const std::string &description);
1602  Partitioner pythonParseSingle(const std::string &specimen, const std::string &purpose, const std::string &description);
1603 
1604 #endif
1605 
1607  // Internal stuff
1609 private:
1610  void init();
1611 
1612  // Similar to ::frontend but a lot less complicated.
1613  SgProject* roseFrontendReplacement(const std::vector<boost::filesystem::path> &fileNames);
1614 };
1615 
1616 } // namespace
1617 } // namespace
1618 } // namespace
1619 
1620 #endif
size_t maxBasicBlockSize() const
Property: Maximum size for basic blocks.
Definition: Engine.h:1195
const Settings & settings() const
Property: All settings.
Definition: Engine.h:986
bool doingPostFunctionStackDelta() const
Property: Whether to run the function stack delta analysis.
Definition: Engine.h:1328
virtual void linkObjectFiles(bool b)
Property: Link object files.
Definition: Engine.h:1087
virtual void memoryIsExecutable(bool b)
Property: Global adjustment to executability.
Definition: Engine.h:1074
virtual void systemCallHeader(const boost::filesystem::path &filename)
Property: Header file in which system calls are defined.
Definition: Engine.h:1535
size_t findingIntraFunctionCode() const
Property: Whether to find intra-function code.
Definition: Engine.h:1280
virtual void disassembler(Disassembler *d)
Property: Disassembler.
Definition: Engine.h:1122
bool checkingCallBranch() const
Property: Whether to look for function calls used as branches.
Definition: Engine.h:1471
virtual void maxBasicBlockSize(size_t n)
Property: Maximum size for basic blocks.
Definition: Engine.h:1196
Settings for controling the engine behavior.
Definition: BasicTypes.h:439
virtual void namingStrings(bool b)
Property: Give names to string literal addresses.
Definition: Engine.h:1514
MemoryDataAdjustment
How the partitioner should globally treat memory.
Definition: BasicTypes.h:178
bool findingInterFunctionCalls() const
Property: Whether to search for function calls between exiting functions.
Definition: Engine.h:1383
Instruction basic block.
virtual void findingExportFunctions(bool b)
Property: Whether to make functions at export addresses.
Definition: Engine.h:1433
Progress::Ptr progress() const
Property: progress reporting.
Definition: Engine.h:1007
Base class for adjusting basic blocks during discovery.
Definition: Modules.h:39
virtual void findingFunctionCallFunctions(bool b)
Property: Whether to turn function call targets into functions.
Definition: Engine.h:1394
virtual void followingGhostEdges(bool b)
Property: Whether to follow ghost edges.
Definition: Engine.h:1174
virtual void interruptVector(const AddressInterval &i)
Property: Location of machine interrupt vector.
Definition: Engine.h:1301
virtual void astCopyAllInstructions(bool b)
Property: Whether to copy instructions when building the AST.
Definition: Engine.h:1592
virtual void findingSymbolFunctions(bool b)
Property: Whether to make functions according to symbol tables.
Definition: Engine.h:1443
Sawyer::SharedPointer< BinaryLoader > Ptr
Referenc counting pointer to BinaryLoader.
Definition: BinaryLoader.h:60
bool namingStrings() const
Property: Give names to string literal addresses.
Definition: Engine.h:1513
bool findingDeadCode() const
Property: Whether to find dead code.
Definition: Engine.h:1259
virtual void findingCodeFunctionPointers(bool b)
Property: Whether to search existing instructions for function pointers.
Definition: Engine.h:1463
size_t functionReturnAnalysisMaxSorts() const
Property: Maximum number of function may-return sorting operations.
Definition: Engine.h:1373
virtual void functionSplittingThunks(const ThunkPredicates::Ptr &p)
Property: Predicate for finding thunks at the start of functions.
Definition: Engine.h:1250
const std::vector< std::string > & configurationNames() const
Property: Configuration files.
Definition: Engine.h:1495
virtual void doingPostFunctionNoop(bool b)
Property: Whether to run no-op function analysis.
Definition: Engine.h:1348
Settings that control the disassembler.
Definition: BasicTypes.h:248
Base class for engines driving the partitioner.
Definition: Engine.h:111
Engine(const Settings &settings)
Construct engine with settings.
Definition: Engine.h:258
The result from parsing a command line.
bool namingConstants() const
Property: Give names to constants.
Definition: Engine.h:1504
Disassembler * disassembler() const
Property: Disassembler.
Definition: Engine.h:1121
virtual void exitOnError(bool b)
Property: Error handling.
Definition: Engine.h:999
virtual void peScramblerDispatcherVa(rose_addr_t va)
Property: PE-Scrambler dispatcher address.
Definition: Engine.h:1270
SemanticMemoryParadigm semanticMemoryParadigm() const
Property: Type of container for semantic memory.
Definition: Engine.h:1161
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:1357
ThunkPredicates::Ptr functionSplittingThunks() const
Property: Predicate for finding thunks at the start of functions.
Definition: Engine.h:1249
size_t deExecuteZerosLeaveAtBack() const
Property: when to remove execute permission from zero bytes.
Definition: Engine.h:1046
const std::string & isaName() const
Property: Instruction set architecture name.
Definition: Engine.h:1131
virtual void findingIntraFunctionData(bool b)
Property: Whether to find intra-function data.
Definition: Engine.h:1291
Settings & settings()
Property: All settings.
Definition: Engine.h:987
A collection of related switch declarations.
MemoryDataAdjustment memoryDataAdjustment() const
Property: Global adjustments to memory map data access bits.
Definition: Engine.h:1062
bool linkObjectFiles() const
Property: Link object files.
Definition: Engine.h:1086
virtual void findingDataFunctionPointers(bool b)
Property: Whether to search static data for function pointers.
Definition: Engine.h:1453
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:1132
virtual void findingErrorFunctions(bool b)
Property: Whether to make error handling functions.
Definition: Engine.h:1413
virtual void memoryMap(const MemoryMap::Ptr &m)
Property: memory map.
Definition: Engine.h:570
bool findingErrorFunctions() const
Property: Whether to make error handling functions.
Definition: Engine.h:1412
Main namespace for the ROSE library.
Settings for loading specimens.
Definition: BasicTypes.h:193
Settings that control building the AST.
Definition: BasicTypes.h:89
BinaryLoader::Ptr binaryLoader() const
Property: binary loader.
Definition: Engine.h:1028
virtual void findingEntryFunctions(bool b)
Property: Whether to make functions at program entry points.
Definition: Engine.h:1403
bool followingGhostEdges() const
Property: Whether to follow ghost edges.
Definition: Engine.h:1173
bool demangleNames() const
Property: Demangle names.
Definition: Engine.h:1544
bool astAllowEmptyGlobalBlock() const
Property: Whether to allow empty global block in the AST.
Definition: Engine.h:1554
bool findingFunctionPadding() const
Property: Whether to find function padding.
Definition: Engine.h:1205
bool doingPostCallingConvention() const
Property: Whether to run calling-convention analysis.
Definition: Engine.h:1337
bool discontiguousBlocks() const
Property: Whether to allow discontiguous basic blocks.
Definition: Engine.h:1184
virtual void namingConstants(bool b)
Property: Give names to constants.
Definition: Engine.h:1505
bool findingIntraFunctionData() const
Property: Whether to find intra-function data.
Definition: Engine.h:1290
virtual void findingIntraFunctionCode(size_t n)
Property: Whether to find intra-function code.
Definition: Engine.h:1281
ThunkPredicates::Ptr functionMatcherThunks() const
Property: Predicate for finding functions that are thunks.
Definition: Engine.h:1227
virtual void astAllowEmptyGlobalBlock(bool b)
Property: Whether to allow empty global block in the AST.
Definition: Engine.h:1555
bool memoryIsExecutable() const
Property: Global adjustment to executability.
Definition: Engine.h:1073
bool doingPostFunctionMayReturn() const
Property: Whether to run the function may-return analysis.
Definition: Engine.h:1319
virtual void doingPostFunctionStackDelta(bool b)
Property: Whether to run the function stack delta analysis.
Definition: Engine.h:1329
virtual void findingThunks(bool b)
Property: Whether to find thunk patterns.
Definition: Engine.h:1216
virtual void usingSemantics(bool b)
Property: Whether to use instruction semantics.
Definition: Engine.h:1152
virtual void findingFunctionPadding(bool b)
Property: Whether to find function padding.
Definition: Engine.h:1206
size_t deExecuteZerosLeaveAtFront() const
Property: when to remove execute permission from zero bytes.
Definition: Engine.h:1044
bool astAllowFunctionWithNoBasicBlocks() const
Property: Whether to allow empty functions in the AST.
Definition: Engine.h:1564
bool namingSystemCalls() const
Property: Give names to system calls.
Definition: Engine.h:1523
virtual void astAllowEmptyBasicBlock(bool b)
Property: Whether to allow empty basic blocks in the AST.
Definition: Engine.h:1579
The parser for a program command line.
virtual void semanticMemoryParadigm(SemanticMemoryParadigm p)
Property: Type of container for semantic memory.
Definition: Engine.h:1162
virtual void interpretation(SgAsmInterpretation *interp)
Property: interpretation.
Definition: Engine.h:1019
const AddressInterval & interruptVector() const
Property: Location of machine interrupt vector.
Definition: Engine.h:1300
Settings that control the engine partitioning.
Definition: BasicTypes.h:307
virtual void deExecuteZerosLeaveAtBack(size_t n)
Property: when to remove execute permission from zero bytes.
Definition: Engine.h:1047
std::vector< std::string > & configurationNames()
Property: Configuration files.
Definition: Engine.h:1496
bool findingSymbolFunctions() const
Property: Whether to make functions according to symbol tables.
Definition: Engine.h:1442
bool findingDataFunctionPointers() const
Property: Whether to search static data for function pointers.
Definition: Engine.h:1452
DisassemblerSettings disassembler
Settings for creating the disassembler.
Definition: Engine.h:118
SemanticMemoryParadigm
Organization of semantic memory.
Definition: BasicTypes.h:80
virtual void findingImportFunctions(bool b)
Property: Whether to make functions at import addresses.
Definition: Engine.h:1423
virtual void findingDeadCode(bool b)
Property: Whether to find dead code.
Definition: Engine.h:1260
bool findingCodeFunctionPointers() const
Property: Whether to search existing instructions for function pointers.
Definition: Engine.h:1462
virtual void deExecuteZerosThreshold(size_t n)
Property: when to remove execute permission from zero bytes.
Definition: Engine.h:1043
FunctionReturnAnalysis
Controls whether the function may-return analysis runs.
Definition: BasicTypes.h:263
bool findingEntryFunctions() const
Property: Whether to make functions at program entry points.
Definition: Engine.h:1402
SgAsmInterpretation * interpretation() const
Property: interpretation.
Definition: Engine.h:1018
virtual void checkingCallBranch(bool b)
Property: Whether to look for function calls used as branches.
Definition: Engine.h:1472
AstConstructionSettings astConstruction
Settings for constructing the AST.
Definition: Engine.h:121
bool astCopyAllInstructions() const
Property: Whether to copy instructions when building the AST.
Definition: Engine.h:1591
size_t deExecuteZerosThreshold() const
Property: when to remove execute permission from zero bytes.
Definition: Engine.h:1042
virtual void demangleNames(bool b)
Property: Demangle names.
Definition: Engine.h:1545
bool doingPostAnalysis() const
Property: Whether to perform post-partitioning analysis steps.
Definition: Engine.h:1310
bool usingSemantics() const
Property: Whether to use instruction semantics.
Definition: Engine.h:1151
void basicBlockSemanticsAutoDrop(bool b)
Property: Automatically drop semantics for attached basic blocks.
Definition: Engine.h:1487
MemoryMap::Ptr memoryMap() const
Property: memory map.
Definition: Engine.h:569
bool exitOnError() const
Property: Error handling.
Definition: Engine.h:998
bool doingPostFunctionNoop() const
Property: Whether to run no-op function analysis.
Definition: Engine.h:1347
const boost::filesystem::path & systemCallHeader() const
Property: Header file in which system calls are defined.
Definition: Engine.h:1534
A general, thread-safe way to report progress made on some task.
Definition: Progress.h:164
bool findingExportFunctions() const
Property: Whether to make functions at export addresses.
Definition: Engine.h:1432
virtual void splittingThunks(bool b)
Property: Whether to split thunk instructions into mini functions.
Definition: Engine.h:1238
virtual void astAllowFunctionWithNoBasicBlocks(bool b)
Property: Whether to allow empty functions in the AST.
Definition: Engine.h:1567
bool linkStaticArchives() const
Property: Link library archives.
Definition: Engine.h:1099
bool astAllowEmptyBasicBlock() const
Property: Whether to allow empty basic blocks in the AST.
Definition: Engine.h:1578
virtual void functionMatcherThunks(const ThunkPredicates::Ptr &p)
Property: Predicate for finding functions that are thunks.
Definition: Engine.h:1228
virtual void deExecuteZerosLeaveAtFront(size_t n)
Property: when to remove execute permission from zero bytes.
Definition: Engine.h:1045
rose_addr_t peScramblerDispatcherVa() const
Property: PE-Scrambler dispatcher address.
Definition: Engine.h:1269
bool findingImportFunctions() const
Property: Whether to make functions at import addresses.
Definition: Engine.h:1422
virtual void linkerCommand(const std::string &cmd)
Property: Linker command.
Definition: Engine.h:1112
Format
Format of the state file.
virtual void findingInterFunctionCalls(bool b)
Property: Whether to search for function calls between exiting functions.
Definition: Engine.h:1384
This class represents a source project, with a list of SgFile objects and global information about th...
PartitionerSettings partitioner
Settings for creating a partitioner.
Definition: Engine.h:119
bool findingFunctionCallFunctions() const
Property: Whether to turn function call targets into functions.
Definition: Engine.h:1393
LoaderSettings loader
Settings used during specimen loading.
Definition: Engine.h:117
virtual void binaryLoader(const BinaryLoader::Ptr &loader)
Property: binary loader.
Definition: Engine.h:1029
virtual void doingPostCallingConvention(bool b)
Property: Whether to run calling-convention analysis.
Definition: Engine.h:1338
virtual void namingSystemCalls(bool b)
Property: Give names to system calls.
Definition: Engine.h:1524
virtual void discontiguousBlocks(bool b)
Property: Whether to allow discontiguous basic blocks.
Definition: Engine.h:1185
bool findingThunks() const
Property: Whether to find thunk patterns.
Definition: Engine.h:1215
Partitions instructions into basic blocks and functions.
Definition: Partitioner.h:293
Base class for all ROSE exceptions.
Definition: RoseException.h:9
virtual void doingPostFunctionMayReturn(bool b)
Property: Whether to run the function may-return analysis.
Definition: Engine.h:1320
Binary state files are smaller and faster than the other formats, but are not portable across archite...
Virtual base class for instruction disassemblers.
Definition: Disassembler.h:43
Represents an interpretation of a binary container.
virtual void functionReturnAnalysis(FunctionReturnAnalysis x)
Property: Whether to run the function may-return analysis.
Definition: Engine.h:1358
EngineSettings engine
Settings that control engine behavior.
Definition: Engine.h:120
const std::vector< rose_addr_t > & startingVas() const
Property: Starting addresses for disassembly.
Definition: Engine.h:1141
bool basicBlockSemanticsAutoDrop() const
Property: Automatically drop semantics for attached basic blocks.
Definition: Engine.h:1486
virtual void linkStaticArchives(bool b)
Property: Link library archives.
Definition: Engine.h:1100
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:1374
std::vector< rose_addr_t > & startingVas()
Property: Starting addresses for disassembly.
Definition: Engine.h:1142
virtual void doingPostAnalysis(bool b)
Property: Whether to perform post-partitioning analysis steps.
Definition: Engine.h:1311
virtual void progress(const Progress::Ptr &progress)
Property: progress reporting.
Definition: Engine.h:1008
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:1063
Holds configuration information.
Definition: Config.h:210
const std::string & linkerCommand() const
Property: Linker command.
Definition: Engine.h:1111
bool splittingThunks() const
Property: Whether to split thunk instructions into mini functions.
Definition: Engine.h:1237