Decompresses an entire compressed buffer
#include <WinAPISys.au3>
_WinAPI_DecompressBuffer ( $pUncompressedBuffer, $iUncompressedSize, $pCompressedBuffer, $iCompressedSize [, $iFormat = 0x0002] )
$pUncompressedBuffer | A pointer to a caller-allocated buffer that receives the decompressed data from compressed buffer. |
$iUncompressedSize | The size of the uncompressed buffer, in bytes. |
$pCompressedBuffer | A pointer to the buffer that contains the data to decompress. |
$iCompressedSize | The size of the compressed buffer, in bytes. |
$iFormat | [optional] The compression format of the data in compressed buffer. This parameter must be one of the following values: $COMPRESSION_FORMAT_LZNT1 (Default) $COMPRESSION_FORMAT_XPRESS $COMPRESSION_FORMAT_XPRESS_HUFF |
Success: | The size of the decompressed data stored in uncompressed buffer, in bytes. |
Failure: | 0 and sets the @error flag to non-zero, @extended flag may contain the NTSTATUS error code. |
The _WinAPI_DecompressBuffer() function takes as input an entire compressed buffer and produces its decompressed equivalent provided that the uncompressed data fits within the specified destination buffer.
To compress an uncompressed buffer, use the _WinAPI_CompressBuffer() function.
Search RtlDecompressBuffer in MSDN Library.
#include <APISysConstants.au3>
#include <WinAPIMem.au3>
#include <WinAPISys.au3>
; Create compressed and uncompressed buffers
Local $a_pBuffer[2]
For $i = 0 To 1
$a_pBuffer[$i] = _WinAPI_CreateBuffer(1024)
Next
; Compress binary data
Local $dData = Binary('0x00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF')
Local $iSize = BinaryLen($dData)
DllStructSetData(DllStructCreate('byte[' & $iSize & ']', $a_pBuffer[0]), 1, $dData)
$iSize = _WinAPI_CompressBuffer($a_pBuffer[0], $iSize, $a_pBuffer[1], 1024, BitOR($COMPRESSION_FORMAT_LZNT1, $COMPRESSION_ENGINE_MAXIMUM))
If Not @error Then
ConsoleWrite('Compressed: ' & DllStructGetData(DllStructCreate('byte[' & $iSize & ']', $a_pBuffer[1]), 1) & @CRLF)
EndIf
; Decompress data
$iSize = _WinAPI_DecompressBuffer($a_pBuffer[0], 1024, $a_pBuffer[1], $iSize)
If Not @error Then
ConsoleWrite('Uncompressed: ' & DllStructGetData(DllStructCreate('byte[' & $iSize & ']', $a_pBuffer[0]), 1) & @CRLF)
EndIf
; Free memory
For $i = 0 To 1
_WinAPI_FreeMemory($a_pBuffer[$i])
Next