1 #ifndef ROSE_BinaryAnalysis_Partitioner2_Modules_H
2 #define ROSE_BinaryAnalysis_Partitioner2_Modules_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
6 #include <Rose/BinaryAnalysis/Partitioner2/BasicBlock.h>
7 #include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
8 #include <Rose/BinaryAnalysis/Partitioner2/ControlFlowGraph.h>
9 #include <Rose/BinaryAnalysis/Partitioner2/Function.h>
10 #include <Rose/BinaryAnalysis/Partitioner2/Thunk.h>
11 #include <Rose/BinaryAnalysis/Partitioner2/Utility.h>
13 #include <boost/logic/tribool.hpp>
14 #include <Sawyer/SharedPointer.h>
17 namespace BinaryAnalysis {
18 namespace Partitioner2 {
66 : partitioner(partitioner), bblock(bblock), results(results) {}
74 virtual bool operator()(
bool chain,
const Args&) = 0;
128 virtual std::vector<Function::Ptr>
functions()
const = 0;
213 : maxInsns_(maxInsns) {}
233 virtual bool operator()(
bool chain,
const Args&)
override;
246 std::vector<AddressPair> rewrites_;
250 : rewrites_(rewrites) {}
264 const std::vector<AddressPair>&
rewrites()
const {
return rewrites_; }
265 std::vector<AddressPair>&
rewrites() {
return rewrites_; }
266 void rewrites(std::vector<AddressPair> &v) { rewrites_ = v; }
269 virtual bool operator()(
bool chain,
const Args&)
override;
290 static Ptr instance(
const std::string &config);
291 static Ptr instance(
const std::vector<std::string> &args);
293 static std::string docString();
294 virtual bool operator()(
bool chain,
const AttachedBasicBlock &args)
override;
308 std::string fileName;
318 static Ptr instance(
const std::string &config);
319 static Ptr instance(
const std::vector<std::string> &args);
321 static std::string docString();
322 virtual bool operator()(
bool chain,
const AttachedBasicBlock &args)
override;
335 bool accentSpecialValues;
336 Settings(): accentSpecialValues(
true) {}
342 HexDumper(
const Settings &settings): settings_(settings), trigger_(settings.when) {}
344 static Ptr instance(
const Settings &settings) {
return Ptr(
new HexDumper(settings)); }
345 static Ptr instance(
const std::string &config);
346 static Ptr instance(
const std::vector<std::string> &args);
348 static std::string docString();
349 virtual bool operator()(
bool chain,
const AttachedBasicBlock &args)
override;
366 Debugger(
const Settings &settings): settings_(settings), trigger_(settings.when) {}
368 static Ptr instance(
const Settings &settings) {
return Ptr(
new Debugger(settings)); }
369 static Ptr instance(
const std::string &config);
370 static Ptr instance(
const std::vector<std::string> &args);
372 static std::string docString();
373 virtual bool operator()(
bool chain,
const AttachedBasicBlock &args)
override;
386 std::vector<Function::Ptr> functions_;
391 : predicates_(predicates) {}
406 virtual std::vector<Function::Ptr>
functions()
const override {
return functions_; }
425 size_t leaveAtFront=16,
size_t leaveAtBack=1);
Termination
Whether to terminate a basic block.
void fixupAstPointers(SgNode *ast, SgAsmInterpretation *interp=NULL)
Fixes pointers in the AST.
Produce a hexdump at a certain time.
List some instructions at a certain time.
void nameConstants(const Partitioner &)
Gives names to constants in instructions.
void demangleFunctionNames(const Partitioner &)
Demangle all function names.
Base class for matching function padding.
Base class for CFG-adjustment callbacks.
Base class for adjusting basic blocks during discovery.
void nameNoopFunctions(const Partitioner &)
Give names to functions that are no-ops.
std::pair< rose_addr_t, rose_addr_t > AddressPair
Pairs of old and new addresses.
Sawyer::SharedPointer< BasicBlockSizeLimiter > Ptr
Shared-ownership pointer to a BasicBlockSizeLimiter.
Base class for matching function prologues.
static Ptr instance(size_t maxInsns)
Constructor.
SgAsmBlock * buildAst(const Partitioner &, SgAsmInterpretation *interp=NULL, const AstConstructionSettings &settings=AstConstructionSettings::strict())
Builds an AST from the CFG.
SgAsmBlock * buildBasicBlockAst(const Partitioner &, const BasicBlock::Ptr &, const Function::Ptr &, const AstConstructionSettings &)
Build AST for basic block.
virtual bool operator()(bool chain, const Args &) override
Callback method.
std::string canonicalFunctionName(const std::string &)
Convert system function names to ROSE canonical form.
SgAsmBlock * buildDataBlockAst(const Partitioner &, const DataBlock::Ptr &, const AstConstructionSettings &)
Build AST for data block.
size_t maxInstructions() const
Property: Maximum size of block.
Callback to limit basic block size.
std::vector< AddressPair > & rewrites()
Property: Pairs of old/new addresses to rewrite.
Termination terminate
Whether block should be explicitly terminated.
A collection of related switch declarations.
Represents a synthesized function.
void rewrites(std::vector< AddressPair > &v)
Property: Pairs of old/new addresses to rewrite.
ThunkPredicates::Ptr predicates() const
Property: Predicates used for matching thunks.
static Ptr instance(const ThunkPredicates::Ptr &predicates)
Allocating constructor.
Results coordinated across all callbacks.
virtual bool operator()(bool chain, const DetachedBasicBlock &) override
Called when basic block is detached or placeholder erased.
std::vector< Function::Ptr > findSymbolFunctions(const Partitioner &, SgAsmGenericHeader *)
Finds functions for which symbols exist.
virtual bool operator()(bool chain, const AttachedBasicBlock &args) override
Called when basic block is attached or placeholder inserted.
SgAsmFunction * buildFunctionAst(const Partitioner &, const Function::Ptr &, const AstConstructionSettings &)
Build AST for function.
Main namespace for the ROSE library.
Settings that control building the AST.
Base class for matching an instruction pattern.
static AstConstructionSettings strict()
Default strict settings.
Sawyer::SharedPointer< CfgAdjustmentCallback > Ptr
Shared ownership pointer to CfgAdjustmentCallback.
Make current instruction the final instruction of the block.
Reference-counting intrusive smart pointer.
Do not explicitly terminate block here.
virtual bool operator()(bool chain, const DetachedBasicBlock &) override
Called when basic block is detached or placeholder erased.
Convenient place to attach a debugger.
static Ptr instance(const std::vector< AddressPair > &rewrites)
Constructor.
Trigger based on number of times called.
virtual bool operator()(bool chain, const DetachedBasicBlock &) override
Called when basic block is detached or placeholder erased.
virtual bool operator()(bool chain, const AttachedBasicBlock &args) override
Called when basic block is attached or placeholder inserted.
virtual bool operator()(bool chain, const Args &)=0
Callback method.
virtual bool match(const Partitioner &, rose_addr_t anchor)=0
Attempt to match an instruction pattern.
virtual bool operator()(bool chain, const AttachedBasicBlock &args) override
Called when basic block is attached or placeholder inserted.
virtual bool operator()(bool chain, const Args &args) override
Callback method.
This class represents the base class for all IR nodes within Sage III.
static Interval whole()
Construct an interval that covers the entire domain.
virtual rose_addr_t match(const Partitioner &, rose_addr_t anchor)=0
Attempt to match padding.
const Partitioner & partitioner
Partitioner requesting basic block successors.
void maxInstructions(size_t maxInsns)
Property: Maximum size of block.
Prevent discontiguous basic blocks.
virtual std::vector< Function::Ptr > functions() const =0
Returns the function(s) for the previous successful match.
AddressIntervalSet deExecuteZeros(const MemoryMap::Ptr &map, size_t threshold, size_t leaveAtFront=16, size_t leaveAtBack=1)
Remove execute permissions for zeros.
const std::vector< AddressPair > & rewrites() const
Property: Pairs of old/new addresses to rewrite.
SgAsmBlock * buildGlobalBlockAst(const Partitioner &, const AstConstructionSettings &)
Builds the global block AST.
virtual bool operator()(bool chain, const Args &args) override
Callback method.
Callback to rewrite CFG edges.
BasicBlock::Ptr bblock
Basic block whose successors are to be computed.
Sawyer::SharedPointer< FunctionPaddingMatcher > Ptr
Shared-ownership pointer to a FunctionPaddingMatcher.
Produce a GraphViz file for the CFG at a certain time.
Base class for reference counted objects.
Arguments for detaching a basic block.
Make previous instruction the final instruction of the block.
void labelSymbolAddresses(Partitioner &, SgAsmGenericHeader *)
Give labels to addresses that are symbols.
Sawyer::SharedPointer< FunctionPrologueMatcher > Ptr
Shared-ownership pointer to a FunctionPrologueMatcher.
virtual bool operator()(bool chain, const Args &) override
Callback method.
virtual bool operator()(bool chain, const AttachedBasicBlock &args) override
Called when basic block is attached or placeholder inserted.
Arguments passed to the callback.
Sawyer::SharedPointer< InstructionMatcher > Ptr
Shared-ownership pointer to an InstructionMatcher.
Sawyer::SharedPointer< BasicBlockCallback > Ptr
Shared-ownership pointer to a BasicBlockCallback.
Follow basic block ghost edges.
void nameStrings(const Partitioner &, const AddressInterval &)
Give labels to string constants.
virtual std::vector< Function::Ptr > functions() const override
Returns the function(s) for the previous successful match.
Partitions instructions into basic blocks and functions.
virtual bool match(const Partitioner &, rose_addr_t anchor) override
Attempt to match an instruction pattern.
void predicates(const ThunkPredicates::Ptr &p)
Property: Predicates used for matching thunks.
Represents an interpretation of a binary container.
Results & results
Results to control basic block discovery.
void fixupAstCallingConventions(const Partitioner &, SgNode *ast)
Fixes calling convention results.
virtual bool operator()(bool chain, const DetachedBasicBlock &) override
Called when basic block is detached or placeholder erased.
boost::logic::tribool isStackBasedReturn(const Partitioner &, const BasicBlock::Ptr &)
Determine if basic block is a stack-based function return.
std::vector< Function::Ptr > findNoopFunctions(const Partitioner &)
Find functions that are no-ops.
Sawyer::SharedPointer< IpRewriter > Ptr
Shared-ownership pointer to a IpRewriter.