decompiler  1.0.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Attributes | List of all members
PrintLanguage Class Referenceabstract

The base class API for emitting a high-level language. More...

#include <printlanguage.hh>

Inheritance diagram for PrintLanguage:
PrintC PrintJava

Classes

struct  Atom
 A single non-operator token emitted by the decompiler. More...
 
struct  NodePending
 A pending data-flow node; waiting to be placed on the reverse polish notation stack. More...
 
struct  ReversePolish
 An entry on the reverse polish notation (RPN) stack. More...
 

Public Types

enum  modifiers {
  force_hex = 1, force_dec = 2, bestfit = 4, force_scinote = 8,
  force_pointer = 0x10, print_load_value = 0x20, print_store_value = 0x40, no_branch = 0x80,
  only_branch = 0x100, comma_separate = 0x200, flat = 0x400, falsebranch = 0x800,
  nofallthru = 0x1000, negatetoken = 0x2000, hide_thisparam = 0x4000
}
 Possible context sensitive modifiers to how tokens get emitted. More...
 
enum  tagtype {
  syntax, vartoken, functoken, optoken,
  typetoken, fieldtoken, blanktoken
}
 Possible types of Atom. More...
 
enum  namespace_strategy { MINIMAL_NAMESPACES = 0, NO_NAMESPACES = 1, ALL_NAMESPACES = 2 }
 Strategies for displaying namespace tokens. More...
 

Public Member Functions

 PrintLanguage (Architecture *g, const string &nm)
 Constructor. More...
 
virtual ~PrintLanguage (void)
 Destructor.
 
const string & getName (void) const
 Get the language name.
 
CastStrategygetCastStrategy (void) const
 Get the casting strategy for the language.
 
ostream * getOutputStream (void) const
 Get the output stream being emitted to.
 
void setOutputStream (ostream *t)
 Set the output stream to emit to.
 
void setMaxLineSize (int4 mls)
 Set the maximum number of characters per line.
 
void setIndentIncrement (int4 inc)
 Set the number of characters to indent per level of code nesting.
 
void setLineCommentIndent (int4 val)
 Set the number of characters to indent comment lines. More...
 
void setCommentDelimeter (const string &start, const string &stop, bool usecommentfill)
 Establish comment delimiters for the language. More...
 
uint4 getInstructionComment (void) const
 Get the type of comments suitable within the body of a function.
 
void setInstructionComment (uint4 val)
 Set the type of comments suitable within the body of a function.
 
void setNamespaceStrategy (namespace_strategy strat)
 Set how namespace tokens are displayed.
 
uint4 getHeaderComment (void) const
 Get the type of comments suitable for a function header.
 
void setHeaderComment (uint4 val)
 Set the type of comments suitable for a function header.
 
bool emitsXml (void) const
 Does the low-level emitter, emit XML markup.
 
void setXML (bool val)
 Set whether the low-level emitter, emits XML markup. More...
 
void setFlat (bool val)
 Set whether nesting code structure should be emitted. More...
 
virtual void adjustTypeOperators (void)=0
 Set basic data-type information for p-code operators.
 
virtual void resetDefaults (void)
 Set printing options to their default value.
 
virtual void clear (void)
 Clear the RPN stack and the low-level emitter.
 
virtual void setIntegerFormat (const string &nm)
 Set the default integer format. More...
 
virtual void setCommentStyle (const string &nm)=0
 Set the way comments are displayed in decompiler output. More...
 
virtual void docTypeDefinitions (const TypeFactory *typegrp)=0
 Emit definitions of data-types. More...
 
virtual void docAllGlobals (void)=0
 Emit declarations of global variables.
 
virtual void docSingleGlobal (const Symbol *sym)=0
 Emit the declaration for a single (global) Symbol. More...
 
virtual void docFunction (const Funcdata *fd)=0
 Emit the declaration (and body) of a function. More...
 
virtual void emitBlockBasic (const BlockBasic *bb)=0
 Emit statements in a basic block.
 
virtual void emitBlockGraph (const BlockGraph *bl)=0
 Emit (an unspecified) list of blocks.
 
virtual void emitBlockCopy (const BlockCopy *bl)=0
 Emit a basic block (with any labels)
 
virtual void emitBlockGoto (const BlockGoto *bl)=0
 Emit a block ending with a goto statement.
 
virtual void emitBlockLs (const BlockList *bl)=0
 Emit a sequence of blocks.
 
virtual void emitBlockCondition (const BlockCondition *bl)=0
 Emit a conditional statement.
 
virtual void emitBlockIf (const BlockIf *bl)=0
 Emit an if/else style construct.
 
virtual void emitBlockWhileDo (const BlockWhileDo *bl)=0
 Emit a loop structure, check at top.
 
virtual void emitBlockFor (const BlockFor *bl)=0
 TODO.
 
virtual void emitBlockDoWhile (const BlockDoWhile *bl)=0
 Emit a loop structure, check at bottom.
 
