@@ -1696,6 +1696,42 @@ def generic_read(self, addr: int, attributes: list):
16961696 already_read += size
16971697 self .addr = addr
16981698
1699+ class AlignedWindowsStruct (WindowsStruct ):
1700+ def __init__ (self , ql ):
1701+ super ().__init__ (ql )
1702+
1703+ def write (self , addr ):
1704+ super ().write (addr )
1705+
1706+ def read (self , addr ):
1707+ super ().read (addr )
1708+
1709+ def generic_write (self , addr : int , attributes : list ):
1710+ super ().generic_write (addr , attributes )
1711+
1712+ def generic_read (self , addr : int , attributes : list ):
1713+ self .ql .log .debug ("Reading unpacked Windows object aligned " + self .__class__ .__name__ )
1714+ already_read = 0
1715+ for elem in attributes :
1716+ (val , size , endianness , type , alignment ) = elem
1717+ if already_read != 0 :
1718+ modulo = already_read % alignment
1719+ already_read = already_read + modulo
1720+
1721+ value = self .ql .mem .read (addr + already_read , size )
1722+ self .ql .log .debug ("Reading from %x value %s" % (addr + already_read , value ))
1723+ if type == int :
1724+ elem [0 ] = int .from_bytes (value , endianness )
1725+ elif type == bytes :
1726+ elem [0 ] = value
1727+ elif issubclass (type , WindowsStruct ):
1728+ obj = type (self .ql )
1729+ obj .read (addr )
1730+ elem [0 ] = obj
1731+ else :
1732+ raise QlErrorNotImplemented ("API not implemented" )
1733+ already_read += size
1734+ self .addr = addr
16991735
17001736class Token :
17011737 class TokenInformationClass (IntEnum ):
@@ -2234,7 +2270,7 @@ def read(self, addr):
22342270# USHORT MaximumLength;
22352271# PWSTR Buffer;
22362272# } UNICODE_STRING
2237- class UnicodeString (WindowsStruct ):
2273+ class UnicodeString (AlignedWindowsStruct ):
22382274 def write (self , addr ):
22392275 super ().generic_write (addr , [self .length , self .maxLength , self .buffer ])
22402276
@@ -2243,10 +2279,16 @@ def read(self, addr):
22432279
22442280 def __init__ (self , ql , length = None , maxLength = None , buffer = None ):
22452281 super ().__init__ (ql )
2246- self .size = self .USHORT_SIZE * 2 + self .POINTER_SIZE
2247- self .length = [length , self .USHORT_SIZE , "little" , int ]
2248- self .maxLength = [maxLength , self .USHORT_SIZE , "little" , int ]
2249- self .buffer = [buffer , self .POINTER_SIZE , "little" , int ]
2282+
2283+ # on x64, self.buffer is aligned to 8
2284+ if (ql .archtype == 32 ):
2285+ self .size = self .USHORT_SIZE * 2 + self .POINTER_SIZE
2286+ else :
2287+ self .size = self .USHORT_SIZE * 2 + 4 + self .POINTER_SIZE
2288+
2289+ self .length = [length , self .USHORT_SIZE , "little" , int , self .USHORT_SIZE ]
2290+ self .maxLength = [maxLength , self .USHORT_SIZE , "little" , int , self .USHORT_SIZE ]
2291+ self .buffer = [buffer , self .POINTER_SIZE , "little" , int , self .POINTER_SIZE ]
22502292
22512293
22522294# typedef struct _OBJECT_TYPE_INFORMATION {
0 commit comments