hakril / PythonForWindows

A codebase aimed to make interaction with Windows and native execution easier
BSD 3-Clause "New" or "Revised" License
573 stars 112 forks source link

Fix rpc data marshall aligment issue #59

Closed syjzwjj closed 1 week ago

syjzwjj commented 4 months ago

NdrWriteStream object use to marshall data to the memory, however, there's a problem when do alignment. Let' see the rpc interface idl below:

int Output2(
    [in] handle_t hBinding,
    [in] short* Output1,
    [in] hyper* Output2);

The code we reach the interface:

# ...
class Output2(ndr.NdrParameters):
    MEMBERS = [ndr.NdrShort, ndr.NdrHyper]

# ... 
params = Output2.pack([0x4242, 0x4141414141414141])
# ...

We observed the server side argument memory:

000001f2`8bd2d1f8  50505050`50504040 41414141`41414141
000001f2`8bd2d208  00000000`00000000 00000000`00000000
000001f2`8bd2d218  00000000`00000000 00000000`00000000

Althougth the data successful passed to the serverside with no unmarshall error, the padding data P cause confusion for me when I do rpc research, especially when it these simple type stored into structure. Hope this patch can fix this problem, thanks!

hakril commented 1 week ago

Hi,

Thank you for the Pull request. Unfortunately, I will not merge your PR as-is. My choice of using P (or 0x50) as the padding value is a deliberate and considered choice from me. Indeed, this allows me to easily make the difference between chose NULL values & parameters VS bytes which are exclusively here for automatic padding. These bytes being padding, they are ignored and the choice of 0x50 should not have any impact on the receiving end. Thus I would not consider it a bug.

If you want, I would be open to a PR that allow choosing/setting the padding bytes used by ndr.py. as a parameter.