mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 10:49:34 +02:00
GP-1403 corrected improper recursion
This commit is contained in:
parent
17534b9c3f
commit
a58c04d54d
2 changed files with 12 additions and 52 deletions
|
@ -468,41 +468,16 @@ public final class DataUtilities {
|
||||||
*
|
*
|
||||||
* @param program the program
|
* @param program the program
|
||||||
* @param address the data address
|
* @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) {
|
public static Data getDataAtAddress(Program program, Address address) {
|
||||||
if (address == null) {
|
if (address == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Listing listing = program.getListing();
|
Listing listing = program.getListing();
|
||||||
return listing.getDataAt(address);
|
CodeUnit cu = listing.getCodeUnitAt(address);
|
||||||
}
|
if (cu instanceof Data) {
|
||||||
|
return (Data) cu;
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,7 +232,7 @@ public class StringDataInstance {
|
||||||
private final int charSize;
|
private final int charSize;
|
||||||
private final int paddedCharSize;
|
private final int paddedCharSize;
|
||||||
private final StringLayoutEnum stringLayout;
|
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 Endian endianSetting;
|
||||||
|
|
||||||
private final boolean showTranslation;
|
private final boolean showTranslation;
|
||||||
|
@ -307,31 +307,16 @@ public class StringDataInstance {
|
||||||
this.length = length;
|
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) {
|
private static String getTranslatedValue(Settings settings, MemBuffer buf) {
|
||||||
Data data = getData(settings, buf);
|
// Translation only exists for defined Data which corresponds to settings.
|
||||||
if (data == null) {
|
if (settings instanceof Data) {
|
||||||
return null;
|
Data data = (Data) settings;
|
||||||
}
|
if (data.isDefined()) {
|
||||||
return TRANSLATION.getTranslatedValue(data);
|
return TRANSLATION.getTranslatedValue(data);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private StringDataInstance(StringDataInstance copyFrom, StringLayoutEnum newLayout,
|
private StringDataInstance(StringDataInstance copyFrom, StringLayoutEnum newLayout,
|
||||||
MemBuffer newBuf, int newLen, String newCharsetName) {
|
MemBuffer newBuf, int newLen, String newCharsetName) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue