GP-1403 corrected improper recursion

This commit is contained in:
ghidra1 2022-04-12 10:23:02 -04:00
parent 17534b9c3f
commit a58c04d54d
2 changed files with 12 additions and 52 deletions

View file

@ -468,41 +468,16 @@ public final class DataUtilities {
*
* @param program the program
* @param address the data address
* @return the outermost Data code unit that starts at the given address or null if the address is code or offcut
* @return the Data that starts at the given address or null if the address is code or offcut
*/
public static Data getDataAtAddress(Program program, Address address) {
if (address == null) {
return null;
}
Listing listing = program.getListing();
return listing.getDataAt(address);
}
/**
* Get the primitive (i.e., non-composite/non-array) data at the given address.
* Composites, Arrays or other types which contain components will not be returned.
* @param program the program
* @param address the data address
* @return the lowest-level primitive Data that starts at the given address or null.
*/
public static Data getPrimitiveDataAtAddress(Program program, Address address) {
Listing listing = program.getListing();
long componentOffset = 0;
Data dataContaining = listing.getDataContaining(address);
Data lastData = dataContaining;
while (dataContaining != null) {
componentOffset = address.subtract(dataContaining.getMinAddress());
if (componentOffset > Integer.MAX_VALUE) {
return null;
}
lastData = dataContaining;
dataContaining = dataContaining.getComponentContaining((int) componentOffset);
}
if (lastData != null && componentOffset == 0 && lastData.getNumComponents() == 0) {
DataType dt = lastData.getDataType();
if (!(dt instanceof Composite) && !(dt instanceof Array)) {
return lastData;
}
CodeUnit cu = listing.getCodeUnitAt(address);
if (cu instanceof Data) {
return (Data) cu;
}
return null;
}

View file

@ -232,7 +232,7 @@ public class StringDataInstance {
private final int charSize;
private final int paddedCharSize;
private final StringLayoutEnum stringLayout;
private final String translatedValue;
private final String translatedValue; // empty string indicates no-value, null indicates not-initialized
private final Endian endianSetting;
private final boolean showTranslation;
@ -307,30 +307,15 @@ public class StringDataInstance {
this.length = length;
}
private static Data getData(Settings settings, MemBuffer buf) {
Data data = null;
if (settings instanceof Data) {
data = (Data) settings;
if (!data.getAddress().equals(buf.getAddress())) {
data = null; // address mismatch - not expected
}
}
else {
Memory mem = buf.getMemory();
if (mem == null) {
return null; // must have memory to access translation
}
data = DataUtilities.getPrimitiveDataAtAddress(mem.getProgram(), buf.getAddress());
}
return data;
}
private static String getTranslatedValue(Settings settings, MemBuffer buf) {
Data data = getData(settings, buf);
if (data == null) {
return null;
// Translation only exists for defined Data which corresponds to settings.
if (settings instanceof Data) {
Data data = (Data) settings;
if (data.isDefined()) {
return TRANSLATION.getTranslatedValue(data);
}
}
return TRANSLATION.getTranslatedValue(data);
return null;
}
private StringDataInstance(StringDataInstance copyFrom, StringLayoutEnum newLayout,