Skip to content

Commit bfcf6a1

Browse files
committed
fix: Optimize format_data function to use UTF-16LE encoding for improved performance
1 parent c478681 commit bfcf6a1

File tree

1 file changed

+1
-14
lines changed

1 file changed

+1
-14
lines changed

Jiyu_attack.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,20 +172,7 @@ def format_data(
172172
throw_error(f"Expected string, got {type(data).__name__}", errors=errors)
173173
if not isinstance(max_length, int) or max_length <= 0:
174174
throw_error(f"Invalid maximum length: {max_length}", errors=errors)
175-
ret = bytearray()
176-
for s in data:
177-
c = ord(s)
178-
if c > 0xFFFF:
179-
throw_error(f"Character {s} (0x{c:X}) is not supported.", errors=errors)
180-
else:
181-
ret.append(c & 0xFF)
182-
ret.append((c >> 8) & 0xFF)
183-
if len(ret) > max_length:
184-
throw_error(
185-
f"Data length exceeds maximum length of {max_length} bytes: {len(ret)} bytes.",
186-
errors=errors,
187-
)
188-
return bytes(ret.ljust(max_length, b"\x00"))[:max_length]
175+
return data.encode("utf-16le").ljust(max_length, b"\x00")[:max_length]
189176

190177

191178
def pkg_message(

0 commit comments

Comments
 (0)