Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/test_apisetmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def dumped_apisetmap_base_and_version(request):
ctypes_data = ctypes.c_buffer(data)
yield ctypes.addressof(ctypes_data), version

KNOWN_APISETMAP_PREFIX = ["api-", "ext-", "MS-Win-"]
KNOWN_APISETMAP_PREFIX = ["api-", "ext-", "MS-Win-", "SchemaExt-"]

def verify_apisetmap_parsing(apisetmap_base, version=None):
if version is not None:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_ndr.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ class ComplexAlignementStructure(ndr.NdrStructure):
NDR_PACK_TEST_CASE = [
# Simple case
(ndr.make_structure([ndr.NdrLong, ndr.NdrLong]), (2, 2), b"\x02\x00\x00\x00\x02\x00\x00\x00"),
# String case, test packing works + \x00 is added if not present in string
(ndr.NdrCString, "Hello", b"\x06\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00Hello\x00PP"),
(ndr.NdrCString, "Hello\x00", b"\x06\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00Hello\x00PP"),
(ndr.NdrWString, "Hello", b"\x06\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00H\x00e\x00l\x00l\x00o\x00\x00\x00"),
(ndr.NdrWString, "Hello\x00", b"\x06\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00H\x00e\x00l\x00l\x00o\x00\x00\x00"),
# Test GUID packing
(ndr.NdrGuid, gdef.GUID.from_string("42424242-42424242-4242-4242-424242424242"), b"BBBBBBBBBBBBBBBB"),
# Test CtxHandle packing
Expand Down
9 changes: 8 additions & 1 deletion windows/rpc/ndr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand All @@ -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
Expand Down