mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 02:39:44 +02:00
Don't use StringUtilties.toQuotedString.
This commit is contained in:
parent
e2354a7976
commit
0c97e44bf7
2 changed files with 39 additions and 12 deletions
|
@ -18,13 +18,13 @@ package ghidra.program.model.data;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
import ghidra.docking.settings.*;
|
import ghidra.docking.settings.*;
|
||||||
|
import ghidra.program.model.data.RenderUnicodeSettingsDefinition.RENDER_ENUM;
|
||||||
import ghidra.program.model.mem.ByteMemBufferImpl;
|
import ghidra.program.model.mem.ByteMemBufferImpl;
|
||||||
import ghidra.program.model.mem.MemBuffer;
|
import ghidra.program.model.mem.MemBuffer;
|
||||||
import ghidra.program.model.scalar.Scalar;
|
import ghidra.program.model.scalar.Scalar;
|
||||||
import ghidra.util.BigEndianDataConverter;
|
import ghidra.util.BigEndianDataConverter;
|
||||||
import ghidra.util.LittleEndianDataConverter;
|
import ghidra.util.LittleEndianDataConverter;
|
||||||
import ghidra.util.StringFormat;
|
import ghidra.util.StringFormat;
|
||||||
import ghidra.util.StringUtilities;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base type for integer data types such as {@link CharDataType chars}, {@link IntegerDataType ints},
|
* Base type for integer data types such as {@link CharDataType chars}, {@link IntegerDataType ints},
|
||||||
|
@ -281,17 +281,10 @@ public abstract class AbstractIntegerDataType extends BuiltIn implements ArraySt
|
||||||
}
|
}
|
||||||
|
|
||||||
MemBuffer memBuf = new ByteMemBufferImpl(null, bytes, true);
|
MemBuffer memBuf = new ByteMemBufferImpl(null, bytes, true);
|
||||||
StringDataInstance instance = new StringDataInstance(this, settings, memBuf, nominalLen);
|
StringDataInstance instance = new StringDataInstance(this, settings, memBuf,
|
||||||
if (bytes.length == 1) {
|
nominalLen, RENDER_ENUM.ESC_SEQ);
|
||||||
return instance.getCharRepresentation();
|
return bytes.length == 1 ? instance.getCharRepresentation() :
|
||||||
}
|
instance.getStringRepresentation();
|
||||||
|
|
||||||
String stringRepresentation = instance.getStringRepresentation();
|
|
||||||
if (stringRepresentation.length() != nominalLen) {
|
|
||||||
stringRepresentation = StringUtilities.toQuotedString(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
return stringRepresentation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String valStr;
|
String valStr;
|
||||||
|
|
|
@ -205,6 +205,37 @@ public class StringDataInstance {
|
||||||
this.length = length;
|
this.length = length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a string instance using the data in the {@link MemBuffer} and the settings
|
||||||
|
* pulled from the {@link AbstractStringDataType string data type} but using the given
|
||||||
|
* {@link RenderUnicodeSettingsDefinition.RENDER_ENUM rendering setting}.
|
||||||
|
*
|
||||||
|
* @param stringDataType {@link AbstractStringDataType} common string base data type.
|
||||||
|
* @param settings {@link Settings} attached to the data location.
|
||||||
|
* @param buf {@link MemBuffer} containing the data.
|
||||||
|
* @param length Length passed from the caller to the datatype. -1 indicates a 'probe'
|
||||||
|
* trying to detect the length of an unknown string, otherwise it will be the length
|
||||||
|
* of the containing field of the data instance.
|
||||||
|
* @param renderSettings How to render the instance contents.
|
||||||
|
*/
|
||||||
|
public StringDataInstance(DataType dataType, Settings settings, MemBuffer buf, int length,
|
||||||
|
RenderUnicodeSettingsDefinition.RENDER_ENUM renderSettings) {
|
||||||
|
settings = (settings == null) ? SettingsImpl.NO_SETTINGS : settings;
|
||||||
|
this.buf = buf;
|
||||||
|
this.charsetName = getCharsetNameFromDataTypeOrSettings(dataType, settings);
|
||||||
|
this.charSize = CharsetInfo.getInstance().getCharsetCharSize(charsetName);
|
||||||
|
// NOTE: for now only handle padding for charSize == 1
|
||||||
|
this.paddedCharSize =
|
||||||
|
charSize == 1 ? getDataOrganization(dataType).getCharSize() : charSize;
|
||||||
|
this.stringLayout = getLayoutFromDataType(dataType);
|
||||||
|
this.showTranslation = TRANSLATION.isShowTranslated(settings);
|
||||||
|
this.translatedValue = TRANSLATION.getTranslatedValue(settings);
|
||||||
|
this.renderSetting = renderSettings;
|
||||||
|
this.endianSetting = ENDIAN.getEndianess(settings, null);
|
||||||
|
|
||||||
|
this.length = length;
|
||||||
|
}
|
||||||
|
|
||||||
private StringDataInstance(StringDataInstance copyFrom, StringLayoutEnum newLayout,
|
private StringDataInstance(StringDataInstance copyFrom, StringLayoutEnum newLayout,
|
||||||
MemBuffer newBuf, int newLen) {
|
MemBuffer newBuf, int newLen) {
|
||||||
this.charSize = copyFrom.charSize;
|
this.charSize = copyFrom.charSize;
|
||||||
|
@ -234,6 +265,9 @@ public class StringDataInstance {
|
||||||
if (dataType instanceof AbstractStringDataType) {
|
if (dataType instanceof AbstractStringDataType) {
|
||||||
return ((AbstractStringDataType) dataType).getStringLayout();
|
return ((AbstractStringDataType) dataType).getStringLayout();
|
||||||
}
|
}
|
||||||
|
if (dataType instanceof AbstractIntegerDataType) {
|
||||||
|
return StringLayoutEnum.FIXED_LEN;
|
||||||
|
}
|
||||||
return StringLayoutEnum.NULL_TERMINATED_BOUNDED;
|
return StringLayoutEnum.NULL_TERMINATED_BOUNDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue