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/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>
22 #ifdef ROSE_ENABLE_PYTHON_API
23 #undef slots // stupid Qt pollution
24 #include <boost/python.hpp>
28 namespace BinaryAnalysis {
29 namespace Partitioner2 {
114 class ROSE_DLL_API
Engine:
private boost::noncopyable {
127 friend class boost::serialization::access;
130 void serialize(S &s,
unsigned version) {
131 s & loader & disassembler & partitioner & engine & astConstruction;
153 static Ptr instance() {
return Ptr(
new BasicBlockFinalizer); }
154 virtual bool operator()(
bool chain,
const Args &args)
override;
156 void fixFunctionReturnEdge(
const Args&);
157 void fixFunctionCallEdges(
const Args&);
158 void addPossibleIndeterminateEdge(
const Args&);
163 class BasicBlockWorkList:
public CfgAdjustmentCallback {
189 BasicBlockWorkList(Engine *engine,
size_t maxSorts): engine_(engine), maxSorts_(maxSorts) {}
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;
199 void moveAndSortCallReturn(
const Partitioner&);
203 class CodeConstants:
public CfgAdjustmentCallback {
208 std::set<rose_addr_t> toBeExamined_;
209 std::set<rose_addr_t> wasExamined_;
210 rose_addr_t inProgress_;
211 std::vector<rose_addr_t> constants_;
214 CodeConstants(): inProgress_(0) {}
217 static Ptr instance() {
return Ptr(
new CodeConstants); }
220 virtual bool operator()(
bool chain,
const AttachedBasicBlock &attached)
override;
223 virtual bool operator()(
bool chain,
const DetachedBasicBlock &detached)
override;
229 rose_addr_t inProgress()
const {
return inProgress_; }
241 BasicBlockWorkList::Ptr basicBlockWorkList_;
242 CodeConstants::Ptr codeFunctionPointers_;
245 ThunkPredicates::Ptr functionMatcherThunks_;
246 ThunkPredicates::Ptr functionSplittingThunks_;
256 explicit Engine(
const Settings &settings);
296 const std::string &purpose,
const std::string &description);
297 virtual SgAsmBlock* frontend(
const std::vector<std::string> &args,
298 const std::string &purpose,
const std::string &description);
339 const std::string &purpose,
const std::string &description) ;
341 const std::string &purpose,
const std::string &description);
387 virtual MemoryMap::Ptr loadSpecimens(
const std::vector<std::string> &fileNames = std::vector<std::string>());
410 virtual Partitioner partition(
const std::vector<std::string> &fileNames = std::vector<std::string>());
411 Partitioner partition(
const std::string &fileName) ;
428 SgAsmBlock* buildAst(
const std::vector<std::string> &fileNames = std::vector<std::string>()) ;
429 SgAsmBlock* buildAst(
const std::string &fileName) ;
487 static std::string specimenNameDocumentation();
508 virtual void checkSettings();
520 virtual bool isRbaFile(
const std::string&);
526 virtual bool isNonContainer(
const std::string&);
533 virtual bool areContainersParsed()
const;
539 virtual void loadVxCore(
const std::string &spec);
550 virtual bool areSpecimensLoaded()
const;
574 virtual void loadContainers(
const std::vector<std::string> &fileNames);
580 virtual void loadNonContainers(
const std::vector<std::string> &names);
585 virtual void adjustMemoryMap();
634 virtual void checkCreatePartitionerPrerequisites()
const;
679 virtual void runPartitionerRecursive(
Partitioner&);
782 virtual std::vector<Function::Ptr> makeUserFunctions(
Partitioner&,
const std::vector<rose_addr_t>&);
826 virtual std::vector<Function::Ptr> makeCalledFunctions(
Partitioner&);
843 virtual std::vector<Function::Ptr> makeNextPrologueFunction(
Partitioner&, rose_addr_t startVa);
844 virtual std::vector<Function::Ptr> makeNextPrologueFunction(
Partitioner&, rose_addr_t startVa, rose_addr_t &lastSearchedVa);
865 virtual std::vector<Function::Ptr>
866 makeFunctionFromInterFunctionCalls(
Partitioner &partitioner, rose_addr_t &startVa );
890 virtual std::set<rose_addr_t> attachDeadCodeToFunction(
Partitioner&,
const Function::Ptr&,
size_t maxIterations=
size_t(-1));
905 virtual std::vector<DataBlock::Ptr> attachPaddingToFunctions(
Partitioner&);
917 virtual size_t attachAllSurroundedCodeToFunctions(
Partitioner&);
926 virtual size_t attachSurroundedCodeToFunctions(
Partitioner&);
932 virtual void attachBlocksToFunctions(
Partitioner&);
940 virtual std::set<rose_addr_t> attachDeadCodeToFunctions(
Partitioner&,
size_t maxIterations=
size_t(-1));
951 virtual std::vector<DataBlock::Ptr> attachSurroundedDataToFunctions(
Partitioner&);
978 virtual bool makeNextCallReturnEdge(
Partitioner&, boost::logic::tribool assumeCallReturns);
1059 #ifdef ROSE_ENABLE_PYTHON_API
1062 Partitioner pythonParseVector(boost::python::list &pyArgs,
const std::string &purpose,
const std::string &description);
1063 Partitioner pythonParseSingle(
const std::string &specimen,
const std::string &purpose,
const std::string &description);
1074 SgProject* roseFrontendReplacement(
const std::vector<boost::filesystem::path> &fileNames);
Rose::BinaryAnalysis::DataFlow::Engine< DfCfg, BaseSemantics::StatePtr, TransferFunction, MergeFunction > Engine
Data-Flow engine.
const Settings & settings() const
Property: All settings.
Settings for controling the engine behavior.
BinaryLoaderPtr Ptr
Referenc counting pointer to BinaryLoader.
Progress::Ptr progress() const
Property: progress reporting.
Base class for adjusting basic blocks during discovery.
Settings that control the disassembler.
Base class for engines driving the partitioner.
The result from parsing a command line.
List of things to work on.
Settings & settings()
Property: All settings.
A collection of related switch declarations.
static Engine * instance()
Factory method returning an Engine instance of type EngineBinary.
Sawyer::SharedPointer< LibcStartMain > Ptr
Shared ownership pointer to LibcStartMain callback.
virtual void memoryMap(const MemoryMap::Ptr &m)
Property: memory map.
Main namespace for the ROSE library.
Settings for loading specimens.
Settings that control building the AST.
static Engine * instance(const Settings &settings)
Factory method returning an Engine instance of type based on settings.
MemoryMapPtr Ptr
Reference counting pointer.
The parser for a program command line.
virtual void interpretation(SgAsmInterpretation *interp)
Property: interpretation.
Settings that control the engine partitioning.
DisassemblerSettings disassembler
Settings for creating the disassembler.
SgAsmInterpretation * interpretation() const
Property: interpretation.
AstConstructionSettings astConstruction
Settings for constructing the AST.
MemoryMap::Ptr memoryMap() const
Property: memory map.
Format
Format of the state file.
This class represents a source project, with a list of SgFile objects and global information about th...
PartitionerSettings partitioner
Settings for creating a partitioner.
LoaderSettings loader
Settings used during specimen loading.
Sawyer::SharedPointer< Base > BasePtr
Reference counted pointer for disassemblers.
Partitions instructions into basic blocks and functions.
Base class for all ROSE exceptions.
Binary state files are smaller and faster than the other formats, but are not portable across archite...
Represents an interpretation of a binary container.
EngineSettings engine
Settings that control engine behavior.
Container associating values with keys.
virtual void progress(const Progress::Ptr &progress)
Property: progress reporting.
Sawyer::SharedPointer< Progress > Ptr
Progress objects are reference counted.
Holds configuration information.