Ghidra Decompiler Analysis Engine
printc.hh
Go to the documentation of this file.
1 /* ###
2  * IP: GHIDRA
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
18 
19 #ifndef __PRINTC__
20 #define __PRINTC__
21 
22 #include "printlanguage.hh"
23 #include "comment.hh"
24 
25 class FuncProto;
26 class JumpTable;
27 
33  static PrintCCapability printCCapability;
34  PrintCCapability(void);
36  PrintCCapability &operator=(const PrintCCapability &op);
37 public:
39 };
40 
46  const OpToken *token;
47  const TypeField *field;
48  const Datatype *parent;
49  string fieldname;
51 };
52 
63 class PrintC : public PrintLanguage {
64 protected:
65  static OpToken hidden;
66  static OpToken scope;
69  static OpToken subscript;
75  static OpToken addressof;
77  static OpToken typecast;
78  static OpToken multiply;
79  static OpToken divide;
80  static OpToken modulo;
86  static OpToken less_than;
90  static OpToken equal;
91  static OpToken not_equal;
99  static OpToken comma;
100  static OpToken new_op;
102  static OpToken divequal;
103  static OpToken remequal;
108  static OpToken andequal;
109  static OpToken orequal;
110  static OpToken xorequal;
113  static OpToken ptr_expr;
115  static OpToken enum_cat;
116  bool option_NULL;
122  string nullToken;
124 
125  // Routines that are specific to C/C++
126  void buildTypeStack(const Datatype *ct,vector<const Datatype *> &typestack);
127  void pushPrototypeInputs(const FuncProto *proto);
128  void pushSymbolScope(const Symbol *symbol);
129  void emitSymbolScope(const Symbol *symbol);
130  virtual void pushTypeStart(const Datatype *ct,bool noident);
131  virtual void pushTypeEnd(const Datatype *ct);
132  void pushBoolConstant(uintb val,const TypeBase *ct,const Varnode *vn,
133  const PcodeOp *op);
134  void pushCharConstant(uintb val,const TypeChar *ct,const Varnode *vn,
135  const PcodeOp *op);
136  void pushEnumConstant(uintb val,const TypeEnum *ct,const Varnode *vn,
137  const PcodeOp *op);
138  virtual bool pushPtrCharConstant(uintb val,const TypePointer *ct,const Varnode *vn,
139  const PcodeOp *op);
140  bool pushPtrCodeConstant(uintb val,const TypePointer *ct,const Varnode *vn,
141  const PcodeOp *op);
142  virtual bool doEmitWideCharPrefix(void) const;
143 
144  bool checkArrayDeref(const Varnode *vn) const;
145  void emitStructDefinition(const TypeStruct *ct);
146  void emitEnumDefinition(const TypeEnum *ct);
147  void emitPrototypeOutput(const FuncProto *proto,const Funcdata *fd);
148  void emitPrototypeInputs(const FuncProto *proto);
150  void emitLocalVarDecls(const Funcdata *fd);
151  void emitStatement(const PcodeOp *inst);
152  bool emitInplaceOp(const PcodeOp *op);
153  void emitGotoStatement(const FlowBlock *bl,const FlowBlock *exp_bl,uint4 type);
154  void emitSwitchCase(int4 casenum,const BlockSwitch *switchbl);
155  void emitLabel(const FlowBlock *bl);
156  void emitLabelStatement(const FlowBlock *bl);
157  void emitAnyLabelStatement(const FlowBlock *bl);
158  void emitCommentGroup(const PcodeOp *inst);
159  void emitCommentBlockTree(const FlowBlock *bl);
160  void emitCommentFuncHeader(const Funcdata *fd);
161  void emitForLoop(const BlockWhileDo *bl);
162  void opFunc(const PcodeOp *op);
163  void opTypeCast(const PcodeOp *op);
164  void opHiddenFunc(const PcodeOp *op);
165  bool printCharacterConstant(ostream &s,const Address &addr,Datatype *charType) const;
166  int4 getHiddenThisSlot(const PcodeOp *op,FuncProto *fc);
167  void resetDefaultsPrintC(void);
168  virtual void pushConstant(uintb val,const Datatype *ct,
169  const Varnode *vn,const PcodeOp *op);
170  virtual bool pushEquate(uintb val,int4 sz,const EquateSymbol *sym,
171  const Varnode *vn,const PcodeOp *op);
172  virtual void pushAnnotation(const Varnode *vn,const PcodeOp *op);
173  virtual void pushSymbol(const Symbol *sym,const Varnode *vn,
174  const PcodeOp *op);
175  virtual void pushUnnamedLocation(const Address &addr,
176  const Varnode *vn,const PcodeOp *op);
177  virtual void pushPartialSymbol(const Symbol *sym,int4 off,int4 sz,
178  const Varnode *vn,const PcodeOp *op,Datatype *outtype);
179  virtual void pushMismatchSymbol(const Symbol *sym,int4 off,int4 sz,
180  const Varnode *vn,const PcodeOp *op);
181  virtual void push_integer(uintb val,int4 sz,bool sign,
182  const Varnode *vn,
183  const PcodeOp *op);
184  virtual void push_float(uintb val,int4 sz,const Varnode *vn,
185  const PcodeOp *op);
186  virtual void printUnicode(ostream &s,int4 onechar) const;
187  virtual void pushType(const Datatype *ct);
188  virtual string genericFunctionName(const Address &addr);
189  virtual string genericTypeName(const Datatype *ct);
190 
191  virtual void emitExpression(const PcodeOp *op);
192  virtual void emitVarDecl(const Symbol *sym);
193  virtual void emitVarDeclStatement(const Symbol *sym);
194  virtual bool emitScopeVarDecls(const Scope *scope,int4 cat);
195  virtual void emitFunctionDeclaration(const Funcdata *fd);
196  virtual void emitTypeDefinition(const Datatype *ct);
197  virtual bool checkPrintNegation(const Varnode *vn);
198 public:
199  PrintC(Architecture *g,const string &nm="c-language");
200  void setNULLPrinting(bool val) { option_NULL = val; }
201  void setInplaceOps(bool val) { option_inplace_ops = val; }
202  void setConvention(bool val) { option_convention = val; }
203  void setNoCastPrinting(bool val) { option_nocasts = val; }
204  void setCStyleComments(void) { setCommentDelimeter("/* "," */",false); }
205  void setCPlusPlusStyleComments(void) { setCommentDelimeter("// ","",true); }
206  void setDisplayUnplaced(bool val) { option_unplaced = val; }
207  void setHideImpliedExts(bool val) { option_hide_exts = val; }
208  virtual ~PrintC(void) {}
209  virtual void resetDefaults(void);
210  virtual void adjustTypeOperators(void);
211  virtual void setCommentStyle(const string &nm);
212  virtual void docTypeDefinitions(const TypeFactory *typegrp);
213  virtual void docAllGlobals(void);
214  virtual void docSingleGlobal(const Symbol *sym);
215  virtual void docFunction(const Funcdata *fd);
216 
217  virtual void emitBlockBasic(const BlockBasic *bb);
218  virtual void emitBlockGraph(const BlockGraph *bl);
219  virtual void emitBlockCopy(const BlockCopy *bl);
220  virtual void emitBlockGoto(const BlockGoto *bl);
221  virtual void emitBlockLs(const BlockList *bl);
222  virtual void emitBlockCondition(const BlockCondition *bl);
223  virtual void emitBlockIf(const BlockIf *bl);
224  virtual void emitBlockWhileDo(const BlockWhileDo *bl);
225  virtual void emitBlockDoWhile(const BlockDoWhile *bl);
226  virtual void emitBlockInfLoop(const BlockInfLoop *bl);
227  virtual void emitBlockSwitch(const BlockSwitch *bl);
228 
229  virtual void opCopy(const PcodeOp *op);
230  virtual void opLoad(const PcodeOp *op);
231  virtual void opStore(const PcodeOp *op);
232  virtual void opBranch(const PcodeOp *op);
233  virtual void opCbranch(const PcodeOp *op);
234  virtual void opBranchind(const PcodeOp *op);
235  virtual void opCall(const PcodeOp *op);
236  virtual void opCallind(const PcodeOp *op);
237  virtual void opCallother(const PcodeOp *op);
238  virtual void opConstructor(const PcodeOp *op,bool withNew);
239  virtual void opReturn(const PcodeOp *op);
240  virtual void opIntEqual(const PcodeOp *op) { opBinary(&equal,op); }
241  virtual void opIntNotEqual(const PcodeOp *op) { opBinary(&not_equal,op); }
242  virtual void opIntSless(const PcodeOp *op) { opBinary(&less_than,op); }
243  virtual void opIntSlessEqual(const PcodeOp *op) { opBinary(&less_equal,op); }
244  virtual void opIntLess(const PcodeOp *op) { opBinary(&less_than,op); }
245  virtual void opIntLessEqual(const PcodeOp *op) { opBinary(&less_equal,op); }
246  virtual void opIntZext(const PcodeOp *op,const PcodeOp *readOp);
247  virtual void opIntSext(const PcodeOp *op,const PcodeOp *readOp);
248  virtual void opIntAdd(const PcodeOp *op) { opBinary(&binary_plus,op); }
249  virtual void opIntSub(const PcodeOp *op) { opBinary(&binary_minus,op); }
250  virtual void opIntCarry(const PcodeOp *op) { opFunc(op); }
251  virtual void opIntScarry(const PcodeOp *op) { opFunc(op); }
252  virtual void opIntSborrow(const PcodeOp *op) { opFunc(op); }
253  virtual void opInt2Comp(const PcodeOp *op) { opUnary(&unary_minus,op); }
254  virtual void opIntNegate(const PcodeOp *op) { opUnary(&bitwise_not,op); }
255  virtual void opIntXor(const PcodeOp *op) { opBinary(&bitwise_xor,op); }
256  virtual void opIntAnd(const PcodeOp *op) { opBinary(&bitwise_and,op); }
257  virtual void opIntOr(const PcodeOp *op) { opBinary(&bitwise_or,op); }
258  virtual void opIntLeft(const PcodeOp *op) { opBinary(&shift_left,op); }
259  virtual void opIntRight(const PcodeOp *op) { opBinary(&shift_right,op); }
260  virtual void opIntSright(const PcodeOp *op) { opBinary(&shift_sright,op); }
261  virtual void opIntMult(const PcodeOp *op) { opBinary(&multiply,op); }
262  virtual void opIntDiv(const PcodeOp *op) { opBinary(&divide,op); }
263  virtual void opIntSdiv(const PcodeOp *op) { opBinary(&divide,op); }
264  virtual void opIntRem(const PcodeOp *op) { opBinary(&modulo,op); }
265  virtual void opIntSrem(const PcodeOp *op) { opBinary(&modulo,op); }
266  virtual void opBoolNegate(const PcodeOp *op);
267  virtual void opBoolXor(const PcodeOp *op) { opBinary(&boolean_xor,op); }
268  virtual void opBoolAnd(const PcodeOp *op) { opBinary(&boolean_and,op); }
269  virtual void opBoolOr(const PcodeOp *op) { opBinary(&boolean_or,op); }
270  virtual void opFloatEqual(const PcodeOp *op) { opBinary(&equal,op); }
271  virtual void opFloatNotEqual(const PcodeOp *op) { opBinary(&not_equal,op); }
272  virtual void opFloatLess(const PcodeOp *op) { opBinary(&less_than,op); }
273  virtual void opFloatLessEqual(const PcodeOp *op) { opBinary(&less_equal,op); }
274  virtual void opFloatNan(const PcodeOp *op) { opFunc(op); }
275  virtual void opFloatAdd(const PcodeOp *op) { opBinary(&binary_plus,op); }
276  virtual void opFloatDiv(const PcodeOp *op) { opBinary(&divide,op); }
277  virtual void opFloatMult(const PcodeOp *op) { opBinary(&multiply,op); }
278  virtual void opFloatSub(const PcodeOp *op) { opBinary(&binary_minus,op); }
279  virtual void opFloatNeg(const PcodeOp *op) { opUnary(&unary_minus,op); }
280  virtual void opFloatAbs(const PcodeOp *op) { opFunc(op); }
281  virtual void opFloatSqrt(const PcodeOp *op) { opFunc(op); }
282  virtual void opFloatInt2Float(const PcodeOp *op) { opTypeCast(op); }
283  virtual void opFloatFloat2Float(const PcodeOp *op) { opTypeCast(op); }
284  virtual void opFloatTrunc(const PcodeOp *op) { opTypeCast(op); }
285  virtual void opFloatCeil(const PcodeOp *op) { opFunc(op); }
286  virtual void opFloatFloor(const PcodeOp *op) { opFunc(op); }
287  virtual void opFloatRound(const PcodeOp *op) { opFunc(op); }
288  virtual void opMultiequal(const PcodeOp *op) {}
289  virtual void opIndirect(const PcodeOp *op) {}
290  virtual void opPiece(const PcodeOp *op) { opFunc(op); }
291  virtual void opSubpiece(const PcodeOp *op);
292  virtual void opCast(const PcodeOp *op) { opTypeCast(op); }
293  virtual void opPtradd(const PcodeOp *op);
294  virtual void opPtrsub(const PcodeOp *op);
295  virtual void opSegmentOp(const PcodeOp *op);
296  virtual void opCpoolRefOp(const PcodeOp *op);
297  virtual void opNewOp(const PcodeOp *op);
298  virtual void opInsertOp(const PcodeOp *op);
299  virtual void opExtractOp(const PcodeOp *op);
300  virtual void opPopcountOp(const PcodeOp *op) { opFunc(op); }
301 };
302 
303 #endif
PrintC::option_inplace_ops
bool option_inplace_ops
Set to true if we should use '+=' '&=' etc.
Definition: printc.hh:117
comment.hh
A database interface for high-level language comments.
PrintC::emitForLoop
void emitForLoop(const BlockWhileDo *bl)
Emit block as a for loop.
Definition: printc.cc:2640
PrintC::opFloatLess
virtual void opFloatLess(const PcodeOp *op)
Emit a FLOAT_LESS operator.
Definition: printc.hh:272
PrintC::opIntScarry
virtual void opIntScarry(const PcodeOp *op)
Emit a INT_SCARRY operator.
Definition: printc.hh:251
PrintC::genericFunctionName
virtual string genericFunctionName(const Address &addr)
Create a generic function name base on the entry point address.
Definition: printc.cc:3058
PrintC::emitCommentFuncHeader
void emitCommentFuncHeader(const Funcdata *fd)
Emit comments in the given function's header.
Definition: printc.cc:2970
PrintC::type_expr_nospace
static OpToken type_expr_nospace
Type declaration with no space.
Definition: printc.hh:112
PrintC::emitPrototypeOutput
void emitPrototypeOutput(const FuncProto *proto, const Funcdata *fd)
Emit the output data-type of a function prototype.
Definition: printc.cc:1900
PrintLanguage
The base class API for emitting a high-level language.
Definition: printlanguage.hh:134
PrintC::opPiece
virtual void opPiece(const PcodeOp *op)
Emit a PIECE operator.
Definition: printc.hh:290
PrintC::pushPrototypeInputs
void pushPrototypeInputs(const FuncProto *proto)
Push input parameters.
Definition: printc.cc:141
BlockGraph
A control-flow block built out of sub-components.
Definition: block.hh:271
PrintC::emitBlockGoto
virtual void emitBlockGoto(const BlockGoto *bl)
Emit a block ending with a goto statement.
Definition: printc.cc:2469
PrintC::opIntNotEqual
virtual void opIntNotEqual(const PcodeOp *op)
Emit a INT_NOTEQUAL operator.
Definition: printc.hh:241
PrintC::opReturn
virtual void opReturn(const PcodeOp *op)
Emit a RETURN operator.
Definition: printc.cc:643
PrintC::dereference
static OpToken dereference
The pointer dereference operator.
Definition: printc.hh:76
PrintC::emitLocalVarDecls
void emitLocalVarDecls(const Funcdata *fd)
Emit variable declarations for a function.
Definition: printc.cc:1966
TypePointer
Datatype object representing a pointer.
Definition: type.hh:228
PrintC::emitFunctionDeclaration
virtual void emitFunctionDeclaration(const Funcdata *fd)
Emit a function declaration.
Definition: printc.cc:2273
FlowBlock
Description of a control-flow block containing PcodeOps.
Definition: block.hh:60
PrintC::unary_minus
static OpToken unary_minus
The unary minus operator.
Definition: printc.hh:73
PrintC::less_than
static OpToken less_than
The less than operator.
Definition: printc.hh:86
PrintC::array_expr
static OpToken array_expr
Array adornment for a type declaration.
Definition: printc.hh:114
PrintC::addressof
static OpToken addressof
The address of operator.
Definition: printc.hh:75
PrintC::opFloatRound
virtual void opFloatRound(const PcodeOp *op)
Emit a FLOAT_ROUND operator.
Definition: printc.hh:287
PrintC::buildTypeStack
void buildTypeStack(const Datatype *ct, vector< const Datatype * > &typestack)
Prepare to push components of a data-type declaration.
Definition: printc.cc:115
PartialSymbolEntry::parent
const Datatype * parent
The parent data-type owning the field.
Definition: printc.hh:48
PrintC::opFloatNan
virtual void opFloatNan(const PcodeOp *op)
Emit a FLOAT_NAN operator.
Definition: printc.hh:274
PrintC::opBranch
virtual void opBranch(const PcodeOp *op)
Emit a BRANCH operator.
Definition: printc.cc:435
PrintC::emitBlockWhileDo
virtual void emitBlockWhileDo(const BlockWhileDo *bl)
Emit a loop structure, check at top.
Definition: printc.cc:2688
PrintC::opCbranch
virtual void opCbranch(const PcodeOp *op)
Definition: printc.cc:451
PrintC::emitPrototypeInputs
void emitPrototypeInputs(const FuncProto *proto)
Emit the input data-types of a function prototype.
Definition: printc.cc:1928
PartialSymbolEntry::token
const OpToken * token
Operator used to drill-down to the field.
Definition: printc.hh:46
PrintC::option_hide_exts
bool option_hide_exts
Set to true if we should hide implied extension operations.
Definition: printc.hh:121
PrintC::modulo
static OpToken modulo
The modulo operator.
Definition: printc.hh:80
PrintC::opIntSext
virtual void opIntSext(const PcodeOp *op, const PcodeOp *readOp)
Emit a INT_SEXT operator.
Definition: printc.cc:688
PrintC::typecast
static OpToken typecast
The type cast operator.
Definition: printc.hh:77
PrintC::opIntXor
virtual void opIntXor(const PcodeOp *op)
Emit a INT_XOR operator.
Definition: printc.hh:255
PrintC::opFloatSub
virtual void opFloatSub(const PcodeOp *op)
Emit a FLOAT_SUB operator.
Definition: printc.hh:278
PrintC::emitStructDefinition
void emitStructDefinition(const TypeStruct *ct)
Emit the definition of a structure data-type.
Definition: printc.cc:1817
BlockDoWhile
A loop structure where the condition is checked at the bottom.
Definition: block.hh:618
PrintC::emitSwitchCase
void emitSwitchCase(int4 casenum, const BlockSwitch *switchbl)
Emit labels for a case block.
Definition: printc.cc:2830
JumpTable
A map from values to control-flow targets within a function.
Definition: jumptable.hh:499
EmitXml::syntax_highlight
syntax_highlight
Possible types of syntax highlighting.
Definition: prettyprint.hh:88
PrintC::opIntLeft
virtual void opIntLeft(const PcodeOp *op)
Emit a INT_LEFT operator.
Definition: printc.hh:258
PrintC::opIntSright
virtual void opIntSright(const PcodeOp *op)
Emit a INT_SRIGHT operator.
Definition: printc.hh:260
PrintC::binary_minus
static OpToken binary_minus
The binary subtraction operator.
Definition: printc.hh:82
PrintC::emitAnyLabelStatement
void emitAnyLabelStatement(const FlowBlock *bl)
Emit any required label statement for a given control-flow block.
Definition: printc.cc:2917
PrintLanguage::opUnary
void opUnary(const OpToken *tok, const PcodeOp *op)
Push a unary operator onto the RPN stack.
Definition: printlanguage.cc:563
PrintC::option_NULL
bool option_NULL
Set to true if we should emit NULL keyword.
Definition: printc.hh:116
PrintC::equal
static OpToken equal
The equal operator.
Definition: printc.hh:90
PrintC::opIntDiv
virtual void opIntDiv(const PcodeOp *op)
Emit a INT_DIV operator.
Definition: printc.hh:262
PrintC::opSubpiece
virtual void opSubpiece(const PcodeOp *op)
Emit a SUBPIECE operator.
Definition: printc.cc:719
PrintC::opIntNegate
virtual void opIntNegate(const PcodeOp *op)
Emit a INT_NEGATE operator.
Definition: printc.hh:254
PrintC::opPtrsub
virtual void opPtrsub(const PcodeOp *op)
Definition: printc.cc:779
PrintC::emitBlockBasic
virtual void emitBlockBasic(const BlockBasic *bb)
Emit statements in a basic block.
Definition: printc.cc:2381
PrintC::opIntRight
virtual void opIntRight(const PcodeOp *op)
Emit a INT_RIGHT operator.
Definition: printc.hh:259
PrintC::greater_than
static OpToken greater_than
The greater than operator.
Definition: printc.hh:88
PrintC::emitExpression
virtual void emitExpression(const PcodeOp *op)
Emit a full expression.
Definition: printc.cc:2164
PrintC::opIntSub
virtual void opIntSub(const PcodeOp *op)
Emit a INT_SUB operator.
Definition: printc.hh:249
PrintC::docTypeDefinitions
virtual void docTypeDefinitions(const TypeFactory *typegrp)
Emit definitions of data-types.
Definition: printc.cc:2097
PrintC::push_float
virtual void push_float(uintb val, int4 sz, const Varnode *vn, const PcodeOp *op)
Push a constant with a floating-point data-type to the RPN stack.
Definition: printc.cc:1177
TypeChar
Base type for character data-types: i.e. char.
Definition: type.hh:183
PrintCCapability
Factory and static initializer for the "c-language" back-end to the decompiler.
Definition: printc.hh:32
PrintC::opMultiequal
virtual void opMultiequal(const PcodeOp *op)
Emit a MULTIEQUAL operator.
Definition: printc.hh:288
PartialSymbolEntry::field
const TypeField * field
The component object describing the field.
Definition: printc.hh:47
PrintC::opIntSless
virtual void opIntSless(const PcodeOp *op)
Emit a INT_SLESS operator.
Definition: printc.hh:242
PrintC::opConstructor
virtual void opConstructor(const PcodeOp *op, bool withNew)
Emit an operator constructing an object.
Definition: printc.cc:606
PrintC::opFloatCeil
virtual void opFloatCeil(const PcodeOp *op)
Emit a FLOAT_CEIL operator.
Definition: printc.hh:285
PrintC::enum_cat
static OpToken enum_cat
The concatenation operator for enumerated values.
Definition: printc.hh:115
PrintC::multiply
static OpToken multiply
The multiplication operator.
Definition: printc.hh:78
PrintC::option_convention
bool option_convention
Set to true if we should print calling convention.
Definition: printc.hh:118
Scope
A collection of Symbol objects within a single (namespace or functional) scope.
Definition: database.hh:402
PrintC::opFloatInt2Float
virtual void opFloatInt2Float(const PcodeOp *op)
Emit a FLOAT_INT2FLOAT operator.
Definition: printc.hh:282
PrintC::option_unplaced
bool option_unplaced
Set to true if we should display unplaced comments.
Definition: printc.hh:120
TypeStruct
A composite Datatype object: A "structure" with component "fields".
Definition: type.hh:310
PrintC::bitwise_not
static OpToken bitwise_not
The bitwise negate operator.
Definition: printc.hh:71
PrintC::pushEquate
virtual bool pushEquate(uintb val, int4 sz, const EquateSymbol *sym, const Varnode *vn, const PcodeOp *op)
Push a constant marked up by and EquateSymbol onto the RPN stack.
Definition: printc.cc:1575
PrintC::less_equal
static OpToken less_equal
The less than or equal operator.
Definition: printc.hh:87
PrintC::opFloatLessEqual
virtual void opFloatLessEqual(const PcodeOp *op)
Emit a FLOAT_LESSEQUAL operator.
Definition: printc.hh:273
PrintC::orequal
static OpToken orequal
The in-place logical or operator.
Definition: printc.hh:109
PrintC::boolean_not
static OpToken boolean_not
The boolean not operator.
Definition: printc.hh:72
PrintC::docSingleGlobal
virtual void docSingleGlobal(const Symbol *sym)
Emit the declaration for a single (global) Symbol.
Definition: printc.cc:2329
PrintC::opIntAnd
virtual void opIntAnd(const PcodeOp *op)
Emit a INT_AND operator.
Definition: printc.hh:256
PrintC::opBoolOr
virtual void opBoolOr(const PcodeOp *op)
Emit a BOOL_OR operator.
Definition: printc.hh:269
PrintC::opIntEqual
virtual void opIntEqual(const PcodeOp *op)
Emit a INT_EQUAL operator.
Definition: printc.hh:240
PrintC::pushTypeEnd
virtual void pushTypeEnd(const Datatype *ct)
Push the tail ends of a data-type declaration onto the RPN stack.
Definition: printc.cc:285
PrintC::pushTypeStart
virtual void pushTypeStart(const Datatype *ct, bool noident)
Push part of a data-type declaration onto the RPN stack, up to the identifier.
Definition: printc.cc:236
PrintC::bitwise_and
static OpToken bitwise_and
The logical and operator.
Definition: printc.hh:92
BlockBasic
A basic block for p-code operations.
Definition: block.hh:365
PrintC::opSegmentOp
virtual void opSegmentOp(const PcodeOp *op)
Definition: printc.cc:947
PrintC::emitBlockLs
virtual void emitBlockLs(const BlockList *bl)
Emit a sequence of blocks.
Definition: printc.cc:2484
PrintC::opFloatNeg
virtual void opFloatNeg(const PcodeOp *op)
Emit a FLOAT_NEG operator.
Definition: printc.hh:279
PrintC::pushPtrCharConstant
virtual bool pushPtrCharConstant(uintb val, const TypePointer *ct, const Varnode *vn, const PcodeOp *op)
Attempt to push a quoted string representing a given constant pointer onto the RPN stack.
Definition: printc.cc:1464
PcodeOp
Lowest level operation of the p-code language.
Definition: op.hh:58
PrintC::emitTypeDefinition
virtual void emitTypeDefinition(const Datatype *ct)
Emit the definition of the given data-type.
Definition: printc.cc:2065
Architecture
Manager for all the major decompiler subsystems.
Definition: architecture.hh:119
PrintC::shift_right
static OpToken shift_right
The right shift operator.
Definition: printc.hh:84
PrintC::doEmitWideCharPrefix
virtual bool doEmitWideCharPrefix(void) const
Return true if this language requires a prefix when expressing wide characters.
Definition: printc.cc:1319
PrintC::boolean_or
static OpToken boolean_or
The boolean or operator.
Definition: printc.hh:96
PrintC::emitBlockSwitch
virtual void emitBlockSwitch(const BlockSwitch *bl)
Emit a switch structure.
Definition: printc.cc:3011
PrintC::emitBlockCopy
virtual void emitBlockCopy(const BlockCopy *bl)
Emit a basic block (with any labels)
Definition: printc.cc:2462
PrintC::opIntCarry
virtual void opIntCarry(const PcodeOp *op)
Emit a INT_CARRY operator.
Definition: printc.hh:250
PrintC::getHiddenThisSlot
int4 getHiddenThisSlot(const PcodeOp *op, FuncProto *fc)
Get position of "this" pointer needing to be hidden.
Definition: printc.cc:1361
PrintC::unary_plus
static OpToken unary_plus
The unary plus operator.
Definition: printc.hh:74
PrintC::opExtractOp
virtual void opExtractOp(const PcodeOp *op)
Emit an EXTRACT operator.
Definition: printc.cc:1067
PrintC::docAllGlobals
virtual void docAllGlobals(void)
Emit declarations of global variables.
Definition: printc.cc:2319
PrintC::emitBlockInfLoop
virtual void emitBlockInfLoop(const BlockInfLoop *bl)
Emit an infinite loop structure.
Definition: printc.cc:2794
PrintC::opInt2Comp
virtual void opInt2Comp(const PcodeOp *op)
Emit a INT_2COMP operator.
Definition: printc.hh:253
TypeEnum
An enumerated Datatype object: an integer with named values.
Definition: type.hh:286
PrintC::emitScopeVarDecls
virtual bool emitScopeVarDecls(const Scope *scope, int4 cat)
Emit all the variable declarations for a given scope.
Definition: printc.cc:2214
PrintC::minusequal
static OpToken minusequal
The in-place subtraction operator.
Definition: printc.hh:105
PrintC::emitSymbolScope
void emitSymbolScope(const Symbol *symbol)
Emit tokens resolving a symbol's scope.
Definition: printc.cc:205
PrintC::opIntSborrow
virtual void opIntSborrow(const PcodeOp *op)
Emit a INT_SBORROW operator.
Definition: printc.hh:252
PrintC::assignment
static OpToken assignment
The assignment operator.
Definition: printc.hh:98
PrintC::pushSymbolScope
void pushSymbolScope(const Symbol *symbol)
Push tokens resolving a symbol's scope.
Definition: printc.cc:174
BlockInfLoop
An infinite loop structure.
Definition: block.hh:632
PrintC::pushBoolConstant
void pushBoolConstant(uintb val, const TypeBase *ct, const Varnode *vn, const PcodeOp *op)
Push a true or false token to the RPN stack.
Definition: printc.cc:1302
PrintC::xorequal
static OpToken xorequal
The in-place logical xor operator.
Definition: printc.hh:110
Varnode
A low-level variable or contiguous set of bytes described by an Address and a size.
Definition: varnode.hh:65
PrintC::opCallind
virtual void opCallind(const PcodeOp *op)
Emit a CALLIND operator.
Definition: printc.cc:552
PrintC::rightequal
static OpToken rightequal
The in-place right shift operator.
Definition: printc.hh:107
PrintC::option_nocasts
bool option_nocasts
Don't print a cast if true.
Definition: printc.hh:119
PrintC::opFloatAdd
virtual void opFloatAdd(const PcodeOp *op)
Emit a FLOAT_ADD operator.
Definition: printc.hh:275
PrintC::opIntMult
virtual void opIntMult(const PcodeOp *op)
Emit a INT_MULT operator.
Definition: printc.hh:261
TypeBase
Base class for the fundamental atomic types.
Definition: type.hh:167
BlockGoto
A block that terminates with an unstructured (goto) branch to another block.
Definition: block.hh:444
PrintC::pushSymbol
virtual void pushSymbol(const Symbol *sym, const Varnode *vn, const PcodeOp *op)
Push a specific Symbol onto the RPN stack.
Definition: printc.cc:1670
PrintC::pushType
virtual void pushType(const Datatype *ct)
Push a data-type name onto the RPN expression stack.
Definition: printc.cc:1287
PrintC::emitGlobalVarDeclsRecursive
void emitGlobalVarDeclsRecursive(Scope *scope)
Emit variable declarations for all global symbols under given scope.
Definition: printc.cc:2306
PrintC::divequal
static OpToken divequal
The in-place division operator.
Definition: printc.hh:102
PrintC::opCall
virtual void opCall(const PcodeOp *op)
Emit a CALL operator.
Definition: printc.cc:508
PrintC::opTypeCast
void opTypeCast(const PcodeOp *op)
Push the given p-code op using type-cast syntax to the RPN stack.
Definition: printc.cc:371
PrintC::PrintC
PrintC(Architecture *g, const string &nm="c-language")
Constructor.
Definition: printc.cc:95
PrintC::resetDefaults
virtual void resetDefaults(void)
Set printing options to their default value.
Definition: printc.cc:2031
PrintC::opCpoolRefOp
virtual void opCpoolRefOp(const PcodeOp *op)
Emit a CPOOLREF operator.
Definition: printc.cc:953
PrintLanguage::opBinary
void opBinary(const OpToken *tok, const PcodeOp *op)
Push a binary operator onto the RPN stack.
Definition: printlanguage.cc:543
TypeField
Specifies subfields of a structure or what a pointer points to.
Definition: type.hh:133
PrintC::opFloatTrunc
virtual void opFloatTrunc(const PcodeOp *op)
Emit a FLOAT_TRUNC operator.
Definition: printc.hh:284
PrintC::not_equal
static OpToken not_equal
The not equal operator.
Definition: printc.hh:91
PrintC::opIndirect
virtual void opIndirect(const PcodeOp *op)
Emit a INDIRECT operator.
Definition: printc.hh:289
PrintC::opBoolXor
virtual void opBoolXor(const PcodeOp *op)
Emit a BOOL_XOR operator.
Definition: printc.hh:267
EquateSymbol
A Symbol that holds equate information for a constant.
Definition: database.hh:270
PrintC::shift_left
static OpToken shift_left
The left shift operator.
Definition: printc.hh:83
Address
A low-level machine address for labelling bytes and data.
Definition: address.hh:46
PrintC::emitBlockGraph
virtual void emitBlockGraph(const BlockGraph *bl)
Emit (an unspecified) list of blocks.
Definition: printc.cc:2449
PrintC::resetDefaultsPrintC
void resetDefaultsPrintC(void)
Set default values for options specific to PrintC.
Definition: printc.cc:1380
PrintC::checkPrintNegation
virtual bool checkPrintNegation(const Varnode *vn)
Check whether a given boolean Varnode can be printed in negated form.
Definition: printc.cc:2084
PrintC::pushCharConstant
void pushCharConstant(uintb val, const TypeChar *ct, const Varnode *vn, const PcodeOp *op)
Push a single character constant to the RPN stack.
Definition: printc.cc:1400
PrintC::leftequal
static OpToken leftequal
The in-place left shift operator.
Definition: printc.hh:106
PrintC::opFloatSqrt
virtual void opFloatSqrt(const PcodeOp *op)
Emit a FLOAT_SQRT operator.
Definition: printc.hh:281
Funcdata
Container for data structures associated with a single function.
Definition: funcdata.hh:45
Datatype
The base datatype class for the decompiler.
Definition: type.hh:62
BlockList
A series of blocks that execute in sequence.
Definition: block.hh:497
PrintCCapability::buildLanguage
virtual PrintLanguage * buildLanguage(Architecture *glb)
Build the main PrintLanguage object corresponding to this capability.
Definition: printc.cc:87
PrintC::emitGotoStatement
void emitGotoStatement(const FlowBlock *bl, const FlowBlock *exp_bl, uint4 type)
Emit a statement representing an unstructured branch.
Definition: printc.cc:2009
TypeFactory
Container class for all Datatype objects in an Architecture.
Definition: type.hh:396
PrintC::scope
static OpToken scope
The sub-scope/namespace operator.
Definition: printc.hh:66
PrintC::emitBlockDoWhile
virtual void emitBlockDoWhile(const BlockDoWhile *bl)
Emit a loop structure, check at bottom.
Definition: printc.cc:2761
PrintC::emitLabelStatement
void emitLabelStatement(const FlowBlock *bl)
Emit any required label statement for a given basic block.
Definition: printc.cc:2896
PrintC::greater_equal
static OpToken greater_equal
The greater than or equal operator.
Definition: printc.hh:89
PrintC::andequal
static OpToken andequal
The in-place logical and operator.
Definition: printc.hh:108
PrintC::emitVarDeclStatement
virtual void emitVarDeclStatement(const Symbol *sym)
Emit a variable declaration statement.
Definition: printc.cc:2206
PrintC::emitEnumDefinition
void emitEnumDefinition(const TypeEnum *ct)
Emit the definition of an enumeration data-type.
Definition: printc.cc:1854
PrintC::emitCommentGroup
void emitCommentGroup(const PcodeOp *inst)
Emit comments associated with a given statement.
Definition: printc.cc:2929
PrintC::pushConstant
virtual void pushConstant(uintb val, const Datatype *ct, const Varnode *vn, const PcodeOp *op)
Push a constant onto the RPN stack.
Definition: printc.cc:1508
PartialSymbolEntry::fieldname
string fieldname
The name of the field.
Definition: printc.hh:49
PrintC::opPtradd
virtual void opPtradd(const PcodeOp *op)
Emit a PTRADD operator.
Definition: printc.cc:730
PrintC::adjustTypeOperators
virtual void adjustTypeOperators(void)
Set basic data-type information for p-code operators.
Definition: printc.cc:2038
PrintC::function_call
static OpToken function_call
The function call operator.
Definition: printc.hh:70
PrintC::opFloatFloor
virtual void opFloatFloor(const PcodeOp *op)
Emit a FLOAT_FLOOR operator.
Definition: printc.hh:286
PrintC::emitStatement
void emitStatement(const PcodeOp *inst)
Emit a statement in the body of a function.
Definition: printc.cc:1991
PrintC::genericTypeName
virtual string genericTypeName(const Datatype *ct)
Generate a generic name for an unnamed data-type.
Definition: printc.cc:3072
PrintC::pushEnumConstant
void pushEnumConstant(uintb val, const TypeEnum *ct, const Varnode *vn, const PcodeOp *op)
Push an enumerated value to the RPN stack.
Definition: printc.cc:1432
BlockWhileDo
A loop structure where the condition is checked at the top.
Definition: block.hh:590
PrintC::nullToken
string nullToken
Token to use for 'null'.
Definition: printc.hh:122
PrintC::push_integer
virtual void push_integer(uintb val, int4 sz, bool sign, const Varnode *vn, const PcodeOp *op)
Push a constant with an integer data-type to the RPN stack.
Definition: printc.cc:1084
PrintC::opFloatEqual
virtual void opFloatEqual(const PcodeOp *op)
Emit a FLOAT_EQUAL operator.
Definition: printc.hh:270
PrintC::opFloatNotEqual
virtual void opFloatNotEqual(const PcodeOp *op)
Emit a FLOAT_NOTEQUAL operator.
Definition: printc.hh:271
PrintC::opFloatDiv
virtual void opFloatDiv(const PcodeOp *op)
Emit a FLOAT_DIV operator.
Definition: printc.hh:276
PrintC::opIntSrem
virtual void opIntSrem(const PcodeOp *op)
Emit a INT_SREM operator.
Definition: printc.hh:265
BlockIf
A basic "if" block.
Definition: block.hh:555
PrintC::multequal
static OpToken multequal
The in-place multiplication operator.
Definition: printc.hh:101
PrintC::opBoolAnd
virtual void opBoolAnd(const PcodeOp *op)
Emit a BOOL_AND operator.
Definition: printc.hh:268
PrintC::plusequal
static OpToken plusequal
The in-place addition operator.
Definition: printc.hh:104
PrintLanguageCapability
Base class for high-level language capabilities.
Definition: printlanguage.hh:39
PrintC::opStore
virtual void opStore(const PcodeOp *op)
Emit a STORE operator.
Definition: printc.cc:415
PrintC::comma
static OpToken comma
The comma operator (for parameter lists)
Definition: printc.hh:99
PrintLanguage::setCommentDelimeter
void setCommentDelimeter(const string &start, const string &stop, bool usecommentfill)
Establish comment delimiters for the language.
Definition: printlanguage.cc:93
PrintC::new_op
static OpToken new_op
The new operator.
Definition: printc.hh:100
PartialSymbolEntry::hilite
EmitXml::syntax_highlight hilite
Highlight information for the field token.
Definition: printc.hh:50
PrintC::emitBlockIf
virtual void emitBlockIf(const BlockIf *bl)
Emit an if/else style construct.
Definition: printc.cc:2575
PrintC::pushPartialSymbol
virtual void pushPartialSymbol(const Symbol *sym, int4 off, int4 sz, const Varnode *vn, const PcodeOp *op, Datatype *outtype)
Push a variable that represents only part of a symbol onto the RPN stack.
Definition: printc.cc:1708
printlanguage.hh
Classes for printing tokens in a high-level language.
PrintC::pushPtrCodeConstant
bool pushPtrCodeConstant(uintb val, const TypePointer *ct, const Varnode *vn, const PcodeOp *op)
Attempt to push a function name representing a constant pointer onto the RPN stack.
Definition: printc.cc:1493
PrintC::ptr_expr
static OpToken ptr_expr
Pointer adornment for a type declaration.
Definition: printc.hh:113
PrintC::opIntSlessEqual
virtual void opIntSlessEqual(const PcodeOp *op)
Emit a INT_SLESSEQUAL operator.
Definition: printc.hh:243
CommentSorter
A class for sorting comments into and within basic blocks.
Definition: comment.hh:190
PrintC::docFunction
virtual void docFunction(const Funcdata *fd)
Emit the declaration (and body) of a function.
Definition: printc.cc:2339
PrintC::opInsertOp
virtual void opInsertOp(const PcodeOp *op)
Emit an INSERT operator.
Definition: printc.cc:1061
PrintC::opIntSdiv
virtual void opIntSdiv(const PcodeOp *op)
Emit a INT_SDIV operator.
Definition: printc.hh:263
PrintC::opBoolNegate
virtual void opBoolNegate(const PcodeOp *op)
Definition: printc.cc:703
PrintC::opCallother
virtual void opCallother(const PcodeOp *op)
Emit a CALLOTHER operator.
Definition: printc.cc:588
PrintC::opCopy
virtual void opCopy(const PcodeOp *op)
Emit a COPY operator.
Definition: printc.cc:396
PrintC::bitwise_or
static OpToken bitwise_or
The logical or operator.
Definition: printc.hh:94
PrintC
The c-language token emitter.
Definition: printc.hh:63
PrintC::opIntOr
virtual void opIntOr(const PcodeOp *op)
Emit a INT_OR operator.
Definition: printc.hh:257
PrintC::divide
static OpToken divide
The division operator.
Definition: printc.hh:79
PrintC::printCharacterConstant
bool printCharacterConstant(ostream &s, const Address &addr, Datatype *charType) const
Print a quoted (unicode) string at the given address.
Definition: printc.cc:1333
PrintC::opCast
virtual void opCast(const PcodeOp *op)
Emit a CAST operator.
Definition: printc.hh:292
PrintC::emitCommentBlockTree
void emitCommentBlockTree(const FlowBlock *bl)
Emit any comments under the given control-flow subtree.
Definition: printc.cc:2945
PrintC::printUnicode
virtual void printUnicode(ostream &s, int4 onechar) const
Print a single unicode character as a character constant for the high-level language.
Definition: printc.cc:1234
PrintC::bitwise_xor
static OpToken bitwise_xor
The logical xor operator.
Definition: printc.hh:93
PrintC::pushAnnotation
virtual void pushAnnotation(const Varnode *vn, const PcodeOp *op)
Push an address which is not in the normal data-flow.
Definition: printc.cc:1618
PrintC::emitLabel
void emitLabel(const FlowBlock *bl)
Emit a formal label for a given control-flow block.
Definition: printc.cc:2862
PrintC::object_member
static OpToken object_member
The member operator.
Definition: printc.hh:67
PartialSymbolEntry
A structure for pushing nested fields to the RPN stack.
Definition: printc.hh:45
PrintC::pointer_member
static OpToken pointer_member
The points to member operator.
Definition: printc.hh:68
PrintC::opIntLessEqual
virtual void opIntLessEqual(const PcodeOp *op)
Emit a INT_LESSEQUAL operator.
Definition: printc.hh:245
PrintC::opIntLess
virtual void opIntLess(const PcodeOp *op)
Emit a INT_LESS operator.
Definition: printc.hh:244
PrintC::commsorter
CommentSorter commsorter
Container/organizer for comments in the current function.
Definition: printc.hh:123
PrintC::remequal
static OpToken remequal
The in-place modulo operator.
Definition: printc.hh:103
PrintC::binary_plus
static OpToken binary_plus
The binary addition operator.
Definition: printc.hh:81
BlockCondition
Two conditional blocks combined into one conditional using BOOL_AND or BOOL_OR.
Definition: block.hh:518
PrintC::opFloatAbs
virtual void opFloatAbs(const PcodeOp *op)
Emit a FLOAT_ABS operator.
Definition: printc.hh:280
PrintC::boolean_and
static OpToken boolean_and
The boolean and operator.
Definition: printc.hh:95
PrintC::opHiddenFunc
void opHiddenFunc(const PcodeOp *op)
Push the given p-code op as a hidden token.
Definition: printc.cc:389
FuncProto
A function prototype.
Definition: fspec.hh:1164
PrintC::emitInplaceOp
bool emitInplaceOp(const PcodeOp *op)
Attempt to emit an expression rooted at an in-place operator.
Definition: printc.cc:2114
PrintC::hidden
static OpToken hidden
Hidden functional (that may force parentheses)
Definition: printc.hh:65
PrintC::opPopcountOp
virtual void opPopcountOp(const PcodeOp *op)
Emit a POPCOUNT operator.
Definition: printc.hh:300
PrintC::opNewOp
virtual void opNewOp(const PcodeOp *op)
Emit a NEW operator.
Definition: printc.cc:1027
PrintC::opFloatMult
virtual void opFloatMult(const PcodeOp *op)
Emit a FLOAT_MULT operator.
Definition: printc.hh:277
PrintC::emitBlockCondition
virtual void emitBlockCondition(const BlockCondition *bl)
Emit a conditional statement.
Definition: printc.cc:2539
PrintC::opFloatFloat2Float
virtual void opFloatFloat2Float(const PcodeOp *op)
Emit a FLOAT_FLOAT2FLOAT operator.
Definition: printc.hh:283
OpToken
A token representing an operator in the high-level language.
Definition: printlanguage.hh:81
PrintC::shift_sright
static OpToken shift_sright
The signed right shift operator.
Definition: printc.hh:85
PrintC::checkArrayDeref
bool checkArrayDeref(const Varnode *vn) const
Determine whether a LOAD/STORE expression requires pointer '*' syntax.
Definition: printc.cc:325
PrintC::pushUnnamedLocation
virtual void pushUnnamedLocation(const Address &addr, const Varnode *vn, const PcodeOp *op)
Push an address as a substitute for a Symbol onto the RPN stack.
Definition: printc.cc:1699
PrintC::setCommentStyle
virtual void setCommentStyle(const string &nm)
Set the way comments are displayed in decompiler output.
Definition: printc.cc:2046
Symbol
The base class for a symbol in a symbol table or scope.
Definition: database.hh:152
PrintC::emitVarDecl
virtual void emitVarDecl(const Symbol *sym)
Emit a variable declaration.
Definition: printc.cc:2193
PrintC::opIntRem
virtual void opIntRem(const PcodeOp *op)
Emit a INT_REM operator.
Definition: printc.hh:264
PrintC::opBranchind
virtual void opBranchind(const PcodeOp *op)
Emit a BRANCHIND operator.
Definition: printc.cc:497
PrintC::opIntZext
virtual void opIntZext(const PcodeOp *op, const PcodeOp *readOp)
Emit a INT_ZEXT operator.
Definition: printc.cc:675
PrintC::type_expr_space
static OpToken type_expr_space
Type declaration involving a space (identifier or adornment)
Definition: printc.hh:111
PrintC::pushMismatchSymbol
virtual void pushMismatchSymbol(const Symbol *sym, int4 off, int4 sz, const Varnode *vn, const PcodeOp *op)
Push an identifier for a variable that mismatches with its Symbol.
Definition: printc.cc:1797
PrintC::opFunc
void opFunc(const PcodeOp *op)
Push a functional expression based on the given p-code op to the RPN stack.
Definition: printc.cc:347
BlockSwitch
A structured switch construction.
Definition: block.hh:649
PrintC::boolean_xor
static OpToken boolean_xor
The boolean xor operator.
Definition: printc.hh:97
BlockCopy
This class is used to mirror the BlockBasic objects in the fixed control-flow graph for a function.
Definition: block.hh:419
PrintC::subscript
static OpToken subscript
The array subscript operator.
Definition: printc.hh:69
PrintC::opIntAdd
virtual void opIntAdd(const PcodeOp *op)
Emit a INT_ADD operator.
Definition: printc.hh:248
PrintC::opLoad
virtual void opLoad(const PcodeOp *op)
Emit a LOAD operator.
Definition: printc.cc:402