1#ifndef ROSE_BinaryAnalysis_Partitioner2_Engine_H
2#define ROSE_BinaryAnalysis_Partitioner2_Engine_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
6#include <Rose/BasicTypes.h>
7#include <Rose/BinaryAnalysis/Architecture/BasicTypes.h>
8#include <Rose/BinaryAnalysis/Partitioner2/Exception.h>
9#include <Rose/BinaryAnalysis/Partitioner2/Modules.h>
10#include <Rose/BinaryAnalysis/SerialIo.h>
12#include <Sawyer/DistinctList.h>
13#include <Sawyer/SharedObject.h>
14#include <Sawyer/SharedPointer.h>
17namespace BinaryAnalysis {
18namespace Partitioner2 {
176#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
178 friend class boost::serialization::access;
179 template<
class S>
void serialize(S&,
unsigned version);
214 virtual std::vector<std::string>
specimen(
const std::vector<std::string>&)
const = 0;
220 virtual std::vector<std::string>
specimen(
const std::vector<std::string>&)
const override;
229 virtual std::vector<std::string>
specimen(
const std::vector<std::string>&)
const override;
238 virtual std::vector<std::string>
specimen(
const std::vector<std::string>&)
const override;
249 virtual std::vector<std::string>
specimen(
const std::vector<std::string>&)
const override;
264 static Ptr instance();
267 void fixFunctionReturnEdge(
const Args&);
268 void fixFunctionCallEdges(
const Args&);
269 void addPossibleIndeterminateEdge(
const Args&);
302 ~BasicBlockWorkList();
304 BasicBlockWorkList(
const EnginePtr &engine,
size_t maxSorts);
307 static Ptr instance(
const EnginePtr &engine,
size_t maxSorts);
308 virtual bool operator()(
bool chain,
const AttachedBasicBlock &args)
override;
309 virtual bool operator()(
bool chain,
const DetachedBasicBlock &args)
override;
325 std::set<rose_addr_t> toBeExamined_;
326 std::set<rose_addr_t> wasExamined_;
327 rose_addr_t inProgress_;
328 std::vector<rose_addr_t> constants_;
336 static Ptr instance();
339 rose_addr_t inProgress();
363 std::vector<std::string> specimen_;
612 const std::
string &purpose, const std::
string &description);
614 const std::
string &purpose, const std::
string &description) = 0;
655 const std::
string &purpose, const std::
string &description) ;
657 const std::
string &purpose, const std::
string &description);
674 virtual
SgAsmBlock*
buildAst(const std::vector<std::
string> &fileNames = std::vector<std::
string>()) = 0;
693 ROSE_DEPRECATED("use
Partitioner::instanceFromRbaFile");
953 const std::
string&
name() const ;
1017 virtual
void specimen(const std::vector<std::
string>&);
1025 virtual
SgProject* roseFrontendReplacement(const std::vector<boost::filesystem::path> &fileNames) = 0;
Base class for adjusting basic blocks during discovery.
Base class for CFG-adjustment callbacks.
Holds configuration information.
Engine for specimens containing machine instructions.
All but the last N arguments are the specimen.
AllButLastArguments(size_t n)
Constructor returning all but last n arguments.
virtual std::vector< std::string > specimen(const std::vector< std::string > &) const override
Return specimen from positional arguments.
Return all positional arguments as the specimen.
virtual std::vector< std::string > specimen(const std::vector< std::string > &) const override
Return specimen from positional arguments.
virtual bool operator()(bool chain, const Args &args) override
Callback method.
virtual bool operator()(bool chain, const DetachedBasicBlock &detached) override
Called when basic block is detached or placeholder erased.
virtual bool operator()(bool chain, const AttachedBasicBlock &attached) override
Called when basic block is attached or placeholder inserted.
Exception(const std::string &)
Construct an exception with a message string.
Up to first N arguments are the specimen.
FirstPositionalArguments(size_t n)
Constructor returning up to n arguments.
virtual std::vector< std::string > specimen(const std::vector< std::string > &) const override
Return specimen from positional arguments.
Nth group of arguments are the specimen.
GroupedPositionalArguments(size_t)
Constructor returning nth group of arguments.
virtual std::vector< std::string > specimen(const std::vector< std::string > &) const override
Return specimen from positional arguments.
GroupedPositionalArguments()
Constructor returning first group of arguments.
How to parse positional command-line arguments.
virtual std::vector< std::string > specimen(const std::vector< std::string > &) const =0
Return specimen from positional arguments.
Base class for engines driving the partitioner.
virtual PartitionerPtr createBarePartitioner()
Create a bare partitioner.
virtual Sawyer::CommandLine::Parser commandLineParser(const std::string &purpose, const std::string &description)
Creates a command-line parser.
void addAllToParser(Sawyer::CommandLine::Parser &)
Add switches and sections to command-line parser.
virtual bool isRbaFile(const std::string &)
Determine whether a specimen is an RBA file.
MemoryMapPtr memoryMap() const
Property: memory map.
virtual void runPartitionerRecursive(const PartitionerPtr &)=0
Runs the recursive part of partioning.
virtual void addToParser(Sawyer::CommandLine::Parser &)
Add switches and sections to command-line parser.
virtual std::pair< std::string, std::string > specimenNameDocumentation()=0
Documentation about how the specimen is specified.
virtual std::vector< DataBlockPtr > makeConfiguredDataBlocks(const PartitionerPtr &, const Configuration &)
Make data blocks based on configuration.
static std::list< std::pair< std::string, std::string > > allSpecimenNameDocumentation()
Documentation for all specimen specifications.
Sawyer::CommandLine::ParserResult parseCommandLine(int argc, char *argv[], const std::string &purpose, const std::string &description)
Parse the command-line.
SgAsmInterpretation * interpretation() const
Property: interpretation.
virtual bool areSpecimensLoaded() const
Returns true if specimens are loaded.
const std::vector< std::string > & specimen() const
Property: specimen.
static bool deregisterFactory(const EnginePtr &factory)
Remove a concrete engine factory from the registry.
ProgressPtr progress() const
Property: progress reporting.
virtual void runPartitionerFinal(const PartitionerPtr &)=0
Runs the final parts of partitioning.
virtual bool areContainersParsed() const =0
Returns true if containers are parsed.
SgAsmBlock * frontend(int argc, char *argv[], const std::string &purpose, const std::string &description)
Most basic usage of the partitioner.
virtual EnginePtr instanceFromFactory(const Settings &)=0
Virtual constructor for factories.
virtual std::vector< FunctionPtr > makeConfiguredFunctions(const PartitionerPtr &, const Configuration &)
Make functions based on configuration information.
static void registerFactory(const EnginePtr &factory)
Register an engine as a factory.
virtual void adjustMemoryMap()
Adjust memory map post-loading.
Architecture::BaseConstPtr architecture()
Property: Architecture.
virtual void checkSettings()
Check settings after command-line is processed.
Engine()=delete
Default constructor.
virtual void runPartitionerInit(const PartitionerPtr &)=0
Finds interesting things to work on initially.
virtual PartitionerPtr createPartitioner()=0
Create partitioner.
static EnginePtr forge(const std::vector< std::string > &specimen)
Creates a suitable engine based on the specimen.
std::list< Sawyer::CommandLine::SwitchGroup > allCommandLineSwitches()
List of command-line switches for all engines.
bool isFactory() const
Returns true if this object is a factory.
virtual bool matchFactory(const std::vector< std::string > &specimen) const =0
Predicate for matching a concrete engine factory by settings and specimen.
virtual std::list< Sawyer::CommandLine::SwitchGroup > commandLineSwitches()
Command-line switches for a particular engine.
BasicBlockWorkList::Ptr basicBlockWorkList() const
Property: BasicBlock work list.
Engine(const std::string &name, const Settings &settings)
Allocating instance constructors are implemented by the non-abstract subclasses.
virtual SgAsmBlock * buildAst(const std::vector< std::string > &fileNames=std::vector< std::string >())=0
Obtain an abstract syntax tree.
CodeConstants::Ptr codeFunctionPointers() const
Property: Instruction AST constants.
const Settings & settings() const
Property: All settings.
virtual bool isNonContainer(const std::string &)=0
Determine whether a specimen name is a non-container.
const std::string & name() const
Property: Name.
virtual SgAsmInterpretation * parseContainers(const std::vector< std::string > &fileNames)=0
Parse specimen binary containers.
virtual void reset()
Reset the engine to its initial state.
virtual void labelAddresses(const PartitionerPtr &, const Configuration &)
Label addresses.
virtual MemoryMapPtr loadSpecimens(const std::vector< std::string > &fileNames=std::vector< std::string >())=0
Load and/or link interpretation.
virtual void updateAnalysisResults(const PartitionerPtr &)
Runs various analysis passes.
virtual void checkCreatePartitionerPrerequisites() const
Check that we have everything necessary to create a partitioner.
virtual void runPartitioner(const PartitionerPtr &)
Partitions instructions into basic blocks and functions.
virtual Architecture::BaseConstPtr obtainArchitecture()
Determine the architecture.
static std::vector< EnginePtr > registeredFactories()
List of all registered factories.
virtual PartitionerPtr partition(const std::vector< std::string > &fileNames=std::vector< std::string >())=0
Partition instructions into basic blocks and functions.
Partitions instructions into basic blocks and functions.
Base class for binary state input and output.
A doubly-linked list of distinct items.
Container associating values with keys.
Holds a value or nothing.
Creates SharedPointer from this.
Base class for reference counted objects.
Represents an interpretation of a binary container.
This class represents a source project, with a list of SgFile objects and global information about th...
std::shared_ptr< const Base > BaseConstPtr
Reference counted pointer for Architecture::Base.
Sawyer::SharedPointer< Engine > EnginePtr
Shared-ownership pointer for Engine.
Settings that control building the AST.
Arguments passed to the callback.
Arguments for attaching a basic block.
Arguments for detaching a basic block.
Settings that control the disassembler.
Settings for controling the engine behavior.
EngineSettings engine
Settings that control engine behavior.
LoaderSettings loader
Settings used during specimen loading.
DisassemblerSettings disassembler
Settings for creating the disassembler.
AstConstructionSettings astConstruction
Settings for constructing the AST.
PartitionerSettings partitioner
Settings for creating a partitioner.
Settings for loading specimens.
Settings that control the engine partitioning.