Compare commits

...

6 Commits

Author SHA1 Message Date
hakril f920ff5644 Merge pull request #86 from hakril/add_ndr_tests
Add tests for NdrCString & NdrWString packing. Fix #84
2025-10-15 06:36:39 -07:00
hakril d6ad3343e8 Fix NdrCString not accepting strings in python3 2025-10-15 15:27:31 +02:00
hakril 7142a8ddb8 Add new found prefix to apiset map dll name : SchemaExt- 2025-10-15 15:18:34 +02:00
hakril cf09ed86a9 More investigation of apisetmap test bug 2025-10-15 15:09:50 +02:00
hakril 1509f7bd56 Investigate bug in apisetmap testing on gitlab CI 2025-10-15 15:01:03 +02:00
hakril c7c8830ce5 Add tests for NdrCString & NdrWString packing 2025-10-15 14:49:25 +02:00
3 changed files with 14 additions and 2 deletions
+1 -1
View File
@@ -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:
+5
View File
@@ -58,6 +58,11 @@ target = "APPP\x01\x02\x03\x04\x05\x06\x07\x08\x44PPP\x09\x0a\x0b\x0c\x0d\x0e\x0
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
+8 -1
View File
@@ -160,6 +160,9 @@ class NdrWString(object):
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 @@ class NdrWString(object):
@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 @@ class NdrCString(object):
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