From 19da4ad36a35b6d6c1bd75225fb19259deb3beb0 Mon Sep 17 00:00:00 2001 From: hakril Date: Wed, 15 Oct 2025 14:40:38 +0200 Subject: [PATCH] Fix NdrCString not accepting strings in python3 --- windows/rpc/ndr.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/windows/rpc/ndr.py b/windows/rpc/ndr.py index 88af1431..065447b8 100644 --- a/windows/rpc/ndr.py +++ b/windows/rpc/ndr.py @@ -160,6 +160,9 @@ def pack(cls, data): return None if not data.endswith('\x00'): data += '\x00' + # Technically windows NDR seems to accept any bitstream that ends with '\x00\x00' here + # And not limited to valid utf-16 + # Exemple: b'\x41\x00\x00\xD8' data = data.encode("utf-16-le") l = (len(data) // 2) result = struct.pack("<3I", l, 0, l) @@ -179,7 +182,7 @@ def unpack(cls, stream): @classmethod def get_alignment(self): - # Not sur, but size is on 4 bytes so... + # Not sure, but size is on 4 bytes so... return 4 class NdrCString(object): @@ -190,6 +193,10 @@ def pack(cls, data): return None if not data.endswith('\x00'): data += '\x00' + # Windows NDR seems to accept any bitstream in a FC_C_CSTRING + # I was able to send range(1, 256) + b"\x00" + # For now play safe for user and only accept encoded with always keep the same number of bytes + data = data.encode("ascii") l = len(data) result = struct.pack("<3I", l, 0, l) result += data