virtual void emitBlockInfLoop (const BlockInfLoop *bl)=0
 Emit an infinite loop structure.
 
virtual void emitBlockSwitch (const BlockSwitch *bl)=0
 Emit a switch structure.
 
virtual void opCopy (const PcodeOp *op)=0
 Emit a COPY operator.
 
virtual void opLoad (const PcodeOp *op)=0
 Emit a LOAD operator.
 
virtual void opStore (const PcodeOp *op)=0
 Emit a STORE operator.
 
virtual void opBranch (const PcodeOp *op)=0
 Emit a BRANCH operator.
 
virtual void opCbranch (const PcodeOp *op)=0
 Emit a CBRANCH operator.
 
virtual void opBranchind (const PcodeOp *op)=0
 Emit a BRANCHIND operator.
 
virtual void opCall (const PcodeOp *op)=0
 Emit a CALL operator.
 
virtual void opCallind (const PcodeOp *op)=0
 Emit a CALLIND operator.
 
virtual void opCallother (const PcodeOp *op)=0
 Emit a CALLOTHER operator.
 
virtual void opConstructor (const PcodeOp *op, bool withNew)=0
 Emit an operator constructing an object.
 
virtual void opReturn (const PcodeOp *op)=0
 Emit a RETURN operator.
 
virtual void opIntEqual (const PcodeOp *op)=0
 Emit a INT_EQUAL operator.
 
virtual void opIntNotEqual (const PcodeOp *op)=0
 Emit a INT_NOTEQUAL operator.
 
virtual void opIntSless (const PcodeOp *op)=0
 Emit a INT_SLESS operator.
 
virtual void opIntSlessEqual (const PcodeOp *op)=0
 Emit a INT_SLESSEQUAL operator.
 
virtual void opIntLess (const PcodeOp *op)=0
 Emit a INT_LESS operator.
 
virtual void opIntLessEqual (const PcodeOp *op)=0
 Emit a INT_LESSEQUAL operator.
 
virtual void opIntZext (const PcodeOp *op, const PcodeOp *readOp)=0
 Emit a INT_ZEXT operator.
 
virtual void opIntSext (const PcodeOp *op, const PcodeOp *readOp)=0
 Emit a INT_SEXT operator.
 
virtual void opIntAdd (const PcodeOp *op)=0
 Emit a INT_ADD operator.
 
virtual void opIntSub (const PcodeOp *op)=0
 Emit a INT_SUB operator.
 
virtual void opIntCarry (const PcodeOp *op)=0
 Emit a INT_CARRY operator.
 
virtual void opIntScarry (const PcodeOp *op)=0
 Emit a INT_SCARRY operator.
 
virtual void opIntSborrow (const PcodeOp *op)=0
 Emit a INT_SBORROW operator.
 
virtual void opInt2Comp (const PcodeOp *op)=0
 Emit a INT_2COMP operator.
 
virtual void opIntNegate (const PcodeOp *op)=0
 Emit a INT_NEGATE operator.
 
virtual void opIntXor (const PcodeOp *op)=0
 Emit a INT_XOR operator.
 
virtual void opIntAnd (const PcodeOp *op)=0
 Emit a INT_AND operator.
 
virtual void opIntOr (const PcodeOp *op)=0
 Emit a INT_OR operator.
 
virtual void opIntLeft (const PcodeOp *op)=0
 Emit a INT_LEFT operator.
 
virtual void opIntRight (const PcodeOp *op)=0
 Emit a INT_RIGHT operator.
 
virtual void opIntSright (const PcodeOp *op)=0
 Emit a INT_SRIGHT operator.
 
virtual void opIntMult (const PcodeOp *op)=0
 Emit a INT_MULT operator.
 
virtual void opIntDiv (const PcodeOp *op)=0
 Emit a INT_DIV operator.
 
virtual void opIntSdiv (const PcodeOp *op)=0
 Emit a INT_SDIV operator.
 
virtual void opIntRem (const PcodeOp *op)=0
 Emit a INT_REM operator.
 
virtual void opIntSrem (const PcodeOp *op)=0
 Emit a INT_SREM operator.
 
virtual void opBoolNegate (const PcodeOp *op)=0
 Emit a BOOL_NEGATE operator.
 
virtual void opBoolXor (const PcodeOp *op)=0
 Emit a BOOL_XOR operator.
 
virtual void opBoolAnd (const PcodeOp *op)=0
 Emit a BOOL_AND operator.
 
virtual void opBoolOr (const PcodeOp *op)=0
 Emit a BOOL_OR operator.
 
virtual void opFloatEqual (const PcodeOp *op)=0
 Emit a FLOAT_EQUAL operator.
 
virtual void opFloatNotEqual (const PcodeOp *op)=0
 Emit a FLOAT_NOTEQUAL operator.
 
virtual void opFloatLess (const PcodeOp *op)=0
 Emit a FLOAT_LESS operator.
 
