Decompresses an entire compressed buffer
#include <WinAPISys.au3>
_WinAPI_DecompressBuffer ( $pUncompressedBuffer, $iUncompressedSize, $pCompressedBuffer, $iCompressedSize [, $iFormat = $COMPRESSION_FORMAT_LZNT1] )
| $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 (see remark) |
| 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.
If $iFormat = $COMPRESSION_FORMAT_XPRESS_HUFF the size of the buffer compressed must have a minimum lenght (not MSDN documented = 1024).
To compress an uncompressed buffer, use the _WinAPI_CompressBuffer() function.
Search RtlDecompressBuffer in MSDN Library.
#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
Local $iCompressFormat = $COMPRESSION_FORMAT_XPRESS_HUFF
;~ Local $iCompressFormat = $COMPRESSION_FORMAT_XPRESS
;~ Local $iCompressFormat = $COMPRESSION_FORMAT_LZNT1
; Compress binary data
Local $dData = Binary('0x00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF')
If $iCompressFormat = $COMPRESSION_FORMAT_XPRESS_HUFF Then
$dData &= $dData ;XPRESS_HUFF looks to struggle with short data
$dData &= $dData
$dData &= $dData
$dData &= $dData
EndIf
Local $iSize = BinaryLen($dData)
DllStructSetData(DllStructCreate('byte[' & $iSize & ']', $a_pBuffer[0]), 1, $dData)
ConsoleWrite('Initial: $iSize = ' & $iSize & @CRLF)
$iSize = _WinAPI_CompressBuffer($a_pBuffer[0], $iSize, $a_pBuffer[1], 1024, BitOR($iCompressFormat, $COMPRESSION_ENGINE_MAXIMUM))
If Not @error Then
ConsoleWrite('Compressed: $iSize = ' & $iSize & ' : ' & DllStructGetData(DllStructCreate('byte[' & $iSize & ']', $a_pBuffer[1]), 1) & @CRLF)
Else
ConsoleWrite('Uncompressed: $iSize = ' & $iSize & ' : ' & ' Error code: ' & @error & ' Extended code: ' & @extended & ' (0x' & Hex(@extended) & ')' & @CRLF)
EndIf
; Decompress data
$iSize = _WinAPI_DecompressBuffer($a_pBuffer[0], 1024, $a_pBuffer[1], $iSize, BitOR($iCompressFormat, $COMPRESSION_ENGINE_MAXIMUM))
If Not @error Then
ConsoleWrite('Uncompressed: $iSize = ' & $iSize & ' : ' & DllStructGetData(DllStructCreate('byte[' & $iSize & ']', $a_pBuffer[0]), 1) & @CRLF)
Else
ConsoleWrite('Uncompressed: $iSize = ' & $iSize & ' : ' & ' Error code: ' & @error & ' Extended code: ' & @extended & ' (0x' & Hex(@extended) & ')' & @CRLF)
EndIf
; Free memory
For $i = 0 To 1
_WinAPI_FreeMemory($a_pBuffer[$i])
Next