Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-5295 Refactor HighCodeSymbol instantiation for consistency and correct use of improperly sized VariableStorage

ghidra1f68246ec17e4
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/GlobalSymbolMap.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/GlobalSymbolMap.java
index aa3db5cd41..5ec7be12da 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/GlobalSymbolMap.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/GlobalSymbolMap.java
@@ -4,9 +4,9 @@
* 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.
@@ -87,18 +87,7 @@ public class GlobalSymbolMap {
}
HighSymbol highSym = null;
if (symbol instanceof CodeSymbol) {
- if (dataType == null) {
- Object dataObj = symbol.getObject();
- if (dataObj instanceof Data) {
- dataType = ((Data) dataObj).getDataType();
- sz = dataType.getLength();
- }
- else {
- dataType = DataType.DEFAULT;
- sz = 1;
- }
- }
- highSym = new HighCodeSymbol((CodeSymbol) symbol, dataType, sz, func);
+ highSym = new HighCodeSymbol((CodeSymbol) symbol, func);
}
else if (symbol instanceof FunctionSymbol) {
highSym = new HighFunctionShellSymbol(id, symbol.getName(), symbol.getAddress(),
@@ -127,15 +116,7 @@ public class GlobalSymbolMap {
}
HighSymbol highSym;
if (symbol instanceof CodeSymbol) {
- Data dataAt = program.getListing().getDataAt(addr);
- DataType dataType = DataType.DEFAULT;
- int sz = 1;
- if (dataAt != null) {
- dataType = dataAt.getDataType();
- sz = dataAt.getLength();
- }
-
- highSym = new HighCodeSymbol((CodeSymbol) symbol, dataType, sz, func);
+ highSym = new HighCodeSymbol((CodeSymbol) symbol, func);
}
else if (symbol instanceof FunctionSymbol) {
highSym = new HighFunctionShellSymbol(symbol.getID(), symbol.getName(),
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighCodeSymbol.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighCodeSymbol.java
index 9b90e6a788..46ee5be4dc 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighCodeSymbol.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighCodeSymbol.java
@@ -4,9 +4,9 @@
* 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.
@@ -40,30 +40,40 @@ public class HighCodeSymbol extends HighSymbol {
* @param sz is the storage size, in bytes, of the symbol
* @param func is the decompiler function model owning the new HighSymbol
*/
- public HighCodeSymbol(CodeSymbol sym, DataType dataType, int sz, HighFunction func) {
- super(sym.getID(), sym.getName(), dataType, func);
+ public HighCodeSymbol(CodeSymbol sym, HighFunction func) {
+ super(sym.getID(), sym.getName(), null, func);
symbol = sym;
setNameLock(true);
setTypeLock(true);
- Data data = null;
+
+ SymbolEntry entry;
+
+ // NOTE: Use of symbol.getObject return Data at the symbol address if it is at the start
+ // of a Data code unit, the lowest level non-composite/primitive DataComponent, or null
+ // if offcut or non-data
Object dataObj = symbol.getObject();
- if (dataObj instanceof Data) {
+ if (dataObj instanceof Data data) {
data = (Data) dataObj;
- }
- VariableStorage store;
- try {
- store = new VariableStorage(symbol.getProgram(), symbol.getAddress(), sz);
- }
- catch (InvalidInputException e) {
- store = VariableStorage.UNASSIGNED_STORAGE;
- }
- SymbolEntry entry;
- if (data != null) {
+ type = data.getDataType();
+ int size = type.getLength();
+ if (size <= 0) {
+ size = data.getLength();
+ }
+
+ VariableStorage store = VariableStorage.UNASSIGNED_STORAGE;
+ try {
+ store = new VariableStorage(symbol.getProgram(), symbol.getAddress(), size);
+ }
+ catch (InvalidInputException e) {
+ // ignore
+ }
entry = new MappedDataEntry(this, store, data);
}
else {
- entry = new MappedEntry(this, store, null);
+ type = DataType.DEFAULT;
+ entry = new MappedEntry(this, VariableStorage.UNASSIGNED_STORAGE, null);
}
+
addMapEntry(entry);
}