virtual void opFloatLessEqual (const PcodeOp *op)=0
 Emit a FLOAT_LESSEQUAL operator.
 
virtual void opFloatNan (const PcodeOp *op)=0
 Emit a FLOAT_NAN operator.
 
virtual void opFloatAdd (const PcodeOp *op)=0
 Emit a FLOAT_ADD operator.
 
virtual void opFloatDiv (const PcodeOp *op)=0
 Emit a FLOAT_DIV operator.
 
virtual void opFloatMult (const PcodeOp *op)=0
 Emit a FLOAT_MULT operator.
 
virtual void opFloatSub (const PcodeOp *op)=0
 Emit a FLOAT_SUB operator.
 
virtual void opFloatNeg (const PcodeOp *op)=0
 Emit a FLOAT_NEG operator.
 
virtual void opFloatAbs (const PcodeOp *op)=0
 Emit a FLOAT_ABS operator.
 
virtual void opFloatSqrt (const PcodeOp *op)=0
 Emit a FLOAT_SQRT operator.
 
virtual void opFloatInt2Float (const PcodeOp *op)=0
 Emit a FLOAT_INT2FLOAT operator.
 
virtual void opFloatFloat2Float (const PcodeOp *op)=0
 Emit a FLOAT_FLOAT2FLOAT operator.
 
virtual void opFloatTrunc (const PcodeOp *op)=0
 Emit a FLOAT_TRUNC operator.
 
virtual void opFloatCeil (const PcodeOp *op)=0
 Emit a FLOAT_CEIL operator.
 
virtual void opFloatFloor (const PcodeOp *op)=0
 Emit a FLOAT_FLOOR operator.
 
virtual void opFloatRound (const PcodeOp *op)=0
 Emit a FLOAT_ROUND operator.
 
virtual void opMultiequal (const PcodeOp *op)=0
 Emit a MULTIEQUAL operator.
 
virtual void opIndirect (const PcodeOp *op)=0
 Emit a INDIRECT operator.
 
virtual void opPiece (const PcodeOp *op)=0
 Emit a PIECE operator.
 
virtual void opSubpiece (const PcodeOp *op)=0
 Emit a SUBPIECE operator.
 
virtual void opCast (const PcodeOp *op)=0
 Emit a CAST operator.
 
virtual void opPtradd (const PcodeOp *op)=0
 Emit a PTRADD operator.
 
virtual void opPtrsub (const PcodeOp *op)=0
 Emit a PTRSUB operator.
 
virtual void opSegmentOp (const PcodeOp *op)=0
 Emit a SEGMENTOP operator.
 
virtual void opCpoolRefOp (const PcodeOp *op)=0
 Emit a CPOOLREF operator.
 
virtual void opNewOp (const PcodeOp *op)=0
 Emit a NEW operator.
 
virtual void opInsertOp (const PcodeOp *op)=0
 Emit an INSERT operator.
 
virtual void opExtractOp (const PcodeOp *op)=0
 Emit an EXTRACT operator.
 
virtual void opPopcountOp (const PcodeOp *op)=0
 Emit a POPCOUNT operator.
 

Static Public Member Functions

static int4 mostNaturalBase (uintb val)
 Determine the most natural base for an integer. More...
 
static void formatBinary (ostream &s, uintb val)
 Print a number in binary form. More...
 

Protected Member Functions

bool isSet (uint4 m) const
 Is the given printing modification active.
 
void pushScope (const Scope *sc)
 Push a new symbol scope.
 
void popScope (void)
 Pop to the previous symbol scope.
 
void pushMod (void)
 Push current printing modifications to the stack.
 
void popMod (void)
 Pop to the previous printing modifications.
 
void setMod (uint4 m)
 Activate the given printing modification.
 
void unsetMod (uint4 m)
 Deactivate the given printing modification.
 
void pushOp (const OpToken *tok, const PcodeOp *op)
 Push an operator token onto the RPN stack. More...
 
void pushAtom (const Atom &atom)
 Push a variable token onto the RPN stack. More...
 
void pushVnImplied (const Varnode *vn, const PcodeOp *op, uint4 m)
 Push an implied variable onto the RPN stack. More...
 
void pushVnExplicit (const Varnode *vn, const PcodeOp *op)
 Push an explicit variable onto the RPN stack. More...
 
void pushVnLHS (const Varnode *vn, const PcodeOp *op)
 Push a variable as the left-hand side of an expression. More...
 
bool parentheses (const OpToken *op2)
 Determine if the given token should be emitted in its own parenthetic expression. More...
 
void emitOp (const ReversePolish &entry)
 Send an operator token from the RPN to the emitter. More...
 
void emitAtom (const Atom &atom)
 Send an variable token from the RPN to the emitter. More...
 
bool escapeCharacterData (ostream &s, const uint1 *buf, int4 count, int4 charsize, bool bigend) const
 Emit a byte buffer to the stream as unicode characters. More...
 
