1#ifndef ROSE_BinaryAnalysis_Partitioner2_EngineBinary_H
2#define ROSE_BinaryAnalysis_Partitioner2_EngineBinary_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
6#include <Rose/BinaryAnalysis/Architecture/BasicTypes.h>
7#include <Rose/BinaryAnalysis/Partitioner2/Engine.h>
8#include <Rose/BinaryAnalysis/Partitioner2/ModulesLinux.h>
9#include <Rose/BinaryAnalysis/Partitioner2/Utility.h>
10#include <Rose/BinaryAnalysis/SerialIo.h>
12#include <boost/noncopyable.hpp>
13#include <boost/regex.hpp>
16#ifdef ROSE_ENABLE_PYTHON_API
18#include <boost/python.hpp>
22namespace BinaryAnalysis {
23namespace Partitioner2 {
357 virtual std::vector<FunctionPtr>
534#ifdef ROSE_ENABLE_PYTHON_API
537 PartitionerPtr pythonParseVector(boost::python::list &pyArgs,
const std::string &purpose,
const std::string &description);
538 PartitionerPtr pythonParseSingle(
const std::string &
specimen,
const std::string &purpose,
const std::string &description);
558 const std::string &purpose,
const std::string &description)
override;
570 virtual SgAsmBlock*
buildAst(
const std::vector<std::string> &fileNames = std::vector<std::string>())
override;
580 virtual SgProject* roseFrontendReplacement(
const std::vector<boost::filesystem::path> &fileNames)
override;
Engine for specimens containing machine instructions.
virtual std::vector< FunctionPtr > makeCalledFunctions(const PartitionerPtr &)
Make functions for function call edges.
virtual std::vector< FunctionPtr > makeExportFunctions(const PartitionerPtr &, SgAsmInterpretation *)
Make functions at export addresses.
virtual BasicBlockPtr makeNextBasicBlock(const PartitionerPtr &)
Discover a basic block.
virtual std::vector< DataBlockPtr > attachPaddingToFunctions(const PartitionerPtr &)
Attach padding to all functions.
static Sawyer::CommandLine::SwitchGroup disassemblerSwitches(DisassemblerSettings &)
Command-line switches related to decoding instructions.
virtual EnginePtr instanceFromFactory(const Settings &) override
Virtual constructor for factories.
virtual void runPartitionerInit(const PartitionerPtr &) override
Finds interesting things to work on initially.
virtual std::vector< FunctionPtr > makeFunctionFromInterFunctionCalls(const PartitionerPtr &, Address &startVa)
Make functions from inter-function calls.
virtual BinaryLoaderPtr obtainLoader(const BinaryLoaderPtr &hint)
Obtain a binary loader.
virtual std::list< Sawyer::CommandLine::SwitchGroup > commandLineSwitches() override
Command-line switches for a particular engine.
virtual bool partitionCilSections(const PartitionerPtr &)
Partition any sections containing CIL code.
virtual SgAsmBlock * buildAst(const std::vector< std::string > &fileNames=std::vector< std::string >()) override
Obtain an abstract syntax tree.
virtual std::vector< FunctionPtr > makeImportFunctions(const PartitionerPtr &, SgAsmInterpretation *)
Make functions at import trampolines.
virtual std::vector< DataBlockPtr > attachSurroundedDataToFunctions(const PartitionerPtr &)
Attach intra-function data to functions.
virtual void reset() override
Reset the engine to its initial state.
static Sawyer::CommandLine::SwitchGroup engineSwitches(EngineSettings &)
Command-line switches related to the general engine behavior.
virtual BasicBlockPtr makeNextBasicBlockFromPlaceholder(const PartitionerPtr &)
Discover basic block at next placeholder.
virtual void runPartitionerFinal(const PartitionerPtr &) override
Runs the final parts of partitioning.
virtual std::vector< FunctionPtr > makeContainerFunctions(const PartitionerPtr &, SgAsmInterpretation *)
Make functions based on specimen container.
virtual void attachBlocksToFunctions(const PartitionerPtr &)
Attach basic blocks to functions.
virtual PartitionerPtr createPartitionerFromAst(SgAsmInterpretation *)
Create a partitioner from an AST.
virtual FunctionPtr makeNextCodeReferencedFunction(const PartitionerConstPtr &)
Scan instruction ASTs to function pointers.
virtual void discoverFunctions(const PartitionerPtr &)
Discover as many functions as possible.
ThunkPredicatesPtr functionMatcherThunks() const
Property: Predicate for finding functions that are thunks.
virtual SgAsmInterpretation * parseContainers(const std::vector< std::string > &fileNames) override
Parse specimen binary containers.
virtual std::vector< FunctionPtr > makeSymbolFunctions(const PartitionerPtr &, SgAsmInterpretation *)
Make functions for symbols.
virtual bool isNonContainer(const std::string &) override
Determine whether a specimen name is a non-container.
SgAsmBlock * frontend(const std::vector< std::string > &args, const std::string &purpose, const std::string &description) override
Most basic usage of the partitioner.
virtual std::vector< FunctionPtr > makeNextPrologueFunction(const PartitionerPtr &, Address startVa)
Make function at prologue pattern.
virtual std::set< Address > attachDeadCodeToFunction(const PartitionerPtr &, const FunctionPtr &, size_t maxIterations=size_t(-1))
Attach dead code to function.
virtual size_t attachSurroundedCodeToFunctions(const PartitionerPtr &)
Attach intra-function basic blocks to functions.
virtual std::vector< FunctionPtr > makeEntryFunctions(const PartitionerPtr &, SgAsmInterpretation *)
Make functions at specimen entry addresses.
virtual std::set< Address > attachDeadCodeToFunctions(const PartitionerPtr &, size_t maxIterations=size_t(-1))
Attach dead code to functions.
virtual std::vector< FunctionPtr > makeErrorHandlingFunctions(const PartitionerPtr &, SgAsmInterpretation *)
Make functions at error handling addresses.
static Sawyer::CommandLine::SwitchGroup astConstructionSwitches(AstConstructionSettings &)
Command-line switches related to constructing an AST from the partitioner.
virtual FunctionPtr makeNextDataReferencedFunction(const PartitionerConstPtr &, Address &startVa)
Scan read-only data to find function pointers.
virtual void runPartitionerRecursive(const PartitionerPtr &) override
Runs the recursive part of partioning.
virtual DataBlockPtr attachPaddingToFunction(const PartitionerPtr &, const FunctionPtr &)
Attach function padding to function.
virtual PartitionerPtr partition(const std::vector< std::string > &fileNames=std::vector< std::string >()) override
Partition instructions into basic blocks and functions.
static Sawyer::CommandLine::SwitchGroup partitionerSwitches(PartitionerSettings &)
Command-line switches related to partitioning instructions.
EngineBinary()=delete
Default constructor.
BinaryLoaderPtr binaryLoader() const
Property: binary loader.
virtual std::vector< FunctionPtr > makeNextPrologueFunction(const PartitionerPtr &, Address startVa, Address &lastSearchedVa)
Make function at prologue pattern.
static Ptr factory()
Allocate a factory.
virtual bool makeNextCallReturnEdge(const PartitionerPtr &, boost::logic::tribool assumeCallReturns)
Insert a call-return edge and discover its basic block.
virtual MemoryMapPtr loadSpecimens(const std::vector< std::string > &fileNames=std::vector< std::string >()) override
Load and/or link interpretation.
static Sawyer::CommandLine::SwitchGroup loaderSwitches(LoaderSettings &)
Command-line switches related to loading specimen into memory.
virtual BinaryLoaderPtr obtainLoader()
Obtain a binary loader.
virtual bool areContainersParsed() const override
Returns true if containers are parsed.
bool hasCilCodeSection()
Determine whether the interpretation header contains a CIL code section.
virtual bool matchFactory(const std::vector< std::string > &specimen) const override
Predicate for matching a concrete engine factory by settings and specimen.
virtual void loadNonContainers(const std::vector< std::string > &names)
Loads memory from non-containers.
virtual PartitionerPtr createTunedPartitioner()
Create a tuned partitioner.
virtual std::vector< FunctionPtr > makeUserFunctions(const PartitionerPtr &, const std::vector< Address > &)
Make a function at each specified address.
virtual PartitionerPtr createPartitioner() override
Create partitioner.
static Ptr instance(const Settings &)
Allocating constructor with settings.
ThunkPredicatesPtr functionSplittingThunks() const
Property: Predicate for finding thunks at the start of functions.
virtual std::pair< std::string, std::string > specimenNameDocumentation() override
Documentation about how the specimen is specified.
static Ptr instance()
Allocating constructor.
virtual std::vector< FunctionPtr > makeInterruptVectorFunctions(const PartitionerPtr &, const AddressInterval &vector)
Make functions from an interrupt vector.
virtual void loadVxCore(const std::string &spec)
Parses a vxcore specification and initializes memory.
virtual size_t attachAllSurroundedCodeToFunctions(const PartitionerPtr &)
Attach all possible intra-function basic blocks to functions.
virtual void loadContainers(const std::vector< std::string > &fileNames)
Loads memory from binary containers.
virtual void discoverBasicBlocks(const PartitionerPtr &)
Discover as many basic blocks as possible.
Base class for engines driving the partitioner.
const std::vector< std::string > & specimen() const
Property: specimen.
SgAsmBlock * frontend(int argc, char *argv[], const std::string &purpose, const std::string &description)
Most basic usage of the partitioner.
Engine()=delete
Default constructor.
virtual SgAsmBlock * buildAst(const std::vector< std::string > &fileNames=std::vector< std::string >())=0
Obtain an abstract syntax tree.
virtual SgAsmInterpretation * parseContainers(const std::vector< std::string > &fileNames)=0
Parse specimen binary containers.
virtual MemoryMapPtr loadSpecimens(const std::vector< std::string > &fileNames=std::vector< std::string >())=0
Load and/or link interpretation.
virtual PartitionerPtr partition(const std::vector< std::string > &fileNames=std::vector< std::string >())=0
Partition instructions into basic blocks and functions.
A collection of related switch declarations.
Reference-counting intrusive smart pointer.
Represents an interpretation of a binary container.
This class represents a source project, with a list of SgFile objects and global information about th...
Sawyer::SharedPointer< EngineBinary > EngineBinaryPtr
Shared-ownership pointer for EngineBinary.
std::uint64_t Address
Address.
Settings that control building the AST.
Settings that control the disassembler.
Settings for controling the engine behavior.
Settings for loading specimens.
Settings that control the engine partitioning.