mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 10:49:34 +02:00
GT-3333, #1255 fix string rendering issue when with dataOrg char sizes >
1 byte. If the language's dataOrg specifies a character size larger than 1 byte, strings with a charSet that uses just 1 byte (ie. UTF-8 strings inside a java .dex file) will incorrectly treat some of the string bytes as padding between array elements. Fixes issue #1255.
This commit is contained in:
parent
7cd82462e9
commit
26750e23f2
2 changed files with 38 additions and 8 deletions
|
@ -45,6 +45,19 @@ public class StringDataTypeTest extends AbstractGTest {
|
|||
private PascalStringDataType pascalString = new PascalStringDataType();
|
||||
private PascalUnicodeDataType pascalUtf16String = new PascalUnicodeDataType();
|
||||
|
||||
private static class DataOrgDTM extends TestDummyDataTypeManager {
|
||||
private DataOrganization dataOrg;
|
||||
|
||||
public DataOrgDTM(DataOrganization dataOrg) {
|
||||
this.dataOrg = dataOrg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataOrganization getDataOrganization() {
|
||||
return dataOrg;
|
||||
}
|
||||
}
|
||||
|
||||
private ByteMemBufferImpl mb(boolean isBE, int... values) {
|
||||
byte[] bytes = new byte[values.length];
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
|
@ -216,6 +229,21 @@ public class StringDataTypeTest extends AbstractGTest {
|
|||
assertEquals("ab\ucc01\u1202", actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStringValue_utf8_2bytechar_dataorg() {
|
||||
// test UTF-8 when the dataorg specifies a 2byte character (ie. JVM)
|
||||
ByteMemBufferImpl buf = mb(false, 'a', 'b', 'c');
|
||||
|
||||
DataOrganizationImpl dataOrg = DataOrganizationImpl.getDefaultOrganization(null);
|
||||
dataOrg.setCharSize(2);
|
||||
DataOrgDTM dtm = new DataOrgDTM(dataOrg);
|
||||
StringUTF8DataType wideCharUTF8DT = new StringUTF8DataType(dtm);
|
||||
|
||||
String actual = (String) wideCharUTF8DT.getValue(buf, newset(), buf.getLength());
|
||||
|
||||
assertEquals("abc", actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStringValue_utf16_le() {
|
||||
ByteMemBufferImpl buf = mb(false, //
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue