Ghidra Decompiler Analysis Engine
funcdata.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  */
16 #ifndef __CPUI_FUNCDATA__
17 #define __CPUI_FUNCDATA__
18 
21 
22 #include "architecture.hh"
23 #include "override.hh"
24 #include "heritage.hh"
25 #include "merge.hh"
26 #include "dynamic.hh"
27 
28 class FlowInfo;
29 
45 class Funcdata {
46  enum {
47  highlevel_on = 1,
48  blocks_generated = 2,
49  blocks_unreachable = 4,
50  processing_started = 8,
51  processing_complete = 0x10,
52  typerecovery_on = 0x20,
53  no_code = 0x40,
54  jumptablerecovery_on = 0x80,
55  jumptablerecovery_dont = 0x100,
56  restart_pending = 0x200,
57  unimplemented_present = 0x400,
58  baddata_present = 0x800,
59  double_precis_on = 0x1000
60  };
61  uint4 flags;
62  uint4 clean_up_index;
63  uint4 high_level_index;
64  uint4 cast_phase_index;
65  uint4 minLanedSize;
66  int4 size;
67  Architecture *glb;
68  FunctionSymbol *functionSymbol;
69  string name;
70  Address baseaddr;
71  FuncProto funcp;
72  ScopeLocal *localmap;
73 
74  vector<FuncCallSpecs *> qlst;
75  vector<JumpTable *> jumpvec;
76 
77  VarnodeBank vbank;
78  PcodeOpBank obank;
79  BlockGraph bblocks;
80  BlockGraph sblocks;
81  Heritage heritage;
82  Merge covermerge;
83  ParamActive *activeoutput;
84  Override localoverride;
85  map<VarnodeData,const LanedRegister *> lanedMap;
86 
87  // Low level Varnode functions
88  void setVarnodeProperties(Varnode *vn) const;
89  HighVariable *assignHigh(Varnode *vn);
90  Symbol *handleSymbolConflict(SymbolEntry *entry,Varnode *vn);
91  bool syncVarnodesWithSymbol(VarnodeLocSet::const_iterator &iter,uint4 flags,Datatype *ct);
92  bool descend2Undef(Varnode *vn);
93 
94  void splitUses(Varnode *vn);
95  Varnode *cloneVarnode(const Varnode *vn);
96  void destroyVarnode(Varnode *vn);
97  void coverVarnodes(SymbolEntry *entry,vector<Varnode *> &list);
98  // Low level op functions
99  void opZeroMulti(PcodeOp *op);
100  // Low level block functions
101  void blockRemoveInternal(BlockBasic *bb,bool unreachable);
102  void branchRemoveInternal(BlockBasic *bb,int4 num);
103  void pushMultiequals(BlockBasic *bb);
104  void clearBlocks(void);
105  void structureReset(void);
106  int4 stageJumpTable(JumpTable *jt,PcodeOp *op,FlowInfo *flow);
107  void switchOverJumpTables(const FlowInfo &flow);
108  void clearJumpTables(void);
109 
110  void sortCallSpecs(void);
111  void deleteCallSpecs(PcodeOp *op);
112  void clearCallSpecs(void);
113 
114  BlockBasic *nodeSplitBlockEdge(BlockBasic *b,int4 inedge);
115  PcodeOp *nodeSplitCloneOp(PcodeOp *op);
116  void nodeSplitCloneVarnode(PcodeOp *op,PcodeOp *newop);
117  void nodeSplitRawDuplicate(BlockBasic *b,BlockBasic *bprime);
118  void nodeSplitInputPatch(BlockBasic *b,BlockBasic *bprime,int4 inedge);
119  static bool descendantsOutside(Varnode *vn);
120  static void saveVarnodeXml(ostream &s,VarnodeLocSet::const_iterator iter,VarnodeLocSet::const_iterator enditer);
121  static bool checkIndirectUse(Varnode *vn);
122  static PcodeOp *findPrimaryBranch(PcodeOpTree::const_iterator iter,PcodeOpTree::const_iterator enditer,
123  bool findbranch,bool findcall,bool findreturn);
124 public:
125  Funcdata(const string &nm,Scope *conf,const Address &addr,FunctionSymbol *sym,int4 sz=0);
126  ~Funcdata(void);
127  const string &getName(void) const { return name; }
128  const Address &getAddress(void) const { return baseaddr; }
129  int4 getSize(void) const { return size; }
130  Architecture *getArch(void) const { return glb; }
131  FunctionSymbol *getSymbol(void) const { return functionSymbol; }
132  bool isHighOn(void) const { return ((flags&highlevel_on)!=0); }
133  bool isProcStarted(void) const { return ((flags&processing_started)!=0); }
134  bool isProcComplete(void) const { return ((flags&processing_complete)!=0); }
135  bool hasUnreachableBlocks(void) const { return ((flags&blocks_unreachable)!=0); }
136  bool isTypeRecoveryOn(void) const { return ((flags&typerecovery_on)!=0); }
137  bool hasNoCode(void) const { return ((flags & no_code)!=0); }
138  void setNoCode(bool val) { if (val) flags |= no_code; else flags &= ~no_code; }
139  void setLanedRegGenerated(void) { minLanedSize = 1000000; }
140 
144  void setJumptableRecovery(bool val) { if (val) flags &= ~jumptablerecovery_dont; else flags |= jumptablerecovery_dont; }
145 
146  bool isJumptableRecoveryOn(void) const { return ((flags & jumptablerecovery_on)!=0); }
147 
151  void setDoublePrecisRecovery(bool val) { if (val) flags |= double_precis_on; else flags &= ~double_precis_on; }
152 
153  bool isDoublePrecisOn(void) const { return ((flags & double_precis_on)!=0); }
154  bool hasNoStructBlocks(void) const { return (sblocks.getSize() == 0); }
155  void clear(void);
156  void warning(const string &txt,const Address &ad) const;
157  void warningHeader(const string &txt) const;
158  void startProcessing(void);
159  void stopProcessing(void);
160  bool startTypeRecovery(void);
161  void startCastPhase(void) { cast_phase_index = vbank.getCreateIndex(); }
162  uint4 getCastPhaseIndex(void) const { return cast_phase_index; }
163  uint4 getHighLevelIndex(void) const { return high_level_index; }
164  void startCleanUp(void) { clean_up_index = vbank.getCreateIndex(); }
165  uint4 getCleanUpIndex(void) const { return clean_up_index; }
166 
167  void followFlow(const Address &baddr,const Address &eadddr);
168  void truncatedFlow(const Funcdata *fd,const FlowInfo *flow);
169  bool inlineFlow(Funcdata *inlinefd,FlowInfo &flow,PcodeOp *callop);
170  void overrideFlow(const Address &addr,uint4 type);
171  void doLiveInject(InjectPayload *payload,const Address &addr,BlockBasic *bl,list<PcodeOp *>::iterator pos);
172 
173  void printRaw(ostream &s) const;
174  void printVarnodeTree(ostream &s) const;
175  void printBlockTree(ostream &s) const;
176  void printLocalRange(ostream &s) const;
177  void saveXml(ostream &s,uint8 id,bool savetree) const;
178  uint8 restoreXml(const Element *el);
179  void saveXmlJumpTable(ostream &s) const;
180  void restoreXmlJumpTable(const Element *el);
181  void saveXmlTree(ostream &s) const;
182  void saveXmlHigh(ostream &s) const;
183 
184  Override &getOverride(void) { return localoverride; }
185 
189  void setRestartPending(bool val) { flags = val ? (flags|restart_pending) : (flags & ~((uint4)restart_pending)); }
190 
194  bool hasRestartPending(void) const { return ((flags&restart_pending)!=0); }
195 
199  bool hasUnimplemented(void) const { return ((flags&unimplemented_present)!=0); }
200 
201  bool hasBadData(void) const { return ((flags&baddata_present)!=0); }
202  void spacebase(void);
205  void spacebaseConstant(PcodeOp *op,int4 slot,SymbolEntry *entry,const Address &rampoint,uintb origval,int4 origsize);
206 
207  int4 getHeritagePass(void) const { return heritage.getPass(); }
208 
213  int4 numHeritagePasses(AddrSpace *spc) { return heritage.numHeritagePasses(spc); }
214 
218  void seenDeadcode(AddrSpace *spc) { heritage.seenDeadCode(spc); }
219 
224  void setDeadCodeDelay(AddrSpace *spc,int4 delay) { heritage.setDeadCodeDelay(spc,delay); }
225 
230  bool deadRemovalAllowed(AddrSpace *spc) const { return heritage.deadRemovalAllowed(spc); }
231 
236  bool deadRemovalAllowedSeen(AddrSpace *spc) { return heritage.deadRemovalAllowedSeen(spc); }
237 
242  bool isHeritaged(Varnode *vn) { return (heritage.heritagePass(vn->getAddr())>=0); }
243 
244  const list<LoadGuard> &getLoadGuards(void) const { return heritage.getLoadGuards(); }
245  const list<LoadGuard> &getStoreGuards(void) const { return heritage.getStoreGuards(); }
246  const LoadGuard *getStoreGuard(PcodeOp *op) const { return heritage.getStoreGuard(op); }
247 
248  // Function prototype and call specification routines
249  int4 numCalls(void) const { return qlst.size(); }
250  FuncCallSpecs *getCallSpecs(int4 i) const { return qlst[i]; }
251  FuncCallSpecs *getCallSpecs(const PcodeOp *op) const;
252  int4 fillinExtrapop(void);
253 
254  // Varnode routines
255  int4 numVarnodes(void) const { return vbank.numVarnodes(); }
256  Varnode *newVarnodeOut(int4 s,const Address &m,PcodeOp *op);
257  Varnode *newUniqueOut(int4 s,PcodeOp *op);
258  Varnode *newVarnode(int4 s,const Address &m,Datatype *ct=(Datatype *)0);
259  Varnode *newConstant(int4 s,uintb constant_val);
260  Varnode *newVarnode(int4 s,AddrSpace *base,uintb off);
264  Varnode *newUnique(int4 s,Datatype *ct=(Datatype *)0);
265  Varnode *newCodeRef(const Address &m);
267  void adjustInputVarnodes(const Address &addr,int4 size);
268  void deleteVarnode(Varnode *vn) { vbank.destroy(vn); }
269 
270  Address findDisjointCover(Varnode *vn,int4 &sz);
271 
277  Varnode *findCoveredInput(int4 s,const Address &loc) const { return vbank.findCoveredInput(s,loc); }
278 
284  Varnode *findCoveringInput(int4 s,const Address &loc) const { return vbank.findCoveringInput(s,loc); }
285 
291  Varnode *findVarnodeInput(int4 s,const Address &loc) const { return vbank.findInput(s,loc); }
292 
300  Varnode *findVarnodeWritten(int4 s,const Address &loc,const Address &pc,uintm uniq=~((uintm)0)) const {
301  return vbank.find(s,loc,pc,uniq); }
302 
304  VarnodeLocSet::const_iterator beginLoc(void) const { return vbank.beginLoc(); }
305 
307  VarnodeLocSet::const_iterator endLoc(void) const { return vbank.endLoc(); }
308 
310  VarnodeLocSet::const_iterator beginLoc(AddrSpace *spaceid) const { return vbank.beginLoc(spaceid); }
311 
313  VarnodeLocSet::const_iterator endLoc(AddrSpace *spaceid) const { return vbank.endLoc(spaceid); }
314 
316  VarnodeLocSet::const_iterator beginLoc(const Address &addr) const { return vbank.beginLoc(addr); }
317 
319  VarnodeLocSet::const_iterator endLoc(const Address &addr) const { return vbank.endLoc(addr); }
320 
322  VarnodeLocSet::const_iterator beginLoc(int4 s,const Address &addr) const { return vbank.beginLoc(s,addr); }
323 
325  VarnodeLocSet::const_iterator endLoc(int4 s,const Address &addr) const { return vbank.endLoc(s,addr); }
326 
328  VarnodeLocSet::const_iterator beginLoc(int4 s,const Address &addr,uint4 fl) const { return vbank.beginLoc(s,addr,fl); }
329 
331  VarnodeLocSet::const_iterator endLoc(int4 s,const Address &addr,uint4 fl) const { return vbank.endLoc(s,addr,fl); }
332 
334  VarnodeLocSet::const_iterator beginLoc(int4 s,const Address &addr,const Address &pc,uintm uniq=~((uintm)0)) const {
335  return vbank.beginLoc(s,addr,pc,uniq); }
336 
338  VarnodeLocSet::const_iterator endLoc(int4 s,const Address &addr,const Address &pc,uintm uniq=~((uintm)0)) const {
339  return vbank.endLoc(s,addr,pc,uniq); }
340 
342  VarnodeDefSet::const_iterator beginDef(void) const { return vbank.beginDef(); }
343 
345  VarnodeDefSet::const_iterator endDef(void) const { return vbank.endDef(); }
346 
348  VarnodeDefSet::const_iterator beginDef(uint4 fl) const { return vbank.beginDef(fl); }
349 
351  VarnodeDefSet::const_iterator endDef(uint4 fl) const { return vbank.endDef(fl); }
352 
354  VarnodeDefSet::const_iterator beginDef(uint4 fl,const Address &addr) const { return vbank.beginDef(fl,addr); }
355 
357  VarnodeDefSet::const_iterator endDef(uint4 fl,const Address &addr) const { return vbank.endDef(fl,addr); }
358 
359  void checkForLanedRegister(int4 size,const Address &addr);
360  map<VarnodeData,const LanedRegister *>::const_iterator beginLaneAccess(void) const { return lanedMap.begin(); }
361  map<VarnodeData,const LanedRegister *>::const_iterator endLaneAccess(void) const { return lanedMap.end(); }
362  void clearLanedAccessMap(void) { lanedMap.clear(); }
363 
364  HighVariable *findHigh(const string &name) const;
365  void mapGlobals(void);
366  bool checkCallDoubleUse(const PcodeOp *opmatch,const PcodeOp *op,const Varnode *vn,const ParamTrial &trial) const;
367  bool onlyOpUse(const Varnode *invn,const PcodeOp *opmatch,const ParamTrial &trial) const;
368  bool ancestorOpUse(int4 maxlevel,const Varnode *invn,const PcodeOp *op,ParamTrial &trial) const;
369  bool syncVarnodesWithSymbols(const ScopeLocal *lm,bool typesyes);
370  void transferVarnodeProperties(Varnode *vn,Varnode *newVn,int4 lsbOffset);
371  bool fillinReadOnly(Varnode *vn);
372  bool replaceVolatile(Varnode *vn);
373  void markIndirectOnly(void);
374  void totalReplace(Varnode *vn,Varnode *newvn);
375  void totalReplaceConstant(Varnode *vn,uintb val);
376  ScopeLocal *getScopeLocal(void) { return localmap; }
377  const ScopeLocal *getScopeLocal(void) const { return localmap; }
378  FuncProto &getFuncProto(void) { return funcp; }
379  const FuncProto &getFuncProto(void) const { return funcp; }
380  void initActiveOutput(void);
381  void clearActiveOutput(void) {
383  if (activeoutput != (ParamActive *)0) delete activeoutput;
384  activeoutput = (ParamActive *)0;
385  }
386  ParamActive *getActiveOutput(void) const { return activeoutput; }
387  void setHighLevel(void);
388  void clearDeadVarnodes(void);
389  void calcNZMask(void);
390  void clearDeadOps(void) { obank.destroyDead(); }
391  void clearSymbolLinks(HighVariable *high);
392  void remapVarnode(Varnode *vn,Symbol *sym,const Address &usepoint);
393  void remapDynamicVarnode(Varnode *vn,Symbol *sym,const Address &usepoint,uint8 hash);
394  Symbol *linkSymbol(Varnode *vn);
396  Varnode *findLinkedVarnode(SymbolEntry *entry) const;
397  void findLinkedVarnodes(SymbolEntry *entry,vector<Varnode *> &res) const;
398  void buildDynamicSymbol(Varnode *vn);
399  bool attemptDynamicMapping(SymbolEntry *entry,DynamicHash &dhash);
401  Merge &getMerge(void) { return covermerge; }
402 
403  // op routines
404  PcodeOp *newOp(int4 inputs,const Address &pc);
405  PcodeOp *newOp(int4 inputs,const SeqNum &sq);
406  PcodeOp *newOpBefore(PcodeOp *follow,OpCode opc,Varnode *in1,Varnode *in2,Varnode *in3=(Varnode *)0);
407  PcodeOp *cloneOp(const PcodeOp *op,const SeqNum &seq);
408  PcodeOp *getFirstReturnOp(void) const;
409  PcodeOp *newIndirectOp(PcodeOp *indeffect,const Address &addr,int4 size,uint4 extraFlags);
410  PcodeOp *newIndirectCreation(PcodeOp *indeffect,const Address &addr,int4 size,bool possibleout);
411  void markIndirectCreation(PcodeOp *indop,bool possibleOutput);
412  PcodeOp *findOp(const SeqNum &sq) { return obank.findOp(sq); }
413  void opInsertBefore(PcodeOp *op,PcodeOp *follow);
414  void opInsertAfter(PcodeOp *op,PcodeOp *prev);
415  void opInsertBegin(PcodeOp *op,BlockBasic *bl);
416  void opInsertEnd(PcodeOp *op,BlockBasic *bl);
417 
419  void opDeadInsertAfter(PcodeOp *op,PcodeOp *prev) { obank.insertAfterDead(op,prev); }
420 
421  void opHeritage(void) { heritage.heritage(); }
422  void opSetOpcode(PcodeOp *op,OpCode opc);
423  void opMarkHalt(PcodeOp *op,uint4 flag);
424  void opSetOutput(PcodeOp *op,Varnode *vn);
425  void opUnsetOutput(PcodeOp *op);
426  void opSetInput(PcodeOp *op,Varnode *vn,int4 slot);
427  void opSwapInput(PcodeOp *op,int4 slot1,int4 slot2);
428  void opUnsetInput(PcodeOp *op,int4 slot);
429  void opInsert(PcodeOp *op,BlockBasic *bl,list<PcodeOp *>::iterator iter);
430  void opUninsert(PcodeOp *op);
431  void opUnlink(PcodeOp *op);
432  void opDestroy(PcodeOp *op);
433  void opDestroyRaw(PcodeOp *op);
434  void opDeadAndGone(PcodeOp *op) { obank.destroy(op); }
435  void opSetAllInput(PcodeOp *op,const vector<Varnode *> &vvec);
436  void opRemoveInput(PcodeOp *op,int4 slot);
437  void opInsertInput(PcodeOp *op,Varnode *vn,int4 slot);
438  void opMarkStartBasic(PcodeOp *op) { op->setFlag(PcodeOp::startbasic); }
439  void opMarkStartInstruction(PcodeOp *op) { op->setFlag(PcodeOp::startmark); }
440  void opMarkNonPrinting(PcodeOp *op) { op->setFlag(PcodeOp::nonprinting); }
441  void opMarkSpecialPrint(PcodeOp *op) { op->setAdditionalFlag(PcodeOp::special_print); }
442  void opMarkNoCollapse(PcodeOp *op) { op->setFlag(PcodeOp::nocollapse); }
443  void opMarkCpoolTransformed(PcodeOp *op) { op->setAdditionalFlag(PcodeOp::is_cpool_transformed); }
444  void opMarkCalculatedBool(PcodeOp *op) { op->setFlag(PcodeOp::calculated_bool); }
445  void opMarkSpacebasePtr(PcodeOp *op) { op->setFlag(PcodeOp::spacebase_ptr); }
446  void opClearSpacebasePtr(PcodeOp *op) { op->clearFlag(PcodeOp::spacebase_ptr); }
447  void opFlipCondition(PcodeOp *op) { op->flipFlag(PcodeOp::boolean_flip); }
448  PcodeOp *target(const Address &addr) const { return obank.target(addr); }
449  Varnode *createStackRef(AddrSpace *spc,uintb off,PcodeOp *op,Varnode *stackptr,bool insertafter);
450  Varnode *opStackLoad(AddrSpace *spc,uintb off,uint4 sz,PcodeOp *op,Varnode *stackptr,bool insertafter);
451  PcodeOp *opStackStore(AddrSpace *spc,uintb off,PcodeOp *op,bool insertafter);
452  void opUndoPtradd(PcodeOp *op,bool finalize);
453 
455  list<PcodeOp *>::const_iterator beginOp(OpCode opc) const { return obank.begin(opc); }
456 
458  list<PcodeOp *>::const_iterator endOp(OpCode opc) const { return obank.end(opc); }
459 
461  list<PcodeOp *>::const_iterator beginOpAlive(void) const { return obank.beginAlive(); }
462 
464  list<PcodeOp *>::const_iterator endOpAlive(void) const { return obank.endAlive(); }
465 
467  list<PcodeOp *>::const_iterator beginOpDead(void) const { return obank.beginDead(); }
468 
470  list<PcodeOp *>::const_iterator endOpDead(void) const { return obank.endDead(); }
471 
473  PcodeOpTree::const_iterator beginOpAll(void) const { return obank.beginAll(); }
474 
476  PcodeOpTree::const_iterator endOpAll(void) const { return obank.endAll(); }
477 
479  PcodeOpTree::const_iterator beginOp(const Address &addr) const { return obank.begin(addr); }
480 
482  PcodeOpTree::const_iterator endOp(const Address &addr) const { return obank.end(addr); }
483 
484  bool moveRespectingCover(PcodeOp *op,PcodeOp *lastOp);
485 
486  // Jumptable routines
488  JumpTable *findJumpTable(const PcodeOp *op) const;
489  JumpTable *installJumpTable(const Address &addr);
490  JumpTable *recoverJumpTable(PcodeOp *op,FlowInfo *flow,int4 &failuremode);
491  int4 numJumpTables(void) const { return jumpvec.size(); }
492  JumpTable *getJumpTable(int4 i) { return jumpvec[i]; }
493  void removeJumpTable(JumpTable *jt);
494 
495  // Block routines
496  BlockGraph &getStructure(void) { return sblocks; }
497  const BlockGraph &getStructure(void) const { return sblocks; }
498  const BlockGraph &getBasicBlocks(void) const { return bblocks; }
499 
505  void setBasicBlockRange(BlockBasic *bb,const Address &beg,const Address &end) { bb->setInitialRange(beg, end); }
506 
507  void removeDoNothingBlock(BlockBasic *bb);
508  bool removeUnreachableBlocks(bool issuewarning,bool checkexistence);
509  void pushBranch(BlockBasic *bb,int4 slot,BlockBasic *bbnew);
510  void removeBranch(BlockBasic *bb,int4 num);
512  bool fora_block1ishigh,bool forb_block1ishigh,const Address &addr);
513  void nodeSplit(BlockBasic *b,int4 inedge);
514  bool forceGoto(const Address &pcop,const Address &pcdest);
515  void removeFromFlowSplit(BlockBasic *bl,bool swap);
516  void switchEdge(FlowBlock *inblock,BlockBasic *outbefore,FlowBlock *outafter);
517  void spliceBlockBasic(BlockBasic *bl);
518  void installSwitchDefaults(void);
519  bool replaceLessequal(PcodeOp *op);
520  bool distributeIntMultAdd(PcodeOp *op);
521  bool collapseIntMultMult(Varnode *vn);
522  static bool compareCallspecs(const FuncCallSpecs *a,const FuncCallSpecs *b);
523 
524 #ifdef OPACTION_DEBUG
525  void (*jtcallback)(Funcdata &orig,Funcdata &fd);
526  vector<PcodeOp *> modify_list;
527  vector<string> modify_before;
528  int4 opactdbg_count;
529  int4 opactdbg_breakcount;
530  bool opactdbg_on;
531  bool opactdbg_active;
532  bool opactdbg_breakon;
533  vector<Address> opactdbg_pclow;
534  vector<Address> opactdbg_pchigh;
535  vector<uintm> opactdbg_uqlow;
536  vector<uintm> opactdbg_uqhigh;
537  void enableJTCallback(void (*jtcb)(Funcdata &orig,Funcdata &fd)) { jtcallback = jtcb; }
538  void disableJTCallback(void) { jtcallback = (void (*)(Funcdata &orig,Funcdata &fd))0; }
539  void debugActivate(void) { if (opactdbg_on) opactdbg_active=true; }
540  void debugDeactivate(void) { opactdbg_active = false; }
541  void debugModCheck(PcodeOp *op);
542  void debugModClear(void);
543  void debugModPrint(const string &actionname);
544  bool debugBreak(void) const { return opactdbg_on&&opactdbg_breakon; }
545  int4 debugSize(void) const { return opactdbg_pclow.size(); }
546  void debugEnable(void) { opactdbg_on = true; opactdbg_count = 0; }
547  void debugDisable(void) { opactdbg_on = false; }
548  void debugClear(void) {
549  opactdbg_pclow.clear(); opactdbg_pchigh.clear(); opactdbg_uqlow.clear(); opactdbg_uqhigh.clear(); }
550  bool debugCheckRange(PcodeOp *op);
551  void debugSetRange(const Address &pclow,const Address &pchigh,
552  uintm uqlow=~((uintm)0),uintm uqhigh=~((uintm)0));
553  void debugHandleBreak(void) { opactdbg_breakon = false; }
554  void debugSetBreak(int4 count) { opactdbg_breakcount = count; }
555  void debugPrintRange(int4 i) const;
556 #endif
557 };
558 
563 class PcodeEmitFd : public PcodeEmit {
564  Funcdata *fd;
565  virtual void dump(const Address &addr,OpCode opc,VarnodeData *outvar,VarnodeData *vars,int4 isize);
566 public:
567  void setFuncdata(Funcdata *f) { fd = f; }
568 };
569 
578  class State {
579  public:
580  enum {
581  seen_solid0 = 1,
582  seen_solid1 = 2,
583  seen_kill = 4
584  };
585  PcodeOp *op;
586  Varnode *vn;
587  int4 slot;
588  uint4 flags;
589 
594  State(PcodeOp *o,int4 s) {
595  op = o;
596  slot = s;
597  vn = op->getIn(slot);
598  flags = 0;
599  }
600  int4 getSolidSlot(void) const { return ((flags & seen_solid0)!=0) ? 0 : 1; }
601  void markSolid(int4 slot) { flags |= (slot==0) ? seen_solid0 : seen_solid1; }
602  void markKill(void) { flags |= seen_kill; }
603  bool seenSolid(void) const { return ((flags & (seen_solid0|seen_solid1))!=0); }
604  bool seenKill(void) const { return ((flags & seen_kill)!=0); }
605  };
607  enum {
608  enter_node,
609  pop_success,
610  pop_solid,
611  pop_fail,
612  pop_failkill
613  };
614  ParamTrial *trial;
615  vector<State> stateStack;
616  vector<const Varnode *> markedVn;
617  int4 multiDepth;
618  bool allowFailingPath;
619 
623  void mark(Varnode *vn) {
624  markedVn.push_back(vn);
625  vn->setMark();
626  }
627 
628  int4 enterNode(State &state);
629  int4 uponPop(State &state,int4 command);
630  bool checkConditionalExe(State &state);
631 public:
632  bool execute(PcodeOp *op,int4 slot,ParamTrial *t,bool allowFail);
633 };
634 
635 extern int4 opFlipInPlaceTest(PcodeOp *op,vector<PcodeOp *> &fliplist);
636 extern void opFlipInPlaceExecute(Funcdata &data,vector<PcodeOp *> &fliplist);
637 
639 extern PcodeOp *cseFindInBlock(PcodeOp *op,Varnode *vn,BlockBasic *bl,PcodeOp *earliest);
640 extern PcodeOp *cseElimination(Funcdata &data,PcodeOp *op1,PcodeOp *op2);
641 extern void cseEliminateList(Funcdata &data,vector< pair<uintm,PcodeOp *> > &list,
642  vector<Varnode *> &outlist);
643 
644 #endif
Funcdata::spacebase
void spacebase(void)
Mark registers that map to a virtual address space.
Definition: funcdata.cc:214
Funcdata::recoverJumpTable
JumpTable * recoverJumpTable(PcodeOp *op, FlowInfo *flow, int4 &failuremode)
Recover destinations for a BRANCHIND by analyzing nearby data and control-flow.
Definition: funcdata_block.cc:559
Funcdata::newVarnodeOut
Varnode * newVarnodeOut(int4 s, const Address &m, PcodeOp *op)
Create a new output Varnode.
Definition: funcdata_varnode.cc:102
Funcdata::clearSymbolLinks
void clearSymbolLinks(HighVariable *high)
Clear Symbols attached to Varnodes in the given HighVariable.
Definition: funcdata_varnode.cc:975
Heritage::deadRemovalAllowed
bool deadRemovalAllowed(AddrSpace *spc) const
Return true if it is safe to remove dead code.
Definition: heritage.cc:2469
Funcdata::markIndirectCreation
void markIndirectCreation(PcodeOp *indop, bool possibleOutput)
Convert CPUI_INDIRECT into an indirect creation.
Definition: funcdata_op.cc:689
Funcdata::opSetAllInput
void opSetAllInput(PcodeOp *op, const vector< Varnode * > &vvec)
Set all input Varnodes for the given PcodeOp simultaneously.
Definition: funcdata_op.cc:240
PcodeOpBank::begin
PcodeOpTree::const_iterator begin(const Address &addr) const
Start of all PcodeOps at one Address.
Definition: op.cc:1003
PcodeEmit
Abstract class for emitting pcode to an application.
Definition: translate.hh:76
Funcdata::Funcdata
Funcdata(const string &nm, Scope *conf, const Address &addr, FunctionSymbol *sym, int4 sz=0)
Constructor.
Definition: funcdata.cc:24
Funcdata::switchEdge
void switchEdge(FlowBlock *inblock, BlockBasic *outbefore, FlowBlock *outafter)
Switch an outgoing edge from the given source block to flow into another block.
Definition: funcdata_block.cc:960
ParamTrial
A register or memory register that may be used to pass a parameter or return value.
Definition: fspec.hh:156
BlockGraph
A control-flow block built out of sub-components.
Definition: block.hh:271
Funcdata::findJumpTable
JumpTable * findJumpTable(const PcodeOp *op) const
Find a jump-table associated with a given BRANCHIND.
Definition: funcdata_block.cc:440
Funcdata::forceGoto
bool forceGoto(const Address &pcop, const Address &pcdest)
Force a specific control-flow edge to be marked as unstructured.
Definition: funcdata_block.cc:658
merge.hh
Utilities for merging low-level Varnodes into high-level variables.
AddrSpace
A region where processor data is stored.
Definition: space.hh:73
Funcdata::opInsert
void opInsert(PcodeOp *op, BlockBasic *bl, list< PcodeOp * >::iterator iter)
Insert the given PcodeOp at specific point in a basic block.
Definition: funcdata_op.cc:148
FlowBlock
Description of a control-flow block containing PcodeOps.
Definition: block.hh:60
Funcdata::adjustInputVarnodes
void adjustInputVarnodes(const Address &addr, int4 size)
Adjust input Varnodes contained in the given range.
Definition: funcdata_varnode.cc:381
VarnodeBank::find
Varnode * find(int4 s, const Address &loc, const Address &pc, uintm uniq=~((uintm) 0)) const
Find a Varnode.
Definition: varnode.cc:1074
Funcdata::newUnique
Varnode * newUnique(int4 s, Datatype *ct=(Datatype *) 0)
Create a new temporary Varnode.
Definition: funcdata_varnode.cc:81
Funcdata::hasUnimplemented
bool hasUnimplemented(void) const
Does this function have instructions marked as unimplemented.
Definition: funcdata.hh:199
Funcdata::opSetOutput
void opSetOutput(PcodeOp *op, Varnode *vn)
Set a specific output Varnode for the given PcodeOp.
Definition: funcdata_op.cc:68
Funcdata::setJumptableRecovery
void setJumptableRecovery(bool val)
Toggle whether this is being used for jump-table recovery.
Definition: funcdata.hh:144
Funcdata::beginOpAll
PcodeOpTree::const_iterator beginOpAll(void) const
Start of all (alive) PcodeOp objects sorted by sequence number.
Definition: funcdata.hh:473
Heritage::deadRemovalAllowedSeen
bool deadRemovalAllowedSeen(AddrSpace *spc)
Check if dead code removal is safe and mark that removal has happened.
Definition: heritage.cc:2483
Funcdata::beginLoc
VarnodeLocSet::const_iterator beginLoc(int4 s, const Address &addr) const
Start of Varnodes with given storage.
Definition: funcdata.hh:322
Funcdata::beginOpAlive
list< PcodeOp * >::const_iterator beginOpAlive(void) const
Start of PcodeOp objects in the alive list.
Definition: funcdata.hh:461
VarnodeBank::endLoc
VarnodeLocSet::const_iterator endLoc(AddrSpace *spaceid) const
Ending of Varnodes in given address space sorted by location.
Definition: varnode.cc:1182
SeqNum
A class for uniquely labelling and comparing PcodeOps.
Definition: address.hh:111
Funcdata::fillinExtrapop
int4 fillinExtrapop(void)
Recover and return the extrapop for this function.
Definition: funcdata.cc:479
PcodeOpBank::endDead
list< PcodeOp * >::const_iterator endDead(void) const
End of all PcodeOps marked as dead.
Definition: op.hh:309
Funcdata::endDef
VarnodeDefSet::const_iterator endDef(void) const
End of all Varnodes sorted by definition address.
Definition: funcdata.hh:345
Funcdata::endLoc
VarnodeLocSet::const_iterator endLoc(int4 s, const Address &addr) const
End of Varnodes with given storage.
Definition: funcdata.hh:325
Funcdata::removeUnreachableBlocks
bool removeUnreachableBlocks(bool issuewarning, bool checkexistence)
Remove any unreachable basic blocks.
Definition: funcdata_block.cc:341
Funcdata::endLoc
VarnodeLocSet::const_iterator endLoc(AddrSpace *spaceid) const
End of Varnodes stored in a given address space.
Definition: funcdata.hh:313
Funcdata::saveXmlTree
void saveXmlTree(ostream &s) const
Save an XML description of the p-code tree to stream.
Definition: funcdata.cc:625
Funcdata::opUnsetOutput
void opUnsetOutput(PcodeOp *op)
Remove output Varnode from the given PcodeOp.
Definition: funcdata_op.cc:50
JumpTable
A map from values to control-flow targets within a function.
Definition: jumptable.hh:499
Funcdata::setBasicBlockRange
void setBasicBlockRange(BlockBasic *bb, const Address &beg, const Address &end)
Set the initial ownership range for the given basic block.
Definition: funcdata.hh:505
Funcdata::getFirstReturnOp
PcodeOp * getFirstReturnOp(void) const
Clone a PcodeOp into this function.
Definition: funcdata_op.cc:585
PcodeOpBank::target
PcodeOp * target(const Address &addr) const
Find the first executing PcodeOp for a target address.
Definition: op.cc:946
Funcdata::linkSymbolReference
Symbol * linkSymbolReference(Varnode *vn)
Discover and attach Symbol to a constant reference.
Definition: funcdata_varnode.cc:1054
PcodeOpBank
Container class for PcodeOps associated with a single function.
Definition: op.hh:253
Funcdata::spliceBlockBasic
void spliceBlockBasic(BlockBasic *bl)
Merge the given basic block with the block it flows into.
Definition: funcdata_block.cc:971
ScopeLocal
A Symbol scope for local variables of a particular function.
Definition: varmap.hh:196
Funcdata::opDestroy
void opDestroy(PcodeOp *op)
Remove given PcodeOp and destroy its Varnode operands.
Definition: funcdata_op.cc:201
Funcdata::endLoc
VarnodeLocSet::const_iterator endLoc(void) const
End of all Varnodes sorted by storage.
Definition: funcdata.hh:307
Funcdata::markIndirectOnly
void markIndirectOnly(void)
Mark illegal input Varnodes used only in INDIRECTs.
Definition: funcdata_varnode.cc:690
Funcdata::initActiveOutput
void initActiveOutput(void)
Definition: funcdata_varnode.cc:472
earliestUseInBlock
PcodeOp * earliestUseInBlock(Varnode *vn, BlockBasic *bl)
Get the earliest use/read of a Varnode in a specified basic block.
Definition: funcdata_op.cc:1210
Funcdata::endOpDead
list< PcodeOp * >::const_iterator endOpDead(void) const
End of PcodeOp objects in the dead list.
Definition: funcdata.hh:470
cseEliminateList
void cseEliminateList(Funcdata &data, vector< pair< uintm, PcodeOp * > > &list, vector< Varnode * > &outlist)
Perform Common Subexpression Elimination on a list of Varnode descendants.
Definition: funcdata_op.cc:1334
Merge
Class for merging low-level Varnodes into high-level HighVariables.
Definition: merge.hh:80
PcodeOpBank::endAll
PcodeOpTree::const_iterator endAll(void) const
End of all PcodeOps in sequence number order.
Definition: op.hh:291
Funcdata::beginLoc
VarnodeLocSet::const_iterator beginLoc(int4 s, const Address &addr, uint4 fl) const
Start of Varnodes matching storage and properties.
Definition: funcdata.hh:328
Heritage
Manage the construction of Static Single Assignment (SSA) form.
Definition: heritage.hh:170
Funcdata::hasRestartPending
bool hasRestartPending(void) const
Does this function need to restart its analysis.
Definition: funcdata.hh:194
PcodeOpBank::beginDead
list< PcodeOp * >::const_iterator beginDead(void) const
Start of all PcodeOps marked as dead.
Definition: op.hh:306
VarnodeBank::endDef
VarnodeDefSet::const_iterator endDef(uint4 fl) const
End of varnodes with set definition property.
Definition: varnode.cc:1440
Override
A container of commands that override the decompiler's default behavior for a single function.
Definition: override.hh:40
Funcdata::onlyOpUse
bool onlyOpUse(const Varnode *invn, const PcodeOp *opmatch, const ParamTrial &trial) const
Test if the given Varnode seems to only be used by a CALL.
Definition: funcdata_varnode.cc:1527
Funcdata::clearActiveOutput
void clearActiveOutput(void)
Clear any analysis of the function's return prototype.
Definition: funcdata.hh:382
PcodeEmitFd
A p-code emitter for building PcodeOp objects.
Definition: funcdata.hh:563
Funcdata::stopProcessing
void stopProcessing(void)
Mark that processing has completed for this function.
Definition: funcdata.cc:156
Funcdata::attemptDynamicMappingLate
bool attemptDynamicMappingLate(SymbolEntry *entry, DynamicHash &dhash)
Map the name of a dynamic symbol to a Varnode.
Definition: funcdata_varnode.cc:1201
Funcdata::truncatedFlow
void truncatedFlow(const Funcdata *fd, const FlowInfo *flow)
Generate a clone with truncated control-flow given a partial function.
Definition: funcdata_op.cc:745
Funcdata::calcNZMask
void calcNZMask(void)
Calculate non-zero masks for all Varnodes.
Definition: funcdata_varnode.cc:731
cseFindInBlock
PcodeOp * cseFindInBlock(PcodeOp *op, Varnode *vn, BlockBasic *bl, PcodeOp *earliest)
Find a duplicate calculation of a given PcodeOp reading a specific Varnode.
Definition: funcdata_op.cc:1238
Funcdata::totalReplace
void totalReplace(Varnode *vn, Varnode *newvn)
Replace all read references to the first Varnode with a second Varnode.
Definition: funcdata_varnode.cc:1252
Funcdata::endOp
list< PcodeOp * >::const_iterator endOp(OpCode opc) const
End of PcodeOp objects with the given op-code.
Definition: funcdata.hh:458
Funcdata::installJumpTable
JumpTable * installJumpTable(const Address &addr)
Install a new jump-table for the given Address.
Definition: funcdata_block.cc:458
Funcdata::findSpacebaseInput
Varnode * findSpacebaseInput(AddrSpace *id) const
Definition: funcdata.cc:275
Funcdata::beginDef
VarnodeDefSet::const_iterator beginDef(uint4 fl, const Address &addr) const
Start of (input or free) Varnodes at a given storage address.
Definition: funcdata.hh:354
Scope
A collection of Symbol objects within a single (namespace or functional) scope.
Definition: database.hh:402
Funcdata::replaceLessequal
bool replaceLessequal(PcodeOp *op)
Replace INT_LESSEQUAL and INT_SLESSEQUAL expressions.
Definition: funcdata_op.cc:977
Funcdata::endDef
VarnodeDefSet::const_iterator endDef(uint4 fl, const Address &addr) const
End of (input or free) Varnodes at a given storage address.
Definition: funcdata.hh:357
AncestorRealistic::execute
bool execute(PcodeOp *op, int4 slot, ParamTrial *t, bool allowFail)
Perform a full ancestor check on a given parameter trial.
Definition: funcdata_varnode.cc:1843
Funcdata::syncVarnodesWithSymbols
bool syncVarnodesWithSymbols(const ScopeLocal *lm, bool typesyes)
Update Varnode properties based on (new) Symbol information.
Definition: funcdata_varnode.cc:812
Funcdata::printBlockTree
void printBlockTree(ostream &s) const
Print a description of control-flow structuring to a stream.
Definition: funcdata_block.cc:25
FlowInfo
A class for generating the control-flow structure for a single function.
Definition: flow.hh:56
Funcdata::cloneOp
PcodeOp * cloneOp(const PcodeOp *op, const SeqNum &seq)
Definition: funcdata_op.cc:569
FuncCallSpecs
A class for analyzing parameters to a sub-function call.
Definition: fspec.hh:1449
Funcdata::opInsertInput
void opInsertInput(PcodeOp *op, Varnode *vn, int4 slot)
Insert a new Varnode into the operand list for the given PcodeOp.
Definition: funcdata_op.cc:281
Funcdata::newOpBefore
PcodeOp * newOpBefore(PcodeOp *follow, OpCode opc, Varnode *in1, Varnode *in2, Varnode *in3=(Varnode *) 0)
Allocate a new PcodeOp with sequence number.
Definition: funcdata_op.cc:609
Funcdata::moveRespectingCover
bool moveRespectingCover(PcodeOp *op, PcodeOp *lastOp)
Move given op past lastOp respecting covers if possible.
Definition: funcdata_op.cc:1373
PcodeOp::nonprinting
@ nonprinting
Op should not be directly printed as source.
Definition: op.hh:89
Element
An XML element. A node in the DOM tree.
Definition: xml.hh:150
BlockBasic
A basic block for p-code operations.
Definition: block.hh:365
Funcdata::followFlow
void followFlow(const Address &baddr, const Address &eadddr)
Generate raw p-code for the function.
Definition: funcdata_op.cc:709
Funcdata::getCallSpecs
FuncCallSpecs * getCallSpecs(const PcodeOp *op) const
Get the call specification associated with a CALL op.
Definition: funcdata.cc:418
PcodeOp
Lowest level operation of the p-code language.
Definition: op.hh:58
Architecture
Manager for all the major decompiler subsystems.
Definition: architecture.hh:119
Funcdata::opUninsert
void opUninsert(PcodeOp *op)
Remove the given PcodeOp from its basic block.
Definition: funcdata_op.cc:162
SymbolEntry
A storage location for a particular Symbol.
Definition: database.hh:51
Heritage::numHeritagePasses
int4 numHeritagePasses(AddrSpace *spc) const
Get the number times heritage was performed for the given address space.
Definition: heritage.cc:2419
PcodeOpBank::endAlive
list< PcodeOp * >::const_iterator endAlive(void) const
End of all PcodeOps marked as alive.
Definition: op.hh:303
Funcdata::printLocalRange
void printLocalRange(ostream &s) const
Print description of memory ranges associated with local scopes.
Definition: funcdata.cc:531
Funcdata::beginDef
VarnodeDefSet::const_iterator beginDef(uint4 fl) const
Start of Varnodes with a given definition property.
Definition: funcdata.hh:348
Funcdata::transferVarnodeProperties
void transferVarnodeProperties(Varnode *vn, Varnode *newVn, int4 lsbOffset)
Copy properties from an existing Varnode to a new Varnode.
Definition: funcdata_varnode.cc:501
Funcdata::beginLoc
VarnodeLocSet::const_iterator beginLoc(void) const
Start of all Varnodes sorted by storage.
Definition: funcdata.hh:304
LoadGuard
Description of a LOAD operation that needs to be guarded.
Definition: heritage.hh:105
Funcdata::createStackRef
Varnode * createStackRef(AddrSpace *spc, uintb off, PcodeOp *op, Varnode *stackptr, bool insertafter)
Create an INT_ADD PcodeOp calculating an offset to the spacebase register.
Definition: funcdata_op.cc:432
Funcdata::opSetInput
void opSetInput(PcodeOp *op, Varnode *vn, int4 slot)
Set a specific input operand for the given PcodeOp.
Definition: funcdata_op.cc:102
Funcdata::endLoc
VarnodeLocSet::const_iterator endLoc(int4 s, const Address &addr, const Address &pc, uintm uniq=~((uintm) 0)) const
End of Varnodes matching storage and definition address.
Definition: funcdata.hh:338
PcodeOpBank::destroy
void destroy(PcodeOp *op)
Destroy/retire the given PcodeOp.
Definition: op.cc:846
Funcdata::remapVarnode
void remapVarnode(Varnode *vn, Symbol *sym, const Address &usepoint)
Remap a Symbol to a given Varnode using a static mapping.
Definition: funcdata_varnode.cc:992
Funcdata::doLiveInject
void doLiveInject(InjectPayload *payload, const Address &addr, BlockBasic *bl, list< PcodeOp * >::iterator pos)
Inject p-code from a payload into this live function.
Definition: funcdata.cc:793
Funcdata::removeFromFlowSplit
void removeFromFlowSplit(BlockBasic *bl, bool swap)
Remove a basic block splitting its control-flow into two distinct paths.
Definition: funcdata_block.cc:944
Funcdata::newIndirectOp
PcodeOp * newIndirectOp(PcodeOp *indeffect, const Address &addr, int4 size, uint4 extraFlags)
Find a representative CPUI_RETURN op for this function.
Definition: funcdata_op.cc:636
Funcdata::endLoc
VarnodeLocSet::const_iterator endLoc(int4 s, const Address &addr, uint4 fl) const
End of Varnodes matching storage and properties.
Definition: funcdata.hh:331
Funcdata::setHighLevel
void setHighLevel(void)
Turn on HighVariable objects for all Varnodes.
Definition: funcdata_varnode.cc:482
Funcdata::fillinReadOnly
bool fillinReadOnly(Varnode *vn)
Replace the given Varnode with its (constant) value in the load image.
Definition: funcdata_varnode.cc:516
InjectPayload
An active container for a set of p-code operations that can be injected into data-flow.
Definition: pcodeinject.hh:78
Varnode
A low-level variable or contiguous set of bytes described by an Address and a size.
Definition: varnode.hh:65
Funcdata::newUniqueOut
Varnode * newUniqueOut(int4 s, PcodeOp *op)
Create a new temporary output Varnode.
Definition: funcdata_varnode.cc:127
ParamActive
Container class for ParamTrial objects.
Definition: fspec.hh:222
Funcdata::printRaw
void printRaw(ostream &s) const
Print raw p-code op descriptions to a stream.
Definition: funcdata.cc:193
Funcdata::opDestroyRaw
void opDestroyRaw(PcodeOp *op)
Remove the given raw PcodeOp.
Definition: funcdata_op.cc:226
Funcdata::saveXmlHigh
void saveXmlHigh(ostream &s) const
Save an XML description of all HighVariables to stream.
Definition: funcdata.cc:596
Funcdata::beginDef
VarnodeDefSet::const_iterator beginDef(void) const
Start of all Varnodes sorted by definition address.
Definition: funcdata.hh:342
Funcdata::seenDeadcode
void seenDeadcode(AddrSpace *spc)
Mark that dead Varnodes have been seen in a specific address space.
Definition: funcdata.hh:218
Funcdata::nodeSplit
void nodeSplit(BlockBasic *b, int4 inedge)
Split control-flow into a basic block, duplicating its p-code into a new block.
Definition: funcdata_block.cc:906
PcodeOpBank::destroyDead
void destroyDead(void)
Destroy/retire all PcodeOps in the dead list.
Definition: op.cc:828
PcodeOpBank::end
PcodeOpTree::const_iterator end(const Address &addr) const
End of all PcodeOps at one Address.
Definition: op.cc:1009
Funcdata::opStackStore
PcodeOp * opStackStore(AddrSpace *spc, uintb off, PcodeOp *op, bool insertafter)
Create a STORE expression at an offset relative to a spacebase register for a given address space.
Definition: funcdata_op.cc:481
Funcdata::findCoveringInput
Varnode * findCoveringInput(int4 s, const Address &loc) const
Find the input Varnode that contains the given range.
Definition: funcdata.hh:284
Funcdata::setInputVarnode
Varnode * setInputVarnode(Varnode *vn)
Mark a Varnode as an input to the function.
Definition: funcdata_varnode.cc:338
Funcdata::beginLoc
VarnodeLocSet::const_iterator beginLoc(AddrSpace *spaceid) const
Start of Varnodes stored in a given address space.
Definition: funcdata.hh:310
Funcdata::opSetOpcode
void opSetOpcode(PcodeOp *op, OpCode opc)
Set the op-code for a specific PcodeOp.
Definition: funcdata_op.cc:23
opFlipInPlaceExecute
void opFlipInPlaceExecute(Funcdata &data, vector< PcodeOp * > &fliplist)
Perform op-code flips (in-place) to change a boolean value.
Definition: funcdata_op.cc:1170
Funcdata::deadRemovalAllowed
bool deadRemovalAllowed(AddrSpace *spc) const
Check if dead code removal is allowed for a specific address space.
Definition: funcdata.hh:230
Funcdata::printVarnodeTree
void printVarnodeTree(ostream &s) const
Print a description of all Varnodes to a stream.
Definition: funcdata.cc:513
Funcdata::opMarkHalt
void opMarkHalt(PcodeOp *op, uint4 flag)
Mark given CPUI_RETURN op as a special halt.
Definition: funcdata_op.cc:35
Heritage::heritage
void heritage(void)
Perform one pass of heritage.
Definition: heritage.cc:2306
Funcdata::opInsertBefore
void opInsertBefore(PcodeOp *op, PcodeOp *follow)
Insert given PcodeOp before a specific op.
Definition: funcdata_op.cc:318
PcodeOpBank::insertAfterDead
void insertAfterDead(PcodeOp *op, PcodeOp *prev)
Insert the given PcodeOp after a point in the dead list.
Definition: op.cc:896
architecture.hh
Architecture and associated classes that help manage a single processor architecture and load image.
Address
A low-level machine address for labelling bytes and data.
Definition: address.hh:46
Funcdata::restoreXml
uint8 restoreXml(const Element *el)
Restore the state of this function from an XML description.
Definition: funcdata.cc:708
Funcdata::setRestartPending
void setRestartPending(bool val)
Toggle whether analysis needs to be restarted for this function.
Definition: funcdata.hh:189
VarnodeBank::findCoveringInput
Varnode * findCoveringInput(int4 s, const Address &loc) const
Find an input Varnode covering a range.
Definition: varnode.cc:1147
Funcdata::findCoveredInput
Varnode * findCoveredInput(int4 s, const Address &loc) const
Find the first input Varnode covered by the given range.
Definition: funcdata.hh:277
Funcdata::opDeadInsertAfter
void opDeadInsertAfter(PcodeOp *op, PcodeOp *prev)
Moved given PcodeOp to specified point in the dead list.
Definition: funcdata.hh:419
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
Heritage::seenDeadCode
void seenDeadCode(AddrSpace *spc)
Inform system of dead code removal in given space.
Definition: heritage.cc:2431
Funcdata::distributeIntMultAdd
bool distributeIntMultAdd(PcodeOp *op)
Distribute constant coefficient to additive input.
Definition: funcdata_op.cc:1020
Funcdata::installSwitchDefaults
void installSwitchDefaults(void)
Make sure default switch cases are properly labeled.
Definition: funcdata_block.cc:604
PcodeOpBank::findOp
PcodeOp * findOp(const SeqNum &num) const
Find a PcodeOp by sequence number.
Definition: op.cc:956
Funcdata::saveXml
void saveXml(ostream &s, uint8 id, bool savetree) const
Emit an XML description of this function to stream.
Definition: funcdata.cc:676
Funcdata::findLinkedVarnode
Varnode * findLinkedVarnode(SymbolEntry *entry) const
Find a Varnode matching the given Symbol mapping.
Definition: funcdata_varnode.cc:1079
Funcdata::opRemoveInput
void opRemoveInput(PcodeOp *op, int4 slot)
Remove a specific input slot for the given PcodeOp.
Definition: funcdata_op.cc:264
Funcdata::beginOpDead
list< PcodeOp * >::const_iterator beginOpDead(void) const
Start of PcodeOp objects in the dead list.
Definition: funcdata.hh:467
PcodeOp::calculated_bool
@ calculated_bool
Output has been determined to be a 1-bit boolean value.
Definition: op.hh:97
Funcdata::linkJumpTable
JumpTable * linkJumpTable(PcodeOp *op)
Link jump-table with a given BRANCHIND.
Definition: funcdata_block.cc:421
Funcdata::opInsertAfter
void opInsertAfter(PcodeOp *op, PcodeOp *prev)
Insert given PcodeOp after a specific op.
Definition: funcdata_op.cc:346
Heritage::setDeadCodeDelay
void setDeadCodeDelay(AddrSpace *spc, int4 delay)
Set delay for a specific space.
Definition: heritage.cc:2455
opFlipInPlaceTest
int4 opFlipInPlaceTest(PcodeOp *op, vector< PcodeOp * > &fliplist)
Trace a boolean value to a set of PcodeOps that can be changed to flip the boolean value.
Definition: funcdata_op.cc:1110
Funcdata::endLoc
VarnodeLocSet::const_iterator endLoc(const Address &addr) const
End of Varnodes at a storage address.
Definition: funcdata.hh:319
Funcdata::compareCallspecs
static bool compareCallspecs(const FuncCallSpecs *a, const FuncCallSpecs *b)
Compare call specification objects by call site address.
Definition: funcdata.cc:438
DynamicHash
A hash utility to uniquely identify a temporary Varnode in data-flow.
Definition: dynamic.hh:60
Funcdata::remapDynamicVarnode
void remapDynamicVarnode(Varnode *vn, Symbol *sym, const Address &usepoint, uint8 hash)
Remap a Symbol to a given Varnode using a new dynamic mapping.
Definition: funcdata_varnode.cc:1008
Funcdata::linkSymbol
Symbol * linkSymbol(Varnode *vn)
Find or create Symbol associated with given Varnode.
Definition: funcdata_varnode.cc:1021
Funcdata::findVarnodeInput
Varnode * findVarnodeInput(int4 s, const Address &loc) const
Find the input Varnode with the given size and storage address.
Definition: funcdata.hh:291
Funcdata::nodeJoinCreateBlock
BlockBasic * nodeJoinCreateBlock(BlockBasic *block1, BlockBasic *block2, BlockBasic *exita, BlockBasic *exitb, bool fora_block1ishigh, bool forb_block1ishigh, const Address &addr)
Create a new basic block for holding a merged CBRANCH.
Definition: funcdata_block.cc:696
Funcdata::isHeritaged
bool isHeritaged(Varnode *vn)
Check if a specific Varnode has been linked in fully to the syntax tree (SSA)
Definition: funcdata.hh:242
Funcdata::totalReplaceConstant
void totalReplaceConstant(Varnode *vn, uintb val)
Replace every read reference of the given Varnode with a constant value.
Definition: funcdata_varnode.cc:1274
Funcdata::inlineFlow
bool inlineFlow(Funcdata *inlinefd, FlowInfo &flow, PcodeOp *callop)
In-line the p-code from another function into this function.
Definition: funcdata_op.cc:806
Funcdata::startTypeRecovery
bool startTypeRecovery(void)
Mark that data-type analysis has started.
Definition: funcdata.cc:166
Funcdata::setDoublePrecisRecovery
void setDoublePrecisRecovery(bool val)
Toggle whether double precision analysis is used.
Definition: funcdata.hh:151
Funcdata::clearDeadVarnodes
void clearDeadVarnodes(void)
Delete any dead Varnodes.
Definition: funcdata_varnode.cc:707
FunctionSymbol
A Symbol representing an executable function.
Definition: database.hh:251
HighVariable
A high-level variable modeled as a list of low-level variables, each written once.
Definition: variable.hh:38
Funcdata::opUnlink
void opUnlink(PcodeOp *op)
Unset inputs/output and remove given PcodeOP from its basic block.
Definition: funcdata_op.cc:177
Funcdata::beginOp
list< PcodeOp * >::const_iterator beginOp(OpCode opc) const
Start of PcodeOp objects with the given op-code.
Definition: funcdata.hh:455
Funcdata::newCodeRef
Varnode * newCodeRef(const Address &m)
Create a code address annotation Varnode.
Definition: funcdata_varnode.cc:220
Funcdata::replaceVolatile
bool replaceVolatile(Varnode *vn)
Replace accesses of the given Varnode with volatile operations.
Definition: funcdata_varnode.cc:598
OpCode
OpCode
The op-code defining a specific p-code operation (PcodeOp)
Definition: opcodes.hh:35
Funcdata::pushBranch
void pushBranch(BlockBasic *bb, int4 slot, BlockBasic *bbnew)
Move a control-flow edge from one block to another.
Definition: funcdata_block.cc:398
VarnodeBank::beginLoc
VarnodeLocSet::const_iterator beginLoc(AddrSpace *spaceid) const
Beginning of Varnodes in given address space sorted by location.
Definition: varnode.cc:1171
heritage.hh
Utilities for building Static Single Assignment (SSA) form
Funcdata::deadRemovalAllowedSeen
bool deadRemovalAllowedSeen(AddrSpace *spc)
Check if dead Varnodes have been removed for a specific address space.
Definition: funcdata.hh:236
VarnodeBank::findCoveredInput
Varnode * findCoveredInput(int4 s, const Address &loc) const
Find an input Varnode contained within this range.
Definition: varnode.cc:1119
Heritage::heritagePass
int4 heritagePass(const Address &addr) const
Get the pass number when the given address was heritaged.
Definition: heritage.hh:277
Funcdata::opSwapInput
void opSwapInput(PcodeOp *op, int4 slot1, int4 slot2)
Swap two input operands in the given PcodeOp.
Definition: funcdata_op.cc:129
Funcdata::warningHeader
void warningHeader(const string &txt) const
Add a warning comment as part of the function header.
Definition: funcdata.cc:123
Funcdata::endDef
VarnodeDefSet::const_iterator endDef(uint4 fl) const
End of Varnodes with a given definition property.
Definition: funcdata.hh:351
PcodeOp::startmark
@ startmark
This op is the first in its instruction.
Definition: op.hh:81
Heritage::getStoreGuard
const LoadGuard * getStoreGuard(PcodeOp *op) const
Get LoadGuard record associated with given PcodeOp.
Definition: heritage.cc:2402
Funcdata::newVarnodeCallSpecs
Varnode * newVarnodeCallSpecs(FuncCallSpecs *fc)
Create a call specification annotation Varnode.
Definition: funcdata_varnode.cc:203
Funcdata::checkForLanedRegister
void checkForLanedRegister(int4 size, const Address &addr)
Check for a potential laned register.
Definition: funcdata_varnode.cc:296
PcodeOpBank::beginAlive
list< PcodeOp * >::const_iterator beginAlive(void) const
Start of all PcodeOps marked as alive.
Definition: op.hh:300
Funcdata::findVarnodeWritten
Varnode * findVarnodeWritten(int4 s, const Address &loc, const Address &pc, uintm uniq=~((uintm) 0)) const
Find a defined Varnode via its storage address and its definition address.
Definition: funcdata.hh:300
Funcdata::startProcessing
void startProcessing(void)
Start processing for this function.
Definition: funcdata.cc:138
Funcdata::beginLoc
VarnodeLocSet::const_iterator beginLoc(int4 s, const Address &addr, const Address &pc, uintm uniq=~((uintm) 0)) const
Start of Varnodes matching storage and definition address.
Definition: funcdata.hh:334
Funcdata::findDisjointCover
Address findDisjointCover(Varnode *vn, int4 &sz)
Find range covering given Varnode and any intersecting Varnodes.
Definition: funcdata_varnode.cc:1351
PcodeOp::spacebase_ptr
@ spacebase_ptr
Loads or stores from a dynamic pointer into a spacebase.
Definition: op.hh:95
Funcdata::opInsertEnd
void opInsertEnd(PcodeOp *op, BlockBasic *bl)
Insert given PcodeOp at the end of a basic block.
Definition: funcdata_op.cc:408
Funcdata::endOp
PcodeOpTree::const_iterator endOp(const Address &addr) const
End of all (alive) PcodeOp objects attached to a specific Address.
Definition: funcdata.hh:482
Funcdata::warning
void warning(const string &txt, const Address &ad) const
Add a warning comment in the function body.
Definition: funcdata.cc:107
Funcdata::saveXmlJumpTable
void saveXmlJumpTable(ostream &s) const
Emit an XML description of jump-tables to stream.
Definition: funcdata.cc:562
PcodeOp::is_cpool_transformed
@ is_cpool_transformed
Have we checked for cpool transforms.
Definition: op.hh:108
Funcdata::buildDynamicSymbol
void buildDynamicSymbol(Varnode *vn)
Build a dynamic Symbol associated with the given Varnode.
Definition: funcdata_varnode.cc:1144
Funcdata::newOp
PcodeOp * newOp(int4 inputs, const Address &pc)
Definition: funcdata_op.cc:295
Funcdata::clear
void clear(void)
Clear out old disassembly.
Definition: funcdata.cc:75
PcodeOp::boolean_flip
@ boolean_flip
Set if condition must be false to take branch.
Definition: op.hh:77
Funcdata::~Funcdata
~Funcdata(void)
Destructor.
Definition: funcdata.cc:174
AncestorRealistic
Helper class for determining if Varnodes can trace their value from a legitimate source.
Definition: funcdata.hh:576
dynamic.hh
Utilities for making references to dynamic variables: defined as locations and constants that can onl...
Funcdata::endOpAll
PcodeOpTree::const_iterator endOpAll(void) const
End of all (alive) PcodeOp objects sorted by sequence number.
Definition: funcdata.hh:476
VarnodeData
Data defining a specific memory location.
Definition: pcoderaw.hh:33
Funcdata::restoreXmlJumpTable
void restoreXmlJumpTable(const Element *el)
Restore jump-tables from an XML description.
Definition: funcdata.cc:547
cseElimination
PcodeOp * cseElimination(Funcdata &data, PcodeOp *op1, PcodeOp *op2)
Perform a Common Subexpression Elimination step.
Definition: funcdata_op.cc:1271
Funcdata::findLinkedVarnodes
void findLinkedVarnodes(SymbolEntry *entry, vector< Varnode * > &res) const
Find Varnodes that map to the given SymbolEntry.
Definition: funcdata_varnode.cc:1118
VarnodeBank::beginDef
VarnodeDefSet::const_iterator beginDef(uint4 fl) const
Beginning of varnodes with set definition property.
Definition: varnode.cc:1402
Funcdata::newVarnode
Varnode * newVarnode(int4 s, const Address &m, Datatype *ct=(Datatype *) 0)
Create a new unattached Varnode object.
Definition: funcdata_varnode.cc:146
VarnodeBank::destroy
void destroy(Varnode *vn)
Remove a Varnode from the container.
Definition: varnode.cc:910
Funcdata::beginLoc
VarnodeLocSet::const_iterator beginLoc(const Address &addr) const
Start of Varnodes at a storage address.
Definition: funcdata.hh:316
PcodeOpBank::beginAll
PcodeOpTree::const_iterator beginAll(void) const
Start of all PcodeOps in sequence number order.
Definition: op.hh:288
Funcdata::spacebaseConstant
void spacebaseConstant(PcodeOp *op, int4 slot, SymbolEntry *entry, const Address &rampoint, uintb origval, int4 origsize)
Convert a constant pointer into a ram CPUI_PTRSUB.
Definition: funcdata.cc:303
Funcdata::newConstant
Varnode * newConstant(int4 s, uintb constant_val)
Create a new constant Varnode.
Definition: funcdata_varnode.cc:64
FuncProto
A function prototype.
Definition: fspec.hh:1164
Funcdata::removeBranch
void removeBranch(BlockBasic *bb, int4 num)
Remove the indicated branch from a basic block.
Definition: funcdata_block.cc:215
VarnodeBank::findInput
Varnode * findInput(int4 s, const Address &loc) const
Find an input Varnode.
Definition: varnode.cc:1099
Funcdata::opUnsetInput
void opUnsetInput(PcodeOp *op, int4 slot)
Clear an input operand slot for the given PcodeOp.
Definition: funcdata_op.cc:90
Funcdata::newVarnodeIop
Varnode * newVarnodeIop(PcodeOp *op)
Create a PcodeOp annotation Varnode.
Definition: funcdata_varnode.cc:174
Funcdata::setDeadCodeDelay
void setDeadCodeDelay(AddrSpace *spc, int4 delay)
Set a delay before removing dead code for a specific address space.
Definition: funcdata.hh:224
Funcdata::newSpacebasePtr
Varnode * newSpacebasePtr(AddrSpace *id)
Construct a new spacebase register for a given address space.
Definition: funcdata.cc:259
Funcdata::numHeritagePasses
int4 numHeritagePasses(AddrSpace *spc)
Get the number of heritage passes performed for the given address space.
Definition: funcdata.hh:213
Funcdata::ancestorOpUse
bool ancestorOpUse(int4 maxlevel, const Varnode *invn, const PcodeOp *op, ParamTrial &trial) const
Test if the given trial Varnode is likely only used for parameter passing.
Definition: funcdata_varnode.cc:1600
Funcdata::mapGlobals
void mapGlobals(void)
Make sure there is a Symbol entry for all global Varnodes.
Definition: funcdata_varnode.cc:1407
PcodeOp::startbasic
@ startbasic
This instruction starts a basic block.
Definition: op.hh:67
Funcdata::newVarnodeSpace
Varnode * newVarnodeSpace(AddrSpace *spc)
Create a constant Varnode referring to an address space.
Definition: funcdata_varnode.cc:188
Funcdata::endOpAlive
list< PcodeOp * >::const_iterator endOpAlive(void) const
End of PcodeOp objects in the alive list.
Definition: funcdata.hh:464
Symbol
The base class for a symbol in a symbol table or scope.
Definition: database.hh:152
PcodeOp::special_print
@ special_print
Op is marked for special printing.
Definition: op.hh:104
Funcdata::findHigh
HighVariable * findHigh(const string &name) const
Find a high-level variable by name.
Definition: funcdata_varnode.cc:314
PcodeOp::nocollapse
@ nocollapse
This op cannot be collapsed further.
Definition: op.hh:71
Funcdata::beginOp
PcodeOpTree::const_iterator beginOp(const Address &addr) const
Start of all (alive) PcodeOp objects attached to a specific Address.
Definition: funcdata.hh:479
VarnodeBank
A container for Varnode objects from a specific function.
Definition: varnode.hh:327
Funcdata::opUndoPtradd
void opUndoPtradd(PcodeOp *op, bool finalize)
Convert a CPUI_PTRADD back into a CPUI_INT_ADD.
Definition: funcdata_op.cc:532
Funcdata::opStackLoad
Varnode * opStackLoad(AddrSpace *spc, uintb off, uint4 sz, PcodeOp *op, Varnode *stackptr, bool insertafter)
Create a LOAD expression at an offset relative to a spacebase register for a given address space.
Definition: funcdata_op.cc:514
Funcdata::removeJumpTable
void removeJumpTable(JumpTable *jt)
Remove/delete the given jump-table.
Definition: funcdata_block.cc:62
Funcdata::newIndirectCreation
PcodeOp * newIndirectCreation(PcodeOp *indeffect, const Address &addr, int4 size, bool possibleout)
Build a CPUI_INDIRECT op that indirectly creates a Varnode.
Definition: funcdata_op.cc:663
Funcdata::collapseIntMultMult
bool collapseIntMultMult(Varnode *vn)
Collapse constant coefficients for two chained CPUI_INT_MULT.
Definition: funcdata_op.cc:1079
Funcdata::removeDoNothingBlock
void removeDoNothingBlock(BlockBasic *bb)
Remove a basic block from control-flow that performs no operations.
Definition: funcdata_block.cc:322
Funcdata::overrideFlow
void overrideFlow(const Address &addr, uint4 type)
Override the control-flow p-code for a particular instruction.
Definition: funcdata_op.cc:917
Funcdata::checkCallDoubleUse
bool checkCallDoubleUse(const PcodeOp *opmatch, const PcodeOp *op, const Varnode *vn, const ParamTrial &trial) const
Test for legitimate double use of a parameter trial.
Definition: funcdata_varnode.cc:1485
override.hh
A system for sending override commands to the decompiler.
Funcdata::attemptDynamicMapping
bool attemptDynamicMapping(SymbolEntry *entry, DynamicHash &dhash)
Map properties of a dynamic symbol to a Varnode.
Definition: funcdata_varnode.cc:1171
Funcdata::opInsertBegin
void opInsertBegin(PcodeOp *op, BlockBasic *bl)
Insert given PcodeOp at the beginning of a basic block.
Definition: funcdata_op.cc:386