void recurse (void)
 Emit from the RPN stack as much as possible. More...
 
void opBinary (const OpToken *tok, const PcodeOp *op)
 Push a binary operator onto the RPN stack. More...
 
void opUnary (const OpToken *tok, const PcodeOp *op)
 Push a unary operator onto the RPN stack. More...
 
int4 getPending (void) const
 Get the number of pending nodes yet to be put on the RPN stack.
 
void resetDefaultsInternal (void)
 Reset options to default for PrintLanguage.
 
virtual void printUnicode (ostream &s, int4 onechar) const =0
 Print a single unicode character as a character constant for the high-level language. More...
 
virtual void pushType (const Datatype *ct)=0
 Push a data-type name onto the RPN expression stack. More...
 
virtual void pushConstant (uintb val, const Datatype *ct, const Varnode *vn, const PcodeOp *op)=0
 Push a constant onto the RPN stack. More...
 
virtual bool pushEquate (uintb val, int4 sz, const EquateSymbol *sym, const Varnode *vn, const PcodeOp *op)=0
 Push a constant marked up by and EquateSymbol onto the RPN stack. More...
 
virtual void pushAnnotation (const Varnode *vn, const PcodeOp *op)=0
 Push an address which is not in the normal data-flow. More...
 
virtual void pushSymbol (const Symbol *sym, const Varnode *vn, const PcodeOp *op)=0
 Push a specific Symbol onto the RPN stack. More...
 
virtual void pushUnnamedLocation (const Address &addr, const Varnode *vn, const PcodeOp *op)=0
 Push an address as a substitute for a Symbol onto the RPN stack. More...
 
virtual void pushPartialSymbol (const Symbol *sym, int4 off, int4 sz, const Varnode *vn, const PcodeOp *op, Datatype *outtype)=0
 Push a variable that represents only part of a symbol onto the RPN stack. More...
 
virtual void pushMismatchSymbol (const Symbol *sym, int4 off, int4 sz, const Varnode *vn, const PcodeOp *op)=0
 Push an identifier for a variable that mismatches with its Symbol. More...
 
virtual void emitLineComment (int4 indent, const Comment *comm)
 Emit a comment line. More...
 
virtual void emitVarDecl (const Symbol *sym)=0
 Emit a variable declaration. More...
 
virtual void emitVarDeclStatement (const Symbol *sym)=0
 Emit a variable declaration statement. More...
 
virtual bool emitScopeVarDecls (const Scope *scope, int4 cat)=0
 Emit all the variable declarations for a given scope. More...
 
virtual void emitExpression (const PcodeOp *op)=0
 Emit a full expression. More...
 
virtual void emitFunctionDeclaration (const Funcdata *fd)=0
 Emit a function declaration. More...
 
virtual bool checkPrintNegation (const Varnode *vn)=0
 Check whether a given boolean Varnode can be printed in negated form. More...
 

Static Protected Member Functions

static bool unicodeNeedsEscape (int4 codepoint)
 Determine if the given codepoint needs to be escaped. More...
 

Protected Attributes

Architectureglb
 The Architecture owning the language emitter.
 
const Scopecurscope
 The current symbol scope.
 
CastStrategycastStrategy
 The strategy for emitting explicit case operations.
 
EmitXmlemit
 The low-level token emitter.
 
uint4 mods
 Currently active printing modifications.
 
uint4 instr_comment_type
 Type of instruction comments to display.
 
uint4 head_comment_type
 Type of header comments to display.
 
namespace_strategy namespc_strategy
 How should namespace tokens be displayed.
 

Private Attributes

string name
 The name of the high-level language.
 
vector< uint4 > modstack
 Printing modification stack.
 
vector< const Scope * > scopestack
 The symbol scope stack.
 
vector< ReversePolishrevpol
 The Reverse Polish Notation (RPN) token stack.
 
vector< NodePendingnodepend
 Data-flow nodes waiting to be pushed onto the RPN stack.
 
int4 pending
 Number of data-flow nodes waiting to be pushed.
 
int4 line_commentindent
 Number of characters a comment line should be indented.
 
string commentstart
 Delimiter characters for the start of a comment.
 
string commentend
 Delimiter characters (if any) for the end of a comment.
 

Detailed Description

The base class API for emitting a high-level language.

Instances of this object are responsible for converting a function's (transformed) data-flow graph into the final stream of tokens of a high-level source code language. There a few main entry points including:

The system is responsible for printing:

As part of all this printing, the system is also responsible for

To accomplish this, the API is broken up into three sections. The first section are the main entry point 'doc' methods. The second section are 'emit' methods, which are responsible for printing a representation of a particular high-level code construct. The third section are 'push' and 'op' methods, which are responsible for walking expression trees. The order in which tokens are emitted for an expression is determined by a Reverse Polish Notation (RPN) stack, that the 'push' methods manipulate. Operators and variables are pushed onto this stack and are ultimately emitted in the correct order.

