Skip to content

Commit d6ad334

Browse files
committed
Fix NdrCString not accepting strings in python3
1 parent 7142a8d commit d6ad334

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

windows/rpc/ndr.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ def pack(cls, data):
160160
return None
161161
if not data.endswith('\x00'):
162162
data += '\x00'
163+
# Technically windows NDR seems to accept any bitstream that ends with '\x00\x00' here
164+
# And not limited to valid utf-16
165+
# Exemple: b'\x41\x00\x00\xD8'
163166
data = data.encode("utf-16-le")
164167
l = (len(data) // 2)
165168
result = struct.pack("<3I", l, 0, l)
@@ -179,7 +182,7 @@ def unpack(cls, stream):
179182

180183
@classmethod
181184
def get_alignment(self):
182-
# Not sur, but size is on 4 bytes so...
185+
# Not sure, but size is on 4 bytes so...
183186
return 4
184187

185188
class NdrCString(object):
@@ -190,6 +193,10 @@ def pack(cls, data):
190193
return None
191194
if not data.endswith('\x00'):
192195
data += '\x00'
196+
# Windows NDR seems to accept any bitstream in a FC_C_CSTRING
197+
# I was able to send range(1, 256) + b"\x00"
198+
# For now play safe for user and only accept encoded with always keep the same number of bytes
199+
data = data.encode("ascii")
193200
l = len(data)
194201
result = struct.pack("<3I", l, 0, l)
195202
result += data

0 commit comments

Comments
 (0)