1#ifndef ROSE_AsmUnparser_H
2#define ROSE_AsmUnparser_H
4#include <featureTests.h>
5#ifdef ROSE_ENABLE_BINARY_ANALYSIS
10#include <Rose/BinaryAnalysis/BasicTypes.h>
11#include <Rose/BinaryAnalysis/ControlFlow.h>
12#include <Rose/BinaryAnalysis/Disassembler/BasicTypes.h>
13#include <Rose/BinaryAnalysis/FunctionCall.h>
14#include <Rose/BinaryAnalysis/Hexdump.h>
15#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics.h>
23namespace BinaryAnalysis {
25namespace Disassembler {
274 typedef boost::graph_traits<CFG>::vertex_descriptor CFG_Vertex;
275 typedef std::map<SgAsmBlock*, CFG_Vertex> CFG_BlockMap;
277 typedef boost::graph_traits<CG>::vertex_descriptor CG_Vertex;
278 typedef std::map<SgAsmFunction*, CG_Vertex> CG_FunctionMap;
285 : unparser(unparser), output(output) {}
293 :
GeneralArgs(unparser, output), insn(insn), position_in_block(position_in_block) {}
302 const std::vector<SgAsmInstruction*> &insns)
303 :
GeneralArgs(unparser, output), block(block), insns(insns) {}
306 const std::vector<SgAsmInstruction*> &
insns;
312 :
GeneralArgs(unparser, output), data(data), position_in_block(position_in_block) {}
321 const std::vector<SgAsmStaticData*> &datalist)
322 :
GeneralArgs(unparser, output), block(block), datalist(datalist) {}
618 bool unparser_allocated_here =
false;
621 virtual void reset();
948 virtual std::string
blank_prefix()
const {
return std::string(line_prefix().size(),
' '); }
1023 SkipBack(): active(
true), triggered(
false), va(0) {}
1031 LinePrefix(): format(
"0x%08" PRIx64
": "), address(0) {}
Functor to emit the instructions that belong to a basic block.
virtual bool operator()(bool enabled, const BasicBlockArgs &args)
Default callbacks.
Functor to clean up after basic block.
virtual bool operator()(bool enabled, const BasicBlockArgs &args)
Default callbacks.
Functor to emit a blank line after every basic block.
virtual bool operator()(bool enabled, const BasicBlockArgs &args)
Default callbacks.
Functor to update unparser's is_noop array.
virtual bool operator()(bool enabled, const BasicBlockArgs &args)
Default callbacks.
bool debug
If set, then emit information about the no-op subsequences.
Functor to emit a warning if the block contains any no-effect sequences.
virtual bool operator()(bool enabled, const BasicBlockArgs &args)
Default callbacks.
Functor to emit basic block outgoing stack delta.
virtual bool operator()(bool enabled, const BasicBlockArgs &args)
Default callbacks.
Functor to emit control flow predecessor addresses.
virtual bool operator()(bool enabled, const BasicBlockArgs &args)
Default callbacks.
Functor to emit reasons this block is part of a function.
virtual bool operator()(bool enabled, const BasicBlockArgs &args)
Default callbacks.
Functor to emit block successor list.
virtual bool operator()(bool enabled, const BasicBlockArgs &args)
Default callbacks.
Functor to emit each data statement of the block.
virtual bool operator()(bool enabled, const DataBlockArgs &args)
Default callbacks.
Functor to emit a blank line after every data block.
virtual bool operator()(bool enabled, const DataBlockArgs &args)
Default callbacks.
Functor to print some information at the beginning of a data block.
virtual bool operator()(bool enabled, const StaticDataArgs &args)
Default callbacks.
Functor to emit function attributes.
virtual bool operator()(bool enabled, const FunctionArgs &args)
Default callbacks.
Functor to unparse the function body.
virtual bool operator()(bool enabled, const FunctionArgs &args)
Default callbacks.
Functor to emit function entry address.
virtual bool operator()(bool enabled, const FunctionArgs &args)
Default callbacks.
Functor to emit function line termination.
virtual bool operator()(bool enabled, const FunctionArgs &args)
Default callbacks.
Functor to emit function name.
virtual bool operator()(bool enabled, const FunctionArgs &args)
Default callbacks.
Functor to print caller addresses.
virtual bool operator()(bool enabled, const FunctionArgs &args)
Default callbacks.
Functor to emit function reasons.
virtual bool operator()(bool enabled, const FunctionArgs &args)
Default callbacks.
Functor to emit function separator.
virtual bool operator()(bool enabled, const FunctionArgs &args)
Default callbacks.
Functor to print callee addresses.
virtual bool operator()(bool enabled, const FunctionArgs &args)
Default callbacks.
Functor to emit instruction address.
virtual bool operator()(bool enabled, const InsnArgs &args)
Default callbacks.
Functor to emit info about the first instruction of a block.
virtual bool operator()(bool enabled, const InsnArgs &args)
Default callbacks.
bool show_function
If true (the default) show entry address of function owning block.
bool show_reasons
If true (the default) show block reason bits.
Functor to emit basic block separation in output organized by address.
virtual bool operator()(bool enabled, const InsnArgs &args)
Default callbacks.
Functor to emit the entire instruction.
virtual bool operator()(bool enabled, const InsnArgs &args)
Default callbacks.
Functor to emit function information at entry points.
virtual bool operator()(bool enabled, const InsnArgs &args)
Default callbacks.
Functor to emit instruction line termination.
virtual bool operator()(bool enabled, const InsnArgs &args)
Default callbacks.
Functor to emit a note about instructions that have no effect.
virtual bool operator()(bool enabled, const InsnArgs &args)
Default callbacks.
Functor to emit instruction bytes.
virtual bool operator()(bool enabled, const InsnArgs &args)
Default callbacks.
Functor to print skip/back information when an instruction is entered.
virtual bool operator()(bool enabled, const InsnArgs &args)
Default callbacks.
Update instruction end address for skip/back reporting.
virtual bool operator()(bool enabled, const InsnArgs &args)
Default callbacks.
Functor to emit the numeric stack delta at each instruction.
virtual bool operator()(bool enabled, const InsnArgs &args)
Default callbacks.
Functor to emit the functions in an interpretation.
virtual bool operator()(bool enabled, const InterpretationArgs &args)
Default callbacks.
Functor to emit interpretation name.
virtual bool operator()(bool enabled, const InterpretationArgs &args)
Default callbacks.
Functor to emit info about the first data node of a block.
bool show_reasons
If true (the default) show block reason bits.
bool show_function
If true (the default) show entry address of function owning block.
virtual bool operator()(bool enabled, const StaticDataArgs &args)
Default callbacks.
Functor to emit data block separation in output organized by address.
virtual bool operator()(bool enabled, const StaticDataArgs &args)
Default callbacks.
Functor to emit details about static data.
virtual bool operator()(bool enabled, const StaticDataArgs &args)
Default callbacks.
virtual bool operator()(bool enabled, const InsnArgs &args)
Default callbacks.
Disassembles static data as if it were code.
virtual bool operator()(bool enabled, const StaticDataArgs &args)
Default callbacks.
Functor to emit a blank line after every data block.
virtual bool operator()(bool enabled, const StaticDataArgs &args)
Default callbacks.
Functor to emit the bytes of the data block.
virtual bool operator()(bool enabled, const StaticDataArgs &args)
Default callbacks.
Functor to print skip/back information when a static data block is entered.
virtual bool operator()(bool enabled, const StaticDataArgs &args)
Default callbacks.
Update static data end address for skip/back reporting.
virtual bool operator()(bool enabled, const StaticDataArgs &args)
Default callbacks.
virtual bool operator()(bool, const BasicBlockArgs &)
Default callbacks.
virtual bool operator()(bool, const InsnArgs &)
Default callbacks.
virtual bool operator()(bool, const InterpretationArgs &)
Default callbacks.
virtual bool operator()(bool, const StaticDataArgs &)
Default callbacks.
virtual bool operator()(bool, const DataBlockArgs &)
Default callbacks.
virtual bool operator()(bool, const FunctionArgs &)
Default callbacks.
Unparses binary AST into text.
virtual rose_addr_t get_prefix_address() const
Controls printing of line prefixes.
CallbackLists insn_callbacks
Callbacks for instruction unparsing.
CallbackLists function_callbacks
Callbacks for function unparsing.
virtual void set_organization(Organization organization)
Get/set how output is organized.
virtual bool unparse_interpretation(bool enabled, std::ostream &, SgAsmInterpretation *)
Unparse an object.
virtual SgNode * find_unparsable_node(SgNode *ast)
Finds first unparsable node.
Organization organization
How output will be organized.
void reset_skipback()
Controls printing of skip/back messages during linear output.
virtual void set_prefix_format(const std::string &format)
Controls printing of line prefixes.
AsmUnparser()
Constructor that intializes the "unparser" callback lists with some useful functors.
void clear_skipback_reporting()
Controls printing of skip/back messages during linear output.
CG_FunctionMap cg_functionmap
A mapping from SgAsmFunction to call graph vertex.
CG cg
Function call graph.
Rose::BinaryAnalysis::ControlFlow::Graph CFG
Control Flow Graph type.
virtual bool unparse_insn(bool enabled, std::ostream &, SgAsmInstruction *, size_t position_in_block=(size_t) -1)
Unparse an object.
void end_of_object(rose_addr_t)
Controls printing of skip/back messages during linear output.
LabelMap labels
This map is consulted whenever a constant is encountered.
void add_control_flow_graph(const Rose::BinaryAnalysis::ControlFlow::Graph &cfg)
Associates a control flow graph with this unparser.
void add_function_labels(SgNode *ast)
Adds function labels to the label map.
virtual bool unparse_datablock(bool enabled, std::ostream &, SgAsmBlock *)
Unparse an object.
virtual std::vector< SgNode * > find_unparsable_nodes(SgNode *ast)
Finds top unparsable nodes.
virtual bool unparse_one_node(std::ostream &, SgNode *)
Unparse a single node if possible.
std::vector< bool > insn_is_noop
Optional information about no-op sequences.
virtual size_t unparse(std::ostream &, SgNode *ast)
Unparse part of the AST.
std::string to_string(SgNode *ast)
Unparse part of the AST into a string.
virtual void set_registers(const RegisterDictionaryPtr ®isters)
Register dictionaries.
void set_skipback_reporting(bool b=true)
Controls printing of skip/back messages during linear output.
virtual Organization get_organization() const
Get/set how output is organized.
virtual bool unparse_function(bool enabled, std::ostream &, SgAsmFunction *)
Unparse an object.
void start_of_object(rose_addr_t, std::ostream &)
Controls printing of skip/back messages during linear output.
CallbackLists datablock_callbacks
Callbacks for data block unparsing.
static Sawyer::Message::Facility mlog
Diagnostic messages.
virtual void init()
Initializes the callback lists.
bool get_skipback_reporting() const
Controls printing of skip/back messages during linear output.
virtual void set_prefix_address(rose_addr_t va)
Controls printing of line prefixes.
std::map< uint64_t, std::string > LabelMap
Maps integers to labels.
CFG cfg
Control flow graph.
virtual RegisterDictionaryPtr get_registers() const
Register dictionaries.
static void initDiagnostics()
Initialize diagnostic messages subsystem.
CFG_BlockMap cfg_blockmap
A mapping from SgAsmBlock to control flow graph vertex.
RegisterDictionaryPtr user_registers
Dictionaries used to convert register descriptors to register names.
CallbackLists staticdata_callbacks
Callbacks for static data unparsing.
virtual const std::string & get_prefix_format() const
Controls printing of line prefixes.
CallbackLists basicblock_callbacks
Callbacks for basic block unparsing.
virtual std::string line_prefix() const
Controls printing of line prefixes.
CallbackLists interp_callbacks
Callbacks for interpretation unparsing.
virtual bool unparse_staticdata(bool enabled, std::ostream &, SgAsmStaticData *, size_t position_in_block=(size_t) -1)
Unparse an object.
virtual std::string blank_prefix() const
Controls printing of line prefixes.
virtual bool unparse_basicblock(bool enabled, std::ostream &, SgAsmBlock *)
Unparse an object.
virtual bool is_unparsable_node(SgNode *node)
Determines if a node can be unparsed.
BlockGraph Graph
Default control flow graph.
boost::adjacency_list< boost::setS, boost::vecS, boost::bidirectionalS, boost::property< boost::vertex_name_t, SgAsmFunction * > > Graph
The default function call graph type.
List of callback functors.
List & clear()
Remove all callbacks from list without destroying them.
Represents a synthesized function.
Base class for machine instructions.
Represents an interpretation of a binary container.
Represents static data in an executable.
This class represents the base class for all IR nodes within Sage III.
Callbacks::List< UnparserCallback > unparse
The main unparsing callbacks.
void clear()
Clears all the callback lists.
Callbacks::List< UnparserCallback > pre
Callbacks invoked before 'unparse' callbacks.
Callbacks::List< UnparserCallback > post
Callbacks invoked after 'unparse' callbacks.
Details for line prefixes.
std::string format
Printf-style format string.
rose_addr_t address
Address to use when generating a prefix string.
Details for skip/back reporting.
bool triggered
Have we seen the first object yet? Is the 'va' member valid?
rose_addr_t va
Virtual address for previous end_of_object() call.
Arguments passed to basic block unparsing callbacks.
SgAsmBlock * block
The basic block being unparsed.
const std::vector< SgAsmInstruction * > & insns
The instructions contained in this basic block.
SgAsmBlock * get_node() const
Return the node being unparsed.
Arguments passed to data block unparsing callbacks.
SgAsmBlock * block
The block of data being unparsed.
SgAsmBlock * get_node() const
Return the node being unparsed.
const std::vector< SgAsmStaticData * > & datalist
The data items contained in this data block.
Arguments passed to function unparsing callbacks.
SgAsmFunction * func
The function being unparsed.
SgAsmFunction * get_node() const
Return the node being unparsed.
Arguments common to all unparser callback lists.
AsmUnparser * unparser
The object doing the unparsing, from which this callback is invoked.
std::ostream & output
Where output should be sent.
Arguments passed to instruction unparsing callbacks.
size_t position_in_block
The index position of the instruction within the basic block, or -1 if unknown.
SgAsmInstruction * get_node() const
Return the node being unparsed.
SgAsmInstruction * insn
The instruction being unparsed.
Arguments passed to interpretation unparsing callbacks.
SgAsmInterpretation * interp
The interpretation being unparsed.
SgAsmInterpretation * get_node() const
Return the node being unparsed.
Arguments passed to data unparsing callbacks.
SgAsmStaticData * get_node() const
Return the node being unparsed.
SgAsmStaticData * data
The data being unparsed.
size_t position_in_block
The index position of the data within the data block, or -1 if unknown.