ROSE  0.11.83.1
Partitioner2/Engine.h
1 #ifndef ROSE_BinaryAnalysis_Partitioner2_Engine_H
2 #define ROSE_BinaryAnalysis_Partitioner2_Engine_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <Rose/BinaryAnalysis/BinaryLoader.h>
7 #include <Rose/BinaryAnalysis/SerialIo.h>
8 #include <boost/noncopyable.hpp>
9 #include <boost/regex.hpp>
10 #include <Rose/BinaryAnalysis/Disassembler.h>
11 #include <Rose/FileSystem.h>
12 #include <Rose/BinaryAnalysis/Partitioner2/Function.h>
13 #include <Rose/BinaryAnalysis/Partitioner2/ModulesLinux.h>
14 #include <Rose/BinaryAnalysis/Partitioner2/Partitioner.h>
15 #include <Rose/BinaryAnalysis/Partitioner2/Thunk.h>
16 #include <Rose/BinaryAnalysis/Partitioner2/Utility.h>
17 #include <Rose/Progress.h>
18 #include <Rose/Exception.h>
19 #include <Sawyer/DistinctList.h>
20 #include <stdexcept>
21 
22 #ifdef ROSE_ENABLE_PYTHON_API
23 #undef slots // stupid Qt pollution
24 #include <boost/python.hpp>
25 #endif
26 
27 namespace Rose {
28 namespace BinaryAnalysis {
29 namespace Partitioner2 {
30 
114 class ROSE_DLL_API Engine: private boost::noncopyable {
115 public:
119  struct Settings {
126  private:
127  friend class boost::serialization::access;
128 
129  template<class S>
130  void serialize(S &s, unsigned version) {
131  s & loader & disassembler & partitioner & engine & astConstruction;
132  }
133  };
134 
136  class Exception: public Rose::Exception {
137  public:
138  Exception(const std::string &mesg)
139  : Rose::Exception(mesg) {}
140  ~Exception() throw () {}
141  };
142 
144  // Internal data structures
146 private:
147  // Engine callback for handling instructions added to basic blocks. This is called when a basic block is discovered,
148  // before it's attached to a partitioner, so it shouldn't really be modifying any state in the engine, but rather only
149  // preparing the basic block to be processed.
150  class BasicBlockFinalizer: public BasicBlockCallback {
151  typedef Sawyer::Container::Map<rose_addr_t /*target*/, std::vector<rose_addr_t> /*sources*/> WorkList;
152  public:
153  static Ptr instance() { return Ptr(new BasicBlockFinalizer); }
154  virtual bool operator()(bool chain, const Args &args) override;
155  private:
156  void fixFunctionReturnEdge(const Args&);
157  void fixFunctionCallEdges(const Args&);
158  void addPossibleIndeterminateEdge(const Args&);
159  };
160 
161  // Basic blocks that need to be worked on next. These lists are adjusted whenever a new basic block (or placeholder) is
162  // inserted or erased from the CFG.
163  class BasicBlockWorkList: public CfgAdjustmentCallback {
164  // The following lists are used for adding outgoing E_CALL_RETURN edges to basic blocks based on whether the basic
165  // block is a call to a function that might return. When a new basic block is inserted into the CFG (or a previous
166  // block is removed, modified, and re-inserted), the operator() is called and conditionally inserts the block into the
167  // "pendingCallReturn" list (if the block is a function call that lacks an E_CALL_RETURN edge and the function is known
168  // to return or the analysis was incomplete).
169  //
170  // When we run out of other ways to create basic blocks, we process the pendingCallReturn list from back to front. If
171  // the back block (which gets popped) has a positive may-return result then an E_CALL_RETURN edge is added to the CFG
172  // and the normal recursive BB discovery is resumed. Otherwise if the analysis is incomplete the basic block is moved
173  // to the processedCallReturn list. The entire pendingCallReturn list is processed before proceeding.
174  //
175  // If there is no more pendingCallReturn work to be done, then the processedCallReturn blocks are moved to the
176  // finalCallReturn list and finalCallReturn is sorted by approximate CFG height (i.e., leafs first). The contents
177  // of the finalCallReturn list is then analyzed and the result (or the default may-return value for failed analyses)
178  // is used to decide whether a new CFG edge should be created, possibly adding new basic block addresses to the
179  // list of undiscovered blocks.
180  //
181  Sawyer::Container::DistinctList<rose_addr_t> pendingCallReturn_; // blocks that might need an E_CALL_RETURN edge
182  Sawyer::Container::DistinctList<rose_addr_t> processedCallReturn_; // call sites whose may-return was indeterminate
183  Sawyer::Container::DistinctList<rose_addr_t> finalCallReturn_; // indeterminate call sites awaiting final analysis
184 
185  Sawyer::Container::DistinctList<rose_addr_t> undiscovered_; // undiscovered basic block list (last-in-first-out)
186  Engine *engine_; // engine to which this callback belongs
187  size_t maxSorts_; // max sorts before using unsorted lists
188  protected:
189  BasicBlockWorkList(Engine *engine, size_t maxSorts): engine_(engine), maxSorts_(maxSorts) {}
190  public:
192  static Ptr instance(Engine *engine, size_t maxSorts) { return Ptr(new BasicBlockWorkList(engine, maxSorts)); }
193  virtual bool operator()(bool chain, const AttachedBasicBlock &args) override;
194  virtual bool operator()(bool chain, const DetachedBasicBlock &args) override;
195  Sawyer::Container::DistinctList<rose_addr_t>& pendingCallReturn() { return pendingCallReturn_; }
196  Sawyer::Container::DistinctList<rose_addr_t>& processedCallReturn() { return processedCallReturn_; }
197  Sawyer::Container::DistinctList<rose_addr_t>& finalCallReturn() { return finalCallReturn_; }
198  Sawyer::Container::DistinctList<rose_addr_t>& undiscovered() { return undiscovered_; }
199  void moveAndSortCallReturn(const Partitioner&);
200  };
201 
202  // A work list providing constants from instructions that are part of the CFG.
203  class CodeConstants: public CfgAdjustmentCallback {
204  public:
206 
207  private:
208  std::set<rose_addr_t> toBeExamined_; // instructions waiting to be examined
209  std::set<rose_addr_t> wasExamined_; // instructions we've already examined
210  rose_addr_t inProgress_; // instruction that is currently in progress
211  std::vector<rose_addr_t> constants_; // constants for the instruction in progress
212 
213  protected:
214  CodeConstants(): inProgress_(0) {}
215 
216  public:
217  static Ptr instance() { return Ptr(new CodeConstants); }
218 
219  // Possibly insert more instructions into the work list when a basic block is added to the CFG
220  virtual bool operator()(bool chain, const AttachedBasicBlock &attached) override;
221 
222  // Possibly remove instructions from the worklist when a basic block is removed from the CFG
223  virtual bool operator()(bool chain, const DetachedBasicBlock &detached) override;
224 
225  // Return the next available constant if any.
226  Sawyer::Optional<rose_addr_t> nextConstant(const Partitioner &partitioner);
227 
228  // Address of instruction being examined.
229  rose_addr_t inProgress() const { return inProgress_; }
230  };
231 
233  // Data members
235 private:
236  Settings settings_; // Settings for the partitioner.
237  SgAsmInterpretation *interp_; // interpretation set by loadSpecimen
238  BinaryLoader::Ptr binaryLoader_; // how to remap, link, and fixup
239  Disassembler *disassembler_; // not ref-counted yet, but don't destroy it since user owns it
240  MemoryMap::Ptr map_; // memory map initialized by load()
241  BasicBlockWorkList::Ptr basicBlockWorkList_; // what blocks to work on next
242  CodeConstants::Ptr codeFunctionPointers_; // generates constants that are found in instruction ASTs
243  Progress::Ptr progress_; // optional progress reporting
244  ModulesLinux::LibcStartMain::Ptr libcStartMain_; // looking for "main" by analyzing libc_start_main?
245  ThunkPredicates::Ptr functionMatcherThunks_; // predicates to find thunks when looking for functions
246  ThunkPredicates::Ptr functionSplittingThunks_; // predicates for splitting thunks from front of functions
247 
249  // Constructors
251 public:
254  : interp_(NULL), disassembler_(NULL),
255  basicBlockWorkList_(BasicBlockWorkList::instance(this, settings_.partitioner.functionReturnAnalysisMaxSorts)),
256  progress_(Progress::instance()) {
257  init();
258  }
259 
261  explicit Engine(const Settings &settings)
262  : settings_(settings), interp_(NULL), disassembler_(NULL),
263  basicBlockWorkList_(BasicBlockWorkList::instance(this, settings_.partitioner.functionReturnAnalysisMaxSorts)),
264  progress_(Progress::instance()) {
265  init();
266  }
267 
268  virtual ~Engine() {}
269 
271  // The very top-level use case
273 public:
298  SgAsmBlock* frontend(int argc, char *argv[],
299  const std::string &purpose, const std::string &description);
300  virtual SgAsmBlock* frontend(const std::vector<std::string> &args,
301  const std::string &purpose, const std::string &description);
304  // Basic top-level steps
307 public:
313  void reset();
314 
341  Sawyer::CommandLine::ParserResult parseCommandLine(int argc, char *argv[],
342  const std::string &purpose, const std::string &description) /*final*/;
343  virtual Sawyer::CommandLine::ParserResult parseCommandLine(const std::vector<std::string> &args,
344  const std::string &purpose, const std::string &description);
366  virtual SgAsmInterpretation* parseContainers(const std::vector<std::string> &fileNames);
367  SgAsmInterpretation* parseContainers(const std::string &fileName) /*final*/;
390  virtual MemoryMap::Ptr loadSpecimens(const std::vector<std::string> &fileNames = std::vector<std::string>());
391  MemoryMap::Ptr loadSpecimens(const std::string &fileName) /*final*/;
413  virtual Partitioner partition(const std::vector<std::string> &fileNames = std::vector<std::string>());
414  Partitioner partition(const std::string &fileName) /*final*/;
431  SgAsmBlock* buildAst(const std::vector<std::string> &fileNames = std::vector<std::string>()) /*final*/;
432  SgAsmBlock* buildAst(const std::string &fileName) /*final*/;
440  virtual void savePartitioner(const Partitioner&, const boost::filesystem::path&, SerialIo::Format fmt = SerialIo::BINARY);
441 
446  virtual Partitioner loadPartitioner(const boost::filesystem::path&, SerialIo::Format fmt = SerialIo::BINARY);
447 
449  // Command-line parsing
450  //
451  // top-level: parseCommandLine
453 public:
457  virtual Sawyer::CommandLine::SwitchGroup loaderSwitches();
458  static Sawyer::CommandLine::SwitchGroup loaderSwitches(LoaderSettings&);
464  virtual Sawyer::CommandLine::SwitchGroup disassemblerSwitches();
465  static Sawyer::CommandLine::SwitchGroup disassemblerSwitches(DisassemblerSettings&);
471  virtual Sawyer::CommandLine::SwitchGroup partitionerSwitches();
472  static Sawyer::CommandLine::SwitchGroup partitionerSwitches(PartitionerSettings&);
478  virtual Sawyer::CommandLine::SwitchGroup engineSwitches();
479  static Sawyer::CommandLine::SwitchGroup engineSwitches(EngineSettings&);
485  virtual Sawyer::CommandLine::SwitchGroup astConstructionSwitches();
486  static Sawyer::CommandLine::SwitchGroup astConstructionSwitches(AstConstructionSettings&);
490  static std::string specimenNameDocumentation();
491 
503  virtual Sawyer::CommandLine::Parser commandLineParser(const std::string &purpose, const std::string &description);
504 
511  virtual void checkSettings();
512 
514  // Container parsing
515  //
516  // top-level: parseContainers
518 public:
523  virtual bool isRbaFile(const std::string&);
524 
529  virtual bool isNonContainer(const std::string&);
530 
536  virtual bool areContainersParsed() const;
537 
542  virtual void loadVxCore(const std::string &spec);
543 
545  // Load specimens
546  //
547  // top-level: loadSpecimens
549 public:
553  virtual bool areSpecimensLoaded() const;
554 
570  virtual BinaryLoader::Ptr obtainLoader(const BinaryLoader::Ptr &hint = BinaryLoader::Ptr());
571 
577  virtual void loadContainers(const std::vector<std::string> &fileNames);
578 
583  virtual void loadNonContainers(const std::vector<std::string> &names);
584 
588  virtual void adjustMemoryMap();
589 
598  MemoryMap::Ptr memoryMap() const /*final*/ { return map_; }
599  virtual void memoryMap(const MemoryMap::Ptr &m) { map_ = m; }
603  // Disassembler
606 public:
625  virtual Disassembler* obtainDisassembler(Disassembler *hint=NULL);
629  // Partitioner high-level functions
631  //
632  // top-level: partition
634 public:
636  virtual void checkCreatePartitionerPrerequisites() const;
637 
645  virtual Partitioner createBarePartitioner();
646 
652  virtual Partitioner createGenericPartitioner();
653 
659  virtual Partitioner createTunedPartitioner();
660 
665  virtual Partitioner createPartitionerFromAst(SgAsmInterpretation*);
666 
671  virtual Partitioner createPartitioner();
672 
676  virtual void runPartitionerInit(Partitioner&);
677 
681  virtual void runPartitionerRecursive(Partitioner&);
682 
687  virtual void runPartitionerFinal(Partitioner&);
688 
694  virtual void runPartitioner(Partitioner&);
695 
696 
698  // Partitioner mid-level functions
699  //
700  // These are the functions called by the partitioner high-level stuff. These are sometimes overridden in subclasses,
701  // although it is more likely that the high-level stuff is overridden.
703 public:
708  virtual void labelAddresses(Partitioner&, const Configuration&);
709 
713  virtual std::vector<DataBlock::Ptr> makeConfiguredDataBlocks(Partitioner&, const Configuration&);
714 
718  virtual std::vector<Function::Ptr> makeConfiguredFunctions(Partitioner&, const Configuration&);
719 
726  virtual std::vector<Function::Ptr> makeEntryFunctions(Partitioner&, SgAsmInterpretation*);
727 
734  virtual std::vector<Function::Ptr> makeErrorHandlingFunctions(Partitioner&, SgAsmInterpretation*);
735 
745  virtual std::vector<Function::Ptr> makeImportFunctions(Partitioner&, SgAsmInterpretation*);
746 
753  virtual std::vector<Function::Ptr> makeExportFunctions(Partitioner&, SgAsmInterpretation*);
754 
761  virtual std::vector<Function::Ptr> makeSymbolFunctions(Partitioner&, SgAsmInterpretation*);
762 
770  virtual std::vector<Function::Ptr> makeContainerFunctions(Partitioner&, SgAsmInterpretation*);
771 
778  virtual std::vector<Function::Ptr> makeInterruptVectorFunctions(Partitioner&, const AddressInterval &vector);
779 
784  virtual std::vector<Function::Ptr> makeUserFunctions(Partitioner&, const std::vector<rose_addr_t>&);
785 
792  virtual void discoverBasicBlocks(Partitioner&);
793 
805  virtual Function::Ptr makeNextDataReferencedFunction(const Partitioner&, rose_addr_t &startVa /*in,out*/);
806 
820  virtual Function::Ptr makeNextCodeReferencedFunction(const Partitioner&);
821 
828  virtual std::vector<Function::Ptr> makeCalledFunctions(Partitioner&);
829 
845  virtual std::vector<Function::Ptr> makeNextPrologueFunction(Partitioner&, rose_addr_t startVa);
846  virtual std::vector<Function::Ptr> makeNextPrologueFunction(Partitioner&, rose_addr_t startVa, rose_addr_t &lastSearchedVa);
867  virtual std::vector<Function::Ptr>
868  makeFunctionFromInterFunctionCalls(Partitioner &partitioner, rose_addr_t &startVa /*in,out*/);
869 
876  virtual void discoverFunctions(Partitioner&);
877 
892  virtual std::set<rose_addr_t> attachDeadCodeToFunction(Partitioner&, const Function::Ptr&, size_t maxIterations=size_t(-1));
893 
901  virtual DataBlock::Ptr attachPaddingToFunction(Partitioner&, const Function::Ptr&);
902 
907  virtual std::vector<DataBlock::Ptr> attachPaddingToFunctions(Partitioner&);
908 
919  virtual size_t attachAllSurroundedCodeToFunctions(Partitioner&);
920 
928  virtual size_t attachSurroundedCodeToFunctions(Partitioner&);
929 
934  virtual void attachBlocksToFunctions(Partitioner&);
935 
942  virtual std::set<rose_addr_t> attachDeadCodeToFunctions(Partitioner&, size_t maxIterations=size_t(-1));
943 
953  virtual std::vector<DataBlock::Ptr> attachSurroundedDataToFunctions(Partitioner&);
954 
960  virtual void updateAnalysisResults(Partitioner&);
961 
962 
964  // Partitioner low-level functions
965  //
966  // These are functions that a subclass seldom overrides, and maybe even shouldn't override because of their complexity or
967  // the way the interact with one another.
969 public:
980  virtual bool makeNextCallReturnEdge(Partitioner&, boost::logic::tribool assumeCallReturns);
981 
987  virtual BasicBlock::Ptr makeNextBasicBlockFromPlaceholder(Partitioner&);
988 
1003  virtual BasicBlock::Ptr makeNextBasicBlock(Partitioner&);
1004 
1005 
1007  // Build AST
1009 public:
1010  // Used internally by ROSE's ::frontend disassemble instructions to build the AST that goes under each SgAsmInterpretation.
1011  static void disassembleForRoseFrontend(SgAsmInterpretation*);
1012 
1013 
1015  // Settings and properties
1017 public:
1024  const Settings& settings() const /*final*/ { return settings_; }
1025  Settings& settings() /*final*/ { return settings_; }
1036  bool exitOnError() const /*final*/ { return settings_.engine.exitOnError; }
1037  virtual void exitOnError(bool b) { settings_.engine.exitOnError = b; }
1045  Progress::Ptr progress() const /*final*/ { return progress_; }
1046  virtual void progress(const Progress::Ptr &progress) { progress_ = progress; }
1056  SgAsmInterpretation* interpretation() const /*final*/ { return interp_; }
1057  virtual void interpretation(SgAsmInterpretation *interp) { interp_ = interp; }
1066  BinaryLoader::Ptr binaryLoader() const /*final*/ { return binaryLoader_; }
1067  virtual void binaryLoader(const BinaryLoader::Ptr &loader) { binaryLoader_ = loader; }
1080  size_t deExecuteZerosThreshold() const /*final*/ { return settings_.loader.deExecuteZerosThreshold; }
1081  virtual void deExecuteZerosThreshold(size_t n) { settings_.loader.deExecuteZerosThreshold = n; }
1082  size_t deExecuteZerosLeaveAtFront() const /*final*/ { return settings_.loader.deExecuteZerosLeaveAtFront; }
1083  virtual void deExecuteZerosLeaveAtFront(size_t n) { settings_.loader.deExecuteZerosLeaveAtFront = n; }
1084  size_t deExecuteZerosLeaveAtBack() const /*final*/ { return settings_.loader.deExecuteZerosLeaveAtBack; }
1085  virtual void deExecuteZerosLeaveAtBack(size_t n) { settings_.loader.deExecuteZerosLeaveAtBack = n; }
1100  MemoryDataAdjustment memoryDataAdjustment() const /*final*/ { return settings_.loader.memoryDataAdjustment; }
1101  virtual void memoryDataAdjustment(MemoryDataAdjustment x) { settings_.loader.memoryDataAdjustment = x; }
1111  bool memoryIsExecutable() const /*final*/ { return settings_.loader.memoryIsExecutable; }
1112  virtual void memoryIsExecutable(bool b) { settings_.loader.memoryIsExecutable = b; }
1124  bool linkObjectFiles() const /*final*/ { return settings_.loader.linkObjectFiles; }
1125  virtual void linkObjectFiles(bool b) { settings_.loader.linkObjectFiles = b; }
1137  bool linkStaticArchives() const /*final*/ { return settings_.loader.linkStaticArchives; }
1138  virtual void linkStaticArchives(bool b) { settings_.loader.linkStaticArchives = b; }
1149  const std::string& linkerCommand() const /*final*/ { return settings_.loader.linker; }
1150  virtual void linkerCommand(const std::string &cmd) { settings_.loader.linker = cmd; }
1158  const std::vector<std::string> environmentEraseNames() const /*final*/ { return settings_.loader.envEraseNames; }
1159  virtual void environmentEraseNames(const std::vector<std::string> &names) { settings_.loader.envEraseNames = names; }
1168  const std::vector<boost::regex> environmentErasePatterns() const /*final*/ { return settings_.loader.envErasePatterns; }
1169  virtual void environmentErasePatterns(const std::vector<boost::regex> &res) { settings_.loader.envErasePatterns = res; }
1179  const std::vector<std::string> environmentInsertions() const /*final*/ { return settings_.loader.envInsert; }
1180  virtual void environmentInsertions(const std::vector<std::string> &vars) { settings_.loader.envInsert = vars; }
1188  bool doDisassemble() const /*final*/ { return settings_.disassembler.doDisassemble; }
1189  virtual void doDisassemble(bool b) { settings_.disassembler.doDisassemble = b; }
1198  Disassembler *disassembler() const /*final*/ { return disassembler_; }
1199  virtual void disassembler(Disassembler *d) { disassembler_ = d; }
1208  const std::string& isaName() const /*final*/ { return settings_.disassembler.isaName; }
1209  virtual void isaName(const std::string &s) { settings_.disassembler.isaName = s; }
1218  const std::vector<rose_addr_t>& functionStartingVas() const /*final*/ { return settings_.partitioner.functionStartingVas; }
1219  std::vector<rose_addr_t>& functionStartingVas() /*final*/ { return settings_.partitioner.functionStartingVas; }
1228  bool usingSemantics() const /*final*/ { return settings_.partitioner.base.usingSemantics; }
1229  virtual void usingSemantics(bool b) { settings_.partitioner.base.usingSemantics = b; }
1240  bool ignoringUnknownInsns() const /*final*/ { return settings_.partitioner.base.ignoringUnknownInsns; }
1241  virtual void ignoringUnknownInsns(bool b) { settings_.partitioner.base.ignoringUnknownInsns = b; }
1250  SemanticMemoryParadigm semanticMemoryParadigm() const /*final*/ { return settings_.partitioner.semanticMemoryParadigm; }
1251  virtual void semanticMemoryParadigm(SemanticMemoryParadigm p) { settings_.partitioner.semanticMemoryParadigm = p; }
1280  bool followingGhostEdges() const /*final*/ { return settings_.partitioner.followingGhostEdges; }
1281  virtual void followingGhostEdges(bool b) { settings_.partitioner.followingGhostEdges = b; }
1291  bool discontiguousBlocks() const /*final*/ { return settings_.partitioner.discontiguousBlocks; }
1292  virtual void discontiguousBlocks(bool b) { settings_.partitioner.discontiguousBlocks = b; }
1302  size_t maxBasicBlockSize() const /*final*/ { return settings_.partitioner.maxBasicBlockSize; }
1303  virtual void maxBasicBlockSize(size_t n) { settings_.partitioner.maxBasicBlockSize = n; }
1314  const std::vector<rose_addr_t>& ipRewrites() const /*final*/ { return settings_.partitioner.ipRewrites; }
1315  virtual void ipRewrites(const std::vector<rose_addr_t> &v) { settings_.partitioner.ipRewrites = v; }
1324  bool findingFunctionPadding() const /*final*/ { return settings_.partitioner.findingFunctionPadding; }
1325  virtual void findingFunctionPadding(bool b) { settings_.partitioner.findingFunctionPadding = b; }
1334  bool findingThunks() const /*final*/ { return settings_.partitioner.findingThunks; }
1335  virtual void findingThunks(bool b) { settings_.partitioner.findingThunks = b; }
1346  ThunkPredicates::Ptr functionMatcherThunks() const /*final*/ { return functionMatcherThunks_; }
1347  virtual void functionMatcherThunks(const ThunkPredicates::Ptr &p) { functionMatcherThunks_ = p; }
1356  bool splittingThunks() const /*final*/ { return settings_.partitioner.splittingThunks; }
1357  virtual void splittingThunks(bool b) { settings_.partitioner.splittingThunks = b; }
1368  ThunkPredicates::Ptr functionSplittingThunks() const /*final*/ { return functionSplittingThunks_; }
1369  virtual void functionSplittingThunks(const ThunkPredicates::Ptr &p) { functionSplittingThunks_ = p; }
1380  bool findingDeadCode() const /*final*/ { return settings_.partitioner.findingDeadCode; }
1381  virtual void findingDeadCode(bool b) { settings_.partitioner.findingDeadCode = b; }
1390  rose_addr_t peScramblerDispatcherVa() const /*final*/ { return settings_.partitioner.peScramblerDispatcherVa; }
1391  virtual void peScramblerDispatcherVa(rose_addr_t va) { settings_.partitioner.peScramblerDispatcherVa = va; }
1401  size_t findingIntraFunctionCode() const /*final*/ { return settings_.partitioner.findingIntraFunctionCode; }
1402  virtual void findingIntraFunctionCode(size_t n) { settings_.partitioner.findingIntraFunctionCode = n; }
1411  bool findingIntraFunctionData() const /*final*/ { return settings_.partitioner.findingIntraFunctionData; }
1412  virtual void findingIntraFunctionData(bool b) { settings_.partitioner.findingIntraFunctionData = b; }
1421  const AddressInterval& interruptVector() const /*final*/ { return settings_.partitioner.interruptVector; }
1422  virtual void interruptVector(const AddressInterval &i) { settings_.partitioner.interruptVector = i; }
1431  bool doingPostAnalysis() const /*final*/ { return settings_.partitioner.doingPostAnalysis; }
1432  virtual void doingPostAnalysis(bool b) { settings_.partitioner.doingPostAnalysis = b; }
1440  bool doingPostFunctionMayReturn() const /*final*/ { return settings_.partitioner.doingPostFunctionMayReturn; }
1441  virtual void doingPostFunctionMayReturn(bool b) { settings_.partitioner.doingPostFunctionMayReturn = b; }
1449  bool doingPostFunctionStackDelta() const /*final*/ { return settings_.partitioner.doingPostFunctionStackDelta; }
1450  virtual void doingPostFunctionStackDelta(bool b) { settings_.partitioner.doingPostFunctionStackDelta = b; }
1458  bool doingPostCallingConvention() const /*final*/ { return settings_.partitioner.doingPostCallingConvention; }
1459  virtual void doingPostCallingConvention(bool b) { settings_.partitioner.doingPostCallingConvention = b; }
1468  bool doingPostFunctionNoop() const /*final*/ { return settings_.partitioner.doingPostFunctionNoop; }
1469  virtual void doingPostFunctionNoop(bool b) { settings_.partitioner.doingPostFunctionNoop = b; }
1478  FunctionReturnAnalysis functionReturnAnalysis() const /*final*/ { return settings_.partitioner.functionReturnAnalysis; }
1479  virtual void functionReturnAnalysis(FunctionReturnAnalysis x) { settings_.partitioner.functionReturnAnalysis = x; }
1494  size_t functionReturnAnalysisMaxSorts() const /*final*/ { return settings_.partitioner.functionReturnAnalysisMaxSorts; }
1495  virtual void functionReturnAnalysisMaxSorts(size_t n) { settings_.partitioner.functionReturnAnalysisMaxSorts = n; }
1504  bool findingInterFunctionCalls() const /*final*/ { return settings_.partitioner.findingInterFunctionCalls; }
1505  virtual void findingInterFunctionCalls(bool b) { settings_.partitioner.findingInterFunctionCalls = b; }
1514  bool findingFunctionCallFunctions() const /*final*/ { return settings_.partitioner.findingFunctionCallFunctions; }
1515  virtual void findingFunctionCallFunctions(bool b) { settings_.partitioner.findingFunctionCallFunctions = b; }
1523  bool findingEntryFunctions() const /*final*/ { return settings_.partitioner.findingEntryFunctions; }
1524  virtual void findingEntryFunctions(bool b) { settings_.partitioner.findingEntryFunctions = b; }
1533  bool findingErrorFunctions() const /*final*/ { return settings_.partitioner.findingErrorFunctions; }
1534  virtual void findingErrorFunctions(bool b) { settings_.partitioner.findingErrorFunctions = b; }
1543  bool findingImportFunctions() const /*final*/ { return settings_.partitioner.findingImportFunctions; }
1544  virtual void findingImportFunctions(bool b) { settings_.partitioner.findingImportFunctions = b; }
1553  bool findingExportFunctions() const /*final*/ { return settings_.partitioner.findingExportFunctions; }
1554  virtual void findingExportFunctions(bool b) { settings_.partitioner.findingExportFunctions = b; }
1563  bool findingSymbolFunctions() const /*final*/ { return settings_.partitioner.findingSymbolFunctions; }
1564  virtual void findingSymbolFunctions(bool b) { settings_.partitioner.findingSymbolFunctions = b; }
1573  bool findingDataFunctionPointers() const /*final*/ { return settings_.partitioner.findingDataFunctionPointers; }
1574  virtual void findingDataFunctionPointers(bool b) { settings_.partitioner.findingDataFunctionPointers = b; }
1583  bool findingCodeFunctionPointers() const /*final*/ { return settings_.partitioner.findingCodeFunctionPointers; }
1584  virtual void findingCodeFunctionPointers(bool b) { settings_.partitioner.findingCodeFunctionPointers = b; }
1592  bool checkingCallBranch() const /*final*/ { return settings_.partitioner.base.checkingCallBranch; }
1593  virtual void checkingCallBranch(bool b) { settings_.partitioner.base.checkingCallBranch = b; }
1607  bool basicBlockSemanticsAutoDrop() const /*final*/ { return settings_.partitioner.base.basicBlockSemanticsAutoDrop; }
1608  void basicBlockSemanticsAutoDrop(bool b) { settings_.partitioner.base.basicBlockSemanticsAutoDrop = b; }
1616  const std::vector<std::string>& configurationNames() /*final*/ const { return settings_.engine.configurationNames; }
1617  std::vector<std::string>& configurationNames() /*final*/ { return settings_.engine.configurationNames; }
1625  bool namingConstants() const /*final*/ { return settings_.partitioner.namingConstants; }
1626  virtual void namingConstants(bool b) { settings_.partitioner.namingConstants = b; }
1636  const AddressInterval& namingStrings() const /*final*/ { return settings_.partitioner.namingStrings; }
1637  void namingStrings(const AddressInterval &where) { settings_.partitioner.namingStrings = where; }
1646  bool namingSystemCalls() const /*final*/ { return settings_.partitioner.namingSyscalls; }
1647  virtual void namingSystemCalls(bool b) { settings_.partitioner.namingSyscalls = b; }
1657  const boost::filesystem::path& systemCallHeader() const /*final*/ { return settings_.partitioner.syscallHeader; }
1658  virtual void systemCallHeader(const boost::filesystem::path &filename) { settings_.partitioner.syscallHeader = filename; }
1667  bool demangleNames() const /*final*/ { return settings_.partitioner.demangleNames; }
1668  virtual void demangleNames(bool b) { settings_.partitioner.demangleNames = b; }
1677  bool astAllowEmptyGlobalBlock() const /*final*/ { return settings_.astConstruction.allowEmptyGlobalBlock; }
1678  virtual void astAllowEmptyGlobalBlock(bool b) { settings_.astConstruction.allowEmptyGlobalBlock = b; }
1687  bool astAllowFunctionWithNoBasicBlocks() const /*final*/ {
1688  return settings_.astConstruction.allowFunctionWithNoBasicBlocks;
1689  }
1690  virtual void astAllowFunctionWithNoBasicBlocks(bool b) {
1691  settings_.astConstruction.allowFunctionWithNoBasicBlocks = b;
1692  }
1701  bool astAllowEmptyBasicBlock() const /*final*/ { return settings_.astConstruction.allowEmptyBasicBlocks; }
1702  virtual void astAllowEmptyBasicBlock(bool b) { settings_.astConstruction.allowEmptyBasicBlocks = b; }
1714  bool astCopyAllInstructions() const /*final*/ { return settings_.astConstruction.copyAllInstructions; }
1715  virtual void astCopyAllInstructions(bool b) { settings_.astConstruction.copyAllInstructions = b; }
1718  // Python API support functions
1721 #ifdef ROSE_ENABLE_PYTHON_API
1722 
1723  // Similar to frontend, but returns a partitioner rather than an AST since the Python API doesn't yet support ASTs.
1724  Partitioner pythonParseVector(boost::python::list &pyArgs, const std::string &purpose, const std::string &description);
1725  Partitioner pythonParseSingle(const std::string &specimen, const std::string &purpose, const std::string &description);
1726 
1727 #endif
1728 
1730  // Internal stuff
1732 private:
1733  void init();
1734 
1735  // Similar to ::frontend but a lot less complicated.
1736  SgProject* roseFrontendReplacement(const std::vector<boost::filesystem::path> &fileNames);
1737 };
1738 
1739 } // namespace
1740 } // namespace
1741 } // namespace
1742 
1743 #endif
1744 #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.
virtual void ignoringUnknownInsns(bool b)
Property: Whether unknown instructions are ignored.
MemoryDataAdjustment
How the partitioner should globally treat memory.
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:42
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:62
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.
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.
Settings & settings()
Property: All settings.
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:45
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.
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.
void namingStrings(const AddressInterval &where)
Property: Addresses where strings might start.
Settings that control the engine partitioning.
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.
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.
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.
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.
const AddressInterval & namingStrings() const
Property: Addresses where strings might start.
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.
Definition: SerialIo.h:122
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:289
Base class for all ROSE exceptions.
Definition: Rose/Exception.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...
Definition: SerialIo.h:123
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.
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:281
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.