解析字符串时保留更多信息

This commit is contained in:
2026-05-01 15:52:15 +08:00
parent df4e7d832d
commit cf610751eb

View File

@@ -42,7 +42,7 @@ def tohex(data: bytes) -> str:
def human_string(data: bytes, is_hex: bool = False, encoding: str = 'utf-8') -> str:
"""将字节数据转换为可读字符串"""
return tohex(data) if is_hex else data.decode(encoding, 'backslashreplace')
return tohex(data) if is_hex else data.decode('utf-8', 'backslashreplace').replace('\x00', '\\x00')
def uint16(b: bytes) -> int:
"""从字节读取无符号16位整数"""