The base class provides a generic printing modifications stack and a symbol scope stack to provide a printing context mechanism for derived classes.

Member Enumeration Documentation

Possible context sensitive modifiers to how tokens get emitted.

Enumerator
force_hex 

Force printing of hex.

force_dec 

Force printing of dec.

bestfit 

Decide on most aesthetic form.

force_scinote 

Force scientific notation for floats.

force_pointer 

Force '*' notation for pointers.

print_load_value 

Hide pointer deref for load with other ops.

print_store_value 

Hide pointer deref for store with other ops.

no_branch 

Do not print branch instruction.

only_branch 

Print only the branch instruction.

comma_separate 

Statements within condition.

flat 

Do not print block structure.

falsebranch 

Print the false branch (for flat)

nofallthru 

Fall-thru no longer exists.

negatetoken 

Print the token representing the negation of current token.

hide_thisparam 

Do not print the 'this' parameter in argument lists.

Strategies for displaying namespace tokens.

Enumerator
MINIMAL_NAMESPACES 

(default) Print just enough namespace info to fully resolve symbol

NO_NAMESPACES 

Never print namespace information.

ALL_NAMESPACES 

Always print all namespace information.

Possible types of Atom.

Enumerator
syntax 

Emit atom as syntax.

vartoken 

Emit atom as variable.

functoken 

Emit atom as function name.

optoken 

Emit atom as operator.

typetoken 

Emit atom as operator.

fieldtoken 

Emit atom as structure field.

blanktoken 

For anonymous types.

Constructor & Destructor Documentation

PrintLanguage::PrintLanguage ( Architecture g,
const string &  nm 
)

Constructor.

Parameters
gis the Architecture that owns and will use this PrintLanguage
nmis the formal name of the language

References PrintLanguageCapability::name.

Member Function Documentation

virtual bool PrintLanguage::checkPrintNegation ( const Varnode vn)
protectedpure virtual

Check whether a given boolean Varnode can be printed in negated form.

In many situations a boolean value can be inverted by flipping the operator token producing it to a complementary token.

Parameters
vnis the given boolean Varnode
Returns
true if the value can be easily inverted

Implemented in PrintC.

virtual void PrintLanguage::docFunction ( const Funcdata fd)
pure virtual

Emit the declaration (and body) of a function.

Parameters
fdis the function to emit

Implemented in PrintC, and PrintJava.

Referenced by DecompileAt::rawAction().

virtual void PrintLanguage::docSingleGlobal ( const Symbol sym)
pure virtual

Emit the declaration for a single (global) Symbol.

Parameters
symis the Symbol to declare

Implemented in PrintC.

virtual void PrintLanguage::docTypeDefinitions ( const TypeFactory typegrp)
pure virtual

Emit definitions of data-types.

Parameters
typegrpis the container for the data-types that should be defined

Implemented in PrintC.

void PrintLanguage::emitAtom ( const Atom atom)
protected

Send an variable token from the RPN to the emitter.

Send the given Atom to the low-level emitter, marking it up according to its type

Parameters
atomis the given Atom to emit

References PrintLanguage::Atom::ct, PrintLanguage::Atom::fd, PrintLanguage::Atom::highlight, PrintLanguage::Atom::name, PrintLanguage::Atom::offset, PrintLanguage::Atom::op, PrintLanguage::Atom::ptr_second, PrintLanguage::Atom::type, and PrintLanguage::Atom::vn.

virtual void PrintLanguage::emitExpression ( const PcodeOp op)
protectedpure virtual

Emit a full expression.

This can be an assignment statement, if the given PcodeOp has an output Varnode, or it can be a statement with no left-hand side.

Parameters
opis the given PcodeOp performing the final operation of the expression

Implemented in PrintC.

virtual void PrintLanguage::emitFunctionDeclaration ( const Funcdata fd)
protectedpure virtual

Emit a function declaration.

This prints the formal defining prototype for a function.

Parameters
fdis the Funcdata object representing the function to be emitted

Implemented in PrintC.

void PrintLanguage::emitLineComment ( int4  indent,
const Comment comm 
)
protectedvirtual

Emit a comment line.

The comment will get emitted as a single line using the high-level language's delimiters with the given indent level

Parameters
indentis the number of characters to indent
commis the Comment object containing the character data and associated markup info

References EmitXml::comment_color, Comment::getAddr(), Address::getOffset(), Address::getSpace(), and Comment::getText().

Referenced by PrintC::emitCommentFuncHeader(), and PrintC::emitCommentGroup().

void PrintLanguage::emitOp ( const ReversePolish entry)
protected

Send an operator token from the RPN to the emitter.

An OpToken directly from the RPN is sent to the low-level emitter, resolving any final spacing or parentheses.

Parameters
entryis the RPN entry to be emitted

