ROSE  0.11.98.0
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/BasicTypes.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::BasePtr 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:
253  Engine();
254 
256  explicit Engine(const Settings &settings);
257 
258  virtual ~Engine();
259 
261  // The very top-level use case
263 public:
288  SgAsmBlock* frontend(int argc, char *argv[],
289  const std::string &purpose, const std::string &description);
290  virtual SgAsmBlock* frontend(const std::vector<std::string> &args,
291  const std::string &purpose, const std::string &description);
294  // Basic top-level steps
297 public:
303  void reset();
304 
331  Sawyer::CommandLine::ParserResult parseCommandLine(int argc, char *argv[],
332  const std::string &purpose, const std::string &description) /*final*/;
333  virtual Sawyer::CommandLine::ParserResult parseCommandLine(const std::vector<std::string> &args,
334  const std::string &purpose, const std::string &description);
356  virtual SgAsmInterpretation* parseContainers(const std::vector<std::string> &fileNames);
357  SgAsmInterpretation* parseContainers(const std::string &fileName) /*final*/;
380  virtual MemoryMap::Ptr loadSpecimens(const std::vector<std::string> &fileNames = std::vector<std::string>());
381  MemoryMap::Ptr loadSpecimens(const std::string &fileName) /*final*/;
403  virtual Partitioner partition(const std::vector<std::string> &fileNames = std::vector<std::string>());
404  Partitioner partition(const std::string &fileName) /*final*/;
421  SgAsmBlock* buildAst(const std::vector<std::string> &fileNames = std::vector<std::string>()) /*final*/;
422  SgAsmBlock* buildAst(const std::string &fileName) /*final*/;
430  virtual void savePartitioner(const Partitioner&, const boost::filesystem::path&, SerialIo::Format fmt = SerialIo::BINARY);
431 
436  virtual Partitioner loadPartitioner(const boost::filesystem::path&, SerialIo::Format fmt = SerialIo::BINARY);
437 
439  // Command-line parsing
440  //
441  // top-level: parseCommandLine
443 public:
447  virtual Sawyer::CommandLine::SwitchGroup loaderSwitches();
448  static Sawyer::CommandLine::SwitchGroup loaderSwitches(LoaderSettings&);
454  virtual Sawyer::CommandLine::SwitchGroup disassemblerSwitches();
455  static Sawyer::CommandLine::SwitchGroup disassemblerSwitches(DisassemblerSettings&);
461  virtual Sawyer::CommandLine::SwitchGroup partitionerSwitches();
462  static Sawyer::CommandLine::SwitchGroup partitionerSwitches(PartitionerSettings&);
468  virtual Sawyer::CommandLine::SwitchGroup engineSwitches();
469  static Sawyer::CommandLine::SwitchGroup engineSwitches(EngineSettings&);
475  virtual Sawyer::CommandLine::SwitchGroup astConstructionSwitches();
476  static Sawyer::CommandLine::SwitchGroup astConstructionSwitches(AstConstructionSettings&);
480  static std::string specimenNameDocumentation();
481 
493  virtual Sawyer::CommandLine::Parser commandLineParser(const std::string &purpose, const std::string &description);
494 
501  virtual void checkSettings();
502 
504  // Container parsing
505  //
506  // top-level: parseContainers
508 public:
513  virtual bool isRbaFile(const std::string&);
514 
519  virtual bool isNonContainer(const std::string&);
520 
526  virtual bool areContainersParsed() const;
527 
532  virtual void loadVxCore(const std::string &spec);
533 
535  // Load specimens
536  //
537  // top-level: loadSpecimens
539 public:
543  virtual bool areSpecimensLoaded() const;
544 
560  virtual BinaryLoader::Ptr obtainLoader(const BinaryLoader::Ptr &hint = BinaryLoader::Ptr());
561 
567  virtual void loadContainers(const std::vector<std::string> &fileNames);
568 
573  virtual void loadNonContainers(const std::vector<std::string> &names);
574 
578  virtual void adjustMemoryMap();
579 
588  MemoryMap::Ptr memoryMap() const /*final*/ { return map_; }
589  virtual void memoryMap(const MemoryMap::Ptr &m) { map_ = m; }
593  // Disassembler
596 public:
615  virtual Disassembler::BasePtr obtainDisassembler();
616  virtual Disassembler::BasePtr obtainDisassembler(const Disassembler::BasePtr &hint);
620  // Partitioner high-level functions
622  //
623  // top-level: partition
625 public:
627  virtual void checkCreatePartitionerPrerequisites() const;
628 
636  virtual Partitioner createBarePartitioner();
637 
643  virtual Partitioner createGenericPartitioner();
644 
650  virtual Partitioner createTunedPartitioner();
651 
656  virtual Partitioner createPartitionerFromAst(SgAsmInterpretation*);
657 
662  virtual Partitioner createPartitioner();
663 
667  virtual void runPartitionerInit(Partitioner&);
668 
672  virtual void runPartitionerRecursive(Partitioner&);
673 
678  virtual void runPartitionerFinal(Partitioner&);
679 
685  virtual void runPartitioner(Partitioner&);
686 
687 
689  // Partitioner mid-level functions
690  //
691  // These are the functions called by the partitioner high-level stuff. These are sometimes overridden in subclasses,
692  // although it is more likely that the high-level stuff is overridden.
694 public:
699  virtual void labelAddresses(Partitioner&, const Configuration&);
700 
704  virtual std::vector<DataBlock::Ptr> makeConfiguredDataBlocks(Partitioner&, const Configuration&);
705 
709  virtual std::vector<Function::Ptr> makeConfiguredFunctions(Partitioner&, const Configuration&);
710 
717  virtual std::vector<Function::Ptr> makeEntryFunctions(Partitioner&, SgAsmInterpretation*);
718 
725  virtual std::vector<Function::Ptr> makeErrorHandlingFunctions(Partitioner&, SgAsmInterpretation*);
726 
736  virtual std::vector<Function::Ptr> makeImportFunctions(Partitioner&, SgAsmInterpretation*);
737 
744  virtual std::vector<Function::Ptr> makeExportFunctions(Partitioner&, SgAsmInterpretation*);
745 
752  virtual std::vector<Function::Ptr> makeSymbolFunctions(Partitioner&, SgAsmInterpretation*);
753 
761  virtual std::vector<Function::Ptr> makeContainerFunctions(Partitioner&, SgAsmInterpretation*);
762 
769  virtual std::vector<Function::Ptr> makeInterruptVectorFunctions(Partitioner&, const AddressInterval &vector);
770 
775  virtual std::vector<Function::Ptr> makeUserFunctions(Partitioner&, const std::vector<rose_addr_t>&);
776 
783  virtual void discoverBasicBlocks(Partitioner&);
784 
796  virtual Function::Ptr makeNextDataReferencedFunction(const Partitioner&, rose_addr_t &startVa /*in,out*/);
797 
811  virtual Function::Ptr makeNextCodeReferencedFunction(const Partitioner&);
812 
819  virtual std::vector<Function::Ptr> makeCalledFunctions(Partitioner&);
820 
836  virtual std::vector<Function::Ptr> makeNextPrologueFunction(Partitioner&, rose_addr_t startVa);
837  virtual std::vector<Function::Ptr> makeNextPrologueFunction(Partitioner&, rose_addr_t startVa, rose_addr_t &lastSearchedVa);
858  virtual std::vector<Function::Ptr>
859  makeFunctionFromInterFunctionCalls(Partitioner &partitioner, rose_addr_t &startVa /*in,out*/);
860 
867  virtual void discoverFunctions(Partitioner&);
868 
883  virtual std::set<rose_addr_t> attachDeadCodeToFunction(Partitioner&, const Function::Ptr&, size_t maxIterations=size_t(-1));
884 
892  virtual DataBlock::Ptr attachPaddingToFunction(Partitioner&, const Function::Ptr&);
893 
898  virtual std::vector<DataBlock::Ptr> attachPaddingToFunctions(Partitioner&);
899 
910  virtual size_t attachAllSurroundedCodeToFunctions(Partitioner&);
911 
919  virtual size_t attachSurroundedCodeToFunctions(Partitioner&);
920 
925  virtual void attachBlocksToFunctions(Partitioner&);
926 
933  virtual std::set<rose_addr_t> attachDeadCodeToFunctions(Partitioner&, size_t maxIterations=size_t(-1));
934 
944  virtual std::vector<DataBlock::Ptr> attachSurroundedDataToFunctions(Partitioner&);
945 
951  virtual void updateAnalysisResults(Partitioner&);
952 
953 
955  // Partitioner low-level functions
956  //
957  // These are functions that a subclass seldom overrides, and maybe even shouldn't override because of their complexity or
958  // the way the interact with one another.
960 public:
971  virtual bool makeNextCallReturnEdge(Partitioner&, boost::logic::tribool assumeCallReturns);
972 
978  virtual BasicBlock::Ptr makeNextBasicBlockFromPlaceholder(Partitioner&);
979 
994  virtual BasicBlock::Ptr makeNextBasicBlock(Partitioner&);
995 
996 
998  // Build AST
1000 public:
1001  // Used internally by ROSE's ::frontend disassemble instructions to build the AST that goes under each SgAsmInterpretation.
1002  static void disassembleForRoseFrontend(SgAsmInterpretation*);
1003 
1004 
1006  // Settings and properties
1008 public:
1015  const Settings& settings() const /*final*/ { return settings_; }
1016  Settings& settings() /*final*/ { return settings_; }
1027  bool exitOnError() const /*final*/ { return settings_.engine.exitOnError; }
1028  virtual void exitOnError(bool b) { settings_.engine.exitOnError = b; }
1036  Progress::Ptr progress() const /*final*/ { return progress_; }
1037  virtual void progress(const Progress::Ptr &progress) { progress_ = progress; }
1047  SgAsmInterpretation* interpretation() const /*final*/ { return interp_; }
1048  virtual void interpretation(SgAsmInterpretation *interp) { interp_ = interp; }
1057  BinaryLoader::Ptr binaryLoader() const /*final*/ { return binaryLoader_; }
1058  virtual void binaryLoader(const BinaryLoader::Ptr &loader) { binaryLoader_ = loader; }
1071  size_t deExecuteZerosThreshold() const /*final*/ { return settings_.loader.deExecuteZerosThreshold; }
1072  virtual void deExecuteZerosThreshold(size_t n) { settings_.loader.deExecuteZerosThreshold = n; }
1073  size_t deExecuteZerosLeaveAtFront() const /*final*/ { return settings_.loader.deExecuteZerosLeaveAtFront; }
1074  virtual void deExecuteZerosLeaveAtFront(size_t n) { settings_.loader.deExecuteZerosLeaveAtFront = n; }
1075  size_t deExecuteZerosLeaveAtBack() const /*final*/ { return settings_.loader.deExecuteZerosLeaveAtBack; }
1076  virtual void deExecuteZerosLeaveAtBack(size_t n) { settings_.loader.deExecuteZerosLeaveAtBack = n; }
1091  MemoryDataAdjustment memoryDataAdjustment() const /*final*/ { return settings_.loader.memoryDataAdjustment; }
1092  virtual void memoryDataAdjustment(MemoryDataAdjustment x) { settings_.loader.memoryDataAdjustment = x; }
1102  bool memoryIsExecutable() const /*final*/ { return settings_.loader.memoryIsExecutable; }
1103  virtual void memoryIsExecutable(bool b) { settings_.loader.memoryIsExecutable = b; }
1115  bool linkObjectFiles() const /*final*/ { return settings_.loader.linkObjectFiles; }
1116  virtual void linkObjectFiles(bool b) { settings_.loader.linkObjectFiles = b; }
1128  bool linkStaticArchives() const /*final*/ { return settings_.loader.linkStaticArchives; }
1129  virtual void linkStaticArchives(bool b) { settings_.loader.linkStaticArchives = b; }
1140  const std::string& linkerCommand() const /*final*/ { return settings_.loader.linker; }
1141  virtual void linkerCommand(const std::string &cmd) { settings_.loader.linker = cmd; }
1149  const std::vector<std::string> environmentEraseNames() const /*final*/ { return settings_.loader.envEraseNames; }
1150  virtual void environmentEraseNames(const std::vector<std::string> &names) { settings_.loader.envEraseNames = names; }
1159  const std::vector<boost::regex> environmentErasePatterns() const /*final*/ { return settings_.loader.envErasePatterns; }
1160  virtual void environmentErasePatterns(const std::vector<boost::regex> &res) { settings_.loader.envErasePatterns = res; }
1170  const std::vector<std::string> environmentInsertions() const /*final*/ { return settings_.loader.envInsert; }
1171  virtual void environmentInsertions(const std::vector<std::string> &vars) { settings_.loader.envInsert = vars; }
1179  bool doDisassemble() const /*final*/ { return settings_.disassembler.doDisassemble; }
1180  virtual void doDisassemble(bool b) { settings_.disassembler.doDisassemble = b; }
1189  Disassembler::BasePtr disassembler() const;
1190  virtual void disassembler(const Disassembler::BasePtr&);
1199  const std::string& isaName() const /*final*/ { return settings_.disassembler.isaName; }
1200  virtual void isaName(const std::string &s) { settings_.disassembler.isaName = s; }
1209  const std::vector<rose_addr_t>& functionStartingVas() const /*final*/ { return settings_.partitioner.functionStartingVas; }
1210  std::vector<rose_addr_t>& functionStartingVas() /*final*/ { return settings_.partitioner.functionStartingVas; }
1219  bool usingSemantics() const /*final*/ { return settings_.partitioner.base.usingSemantics; }
1220  virtual void usingSemantics(bool b) { settings_.partitioner.base.usingSemantics = b; }
1231  bool ignoringUnknownInsns() const /*final*/ { return settings_.partitioner.base.ignoringUnknownInsns; }
1232  virtual void ignoringUnknownInsns(bool b) { settings_.partitioner.base.ignoringUnknownInsns = b; }
1241  SemanticMemoryParadigm semanticMemoryParadigm() const /*final*/ { return settings_.partitioner.semanticMemoryParadigm; }
1242  virtual void semanticMemoryParadigm(SemanticMemoryParadigm p) { settings_.partitioner.semanticMemoryParadigm = p; }
1271  bool followingGhostEdges() const /*final*/ { return settings_.partitioner.followingGhostEdges; }
1272  virtual void followingGhostEdges(bool b) { settings_.partitioner.followingGhostEdges = b; }
1282  bool discontiguousBlocks() const /*final*/ { return settings_.partitioner.discontiguousBlocks; }
1283  virtual void discontiguousBlocks(bool b) { settings_.partitioner.discontiguousBlocks = b; }
1293  size_t maxBasicBlockSize() const /*final*/ { return settings_.partitioner.maxBasicBlockSize; }
1294  virtual void maxBasicBlockSize(size_t n) { settings_.partitioner.maxBasicBlockSize = n; }
1305  const std::vector<rose_addr_t>& ipRewrites() const /*final*/ { return settings_.partitioner.ipRewrites; }
1306  virtual void ipRewrites(const std::vector<rose_addr_t> &v) { settings_.partitioner.ipRewrites = v; }
1315  bool findingFunctionPadding() const /*final*/ { return settings_.partitioner.findingFunctionPadding; }
1316  virtual void findingFunctionPadding(bool b) { settings_.partitioner.findingFunctionPadding = b; }
1325  bool findingThunks() const /*final*/ { return settings_.partitioner.findingThunks; }
1326  virtual void findingThunks(bool b) { settings_.partitioner.findingThunks = b; }
1337  ThunkPredicates::Ptr functionMatcherThunks() const /*final*/ { return functionMatcherThunks_; }
1338  virtual void functionMatcherThunks(const ThunkPredicates::Ptr &p) { functionMatcherThunks_ = p; }
1347  bool splittingThunks() const /*final*/ { return settings_.partitioner.splittingThunks; }
1348  virtual void splittingThunks(bool b) { settings_.partitioner.splittingThunks = b; }
1359  ThunkPredicates::Ptr functionSplittingThunks() const /*final*/ { return functionSplittingThunks_; }
1360  virtual void functionSplittingThunks(const ThunkPredicates::Ptr &p) { functionSplittingThunks_ = p; }
1371  bool findingDeadCode() const /*final*/ { return settings_.partitioner.findingDeadCode; }
1372  virtual void findingDeadCode(bool b) { settings_.partitioner.findingDeadCode = b; }
1381  rose_addr_t peScramblerDispatcherVa() const /*final*/ { return settings_.partitioner.peScramblerDispatcherVa; }
1382  virtual void peScramblerDispatcherVa(rose_addr_t va) { settings_.partitioner.peScramblerDispatcherVa = va; }
1392  size_t findingIntraFunctionCode() const /*final*/ { return settings_.partitioner.findingIntraFunctionCode; }
1393  virtual void findingIntraFunctionCode(size_t n) { settings_.partitioner.findingIntraFunctionCode = n; }
1402  bool findingIntraFunctionData() const /*final*/ { return settings_.partitioner.findingIntraFunctionData; }
1403  virtual void findingIntraFunctionData(bool b) { settings_.partitioner.findingIntraFunctionData = b; }
1412  const AddressInterval& interruptVector() const /*final*/ { return settings_.partitioner.interruptVector; }
1413  virtual void interruptVector(const AddressInterval &i) { settings_.partitioner.interruptVector = i; }
1422  bool doingPostAnalysis() const /*final*/ { return settings_.partitioner.doingPostAnalysis; }
1423  virtual void doingPostAnalysis(bool b) { settings_.partitioner.doingPostAnalysis = b; }
1431  bool doingPostFunctionMayReturn() const /*final*/ { return settings_.partitioner.doingPostFunctionMayReturn; }
1432  virtual void doingPostFunctionMayReturn(bool b) { settings_.partitioner.doingPostFunctionMayReturn = b; }
1440  bool doingPostFunctionStackDelta() const /*final*/ { return settings_.partitioner.doingPostFunctionStackDelta; }
1441  virtual void doingPostFunctionStackDelta(bool b) { settings_.partitioner.doingPostFunctionStackDelta = b; }
1449  bool doingPostCallingConvention() const /*final*/ { return settings_.partitioner.doingPostCallingConvention; }
1450  virtual void doingPostCallingConvention(bool b) { settings_.partitioner.doingPostCallingConvention = b; }
1459  bool doingPostFunctionNoop() const /*final*/ { return settings_.partitioner.doingPostFunctionNoop; }
1460  virtual void doingPostFunctionNoop(bool b) { settings_.partitioner.doingPostFunctionNoop = b; }
1469  FunctionReturnAnalysis functionReturnAnalysis() const /*final*/ { return settings_.partitioner.functionReturnAnalysis; }
1470  virtual void functionReturnAnalysis(FunctionReturnAnalysis x) { settings_.partitioner.functionReturnAnalysis = x; }
1485  size_t functionReturnAnalysisMaxSorts() const /*final*/ { return settings_.partitioner.functionReturnAnalysisMaxSorts; }
1486  virtual void functionReturnAnalysisMaxSorts(size_t n) { settings_.partitioner.functionReturnAnalysisMaxSorts = n; }
1495  bool findingInterFunctionCalls() const /*final*/ { return settings_.partitioner.findingInterFunctionCalls; }
1496  virtual void findingInterFunctionCalls(bool b) { settings_.partitioner.findingInterFunctionCalls = b; }
1505  bool findingFunctionCallFunctions() const /*final*/ { return settings_.partitioner.findingFunctionCallFunctions; }
1506  virtual void findingFunctionCallFunctions(bool b) { settings_.partitioner.findingFunctionCallFunctions = b; }
1514  bool findingEntryFunctions() const /*final*/ { return settings_.partitioner.findingEntryFunctions; }
1515  virtual void findingEntryFunctions(bool b) { settings_.partitioner.findingEntryFunctions = b; }
1524  bool findingErrorFunctions() const /*final*/ { return settings_.partitioner.findingErrorFunctions; }
1525  virtual void findingErrorFunctions(bool b) { settings_.partitioner.findingErrorFunctions = b; }
1534  bool findingImportFunctions() const /*final*/ { return settings_.partitioner.findingImportFunctions; }
1535  virtual void findingImportFunctions(bool b) { settings_.partitioner.findingImportFunctions = b; }
1544  bool findingExportFunctions() const /*final*/ { return settings_.partitioner.findingExportFunctions; }
1545  virtual void findingExportFunctions(bool b) { settings_.partitioner.findingExportFunctions = b; }
1554  bool findingSymbolFunctions() const /*final*/ { return settings_.partitioner.findingSymbolFunctions; }
1555  virtual void findingSymbolFunctions(bool b) { settings_.partitioner.findingSymbolFunctions = b; }
1564  bool findingDataFunctionPointers() const /*final*/ { return settings_.partitioner.findingDataFunctionPointers; }
1565  virtual void findingDataFunctionPointers(bool b) { settings_.partitioner.findingDataFunctionPointers = b; }
1574  bool findingCodeFunctionPointers() const /*final*/ { return settings_.partitioner.findingCodeFunctionPointers; }
1575  virtual void findingCodeFunctionPointers(bool b) { settings_.partitioner.findingCodeFunctionPointers = b; }
1583  bool checkingCallBranch() const /*final*/ { return settings_.partitioner.base.checkingCallBranch; }
1584  virtual void checkingCallBranch(bool b) { settings_.partitioner.base.checkingCallBranch = b; }
1598  bool basicBlockSemanticsAutoDrop() const /*final*/ { return settings_.partitioner.base.basicBlockSemanticsAutoDrop; }
1599  void basicBlockSemanticsAutoDrop(bool b) { settings_.partitioner.base.basicBlockSemanticsAutoDrop = b; }
1607  const std::vector<std::string>& configurationNames() /*final*/ const { return settings_.engine.configurationNames; }
1608  std::vector<std::string>& configurationNames() /*final*/ { return settings_.engine.configurationNames; }
1620  const AddressInterval& namingConstants() const /*final*/ { return settings_.partitioner.namingConstants; }
1621  virtual void namingConstants(const AddressInterval &where) { settings_.partitioner.namingConstants = where; }
1622  void namingConstants(bool b) ROSE_DEPRECATED("this property now stores an interval instead of a Boolean");
1632  const AddressInterval& namingStrings() const /*final*/ { return settings_.partitioner.namingStrings; }
1633  void namingStrings(const AddressInterval &where) { settings_.partitioner.namingStrings = where; }
1642  bool namingSystemCalls() const /*final*/ { return settings_.partitioner.namingSyscalls; }
1643  virtual void namingSystemCalls(bool b) { settings_.partitioner.namingSyscalls = b; }
1653  const boost::filesystem::path& systemCallHeader() const /*final*/ { return settings_.partitioner.syscallHeader; }
1654  virtual void systemCallHeader(const boost::filesystem::path &filename) { settings_.partitioner.syscallHeader = filename; }
1663  bool demangleNames() const /*final*/ { return settings_.partitioner.demangleNames; }
1664  virtual void demangleNames(bool b) { settings_.partitioner.demangleNames = b; }
1673  bool astAllowEmptyGlobalBlock() const /*final*/ { return settings_.astConstruction.allowEmptyGlobalBlock; }
1674  virtual void astAllowEmptyGlobalBlock(bool b) { settings_.astConstruction.allowEmptyGlobalBlock = b; }
1683  bool astAllowFunctionWithNoBasicBlocks() const /*final*/ {
1684  return settings_.astConstruction.allowFunctionWithNoBasicBlocks;
1685  }
1686  virtual void astAllowFunctionWithNoBasicBlocks(bool b) {
1687  settings_.astConstruction.allowFunctionWithNoBasicBlocks = b;
1688  }
1697  bool astAllowEmptyBasicBlock() const /*final*/ { return settings_.astConstruction.allowEmptyBasicBlocks; }
1698  virtual void astAllowEmptyBasicBlock(bool b) { settings_.astConstruction.allowEmptyBasicBlocks = b; }
1710  bool astCopyAllInstructions() const /*final*/ { return settings_.astConstruction.copyAllInstructions; }
1711  virtual void astCopyAllInstructions(bool b) { settings_.astConstruction.copyAllInstructions = b; }
1714  // Python API support functions
1717 #ifdef ROSE_ENABLE_PYTHON_API
1718 
1719  // Similar to frontend, but returns a partitioner rather than an AST since the Python API doesn't yet support ASTs.
1720  Partitioner pythonParseVector(boost::python::list &pyArgs, const std::string &purpose, const std::string &description);
1721  Partitioner pythonParseSingle(const std::string &specimen, const std::string &purpose, const std::string &description);
1722 
1723 #endif
1724 
1726  // Internal stuff
1728 private:
1729  void init();
1730 
1731  // Similar to ::frontend but a lot less complicated.
1732  SgProject* roseFrontendReplacement(const std::vector<boost::filesystem::path> &fileNames);
1733 };
1734 
1735 } // namespace
1736 } // namespace
1737 } // namespace
1738 
1739 #endif
1740 #endif
size_t maxBasicBlockSize() const
Property: Maximum size for basic blocks.
Rose::BinaryAnalysis::DataFlow::Engine< DfCfg, BaseSemantics::StatePtr, TransferFunction, MergeFunction > Engine
Data-Flow engine.
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.
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.
BinaryLoaderPtr Ptr
Referenc counting pointer to BinaryLoader.
Definition: BinaryLoader.h:60
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.
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.
SgAsmBlock * buildAst(const Partitioner &, SgAsmInterpretation *interp=NULL, const AstConstructionSettings &settings=AstConstructionSettings::strict())
Builds an AST from the CFG.
Base class for engines driving the partitioner.
The result from parsing a command line.
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.
const AddressInterval & namingConstants() const
Property: Give names to constants.
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.
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.
MemoryMapPtr Ptr
Reference counting pointer.
Definition: MemoryMap.h:115
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.
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.
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.
Binary analysis.
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.
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...
virtual void namingConstants(const AddressInterval &where)
Property: Give names to constants.
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.
Sawyer::SharedPointer< Base > BasePtr
Reference counted pointer for disassemblers.
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:294
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
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: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.