GP-2048 addressing code review comments

GP-2048 offcut format strings
This commit is contained in:
James 2022-05-23 17:05:20 -04:00
parent 3a09507990
commit 51a433ef04
2 changed files with 27 additions and 10 deletions

View file

@ -109,6 +109,25 @@ public class PcodeFunctionParser {
functionName, data.getDefaultValueRepresentation())); functionName, data.getDefaultValueRepresentation()));
hasDefinedFormatString = true; hasDefinedFormatString = true;
} }
else {
//check for offcut references into a larger defined string
Data containing = program.getListing().getDataContaining(ramSpaceAddress);
if (containing == null) {
continue;
}
if (addressToCandidateData.containsKey(containing.getAddress())) {
StringDataInstance entire =
StringDataInstance.getStringDataInstance(containing);
String subString = entire.getByteOffcut(
(int) (ramSpaceAddress.getOffset() - containing.getAddress().getOffset()))
.getStringValue();
if (subString != null) {
functionCallDataList.add(new FunctionCallData(ast.getSeqnum().getTarget(),
functionName, subString));
hasDefinedFormatString = true;
}
}
}
} }
return hasDefinedFormatString; return hasDefinedFormatString;
} }

View file

@ -353,8 +353,7 @@ public class StringDataInstance {
return StringLayoutEnum.NULL_TERMINATED_BOUNDED; return StringLayoutEnum.NULL_TERMINATED_BOUNDED;
} }
static String getCharsetNameFromDataTypeOrSettings(DataType dataType, static String getCharsetNameFromDataTypeOrSettings(DataType dataType, Settings settings) {
Settings settings) {
if (dataType instanceof BitFieldDataType) { if (dataType instanceof BitFieldDataType) {
dataType = ((BitFieldDataType) dataType).getBaseDataType(); dataType = ((BitFieldDataType) dataType).getBaseDataType();
} }
@ -639,9 +638,9 @@ public class StringDataInstance {
} }
byte[] unpaddedBytes = new byte[(paddedBytes.length / paddedCharSize) * charSize]; byte[] unpaddedBytes = new byte[(paddedBytes.length / paddedCharSize) * charSize];
for (int srcOffset = buf.isBigEndian() ? paddedCharSize - charSize : 0, destOffset = for (int srcOffset = buf.isBigEndian() ? paddedCharSize - charSize : 0,
0; srcOffset < paddedBytes.length; srcOffset += paddedCharSize, destOffset += destOffset = 0; srcOffset < paddedBytes.length; srcOffset +=
charSize) { paddedCharSize, destOffset += charSize) {
System.arraycopy(paddedBytes, srcOffset, unpaddedBytes, destOffset, charSize); System.arraycopy(paddedBytes, srcOffset, unpaddedBytes, destOffset, charSize);
} }
@ -961,8 +960,7 @@ public class StringDataInstance {
return false; return false;
} }
long origCodePointValue = DataConverter.getInstance(buf.isBigEndian()) long origCodePointValue = DataConverter.getInstance(buf.isBigEndian())
.getValue(stringBytes, .getValue(stringBytes, byteOffset, charSize);
byteOffset, charSize);
return origCodePointValue == StringUtilities.UNICODE_REPLACEMENT; return origCodePointValue == StringUtilities.UNICODE_REPLACEMENT;
} }
@ -1023,12 +1021,12 @@ public class StringDataInstance {
* Returns a new {@link StringDataInstance} that points to the string characters that start at * Returns a new {@link StringDataInstance} that points to the string characters that start at
* {@code byteOffset} from the start of this instance. * {@code byteOffset} from the start of this instance.
* <p> * <p>
* If the requested offset is not valid, the base string instance (itself) will be returned * If the requested offset is not valid, StringDataInstance.NULL_INSTANCE is returned.
* instead of a new instance.
* <p> * <p>
* *
* @param byteOffset number of bytes from start of data instance to start new instance. * @param byteOffset number of bytes from start of data instance to start new instance.
* @return new StringDataInstance, or <code>this</code> if offset not valid. * @return new StringDataInstance, or <code>StringDataInstance.NULL_INSTANCE</code> if
* offset not valid.
*/ */
public StringDataInstance getByteOffcut(int byteOffset) { public StringDataInstance getByteOffcut(int byteOffset) {
if (isBadCharSize() || isProbe() || !isValidOffcutOffset(byteOffset)) { if (isBadCharSize() || isProbe() || !isValidOffcutOffset(byteOffset)) {