@@ -266,6 +266,11 @@ def unpack(self, stream):
266266 rawguid = stream .partial_unpack ("16s" )[0 ]
267267 return gdef .IID .from_buffer_copy (rawguid )
268268
269+ @classmethod
270+ def get_alignment (self ):
271+ return 1
272+
273+
269274class NdrContextHandle (object ):
270275 @classmethod
271276 def pack (cls , data ):
@@ -278,6 +283,11 @@ def unpack(self, stream):
278283 attributes , rawguid = stream .partial_unpack ("<I16s" )
279284 return gdef .IID .from_buffer_copy (rawguid )
280285
286+ @classmethod
287+ def get_alignment (self ):
288+ return 4
289+
290+
281291
282292class NdrStructure (object ):
283293 """a NDR structure that tries to respect the rules of pointer packing, this class should be subclassed with
@@ -298,15 +308,19 @@ def pack(cls, data):
298308 res_size = 0
299309 pointed = []
300310 outstream = NdrWriteStream ()
311+ pointed_to_pack = []
312+ # pointedoutstream = NdrWriteStream()
301313 for i , (member , memberdata ) in enumerate (zip (cls .MEMBERS , data )):
302314 if hasattr (member , "pack_in_struct" ):
303315 x , y = member .pack_in_struct (memberdata , i )
304- outstream .align (member .get_alignment ())
316+ assert len (x ) == 4 , "Pointer should be size 4"
317+ # Write the pointer
318+ outstream .align (4 )
305319 outstream .write (x )
306- # res.append(x)
307- # res_size += len(x)
308320 if y is not None :
309- pointed .append (y )
321+ # Store the info to the pointed to pack
322+ pointed_to_pack .append ((member .subcls .get_alignment (), y ))
323+ # pointedoutstream.write(y)
310324 elif hasattr (member , "pack_conformant" ):
311325 size , data = member .pack_conformant (memberdata )
312326 outstream .align (member .get_alignment ())
@@ -318,7 +332,11 @@ def pack(cls, data):
318332 packed_member = member .pack (memberdata )
319333 outstream .align (member .get_alignment ())
320334 outstream .write (packed_member )
321- return dword_pad (b"" .join (conformant_size )) + outstream .get_data () + dword_pad (b"" .join (pointed ))
335+ # Pack the pointed to the stream
336+ for alignement , pointed_data in pointed_to_pack :
337+ outstream .align (alignement )
338+ outstream .write (pointed_data )
339+ return dword_pad (b"" .join (conformant_size )) + outstream .get_data ()
322340
323341 @classmethod
324342 def unpack (cls , stream ):
0 commit comments