References OpToken::binary, OpToken::bump, OpToken::hiddenfunction, PrintLanguage::ReversePolish::id2, EmitXml::no_color, PrintLanguage::ReversePolish::op, OpToken::postsurround, OpToken::presurround, OpToken::print, OpToken::space, OpToken::spacing, PrintLanguage::ReversePolish::tok, OpToken::type, OpToken::unary_prefix, and PrintLanguage::ReversePolish::visited.

Referenced by PrintC::emitBlockCondition().

virtual bool PrintLanguage::emitScopeVarDecls ( const Scope scope,
int4  cat 
)
protectedpure virtual

Emit all the variable declarations for a given scope.

A subset of all variables can be declared by specifying a category, 0 for parameters, -1 for everything.

Parameters
scopeis the given Scope
catis the category of variable to declare

Implemented in PrintC.

virtual void PrintLanguage::emitVarDecl ( const Symbol sym)
protectedpure virtual

Emit a variable declaration.

This can be part of a full a statement, or just the declaration of a function parameter

Parameters
symis the Symbol to be declared

Implemented in PrintC.

virtual void PrintLanguage::emitVarDeclStatement ( const Symbol sym)
protectedpure virtual

Emit a variable declaration statement.

Parameters
symis the Symbol to be declared

Implemented in PrintC.

bool PrintLanguage::escapeCharacterData ( ostream &  s,
const uint1 *  buf,
int4  count,
int4  charsize,
bool  bigend 
) const
protected

Emit a byte buffer to the stream as unicode characters.

Characters are emitted until we reach a terminator character or count bytes is consumed.

Parameters
sis the output stream
bufis the byte buffer
countis the maximum number of bytes to consume
charsizeis 1 for UTF8, 2 for UTF16, or 4 for UTF32
bigendis true for a big endian encoding of UTF elements
Returns
true if we reach a terminator character

References StringManager::getCodepoint().

Referenced by PrintJava::opCpoolRefOp(), PrintC::opCpoolRefOp(), and PrintC::printCharacterConstant().

void PrintLanguage::formatBinary ( ostream &  s,
uintb  val 
)
static

Print a number in binary form.

Print a string a '0' and '1' characters representing the given value

Parameters
sis the output stream
valis the given value

References mostsigbit_set().

Referenced by PrintC::push_integer().

int4 PrintLanguage::mostNaturalBase ( uintb  val)
static

Determine the most natural base for an integer.

Count '0' and '9' digits base 10. Count '0' and 'f' digits base 16. The highest count is the preferred base.

Parameters
valis the given integer
Returns
10 for decimal or 16 for hexidecimal

Referenced by PrintC::push_integer().

void PrintLanguage::opBinary ( const OpToken tok,
const PcodeOp op 
)
protected

Push a binary operator onto the RPN stack.

Push an operator onto the stack that has a normal binary format. Both of its input expressions are also pushed.

Parameters
tokis the operator token to push
opis the associated PcodeOp

References PcodeOp::getIn(), and OpToken::negate.

void PrintLanguage::opUnary ( const OpToken tok,
const PcodeOp op 
)
protected

Push a unary operator onto the RPN stack.

Push an operator onto the stack that has a normal unary format. Its input expression is also pushed.

Parameters
tokis the operator token to push
opis the associated PcodeOp

References PcodeOp::getIn().

bool PrintLanguage::parentheses ( const OpToken op2)
protected

Determine if the given token should be emitted in its own parenthetic expression.

The token at the top of the stack is being emitted. Check if its input expression, ending with the given operator token, needs to be surrounded by parentheses to convey the proper meaning.

Parameters
op2is the input token to this operator
Returns
true if op2 (as input to this) should be parenthesized

References OpToken::binary, OpToken::hiddenfunction, OpToken::postsurround, OpToken::precedence, OpToken::presurround, OpToken::space, OpToken::type, and OpToken::unary_prefix.

virtual void PrintLanguage::printUnicode ( ostream &  s,
int4  onechar 
) const
protectedpure virtual

Print a single unicode character as a character constant for the high-level language.

For most languages, this prints the character surrounded by single quotes.

Parameters
sis the output stream
onecharis the unicode code point of the character to print

Implemented in PrintC, and PrintJava.

virtual void PrintLanguage::pushAnnotation ( const Varnode vn,
const PcodeOp op 
)
protectedpure virtual

Push an address which is not in the normal data-flow.

The given Varnode is treated as an address, which may or may not have a symbol name.

Parameters
vnis the annotation Varnode
opis the PcodeOp which takes the annotation as input

Implemented in PrintC.

void PrintLanguage::pushAtom ( const Atom atom)
protected
virtual void PrintLanguage::pushConstant ( uintb  val,
const Datatype ct,
const Varnode vn,
const PcodeOp op 
)
protectedpure virtual

Push a constant onto the RPN stack.

The value is ultimately emitted based on its data-type and other associated mark-up

