-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path0786-isInfinite-op-for-PCODE-and-SLEIGH.patch
223 lines (212 loc) · 10.9 KB
/
0786-isInfinite-op-for-PCODE-and-SLEIGH.patch
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: mumbel <[email protected]>
Date: Wed, 17 Jul 2019 17:45:34 -0500
Subject: [PATCH] 0786: isInfinite() op for PCODE and SLEIGH
Squashed:
Adding PCODE op FLOAT_INF
This feature is similar to FLOAT_NAN, but returns if the float
is positive or negative infinity. The patch uses the unused
slot 45. Users can GT or LT zero to determine positiver or
negative infinity.
---
.../pcode/opbehavior/OpBehaviorFactory.java | 1 +
.../pcode/opbehavior/OpBehaviorFloatInf.java | 42 +++++++++++++++++++
.../ghidra/pcode/floatformat/FloatFormat.java | 12 ++++++
.../ghidra/pcodeCPort/opcodes/OpCode.java | 10 ++---
.../slgh_compile/ConsistencyChecker.java | 3 ++
.../pcodeCPort/slgh_compile/PcodeCompile.java | 4 ++
.../program/model/pcode/DynamicHash.java | 1 +
.../ghidra/program/model/pcode/PcodeOp.java | 4 +-
8 files changed, 71 insertions(+), 6 deletions(-)
create mode 100644 Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/opbehavior/OpBehaviorFloatInf.java
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/opbehavior/OpBehaviorFactory.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/opbehavior/OpBehaviorFactory.java
index c68028bf1b..218deaf7be 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/opbehavior/OpBehaviorFactory.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/opbehavior/OpBehaviorFactory.java
@@ -82,6 +82,7 @@ public class OpBehaviorFactory {
opBehaviorMap.put(PcodeOp.FLOAT_NOTEQUAL, new OpBehaviorFloatNotEqual());
opBehaviorMap.put(PcodeOp.FLOAT_LESS, new OpBehaviorFloatLess());
opBehaviorMap.put(PcodeOp.FLOAT_LESSEQUAL, new OpBehaviorFloatLessEqual());
+ opBehaviorMap.put(PcodeOp.FLOAT_INF, new OpBehaviorFloatInf());
opBehaviorMap.put(PcodeOp.FLOAT_NAN, new OpBehaviorFloatNan());
opBehaviorMap.put(PcodeOp.FLOAT_ADD, new OpBehaviorFloatAdd());
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/opbehavior/OpBehaviorFloatInf.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/opbehavior/OpBehaviorFloatInf.java
new file mode 100644
index 0000000000..1980bd7d8b
--- /dev/null
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/opbehavior/OpBehaviorFloatInf.java
@@ -0,0 +1,42 @@
+/* ###
+ * IP: GHIDRA
+ * REVIEWED: YES
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.pcode.opbehavior;
+
+import ghidra.pcode.floatformat.FloatFormat;
+import ghidra.pcode.floatformat.FloatFormatFactory;
+import ghidra.program.model.pcode.PcodeOp;
+
+import java.math.BigInteger;
+
+public class OpBehaviorFloatInf extends UnaryOpBehavior {
+
+ public OpBehaviorFloatInf() {
+ super(PcodeOp.FLOAT_INF);
+ }
+
+ @Override
+ public long evaluateUnary(int sizeout, int sizein, long in1) {
+ FloatFormat format = FloatFormatFactory.getFloatFormat(sizein);
+ return format.opInf(in1);
+ }
+
+ @Override
+ public BigInteger evaluateUnary(int sizeout, int sizein, BigInteger in1) {
+ FloatFormat format = FloatFormatFactory.getFloatFormat(sizein);
+ return format.opInf(in1);
+ }
+}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcode/floatformat/FloatFormat.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcode/floatformat/FloatFormat.java
index 6b34dd3c10..d7b167d63c 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcode/floatformat/FloatFormat.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcode/floatformat/FloatFormat.java
@@ -974,6 +974,18 @@ public class FloatFormat {
return res;
}
+ public long opInf(long a) {
+ double val = decodeHostFloat(a);
+ long res = Double.isInfinite(val) ? 1 : 0;
+ return res;
+ }
+
+ public BigInteger opInf(BigInteger a) {
+ BigDecimal val = new BigDecimal(a);
+ BigInteger res = (val == BigFloat.BIG_POSITIVE_INFINITY || val == BigFloat.BIG_NEGATIVE_INFINITY) ? BigInteger.ONE : BigInteger.ZERO;
+ return res;
+ }
+
public long opAdd(long a, long b) { // a + b
double val1 = decodeHostFloat(a);
double val2 = decodeHostFloat(b);
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/opcodes/OpCode.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/opcodes/OpCode.java
index d69279a188..80a8997662 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/opcodes/OpCode.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/opcodes/OpCode.java
@@ -79,7 +79,7 @@ public enum OpCode {
CPUI_FLOAT_NOTEQUAL, // Return TRUE if operand1 != operand2
CPUI_FLOAT_LESS, // Return TRUE if op1 < op2
CPUI_FLOAT_LESSEQUAL, // Return TRUE if op1 <= op2
- CPUI_UNUSED1, // Slot 45 is unused
+ CPUI_FLOAT_INF, // Return TRUE if positive or negative infinity
CPUI_FLOAT_NAN, // Return TRUE if op1 is NaN
CPUI_FLOAT_ADD, // float addition
@@ -202,7 +202,7 @@ public enum OpCode {
"INT_ADD", "INT_SUB", "INT_CARRY", "INT_SCARRY", "INT_SBORROW", "INT_2COMP", "INT_NEGATE",
"INT_XOR", "INT_AND", "INT_OR", "INT_LEFT", "INT_RIGHT", "INT_SRIGHT", "INT_MULT",
"INT_DIV", "INT_SDIV", "INT_REM", "INT_SREM", "BOOL_NEGATE", "BOOL_XOR", "BOOL_AND",
- "BOOL_OR", "FLOAT_EQUAL", "FLOAT_NOTEQUAL", "FLOAT_LESS", "FLOAT_LESSEQUAL", "UNUSED1",
+ "BOOL_OR", "FLOAT_EQUAL", "FLOAT_NOTEQUAL", "FLOAT_LESS", "FLOAT_LESSEQUAL", "FLOAT_INF",
"FLOAT_NAN", "FLOAT_ADD", "FLOAT_DIV", "FLOAT_MULT", "FLOAT_SUB", "FLOAT_NEG", "FLOAT_ABS",
"FLOAT_SQRT", "INT2FLOAT", "FLOAT2FLOAT", "TRUNC", "CEIL", "FLOOR", "ROUND", "BUILD",
"DELAY_SLOT", "PIECE", "SUBPIECE", "CAST", "LABEL", "CROSSBUILD", "SEGMENTOP", "CPOOLREF",
@@ -212,10 +212,10 @@ public enum OpCode {
return opcode_name[op.ordinal()];
}
- static final int opcode_indices[] = { 0, 39, 37, 40, 38, 4, 6, 60, 7, 8, 9, 64, 5, 57, 1, 68,
- 66, 61, 71, 55, 52, 47, 48, 41, 43, 44, 49, 46, 51, 42, 53, 50, 58, 70, 54, 24, 19, 27, 21,
+ static final int opcode_indices[] = { 0, 39, 37, 40, 38, 4, 6, 60, 7, 8, 9, 64, 5, 57, 1, 68, 66,
+ 61, 71, 55, 52, 47, 48, 41, 45, 43, 44, 49, 46, 51, 42, 53, 50, 58, 70, 54, 24, 19, 27, 21,
33, 11, 29, 15, 16, 32, 25, 12, 28, 35, 30, 23, 22, 34, 18, 13, 14, 36, 31, 20, 26, 17, 65,
- 2, 73, 69, 62, 72, 10, 59, 67, 3, 63, 56, 45 };
+ 2, 73, 69, 62, 72, 10, 59, 67, 3, 63, 56 };
public static OpCode get_opcode(String nm) { // Use binary search to find name
int min = 1; // Don't include BLANK
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/ConsistencyChecker.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/ConsistencyChecker.java
index 0c28b1734d..1ebf014e91 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/ConsistencyChecker.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/ConsistencyChecker.java
@@ -144,6 +144,7 @@ class ConsistencyChecker {
return false;
}
return true;
+ case CPUI_FLOAT_INF:
case CPUI_FLOAT_NAN:
vnout = recoverSize(op.getOut().getSize(), ct);
if (vnout == -1) {
@@ -436,6 +437,8 @@ class ConsistencyChecker {
return "Float less than(f<)";
case CPUI_FLOAT_LESSEQUAL:
return "Float less than or equal(f<=)";
+ case CPUI_FLOAT_INF:
+ return "+/- inifity";
case CPUI_FLOAT_NAN:
return "Not a number(nan)";
case CPUI_FLOAT_ADD:
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/PcodeCompile.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/PcodeCompile.java
index 112a531fa9..5612e56f48 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/PcodeCompile.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/PcodeCompile.java
@@ -796,6 +796,7 @@ public abstract class PcodeCompile {
case CPUI_FLOAT_NOTEQUAL:
case CPUI_FLOAT_LESS:
case CPUI_FLOAT_LESSEQUAL:
+ case CPUI_FLOAT_INF:
case CPUI_FLOAT_NAN:
case CPUI_BOOL_NEGATE:
case CPUI_BOOL_XOR:
@@ -954,6 +955,9 @@ public abstract class PcodeCompile {
if ("abs".equals(name) && hasOperands(1, operands, location, name)) {
return createOp(location, OpCode.CPUI_FLOAT_ABS, r);
}
+ if ("inf".equals(name) && hasOperands(1, operands, location, name)) {
+ return createOp(location, OpCode.CPUI_FLOAT_INF, r);
+ }
if ("nan".equals(name) && hasOperands(1, operands, location, name)) {
return createOp(location, OpCode.CPUI_FLOAT_NAN, r);
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/DynamicHash.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/DynamicHash.java
index 5423b73d4f..09904d05c9 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/DynamicHash.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/DynamicHash.java
@@ -62,6 +62,7 @@ public class DynamicHash {
PcodeOp.FLOAT_EQUAL, PcodeOp.FLOAT_EQUAL, // NOTEQUAL hashes same as EQUAL
PcodeOp.FLOAT_LESS, PcodeOp.FLOAT_LESS, // LESSEQUAL hashes same as EQUAL
0, // Unused slot -- skip
+ PcodeOp.FLOAT_INF,
PcodeOp.FLOAT_NAN,
PcodeOp.FLOAT_ADD, PcodeOp.FLOAT_DIV, PcodeOp.FLOAT_MULT, PcodeOp.FLOAT_ADD, // SUB hashes same as ADD
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/PcodeOp.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/PcodeOp.java
index 8c993de27a..809dc37dc7 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/PcodeOp.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/PcodeOp.java
@@ -98,7 +98,7 @@ public class PcodeOp {
public static final int FLOAT_NOTEQUAL = 42; // Return TRUE if operand1 != operand2
public static final int FLOAT_LESS = 43; // Return TRUE if op1 < op2
public static final int FLOAT_LESSEQUAL = 44; // Return TRUE if op1 <= op2
- // Slot 45 is unused
+ public static final int FLOAT_INF = 45; // Return TRUE if positive or negative infinity
public static final int FLOAT_NAN = 46; // Return TRUE if neither op1 is NaN
public static final int FLOAT_ADD = 47; // float addition
@@ -644,6 +644,8 @@ public class PcodeOp {
return "FLOAT_LESS";
case FLOAT_LESSEQUAL:
return "FLOAT_LESSEQUAL";
+ case FLOAT_INF:
+ return "FLOAT_INF";
case FLOAT_NAN:
return "FLOAT_NAN";
case FLOAT_ADD:
--
2.45.1