From 134bd844d66635cbce17b2ccc805b86e7e239252 Mon Sep 17 00:00:00 2001 From: hakril Date: Mon, 6 Sep 2021 22:07:00 +0200 Subject: [PATCH] Fixed issue #30 about NdrContextHandle packing in py3 --- tests/test_ndr.py | 5 ++++- windows/rpc/ndr.py | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/test_ndr.py b/tests/test_ndr.py index e9ea1cc..1f0f7c4 100644 --- a/tests/test_ndr.py +++ b/tests/test_ndr.py @@ -67,6 +67,9 @@ NDR_PACK_TEST_CASE = [ (ndr.make_parameters([ndr.NdrByte, ndr.NdrHyper, ndr.NdrByte, ndr.NdrLong, ndr.NdrHyper]), (0x01, 0x4141414141414141, 0x42, 0x43434343, 0x4444444444444444 ), b"\x01PPPPPPPAAAAAAAABPPPCCCCDDDDDDDD"), + # Test NdrContextHandle / NdrGuid (see https://github.com/hakril/PythonForWindows/issues/30) + (ndr.NdrContextHandle, gdef.GUID.from_string("11223344-1122-3344-5566-424344454647"), b'\x00\x00\x00\x00D3"\x11"\x11D3UfBCDEFG'), + (ndr.NdrGuid, gdef.GUID.from_string("11223344-1122-3344-5566-424344454647"), b'D3"\x11"\x11D3UfBCDEFG'), # Complexe structure (with 4B alignement of 20B structure) (ndr.make_parameters([ndr.NdrShort, DoubleDwordStructure]), (0x0101, [0x41414141, 0x42424242, 0x43434343, 0x44444444, 0x45454545]), @@ -165,4 +168,4 @@ def test_ndr_packing_complex_uac_call(): 0xffffffff]) # UAC Timeout expected_result = b'\x02\x02\x02\x02 \x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00c\x00:\x00\\\x00w\x00i\x00n\x00d\x00o\x00w\x00s\x00\\\x00s\x00y\x00s\x00t\x00e\x00m\x003\x002\x00\\\x00n\x00o\x00t\x00e\x00p\x00a\x00d\x00.\x00e\x00x\x00e\x00\x00\x00\x02\x02\x02\x02\x16\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00\x00N\x00O\x00T\x00_\x00A\x00L\x00I\x00G\x00N\x00E\x00D\x00_\x00S\x00T\x00R\x00I\x00N\x00G\x00X\x00X\x00X\x00\x00\x00\x11\x00\x00\x00\x00\x04\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00PP\x10\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00W\x00i\x00n\x00S\x00t\x00a\x000\x00\\\x00D\x00e\x00f\x00a\x00u\x00l\x00t\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff' - assert parameters == expected_result \ No newline at end of file + assert parameters == expected_result diff --git a/windows/rpc/ndr.py b/windows/rpc/ndr.py index f34636e..4365606 100644 --- a/windows/rpc/ndr.py +++ b/windows/rpc/ndr.py @@ -3,6 +3,11 @@ import windows.generated_def as gdef import struct +try: + unichr # Py2/Py3 compat +except NameError: + unichr = chr + # http://pubs.opengroup.org/onlinepubs/9629399/chap14.htm#tagcjh_19_03_07 ## Array @@ -259,7 +264,7 @@ class NdrGuid(object): def pack(cls, data): if not isinstance(data, gdef.IID): data = gdef.IID.from_string(data) - return str(bytearray(data)) + return bytes(bytearray(data)) @classmethod def unpack(self, stream): @@ -276,7 +281,7 @@ class NdrContextHandle(object): def pack(cls, data): if not isinstance(data, gdef.IID): data = gdef.IID.from_string(data) - return struct.pack("