-
Notifications
You must be signed in to change notification settings - Fork 2
/
1629-Fixed-an-issue-with-the-Set-Equate-dialog-that-.patch
137 lines (128 loc) · 6.82 KB
/
1629-Fixed-an-issue-with-the-Set-Equate-dialog-that-.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
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: snemes <snemes@users.noreply.github.com>
Date: Fri, 13 Mar 2020 12:33:48 +0100
Subject: [PATCH] 1629: Fixed an issue with the Set Equate dialog, that caused
unsigned Enum members not being displayed when a signed immediate operand was
selected
---
.../app/plugin/core/equate/CreateEquateCmd.java | 10 ++++++++--
.../ghidra/app/plugin/core/equate/EquatePlugin.java | 9 ++++++++-
.../java/ghidra/app/util/bean/SetEquateDialog.java | 12 +++++++-----
.../ghidra/program/model/listing/CodeUnitFormat.java | 2 +-
.../ghidra/program/database/symbol/EquateDB.java | 2 +-
.../program/database/symbol/EquateManager.java | 3 ++-
6 files changed, 27 insertions(+), 11 deletions(-)
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/equate/CreateEquateCmd.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/equate/CreateEquateCmd.java
index c70cc6386b..2f99644d61 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/equate/CreateEquateCmd.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/equate/CreateEquateCmd.java
@@ -74,7 +74,13 @@ public class CreateEquateCmd extends BackgroundCommand<Program> {
boolean overwriteExisting, ListingActionContext context) {
super("Create New Equate", true /* has progress */, true /* can cancel */,
false /* is modal */);
- this.targetScalarValue = scalar.getValue();
+ this.targetScalarValue = 0;
+ for (long value : new long[] { scalar.getUnsignedValue(), scalar.getSignedValue() }) {
+ if (enoom.getName(value) != null) {
+ this.targetScalarValue = value;
+ break;
+ }
+ }
this.iterator = iter;
this.overwriteExisting = overwriteExisting;
this.context = context;
@@ -128,7 +134,7 @@ public class CreateEquateCmd extends BackgroundCommand<Program> {
}
Scalar scalar = (Scalar) opObject;
- if (scalar.getValue() != targetScalarValue) {
+ if (scalar.getUnsignedValue() != targetScalarValue && scalar.getSignedValue() != targetScalarValue) {
continue;
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/equate/EquatePlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/equate/EquatePlugin.java
index 8a535920ec..929bdbefad 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/equate/EquatePlugin.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/equate/EquatePlugin.java
@@ -281,7 +281,14 @@ public class EquatePlugin extends Plugin {
if (s == null) {
return null;
}
- return equateTable.getEquate(context.getAddress(), getOperandIndex(context), s.getValue());
+ Equate equate = null;
+ for (long value : new long[] { s.getUnsignedValue(), s.getSignedValue() }) {
+ equate = equateTable.getEquate(context.getAddress(), getOperandIndex(context), value);
+ if (equate != null) {
+ break;
+ }
+ }
+ return equate;
}
private void renameEquate(ListingActionContext context, Enum enoom, Equate oldEquate,
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bean/SetEquateDialog.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bean/SetEquateDialog.java
index 7058d1fb16..1b44f5adc4 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bean/SetEquateDialog.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bean/SetEquateDialog.java
@@ -597,7 +597,6 @@ public class SetEquateDialog extends DialogComponentProvider {
private Enum enoom;
EquateRowObject(String name, Enum enoom) {// Equate based off enum
- long value = scalar.getValue();
if (enoom == null) {
return;
}
@@ -606,10 +605,13 @@ public class SetEquateDialog extends DialogComponentProvider {
this.entryName = name;
this.dataTypeUUID = enoom.getUniversalID();
this.path = getFullPath(enoom);
- String formattedEquateName = EquateManager.formatNameForEquate(dataTypeUUID, value);
- this.equate = equateTable.getEquate(formattedEquateName);
- if (equate != null) {
- this.refCount = equate.getReferenceCount();
+ this.refCount = 0;
+ for (long value : new long[] { scalar.getUnsignedValue(), scalar.getSignedValue() }) {
+ String formattedEquateName = EquateManager.formatNameForEquate(dataTypeUUID, value);
+ this.equate = equateTable.getEquate(formattedEquateName);
+ if (equate != null) {
+ this.refCount += equate.getReferenceCount();
+ }
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/program/model/listing/CodeUnitFormat.java b/Ghidra/Features/Base/src/main/java/ghidra/program/model/listing/CodeUnitFormat.java
index ccb95ca197..f91fc128d0 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/program/model/listing/CodeUnitFormat.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/program/model/listing/CodeUnitFormat.java
@@ -1006,7 +1006,7 @@ public class CodeUnitFormat {
private Equate findEquate(Scalar scalar, List<Equate> equates) {
for (Equate equate : equates) {
if (equate.getValue() == scalar.getSignedValue() ||
- equate.getValue() == scalar.getValue()) {
+ equate.getValue() == scalar.getUnsignedValue()) {
return equate;
}
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/EquateDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/EquateDB.java
index fdf823a467..3106bb7421 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/EquateDB.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/EquateDB.java
@@ -126,7 +126,7 @@ public class EquateDB extends DatabaseObject implements Equate {
for (short i = 0; i < numOperands; i++) {
for (Object obj : instr.getOpObjects(i)) {
if (obj instanceof Scalar) {
- if (((Scalar) obj).getValue() != value) {
+ if (((Scalar) obj).getUnsignedValue() != value && ((Scalar) obj).getSignedValue() != value) {
continue;
}
if (opIndex >= 0) {
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/EquateManager.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/EquateManager.java
index 9a1ad631ce..278a103f5e 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/EquateManager.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/EquateManager.java
@@ -647,7 +647,8 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
* @return The error formatted equate name
*/
public static String formatNameForEquateError(long equateValue) {
- return "0x" + Long.toString(equateValue, 16) + " " + EquateManager.ERROR_TAG;
+ return (equateValue < 0 ? "-" : "") + "0x" + Long.toHexString(Math.abs(equateValue)) +
+ " " + EquateManager.ERROR_TAG;
}
/**
--
2.45.1