Parameters
valis the value of the constant
ctis the data-type of the constant
vnis the Varnode holding the constant (optional)
opis the PcodeOp using the constant (optional)

Implemented in PrintC.

virtual bool PrintLanguage::pushEquate ( uintb  val,
int4  sz,
const EquateSymbol sym,
const Varnode vn,
const PcodeOp op 
)
protectedpure virtual

Push a constant marked up by and EquateSymbol onto the RPN stack.

The equate may substitute a name or force a conversion for the constant

Parameters
valis the value of the constant
szis the number of bytes to use for the encoding
symis the EquateSymbol that marks up the constant
vnis the Varnode holding the constant (optional)
opis the PcodeOp using the constant (optional)

Implemented in PrintC.

virtual void PrintLanguage::pushMismatchSymbol ( const Symbol sym,
int4  off,
int4  sz,
const Varnode vn,
const PcodeOp op 
)
protectedpure virtual

Push an identifier for a variable that mismatches with its Symbol.

This happens when a Varnode overlaps, but is not contained by a Symbol. This most commonly happens when the size of a Symbol is unknown

Parameters
symis the overlapped symbol
offis the byte offset of the variable relative to the symbol
szis the size of the variable in bytes
vnis the Varnode representing the variable
opis a PcodeOp associated with the Varnode

Implemented in PrintC.

void PrintLanguage::pushOp ( const OpToken tok,
const PcodeOp op 
)
protected

Push an operator token onto the RPN stack.

This generally will recursively push an entire expression onto the RPN stack, up to Varnode objects marked as explicit, and will decide token order and parenthesis placement. As the ordering gets resolved, some amount of the expression may get emitted.

Parameters
tokis the operator token to push
opis the PcodeOp associated with the token

Referenced by PrintC::emitExpression(), PrintC::emitInplaceOp(), PrintC::opBoolNegate(), PrintC::opCall(), PrintJava::opCallind(), PrintC::opCallind(), PrintC::opCallother(), PrintC::opCbranch(), PrintC::opConstructor(), PrintJava::opCpoolRefOp(), PrintC::opCpoolRefOp(), PrintC::opFunc(), PrintC::opHiddenFunc(), PrintJava::opLoad(), PrintC::opLoad(), PrintC::opNewOp(), PrintC::opPtradd(), PrintC::opPtrsub(), PrintC::opReturn(), PrintJava::opStore(), PrintC::opStore(), PrintC::opTypeCast(), PrintC::pushConstant(), PrintC::pushEnumConstant(), PrintC::pushEquate(), PrintC::pushPartialSymbol(), PrintC::pushPrototypeInputs(), PrintC::pushSymbolScope(), PrintJava::pushTypeStart(), and PrintC::pushTypeStart().

virtual void PrintLanguage::pushPartialSymbol ( const Symbol sym,
int4  off,
int4  sz,
const Varnode vn,
const PcodeOp op,
Datatype outtype 
)
protectedpure virtual

Push a variable that represents only part of a symbol onto the RPN stack.

Generally member syntax specifying a field within a structure gets emitted.

Parameters
symis the root Symbol
offis the byte offset, within the Symbol, of the partial variable
szis the number of bytes in the partial variable
vnis the Varnode holding the partial value
opis a PcodeOp associate with the Varnode
outtypeis the data-type expected by expression using the partial variable

Implemented in PrintC.

virtual void PrintLanguage::pushSymbol ( const Symbol sym,
const Varnode vn,
const PcodeOp op 
)
protectedpure virtual

Push a specific Symbol onto the RPN stack.

Parameters
symis the given Symbol
vnis the Varnode holding the Symbol value
opis a PcodeOp associated with the Varnode

Implemented in PrintC.

virtual void PrintLanguage::pushType ( const Datatype ct)
protectedpure virtual

Push a data-type name onto the RPN expression stack.

The data-type is generally emitted as if for a cast.

Parameters
ctis the data-type to push

Implemented in PrintC.

virtual void PrintLanguage::pushUnnamedLocation ( const Address addr,
const Varnode vn,
const PcodeOp op 
)
protectedpure virtual

Push an address as a substitute for a Symbol onto the RPN stack.

If there is no Symbol or other name source for an explicit variable, this method is used to print something to represent the variable based on its storage address.

Parameters
addris the storage address
vnis the Varnode representing the variable (if present)
opis a PcodeOp associated with the variable

Implemented in PrintC.

void PrintLanguage::pushVnExplicit ( const Varnode vn,
const PcodeOp op 
)
protected

Push an explicit variable onto the RPN stack.

This method pushes a given Varnode as a leaf of the current expression. It decides how the Varnode should get emitted, as a symbol, constant, etc., and then pushes the resulting leaf Atom onto the stack.

Parameters
vnis the given explicit Varnode
opis the PcodeOp incorporating the Varnode into the current expression

