mirror of
https://github.com/LongSoft/UEFITool.git
synced 2024-11-26 18:08:23 +08:00
Backport decompression updates from new_engine
This commit is contained in:
parent
9807ff36dc
commit
55c567b999
@ -25,8 +25,8 @@ static ISzAlloc SzAllocForLzma = { &AllocForLzma, &FreeForLzma };
|
|||||||
|
|
||||||
SRes OnProgress(void *p, UInt64 inSize, UInt64 outSize)
|
SRes OnProgress(void *p, UInt64 inSize, UInt64 outSize)
|
||||||
{
|
{
|
||||||
(void)p; (void)inSize; (void)outSize;
|
(void)p; (void)inSize; (void)outSize;
|
||||||
return SZ_OK;
|
return SZ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ICompressProgress g_ProgressCallback = { &OnProgress };
|
static ICompressProgress g_ProgressCallback = { &OnProgress };
|
||||||
@ -35,75 +35,76 @@ STATIC
|
|||||||
UINT64
|
UINT64
|
||||||
EFIAPI
|
EFIAPI
|
||||||
RShiftU64 (
|
RShiftU64 (
|
||||||
UINT64 Operand,
|
UINT64 Operand,
|
||||||
UINT32 Count
|
UINT32 Count
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return Operand >> Count;
|
return Operand >> Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
SetEncodedSizeOfBuf (
|
SetEncodedSizeOfBuf(
|
||||||
UINT64 EncodedSize,
|
UINT64 EncodedSize,
|
||||||
UINT8 *EncodedData
|
UINT8* EncodedData
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
INT32 Index;
|
INT32 Index;
|
||||||
|
|
||||||
EncodedData[LZMA_PROPS_SIZE] = EncodedSize & 0xFF;
|
EncodedData[LZMA_PROPS_SIZE] = EncodedSize & 0xFF;
|
||||||
for (Index = LZMA_PROPS_SIZE + 1; Index <= LZMA_PROPS_SIZE + 7; Index++)
|
for (Index = LZMA_PROPS_SIZE + 1; Index <= LZMA_PROPS_SIZE + 7; Index++)
|
||||||
{
|
{
|
||||||
EncodedSize = RShiftU64(EncodedSize, 8);
|
EncodedSize = RShiftU64(EncodedSize, 8);
|
||||||
EncodedData[Index] = EncodedSize & 0xFF;
|
EncodedData[Index] = EncodedSize & 0xFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
INT32
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
LzmaCompress(
|
LzmaCompress (
|
||||||
CONST UINT8 *Source,
|
CONST UINT8 *Source,
|
||||||
UINTN SourceSize,
|
UINT32 SourceSize,
|
||||||
UINT8 *Destination,
|
UINT8 *Destination,
|
||||||
UINTN *DestinationSize
|
UINT32 *DestinationSize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
SRes LzmaResult;
|
SRes LzmaResult;
|
||||||
CLzmaEncProps props;
|
CLzmaEncProps props;
|
||||||
SizeT propsSize = LZMA_PROPS_SIZE;
|
SizeT propsSize = LZMA_PROPS_SIZE;
|
||||||
SizeT destLen = SourceSize + SourceSize / 3 + 128;
|
SizeT destLen = SourceSize + SourceSize / 3 + 128;
|
||||||
|
|
||||||
if (*DestinationSize < destLen)
|
if (*DestinationSize < (UINT32)destLen)
|
||||||
{
|
{
|
||||||
*DestinationSize = (UINTN)destLen;
|
*DestinationSize = (UINT32)destLen;
|
||||||
return ERR_BUFFER_TOO_SMALL;
|
return EFI_BUFFER_TOO_SMALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
LzmaEncProps_Init(&props);
|
LzmaEncProps_Init(&props);
|
||||||
props.dictSize = LZMA_DICTIONARY_SIZE;
|
// TODO: need to detect this instead of hardcoding
|
||||||
props.level = 9;
|
props.dictSize = LZMA_DICTIONARY_SIZE;
|
||||||
props.fb = 273;
|
props.level = 9;
|
||||||
|
props.fb = 273;
|
||||||
|
|
||||||
LzmaResult = LzmaEncode(
|
LzmaResult = LzmaEncode(
|
||||||
(Byte*)((UINT8*)Destination + LZMA_HEADER_SIZE),
|
(Byte*)((UINT8*)Destination + LZMA_HEADER_SIZE),
|
||||||
&destLen,
|
&destLen,
|
||||||
Source,
|
Source,
|
||||||
SourceSize,
|
(SizeT)SourceSize,
|
||||||
&props,
|
&props,
|
||||||
(UINT8*)Destination,
|
(UINT8*)Destination,
|
||||||
&propsSize,
|
&propsSize,
|
||||||
props.writeEndMark,
|
props.writeEndMark,
|
||||||
&g_ProgressCallback,
|
&g_ProgressCallback,
|
||||||
&SzAllocForLzma,
|
&SzAllocForLzma,
|
||||||
&SzAllocForLzma);
|
&SzAllocForLzma);
|
||||||
|
|
||||||
*DestinationSize = destLen + LZMA_HEADER_SIZE;
|
*DestinationSize = (UINT32)(destLen + LZMA_HEADER_SIZE);
|
||||||
|
|
||||||
SetEncodedSizeOfBuf(SourceSize, Destination);
|
SetEncodedSizeOfBuf(SourceSize, Destination);
|
||||||
|
|
||||||
if (LzmaResult == SZ_OK) {
|
if (LzmaResult == SZ_OK) {
|
||||||
return ERR_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return ERR_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __LZMACOMPRESS_H__
|
#ifndef LZMACOMPRESS_H
|
||||||
#define __LZMACOMPRESS_H__
|
#define LZMACOMPRESS_H
|
||||||
|
|
||||||
#include "SDK/C/Types.h"
|
#include "SDK/C/Types.h"
|
||||||
#include "../basetypes.h"
|
#include "../basetypes.h"
|
||||||
@ -24,16 +24,17 @@ extern "C" {
|
|||||||
#define LZMA_DICTIONARY_SIZE 0x800000
|
#define LZMA_DICTIONARY_SIZE 0x800000
|
||||||
#define _LZMA_SIZE_OPT
|
#define _LZMA_SIZE_OPT
|
||||||
|
|
||||||
INT32
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
LzmaCompress(
|
LzmaCompress (
|
||||||
const UINT8 *Source,
|
const UINT8 *Source,
|
||||||
UINTN SourceSize,
|
UINT32 SourceSize,
|
||||||
UINT8 *Destination,
|
UINT8 *Destination,
|
||||||
UINTN *DestinationSize
|
UINT32 *DestinationSize
|
||||||
);
|
);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
#endif // LZMACOMPRESS_H
|
||||||
|
@ -19,12 +19,12 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||||||
|
|
||||||
UINT64
|
UINT64
|
||||||
EFIAPI
|
EFIAPI
|
||||||
LShiftU64(
|
LShiftU64 (
|
||||||
UINT64 Operand,
|
UINT64 Operand,
|
||||||
UINT32 Count
|
UINT32 Count
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return Operand << Count;
|
return Operand << Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void * AllocForLzma(void *p, size_t size) { (void)p; return malloc(size); }
|
static void * AllocForLzma(void *p, size_t size) { (void)p; return malloc(size); }
|
||||||
@ -39,19 +39,19 @@ Get the size of the uncompressed buffer by parsing EncodeData header.
|
|||||||
@return The size of the uncompressed buffer.
|
@return The size of the uncompressed buffer.
|
||||||
*/
|
*/
|
||||||
UINT64
|
UINT64
|
||||||
GetDecodedSizeOfBuf(
|
GetDecodedSizeOfBuf (
|
||||||
UINT8 *EncodedData
|
UINT8 *EncodedData
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINT64 DecodedSize;
|
UINT64 DecodedSize;
|
||||||
INT32 Index;
|
INT32 Index;
|
||||||
|
|
||||||
// Parse header
|
// Parse header
|
||||||
DecodedSize = 0;
|
DecodedSize = 0;
|
||||||
for (Index = LZMA_PROPS_SIZE + 7; Index >= LZMA_PROPS_SIZE; Index--)
|
for (Index = LZMA_PROPS_SIZE + 7; Index >= LZMA_PROPS_SIZE; Index--)
|
||||||
DecodedSize = LShiftU64(DecodedSize, 8) + EncodedData[Index];
|
DecodedSize = LShiftU64(DecodedSize, 8) + EncodedData[Index];
|
||||||
|
|
||||||
return DecodedSize;
|
return DecodedSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -85,18 +85,27 @@ DestinationSize and the size of the scratch
|
|||||||
buffer was returned ScratchSize.
|
buffer was returned ScratchSize.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
INT32
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
LzmaGetInfo(
|
LzmaGetInfo (
|
||||||
CONST VOID *Source,
|
CONST VOID *Source,
|
||||||
UINTN SourceSize,
|
UINT32 SourceSize,
|
||||||
UINTN *DestinationSize
|
UINT32 *DestinationSize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ASSERT(SourceSize >= LZMA_HEADER_SIZE); (void)SourceSize;
|
UINT64 DecodedSize;
|
||||||
|
ASSERT(SourceSize >= LZMA_HEADER_SIZE);
|
||||||
|
(void)SourceSize;
|
||||||
|
|
||||||
*DestinationSize = (UINTN)GetDecodedSizeOfBuf((UINT8*)Source);
|
DecodedSize = GetDecodedSizeOfBuf((UINT8*)Source);
|
||||||
return ERR_SUCCESS;
|
|
||||||
|
if (DecodedSize <= UINT32_MAX) {
|
||||||
|
*DestinationSize = (UINT32)DecodedSize;
|
||||||
|
return ERR_SUCCESS;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return ERR_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -118,38 +127,38 @@ the uncompressed buffer is returned Destination.
|
|||||||
The source buffer specified by Source is corrupted
|
The source buffer specified by Source is corrupted
|
||||||
(not a valid compressed format).
|
(not a valid compressed format).
|
||||||
*/
|
*/
|
||||||
INT32
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
LzmaDecompress(
|
LzmaDecompress (
|
||||||
CONST VOID *Source,
|
CONST VOID *Source,
|
||||||
UINTN SourceSize,
|
UINT32 SourceSize,
|
||||||
VOID *Destination
|
VOID *Destination
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
SRes LzmaResult;
|
SRes LzmaResult;
|
||||||
ELzmaStatus Status;
|
ELzmaStatus Status;
|
||||||
SizeT DecodedBufSize;
|
SizeT DecodedBufSize;
|
||||||
SizeT EncodedDataSize;
|
SizeT EncodedDataSize;
|
||||||
|
|
||||||
DecodedBufSize = (SizeT)GetDecodedSizeOfBuf((UINT8*)Source);
|
DecodedBufSize = (SizeT)GetDecodedSizeOfBuf((UINT8*)Source);
|
||||||
EncodedDataSize = (SizeT)(SourceSize - LZMA_HEADER_SIZE);
|
EncodedDataSize = (SizeT)(SourceSize - LZMA_HEADER_SIZE);
|
||||||
|
|
||||||
LzmaResult = LzmaDecode(
|
LzmaResult = LzmaDecode(
|
||||||
(Byte*)Destination,
|
(Byte*)Destination,
|
||||||
&DecodedBufSize,
|
&DecodedBufSize,
|
||||||
(Byte*)((UINT8*)Source + LZMA_HEADER_SIZE),
|
(Byte*)((UINT8*)Source + LZMA_HEADER_SIZE),
|
||||||
&EncodedDataSize,
|
&EncodedDataSize,
|
||||||
(CONST Byte*) Source,
|
(CONST Byte*) Source,
|
||||||
LZMA_PROPS_SIZE,
|
LZMA_PROPS_SIZE,
|
||||||
LZMA_FINISH_END,
|
LZMA_FINISH_END,
|
||||||
&Status,
|
&Status,
|
||||||
&SzAllocForLzma
|
&SzAllocForLzma
|
||||||
);
|
);
|
||||||
|
|
||||||
if (LzmaResult == SZ_OK) {
|
if (LzmaResult == SZ_OK) {
|
||||||
return ERR_SUCCESS;
|
return ERR_SUCCESS;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return ERR_INVALID_PARAMETER;
|
return ERR_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __LZMADECOMPRESS_H__
|
#ifndef LZMADECOMPRESS_H
|
||||||
#define __LZMADECOMPRESS_H__
|
#define LZMADECOMPRESS_H
|
||||||
|
|
||||||
#include "../basetypes.h"
|
#include "../basetypes.h"
|
||||||
#include "SDK/C/LzmaDec.h"
|
#include "SDK/C/LzmaDec.h"
|
||||||
@ -23,13 +23,6 @@ extern "C" {
|
|||||||
|
|
||||||
#define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + 8)
|
#define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + 8)
|
||||||
|
|
||||||
UINT64
|
|
||||||
EFIAPI
|
|
||||||
LShiftU64(
|
|
||||||
UINT64 Operand,
|
|
||||||
UINT32 Count
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Given a Lzma compressed source buffer, this function retrieves the size of
|
Given a Lzma compressed source buffer, this function retrieves the size of
|
||||||
the uncompressed buffer and the size of the scratch buffer required
|
the uncompressed buffer and the size of the scratch buffer required
|
||||||
@ -57,12 +50,12 @@ extern "C" {
|
|||||||
buffer was returned ScratchSize.
|
buffer was returned ScratchSize.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
INT32
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
LzmaGetInfo(
|
LzmaGetInfo (
|
||||||
const VOID *Source,
|
CONST VOID *Source,
|
||||||
UINTN SourceSize,
|
UINT32 SourceSize,
|
||||||
UINTN *DestinationSize
|
UINT32 *DestinationSize
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -84,15 +77,16 @@ extern "C" {
|
|||||||
The source buffer specified by Source is corrupted
|
The source buffer specified by Source is corrupted
|
||||||
(not a valid compressed format).
|
(not a valid compressed format).
|
||||||
*/
|
*/
|
||||||
INT32
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
LzmaDecompress(
|
LzmaDecompress (
|
||||||
const VOID *Source,
|
CONST VOID *Source,
|
||||||
UINTN SourceSize,
|
UINT32 SourceSize,
|
||||||
VOID *Destination
|
VOID *Destination
|
||||||
);
|
);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
#endif // LZMADECOMPRESS_H
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -20,8 +20,8 @@ Header file for compression routine.
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _EFITIANOCOMPRESS_H_
|
#ifndef EFITIANOCOMPRESS_H
|
||||||
#define _EFITIANOCOMPRESS_H_
|
#define EFITIANOCOMPRESS_H
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -32,84 +32,87 @@ Header file for compression routine.
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*++
|
/*++
|
||||||
|
|
||||||
Routine Description:
|
Routine Description:
|
||||||
|
|
||||||
Tiano compression routine.
|
Tiano compression routine.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
||||||
SrcBuffer - The buffer storing the source data
|
SrcBuffer - The buffer storing the source data
|
||||||
SrcSize - The size of source data
|
SrcSize - The size of source data
|
||||||
DstBuffer - The buffer to store the compressed data
|
DstBuffer - The buffer to store the compressed data
|
||||||
DstSize - On input, the size of DstBuffer; On output,
|
DstSize - On input, the size of DstBuffer; On output,
|
||||||
the size of the actual compressed data.
|
the size of the actual compressed data.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
EFI_BUFFER_TOO_SMALL - The DstBuffer is too small. this case,
|
EFI_BUFFER_TOO_SMALL - The DstBuffer is too small. this case,
|
||||||
DstSize contains the size needed.
|
DstSize contains the size needed.
|
||||||
EFI_SUCCESS - Compression is successful.
|
EFI_SUCCESS - Compression is successful.
|
||||||
EFI_OUT_OF_RESOURCES - No resource to complete function.
|
EFI_OUT_OF_RESOURCES - No resource to complete function.
|
||||||
EFI_INVALID_PARAMETER - Parameter supplied is wrong.
|
EFI_INVALID_PARAMETER - Parameter supplied is wrong.
|
||||||
|
|
||||||
--*/
|
--*/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
TianoCompress(
|
TianoCompress(
|
||||||
IN CONST VOID *SrcBuffer,
|
CONST VOID *SrcBuffer,
|
||||||
IN UINT32 SrcSize,
|
UINT32 SrcSize,
|
||||||
IN VOID *DstBuffer,
|
VOID *DstBuffer,
|
||||||
IN OUT UINT32 *DstSize
|
UINT32 *DstSize
|
||||||
);
|
)
|
||||||
|
;
|
||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
TianoCompressLegacy(
|
TianoCompressLegacy(
|
||||||
CONST VOID *SrcBuffer,
|
CONST VOID *SrcBuffer,
|
||||||
UINT32 SrcSize,
|
UINT32 SrcSize,
|
||||||
VOID *DstBuffer,
|
VOID *DstBuffer,
|
||||||
UINT32 *DstSize
|
UINT32 *DstSize
|
||||||
);
|
)
|
||||||
/*++
|
;
|
||||||
|
/*++
|
||||||
|
|
||||||
Routine Description:
|
Routine Description:
|
||||||
|
|
||||||
EFI 1.1 compression routine.
|
EFI 1.1 compression routine.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
||||||
SrcBuffer - The buffer storing the source data
|
SrcBuffer - The buffer storing the source data
|
||||||
SrcSize - The size of source data
|
SrcSize - The size of source data
|
||||||
DstBuffer - The buffer to store the compressed data
|
DstBuffer - The buffer to store the compressed data
|
||||||
DstSize - On input, the size of DstBuffer; On output,
|
DstSize - On input, the size of DstBuffer; On output,
|
||||||
the size of the actual compressed data.
|
the size of the actual compressed data.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
EFI_BUFFER_TOO_SMALL - The DstBuffer is too small. this case,
|
EFI_BUFFER_TOO_SMALL - The DstBuffer is too small. this case,
|
||||||
DstSize contains the size needed.
|
DstSize contains the size needed.
|
||||||
EFI_SUCCESS - Compression is successful.
|
EFI_SUCCESS - Compression is successful.
|
||||||
EFI_OUT_OF_RESOURCES - No resource to complete function.
|
EFI_OUT_OF_RESOURCES - No resource to complete function.
|
||||||
EFI_INVALID_PARAMETER - Parameter supplied is wrong.
|
EFI_INVALID_PARAMETER - Parameter supplied is wrong.
|
||||||
|
|
||||||
--*/
|
--*/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EfiCompress(
|
EfiCompress(
|
||||||
IN CONST VOID *SrcBuffer,
|
CONST VOID *SrcBuffer,
|
||||||
IN UINT32 SrcSize,
|
UINT32 SrcSize,
|
||||||
IN VOID *DstBuffer,
|
VOID *DstBuffer,
|
||||||
IN OUT UINT32 *DstSize
|
UINT32 *DstSize
|
||||||
);
|
)
|
||||||
|
;
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EfiCompressLegacy(
|
EfiCompressLegacy(
|
||||||
CONST VOID *SrcBuffer,
|
CONST VOID *SrcBuffer,
|
||||||
UINT32 SrcSize,
|
UINT32 SrcSize,
|
||||||
VOID *DstBuffer,
|
VOID *DstBuffer,
|
||||||
UINT32 *DstSize
|
UINT32 *DstSize
|
||||||
);
|
)
|
||||||
|
;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif // EFITIANOCOMPRESS_H
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -21,8 +21,8 @@ Providing both EFI and Tiano decompress algorithms.
|
|||||||
|
|
||||||
--*/
|
--*/
|
||||||
|
|
||||||
#ifndef _EFITIANODECOMPRESS_H_
|
#ifndef EFITIANODECOMPRESS_H
|
||||||
#define _EFITIANODECOMPRESS_H_
|
#define EFITIANODECOMPRESS_H
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@ -32,109 +32,107 @@ Providing both EFI and Tiano decompress algorithms.
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct EFI_TIANO_HEADER_ {
|
||||||
UINT32 CompSize;
|
UINT32 CompSize;
|
||||||
UINT32 OrigSize;
|
UINT32 OrigSize;
|
||||||
} EFI_TIANO_HEADER;
|
} EFI_TIANO_HEADER;
|
||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EfiTianoGetInfo(
|
EFIAPI
|
||||||
IN const VOID *Source,
|
EfiTianoGetInfo(
|
||||||
IN UINT32 SrcSize,
|
const VOID *Source,
|
||||||
OUT UINT32 *DstSize,
|
UINT32 SrcSize,
|
||||||
OUT UINT32 *ScratchSize
|
UINT32 *DstSize,
|
||||||
)
|
UINT32 *ScratchSize
|
||||||
/*++
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
Routine Description:
|
Routine Description:
|
||||||
|
|
||||||
The implementation is same as that of EFI_DECOMPRESS_PROTOCOL.GetInfo().
|
The implementation is same as that of EFI_DECOMPRESS_PROTOCOL.GetInfo().
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
||||||
This - The protocol instance pointer
|
Source - The source buffer containing the compressed data.
|
||||||
Source - The source buffer containing the compressed data.
|
SrcSize - The size of source buffer
|
||||||
SrcSize - The size of source buffer
|
DstSize - The size of destination buffer.
|
||||||
DstSize - The size of destination buffer.
|
ScratchSize - The size of scratch buffer.
|
||||||
ScratchSize - The size of scratch buffer.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successfully retrieved.
|
EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successfully retrieved.
|
||||||
EFI_INVALID_PARAMETER - The source data is corrupted
|
EFI_INVALID_PARAMETER - The source data is corrupted
|
||||||
|
|
||||||
--*/
|
--*/
|
||||||
;
|
;
|
||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
EfiDecompress(
|
EfiDecompress(
|
||||||
IN const VOID *Source,
|
const VOID *Source,
|
||||||
IN UINT32 SrcSize,
|
UINT32 SrcSize,
|
||||||
IN OUT VOID *Destination,
|
VOID *Destination,
|
||||||
IN UINT32 DstSize,
|
UINT32 DstSize,
|
||||||
IN OUT VOID *Scratch,
|
VOID *Scratch,
|
||||||
IN UINT32 ScratchSize
|
UINT32 ScratchSize
|
||||||
)
|
);
|
||||||
/*++
|
/*++
|
||||||
|
|
||||||
Routine Description:
|
Routine Description:
|
||||||
|
|
||||||
The implementation is same as that of EFI_DECOMPRESS_PROTOCOL.Decompress().
|
The implementation is same as that of EFI_DECOMPRESS_PROTOCOL.Decompress().
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
||||||
This - The protocol instance pointer
|
Source - The source buffer containing the compressed data.
|
||||||
Source - The source buffer containing the compressed data.
|
SrcSize - The size of source buffer
|
||||||
SrcSize - The size of source buffer
|
Destination - The destination buffer to store the decompressed data
|
||||||
Destination - The destination buffer to store the decompressed data
|
DstSize - The size of destination buffer.
|
||||||
DstSize - The size of destination buffer.
|
Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
|
||||||
Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
|
ScratchSize - The size of scratch buffer.
|
||||||
ScratchSize - The size of scratch buffer.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
EFI_SUCCESS - Decompression is successful
|
EFI_SUCCESS - Decompression is successful
|
||||||
EFI_INVALID_PARAMETER - The source data is corrupted
|
EFI_INVALID_PARAMETER - The source data is corrupted
|
||||||
|
|
||||||
--*/
|
--*/
|
||||||
;
|
;
|
||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
TianoDecompress(
|
TianoDecompress(
|
||||||
IN const VOID *Source,
|
const VOID *Source,
|
||||||
IN UINT32 SrcSize,
|
UINT32 SrcSize,
|
||||||
IN OUT VOID *Destination,
|
VOID *Destination,
|
||||||
IN UINT32 DstSize,
|
UINT32 DstSize,
|
||||||
IN OUT VOID *Scratch,
|
VOID *Scratch,
|
||||||
IN UINT32 ScratchSize
|
UINT32 ScratchSize
|
||||||
)
|
)
|
||||||
/*++
|
/*++
|
||||||
|
|
||||||
Routine Description:
|
Routine Description:
|
||||||
|
|
||||||
The implementation is same as that of EFI_TIANO_DECOMPRESS_PROTOCOL.Decompress().
|
The implementation is same as that of EFI_TIANO_DECOMPRESS_PROTOCOL.Decompress().
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
||||||
This - The protocol instance pointer
|
Source - The source buffer containing the compressed data.
|
||||||
Source - The source buffer containing the compressed data.
|
SrcSize - The size of source buffer
|
||||||
SrcSize - The size of source buffer
|
Destination - The destination buffer to store the decompressed data
|
||||||
Destination - The destination buffer to store the decompressed data
|
DstSize - The size of destination buffer.
|
||||||
DstSize - The size of destination buffer.
|
Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
|
||||||
Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
|
ScratchSize - The size of scratch buffer.
|
||||||
ScratchSize - The size of scratch buffer.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
EFI_SUCCESS - Decompression is successful
|
EFI_SUCCESS - Decompression is successful
|
||||||
EFI_INVALID_PARAMETER - The source data is corrupted
|
EFI_INVALID_PARAMETER - The source data is corrupted
|
||||||
|
|
||||||
--*/
|
--*/
|
||||||
;
|
;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif // EFITIANODECOMPRESS_H
|
||||||
|
@ -16,6 +16,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
typedef uint8_t BOOLEAN;
|
typedef uint8_t BOOLEAN;
|
||||||
typedef int8_t INT8;
|
typedef int8_t INT8;
|
||||||
@ -28,7 +29,7 @@ typedef int64_t INT64;
|
|||||||
typedef uint64_t UINT64;
|
typedef uint64_t UINT64;
|
||||||
typedef char CHAR8;
|
typedef char CHAR8;
|
||||||
typedef uint16_t CHAR16;
|
typedef uint16_t CHAR16;
|
||||||
typedef unsigned int UINTN;
|
typedef size_t UINTN;
|
||||||
|
|
||||||
#define CONST const
|
#define CONST const
|
||||||
#define VOID void
|
#define VOID void
|
||||||
|
@ -2741,7 +2741,13 @@ UINT8 FfsEngine::decompress(const QByteArray & compressedData, const UINT8 compr
|
|||||||
else if (algorithm)
|
else if (algorithm)
|
||||||
*algorithm = COMPRESSION_ALGORITHM_TIANO;
|
*algorithm = COMPRESSION_ALGORITHM_TIANO;
|
||||||
|
|
||||||
decompressedData = QByteArray((const char*)decompressed, decompressedSize);
|
if (decompressedSize > INT32_MAX) {
|
||||||
|
delete[] decompressed;
|
||||||
|
delete[] scratch;
|
||||||
|
return ERR_STANDARD_DECOMPRESSION_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
decompressedData = QByteArray((const char*)decompressed, (int)decompressedSize);
|
||||||
|
|
||||||
delete[] decompressed;
|
delete[] decompressed;
|
||||||
delete[] scratch;
|
delete[] scratch;
|
||||||
@ -2778,7 +2784,8 @@ UINT8 FfsEngine::decompress(const QByteArray & compressedData, const UINT8 compr
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Decompress section data again
|
// Decompress section data again
|
||||||
if (ERR_SUCCESS != LzmaDecompress(data, dataSize, decompressed)) {
|
if (ERR_SUCCESS != LzmaDecompress(data, dataSize, decompressed)
|
||||||
|
|| decompressedSize > INT32_MAX) {
|
||||||
if (algorithm)
|
if (algorithm)
|
||||||
*algorithm = COMPRESSION_ALGORITHM_UNKNOWN;
|
*algorithm = COMPRESSION_ALGORITHM_UNKNOWN;
|
||||||
delete[] decompressed;
|
delete[] decompressed;
|
||||||
@ -2787,13 +2794,17 @@ UINT8 FfsEngine::decompress(const QByteArray & compressedData, const UINT8 compr
|
|||||||
else {
|
else {
|
||||||
if (algorithm)
|
if (algorithm)
|
||||||
*algorithm = COMPRESSION_ALGORITHM_IMLZMA;
|
*algorithm = COMPRESSION_ALGORITHM_IMLZMA;
|
||||||
decompressedData = QByteArray((const char*)decompressed, decompressedSize);
|
decompressedData = QByteArray((const char*)decompressed, (int)decompressedSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (decompressedSize > INT32_MAX) {
|
||||||
|
delete[] decompressed;
|
||||||
|
return ERR_CUSTOMIZED_DECOMPRESSION_FAILED;
|
||||||
|
}
|
||||||
if (algorithm)
|
if (algorithm)
|
||||||
*algorithm = COMPRESSION_ALGORITHM_LZMA;
|
*algorithm = COMPRESSION_ALGORITHM_LZMA;
|
||||||
decompressedData = QByteArray((const char*)decompressed, decompressedSize);
|
decompressedData = QByteArray((const char*)decompressed, (int)decompressedSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] decompressed;
|
delete[] decompressed;
|
||||||
|
Loading…
Reference in New Issue
Block a user