From 588f24b0f0f0f9bc9dd3503abc0e6e4d2a01fc98 Mon Sep 17 00:00:00 2001 From: alexisbalbachan Date: Mon, 7 Jul 2025 02:19:44 -0300 Subject: [PATCH] Fix calcUnpackSize for unicode format 'u' by searching for the real NULL-NULL terminator Changed documentation about the 'u' format to clarify that it is UTF16-le --- impacket/structure.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/impacket/structure.py b/impacket/structure.py index 3493e68d9c..e3feaffbe2 100644 --- a/impacket/structure.py +++ b/impacket/structure.py @@ -11,6 +11,8 @@ from __future__ import division from __future__ import print_function + +import re from struct import pack, unpack, calcsize import six @@ -66,7 +68,7 @@ class is the class to use when unpacking ':' fields. some additional format specifiers: : just copy the bytes from the field into the output string (input may be string, other structure, or anything responding to __str__()) (for unpacking, all what's left is returned) z same as :, but adds a NUL byte at the end (asciiz) (for unpacking the first NUL byte is used as terminator) [asciiz string] - u same as z, but adds two NUL bytes at the end (after padding to an even size with NULs). (same for unpacking) [unicode string] + u same as z, but adds two NUL bytes at the end (after padding to an even size with NULs). (same for unpacking) [UTF16-le encoded bytes] w DCE-RPC/NDR string (it's a macro for [ '