References Varnode::getAddr(), Varnode::getHigh(), HighVariable::getNameRepresentative(), Varnode::getOffset(), Datatype::getSize(), Varnode::getSize(), HighVariable::getSymbol(), HighVariable::getSymbolOffset(), HighVariable::getType(), Symbol::getType(), Varnode::isAnnotation(), and Varnode::isConstant().

Referenced by PrintC::emitInplaceOp().

void PrintLanguage::pushVnImplied ( const Varnode vn,
const PcodeOp op,
uint4  m 
)
protected

Push an implied variable onto the RPN stack.

For a given implied Varnode, the entire expression producing it is recursively pushed onto the RPN stack.

When calling this method multiple times to push Varnode inputs for a single p-code op, the inputs must be pushed in reverse order.

Parameters
vnis the given implied Varnode
opis PcodeOp taking the Varnode as input
mis the set of printing modifications to apply for this sub-expression

Referenced by PrintC::emitInplaceOp(), PrintC::opBoolNegate(), PrintC::opBranch(), PrintC::opBranchind(), PrintC::opCall(), PrintJava::opCallind(), PrintC::opCallind(), PrintC::opCallother(), PrintC::opCbranch(), PrintC::opConstructor(), PrintC::opCopy(), PrintJava::opCpoolRefOp(), PrintC::opCpoolRefOp(), PrintC::opFunc(), PrintC::opHiddenFunc(), PrintJava::opLoad(), PrintC::opLoad(), PrintC::opNewOp(), PrintC::opPtradd(), PrintC::opPtrsub(), PrintC::opReturn(), PrintC::opSegmentOp(), PrintJava::opStore(), PrintC::opStore(), and PrintC::opTypeCast().

void PrintLanguage::pushVnLHS ( const Varnode vn,
const PcodeOp op 
)
protected

Push a variable as the left-hand side of an expression.

The given Varnode will ultimately be emitted as an explicit variable on the left-hand side of an assignment statement. As with pushVnExplicit(), this method decides how the Varnode will be emitted and pushes the resulting Atom onto the RPN stack.

Parameters
vnis the given LSH Varnode
opis the PcodeOp which produces the Varnode as an output

References Varnode::getAddr(), Varnode::getHigh(), HighVariable::getNameRepresentative(), Datatype::getSize(), Varnode::getSize(), HighVariable::getSymbol(), HighVariable::getSymbolOffset(), and Symbol::getType().

Referenced by PrintC::emitExpression().

void PrintLanguage::recurse ( void  )
protected
void PrintLanguage::setCommentDelimeter ( const string &  start,
const string &  stop,
bool  usecommentfill 
)

Establish comment delimiters for the language.

By default, comments are indicated in the high-level language by preceding them with a specific sequence of delimiter characters, and optionally by ending the comment with another set of delimiter characters.

Parameters
startis the initial sequence of characters delimiting a comment
stopif not empty is the sequence delimiting the end of the comment
usecommentfillis true if the delimiter needs to be emitted after every line break
virtual void PrintLanguage::setCommentStyle ( const string &  nm)
pure virtual

Set the way comments are displayed in decompiler output.

This method can either be provided a formal name or a sample of the initial delimiter, then it will choose from among the schemes it knows

Parameters
nmis the configuration description

Implemented in PrintC.

Referenced by OptionCommentStyle::apply().

void PrintLanguage::setFlat ( bool  val)

Set whether nesting code structure should be emitted.

Emitting formal code structuring can be turned off, causing all control-flow to be represented as goto statements and labels.

Parameters
valis true if no code structuring should be emitted
void PrintLanguage::setIntegerFormat ( const string &  nm)
virtual

Set the default integer format.

This determines how integers are displayed by default. Possible values are "hex" and "dec" to force a given format, or "best" can be used to let the decompiler select what it thinks best for each individual integer.

Parameters
nmis "hex", "dec", or "best"

Referenced by OptionIntegerFormat::apply().

void PrintLanguage::setLineCommentIndent ( int4  val)

Set the number of characters to indent comment lines.

Parameters
valis the number of characters

Referenced by OptionCommentIndent::apply().

void PrintLanguage::setXML ( bool  val)

Set whether the low-level emitter, emits XML markup.

Tell the emitter whether to emit just the raw tokens or if output is in XML format with additional mark-up on the raw tokens.

Parameters
valis true for XML mark-up

Referenced by ArchitectureGhidra::ArchitectureGhidra().

bool PrintLanguage::unicodeNeedsEscape ( int4  codepoint)
staticprotected

Determine if the given codepoint needs to be escaped.

Separate unicode characters that can be clearly emitted in a source code string (letters, numbers, punctuation, symbols) from characters that are better represented in source code with an escape sequence (control characters, unusual spaces, separators, private use characters etc.

Parameters
codepointis the given unicode codepoint to categorize.
Returns
true if the codepoint needs to be escaped

Referenced by PrintJava::printUnicode(), and PrintC::printUnicode().


The documentation for this class was generated from the following files: