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/InstructionSemantics/BaseSemantics.h>
22 namespace BinaryAnalysis {
24 namespace Disassembler {
273 typedef boost::graph_traits<CFG>::vertex_descriptor CFG_Vertex;
274 typedef std::map<SgAsmBlock*, CFG_Vertex> CFG_BlockMap;
276 typedef boost::graph_traits<CG>::vertex_descriptor CG_Vertex;
277 typedef std::map<SgAsmFunction*, CG_Vertex> CG_FunctionMap;
284 : unparser(unparser), output(output) {}
292 :
GeneralArgs(unparser, output), insn(insn), position_in_block(position_in_block) {}
301 const std::vector<SgAsmInstruction*> &insns)
302 :
GeneralArgs(unparser, output), block(block), insns(insns) {}
305 const std::vector<SgAsmInstruction*> &
insns;
311 :
GeneralArgs(unparser, output), data(data), position_in_block(position_in_block) {}
320 const std::vector<SgAsmStaticData*> &datalist)
321 :
GeneralArgs(unparser, output), block(block), datalist(datalist) {}
374 virtual bool operator()(
bool enabled,
const InsnArgs &args);
383 virtual bool operator()(
bool enabled,
const InsnArgs &args);
390 virtual bool operator()(
bool enabled,
const InsnArgs &args);
396 virtual bool operator()(
bool enabled,
const InsnArgs &args);
409 virtual bool operator()(
bool enabled,
const InsnArgs &args);
421 virtual bool operator()(
bool enabled,
const InsnArgs &args);
427 virtual bool operator()(
bool enabled,
const InsnArgs &args);
433 virtual bool operator()(
bool enabled,
const InsnArgs &args);
440 virtual bool operator()(
bool enabled,
const InsnArgs &args);
446 virtual bool operator()(
bool enabled,
const InsnArgs &args);
452 virtual bool operator()(
bool enabled,
const InsnArgs &args);
460 virtual bool operator()(
bool enabled,
const InsnArgs &args);
470 virtual bool operator()(
bool enabled,
const BasicBlockArgs &args);
477 virtual bool operator()(
bool enabled,
const BasicBlockArgs &args);
485 virtual bool operator()(
bool enabled,
const BasicBlockArgs &args);
491 virtual bool operator()(
bool enabled,
const BasicBlockArgs &args);
498 virtual bool operator()(
bool enabled,
const BasicBlockArgs &args);
504 virtual bool operator()(
bool enabled,
const BasicBlockArgs &args);
513 virtual bool operator()(
bool enabled,
const BasicBlockArgs &args);
519 virtual bool operator()(
bool enabled,
const BasicBlockArgs &args);
526 virtual bool operator()(
bool enabled,
const BasicBlockArgs &args);
539 virtual bool operator()(
bool enabled,
const StaticDataArgs &args);
548 virtual bool operator()(
bool enabled,
const StaticDataArgs &args);
566 virtual bool operator()(
bool enabled,
const StaticDataArgs &args);
578 virtual bool operator()(
bool enabled,
const StaticDataArgs &args);
584 virtual bool operator()(
bool enabled,
const StaticDataArgs &args);
590 virtual bool operator()(
bool enabled,
const StaticDataArgs &args);
596 virtual bool operator()(
bool enabled,
const StaticDataArgs &args);
617 bool unparser_allocated_here =
false;
620 virtual void reset();
622 virtual bool operator()(
bool enabled,
const StaticDataArgs &args);
630 virtual bool operator()(
bool enabled,
const StaticDataArgs &args);
640 virtual bool operator()(
bool enabled,
const StaticDataArgs &args);
646 virtual bool operator()(
bool enabled,
const DataBlockArgs &args);
652 virtual bool operator()(
bool enabled,
const DataBlockArgs &args);
662 virtual bool operator()(
bool enabled,
const FunctionArgs &args);
668 virtual bool operator()(
bool enabled,
const FunctionArgs &args);
674 virtual bool operator()(
bool enabled,
const FunctionArgs &args);
680 virtual bool operator()(
bool enabled,
const FunctionArgs &args);
686 virtual bool operator()(
bool enabled,
const FunctionArgs &args);
692 virtual bool operator()(
bool enabled,
const FunctionArgs &args);
699 virtual bool operator()(
bool enabled,
const FunctionArgs &args);
706 virtual bool operator()(
bool enabled,
const FunctionArgs &args);
714 virtual bool operator()(
bool enabled,
const FunctionArgs &args);
720 virtual bool operator()(
bool enabled,
const FunctionArgs &args);
825 virtual bool is_unparsable_node(
SgNode *node);
838 virtual std::vector<SgNode*> find_unparsable_nodes(
SgNode *ast);
874 virtual size_t unparse(std::ostream&,
SgNode *ast);
879 std::string to_string(
SgNode *ast);
887 virtual bool unparse_one_node(std::ostream&,
SgNode*);
892 virtual bool unparse_insn(
bool enabled, std::ostream&,
SgAsmInstruction*,
size_t position_in_block=(
size_t)-1);
893 virtual bool unparse_basicblock(
bool enabled, std::ostream&,
SgAsmBlock*);
894 virtual bool unparse_staticdata(
bool enabled, std::ostream&,
SgAsmStaticData*,
size_t position_in_block=(
size_t)-1);
895 virtual bool unparse_datablock(
bool enabled, std::ostream&,
SgAsmBlock*);
896 virtual bool unparse_function(
bool enabled, std::ostream&,
SgAsmFunction*);
907 void add_function_labels(
SgNode *ast);
924 void start_of_object(rose_addr_t, std::ostream&);
925 void end_of_object(rose_addr_t);
946 virtual std::string line_prefix()
const;
947 virtual std::string
blank_prefix()
const {
return std::string(line_prefix().size(),
' '); }
951 static void initDiagnostics();
1004 virtual void init();
1022 SkipBack(): active(
true), triggered(
false), va(0) {}
1030 LinePrefix(): format(
"0x%08" PRIx64
": "), address(0) {}
size_t position_in_block
The index position of the instruction within the basic block, or -1 if unknown.
virtual std::string blank_prefix() const
Controls printing of line prefixes.
BlockGraph Graph
Default control flow graph.
void set_skipback_reporting(bool b=true)
Controls printing of skip/back messages during linear output.
const std::vector< SgAsmStaticData * > & datalist
The data items contained in this data block.
Functor to emit function information at entry points.
Functor to emit info about the first instruction of a block.
Functor to emit a blank line after every basic block.
List of callback functors.
bool triggered
Have we seen the first object yet? Is the 'va' member valid?
Functor to unparse the function body.
bool show_reasons
If true (the default) show block reason bits.
AsmUnparser * unparser
The object doing the unparsing, from which this callback is invoked.
Update instruction end address for skip/back reporting.
Functor to update unparser's is_noop array.
rose_addr_t va
Virtual address for previous end_of_object() call.
SgAsmInstruction * insn
The instruction being unparsed.
SgAsmBlock * block
The block of data being unparsed.
virtual void set_prefix_address(rose_addr_t va)
Controls printing of line prefixes.
CallbackLists insn_callbacks
Callbacks for instruction unparsing.
const std::vector< SgAsmInstruction * > & insns
The instructions contained in this basic block.
virtual void set_prefix_format(const std::string &format)
Controls printing of line prefixes.
Functor to print skip/back information when an instruction is entered.
Functor to emit instruction bytes.
Details for line prefixes.
Base class for machine instructions.
Disassembles static data as if it were code.
std::vector< bool > insn_is_noop
Optional information about no-op sequences.
Functor to emit the instructions that belong to a basic block.
Functor to clean up after basic block.
Functor to emit data block separation in output organized by address.
virtual bool operator()(bool enabled, const InsnArgs &args)
Default callbacks.
Update static data end address for skip/back reporting.
Arguments passed to data unparsing callbacks.
std::ostream & output
Where output should be sent.
Functor to emit function line termination.
std::string format
Printf-style format string.
void clear_skipback_reporting()
Controls printing of skip/back messages during linear output.
bool show_function
If true (the default) show entry address of function owning block.
Functor to emit basic block separation in output organized by address.
Callbacks::List< UnparserCallback > post
Callbacks invoked after 'unparse' callbacks.
Functor to print callee addresses.
Represents a synthesized function.
Main namespace for the ROSE library.
Arguments passed to data block unparsing callbacks.
Rose::BinaryAnalysis::ControlFlow::Graph CFG
Control Flow Graph type.
size_t position_in_block
The index position of the data within the data block, or -1 if unknown.
CallbackLists basicblock_callbacks
Callbacks for basic block unparsing.
CallbackLists interp_callbacks
Callbacks for interpretation unparsing.
rose_addr_t address
Address to use when generating a prefix string.
virtual bool operator()(bool, const StaticDataArgs &)
Default callbacks.
void reset_skipback()
Controls printing of skip/back messages during linear output.
Unparses binary AST into text.
bool show_reasons
If true (the default) show block reason bits.
virtual rose_addr_t get_prefix_address() const
Controls printing of line prefixes.
Functor to emit instruction address.
bool debug
If set, then emit information about the no-op subsequences.
Functor to emit function entry address.
virtual bool operator()(bool, const InterpretationArgs &)
Default callbacks.
LabelMap labels
This map is consulted whenever a constant is encountered.
Functor to print skip/back information when a static data block is entered.
Organization organization
How output will be organized.
CallbackLists function_callbacks
Callbacks for function unparsing.
Arguments passed to interpretation unparsing callbacks.
SgAsmInterpretation * get_node() const
Return the node being unparsed.
SgAsmStaticData * get_node() const
Return the node being unparsed.
Functor to emit a warning if the block contains any no-effect sequences.
SgAsmInstruction * get_node() const
Return the node being unparsed.
boost::adjacency_list< boost::setS, boost::vecS, boost::bidirectionalS, boost::property< boost::vertex_name_t, SgAsmFunction * > > Graph
The default function call graph type.
Functor to emit the functions in an interpretation.
Functor to emit instruction line termination.
Functor to emit basic block outgoing stack delta.
Functor to emit a blank line after every data block.
CG cg
Function call graph.
This class represents the base class for all IR nodes within Sage III.
SgAsmInterpretation * interp
The interpretation being unparsed.
virtual Organization get_organization() const
Get/set how output is organized.
Functor to emit details about static data.
CFG_BlockMap cfg_blockmap
A mapping from SgAsmBlock to control flow graph vertex.
Functor to emit the bytes of the data block.
RegisterDictionaryPtr user_registers
Dictionaries used to convert register descriptors to register names.
SgAsmBlock * get_node() const
Return the node being unparsed.
Functor to emit control flow predecessor addresses.
Represents static data in an executable.
CG_FunctionMap cg_functionmap
A mapping from SgAsmFunction to call graph vertex.
Functor to emit the entire instruction.
void clear()
Clears all the callback lists.
Functor to print caller addresses.
Functor to emit interpretation name.
Details for skip/back reporting.
virtual bool operator()(bool, const InsnArgs &)
Default callbacks.
Functor to emit function separator.
SgAsmStaticData * data
The data being unparsed.
static Sawyer::Message::Facility mlog
Diagnostic messages.
Functor to emit a blank line after every data block.
std::map< uint64_t, std::string > LabelMap
Maps integers to labels.
virtual const std::string & get_prefix_format() const
Controls printing of line prefixes.
Functor to emit info about the first data node of a block.
List & clear()
Remove all callbacks from list without destroying them.
Functor to emit function reasons.
virtual bool operator()(bool, const FunctionArgs &)
Default callbacks.
Functor to emit the numeric stack delta at each instruction.
bool get_skipback_reporting() const
Controls printing of skip/back messages during linear output.
SgAsmBlock * get_node() const
Return the node being unparsed.
bool show_function
If true (the default) show entry address of function owning block.
Arguments common to all unparser callback lists.
CallbackLists datablock_callbacks
Callbacks for data block unparsing.
virtual bool operator()(bool, const DataBlockArgs &)
Default callbacks.
Functor to print some information at the beginning of a data block.
SgAsmFunction * func
The function being unparsed.
Functor to emit each data statement of the block.
virtual bool operator()(bool, const BasicBlockArgs &)
Default callbacks.
Functor to emit a note about instructions that have no effect.
SgAsmBlock * block
The basic block being unparsed.
Callbacks::List< UnparserCallback > pre
Callbacks invoked before 'unparse' callbacks.
Arguments passed to instruction unparsing callbacks.
SgAsmFunction * get_node() const
Return the node being unparsed.
virtual void set_organization(Organization organization)
Get/set how output is organized.
Represents an interpretation of a binary container.
Callbacks::List< UnparserCallback > unparse
The main unparsing callbacks.
CFG cfg
Control flow graph.
Functor to emit function attributes.
Arguments passed to function unparsing callbacks.
Functor to emit function name.
Functor to emit block successor list.
Functor to emit reasons this block is part of a function.
CallbackLists staticdata_callbacks
Callbacks for static data unparsing.
Arguments passed to basic block unparsing callbacks.