Ghidra Decompiler Analysis Engine
paramid.hh
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_PARAMID__
17 #define __CPUI_PARAMID__
18 
19 #include "funcdata.hh"
20 
21 class ParamMeasure {
22 public:
23  enum ParamIDIO {
24  INPUT = 0,
25  OUTPUT = 1
26  };
27  enum ParamRank {
28  BESTRANK = 1,
29  DIRECTWRITEWITHOUTREAD = 1, //Output
30  DIRECTREAD = 2, //Input. Must be same as DIRECTWRITEWITHREAD so that walkforward as part of walkbackward works
31  // for detecting(not that DIRECTREAD is lower rank that DIRECTWRITEWITHOUTREAD)
32  DIRECTWRITEWITHREAD = 2, //Output
33  DIRECTWRITEUNKNOWNREAD = 3, //Output
34  SUBFNPARAM = 4, //Input
35  THISFNPARAM = 4, //Output
36  SUBFNRETURN = 5, //Output
37  THISFNRETURN = 5, //Input
38  INDIRECT = 6, //Input or Output
39  WORSTRANK = 7
40  };
41  struct WalkState {
42  bool best;
43  int4 depth;
44  ParamRank terminalrank;
45  };
46 private:
47  VarnodeData vndata;
48  Datatype *vntype;
49  ParamRank rank;
50  ParamIDIO io;
51  int4 numcalls;
52  void walkforward( WalkState &state, PcodeOp *ignoreop, Varnode *vn );
53  void walkbackward( WalkState &state, PcodeOp *ignoreop,Varnode *vn );
54  void updaterank( ParamRank rank_in,bool best ) { rank = (best==true) ? min( rank, rank_in ) : max( rank, rank_in ); }
55 public:
56  ParamMeasure( const Address &addr, int4 sz, Datatype *dt, ParamIDIO io_in) {
57  vndata.space=addr.getSpace(); vndata.offset=addr.getOffset(); vndata.size = sz; vntype=dt; io = io_in; rank=WORSTRANK; }
58  void calculateRank(bool best,Varnode *basevn,PcodeOp *ignoreop);
59  void saveXml( ostream &s,string tag,bool moredetail ) const;
60  void savePretty( ostream &s,bool moredetail ) const;
61  int4 getMeasure(void) const { return (int4) rank; }
62 };
63 
65 {
66  Funcdata *fd;
67  list<ParamMeasure> InputParamMeasures;
68  list<ParamMeasure> OutputParamMeasures;
69 public:
70  ParamIDAnalysis( Funcdata *fd_in, bool justproto );
71  void saveXml( ostream &s, bool moredetail ) const;
72  void savePretty( ostream &s, bool moredetail ) const;
73 };
74 
75 #endif //ifndef __CPUI_PARAMID__
VarnodeData::space
AddrSpace * space
The address space.
Definition: pcoderaw.hh:34
ParamMeasure
Definition: paramid.hh:21
ParamMeasure::WalkState
Definition: paramid.hh:41
Address::getOffset
uintb getOffset(void) const
Get the address offset.
Definition: address.hh:300
PcodeOp
Lowest level operation of the p-code language.
Definition: op.hh:58
ParamIDAnalysis
Definition: paramid.hh:64
VarnodeData::offset
uintb offset
The offset within the space.
Definition: pcoderaw.hh:35
VarnodeData::size
uint4 size
The number of bytes in the location.
Definition: pcoderaw.hh:36
Varnode
A low-level variable or contiguous set of bytes described by an Address and a size.
Definition: varnode.hh:65
funcdata.hh
Utilities for processing data structures associated with a single function.
Address::getSpace
AddrSpace * getSpace(void) const
Get the address space.
Definition: address.hh:294
Address
A low-level machine address for labelling bytes and data.
Definition: address.hh:46
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
VarnodeData
Data defining a specific memory location.
Definition: pcoderaw.hh:33