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>
14 namespace BinaryAnalysis {
15 namespace Partitioner2 {
125 virtual std::vector<FunctionPtr>
functions()
const = 0;
210 : maxInsns_(maxInsns) {}
230 virtual bool operator()(
bool chain,
const Args&)
override;
243 std::vector<AddressPair> rewrites_;
247 : rewrites_(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; }
266 virtual bool operator()(
bool chain,
const Args&)
override;
287 static Ptr instance(
const std::string &config);
288 static Ptr instance(
const std::vector<std::string> &args);
290 static std::string docString();
291 virtual bool operator()(
bool chain,
const AttachedBasicBlock &args)
override;
305 std::string fileName;
315 static Ptr instance(
const std::string &config);
316 static Ptr instance(
const std::vector<std::string> &args);
318 static std::string docString();
319 virtual bool operator()(
bool chain,
const AttachedBasicBlock &args)
override;
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);
345 static std::string docString();
346 virtual bool operator()(
bool chain,
const AttachedBasicBlock &args)
override;
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);
369 static std::string docString();
370 virtual bool operator()(
bool chain,
const AttachedBasicBlock &args)
override;
383 std::vector<FunctionPtr> functions_;
402 virtual std::vector<FunctionPtr>
functions()
const override;
421 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.
void nameConstants(const PartitionerConstPtr &, const AddressInterval &)
Gives names to constants in instructions.
List some instructions at a certain time.
std::vector< FunctionPtr > findSymbolFunctions(const PartitionerConstPtr &, SgAsmGenericHeader *)
Finds functions for which symbols exist.
Base class for matching function padding.
Base class for CFG-adjustment callbacks.
Base class for adjusting basic blocks during discovery.
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.
virtual bool match(const PartitionerConstPtr &, rose_addr_t anchor)=0
Attempt to match an instruction pattern.
Base class for matching function prologues.
static Ptr instance(size_t maxInsns)
Constructor.
PartitionerConstPtr partitioner
Partitioner requesting basic block successors.
virtual bool operator()(bool chain, const Args &) override
Callback method.
virtual std::vector< FunctionPtr > functions() const override
Returns the function(s) for the previous successful match.
std::string canonicalFunctionName(const std::string &)
Convert system function names to ROSE canonical form.
AddressIntervalSet deExecuteZeros(const MemoryMapPtr &map, size_t threshold, size_t leaveAtFront=16, size_t leaveAtBack=1)
Remove execute permissions for zeros.
Sawyer::SharedPointer< BasicBlockCallback > BasicBlockCallbackPtr
Shared ownership pointer.
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.
static Ptr instance(const ThunkPredicatesPtr &)
Allocating constructor.
virtual bool match(const PartitionerConstPtr &, rose_addr_t anchor) override
Attempt to match an instruction pattern.
A collection of related switch declarations.
Represents a synthesized function.
void rewrites(std::vector< AddressPair > &v)
Property: Pairs of old/new addresses to rewrite.
Results coordinated across all callbacks.
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.
Main namespace for the ROSE library.
Settings that control building the AST.
void fixupAstCallingConventions(const PartitionerConstPtr &, SgNode *ast)
Fixes calling convention results.
Base class for matching an instruction pattern.
static AstConstructionSettings strict()
Default strict settings.
Sawyer::SharedPointer< CfgAdjustmentCallback > Ptr
Shared ownership pointer.
Make current instruction the final instruction of the block.
Reference-counting intrusive smart pointer.
Do not explicitly terminate block here.
SgAsmFunction * buildFunctionAst(const PartitionerConstPtr &, const FunctionPtr &, const AstConstructionSettings &)
Build AST for function.
SgAsmBlock * buildDataBlockAst(const PartitionerConstPtr &, const DataBlockPtr &, const AstConstructionSettings &)
Build AST for data block.
virtual bool operator()(bool chain, const DetachedBasicBlock &) override
Called when basic block is detached or placeholder erased.
SgAsmBlock * buildAst(const PartitionerConstPtr &, SgAsmInterpretation *interp=NULL, const AstConstructionSettings &settings=AstConstructionSettings::strict())
Builds an AST from the CFG.
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.
boost::logic::tribool isStackBasedReturn(const PartitionerConstPtr &, const BasicBlockPtr &)
Determine if basic block is a stack-based function return.
virtual bool operator()(bool chain, const Args &)=0
Callback method.
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.
void nameStrings(const PartitionerConstPtr &, const AddressInterval &)
Give labels to string constants.
This class represents the base class for all IR nodes within Sage III.
static Interval whole()
Construct an interval that covers the entire domain.
void maxInstructions(size_t maxInsns)
Property: Maximum size of block.
Prevent discontiguous basic blocks.
std::vector< FunctionPtr > findNoopFunctions(const PartitionerConstPtr &)
Find functions that are no-ops.
const std::vector< AddressPair > & rewrites() const
Property: Pairs of old/new addresses to rewrite.
virtual bool operator()(bool chain, const Args &args) override
Callback method.
Callback to rewrite CFG edges.
virtual std::vector< FunctionPtr > functions() const =0
Returns the function(s) for the previous successful match.
Sawyer::SharedPointer< FunctionPaddingMatcher > FunctionPaddingMatcherPtr
Shared ownership pointer.
void nameNoopFunctions(const PartitionerConstPtr &)
Give names to functions that are no-ops.
Sawyer::SharedPointer< FunctionPrologueMatcher > FunctionPrologueMatcherPtr
Shared ownership pointer.
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.
SgAsmBlock * buildBasicBlockAst(const PartitionerConstPtr &, const BasicBlockPtr &, const FunctionPtr &, const AstConstructionSettings &)
Build AST for basic block.
virtual bool operator()(bool chain, const Args &) override
Callback method.
SgAsmBlock * buildGlobalBlockAst(const PartitionerConstPtr &, const AstConstructionSettings &)
Builds the global block AST.
virtual bool operator()(bool chain, const AttachedBasicBlock &args) override
Called when basic block is attached or placeholder inserted.
Arguments passed to the callback.
void labelSymbolAddresses(const PartitionerPtr &, SgAsmGenericHeader *)
Give labels to addresses that are symbols.
Sawyer::SharedPointer< InstructionMatcher > Ptr
Shared-ownership pointer to an InstructionMatcher.
ThunkPredicatesPtr predicates() const
Property: Predicates used for matching thunks.
virtual rose_addr_t match(const PartitionerConstPtr &, rose_addr_t anchor)=0
Attempt to match padding.
Follow basic block ghost edges.
BasicBlockPtr bblock
Basic block whose successors are to be computed.
BasicBlockCallbackPtr Ptr
Shared-ownership pointer to a BasicBlockCallback.
Represents an interpretation of a binary container.
Results & results
Results to control basic block discovery.
virtual bool operator()(bool chain, const DetachedBasicBlock &) override
Called when basic block is detached or placeholder erased.
void demangleFunctionNames(const PartitionerConstPtr &)
Demangle all function names.
Sawyer::SharedPointer< IpRewriter > Ptr
Shared-ownership pointer to a IpRewriter.