ROSE  0.11.31.0
frontend/Partitioner2/Engine.h
1 #ifndef ROSE_Partitioner2_Engine_H
2 #define ROSE_Partitioner2_Engine_H
3 
4 #include <featureTests.h>
5 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
6 
7 #include <BinaryLoader.h>
8 #include <BinarySerialIo.h>
9 #include <boost/noncopyable.hpp>
10 #include <boost/regex.hpp>
11 #include <Disassembler.h>
12 #include <FileSystem.h>
13 #include <Partitioner2/Function.h>
14 #include <Partitioner2/ModulesLinux.h>
15 #include <Partitioner2/Partitioner.h>
16 #include <Partitioner2/Thunk.h>
17 #include <Partitioner2/Utility.h>
18 #include <Progress.h>
19 #include <RoseException.h>
20 #include <Sawyer/DistinctList.h>
21 #include <stdexcept>
22 
23 #ifdef ROSE_ENABLE_PYTHON_API
24 #undef slots // stupid Qt pollution
25 #include <boost/python.hpp>
26 #endif
27 
28 namespace Rose {
29 namespace BinaryAnalysis {
30 namespace Partitioner2 {
31 
115 class ROSE_DLL_API Engine: private boost::noncopyable {
116 public:
120  struct Settings {
127  private:
128  friend class boost::serialization::access;
129 
130  template<class S>
131  void serialize(S &s, unsigned version) {
132  s & loader & disassembler & partitioner & engine & astConstruction;
133  }
134  };
135 
137  class Exception: public Rose::Exception {
138  public:
139  Exception(const std::string &mesg)
140  : Rose::Exception(mesg) {}
141  ~Exception() throw () {}
142  };
143 
145  // Internal data structures
147 private:
148  // Engine callback for handling instructions added to basic blocks. This is called when a basic block is discovered,
149  // before it's attached to a partitioner, so it shouldn't really be modifying any state in the engine, but rather only
150  // preparing the basic block to be processed.
151  class BasicBlockFinalizer: public BasicBlockCallback {
152  typedef Sawyer::Container::Map<rose_addr_t /*target*/, std::vector<rose_addr_t> /*sources*/> WorkList;
153  public:
154  static Ptr instance() { return Ptr(new BasicBlockFinalizer); }
155  virtual bool operator()(bool chain, const Args &args) ROSE_OVERRIDE;
156  private:
157  void fixFunctionReturnEdge(const Args&);
158  void fixFunctionCallEdges(const Args&);
159  void addPossibleIndeterminateEdge(const Args&);
160  };
161 
162  // Basic blocks that need to be worked on next. These lists are adjusted whenever a new basic block (or placeholder) is
163  // inserted or erased from the CFG.
164  class BasicBlockWorkList: public CfgAdjustmentCallback {
165  // The following lists are used for adding outgoing E_CALL_RETURN edges to basic blocks based on whether the basic
166  // block is a call to a function that might return. When a new basic block is inserted into the CFG (or a previous
167  // block is removed, modified, and re-inserted), the operator() is called and conditionally inserts the block into the
168  // "pendingCallReturn" list (if the block is a function call that lacks an E_CALL_RETURN edge and the function is known
169  // to return or the analysis was incomplete).
170  //
171  // When we run out of other ways to create basic blocks, we process the pendingCallReturn list from back to front. If
172  // the back block (which gets popped) has a positive may-return result then an E_CALL_RETURN edge is added to the CFG
173  // and the normal recursive BB discovery is resumed. Otherwise if the analysis is incomplete the basic block is moved
174  // to the processedCallReturn list. The entire pendingCallReturn list is processed before proceeding.
175  //
176  // If there is no more pendingCallReturn work to be done, then the processedCallReturn blocks are moved to the
177  // finalCallReturn list and finalCallReturn is sorted by approximate CFG height (i.e., leafs first). The contents
178  // of the finalCallReturn list is then analyzed and the result (or the default may-return value for failed analyses)
179  // is used to decide whether a new CFG edge should be created, possibly adding new basic block addresses to the
180  // list of undiscovered blocks.
181  //
182  Sawyer::Container::DistinctList<rose_addr_t> pendingCallReturn_; // blocks that might need an E_CALL_RETURN edge
183  Sawyer::Container::DistinctList<rose_addr_t> processedCallReturn_; // call sites whose may-return was indeterminate
184  Sawyer::Container::DistinctList<rose_addr_t> finalCallReturn_; // indeterminate call sites awaiting final analysis
185 
186  Sawyer::Container::DistinctList<rose_addr_t> undiscovered_; // undiscovered basic block list (last-in-first-out)
187  Engine *engine_; // engine to which this callback belongs
188  size_t maxSorts_; // max sorts before using unsorted lists
189  protected:
190  BasicBlockWorkList(Engine *engine, size_t maxSorts): engine_(engine), maxSorts_(maxSorts) {}
191  public:
193  static Ptr instance(Engine *engine, size_t maxSorts) { return Ptr(new BasicBlockWorkList(engine, maxSorts)); }
194  virtual bool operator()(bool chain, const AttachedBasicBlock &args) ROSE_OVERRIDE;
195  virtual bool operator()(bool chain, const DetachedBasicBlock &args) ROSE_OVERRIDE;
196  Sawyer::Container::DistinctList<rose_addr_t>& pendingCallReturn() { return pendingCallReturn_; }
197  Sawyer::Container::DistinctList<rose_addr_t>& processedCallReturn() { return processedCallReturn_; }
198  Sawyer::Container::DistinctList<rose_addr_t>& finalCallReturn() { return finalCallReturn_; }
199  Sawyer::Container::DistinctList<rose_addr_t>& undiscovered() { return undiscovered_; }
200  void moveAndSortCallReturn(const Partitioner&);
201  };
202 
203  // A work list providing constants from instructions that are part of the CFG.
204  class CodeConstants: public CfgAdjustmentCallback {
205  public:
207 
208  private:
209  std::set<rose_addr_t> toBeExamined_; // instructions waiting to be examined
210  std::set<rose_addr_t> wasExamined_; // instructions we've already examined
211  rose_addr_t inProgress_; // instruction that is currently in progress
212  std::vector<rose_addr_t> constants_; // constants for the instruction in progress
213 
214  protected:
215  CodeConstants(): inProgress_(0) {}
216 
217  public:
218  static Ptr instance() { return Ptr(new CodeConstants); }
219 
220  // Possibly insert more instructions into the work list when a basic block is added to the CFG
221  virtual bool operator()(bool chain, const AttachedBasicBlock &attached) ROSE_OVERRIDE;
222 
223  // Possibly remove instructions from the worklist when a basic block is removed from the CFG
224  virtual bool operator()(bool chain, const DetachedBasicBlock &detached) ROSE_OVERRIDE;
225 
226  // Return the next available constant if any.
227  Sawyer::Optional<rose_addr_t> nextConstant(const Partitioner &partitioner);
228 
229  // Address of instruction being examined.
230  rose_addr_t inProgress() const { return inProgress_; }
231  };
232 
234  // Data members
236 private:
237  Settings settings_; // Settings for the partitioner.
238  SgAsmInterpretation *interp_; // interpretation set by loadSpecimen
239  BinaryLoader::Ptr binaryLoader_; // how to remap, link, and fixup
240  Disassembler *disassembler_; // not ref-counted yet, but don't destroy it since user owns it
241  MemoryMap::Ptr map_; // memory map initialized by load()
242  BasicBlockWorkList::Ptr basicBlockWorkList_; // what blocks to work on next
243  CodeConstants::Ptr codeFunctionPointers_; // generates constants that are found in instruction ASTs
244  Progress::Ptr progress_; // optional progress reporting
245  ModulesLinux::LibcStartMain::Ptr libcStartMain_; // looking for "main" by analyzing libc_start_main?
246  ThunkPredicates::Ptr functionMatcherThunks_; // predicates to find thunks when looking for functions
247  ThunkPredicates::Ptr functionSplittingThunks_; // predicates for splitting thunks from front of functions
248 
250  // Constructors
252 public:
255  : interp_(NULL), disassembler_(NULL),
256  basicBlockWorkList_(BasicBlockWorkList::instance(this, settings_.partitioner.functionReturnAnalysisMaxSorts)),
257  progress_(Progress::instance()) {
258  init();
259  }
260 
262  explicit Engine(const Settings &settings)
263  : settings_(settings), interp_(NULL), disassembler_(NULL),
264  basicBlockWorkList_(BasicBlockWorkList::instance(this, settings_.partitioner.functionReturnAnalysisMaxSorts)),
265  progress_(Progress::instance()) {
266  init();
267  }
268 
269  virtual ~Engine() {}
270 
272  // The very top-level use case
274 public:
299  SgAsmBlock* frontend(int argc, char *argv[],
300  const std::string &purpose, const std::string &description);
301  virtual SgAsmBlock* frontend(const std::vector<std::string> &args,
302  const std::string &purpose, const std::string &description);
305  // Basic top-level steps
308 public:
314  void reset();
315 
342  Sawyer::CommandLine::ParserResult parseCommandLine(int argc, char *argv[],
343  const std::string &purpose, const std::string &description) /*final*/;
344  virtual Sawyer::CommandLine::ParserResult parseCommandLine(const std::vector<std::string> &args,
345  const std::string &purpose, const std::string &description);
367  virtual SgAsmInterpretation* parseContainers(const std::vector<std::string> &fileNames);
368  SgAsmInterpretation* parseContainers(const std::string &fileName) /*final*/;
391  virtual MemoryMap::Ptr loadSpecimens(const std::vector<std::string> &fileNames = std::vector<std::string>());
392  MemoryMap::Ptr loadSpecimens(const std::string &fileName) /*final*/;
414  virtual Partitioner partition(const std::vector<std::string> &fileNames = std::vector<std::string>());
415  Partitioner partition(const std::string &fileName) /*final*/;
432  SgAsmBlock* buildAst(const std::vector<std::string> &fileNames = std::vector<std::string>()) /*final*/;
433  SgAsmBlock* buildAst(const std::string &fileName) /*final*/;
441  virtual void savePartitioner(const Partitioner&, const boost::filesystem::path&, SerialIo::Format fmt = SerialIo::BINARY);
442 
447  virtual Partitioner loadPartitioner(const boost::filesystem::path&, SerialIo::Format fmt = SerialIo::BINARY);
448 
450  // Command-line parsing
451  //
452  // top-level: parseCommandLine
454 public:
458  virtual Sawyer::CommandLine::SwitchGroup loaderSwitches();
459  static Sawyer::CommandLine::SwitchGroup loaderSwitches(LoaderSettings&);
465  virtual Sawyer::CommandLine::SwitchGroup disassemblerSwitches();
466  static Sawyer::CommandLine::SwitchGroup disassemblerSwitches(DisassemblerSettings&);
472  virtual Sawyer::CommandLine::SwitchGroup partitionerSwitches();
473  static Sawyer::CommandLine::SwitchGroup partitionerSwitches(PartitionerSettings&);
479  virtual Sawyer::CommandLine::SwitchGroup engineSwitches();
480  static Sawyer::CommandLine::SwitchGroup engineSwitches(EngineSettings&);
486  virtual Sawyer::CommandLine::SwitchGroup astConstructionSwitches();
487  static Sawyer::CommandLine::SwitchGroup astConstructionSwitches(AstConstructionSettings&);
491  static std::string specimenNameDocumentation();
492 
504  virtual Sawyer::CommandLine::Parser commandLineParser(const std::string &purpose, const std::string &description);
505 
512  virtual void checkSettings();
513 
515  // Container parsing
516  //
517  // top-level: parseContainers
519 public:
524  virtual bool isRbaFile(const std::string&);
525 
530  virtual bool isNonContainer(const std::string&);
531 
537  virtual bool areContainersParsed() const;
538 
543  virtual void loadVxCore(const std::string &spec);
544 
546  // Load specimens
547  //
548  // top-level: loadSpecimens
550 public:
554  virtual bool areSpecimensLoaded() const;
555 
571  virtual BinaryLoader::Ptr obtainLoader(const BinaryLoader::Ptr &hint = BinaryLoader::Ptr());
572 
578  virtual void loadContainers(const std::vector<std::string> &fileNames);
579 
584  virtual void loadNonContainers(const std::vector<std::string> &names);
585 
589  virtual void adjustMemoryMap();
590 
599  MemoryMap::Ptr memoryMap() const /*final*/ { return map_; }
600  virtual void memoryMap(const MemoryMap::Ptr &m) { map_ = m; }
604  // Disassembler
607 public:
626  virtual Disassembler* obtainDisassembler(Disassembler *hint=NULL);
630  // Partitioner high-level functions
632  //
633  // top-level: partition
635 public:
637  virtual void checkCreatePartitionerPrerequisites() const;
638 
646  virtual Partitioner createBarePartitioner();
647 
653  virtual Partitioner createGenericPartitioner();
654 
660  virtual Partitioner createTunedPartitioner();
661 
666  virtual Partitioner createPartitionerFromAst(SgAsmInterpretation*);
667 
672  virtual Partitioner createPartitioner();
673 
677  virtual void runPartitionerInit(Partitioner&);
678 
682  virtual void runPartitionerRecursive(Partitioner&);
683 
688  virtual void runPartitionerFinal(Partitioner&);
689 
695  virtual void runPartitioner(Partitioner&);
696 
697 
699  // Partitioner mid-level functions
700  //
701  // These are the functions called by the partitioner high-level stuff. These are sometimes overridden in subclasses,
702  // although it is more likely that the high-level stuff is overridden.
704 public:
709  virtual void labelAddresses(Partitioner&, const Configuration&);
710 
714  virtual std::vector<DataBlock::Ptr> makeConfiguredDataBlocks(Partitioner&, const Configuration&);
715 
719  virtual std::vector<Function::Ptr> makeConfiguredFunctions(Partitioner&, const Configuration&);
720 
727  virtual std::vector<Function::Ptr> makeEntryFunctions(Partitioner&, SgAsmInterpretation*);
728 
735  virtual std::vector<Function::Ptr> makeErrorHandlingFunctions(Partitioner&, SgAsmInterpretation*);
736 
746  virtual std::vector<Function::Ptr> makeImportFunctions(Partitioner&, SgAsmInterpretation*);
747 
754  virtual std::vector<Function::Ptr> makeExportFunctions(Partitioner&, SgAsmInterpretation*);
755 
762  virtual std::vector<Function::Ptr> makeSymbolFunctions(Partitioner&, SgAsmInterpretation*);
763 
771  virtual std::vector<Function::Ptr> makeContainerFunctions(Partitioner&, SgAsmInterpretation*);
772 
779  virtual std::vector<Function::Ptr> makeInterruptVectorFunctions(Partitioner&, const AddressInterval &vector);
780 
785  virtual std::vector<Function::Ptr> makeUserFunctions(Partitioner&, const std::vector<rose_addr_t>&);
786 
793  virtual void discoverBasicBlocks(Partitioner&);
794 
806  virtual Function::Ptr makeNextDataReferencedFunction(const Partitioner&, rose_addr_t &startVa /*in,out*/);
807 
821  virtual Function::Ptr makeNextCodeReferencedFunction(const Partitioner&);
822 
829  virtual std::vector<Function::Ptr> makeCalledFunctions(Partitioner&);
830 
846  virtual std::vector<Function::Ptr> makeNextPrologueFunction(Partitioner&, rose_addr_t startVa);
847  virtual std::vector<Function::Ptr> makeNextPrologueFunction(Partitioner&, rose_addr_t startVa, rose_addr_t &lastSearchedVa);
868  virtual std::vector<Function::Ptr>
869  makeFunctionFromInterFunctionCalls(Partitioner &partitioner, rose_addr_t &startVa /*in,out*/);
870 
877  virtual void discoverFunctions(Partitioner&);
878 
893  virtual std::set<rose_addr_t> attachDeadCodeToFunction(Partitioner&, const Function::Ptr&, size_t maxIterations=size_t(-1));
894 
902  virtual DataBlock::Ptr attachPaddingToFunction(Partitioner&, const Function::Ptr&);
903 
908  virtual std::vector<DataBlock::Ptr> attachPaddingToFunctions(Partitioner&);
909 
920  virtual size_t attachAllSurroundedCodeToFunctions(Partitioner&);
921 
929  virtual size_t attachSurroundedCodeToFunctions(Partitioner&);
930 
935  virtual void attachBlocksToFunctions(Partitioner&);
936 
943  virtual std::set<rose_addr_t> attachDeadCodeToFunctions(Partitioner&, size_t maxIterations=size_t(-1));
944 
954  virtual std::vector<DataBlock::Ptr> attachSurroundedDataToFunctions(Partitioner&);
955 
961  virtual void updateAnalysisResults(Partitioner&);
962 
963 
965  // Partitioner low-level functions
966  //
967  // These are functions that a subclass seldom overrides, and maybe even shouldn't override because of their complexity or
968  // the way the interact with one another.
970 public:
981  virtual bool makeNextCallReturnEdge(Partitioner&, boost::logic::tribool assumeCallReturns);
982 
988  virtual BasicBlock::Ptr makeNextBasicBlockFromPlaceholder(Partitioner&);
989 
1004  virtual BasicBlock::Ptr makeNextBasicBlock(Partitioner&);
1005 
1006 
1008  // Build AST
1010 public:
1011  // Used internally by ROSE's ::frontend disassemble instructions to build the AST that goes under each SgAsmInterpretation.
1012  static void disassembleForRoseFrontend(SgAsmInterpretation*);
1013 
1014 
1016  // Settings and properties
1018 public:
1025  const Settings& settings() const /*final*/ { return settings_; }
1026  Settings& settings() /*final*/ { return settings_; }
1037  bool exitOnError() const /*final*/ { return settings_.engine.exitOnError; }
1038  virtual void exitOnError(bool b) { settings_.engine.exitOnError = b; }
1046  Progress::Ptr progress() const /*final*/ { return progress_; }
1047  virtual void progress(const Progress::Ptr &progress) { progress_ = progress; }
1057  SgAsmInterpretation* interpretation() const /*final*/ { return interp_; }
1058  virtual void interpretation(SgAsmInterpretation *interp) { interp_ = interp; }
1067  BinaryLoader::Ptr binaryLoader() const /*final*/ { return binaryLoader_; }
1068  virtual void binaryLoader(const BinaryLoader::Ptr &loader) { binaryLoader_ = loader; }
1081  size_t deExecuteZerosThreshold() const /*final*/ { return settings_.loader.deExecuteZerosThreshold; }
1082  virtual void deExecuteZerosThreshold(size_t n) { settings_.loader.deExecuteZerosThreshold = n; }
1083  size_t deExecuteZerosLeaveAtFront() const /*final*/ { return settings_.loader.deExecuteZerosLeaveAtFront; }
1084  virtual void deExecuteZerosLeaveAtFront(size_t n) { settings_.loader.deExecuteZerosLeaveAtFront = n; }
1085  size_t deExecuteZerosLeaveAtBack() const /*final*/ { return settings_.loader.deExecuteZerosLeaveAtBack; }
1086  virtual void deExecuteZerosLeaveAtBack(size_t n) { settings_.loader.deExecuteZerosLeaveAtBack = n; }
1101  MemoryDataAdjustment memoryDataAdjustment() const /*final*/ { return settings_.loader.memoryDataAdjustment; }
1102  virtual void memoryDataAdjustment(MemoryDataAdjustment x) { settings_.loader.memoryDataAdjustment = x; }
1112  bool memoryIsExecutable() const /*final*/ { return settings_.loader.memoryIsExecutable; }
1113  virtual void memoryIsExecutable(bool b) { settings_.loader.memoryIsExecutable = b; }
1125  bool linkObjectFiles() const /*final*/ { return settings_.loader.linkObjectFiles; }
1126  virtual void linkObjectFiles(bool b) { settings_.loader.linkObjectFiles = b; }
1138  bool linkStaticArchives() const /*final*/ { return settings_.loader.linkStaticArchives; }
1139  virtual void linkStaticArchives(bool b) { settings_.loader.linkStaticArchives = b; }
1150  const std::string& linkerCommand() const /*final*/ { return settings_.loader.linker; }
1151  virtual void linkerCommand(const std::string &cmd) { settings_.loader.linker = cmd; }
1159  const std::vector<std::string> environmentEraseNames() const /*final*/ { return settings_.loader.envEraseNames; }
1160  virtual void environmentEraseNames(const std::vector<std::string> &names) { settings_.loader.envEraseNames = names; }
1169  const std::vector<boost::regex> environmentErasePatterns() const /*final*/ { return settings_.loader.envErasePatterns; }
1170  virtual void environmentErasePatterns(const std::vector<boost::regex> &res) { settings_.loader.envErasePatterns = res; }
1180  const std::vector<std::string> environmentInsertions() const /*final*/ { return settings_.loader.envInsert; }
1181  virtual void environmentInsertions(const std::vector<std::string> &vars) { settings_.loader.envInsert = vars; }
1189  bool doDisassemble() const /*final*/ { return settings_.disassembler.doDisassemble; }
1190  virtual void doDisassemble(bool b) { settings_.disassembler.doDisassemble = b; }
1199  Disassembler *disassembler() const /*final*/ { return disassembler_; }
1200  virtual void disassembler(Disassembler *d) { disassembler_ = d; }
1209  const std::string& isaName() const /*final*/ { return settings_.disassembler.isaName; }
1210  virtual void isaName(const std::string &s) { settings_.disassembler.isaName = s; }
1213  // This is a list of addresses where functions will be created in addition to those functions discovered by examining the
1214  // binary container. Use functionStartingVas instead.
1215  // DEPRECATED on 5/27/20
1216  const std::vector<rose_addr_t>& startingVas() const ROSE_DEPRECATED("use functionStartingVas") /*final*/ { return settings_.partitioner.functionStartingVas; }
1217  std::vector<rose_addr_t>& startingVas() ROSE_DEPRECATED("use functionStartingVas") /*final*/ { return settings_.partitioner.functionStartingVas; }
1218 
1225  const std::vector<rose_addr_t>& functionStartingVas() const /*final*/ { return settings_.partitioner.functionStartingVas; }
1226  std::vector<rose_addr_t>& functionStartingVas() /*final*/ { return settings_.partitioner.functionStartingVas; }
1235  bool usingSemantics() const /*final*/ { return settings_.partitioner.base.usingSemantics; }
1236  virtual void usingSemantics(bool b) { settings_.partitioner.base.usingSemantics = b; }
1247  bool ignoringUnknownInsns() const /*final*/ { return settings_.partitioner.base.ignoringUnknownInsns; }
1248  virtual void ignoringUnknownInsns(bool b) { settings_.partitioner.base.ignoringUnknownInsns = b; }
1257  SemanticMemoryParadigm semanticMemoryParadigm() const /*final*/ { return settings_.partitioner.semanticMemoryParadigm; }
1258  virtual void semanticMemoryParadigm(SemanticMemoryParadigm p) { settings_.partitioner.semanticMemoryParadigm = p; }
1287  bool followingGhostEdges() const /*final*/ { return settings_.partitioner.followingGhostEdges; }
1288  virtual void followingGhostEdges(bool b) { settings_.partitioner.followingGhostEdges = b; }
1298  bool discontiguousBlocks() const /*final*/ { return settings_.partitioner.discontiguousBlocks; }
1299  virtual void discontiguousBlocks(bool b) { settings_.partitioner.discontiguousBlocks = b; }
1309  size_t maxBasicBlockSize() const /*final*/ { return settings_.partitioner.maxBasicBlockSize; }
1310  virtual void maxBasicBlockSize(size_t n) { settings_.partitioner.maxBasicBlockSize = n; }
1321  const std::vector<rose_addr_t>& ipRewrites() const /*final*/ { return settings_.partitioner.ipRewrites; }
1322  virtual void ipRewrites(const std::vector<rose_addr_t> &v) { settings_.partitioner.ipRewrites = v; }
1331  bool findingFunctionPadding() const /*final*/ { return settings_.partitioner.findingFunctionPadding; }
1332  virtual void findingFunctionPadding(bool b) { settings_.partitioner.findingFunctionPadding = b; }
1341  bool findingThunks() const /*final*/ { return settings_.partitioner.findingThunks; }
1342  virtual void findingThunks(bool b) { settings_.partitioner.findingThunks = b; }
1353  ThunkPredicates::Ptr functionMatcherThunks() const /*final*/ { return functionMatcherThunks_; }
1354  virtual void functionMatcherThunks(const ThunkPredicates::Ptr &p) { functionMatcherThunks_ = p; }
1363  bool splittingThunks() const /*final*/ { return settings_.partitioner.splittingThunks; }
1364  virtual void splittingThunks(bool b) { settings_.partitioner.splittingThunks = b; }
1375  ThunkPredicates::Ptr functionSplittingThunks() const /*final*/ { return functionSplittingThunks_; }
1376  virtual void functionSplittingThunks(const ThunkPredicates::Ptr &p) { functionSplittingThunks_ = p; }
1387  bool findingDeadCode() const /*final*/ { return settings_.partitioner.findingDeadCode; }
1388  virtual void findingDeadCode(bool b) { settings_.partitioner.findingDeadCode = b; }
1397  rose_addr_t peScramblerDispatcherVa() const /*final*/ { return settings_.partitioner.peScramblerDispatcherVa; }
1398  virtual void peScramblerDispatcherVa(rose_addr_t va) { settings_.partitioner.peScramblerDispatcherVa = va; }
1408  size_t findingIntraFunctionCode() const /*final*/ { return settings_.partitioner.findingIntraFunctionCode; }
1409  virtual void findingIntraFunctionCode(size_t n) { settings_.partitioner.findingIntraFunctionCode = n; }
1418  bool findingIntraFunctionData() const /*final*/ { return settings_.partitioner.findingIntraFunctionData; }
1419  virtual void findingIntraFunctionData(bool b) { settings_.partitioner.findingIntraFunctionData = b; }
1428  const AddressInterval& interruptVector() const /*final*/ { return settings_.partitioner.interruptVector; }
1429  virtual void interruptVector(const AddressInterval &i) { settings_.partitioner.interruptVector = i; }
1438  bool doingPostAnalysis() const /*final*/ { return settings_.partitioner.doingPostAnalysis; }
1439  virtual void doingPostAnalysis(bool b) { settings_.partitioner.doingPostAnalysis = b; }
1447  bool doingPostFunctionMayReturn() const /*final*/ { return settings_.partitioner.doingPostFunctionMayReturn; }
1448  virtual void doingPostFunctionMayReturn(bool b) { settings_.partitioner.doingPostFunctionMayReturn = b; }
1456  bool doingPostFunctionStackDelta() const /*final*/ { return settings_.partitioner.doingPostFunctionStackDelta; }
1457  virtual void doingPostFunctionStackDelta(bool b) { settings_.partitioner.doingPostFunctionStackDelta = b; }
1465  bool doingPostCallingConvention() const /*final*/ { return settings_.partitioner.doingPostCallingConvention; }
1466  virtual void doingPostCallingConvention(bool b) { settings_.partitioner.doingPostCallingConvention = b; }
1475  bool doingPostFunctionNoop() const /*final*/ { return settings_.partitioner.doingPostFunctionNoop; }
1476  virtual void doingPostFunctionNoop(bool b) { settings_.partitioner.doingPostFunctionNoop = b; }
1485  FunctionReturnAnalysis functionReturnAnalysis() const /*final*/ { return settings_.partitioner.functionReturnAnalysis; }
1486  virtual void functionReturnAnalysis(FunctionReturnAnalysis x) { settings_.partitioner.functionReturnAnalysis = x; }
1501  size_t functionReturnAnalysisMaxSorts() const /*final*/ { return settings_.partitioner.functionReturnAnalysisMaxSorts; }
1502  virtual void functionReturnAnalysisMaxSorts(size_t n) { settings_.partitioner.functionReturnAnalysisMaxSorts = n; }
1511  bool findingInterFunctionCalls() const /*final*/ { return settings_.partitioner.findingInterFunctionCalls; }
1512  virtual void findingInterFunctionCalls(bool b) { settings_.partitioner.findingInterFunctionCalls = b; }
1521  bool findingFunctionCallFunctions() const /*final*/ { return settings_.partitioner.findingFunctionCallFunctions; }
1522  virtual void findingFunctionCallFunctions(bool b) { settings_.partitioner.findingFunctionCallFunctions = b; }
1530  bool findingEntryFunctions() const /*final*/ { return settings_.partitioner.findingEntryFunctions; }
1531  virtual void findingEntryFunctions(bool b) { settings_.partitioner.findingEntryFunctions = b; }
1540  bool findingErrorFunctions() const /*final*/ { return settings_.partitioner.findingErrorFunctions; }
1541  virtual void findingErrorFunctions(bool b) { settings_.partitioner.findingErrorFunctions = b; }
1550  bool findingImportFunctions() const /*final*/ { return settings_.partitioner.findingImportFunctions; }
1551  virtual void findingImportFunctions(bool b) { settings_.partitioner.findingImportFunctions = b; }
1560  bool findingExportFunctions() const /*final*/ { return settings_.partitioner.findingExportFunctions; }
1561  virtual void findingExportFunctions(bool b) { settings_.partitioner.findingExportFunctions = b; }
1570  bool findingSymbolFunctions() const /*final*/ { return settings_.partitioner.findingSymbolFunctions; }
1571  virtual void findingSymbolFunctions(bool b) { settings_.partitioner.findingSymbolFunctions = b; }
1580  bool findingDataFunctionPointers() const /*final*/ { return settings_.partitioner.findingDataFunctionPointers; }
1581  virtual void findingDataFunctionPointers(bool b) { settings_.partitioner.findingDataFunctionPointers = b; }
1590  bool findingCodeFunctionPointers() const /*final*/ { return settings_.partitioner.findingCodeFunctionPointers; }
1591  virtual void findingCodeFunctionPointers(bool b) { settings_.partitioner.findingCodeFunctionPointers = b; }
1599  bool checkingCallBranch() const /*final*/ { return settings_.partitioner.base.checkingCallBranch; }
1600  virtual void checkingCallBranch(bool b) { settings_.partitioner.base.checkingCallBranch = b; }
1614  bool basicBlockSemanticsAutoDrop() const /*final*/ { return settings_.partitioner.base.basicBlockSemanticsAutoDrop; }
1615  void basicBlockSemanticsAutoDrop(bool b) { settings_.partitioner.base.basicBlockSemanticsAutoDrop = b; }
1623  const std::vector<std::string>& configurationNames() /*final*/ const { return settings_.engine.configurationNames; }
1624  std::vector<std::string>& configurationNames() /*final*/ { return settings_.engine.configurationNames; }
1632  bool namingConstants() const /*final*/ { return settings_.partitioner.namingConstants; }
1633  virtual void namingConstants(bool b) { settings_.partitioner.namingConstants = b; }
1641  bool namingStrings() const /*final*/ { return settings_.partitioner.namingStrings; }
1642  virtual void namingStrings(bool b) { settings_.partitioner.namingStrings = b; }
1651  bool namingSystemCalls() const /*final*/ { return settings_.partitioner.namingSyscalls; }
1652  virtual void namingSystemCalls(bool b) { settings_.partitioner.namingSyscalls = b; }
1662  const boost::filesystem::path& systemCallHeader() const /*final*/ { return settings_.partitioner.syscallHeader; }
1663  virtual void systemCallHeader(const boost::filesystem::path &filename) { settings_.partitioner.syscallHeader = filename; }
1672  bool demangleNames() const /*final*/ { return settings_.partitioner.demangleNames; }
1673  virtual void demangleNames(bool b) { settings_.partitioner.demangleNames = b; }
1682  bool astAllowEmptyGlobalBlock() const /*final*/ { return settings_.astConstruction.allowEmptyGlobalBlock; }
1683  virtual void astAllowEmptyGlobalBlock(bool b) { settings_.astConstruction.allowEmptyGlobalBlock = b; }
1692  bool astAllowFunctionWithNoBasicBlocks() const /*final*/ {
1693  return settings_.astConstruction.allowFunctionWithNoBasicBlocks;
1694  }
1695  virtual void astAllowFunctionWithNoBasicBlocks(bool b) {
1696  settings_.astConstruction.allowFunctionWithNoBasicBlocks = b;
1697  }
1706  bool astAllowEmptyBasicBlock() const /*final*/ { return settings_.astConstruction.allowEmptyBasicBlocks; }
1707  virtual void astAllowEmptyBasicBlock(bool b) { settings_.astConstruction.allowEmptyBasicBlocks = b; }
1719  bool astCopyAllInstructions() const /*final*/ { return settings_.astConstruction.copyAllInstructions; }
1720  virtual void astCopyAllInstructions(bool b) { settings_.astConstruction.copyAllInstructions = b; }
1723  // Python API support functions
1726 #ifdef ROSE_ENABLE_PYTHON_API
1727 
1728  // Similar to frontend, but returns a partitioner rather than an AST since the Python API doesn't yet support ASTs.
1729  Partitioner pythonParseVector(boost::python::list &pyArgs, const std::string &purpose, const std::string &description);
1730  Partitioner pythonParseSingle(const std::string &specimen, const std::string &purpose, const std::string &description);
1731 
1732 #endif
1733 
1735  // Internal stuff
1737 private:
1738  void init();
1739 
1740  // Similar to ::frontend but a lot less complicated.
1741  SgProject* roseFrontendReplacement(const std::vector<boost::filesystem::path> &fileNames);
1742 };
1743 
1744 } // namespace
1745 } // namespace
1746 } // namespace
1747 
1748 #endif
1749 #endif
size_t maxBasicBlockSize() const
Property: Maximum size for basic blocks.
const Settings & settings() const
Property: All settings.
bool doingPostFunctionStackDelta() const
Property: Whether to run the function stack delta analysis.
virtual void linkObjectFiles(bool b)
Property: Link object files.
virtual void memoryIsExecutable(bool b)
Property: Global adjustment to executability.
virtual void systemCallHeader(const boost::filesystem::path &filename)
Property: Header file in which system calls are defined.
size_t findingIntraFunctionCode() const
Property: Whether to find intra-function code.
virtual void disassembler(Disassembler *d)
Property: Disassembler.
bool checkingCallBranch() const
Property: Whether to look for function calls used as branches.
virtual void maxBasicBlockSize(size_t n)
Property: Maximum size for basic blocks.
Settings for controling the engine behavior.
Definition: BasicTypes.h:481
virtual void ignoringUnknownInsns(bool b)
Property: Whether unknown instructions are ignored.
virtual void namingStrings(bool b)
Property: Give names to string literal addresses.
MemoryDataAdjustment
How the partitioner should globally treat memory.
Definition: BasicTypes.h:183
bool findingInterFunctionCalls() const
Property: Whether to search for function calls between exiting functions.
Instruction basic block.
const std::vector< rose_addr_t > & functionStartingVas() const
Property: Starting addresses for disassembly.
virtual void findingExportFunctions(bool b)
Property: Whether to make functions at export addresses.
Progress::Ptr progress() const
Property: progress reporting.
Base class for adjusting basic blocks during discovery.
Definition: Modules.h:43
virtual void findingFunctionCallFunctions(bool b)
Property: Whether to turn function call targets into functions.
virtual void followingGhostEdges(bool b)
Property: Whether to follow ghost edges.
virtual void interruptVector(const AddressInterval &i)
Property: Location of machine interrupt vector.
virtual void astCopyAllInstructions(bool b)
Property: Whether to copy instructions when building the AST.
virtual void findingSymbolFunctions(bool b)
Property: Whether to make functions according to symbol tables.
Sawyer::SharedPointer< BinaryLoader > Ptr
Referenc counting pointer to BinaryLoader.
Definition: BinaryLoader.h:63
bool namingStrings() const
Property: Give names to string literal addresses.
bool findingDeadCode() const
Property: Whether to find dead code.
virtual void findingCodeFunctionPointers(bool b)
Property: Whether to search existing instructions for function pointers.
size_t functionReturnAnalysisMaxSorts() const
Property: Maximum number of function may-return sorting operations.
virtual void functionSplittingThunks(const ThunkPredicates::Ptr &p)
Property: Predicate for finding thunks at the start of functions.
const std::vector< std::string > & configurationNames() const
Property: Configuration files.
virtual void doingPostFunctionNoop(bool b)
Property: Whether to run no-op function analysis.
std::vector< rose_addr_t > & functionStartingVas()
Property: Starting addresses for disassembly.
Settings that control the disassembler.
Definition: BasicTypes.h:276
Base class for engines driving the partitioner.
Engine(const Settings &settings)
Construct engine with settings.
The result from parsing a command line.
bool namingConstants() const
Property: Give names to constants.
Disassembler * disassembler() const
Property: Disassembler.
virtual void exitOnError(bool b)
Property: Error handling.
const std::vector< std::string > environmentInsertions() const
Property: Environment variables to insert.
virtual void peScramblerDispatcherVa(rose_addr_t va)
Property: PE-Scrambler dispatcher address.
SemanticMemoryParadigm semanticMemoryParadigm() const
Property: Type of container for semantic memory.
List of things to work on.
Definition: WorkLists.h:60
FunctionReturnAnalysis functionReturnAnalysis() const
Property: Whether to run the function may-return analysis.
ThunkPredicates::Ptr functionSplittingThunks() const
Property: Predicate for finding thunks at the start of functions.
size_t deExecuteZerosLeaveAtBack() const
Property: when to remove execute permission from zero bytes.
const std::string & isaName() const
Property: Instruction set architecture name.
virtual void findingIntraFunctionData(bool b)
Property: Whether to find intra-function data.
A collection of related switch declarations.
MemoryDataAdjustment memoryDataAdjustment() const
Property: Global adjustments to memory map data access bits.
bool linkObjectFiles() const
Property: Link object files.
virtual void findingDataFunctionPointers(bool b)
Property: Whether to search static data for function pointers.
Sawyer::SharedPointer< LibcStartMain > Ptr
Shared ownership pointer to LibcStartMain callback.
Definition: ModulesLinux.h:46
virtual void isaName(const std::string &s)
Property: Instruction set architecture name.
virtual void findingErrorFunctions(bool b)
Property: Whether to make error handling functions.
virtual void memoryMap(const MemoryMap::Ptr &m)
Property: memory map.
bool findingErrorFunctions() const
Property: Whether to make error handling functions.
Main namespace for the ROSE library.
Settings for loading specimens.
Definition: BasicTypes.h:198
Settings that control building the AST.
Definition: BasicTypes.h:94
BinaryLoader::Ptr binaryLoader() const
Property: binary loader.
virtual void findingEntryFunctions(bool b)
Property: Whether to make functions at program entry points.
bool followingGhostEdges() const
Property: Whether to follow ghost edges.
bool demangleNames() const
Property: Demangle names.
bool astAllowEmptyGlobalBlock() const
Property: Whether to allow empty global block in the AST.
bool findingFunctionPadding() const
Property: Whether to find function padding.
bool doingPostCallingConvention() const
Property: Whether to run calling-convention analysis.
bool discontiguousBlocks() const
Property: Whether to allow discontiguous basic blocks.
virtual void namingConstants(bool b)
Property: Give names to constants.
bool doDisassemble() const
Property: Perform disassembly.
bool findingIntraFunctionData() const
Property: Whether to find intra-function data.
virtual void findingIntraFunctionCode(size_t n)
Property: Whether to find intra-function code.
ThunkPredicates::Ptr functionMatcherThunks() const
Property: Predicate for finding functions that are thunks.
virtual void astAllowEmptyGlobalBlock(bool b)
Property: Whether to allow empty global block in the AST.
bool memoryIsExecutable() const
Property: Global adjustment to executability.
bool doingPostFunctionMayReturn() const
Property: Whether to run the function may-return analysis.
virtual void doingPostFunctionStackDelta(bool b)
Property: Whether to run the function stack delta analysis.
virtual void findingThunks(bool b)
Property: Whether to find thunk patterns.
virtual void usingSemantics(bool b)
Property: Whether to use instruction semantics.
virtual void findingFunctionPadding(bool b)
Property: Whether to find function padding.
size_t deExecuteZerosLeaveAtFront() const
Property: when to remove execute permission from zero bytes.
bool astAllowFunctionWithNoBasicBlocks() const
Property: Whether to allow empty functions in the AST.
const std::vector< boost::regex > environmentErasePatterns() const
Property: Environment variable erasure patterns.
bool namingSystemCalls() const
Property: Give names to system calls.
virtual void astAllowEmptyBasicBlock(bool b)
Property: Whether to allow empty basic blocks in the AST.
The parser for a program command line.
virtual void semanticMemoryParadigm(SemanticMemoryParadigm p)
Property: Type of container for semantic memory.
virtual void interpretation(SgAsmInterpretation *interp)
Property: interpretation.
const AddressInterval & interruptVector() const
Property: Location of machine interrupt vector.
Settings that control the engine partitioning.
Definition: BasicTypes.h:346
virtual void deExecuteZerosLeaveAtBack(size_t n)
Property: when to remove execute permission from zero bytes.
std::vector< std::string > & configurationNames()
Property: Configuration files.
bool findingSymbolFunctions() const
Property: Whether to make functions according to symbol tables.
virtual void environmentInsertions(const std::vector< std::string > &vars)
Property: Environment variables to insert.
bool findingDataFunctionPointers() const
Property: Whether to search static data for function pointers.
DisassemblerSettings disassembler
Settings for creating the disassembler.
virtual void ipRewrites(const std::vector< rose_addr_t > &v)
Property: CFG edge rewrite pairs.
SemanticMemoryParadigm
Organization of semantic memory.
Definition: BasicTypes.h:85
virtual void findingImportFunctions(bool b)
Property: Whether to make functions at import addresses.
virtual void findingDeadCode(bool b)
Property: Whether to find dead code.
bool findingCodeFunctionPointers() const
Property: Whether to search existing instructions for function pointers.
virtual void deExecuteZerosThreshold(size_t n)
Property: when to remove execute permission from zero bytes.
FunctionReturnAnalysis
Controls whether the function may-return analysis runs.
Definition: BasicTypes.h:299
bool findingEntryFunctions() const
Property: Whether to make functions at program entry points.
SgAsmInterpretation * interpretation() const
Property: interpretation.
virtual void checkingCallBranch(bool b)
Property: Whether to look for function calls used as branches.
AstConstructionSettings astConstruction
Settings for constructing the AST.
bool astCopyAllInstructions() const
Property: Whether to copy instructions when building the AST.
size_t deExecuteZerosThreshold() const
Property: when to remove execute permission from zero bytes.
virtual void demangleNames(bool b)
Property: Demangle names.
bool doingPostAnalysis() const
Property: Whether to perform post-partitioning analysis steps.
bool usingSemantics() const
Property: Whether to use instruction semantics.
virtual void environmentEraseNames(const std::vector< std::string > &names)
Property: Environment variable erasure names.
void basicBlockSemanticsAutoDrop(bool b)
Property: Automatically drop semantics for attached basic blocks.
MemoryMap::Ptr memoryMap() const
Property: memory map.
bool exitOnError() const
Property: Error handling.
bool doingPostFunctionNoop() const
Property: Whether to run no-op function analysis.
const boost::filesystem::path & systemCallHeader() const
Property: Header file in which system calls are defined.
A general, thread-safe way to report progress made on some task.
Definition: Progress.h:165
bool findingExportFunctions() const
Property: Whether to make functions at export addresses.
virtual void splittingThunks(bool b)
Property: Whether to split thunk instructions into mini functions.
virtual void astAllowFunctionWithNoBasicBlocks(bool b)
Property: Whether to allow empty functions in the AST.
bool linkStaticArchives() const
Property: Link library archives.
bool astAllowEmptyBasicBlock() const
Property: Whether to allow empty basic blocks in the AST.
virtual void functionMatcherThunks(const ThunkPredicates::Ptr &p)
Property: Predicate for finding functions that are thunks.
virtual void deExecuteZerosLeaveAtFront(size_t n)
Property: when to remove execute permission from zero bytes.
rose_addr_t peScramblerDispatcherVa() const
Property: PE-Scrambler dispatcher address.
virtual void environmentErasePatterns(const std::vector< boost::regex > &res)
Property: Environment variable erasure patterns.
bool findingImportFunctions() const
Property: Whether to make functions at import addresses.
virtual void linkerCommand(const std::string &cmd)
Property: Linker command.
Format
Format of the state file.
virtual void findingInterFunctionCalls(bool b)
Property: Whether to search for function calls between exiting functions.
This class represents a source project, with a list of SgFile objects and global information about th...
PartitionerSettings partitioner
Settings for creating a partitioner.
bool findingFunctionCallFunctions() const
Property: Whether to turn function call targets into functions.
LoaderSettings loader
Settings used during specimen loading.
virtual void binaryLoader(const BinaryLoader::Ptr &loader)
Property: binary loader.
virtual void doingPostCallingConvention(bool b)
Property: Whether to run calling-convention analysis.
virtual void namingSystemCalls(bool b)
Property: Give names to system calls.
virtual void discontiguousBlocks(bool b)
Property: Whether to allow discontiguous basic blocks.
bool findingThunks() const
Property: Whether to find thunk patterns.
virtual void doDisassemble(bool b)
Property: Perform disassembly.
Partitions instructions into basic blocks and functions.
Definition: Partitioner.h:323
Base class for all ROSE exceptions.
Definition: RoseException.h:9
const std::vector< std::string > environmentEraseNames() const
Property: Environment variable erasure names.
virtual void doingPostFunctionMayReturn(bool b)
Property: Whether to run the function may-return analysis.
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:50
Represents an interpretation of a binary container.
virtual void functionReturnAnalysis(FunctionReturnAnalysis x)
Property: Whether to run the function may-return analysis.
EngineSettings engine
Settings that control engine behavior.
bool basicBlockSemanticsAutoDrop() const
Property: Automatically drop semantics for attached basic blocks.
virtual void linkStaticArchives(bool b)
Property: Link library archives.
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.
virtual void doingPostAnalysis(bool b)
Property: Whether to perform post-partitioning analysis steps.
virtual void progress(const Progress::Ptr &progress)
Property: progress reporting.
Sawyer::SharedPointer< Progress > Ptr
Progress objects are reference counted.
Definition: Progress.h:168
bool ignoringUnknownInsns() const
Property: Whether unknown instructions are ignored.
virtual void memoryDataAdjustment(MemoryDataAdjustment x)
Property: Global adjustments to memory map data access bits.
Holds configuration information.
Definition: Config.h:282
const std::string & linkerCommand() const
Property: Linker command.
bool splittingThunks() const
Property: Whether to split thunk instructions into mini functions.
const std::vector< rose_addr_t > & ipRewrites() const
Property: CFG edge rewrite pairs.