From 59b49b572f6e2b048e67cd69a37cd7d020666cac Mon Sep 17 00:00:00 2001 From: Hakan Yavuz Date: Sat, 19 Oct 2024 12:36:02 +0300 Subject: [PATCH] unicode encoding error fix --- impacket/structure.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/impacket/structure.py b/impacket/structure.py index e0bf0f2482..3522bdfce1 100644 --- a/impacket/structure.py +++ b/impacket/structure.py @@ -12,7 +12,7 @@ from __future__ import division from __future__ import print_function from struct import pack, unpack, calcsize -from six import b, PY3 +from six import ensure_binary, PY3 from binascii import hexlify @@ -197,7 +197,7 @@ def pack(self, format, data, field = None): # quote specifier if format[:1] == "'" or format[:1] == '"': - return b(format[1:]) + return ensure_binary(format[1:]) # code specifier two = format.split('=') @@ -245,26 +245,26 @@ def pack(self, format, data, field = None): # "printf" string specifier if format[:1] == '%': # format string like specifier - return b(format % data) + return ensure_binary(format % data) # asciiz specifier if format[:1] == 'z': if isinstance(data,bytes): - return data + b('\0') - return bytes(b(data)+b('\0')) + return data + ensure_binary('\0') + return bytes(ensure_binary(data)+ensure_binary('\0')) # unicode specifier if format[:1] == 'u': - return bytes(data+b('\0\0') + (len(data) & 1 and b('\0') or b'')) + return bytes(data+ensure_binary('\0\0') + (len(data) & 1 and ensure_binary('\0') or b'')) # DCE-RPC/NDR string specifier if format[:1] == 'w': if len(data) == 0: - data = b('\0\0') + data = ensure_binary('\0\0') elif len(data) % 2: - data = b(data) + b('\0') + data = ensure_binary(data) + ensure_binary('\0') l = pack('