1 #ifndef ROSE_AsmUnparser_H
2 #define ROSE_AsmUnparser_H
4 #include <featureTests.h>
5 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
10 #include "BinaryControlFlow.h"
11 #include "BinaryFunctionCall.h"
12 #include "BaseSemantics2.h"
269 typedef boost::graph_traits<CFG>::vertex_descriptor CFG_Vertex;
270 typedef std::map<SgAsmBlock*, CFG_Vertex> CFG_BlockMap;
272 typedef boost::graph_traits<CG>::vertex_descriptor CG_Vertex;
273 typedef std::map<SgAsmFunction*, CG_Vertex> CG_FunctionMap;
280 : unparser(unparser), output(output) {}
288 :
GeneralArgs(unparser, output), insn(insn), position_in_block(position_in_block) {}
297 const std::vector<SgAsmInstruction*> &insns)
298 :
GeneralArgs(unparser, output), block(block), insns(insns) {}
301 const std::vector<SgAsmInstruction*> &
insns;
307 :
GeneralArgs(unparser, output), data(data), position_in_block(position_in_block) {}
316 const std::vector<SgAsmStaticData*> &datalist)
317 :
GeneralArgs(unparser, output), block(block), datalist(datalist) {}
370 virtual bool operator()(
bool enabled,
const InsnArgs &args);
379 virtual bool operator()(
bool enabled,
const InsnArgs &args);
386 virtual bool operator()(
bool enabled,
const InsnArgs &args);
392 virtual bool operator()(
bool enabled,
const InsnArgs &args);
405 virtual bool operator()(
bool enabled,
const InsnArgs &args);
417 virtual bool operator()(
bool enabled,
const InsnArgs &args);
423 virtual bool operator()(
bool enabled,
const InsnArgs &args);
429 virtual bool operator()(
bool enabled,
const InsnArgs &args);
436 virtual bool operator()(
bool enabled,
const InsnArgs &args);
442 virtual bool operator()(
bool enabled,
const InsnArgs &args);
448 virtual bool operator()(
bool enabled,
const InsnArgs &args);
456 virtual bool operator()(
bool enabled,
const InsnArgs &args);
466 virtual bool operator()(
bool enabled,
const BasicBlockArgs &args);
473 virtual bool operator()(
bool enabled,
const BasicBlockArgs &args);
481 virtual bool operator()(
bool enabled,
const BasicBlockArgs &args);
487 virtual bool operator()(
bool enabled,
const BasicBlockArgs &args);
494 virtual bool operator()(
bool enabled,
const BasicBlockArgs &args);
500 virtual bool operator()(
bool enabled,
const BasicBlockArgs &args);
509 virtual bool operator()(
bool enabled,
const BasicBlockArgs &args);
515 virtual bool operator()(
bool enabled,
const BasicBlockArgs &args);
522 virtual bool operator()(
bool enabled,
const BasicBlockArgs &args);
535 virtual bool operator()(
bool enabled,
const StaticDataArgs &args);
544 virtual bool operator()(
bool enabled,
const StaticDataArgs &args);
562 virtual bool operator()(
bool enabled,
const StaticDataArgs &args);
574 virtual bool operator()(
bool enabled,
const StaticDataArgs &args);
580 virtual bool operator()(
bool enabled,
const StaticDataArgs &args);
586 virtual bool operator()(
bool enabled,
const StaticDataArgs &args);
592 virtual bool operator()(
bool enabled,
const StaticDataArgs &args);
613 bool unparser_allocated_here;
615 ~StaticDataDisassembler() { reset(); }
616 virtual void reset();
617 virtual void init(Disassembler *disassembler, AsmUnparser *unparser=NULL);
618 virtual bool operator()(
bool enabled,
const StaticDataArgs &args);
626 virtual bool operator()(
bool enabled,
const StaticDataArgs &args);
636 virtual bool operator()(
bool enabled,
const StaticDataArgs &args);
642 virtual bool operator()(
bool enabled,
const DataBlockArgs &args);
648 virtual bool operator()(
bool enabled,
const DataBlockArgs &args);
658 virtual bool operator()(
bool enabled,
const FunctionArgs &args);
664 virtual bool operator()(
bool enabled,
const FunctionArgs &args);
670 virtual bool operator()(
bool enabled,
const FunctionArgs &args);
676 virtual bool operator()(
bool enabled,
const FunctionArgs &args);
682 virtual bool operator()(
bool enabled,
const FunctionArgs &args);
688 virtual bool operator()(
bool enabled,
const FunctionArgs &args);
695 virtual bool operator()(
bool enabled,
const FunctionArgs &args);
702 virtual bool operator()(
bool enabled,
const FunctionArgs &args);
710 virtual bool operator()(
bool enabled,
const FunctionArgs &args);
716 virtual bool operator()(
bool enabled,
const FunctionArgs &args);
824 virtual bool is_unparsable_node(
SgNode *node);
837 virtual std::vector<SgNode*> find_unparsable_nodes(
SgNode *ast);
873 virtual size_t unparse(std::ostream&,
SgNode *ast);
878 std::string to_string(
SgNode *ast);
886 virtual bool unparse_one_node(std::ostream&,
SgNode*);
891 virtual bool unparse_insn(
bool enabled, std::ostream&,
SgAsmInstruction*,
size_t position_in_block=(
size_t)-1);
892 virtual bool unparse_basicblock(
bool enabled, std::ostream&,
SgAsmBlock*);
893 virtual bool unparse_staticdata(
bool enabled, std::ostream&,
SgAsmStaticData*,
size_t position_in_block=(
size_t)-1);
894 virtual bool unparse_datablock(
bool enabled, std::ostream&,
SgAsmBlock*);
895 virtual bool unparse_function(
bool enabled, std::ostream&,
SgAsmFunction*);
906 void add_function_labels(
SgNode *ast);
923 void start_of_object(rose_addr_t, std::ostream&);
924 void end_of_object(rose_addr_t);
945 virtual std::string line_prefix()
const;
946 virtual std::string
blank_prefix()
const {
return std::string(line_prefix().size(),
' '); }
955 static void initDiagnostics();
1008 virtual void init();
1026 SkipBack(): active(
true), triggered(
false), va(0) {}
1034 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.
Describes (part of) a physical CPU register.
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.
virtual void set_registers(const RegisterDictionary *registers)
Register dictionaries.
Functor to emit the bytes of the data block.
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.
const RegisterDictionary * user_registers
Dictionaries used to convert register descriptors to register names.
AsmUnparser()
Constructor that intializes the "unparser" callback lists with some useful functors.
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.
Defines registers available for a particular architecture.
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.
Virtual base class for instruction disassemblers.
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.