-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathVariable.cs
More file actions
183 lines (162 loc) · 3.99 KB
/
Copy pathVariable.cs
File metadata and controls
183 lines (162 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
namespace BinaryNinja
{
public abstract class AbstractFunctionVariable<T_SELF> : AbstractVariable<T_SELF>
where T_SELF : AbstractFunctionVariable<T_SELF>
{
public Function Function { get; }
internal AbstractFunctionVariable(AbstractFunctionVariable<T_SELF> other)
:base(other.Type , other.Index ,other.Storage)
{
this.Function = other.Function;
}
internal AbstractFunctionVariable(
Function function ,
VariableSourceType type ,
uint index ,
long storage
) : base(type , index , storage)
{
this.Function = function;
}
public AbstractFunctionVariable(Function function , BNVariable native)
:base(native)
{
this.Function = function;
}
public string Name
{
get
{
return UnsafeUtils.TakeAnsiString(
NativeMethods.BNGetVariableNameOrDefault(
this.Function.DangerousGetHandle() ,
this.ToNative()
)
);
}
}
public string LastSeenName
{
get
{
return UnsafeUtils.TakeAnsiString(
NativeMethods.BNGetLastSeenVariableNameOrDefault(
this.Function.DangerousGetHandle() ,
this.ToNative()
)
);
}
}
public override string ToString()
{
return this.Name;
}
/// <summary>
/// This variable as a plain <see cref="CoreVariable"/> (type/index/storage
/// without the owning function), for the <c>Function</c> APIs that take one.
/// </summary>
public CoreVariable AsCoreVariable()
{
return CoreVariable.FromNative(this.ToNative());
}
/// <summary>
/// The data type of this variable. Mirrors Python <c>Variable.type</c>.
/// (Named <c>VariableType</c> because <see cref="AbstractVariable{T}.Type"/>
/// already denotes the variable's <see cref="VariableSourceType"/>.)
/// The setter defines a user variable keeping the current name.
/// </summary>
public TypeWithConfidence VariableType
{
get
{
return this.Function.GetVariableType(this.AsCoreVariable());
}
set
{
this.Function.CreateUserVariable(
this.AsCoreVariable() ,
value ,
this.Name ,
false
);
}
}
/// <summary>
/// Whether this variable is a parameter of its function.
/// Mirrors Python <c>Variable.is_parameter_variable</c>.
/// </summary>
public bool IsParameter
{
get
{
foreach (Variable parameter in this.Function.ParameterVariables.Variables)
{
if (parameter.Identifier == this.Identifier)
{
return true;
}
}
return false;
}
}
/// <summary>
/// The dead-store elimination mode for this variable.
/// Mirrors Python <c>Variable.dead_store_elimination</c>.
/// </summary>
public DeadStoreElimination DeadStoreElimination
{
get
{
return this.Function.GetFunctionVariableDeadStoreElimination(this.AsCoreVariable());
}
set
{
this.Function.SetFunctionVariableDeadStoreElimination(this.AsCoreVariable() , value);
}
}
public void SetUserValue(ArchitectureAndAddress defSite , PossibleValueSet value , bool after)
{
using (ScopedAllocator allocator = new ScopedAllocator())
{
NativeMethods.BNSetUserVariableValue(
this.Function.DangerousGetHandle() ,
this.ToNative() ,
defSite.ToNative() ,
after ,
value.ToNativeEx(allocator)
);
}
}
public void ClearUserValue(ArchitectureAndAddress defSite , bool after)
{
NativeMethods.BNClearUserVariableValue(
this.Function.DangerousGetHandle() ,
this.ToNative() ,
defSite.ToNative() ,
after
);
}
}
public sealed class Variable : AbstractFunctionVariable<Variable>
{
internal Variable(Variable other)
:base(other)
{
}
public Variable(Function function , BNVariable native)
:base(function , native)
{
}
internal static Variable FromIdentifierEx(Function function ,ulong identifier)
{
return Variable.FromNativeEx(
function,
NativeMethods.BNFromVariableIdentifier(identifier)
);
}
internal static Variable FromNativeEx(Function function , BNVariable native)
{
return new Variable(function, native);
}
}
}