1#ifndef ROSE_BinaryAnalysis_Partitioner2_Modules_H
2#define ROSE_BinaryAnalysis_Partitioner2_Modules_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5#include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
7#include <Rose/BinaryAnalysis/Partitioner2/ControlFlowGraph.h>
8#include <Rose/BinaryAnalysis/Partitioner2/Thunk.h>
10#include <boost/logic/tribool.hpp>
11#include <Sawyer/SharedPointer.h>
14namespace BinaryAnalysis {
15namespace Partitioner2 {
210 : maxInsns_(maxInsns) {}
243 std::vector<AddressPair> rewrites_;
261 const std::vector<AddressPair>&
rewrites()
const {
return rewrites_; }
262 std::vector<AddressPair>&
rewrites() {
return rewrites_; }
263 void rewrites(std::vector<AddressPair> &v) { rewrites_ = v; }
287 static Ptr instance(
const std::string &config);
288 static Ptr instance(
const std::vector<std::string> &args);
305 std::string fileName;
315 static Ptr instance(
const std::string &config);
316 static Ptr instance(
const std::vector<std::string> &args);
332 bool accentSpecialValues;
333 Settings(): accentSpecialValues(
true) {}
339 HexDumper(
const Settings &settings): settings_(settings), trigger_(settings.when) {}
341 static Ptr instance(
const Settings &settings) {
return Ptr(
new HexDumper(settings)); }
342 static Ptr instance(
const std::string &config);
343 static Ptr instance(
const std::vector<std::string> &args);
363 Debugger(
const Settings &settings): settings_(settings), trigger_(settings.when) {}
365 static Ptr instance(
const Settings &settings) {
return Ptr(
new Debugger(settings)); }
366 static Ptr instance(
const std::string &config);
367 static Ptr instance(
const std::vector<std::string> &args);
383 std::vector<FunctionPtr> functions_;
402 virtual std::vector<FunctionPtr>
functions()
const override;
421 size_t leaveAtFront=16,
size_t leaveAtBack=1);
Base class for adjusting basic blocks during discovery.
virtual bool operator()(bool chain, const Args &)=0
Callback method.
BasicBlockCallbackPtr Ptr
Shared-ownership pointer to a BasicBlockCallback.
Termination
Whether to terminate a basic block.
@ CONTINUE_DISCOVERY
Do not explicitly terminate block here.
@ TERMINATE_PRIOR
Make previous instruction the final instruction of the block.
@ TERMINATE_NOW
Make current instruction the final instruction of the block.
Base class for CFG-adjustment callbacks.
Sawyer::SharedPointer< CfgAdjustmentCallback > Ptr
Shared ownership pointer.
Base class for matching function padding.
virtual rose_addr_t match(const PartitionerConstPtr &, rose_addr_t anchor)=0
Attempt to match padding.
Base class for matching function prologues.
virtual std::vector< FunctionPtr > functions() const =0
Returns the function(s) for the previous successful match.
Base class for matching an instruction pattern.
Sawyer::SharedPointer< InstructionMatcher > Ptr
Shared-ownership pointer to an InstructionMatcher.
virtual bool match(const PartitionerConstPtr &, rose_addr_t anchor)=0
Attempt to match an instruction pattern.
Follow basic block ghost edges.
virtual bool operator()(bool chain, const Args &args) override
Callback method.
Callback to limit basic block size.
Sawyer::SharedPointer< BasicBlockSizeLimiter > Ptr
Shared-ownership pointer to a BasicBlockSizeLimiter.
size_t maxInstructions() const
Property: Maximum size of block.
static Ptr instance(size_t maxInsns)
Constructor.
virtual bool operator()(bool chain, const Args &) override
Callback method.
void maxInstructions(size_t maxInsns)
Property: Maximum size of block.
Produce a GraphViz file for the CFG at a certain time.
static std::string docString()
Documentation string.
virtual bool operator()(bool chain, const AttachedBasicBlock &args) override
Called when basic block is attached or placeholder inserted.
virtual bool operator()(bool chain, const DetachedBasicBlock &) override
Called when basic block is detached or placeholder erased.
Convenient place to attach a debugger.
static std::string docString()
Documentation string.
virtual bool operator()(bool chain, const AttachedBasicBlock &args) override
Called when basic block is attached or placeholder inserted.
virtual bool operator()(bool chain, const DetachedBasicBlock &) override
Called when basic block is detached or placeholder erased.
Produce a hexdump at a certain time.
virtual bool operator()(bool chain, const DetachedBasicBlock &) override
Called when basic block is detached or placeholder erased.
static std::string docString()
Documentation string.
virtual bool operator()(bool chain, const AttachedBasicBlock &args) override
Called when basic block is attached or placeholder inserted.
List some instructions at a certain time.
virtual bool operator()(bool chain, const DetachedBasicBlock &) override
Called when basic block is detached or placeholder erased.
static std::string docString()
Documentation string.
virtual bool operator()(bool chain, const AttachedBasicBlock &args) override
Called when basic block is attached or placeholder inserted.
Callback to rewrite CFG edges.
void rewrites(std::vector< AddressPair > &v)
Property: Pairs of old/new addresses to rewrite.
virtual bool operator()(bool chain, const Args &) override
Callback method.
std::pair< rose_addr_t, rose_addr_t > AddressPair
Pairs of old and new addresses.
Sawyer::SharedPointer< IpRewriter > Ptr
Shared-ownership pointer to a IpRewriter.
std::vector< AddressPair > & rewrites()
Property: Pairs of old/new addresses to rewrite.
const std::vector< AddressPair > & rewrites() const
Property: Pairs of old/new addresses to rewrite.
static Ptr instance(const std::vector< AddressPair > &rewrites)
Constructor.
static Ptr instance(const ThunkPredicatesPtr &)
Allocating constructor.
virtual bool match(const PartitionerConstPtr &, rose_addr_t anchor) override
Attempt to match an instruction pattern.
ThunkPredicatesPtr predicates() const
Property: Predicates used for matching thunks.
virtual std::vector< FunctionPtr > functions() const override
Returns the function(s) for the previous successful match.
void predicates(const ThunkPredicatesPtr &)
Property: Predicates used for matching thunks.
Prevent discontiguous basic blocks.
virtual bool operator()(bool chain, const Args &args) override
Callback method.
Trigger based on number of times called.
A collection of related switch declarations.
static Interval whole()
Construct an interval that covers the entire domain.
Base class for reference counted objects.
Reference-counting intrusive smart pointer.
Represents a synthesized function.
Represents an interpretation of a binary container.
This class represents the base class for all IR nodes within Sage III.
void nameStrings(const PartitionerConstPtr &, const AddressInterval &)
Give labels to string constants.
void labelSymbolAddresses(const PartitionerPtr &, SgAsmGenericHeader *)
Give labels to addresses that are symbols.
void fixupAstCallingConventions(const PartitionerConstPtr &, SgNode *ast)
Fixes calling convention results.
void nameConstants(const PartitionerConstPtr &, const AddressInterval &)
Gives names to constants in instructions.
SgAsmBlock * buildBasicBlockAst(const PartitionerConstPtr &, const BasicBlockPtr &, const FunctionPtr &, const AstConstructionSettings &)
Build AST for basic block.
SgAsmBlock * buildGlobalBlockAst(const PartitionerConstPtr &, const AstConstructionSettings &)
Builds the global block AST.
std::vector< FunctionPtr > findSymbolFunctions(const PartitionerConstPtr &, SgAsmGenericHeader *)
Finds functions for which symbols exist.
std::vector< FunctionPtr > findNoopFunctions(const PartitionerConstPtr &)
Find functions that are no-ops.
AddressIntervalSet deExecuteZeros(const MemoryMapPtr &map, size_t threshold, size_t leaveAtFront=16, size_t leaveAtBack=1)
Remove execute permissions for zeros.
void demangleFunctionNames(const PartitionerConstPtr &)
Demangle all function names.
std::string canonicalFunctionName(const std::string &)
Convert system function names to ROSE canonical form.
SgAsmFunction * buildFunctionAst(const PartitionerConstPtr &, const FunctionPtr &, const AstConstructionSettings &)
Build AST for function.
boost::logic::tribool isStackBasedReturn(const PartitionerConstPtr &, const BasicBlockPtr &)
Determine if basic block is a stack-based function return.
void fixupAstPointers(SgNode *ast, SgAsmInterpretation *interp=NULL)
Fixes pointers in the AST.
void nameNoopFunctions(const PartitionerConstPtr &)
Give names to functions that are no-ops.
SgAsmBlock * buildDataBlockAst(const PartitionerConstPtr &, const DataBlockPtr &, const AstConstructionSettings &)
Build AST for data block.
SgAsmBlock * buildAst(const PartitionerConstPtr &, SgAsmInterpretation *interp=NULL, const AstConstructionSettings &settings=AstConstructionSettings::strict())
Builds an AST from the CFG.
Sawyer::SharedPointer< FunctionPaddingMatcher > FunctionPaddingMatcherPtr
Shared ownership pointer.
Sawyer::SharedPointer< FunctionPrologueMatcher > FunctionPrologueMatcherPtr
Shared ownership pointer.
Sawyer::SharedPointer< BasicBlockCallback > BasicBlockCallbackPtr
Shared ownership pointer.
Settings that control building the AST.
static AstConstructionSettings strict()
Default strict settings.
Arguments passed to the callback.
Results & results
Results to control basic block discovery.
PartitionerConstPtr partitioner
Partitioner requesting basic block successors.
BasicBlockPtr bblock
Basic block whose successors are to be computed.
Results coordinated across all callbacks.
Termination terminate
Whether block should be explicitly terminated.
Arguments for attaching a basic block.
Arguments for detaching a basic block.