Skip to content

Ghidra is a software reverse engineering (SRE) framework

Fixed string mem search for utf8 in case insensitive mode

dragonmacherb2db7056dba2
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/features/base/memsearch/format/StringSearchFormat.java b/Ghidra/Features/Base/src/main/java/ghidra/features/base/memsearch/format/StringSearchFormat.java
index 2ed5294f0d..7e80d998e8 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/features/base/memsearch/format/StringSearchFormat.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/features/base/memsearch/format/StringSearchFormat.java
@@ -107,9 +107,8 @@ class StringSearchFormat extends SearchFormat {
private int bytesPerCharUTF8(byte zByte) {
// This method is intended for UTF-8 encoding.
- // The first byte in a sequence of UTF-8 bytes can tell
- // us how many bytes make up a char.
- int offset = 1;
+ // The first byte in a sequence of UTF-8 bytes can tell us how many bytes make up a char.
+ int offset = 0;
// If the char is ascii, this loop will be skipped.
while ((zByte & 0x80) != 0x00) {
zByte <<= 1;
diff --git a/Ghidra/Features/Base/src/test/java/ghidra/features/base/memsearch/format/StringSearchFormatTest.java b/Ghidra/Features/Base/src/test/java/ghidra/features/base/memsearch/format/StringSearchFormatTest.java
index dfc94da9b6..781c64d116 100644
--- a/Ghidra/Features/Base/src/test/java/ghidra/features/base/memsearch/format/StringSearchFormatTest.java
+++ b/Ghidra/Features/Base/src/test/java/ghidra/features/base/memsearch/format/StringSearchFormatTest.java
@@ -64,6 +64,16 @@ public class StringSearchFormatTest extends AbstractSearchFormatTest {
assertMask(0xdf, 0xdf, 0xdf, 0xff, 0xff);
}
+ @Test
+ public void testFoo() {
+ settings = settings.withStringCharset(StandardCharsets.UTF_8);
+ settings = settings.withCaseSensitive(false);
+ matcher = parse("éa");
+
+ assertBytes(0xc3, 0xa9, 0x41); // éA upper-case the ASCII portion of the bytes
+ assertMask(0xff, 0xff, 0xdf);
+ }
+
@Test
public void testEscapeSequence() {
settings = settings.withUseEscapeSequence(false);