Skip to content

Commit adda4c7

Browse files
committed
Slightly improve string extraction performance
1 parent b25cbe1 commit adda4c7

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

qiling/os/utils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,21 @@ def string_appearance(self, s: str) -> None:
6868
self.appeared_strings.setdefault(token, set()).add(self.syscalls_counter)
6969

7070
@staticmethod
71-
def read_string(ql: Qiling, address: int, terminator: str) -> str:
72-
result = ""
71+
def read_string(ql: Qiling, address: int, terminator: bytes) -> str:
72+
result = bytearray()
7373
charlen = len(terminator)
7474

7575
char = ql.mem.read(address, charlen)
7676

77-
while char.decode(errors="ignore") != terminator:
77+
while char != terminator:
7878
address += charlen
79-
result += char.decode(errors="ignore")
79+
result += char
8080
char = ql.mem.read(address, charlen)
8181

82-
return result
82+
return result.decode(errors="ignore")
8383

8484
def read_wstring(self, address: int) -> str:
85-
s = QlOsUtils.read_string(self.ql, address, '\x00\x00')
85+
s = QlOsUtils.read_string(self.ql, address, b'\x00\x00')
8686

8787
# We need to remove \x00 inside the string. Compares do not work otherwise
8888
s = s.replace("\x00", "")
@@ -91,7 +91,7 @@ def read_wstring(self, address: int) -> str:
9191
return s
9292

9393
def read_cstring(self, address: int) -> str:
94-
s = QlOsUtils.read_string(self.ql, address, '\x00')
94+
s = QlOsUtils.read_string(self.ql, address, b'\x00')
9595

9696
self.string_appearance(s)
9797

0 commit comments

Comments
 (0)