mirror of https://github.com/acidanthera/audk.git
MdeModulePkg: Add two library instances
Copy below two library instances from IntelFrameworkModulePkg to MdeModulePkg. Then, Platform dsc can refer to them from MdeModulePkg, and remove the dependency of IntelFrameworkModulePkg. The ones in IntelFrameworkModulePkg are still kept for compatibility. 1. PeiDxeDebugLibReportStatusCode 2. LzmaCustomDecompressLib Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Jordan Justen <jordan.l.justen@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17112 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
a7adc5c566
commit
11ff2c714b
|
@ -0,0 +1,218 @@
|
|||
/** @file
|
||||
LZMA Decompress GUIDed Section Extraction Library, which produces LZMA custom
|
||||
decompression algorithm with the converter for the different arch code.
|
||||
It wraps Lzma decompress interfaces to GUIDed Section Extraction interfaces
|
||||
and registers them into GUIDed handler table.
|
||||
|
||||
Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "LzmaDecompressLibInternal.h"
|
||||
#include "Sdk/C/Bra.h"
|
||||
|
||||
/**
|
||||
Examines a GUIDed section and returns the size of the decoded buffer and the
|
||||
size of an scratch buffer required to actually decode the data in a GUIDed section.
|
||||
|
||||
Examines a GUIDed section specified by InputSection.
|
||||
If GUID for InputSection does not match the GUID that this handler supports,
|
||||
then RETURN_UNSUPPORTED is returned.
|
||||
If the required information can not be retrieved from InputSection,
|
||||
then RETURN_INVALID_PARAMETER is returned.
|
||||
If the GUID of InputSection does match the GUID that this handler supports,
|
||||
then the size required to hold the decoded buffer is returned in OututBufferSize,
|
||||
the size of an optional scratch buffer is returned in ScratchSize, and the Attributes field
|
||||
from EFI_GUID_DEFINED_SECTION header of InputSection is returned in SectionAttribute.
|
||||
|
||||
If InputSection is NULL, then ASSERT().
|
||||
If OutputBufferSize is NULL, then ASSERT().
|
||||
If ScratchBufferSize is NULL, then ASSERT().
|
||||
If SectionAttribute is NULL, then ASSERT().
|
||||
|
||||
|
||||
@param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.
|
||||
@param[out] OutputBufferSize A pointer to the size, in bytes, of an output buffer required
|
||||
if the buffer specified by InputSection were decoded.
|
||||
@param[out] ScratchBufferSize A pointer to the size, in bytes, required as scratch space
|
||||
if the buffer specified by InputSection were decoded.
|
||||
@param[out] SectionAttribute A pointer to the attributes of the GUIDed section. See the Attributes
|
||||
field of EFI_GUID_DEFINED_SECTION in the PI Specification.
|
||||
|
||||
@retval RETURN_SUCCESS The information about InputSection was returned.
|
||||
@retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.
|
||||
@retval RETURN_INVALID_PARAMETER The information can not be retrieved from the section specified by InputSection.
|
||||
|
||||
**/
|
||||
RETURN_STATUS
|
||||
EFIAPI
|
||||
LzmaArchGuidedSectionGetInfo (
|
||||
IN CONST VOID *InputSection,
|
||||
OUT UINT32 *OutputBufferSize,
|
||||
OUT UINT32 *ScratchBufferSize,
|
||||
OUT UINT16 *SectionAttribute
|
||||
)
|
||||
{
|
||||
ASSERT (InputSection != NULL);
|
||||
ASSERT (OutputBufferSize != NULL);
|
||||
ASSERT (ScratchBufferSize != NULL);
|
||||
ASSERT (SectionAttribute != NULL);
|
||||
|
||||
if (IS_SECTION2 (InputSection)) {
|
||||
if (!CompareGuid (
|
||||
&gLzmaF86CustomDecompressGuid,
|
||||
&(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {
|
||||
return RETURN_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
*SectionAttribute = ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->Attributes;
|
||||
|
||||
return LzmaUefiDecompressGetInfo (
|
||||
(UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,
|
||||
SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,
|
||||
OutputBufferSize,
|
||||
ScratchBufferSize
|
||||
);
|
||||
} else {
|
||||
if (!CompareGuid (
|
||||
&gLzmaF86CustomDecompressGuid,
|
||||
&(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {
|
||||
return RETURN_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
*SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;
|
||||
|
||||
return LzmaUefiDecompressGetInfo (
|
||||
(UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
|
||||
SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
|
||||
OutputBufferSize,
|
||||
ScratchBufferSize
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Decompress a LZAM compressed GUIDed section into a caller allocated output buffer.
|
||||
|
||||
Decodes the GUIDed section specified by InputSection.
|
||||
If GUID for InputSection does not match the GUID that this handler supports, then RETURN_UNSUPPORTED is returned.
|
||||
If the data in InputSection can not be decoded, then RETURN_INVALID_PARAMETER is returned.
|
||||
If the GUID of InputSection does match the GUID that this handler supports, then InputSection
|
||||
is decoded into the buffer specified by OutputBuffer and the authentication status of this
|
||||
decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the
|
||||
data in InputSection, then OutputBuffer is set to point at the data in InputSection. Otherwise,
|
||||
the decoded data will be placed in caller allocated buffer specified by OutputBuffer.
|
||||
|
||||
If InputSection is NULL, then ASSERT().
|
||||
If OutputBuffer is NULL, then ASSERT().
|
||||
If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().
|
||||
If AuthenticationStatus is NULL, then ASSERT().
|
||||
|
||||
|
||||
@param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.
|
||||
@param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation.
|
||||
@param[out] ScratchBuffer A caller allocated buffer that may be required by this function
|
||||
as a scratch buffer to perform the decode operation.
|
||||
@param[out] AuthenticationStatus
|
||||
A pointer to the authentication status of the decoded output buffer.
|
||||
See the definition of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
|
||||
section of the PI Specification. EFI_AUTH_STATUS_PLATFORM_OVERRIDE must
|
||||
never be set by this handler.
|
||||
|
||||
@retval RETURN_SUCCESS The buffer specified by InputSection was decoded.
|
||||
@retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.
|
||||
@retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.
|
||||
|
||||
**/
|
||||
RETURN_STATUS
|
||||
EFIAPI
|
||||
LzmaArchGuidedSectionExtraction (
|
||||
IN CONST VOID *InputSection,
|
||||
OUT VOID **OutputBuffer,
|
||||
OUT VOID *ScratchBuffer, OPTIONAL
|
||||
OUT UINT32 *AuthenticationStatus
|
||||
)
|
||||
{
|
||||
EFI_GUID *InputGuid;
|
||||
VOID *Source;
|
||||
UINTN SourceSize;
|
||||
EFI_STATUS Status;
|
||||
UINT32 X86State;
|
||||
UINT32 OutputBufferSize;
|
||||
UINT32 ScratchBufferSize;
|
||||
|
||||
ASSERT (OutputBuffer != NULL);
|
||||
ASSERT (InputSection != NULL);
|
||||
|
||||
if (IS_SECTION2 (InputSection)) {
|
||||
InputGuid = &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid);
|
||||
Source = (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset;
|
||||
SourceSize = SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset;
|
||||
} else {
|
||||
InputGuid = &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid);
|
||||
Source = (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset;
|
||||
SourceSize = SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset;
|
||||
}
|
||||
|
||||
if (!CompareGuid (&gLzmaF86CustomDecompressGuid, InputGuid)) {
|
||||
return RETURN_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
//
|
||||
// Authentication is set to Zero, which may be ignored.
|
||||
//
|
||||
*AuthenticationStatus = 0;
|
||||
|
||||
Status = LzmaUefiDecompress (
|
||||
Source,
|
||||
SourceSize,
|
||||
*OutputBuffer,
|
||||
ScratchBuffer
|
||||
);
|
||||
|
||||
//
|
||||
// After decompress, the data need to be converted to the raw data.
|
||||
//
|
||||
if (!EFI_ERROR (Status)) {
|
||||
Status = LzmaUefiDecompressGetInfo (
|
||||
Source,
|
||||
(UINT32) SourceSize,
|
||||
&OutputBufferSize,
|
||||
&ScratchBufferSize
|
||||
);
|
||||
|
||||
if (!EFI_ERROR (Status)) {
|
||||
x86_Convert_Init(X86State);
|
||||
x86_Convert(*OutputBuffer, OutputBufferSize, 0, &X86State, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Register LzmaArchDecompress and LzmaArchDecompressGetInfo handlers with LzmaF86CustomDecompressGuid.
|
||||
|
||||
@retval RETURN_SUCCESS Register successfully.
|
||||
@retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
LzmaArchDecompressLibConstructor (
|
||||
)
|
||||
{
|
||||
return ExtractGuidedSectionRegisterHandlers (
|
||||
&gLzmaF86CustomDecompressGuid,
|
||||
LzmaArchGuidedSectionGetInfo,
|
||||
LzmaArchGuidedSectionExtraction
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,201 @@
|
|||
/** @file
|
||||
LZMA Decompress GUIDed Section Extraction Library.
|
||||
It wraps Lzma decompress interfaces to GUIDed Section Extraction interfaces
|
||||
and registers them into GUIDed handler table.
|
||||
|
||||
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "LzmaDecompressLibInternal.h"
|
||||
|
||||
/**
|
||||
Examines a GUIDed section and returns the size of the decoded buffer and the
|
||||
size of an scratch buffer required to actually decode the data in a GUIDed section.
|
||||
|
||||
Examines a GUIDed section specified by InputSection.
|
||||
If GUID for InputSection does not match the GUID that this handler supports,
|
||||
then RETURN_UNSUPPORTED is returned.
|
||||
If the required information can not be retrieved from InputSection,
|
||||
then RETURN_INVALID_PARAMETER is returned.
|
||||
If the GUID of InputSection does match the GUID that this handler supports,
|
||||
then the size required to hold the decoded buffer is returned in OututBufferSize,
|
||||
the size of an optional scratch buffer is returned in ScratchSize, and the Attributes field
|
||||
from EFI_GUID_DEFINED_SECTION header of InputSection is returned in SectionAttribute.
|
||||
|
||||
If InputSection is NULL, then ASSERT().
|
||||
If OutputBufferSize is NULL, then ASSERT().
|
||||
If ScratchBufferSize is NULL, then ASSERT().
|
||||
If SectionAttribute is NULL, then ASSERT().
|
||||
|
||||
|
||||
@param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.
|
||||
@param[out] OutputBufferSize A pointer to the size, in bytes, of an output buffer required
|
||||
if the buffer specified by InputSection were decoded.
|
||||
@param[out] ScratchBufferSize A pointer to the size, in bytes, required as scratch space
|
||||
if the buffer specified by InputSection were decoded.
|
||||
@param[out] SectionAttribute A pointer to the attributes of the GUIDed section. See the Attributes
|
||||
field of EFI_GUID_DEFINED_SECTION in the PI Specification.
|
||||
|
||||
@retval RETURN_SUCCESS The information about InputSection was returned.
|
||||
@retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.
|
||||
@retval RETURN_INVALID_PARAMETER The information can not be retrieved from the section specified by InputSection.
|
||||
|
||||
**/
|
||||
RETURN_STATUS
|
||||
EFIAPI
|
||||
LzmaGuidedSectionGetInfo (
|
||||
IN CONST VOID *InputSection,
|
||||
OUT UINT32 *OutputBufferSize,
|
||||
OUT UINT32 *ScratchBufferSize,
|
||||
OUT UINT16 *SectionAttribute
|
||||
)
|
||||
{
|
||||
ASSERT (InputSection != NULL);
|
||||
ASSERT (OutputBufferSize != NULL);
|
||||
ASSERT (ScratchBufferSize != NULL);
|
||||
ASSERT (SectionAttribute != NULL);
|
||||
|
||||
if (IS_SECTION2 (InputSection)) {
|
||||
if (!CompareGuid (
|
||||
&gLzmaCustomDecompressGuid,
|
||||
&(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {
|
||||
return RETURN_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
*SectionAttribute = ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->Attributes;
|
||||
|
||||
return LzmaUefiDecompressGetInfo (
|
||||
(UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,
|
||||
SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,
|
||||
OutputBufferSize,
|
||||
ScratchBufferSize
|
||||
);
|
||||
} else {
|
||||
if (!CompareGuid (
|
||||
&gLzmaCustomDecompressGuid,
|
||||
&(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {
|
||||
return RETURN_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
*SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;
|
||||
|
||||
return LzmaUefiDecompressGetInfo (
|
||||
(UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
|
||||
SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
|
||||
OutputBufferSize,
|
||||
ScratchBufferSize
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Decompress a LZAM compressed GUIDed section into a caller allocated output buffer.
|
||||
|
||||
Decodes the GUIDed section specified by InputSection.
|
||||
If GUID for InputSection does not match the GUID that this handler supports, then RETURN_UNSUPPORTED is returned.
|
||||
If the data in InputSection can not be decoded, then RETURN_INVALID_PARAMETER is returned.
|
||||
If the GUID of InputSection does match the GUID that this handler supports, then InputSection
|
||||
is decoded into the buffer specified by OutputBuffer and the authentication status of this
|
||||
decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the
|
||||
data in InputSection, then OutputBuffer is set to point at the data in InputSection. Otherwise,
|
||||
the decoded data will be placed in caller allocated buffer specified by OutputBuffer.
|
||||
|
||||
If InputSection is NULL, then ASSERT().
|
||||
If OutputBuffer is NULL, then ASSERT().
|
||||
If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().
|
||||
If AuthenticationStatus is NULL, then ASSERT().
|
||||
|
||||
|
||||
@param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.
|
||||
@param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation.
|
||||
@param[out] ScratchBuffer A caller allocated buffer that may be required by this function
|
||||
as a scratch buffer to perform the decode operation.
|
||||
@param[out] AuthenticationStatus
|
||||
A pointer to the authentication status of the decoded output buffer.
|
||||
See the definition of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
|
||||
section of the PI Specification. EFI_AUTH_STATUS_PLATFORM_OVERRIDE must
|
||||
never be set by this handler.
|
||||
|
||||
@retval RETURN_SUCCESS The buffer specified by InputSection was decoded.
|
||||
@retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.
|
||||
@retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.
|
||||
|
||||
**/
|
||||
RETURN_STATUS
|
||||
EFIAPI
|
||||
LzmaGuidedSectionExtraction (
|
||||
IN CONST VOID *InputSection,
|
||||
OUT VOID **OutputBuffer,
|
||||
OUT VOID *ScratchBuffer, OPTIONAL
|
||||
OUT UINT32 *AuthenticationStatus
|
||||
)
|
||||
{
|
||||
ASSERT (OutputBuffer != NULL);
|
||||
ASSERT (InputSection != NULL);
|
||||
|
||||
if (IS_SECTION2 (InputSection)) {
|
||||
if (!CompareGuid (
|
||||
&gLzmaCustomDecompressGuid,
|
||||
&(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {
|
||||
return RETURN_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
//
|
||||
// Authentication is set to Zero, which may be ignored.
|
||||
//
|
||||
*AuthenticationStatus = 0;
|
||||
|
||||
return LzmaUefiDecompress (
|
||||
(UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,
|
||||
SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,
|
||||
*OutputBuffer,
|
||||
ScratchBuffer
|
||||
);
|
||||
} else {
|
||||
if (!CompareGuid (
|
||||
&gLzmaCustomDecompressGuid,
|
||||
&(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {
|
||||
return RETURN_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
//
|
||||
// Authentication is set to Zero, which may be ignored.
|
||||
//
|
||||
*AuthenticationStatus = 0;
|
||||
|
||||
return LzmaUefiDecompress (
|
||||
(UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
|
||||
SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,
|
||||
*OutputBuffer,
|
||||
ScratchBuffer
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Register LzmaDecompress and LzmaDecompressGetInfo handlers with LzmaCustomerDecompressGuid.
|
||||
|
||||
@retval RETURN_SUCCESS Register successfully.
|
||||
@retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
LzmaDecompressLibConstructor (
|
||||
)
|
||||
{
|
||||
return ExtractGuidedSectionRegisterHandlers (
|
||||
&gLzmaCustomDecompressGuid,
|
||||
LzmaGuidedSectionGetInfo,
|
||||
LzmaGuidedSectionExtraction
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
LzmaCustomDecompressLib is based on the LZMA SDK 4.65.
|
||||
LZMA SDK 4.65 was placed in the public domain on
|
||||
2009-02-03. It was released on the
|
||||
http://www.7-zip.org/sdk.html website.
|
|
@ -0,0 +1,66 @@
|
|||
## @file
|
||||
# LzmaArchCustomDecompressLib produces LZMA custom decompression algorithm with the converter for the different arch code.
|
||||
#
|
||||
# It is based on the LZMA SDK 4.65.
|
||||
# LZMA SDK 4.65 was placed in the public domain on 2009-02-03.
|
||||
# It was released on the http://www.7-zip.org/sdk.html website.
|
||||
#
|
||||
# Copyright (c) 2012 - 2015, Intel Corporation. All rights reserved.<BR>
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
BASE_NAME = LzmaArchDecompressLib
|
||||
MODULE_UNI_FILE = LzmaArchDecompressLib.uni
|
||||
FILE_GUID = A853C1D2-E003-4cc4-9DD1-8824AD79FE48
|
||||
MODULE_TYPE = BASE
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = NULL
|
||||
CONSTRUCTOR = LzmaArchDecompressLibConstructor
|
||||
|
||||
#
|
||||
# The following information is for reference only and not required by the build tools.
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64
|
||||
#
|
||||
|
||||
[Sources]
|
||||
LzmaDecompress.c
|
||||
Sdk/C/Bra.h
|
||||
Sdk/C/LzFind.c
|
||||
Sdk/C/LzmaDec.c
|
||||
Sdk/C/7zVersion.h
|
||||
Sdk/C/CpuArch.h
|
||||
Sdk/C/LzFind.h
|
||||
Sdk/C/LzHash.h
|
||||
Sdk/C/LzmaDec.h
|
||||
Sdk/C/Types.h
|
||||
UefiLzma.h
|
||||
LzmaDecompressLibInternal.h
|
||||
|
||||
[Sources.Ia32, Sources.X64]
|
||||
Sdk/C/Bra86.c
|
||||
F86GuidedSectionExtraction.c
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
|
||||
[Guids.Ia32, Guids.X64]
|
||||
gLzmaF86CustomDecompressGuid ## PRODUCES ## GUID # specifies LZMA custom decompress algorithm with converter for x86 code.
|
||||
|
||||
[LibraryClasses]
|
||||
BaseLib
|
||||
DebugLib
|
||||
BaseMemoryLib
|
||||
ExtractGuidedSectionLib
|
||||
|
Binary file not shown.
|
@ -0,0 +1,62 @@
|
|||
## @file
|
||||
# LzmaCustomDecompressLib produces LZMA custom decompression algorithm.
|
||||
#
|
||||
# It is based on the LZMA SDK 4.65.
|
||||
# LZMA SDK 4.65 was placed in the public domain on 2009-02-03.
|
||||
# It was released on the http://www.7-zip.org/sdk.html website.
|
||||
#
|
||||
# Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
BASE_NAME = LzmaDecompressLib
|
||||
MODULE_UNI_FILE = LzmaDecompressLib.uni
|
||||
FILE_GUID = 35194660-7421-44ad-9636-e44885f092d1
|
||||
MODULE_TYPE = BASE
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = NULL
|
||||
CONSTRUCTOR = LzmaDecompressLibConstructor
|
||||
|
||||
#
|
||||
# The following information is for reference only and not required by the build tools.
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
|
||||
#
|
||||
|
||||
[Sources]
|
||||
LzmaDecompress.c
|
||||
Sdk/C/LzFind.c
|
||||
Sdk/C/LzmaDec.c
|
||||
Sdk/C/7zVersion.h
|
||||
Sdk/C/CpuArch.h
|
||||
Sdk/C/LzFind.h
|
||||
Sdk/C/LzHash.h
|
||||
Sdk/C/LzmaDec.h
|
||||
Sdk/C/Types.h
|
||||
GuidedSectionExtraction.c
|
||||
UefiLzma.h
|
||||
LzmaDecompressLibInternal.h
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
|
||||
[Guids]
|
||||
gLzmaCustomDecompressGuid ## PRODUCES ## UNDEFINED # specifies LZMA custom decompress algorithm.
|
||||
|
||||
[LibraryClasses]
|
||||
BaseLib
|
||||
DebugLib
|
||||
BaseMemoryLib
|
||||
ExtractGuidedSectionLib
|
||||
|
|
@ -0,0 +1,220 @@
|
|||
/** @file
|
||||
LZMA Decompress interfaces
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "LzmaDecompressLibInternal.h"
|
||||
#include "Sdk/C/Types.h"
|
||||
#include "Sdk/C/7zVersion.h"
|
||||
#include "Sdk/C/LzmaDec.h"
|
||||
|
||||
#define SCRATCH_BUFFER_REQUEST_SIZE SIZE_64KB
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ISzAlloc Functions;
|
||||
VOID *Buffer;
|
||||
UINTN BufferSize;
|
||||
} ISzAllocWithData;
|
||||
|
||||
/**
|
||||
Allocation routine used by LZMA decompression.
|
||||
|
||||
@param P Pointer to the ISzAlloc instance
|
||||
@param Size The size in bytes to be allocated
|
||||
|
||||
@return The allocated pointer address, or NULL on failure
|
||||
**/
|
||||
VOID *
|
||||
SzAlloc (
|
||||
VOID *P,
|
||||
size_t Size
|
||||
)
|
||||
{
|
||||
VOID *Addr;
|
||||
ISzAllocWithData *Private;
|
||||
|
||||
Private = (ISzAllocWithData*) P;
|
||||
|
||||
if (Private->BufferSize >= Size) {
|
||||
Addr = Private->Buffer;
|
||||
Private->Buffer = (VOID*) ((UINT8*)Addr + Size);
|
||||
Private->BufferSize -= Size;
|
||||
return Addr;
|
||||
} else {
|
||||
ASSERT (FALSE);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Free routine used by LZMA decompression.
|
||||
|
||||
@param P Pointer to the ISzAlloc instance
|
||||
@param Address The address to be freed
|
||||
**/
|
||||
VOID
|
||||
SzFree (
|
||||
VOID *P,
|
||||
VOID *Address
|
||||
)
|
||||
{
|
||||
//
|
||||
// We use the 'scratch buffer' for allocations, so there is no free
|
||||
// operation required. The scratch buffer will be freed by the caller
|
||||
// of the decompression code.
|
||||
//
|
||||
}
|
||||
|
||||
#define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + 8)
|
||||
|
||||
/**
|
||||
Get the size of the uncompressed buffer by parsing EncodeData header.
|
||||
|
||||
@param EncodedData Pointer to the compressed data.
|
||||
|
||||
@return The size of the uncompressed buffer.
|
||||
**/
|
||||
UINT64
|
||||
GetDecodedSizeOfBuf(
|
||||
UINT8 *EncodedData
|
||||
)
|
||||
{
|
||||
UINT64 DecodedSize;
|
||||
INTN Index;
|
||||
|
||||
/* Parse header */
|
||||
DecodedSize = 0;
|
||||
for (Index = LZMA_PROPS_SIZE + 7; Index >= LZMA_PROPS_SIZE; Index--)
|
||||
DecodedSize = LShiftU64(DecodedSize, 8) + EncodedData[Index];
|
||||
|
||||
return DecodedSize;
|
||||
}
|
||||
|
||||
//
|
||||
// LZMA functions and data as defined in local LzmaDecompressLibInternal.h
|
||||
//
|
||||
|
||||
/**
|
||||
Given a Lzma compressed source buffer, this function retrieves the size of
|
||||
the uncompressed buffer and the size of the scratch buffer required
|
||||
to decompress the compressed source buffer.
|
||||
|
||||
Retrieves the size of the uncompressed buffer and the temporary scratch buffer
|
||||
required to decompress the buffer specified by Source and SourceSize.
|
||||
The size of the uncompressed buffer is returned in DestinationSize,
|
||||
the size of the scratch buffer is returned in ScratchSize, and RETURN_SUCCESS is returned.
|
||||
This function does not have scratch buffer available to perform a thorough
|
||||
checking of the validity of the source data. It just retrieves the "Original Size"
|
||||
field from the LZMA_HEADER_SIZE beginning bytes of the source data and output it as DestinationSize.
|
||||
And ScratchSize is specific to the decompression implementation.
|
||||
|
||||
If SourceSize is less than LZMA_HEADER_SIZE, then ASSERT().
|
||||
|
||||
@param Source The source buffer containing the compressed data.
|
||||
@param SourceSize The size, in bytes, of the source buffer.
|
||||
@param DestinationSize A pointer to the size, in bytes, of the uncompressed buffer
|
||||
that will be generated when the compressed buffer specified
|
||||
by Source and SourceSize is decompressed.
|
||||
@param ScratchSize A pointer to the size, in bytes, of the scratch buffer that
|
||||
is required to decompress the compressed buffer specified
|
||||
by Source and SourceSize.
|
||||
|
||||
@retval RETURN_SUCCESS The size of the uncompressed data was returned
|
||||
in DestinationSize and the size of the scratch
|
||||
buffer was returned in ScratchSize.
|
||||
|
||||
**/
|
||||
RETURN_STATUS
|
||||
EFIAPI
|
||||
LzmaUefiDecompressGetInfo (
|
||||
IN CONST VOID *Source,
|
||||
IN UINT32 SourceSize,
|
||||
OUT UINT32 *DestinationSize,
|
||||
OUT UINT32 *ScratchSize
|
||||
)
|
||||
{
|
||||
UInt64 DecodedSize;
|
||||
|
||||
ASSERT(SourceSize >= LZMA_HEADER_SIZE);
|
||||
|
||||
DecodedSize = GetDecodedSizeOfBuf((UINT8*)Source);
|
||||
|
||||
*DestinationSize = (UINT32)DecodedSize;
|
||||
*ScratchSize = SCRATCH_BUFFER_REQUEST_SIZE;
|
||||
return RETURN_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
Decompresses a Lzma compressed source buffer.
|
||||
|
||||
Extracts decompressed data to its original form.
|
||||
If the compressed source data specified by Source is successfully decompressed
|
||||
into Destination, then RETURN_SUCCESS is returned. If the compressed source data
|
||||
specified by Source is not in a valid compressed data format,
|
||||
then RETURN_INVALID_PARAMETER is returned.
|
||||
|
||||
@param Source The source buffer containing the compressed data.
|
||||
@param SourceSize The size of source buffer.
|
||||
@param Destination The destination buffer to store the decompressed data
|
||||
@param Scratch A temporary scratch buffer that is used to perform the decompression.
|
||||
This is an optional parameter that may be NULL if the
|
||||
required scratch buffer size is 0.
|
||||
|
||||
@retval RETURN_SUCCESS Decompression completed successfully, and
|
||||
the uncompressed buffer is returned in Destination.
|
||||
@retval RETURN_INVALID_PARAMETER
|
||||
The source buffer specified by Source is corrupted
|
||||
(not in a valid compressed format).
|
||||
**/
|
||||
RETURN_STATUS
|
||||
EFIAPI
|
||||
LzmaUefiDecompress (
|
||||
IN CONST VOID *Source,
|
||||
IN UINTN SourceSize,
|
||||
IN OUT VOID *Destination,
|
||||
IN OUT VOID *Scratch
|
||||
)
|
||||
{
|
||||
SRes LzmaResult;
|
||||
ELzmaStatus Status;
|
||||
SizeT DecodedBufSize;
|
||||
SizeT EncodedDataSize;
|
||||
ISzAllocWithData AllocFuncs;
|
||||
|
||||
AllocFuncs.Functions.Alloc = SzAlloc;
|
||||
AllocFuncs.Functions.Free = SzFree;
|
||||
AllocFuncs.Buffer = Scratch;
|
||||
AllocFuncs.BufferSize = SCRATCH_BUFFER_REQUEST_SIZE;
|
||||
|
||||
DecodedBufSize = (SizeT)GetDecodedSizeOfBuf((UINT8*)Source);
|
||||
EncodedDataSize = (SizeT) (SourceSize - LZMA_HEADER_SIZE);
|
||||
|
||||
LzmaResult = LzmaDecode(
|
||||
Destination,
|
||||
&DecodedBufSize,
|
||||
(Byte*)((UINT8*)Source + LZMA_HEADER_SIZE),
|
||||
&EncodedDataSize,
|
||||
Source,
|
||||
LZMA_PROPS_SIZE,
|
||||
LZMA_FINISH_END,
|
||||
&Status,
|
||||
&(AllocFuncs.Functions)
|
||||
);
|
||||
|
||||
if (LzmaResult == SZ_OK) {
|
||||
return RETURN_SUCCESS;
|
||||
} else {
|
||||
return RETURN_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
|
@ -0,0 +1,96 @@
|
|||
/** @file
|
||||
LZMA Decompress Library internal header file declares Lzma decompress interfaces.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef __LZMADECOMPRESSLIB_INTERNAL_H__
|
||||
#define __LZMADECOMPRESSLIB_INTERNAL_H__
|
||||
|
||||
#include <PiPei.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/ExtractGuidedSectionLib.h>
|
||||
#include <Guid/LzmaDecompress.h>
|
||||
|
||||
/**
|
||||
Given a Lzma compressed source buffer, this function retrieves the size of
|
||||
the uncompressed buffer and the size of the scratch buffer required
|
||||
to decompress the compressed source buffer.
|
||||
|
||||
Retrieves the size of the uncompressed buffer and the temporary scratch buffer
|
||||
required to decompress the buffer specified by Source and SourceSize.
|
||||
The size of the uncompressed buffer is returned in DestinationSize,
|
||||
the size of the scratch buffer is returned in ScratchSize, and RETURN_SUCCESS is returned.
|
||||
This function does not have scratch buffer available to perform a thorough
|
||||
checking of the validity of the source data. It just retrieves the "Original Size"
|
||||
field from the LZMA_HEADER_SIZE beginning bytes of the source data and output it as DestinationSize.
|
||||
And ScratchSize is specific to the decompression implementation.
|
||||
|
||||
If SourceSize is less than LZMA_HEADER_SIZE, then ASSERT().
|
||||
|
||||
@param Source The source buffer containing the compressed data.
|
||||
@param SourceSize The size, in bytes, of the source buffer.
|
||||
@param DestinationSize A pointer to the size, in bytes, of the uncompressed buffer
|
||||
that will be generated when the compressed buffer specified
|
||||
by Source and SourceSize is decompressed.
|
||||
@param ScratchSize A pointer to the size, in bytes, of the scratch buffer that
|
||||
is required to decompress the compressed buffer specified
|
||||
by Source and SourceSize.
|
||||
|
||||
@retval RETURN_SUCCESS The size of the uncompressed data was returned
|
||||
in DestinationSize and the size of the scratch
|
||||
buffer was returned in ScratchSize.
|
||||
|
||||
**/
|
||||
RETURN_STATUS
|
||||
EFIAPI
|
||||
LzmaUefiDecompressGetInfo (
|
||||
IN CONST VOID *Source,
|
||||
IN UINT32 SourceSize,
|
||||
OUT UINT32 *DestinationSize,
|
||||
OUT UINT32 *ScratchSize
|
||||
);
|
||||
|
||||
/**
|
||||
Decompresses a Lzma compressed source buffer.
|
||||
|
||||
Extracts decompressed data to its original form.
|
||||
If the compressed source data specified by Source is successfully decompressed
|
||||
into Destination, then RETURN_SUCCESS is returned. If the compressed source data
|
||||
specified by Source is not in a valid compressed data format,
|
||||
then RETURN_INVALID_PARAMETER is returned.
|
||||
|
||||
@param Source The source buffer containing the compressed data.
|
||||
@param SourceSize The size of source buffer.
|
||||
@param Destination The destination buffer to store the decompressed data
|
||||
@param Scratch A temporary scratch buffer that is used to perform the decompression.
|
||||
This is an optional parameter that may be NULL if the
|
||||
required scratch buffer size is 0.
|
||||
|
||||
@retval RETURN_SUCCESS Decompression completed successfully, and
|
||||
the uncompressed buffer is returned in Destination.
|
||||
@retval RETURN_INVALID_PARAMETER
|
||||
The source buffer specified by Source is corrupted
|
||||
(not in a valid compressed format).
|
||||
**/
|
||||
RETURN_STATUS
|
||||
EFIAPI
|
||||
LzmaUefiDecompress (
|
||||
IN CONST VOID *Source,
|
||||
IN UINTN SourceSize,
|
||||
IN OUT VOID *Destination,
|
||||
IN OUT VOID *Scratch
|
||||
);
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#define MY_VER_MAJOR 4
|
||||
#define MY_VER_MINOR 65
|
||||
#define MY_VER_BUILD 0
|
||||
#define MY_VERSION "4.65"
|
||||
#define MY_DATE "2009-02-03"
|
||||
#define MY_COPYRIGHT ": Igor Pavlov : Public domain"
|
||||
#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " : " MY_DATE
|
|
@ -0,0 +1,60 @@
|
|||
/* Bra.h -- Branch converters for executables
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __BRA_H
|
||||
#define __BRA_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
/*
|
||||
These functions convert relative addresses to absolute addresses
|
||||
in CALL instructions to increase the compression ratio.
|
||||
|
||||
In:
|
||||
data - data buffer
|
||||
size - size of data
|
||||
ip - current virtual Instruction Pinter (IP) value
|
||||
state - state variable for x86 converter
|
||||
encoding - 0 (for decoding), 1 (for encoding)
|
||||
|
||||
Out:
|
||||
state - state variable for x86 converter
|
||||
|
||||
Returns:
|
||||
The number of processed bytes. If you call these functions with multiple calls,
|
||||
you must start next call with first byte after block of processed bytes.
|
||||
|
||||
Type Endian Alignment LookAhead
|
||||
|
||||
x86 little 1 4
|
||||
ARMT little 2 2
|
||||
ARM little 4 0
|
||||
PPC big 4 0
|
||||
SPARC big 4 0
|
||||
IA64 little 16 0
|
||||
|
||||
size must be >= Alignment + LookAhead, if it's not last block.
|
||||
If (size < Alignment + LookAhead), converter returns 0.
|
||||
|
||||
Example:
|
||||
|
||||
UInt32 ip = 0;
|
||||
for ()
|
||||
{
|
||||
; size must be >= Alignment + LookAhead, if it's not last block
|
||||
SizeT processed = Convert(data, size, ip, 1);
|
||||
data += processed;
|
||||
size -= processed;
|
||||
ip += processed;
|
||||
}
|
||||
*/
|
||||
|
||||
#define x86_Convert_Init(state) { state = 0; }
|
||||
SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);
|
||||
SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
|
||||
SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
|
||||
SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
|
||||
SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
|
||||
SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,85 @@
|
|||
/* Bra86.c -- Converter for x86 code (BCJ)
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Bra.h"
|
||||
|
||||
#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)
|
||||
|
||||
const Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};
|
||||
const Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};
|
||||
|
||||
SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)
|
||||
{
|
||||
SizeT bufferPos = 0, prevPosT;
|
||||
UInt32 prevMask = *state & 0x7;
|
||||
if (size < 5)
|
||||
return 0;
|
||||
ip += 5;
|
||||
prevPosT = (SizeT)0 - 1;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
Byte *p = data + bufferPos;
|
||||
Byte *limit = data + size - 4;
|
||||
for (; p < limit; p++)
|
||||
if ((*p & 0xFE) == 0xE8)
|
||||
break;
|
||||
bufferPos = (SizeT)(p - data);
|
||||
if (p >= limit)
|
||||
break;
|
||||
prevPosT = bufferPos - prevPosT;
|
||||
if (prevPosT > 3)
|
||||
prevMask = 0;
|
||||
else
|
||||
{
|
||||
prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7;
|
||||
if (prevMask != 0)
|
||||
{
|
||||
Byte b = p[4 - kMaskToBitNumber[prevMask]];
|
||||
if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b))
|
||||
{
|
||||
prevPosT = bufferPos;
|
||||
prevMask = ((prevMask << 1) & 0x7) | 1;
|
||||
bufferPos++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
prevPosT = bufferPos;
|
||||
|
||||
if (Test86MSByte(p[4]))
|
||||
{
|
||||
UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);
|
||||
UInt32 dest;
|
||||
for (;;)
|
||||
{
|
||||
Byte b;
|
||||
int index;
|
||||
if (encoding)
|
||||
dest = (ip + (UInt32)bufferPos) + src;
|
||||
else
|
||||
dest = src - (ip + (UInt32)bufferPos);
|
||||
if (prevMask == 0)
|
||||
break;
|
||||
index = kMaskToBitNumber[prevMask] * 8;
|
||||
b = (Byte)(dest >> (24 - index));
|
||||
if (!Test86MSByte(b))
|
||||
break;
|
||||
src = dest ^ ((1 << (32 - index)) - 1);
|
||||
}
|
||||
p[4] = (Byte)(~(((dest >> 24) & 1) - 1));
|
||||
p[3] = (Byte)(dest >> 16);
|
||||
p[2] = (Byte)(dest >> 8);
|
||||
p[1] = (Byte)dest;
|
||||
bufferPos += 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
prevMask = ((prevMask << 1) & 0x7) | 1;
|
||||
bufferPos++;
|
||||
}
|
||||
}
|
||||
prevPosT = bufferPos - prevPosT;
|
||||
*state = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));
|
||||
return bufferPos;
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/* CpuArch.h
|
||||
2008-08-05
|
||||
Igor Pavlov
|
||||
Public domain */
|
||||
|
||||
#ifndef __CPUARCH_H
|
||||
#define __CPUARCH_H
|
||||
|
||||
/*
|
||||
LITTLE_ENDIAN_UNALIGN means:
|
||||
1) CPU is LITTLE_ENDIAN
|
||||
2) it's allowed to make unaligned memory accesses
|
||||
if LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know
|
||||
about these properties of platform.
|
||||
*/
|
||||
|
||||
#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)
|
||||
#define LITTLE_ENDIAN_UNALIGN
|
||||
#endif
|
||||
|
||||
#ifdef LITTLE_ENDIAN_UNALIGN
|
||||
|
||||
#define GetUi16(p) (*(const UInt16 *)(p))
|
||||
#define GetUi32(p) (*(const UInt32 *)(p))
|
||||
#define GetUi64(p) (*(const UInt64 *)(p))
|
||||
#define SetUi32(p, d) *(UInt32 *)(p) = (d);
|
||||
|
||||
#else
|
||||
|
||||
#define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8))
|
||||
|
||||
#define GetUi32(p) ( \
|
||||
((const Byte *)(p))[0] | \
|
||||
((UInt32)((const Byte *)(p))[1] << 8) | \
|
||||
((UInt32)((const Byte *)(p))[2] << 16) | \
|
||||
((UInt32)((const Byte *)(p))[3] << 24))
|
||||
|
||||
#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))
|
||||
|
||||
#define SetUi32(p, d) { UInt32 _x_ = (d); \
|
||||
((Byte *)(p))[0] = (Byte)_x_; \
|
||||
((Byte *)(p))[1] = (Byte)(_x_ >> 8); \
|
||||
((Byte *)(p))[2] = (Byte)(_x_ >> 16); \
|
||||
((Byte *)(p))[3] = (Byte)(_x_ >> 24); }
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(LITTLE_ENDIAN_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)
|
||||
|
||||
#pragma intrinsic(_byteswap_ulong)
|
||||
#pragma intrinsic(_byteswap_uint64)
|
||||
#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))
|
||||
#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))
|
||||
|
||||
#else
|
||||
|
||||
#define GetBe32(p) ( \
|
||||
((UInt32)((const Byte *)(p))[0] << 24) | \
|
||||
((UInt32)((const Byte *)(p))[1] << 16) | \
|
||||
((UInt32)((const Byte *)(p))[2] << 8) | \
|
||||
((const Byte *)(p))[3] )
|
||||
|
||||
#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))
|
||||
|
||||
#endif
|
||||
|
||||
#define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])
|
||||
|
||||
#endif
|
|
@ -0,0 +1,770 @@
|
|||
/** @file
|
||||
LzFind.c
|
||||
|
||||
Based on LZMA SDK 4.65:
|
||||
LzFind.c -- Match finder for LZ algorithms
|
||||
2008-10-04 : Igor Pavlov : Public domain
|
||||
|
||||
Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef EFIAPI
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#endif // !EFIAPI
|
||||
|
||||
#include "LzFind.h"
|
||||
#include "LzHash.h"
|
||||
|
||||
#define kEmptyHashValue 0
|
||||
#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)
|
||||
#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */
|
||||
#define kNormalizeMask (~(kNormalizeStepMin - 1))
|
||||
#define kMaxHistorySize ((UInt32)3 << 30)
|
||||
|
||||
#define kStartMaxLen 3
|
||||
|
||||
static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)
|
||||
{
|
||||
if (!p->directInput)
|
||||
{
|
||||
alloc->Free(alloc, p->bufferBase);
|
||||
p->bufferBase = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */
|
||||
|
||||
static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)
|
||||
{
|
||||
UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
|
||||
if (p->directInput)
|
||||
{
|
||||
p->blockSize = blockSize;
|
||||
return 1;
|
||||
}
|
||||
if (p->bufferBase == 0 || p->blockSize != blockSize)
|
||||
{
|
||||
LzInWindow_Free(p, alloc);
|
||||
p->blockSize = blockSize;
|
||||
p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);
|
||||
}
|
||||
return (p->bufferBase != 0);
|
||||
}
|
||||
|
||||
Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
|
||||
Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }
|
||||
|
||||
UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
|
||||
|
||||
void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
|
||||
{
|
||||
p->posLimit -= subValue;
|
||||
p->pos -= subValue;
|
||||
p->streamPos -= subValue;
|
||||
}
|
||||
|
||||
static void MatchFinder_ReadBlock(CMatchFinder *p)
|
||||
{
|
||||
if (p->streamEndWasReached || p->result != SZ_OK)
|
||||
return;
|
||||
for (;;)
|
||||
{
|
||||
Byte *dest = p->buffer + (p->streamPos - p->pos);
|
||||
size_t size = (p->bufferBase + p->blockSize - dest);
|
||||
if (size == 0)
|
||||
return;
|
||||
p->result = p->stream->Read(p->stream, dest, &size);
|
||||
if (p->result != SZ_OK)
|
||||
return;
|
||||
if (size == 0)
|
||||
{
|
||||
p->streamEndWasReached = 1;
|
||||
return;
|
||||
}
|
||||
p->streamPos += (UInt32)size;
|
||||
if (p->streamPos - p->pos > p->keepSizeAfter)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void MatchFinder_MoveBlock(CMatchFinder *p)
|
||||
{
|
||||
memmove(p->bufferBase,
|
||||
p->buffer - p->keepSizeBefore,
|
||||
(size_t)(p->streamPos - p->pos + p->keepSizeBefore));
|
||||
p->buffer = p->bufferBase + p->keepSizeBefore;
|
||||
}
|
||||
|
||||
int MatchFinder_NeedMove(CMatchFinder *p)
|
||||
{
|
||||
/* if (p->streamEndWasReached) return 0; */
|
||||
return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);
|
||||
}
|
||||
|
||||
void MatchFinder_ReadIfRequired(CMatchFinder *p)
|
||||
{
|
||||
if (p->streamEndWasReached)
|
||||
return;
|
||||
if (p->keepSizeAfter >= p->streamPos - p->pos)
|
||||
MatchFinder_ReadBlock(p);
|
||||
}
|
||||
|
||||
static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)
|
||||
{
|
||||
if (MatchFinder_NeedMove(p))
|
||||
MatchFinder_MoveBlock(p);
|
||||
MatchFinder_ReadBlock(p);
|
||||
}
|
||||
|
||||
static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
|
||||
{
|
||||
p->cutValue = 32;
|
||||
p->btMode = 1;
|
||||
p->numHashBytes = 4;
|
||||
/* p->skipModeBits = 0; */
|
||||
p->directInput = 0;
|
||||
p->bigHash = 0;
|
||||
}
|
||||
|
||||
#define kCrcPoly 0xEDB88320
|
||||
|
||||
void MatchFinder_Construct(CMatchFinder *p)
|
||||
{
|
||||
UInt32 i;
|
||||
p->bufferBase = 0;
|
||||
p->directInput = 0;
|
||||
p->hash = 0;
|
||||
MatchFinder_SetDefaultSettings(p);
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
UInt32 r = i;
|
||||
int j;
|
||||
for (j = 0; j < 8; j++)
|
||||
r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
|
||||
p->crc[i] = r;
|
||||
}
|
||||
}
|
||||
|
||||
static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)
|
||||
{
|
||||
alloc->Free(alloc, p->hash);
|
||||
p->hash = 0;
|
||||
}
|
||||
|
||||
void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)
|
||||
{
|
||||
MatchFinder_FreeThisClassMemory(p, alloc);
|
||||
LzInWindow_Free(p, alloc);
|
||||
}
|
||||
|
||||
static CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)
|
||||
{
|
||||
size_t sizeInBytes = (size_t)num * sizeof(CLzRef);
|
||||
if (sizeInBytes / sizeof(CLzRef) != num)
|
||||
return 0;
|
||||
return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);
|
||||
}
|
||||
|
||||
int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
|
||||
UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
|
||||
ISzAlloc *alloc)
|
||||
{
|
||||
UInt32 sizeReserv;
|
||||
if (historySize > kMaxHistorySize)
|
||||
{
|
||||
MatchFinder_Free(p, alloc);
|
||||
return 0;
|
||||
}
|
||||
sizeReserv = historySize >> 1;
|
||||
if (historySize > ((UInt32)2 << 30))
|
||||
sizeReserv = historySize >> 2;
|
||||
sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);
|
||||
|
||||
p->keepSizeBefore = historySize + keepAddBufferBefore + 1;
|
||||
p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;
|
||||
/* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */
|
||||
if (LzInWindow_Create(p, sizeReserv, alloc))
|
||||
{
|
||||
UInt32 newCyclicBufferSize = (historySize /* >> p->skipModeBits */) + 1;
|
||||
UInt32 hs;
|
||||
p->matchMaxLen = matchMaxLen;
|
||||
{
|
||||
p->fixedHashSize = 0;
|
||||
if (p->numHashBytes == 2)
|
||||
hs = (1 << 16) - 1;
|
||||
else
|
||||
{
|
||||
hs = historySize - 1;
|
||||
hs |= (hs >> 1);
|
||||
hs |= (hs >> 2);
|
||||
hs |= (hs >> 4);
|
||||
hs |= (hs >> 8);
|
||||
hs >>= 1;
|
||||
/* hs >>= p->skipModeBits; */
|
||||
hs |= 0xFFFF; /* don't change it! It's required for Deflate */
|
||||
if (hs > (1 << 24))
|
||||
{
|
||||
if (p->numHashBytes == 3)
|
||||
hs = (1 << 24) - 1;
|
||||
else
|
||||
hs >>= 1;
|
||||
}
|
||||
}
|
||||
p->hashMask = hs;
|
||||
hs++;
|
||||
if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;
|
||||
if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;
|
||||
if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;
|
||||
hs += p->fixedHashSize;
|
||||
}
|
||||
|
||||
{
|
||||
UInt32 prevSize = p->hashSizeSum + p->numSons;
|
||||
UInt32 newSize;
|
||||
p->historySize = historySize;
|
||||
p->hashSizeSum = hs;
|
||||
p->cyclicBufferSize = newCyclicBufferSize;
|
||||
p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize);
|
||||
newSize = p->hashSizeSum + p->numSons;
|
||||
if (p->hash != 0 && prevSize == newSize)
|
||||
return 1;
|
||||
MatchFinder_FreeThisClassMemory(p, alloc);
|
||||
p->hash = AllocRefs(newSize, alloc);
|
||||
if (p->hash != 0)
|
||||
{
|
||||
p->son = p->hash + p->hashSizeSum;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
MatchFinder_Free(p, alloc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void MatchFinder_SetLimits(CMatchFinder *p)
|
||||
{
|
||||
UInt32 limit = kMaxValForNormalize - p->pos;
|
||||
UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;
|
||||
if (limit2 < limit)
|
||||
limit = limit2;
|
||||
limit2 = p->streamPos - p->pos;
|
||||
if (limit2 <= p->keepSizeAfter)
|
||||
{
|
||||
if (limit2 > 0)
|
||||
limit2 = 1;
|
||||
}
|
||||
else
|
||||
limit2 -= p->keepSizeAfter;
|
||||
if (limit2 < limit)
|
||||
limit = limit2;
|
||||
{
|
||||
UInt32 lenLimit = p->streamPos - p->pos;
|
||||
if (lenLimit > p->matchMaxLen)
|
||||
lenLimit = p->matchMaxLen;
|
||||
p->lenLimit = lenLimit;
|
||||
}
|
||||
p->posLimit = p->pos + limit;
|
||||
}
|
||||
|
||||
void MatchFinder_Init(CMatchFinder *p)
|
||||
{
|
||||
UInt32 i;
|
||||
for (i = 0; i < p->hashSizeSum; i++)
|
||||
p->hash[i] = kEmptyHashValue;
|
||||
p->cyclicBufferPos = 0;
|
||||
p->buffer = p->bufferBase;
|
||||
p->pos = p->streamPos = p->cyclicBufferSize;
|
||||
p->result = SZ_OK;
|
||||
p->streamEndWasReached = 0;
|
||||
MatchFinder_ReadBlock(p);
|
||||
MatchFinder_SetLimits(p);
|
||||
}
|
||||
|
||||
static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)
|
||||
{
|
||||
return (p->pos - p->historySize - 1) & kNormalizeMask;
|
||||
}
|
||||
|
||||
void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
|
||||
{
|
||||
UInt32 i;
|
||||
for (i = 0; i < numItems; i++)
|
||||
{
|
||||
UInt32 value = items[i];
|
||||
if (value <= subValue)
|
||||
value = kEmptyHashValue;
|
||||
else
|
||||
value -= subValue;
|
||||
items[i] = value;
|
||||
}
|
||||
}
|
||||
|
||||
static void MatchFinder_Normalize(CMatchFinder *p)
|
||||
{
|
||||
UInt32 subValue = MatchFinder_GetSubValue(p);
|
||||
MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);
|
||||
MatchFinder_ReduceOffsets(p, subValue);
|
||||
}
|
||||
|
||||
static void MatchFinder_CheckLimits(CMatchFinder *p)
|
||||
{
|
||||
if (p->pos == kMaxValForNormalize)
|
||||
MatchFinder_Normalize(p);
|
||||
if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)
|
||||
MatchFinder_CheckAndMoveAndRead(p);
|
||||
if (p->cyclicBufferPos == p->cyclicBufferSize)
|
||||
p->cyclicBufferPos = 0;
|
||||
MatchFinder_SetLimits(p);
|
||||
}
|
||||
|
||||
static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
|
||||
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
|
||||
UInt32 *distances, UInt32 maxLen)
|
||||
{
|
||||
son[_cyclicBufferPos] = curMatch;
|
||||
for (;;)
|
||||
{
|
||||
UInt32 delta = pos - curMatch;
|
||||
if (cutValue-- == 0 || delta >= _cyclicBufferSize)
|
||||
return distances;
|
||||
{
|
||||
const Byte *pb = cur - delta;
|
||||
curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
|
||||
if (pb[maxLen] == cur[maxLen] && *pb == *cur)
|
||||
{
|
||||
UInt32 len = 0;
|
||||
while (++len != lenLimit)
|
||||
if (pb[len] != cur[len])
|
||||
break;
|
||||
if (maxLen < len)
|
||||
{
|
||||
*distances++ = maxLen = len;
|
||||
*distances++ = delta - 1;
|
||||
if (len == lenLimit)
|
||||
return distances;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
|
||||
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
|
||||
UInt32 *distances, UInt32 maxLen)
|
||||
{
|
||||
CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
|
||||
CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
|
||||
UInt32 len0 = 0, len1 = 0;
|
||||
for (;;)
|
||||
{
|
||||
UInt32 delta = pos - curMatch;
|
||||
if (cutValue-- == 0 || delta >= _cyclicBufferSize)
|
||||
{
|
||||
*ptr0 = *ptr1 = kEmptyHashValue;
|
||||
return distances;
|
||||
}
|
||||
{
|
||||
CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
|
||||
const Byte *pb = cur - delta;
|
||||
UInt32 len = (len0 < len1 ? len0 : len1);
|
||||
if (pb[len] == cur[len])
|
||||
{
|
||||
if (++len != lenLimit && pb[len] == cur[len])
|
||||
while (++len != lenLimit)
|
||||
if (pb[len] != cur[len])
|
||||
break;
|
||||
if (maxLen < len)
|
||||
{
|
||||
*distances++ = maxLen = len;
|
||||
*distances++ = delta - 1;
|
||||
if (len == lenLimit)
|
||||
{
|
||||
*ptr1 = pair[0];
|
||||
*ptr0 = pair[1];
|
||||
return distances;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pb[len] < cur[len])
|
||||
{
|
||||
*ptr1 = curMatch;
|
||||
ptr1 = pair + 1;
|
||||
curMatch = *ptr1;
|
||||
len1 = len;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ptr0 = curMatch;
|
||||
ptr0 = pair;
|
||||
curMatch = *ptr0;
|
||||
len0 = len;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
|
||||
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)
|
||||
{
|
||||
CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
|
||||
CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
|
||||
UInt32 len0 = 0, len1 = 0;
|
||||
for (;;)
|
||||
{
|
||||
UInt32 delta = pos - curMatch;
|
||||
if (cutValue-- == 0 || delta >= _cyclicBufferSize)
|
||||
{
|
||||
*ptr0 = *ptr1 = kEmptyHashValue;
|
||||
return;
|
||||
}
|
||||
{
|
||||
CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
|
||||
const Byte *pb = cur - delta;
|
||||
UInt32 len = (len0 < len1 ? len0 : len1);
|
||||
if (pb[len] == cur[len])
|
||||
{
|
||||
while (++len != lenLimit)
|
||||
if (pb[len] != cur[len])
|
||||
break;
|
||||
{
|
||||
if (len == lenLimit)
|
||||
{
|
||||
*ptr1 = pair[0];
|
||||
*ptr0 = pair[1];
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pb[len] < cur[len])
|
||||
{
|
||||
*ptr1 = curMatch;
|
||||
ptr1 = pair + 1;
|
||||
curMatch = *ptr1;
|
||||
len1 = len;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ptr0 = curMatch;
|
||||
ptr0 = pair;
|
||||
curMatch = *ptr0;
|
||||
len0 = len;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define MOVE_POS \
|
||||
++p->cyclicBufferPos; \
|
||||
p->buffer++; \
|
||||
if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);
|
||||
|
||||
#define MOVE_POS_RET MOVE_POS return offset;
|
||||
|
||||
static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
|
||||
|
||||
#define GET_MATCHES_HEADER2(minLen, ret_op) \
|
||||
UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \
|
||||
lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
|
||||
cur = p->buffer;
|
||||
|
||||
#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)
|
||||
#define SKIP_HEADER(minLen) GET_MATCHES_HEADER2(minLen, continue)
|
||||
|
||||
#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue
|
||||
|
||||
#define GET_MATCHES_FOOTER(offset, maxLen) \
|
||||
offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \
|
||||
distances + offset, maxLen) - distances); MOVE_POS_RET;
|
||||
|
||||
#define SKIP_FOOTER \
|
||||
SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
|
||||
|
||||
static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
|
||||
{
|
||||
UInt32 offset;
|
||||
GET_MATCHES_HEADER(2)
|
||||
HASH2_CALC;
|
||||
curMatch = p->hash[hashValue];
|
||||
p->hash[hashValue] = p->pos;
|
||||
offset = 0;
|
||||
GET_MATCHES_FOOTER(offset, 1)
|
||||
}
|
||||
|
||||
UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
|
||||
{
|
||||
UInt32 offset;
|
||||
GET_MATCHES_HEADER(3)
|
||||
HASH_ZIP_CALC;
|
||||
curMatch = p->hash[hashValue];
|
||||
p->hash[hashValue] = p->pos;
|
||||
offset = 0;
|
||||
GET_MATCHES_FOOTER(offset, 2)
|
||||
}
|
||||
|
||||
static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
|
||||
{
|
||||
UInt32 hash2Value, delta2, maxLen, offset;
|
||||
GET_MATCHES_HEADER(3)
|
||||
|
||||
HASH3_CALC;
|
||||
|
||||
delta2 = p->pos - p->hash[hash2Value];
|
||||
curMatch = p->hash[kFix3HashSize + hashValue];
|
||||
|
||||
p->hash[hash2Value] =
|
||||
p->hash[kFix3HashSize + hashValue] = p->pos;
|
||||
|
||||
|
||||
maxLen = 2;
|
||||
offset = 0;
|
||||
if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
|
||||
{
|
||||
for (; maxLen != lenLimit; maxLen++)
|
||||
if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
|
||||
break;
|
||||
distances[0] = maxLen;
|
||||
distances[1] = delta2 - 1;
|
||||
offset = 2;
|
||||
if (maxLen == lenLimit)
|
||||
{
|
||||
SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
|
||||
MOVE_POS_RET;
|
||||
}
|
||||
}
|
||||
GET_MATCHES_FOOTER(offset, maxLen)
|
||||
}
|
||||
|
||||
static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
|
||||
{
|
||||
UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
|
||||
GET_MATCHES_HEADER(4)
|
||||
|
||||
HASH4_CALC;
|
||||
|
||||
delta2 = p->pos - p->hash[ hash2Value];
|
||||
delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
|
||||
curMatch = p->hash[kFix4HashSize + hashValue];
|
||||
|
||||
p->hash[ hash2Value] =
|
||||
p->hash[kFix3HashSize + hash3Value] =
|
||||
p->hash[kFix4HashSize + hashValue] = p->pos;
|
||||
|
||||
maxLen = 1;
|
||||
offset = 0;
|
||||
if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
|
||||
{
|
||||
distances[0] = maxLen = 2;
|
||||
distances[1] = delta2 - 1;
|
||||
offset = 2;
|
||||
}
|
||||
if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)
|
||||
{
|
||||
maxLen = 3;
|
||||
distances[offset + 1] = delta3 - 1;
|
||||
offset += 2;
|
||||
delta2 = delta3;
|
||||
}
|
||||
if (offset != 0)
|
||||
{
|
||||
for (; maxLen != lenLimit; maxLen++)
|
||||
if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
|
||||
break;
|
||||
distances[offset - 2] = maxLen;
|
||||
if (maxLen == lenLimit)
|
||||
{
|
||||
SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
|
||||
MOVE_POS_RET;
|
||||
}
|
||||
}
|
||||
if (maxLen < 3)
|
||||
maxLen = 3;
|
||||
GET_MATCHES_FOOTER(offset, maxLen)
|
||||
}
|
||||
|
||||
static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
|
||||
{
|
||||
UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
|
||||
GET_MATCHES_HEADER(4)
|
||||
|
||||
HASH4_CALC;
|
||||
|
||||
delta2 = p->pos - p->hash[ hash2Value];
|
||||
delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
|
||||
curMatch = p->hash[kFix4HashSize + hashValue];
|
||||
|
||||
p->hash[ hash2Value] =
|
||||
p->hash[kFix3HashSize + hash3Value] =
|
||||
p->hash[kFix4HashSize + hashValue] = p->pos;
|
||||
|
||||
maxLen = 1;
|
||||
offset = 0;
|
||||
if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
|
||||
{
|
||||
distances[0] = maxLen = 2;
|
||||
distances[1] = delta2 - 1;
|
||||
offset = 2;
|
||||
}
|
||||
if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)
|
||||
{
|
||||
maxLen = 3;
|
||||
distances[offset + 1] = delta3 - 1;
|
||||
offset += 2;
|
||||
delta2 = delta3;
|
||||
}
|
||||
if (offset != 0)
|
||||
{
|
||||
for (; maxLen != lenLimit; maxLen++)
|
||||
if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
|
||||
break;
|
||||
distances[offset - 2] = maxLen;
|
||||
if (maxLen == lenLimit)
|
||||
{
|
||||
p->son[p->cyclicBufferPos] = curMatch;
|
||||
MOVE_POS_RET;
|
||||
}
|
||||
}
|
||||
if (maxLen < 3)
|
||||
maxLen = 3;
|
||||
offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
|
||||
distances + offset, maxLen) - (distances));
|
||||
MOVE_POS_RET
|
||||
}
|
||||
|
||||
UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
|
||||
{
|
||||
UInt32 offset;
|
||||
GET_MATCHES_HEADER(3)
|
||||
HASH_ZIP_CALC;
|
||||
curMatch = p->hash[hashValue];
|
||||
p->hash[hashValue] = p->pos;
|
||||
offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
|
||||
distances, 2) - (distances));
|
||||
MOVE_POS_RET
|
||||
}
|
||||
|
||||
static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
|
||||
{
|
||||
do
|
||||
{
|
||||
SKIP_HEADER(2)
|
||||
HASH2_CALC;
|
||||
curMatch = p->hash[hashValue];
|
||||
p->hash[hashValue] = p->pos;
|
||||
SKIP_FOOTER
|
||||
}
|
||||
while (--num != 0);
|
||||
}
|
||||
|
||||
void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
|
||||
{
|
||||
do
|
||||
{
|
||||
SKIP_HEADER(3)
|
||||
HASH_ZIP_CALC;
|
||||
curMatch = p->hash[hashValue];
|
||||
p->hash[hashValue] = p->pos;
|
||||
SKIP_FOOTER
|
||||
}
|
||||
while (--num != 0);
|
||||
}
|
||||
|
||||
static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
|
||||
{
|
||||
do
|
||||
{
|
||||
UInt32 hash2Value;
|
||||
SKIP_HEADER(3)
|
||||
HASH3_CALC;
|
||||
curMatch = p->hash[kFix3HashSize + hashValue];
|
||||
p->hash[hash2Value] =
|
||||
p->hash[kFix3HashSize + hashValue] = p->pos;
|
||||
SKIP_FOOTER
|
||||
}
|
||||
while (--num != 0);
|
||||
}
|
||||
|
||||
static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
|
||||
{
|
||||
do
|
||||
{
|
||||
UInt32 hash2Value, hash3Value;
|
||||
SKIP_HEADER(4)
|
||||
HASH4_CALC;
|
||||
curMatch = p->hash[kFix4HashSize + hashValue];
|
||||
p->hash[ hash2Value] =
|
||||
p->hash[kFix3HashSize + hash3Value] = p->pos;
|
||||
p->hash[kFix4HashSize + hashValue] = p->pos;
|
||||
SKIP_FOOTER
|
||||
}
|
||||
while (--num != 0);
|
||||
}
|
||||
|
||||
static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
|
||||
{
|
||||
do
|
||||
{
|
||||
UInt32 hash2Value, hash3Value;
|
||||
SKIP_HEADER(4)
|
||||
HASH4_CALC;
|
||||
curMatch = p->hash[kFix4HashSize + hashValue];
|
||||
p->hash[ hash2Value] =
|
||||
p->hash[kFix3HashSize + hash3Value] =
|
||||
p->hash[kFix4HashSize + hashValue] = p->pos;
|
||||
p->son[p->cyclicBufferPos] = curMatch;
|
||||
MOVE_POS
|
||||
}
|
||||
while (--num != 0);
|
||||
}
|
||||
|
||||
void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
|
||||
{
|
||||
do
|
||||
{
|
||||
SKIP_HEADER(3)
|
||||
HASH_ZIP_CALC;
|
||||
curMatch = p->hash[hashValue];
|
||||
p->hash[hashValue] = p->pos;
|
||||
p->son[p->cyclicBufferPos] = curMatch;
|
||||
MOVE_POS
|
||||
}
|
||||
while (--num != 0);
|
||||
}
|
||||
|
||||
void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)
|
||||
{
|
||||
vTable->Init = (Mf_Init_Func)MatchFinder_Init;
|
||||
vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;
|
||||
vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;
|
||||
vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;
|
||||
if (!p->btMode)
|
||||
{
|
||||
vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;
|
||||
vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;
|
||||
}
|
||||
else if (p->numHashBytes == 2)
|
||||
{
|
||||
vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;
|
||||
vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;
|
||||
}
|
||||
else if (p->numHashBytes == 3)
|
||||
{
|
||||
vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;
|
||||
vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;
|
||||
}
|
||||
else
|
||||
{
|
||||
vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;
|
||||
vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
/* LzFind.h -- Match finder for LZ algorithms
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __LZFIND_H
|
||||
#define __LZFIND_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
typedef UInt32 CLzRef;
|
||||
|
||||
typedef struct _CMatchFinder
|
||||
{
|
||||
Byte *buffer;
|
||||
UInt32 pos;
|
||||
UInt32 posLimit;
|
||||
UInt32 streamPos;
|
||||
UInt32 lenLimit;
|
||||
|
||||
UInt32 cyclicBufferPos;
|
||||
UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
|
||||
|
||||
UInt32 matchMaxLen;
|
||||
CLzRef *hash;
|
||||
CLzRef *son;
|
||||
UInt32 hashMask;
|
||||
UInt32 cutValue;
|
||||
|
||||
Byte *bufferBase;
|
||||
ISeqInStream *stream;
|
||||
int streamEndWasReached;
|
||||
|
||||
UInt32 blockSize;
|
||||
UInt32 keepSizeBefore;
|
||||
UInt32 keepSizeAfter;
|
||||
|
||||
UInt32 numHashBytes;
|
||||
int directInput;
|
||||
int btMode;
|
||||
/* int skipModeBits; */
|
||||
int bigHash;
|
||||
UInt32 historySize;
|
||||
UInt32 fixedHashSize;
|
||||
UInt32 hashSizeSum;
|
||||
UInt32 numSons;
|
||||
SRes result;
|
||||
UInt32 crc[256];
|
||||
} CMatchFinder;
|
||||
|
||||
#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
|
||||
#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])
|
||||
|
||||
#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
|
||||
|
||||
int MatchFinder_NeedMove(CMatchFinder *p);
|
||||
Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
|
||||
void MatchFinder_MoveBlock(CMatchFinder *p);
|
||||
void MatchFinder_ReadIfRequired(CMatchFinder *p);
|
||||
|
||||
void MatchFinder_Construct(CMatchFinder *p);
|
||||
|
||||
/* Conditions:
|
||||
historySize <= 3 GB
|
||||
keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB
|
||||
*/
|
||||
int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
|
||||
UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
|
||||
ISzAlloc *alloc);
|
||||
void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);
|
||||
void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);
|
||||
void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
|
||||
|
||||
UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
|
||||
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
|
||||
UInt32 *distances, UInt32 maxLen);
|
||||
|
||||
/*
|
||||
Conditions:
|
||||
Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
|
||||
Mf_GetPointerToCurrentPos_Func's result must be used only before any other function
|
||||
*/
|
||||
|
||||
typedef void (*Mf_Init_Func)(void *object);
|
||||
typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);
|
||||
typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);
|
||||
typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);
|
||||
typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);
|
||||
typedef void (*Mf_Skip_Func)(void *object, UInt32);
|
||||
|
||||
typedef struct _IMatchFinder
|
||||
{
|
||||
Mf_Init_Func Init;
|
||||
Mf_GetIndexByte_Func GetIndexByte;
|
||||
Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
|
||||
Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
|
||||
Mf_GetMatches_Func GetMatches;
|
||||
Mf_Skip_Func Skip;
|
||||
} IMatchFinder;
|
||||
|
||||
void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
|
||||
|
||||
void MatchFinder_Init(CMatchFinder *p);
|
||||
UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
|
||||
UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
|
||||
void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
|
||||
void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,54 @@
|
|||
/* LzHash.h -- HASH functions for LZ algorithms
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __LZHASH_H
|
||||
#define __LZHASH_H
|
||||
|
||||
#define kHash2Size (1 << 10)
|
||||
#define kHash3Size (1 << 16)
|
||||
#define kHash4Size (1 << 20)
|
||||
|
||||
#define kFix3HashSize (kHash2Size)
|
||||
#define kFix4HashSize (kHash2Size + kHash3Size)
|
||||
#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
|
||||
|
||||
#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);
|
||||
|
||||
#define HASH3_CALC { \
|
||||
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
|
||||
hash2Value = temp & (kHash2Size - 1); \
|
||||
hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }
|
||||
|
||||
#define HASH4_CALC { \
|
||||
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
|
||||
hash2Value = temp & (kHash2Size - 1); \
|
||||
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
|
||||
hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }
|
||||
|
||||
#define HASH5_CALC { \
|
||||
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
|
||||
hash2Value = temp & (kHash2Size - 1); \
|
||||
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
|
||||
hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \
|
||||
hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \
|
||||
hash4Value &= (kHash4Size - 1); }
|
||||
|
||||
/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */
|
||||
#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;
|
||||
|
||||
|
||||
#define MT_HASH2_CALC \
|
||||
hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);
|
||||
|
||||
#define MT_HASH3_CALC { \
|
||||
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
|
||||
hash2Value = temp & (kHash2Size - 1); \
|
||||
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }
|
||||
|
||||
#define MT_HASH4_CALC { \
|
||||
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
|
||||
hash2Value = temp & (kHash2Size - 1); \
|
||||
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
|
||||
hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,223 @@
|
|||
/* LzmaDec.h -- LZMA Decoder
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __LZMADEC_H
|
||||
#define __LZMADEC_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
/* #define _LZMA_PROB32 */
|
||||
/* _LZMA_PROB32 can increase the speed on some CPUs,
|
||||
but memory usage for CLzmaDec::probs will be doubled in that case */
|
||||
|
||||
#ifdef _LZMA_PROB32
|
||||
#define CLzmaProb UInt32
|
||||
#else
|
||||
#define CLzmaProb UInt16
|
||||
#endif
|
||||
|
||||
|
||||
/* ---------- LZMA Properties ---------- */
|
||||
|
||||
#define LZMA_PROPS_SIZE 5
|
||||
|
||||
typedef struct _CLzmaProps
|
||||
{
|
||||
unsigned lc, lp, pb;
|
||||
UInt32 dicSize;
|
||||
} CLzmaProps;
|
||||
|
||||
/* LzmaProps_Decode - decodes properties
|
||||
Returns:
|
||||
SZ_OK
|
||||
SZ_ERROR_UNSUPPORTED - Unsupported properties
|
||||
*/
|
||||
|
||||
SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
|
||||
|
||||
|
||||
/* ---------- LZMA Decoder state ---------- */
|
||||
|
||||
/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
|
||||
Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
|
||||
|
||||
#define LZMA_REQUIRED_INPUT_MAX 20
|
||||
|
||||
typedef struct
|
||||
{
|
||||
CLzmaProps prop;
|
||||
CLzmaProb *probs;
|
||||
Byte *dic;
|
||||
const Byte *buf;
|
||||
UInt32 range, code;
|
||||
SizeT dicPos;
|
||||
SizeT dicBufSize;
|
||||
UInt32 processedPos;
|
||||
UInt32 checkDicSize;
|
||||
unsigned state;
|
||||
UInt32 reps[4];
|
||||
unsigned remainLen;
|
||||
int needFlush;
|
||||
int needInitState;
|
||||
UInt32 numProbs;
|
||||
unsigned tempBufSize;
|
||||
Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];
|
||||
} CLzmaDec;
|
||||
|
||||
#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
|
||||
|
||||
void LzmaDec_Init(CLzmaDec *p);
|
||||
|
||||
/* There are two types of LZMA streams:
|
||||
0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
|
||||
1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LZMA_FINISH_ANY, /* finish at any point */
|
||||
LZMA_FINISH_END /* block must be finished at the end */
|
||||
} ELzmaFinishMode;
|
||||
|
||||
/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
|
||||
|
||||
You must use LZMA_FINISH_END, when you know that current output buffer
|
||||
covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
|
||||
|
||||
If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
|
||||
and output value of destLen will be less than output buffer size limit.
|
||||
You can check status result also.
|
||||
|
||||
You can use multiple checks to test data integrity after full decompression:
|
||||
1) Check Result and "status" variable.
|
||||
2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
|
||||
3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
|
||||
You must use correct finish mode in that case. */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */
|
||||
LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */
|
||||
LZMA_STATUS_NOT_FINISHED, /* stream was not finished */
|
||||
LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
|
||||
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */
|
||||
} ELzmaStatus;
|
||||
|
||||
/* ELzmaStatus is used only as output value for function call */
|
||||
|
||||
|
||||
/* ---------- Interfaces ---------- */
|
||||
|
||||
/* There are 3 levels of interfaces:
|
||||
1) Dictionary Interface
|
||||
2) Buffer Interface
|
||||
3) One Call Interface
|
||||
You can select any of these interfaces, but don't mix functions from different
|
||||
groups for same object. */
|
||||
|
||||
|
||||
/* There are two variants to allocate state for Dictionary Interface:
|
||||
1) LzmaDec_Allocate / LzmaDec_Free
|
||||
2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
|
||||
You can use variant 2, if you set dictionary buffer manually.
|
||||
For Buffer Interface you must always use variant 1.
|
||||
|
||||
LzmaDec_Allocate* can return:
|
||||
SZ_OK
|
||||
SZ_ERROR_MEM - Memory allocation error
|
||||
SZ_ERROR_UNSUPPORTED - Unsupported properties
|
||||
*/
|
||||
|
||||
SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);
|
||||
void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
|
||||
|
||||
SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);
|
||||
void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
|
||||
|
||||
/* ---------- Dictionary Interface ---------- */
|
||||
|
||||
/* You can use it, if you want to eliminate the overhead for data copying from
|
||||
dictionary to some other external buffer.
|
||||
You must work with CLzmaDec variables directly in this interface.
|
||||
|
||||
STEPS:
|
||||
LzmaDec_Constr()
|
||||
LzmaDec_Allocate()
|
||||
for (each new stream)
|
||||
{
|
||||
LzmaDec_Init()
|
||||
while (it needs more decompression)
|
||||
{
|
||||
LzmaDec_DecodeToDic()
|
||||
use data from CLzmaDec::dic and update CLzmaDec::dicPos
|
||||
}
|
||||
}
|
||||
LzmaDec_Free()
|
||||
*/
|
||||
|
||||
/* LzmaDec_DecodeToDic
|
||||
|
||||
The decoding to internal dictionary buffer (CLzmaDec::dic).
|
||||
You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
|
||||
|
||||
finishMode:
|
||||
It has meaning only if the decoding reaches output limit (dicLimit).
|
||||
LZMA_FINISH_ANY - Decode just dicLimit bytes.
|
||||
LZMA_FINISH_END - Stream must be finished after dicLimit.
|
||||
|
||||
Returns:
|
||||
SZ_OK
|
||||
status:
|
||||
LZMA_STATUS_FINISHED_WITH_MARK
|
||||
LZMA_STATUS_NOT_FINISHED
|
||||
LZMA_STATUS_NEEDS_MORE_INPUT
|
||||
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
|
||||
SZ_ERROR_DATA - Data error
|
||||
*/
|
||||
|
||||
SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
|
||||
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
|
||||
|
||||
|
||||
/* ---------- Buffer Interface ---------- */
|
||||
|
||||
/* It's zlib-like interface.
|
||||
See LzmaDec_DecodeToDic description for information about STEPS and return results,
|
||||
but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
|
||||
to work with CLzmaDec variables manually.
|
||||
|
||||
finishMode:
|
||||
It has meaning only if the decoding reaches output limit (*destLen).
|
||||
LZMA_FINISH_ANY - Decode just destLen bytes.
|
||||
LZMA_FINISH_END - Stream must be finished after (*destLen).
|
||||
*/
|
||||
|
||||
SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
|
||||
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
|
||||
|
||||
|
||||
/* ---------- One Call Interface ---------- */
|
||||
|
||||
/* LzmaDecode
|
||||
|
||||
finishMode:
|
||||
It has meaning only if the decoding reaches output limit (*destLen).
|
||||
LZMA_FINISH_ANY - Decode just destLen bytes.
|
||||
LZMA_FINISH_END - Stream must be finished after (*destLen).
|
||||
|
||||
Returns:
|
||||
SZ_OK
|
||||
status:
|
||||
LZMA_STATUS_FINISHED_WITH_MARK
|
||||
LZMA_STATUS_NOT_FINISHED
|
||||
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
|
||||
SZ_ERROR_DATA - Data error
|
||||
SZ_ERROR_MEM - Memory allocation error
|
||||
SZ_ERROR_UNSUPPORTED - Unsupported properties
|
||||
SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
|
||||
*/
|
||||
|
||||
SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
|
||||
const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
|
||||
ELzmaStatus *status, ISzAlloc *alloc);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,231 @@
|
|||
/** @file
|
||||
Types.h
|
||||
|
||||
Based on LZMA SDK 4.65:
|
||||
Types.h -- Basic types
|
||||
2008-11-23 : Igor Pavlov : Public domain
|
||||
|
||||
Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef __7Z_TYPES_H
|
||||
#define __7Z_TYPES_H
|
||||
|
||||
#ifdef EFIAPI
|
||||
|
||||
#include "UefiLzma.h"
|
||||
|
||||
#else
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#define SZ_OK 0
|
||||
|
||||
#define SZ_ERROR_DATA 1
|
||||
#define SZ_ERROR_MEM 2
|
||||
#define SZ_ERROR_CRC 3
|
||||
#define SZ_ERROR_UNSUPPORTED 4
|
||||
#define SZ_ERROR_PARAM 5
|
||||
#define SZ_ERROR_INPUT_EOF 6
|
||||
#define SZ_ERROR_OUTPUT_EOF 7
|
||||
#define SZ_ERROR_READ 8
|
||||
#define SZ_ERROR_WRITE 9
|
||||
#define SZ_ERROR_PROGRESS 10
|
||||
#define SZ_ERROR_FAIL 11
|
||||
#define SZ_ERROR_THREAD 12
|
||||
|
||||
#define SZ_ERROR_ARCHIVE 16
|
||||
#define SZ_ERROR_NO_ARCHIVE 17
|
||||
|
||||
typedef int SRes;
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef DWORD WRes;
|
||||
#else
|
||||
typedef int WRes;
|
||||
#endif
|
||||
|
||||
#ifndef RINOK
|
||||
#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
|
||||
#endif
|
||||
|
||||
typedef unsigned char Byte;
|
||||
typedef short Int16;
|
||||
typedef unsigned short UInt16;
|
||||
|
||||
#ifdef _LZMA_UINT32_IS_ULONG
|
||||
typedef long Int32;
|
||||
typedef unsigned long UInt32;
|
||||
#else
|
||||
typedef int Int32;
|
||||
typedef unsigned int UInt32;
|
||||
#endif
|
||||
|
||||
#ifdef _SZ_NO_INT_64
|
||||
|
||||
/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
|
||||
NOTES: Some code will work incorrectly in that case! */
|
||||
|
||||
typedef long Int64;
|
||||
typedef unsigned long UInt64;
|
||||
|
||||
#else
|
||||
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
typedef __int64 Int64;
|
||||
typedef unsigned __int64 UInt64;
|
||||
#else
|
||||
typedef long long int Int64;
|
||||
typedef unsigned long long int UInt64;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _LZMA_NO_SYSTEM_SIZE_T
|
||||
typedef UInt32 SizeT;
|
||||
#else
|
||||
typedef size_t SizeT;
|
||||
#endif
|
||||
|
||||
typedef int Bool;
|
||||
#define True 1
|
||||
#define False 0
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#if _MSC_VER >= 1300
|
||||
#define MY_NO_INLINE __declspec(noinline)
|
||||
#else
|
||||
#define MY_NO_INLINE
|
||||
#endif
|
||||
|
||||
#define MY_CDECL __cdecl
|
||||
#define MY_STD_CALL __stdcall
|
||||
#define MY_FAST_CALL MY_NO_INLINE __fastcall
|
||||
|
||||
#else
|
||||
|
||||
#define MY_CDECL
|
||||
#define MY_STD_CALL
|
||||
#define MY_FAST_CALL
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* The following interfaces use first parameter as pointer to structure */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SRes (*Read)(void *p, void *buf, size_t *size);
|
||||
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
|
||||
(output(*size) < input(*size)) is allowed */
|
||||
} ISeqInStream;
|
||||
|
||||
/* it can return SZ_ERROR_INPUT_EOF */
|
||||
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
|
||||
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
|
||||
SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t (*Write)(void *p, const void *buf, size_t size);
|
||||
/* Returns: result - the number of actually written bytes.
|
||||
(result < size) means error */
|
||||
} ISeqOutStream;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SZ_SEEK_SET = 0,
|
||||
SZ_SEEK_CUR = 1,
|
||||
SZ_SEEK_END = 2
|
||||
} ESzSeek;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */
|
||||
SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
|
||||
} ISeekInStream;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SRes (*Look)(void *p, void **buf, size_t *size);
|
||||
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
|
||||
(output(*size) > input(*size)) is not allowed
|
||||
(output(*size) < input(*size)) is allowed */
|
||||
SRes (*Skip)(void *p, size_t offset);
|
||||
/* offset must be <= output(*size) of Look */
|
||||
|
||||
SRes (*Read)(void *p, void *buf, size_t *size);
|
||||
/* reads directly (without buffer). It's same as ISeqInStream::Read */
|
||||
SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
|
||||
} ILookInStream;
|
||||
|
||||
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
|
||||
SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
|
||||
|
||||
/* reads via ILookInStream::Read */
|
||||
SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
|
||||
SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
|
||||
|
||||
#define LookToRead_BUF_SIZE (1 << 14)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ILookInStream s;
|
||||
ISeekInStream *realStream;
|
||||
size_t pos;
|
||||
size_t size;
|
||||
Byte buf[LookToRead_BUF_SIZE];
|
||||
} CLookToRead;
|
||||
|
||||
void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
|
||||
void LookToRead_Init(CLookToRead *p);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ISeqInStream s;
|
||||
ILookInStream *realStream;
|
||||
} CSecToLook;
|
||||
|
||||
void SecToLook_CreateVTable(CSecToLook *p);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ISeqInStream s;
|
||||
ILookInStream *realStream;
|
||||
} CSecToRead;
|
||||
|
||||
void SecToRead_CreateVTable(CSecToRead *p);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
|
||||
/* Returns: result. (result != SZ_OK) means break.
|
||||
Value (UInt64)(Int64)-1 for size means unknown value. */
|
||||
} ICompressProgress;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void *(*Alloc)(void *p, size_t size);
|
||||
void (*Free)(void *p, void *address); /* address can be 0 */
|
||||
} ISzAlloc;
|
||||
|
||||
#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
|
||||
#define IAlloc_Free(p, a) (p)->Free((p), a)
|
||||
|
||||
#endif
|
|
@ -0,0 +1,236 @@
|
|||
HISTORY of the LZMA SDK
|
||||
-----------------------
|
||||
|
||||
4.65 2009-02-03
|
||||
-------------------------
|
||||
- Some minor fixes
|
||||
|
||||
|
||||
4.63 2008-12-31
|
||||
-------------------------
|
||||
- Some minor fixes
|
||||
|
||||
|
||||
4.61 beta 2008-11-23
|
||||
-------------------------
|
||||
- The bug in ANSI-C LZMA Decoder was fixed:
|
||||
If encoded stream was corrupted, decoder could access memory
|
||||
outside of allocated range.
|
||||
- Some changes in ANSI-C 7z Decoder interfaces.
|
||||
- LZMA SDK is placed in the public domain.
|
||||
|
||||
|
||||
4.60 beta 2008-08-19
|
||||
-------------------------
|
||||
- Some minor fixes.
|
||||
|
||||
|
||||
4.59 beta 2008-08-13
|
||||
-------------------------
|
||||
- The bug was fixed:
|
||||
LZMA Encoder in fast compression mode could access memory outside of
|
||||
allocated range in some rare cases.
|
||||
|
||||
|
||||
4.58 beta 2008-05-05
|
||||
-------------------------
|
||||
- ANSI-C LZMA Decoder was rewritten for speed optimizations.
|
||||
- ANSI-C LZMA Encoder was included to LZMA SDK.
|
||||
- C++ LZMA code now is just wrapper over ANSI-C code.
|
||||
|
||||
|
||||
4.57 2007-12-12
|
||||
-------------------------
|
||||
- Speed optimizations in Ñ++ LZMA Decoder.
|
||||
- Small changes for more compatibility with some C/C++ compilers.
|
||||
|
||||
|
||||
4.49 beta 2007-07-05
|
||||
-------------------------
|
||||
- .7z ANSI-C Decoder:
|
||||
- now it supports BCJ and BCJ2 filters
|
||||
- now it supports files larger than 4 GB.
|
||||
- now it supports "Last Write Time" field for files.
|
||||
- C++ code for .7z archives compressing/decompressing from 7-zip
|
||||
was included to LZMA SDK.
|
||||
|
||||
|
||||
4.43 2006-06-04
|
||||
-------------------------
|
||||
- Small changes for more compatibility with some C/C++ compilers.
|
||||
|
||||
|
||||
4.42 2006-05-15
|
||||
-------------------------
|
||||
- Small changes in .h files in ANSI-C version.
|
||||
|
||||
|
||||
4.39 beta 2006-04-14
|
||||
-------------------------
|
||||
- The bug in versions 4.33b:4.38b was fixed:
|
||||
C++ version of LZMA encoder could not correctly compress
|
||||
files larger than 2 GB with HC4 match finder (-mfhc4).
|
||||
|
||||
|
||||
4.37 beta 2005-04-06
|
||||
-------------------------
|
||||
- Fixes in C++ code: code could no be compiled if _NO_EXCEPTIONS was defined.
|
||||
|
||||
|
||||
4.35 beta 2005-03-02
|
||||
-------------------------
|
||||
- The bug was fixed in C++ version of LZMA Decoder:
|
||||
If encoded stream was corrupted, decoder could access memory
|
||||
outside of allocated range.
|
||||
|
||||
|
||||
4.34 beta 2006-02-27
|
||||
-------------------------
|
||||
- Compressing speed and memory requirements for compressing were increased
|
||||
- LZMA now can use only these match finders: HC4, BT2, BT3, BT4
|
||||
|
||||
|
||||
4.32 2005-12-09
|
||||
-------------------------
|
||||
- Java version of LZMA SDK was included
|
||||
|
||||
|
||||
4.30 2005-11-20
|
||||
-------------------------
|
||||
- Compression ratio was improved in -a2 mode
|
||||
- Speed optimizations for compressing in -a2 mode
|
||||
- -fb switch now supports values up to 273
|
||||
- The bug in 7z_C (7zIn.c) was fixed:
|
||||
It used Alloc/Free functions from different memory pools.
|
||||
So if program used two memory pools, it worked incorrectly.
|
||||
- 7z_C: .7z format supporting was improved
|
||||
- LZMA# SDK (C#.NET version) was included
|
||||
|
||||
|
||||
4.27 (Updated) 2005-09-21
|
||||
-------------------------
|
||||
- Some GUIDs/interfaces in C++ were changed.
|
||||
IStream.h:
|
||||
ISequentialInStream::Read now works as old ReadPart
|
||||
ISequentialOutStream::Write now works as old WritePart
|
||||
|
||||
|
||||
4.27 2005-08-07
|
||||
-------------------------
|
||||
- The bug in LzmaDecodeSize.c was fixed:
|
||||
if _LZMA_IN_CB and _LZMA_OUT_READ were defined,
|
||||
decompressing worked incorrectly.
|
||||
|
||||
|
||||
4.26 2005-08-05
|
||||
-------------------------
|
||||
- Fixes in 7z_C code and LzmaTest.c:
|
||||
previous versions could work incorrectly,
|
||||
if malloc(0) returns 0
|
||||
|
||||
|
||||
4.23 2005-06-29
|
||||
-------------------------
|
||||
- Small fixes in C++ code
|
||||
|
||||
|
||||
4.22 2005-06-10
|
||||
-------------------------
|
||||
- Small fixes
|
||||
|
||||
|
||||
4.21 2005-06-08
|
||||
-------------------------
|
||||
- Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed
|
||||
- New additional version of ANSI-C LZMA Decoder with zlib-like interface:
|
||||
- LzmaStateDecode.h
|
||||
- LzmaStateDecode.c
|
||||
- LzmaStateTest.c
|
||||
- ANSI-C LZMA Decoder now can decompress files larger than 4 GB
|
||||
|
||||
|
||||
4.17 2005-04-18
|
||||
-------------------------
|
||||
- New example for RAM->RAM compressing/decompressing:
|
||||
LZMA + BCJ (filter for x86 code):
|
||||
- LzmaRam.h
|
||||
- LzmaRam.cpp
|
||||
- LzmaRamDecode.h
|
||||
- LzmaRamDecode.c
|
||||
- -f86 switch for lzma.exe
|
||||
|
||||
|
||||
4.16 2005-03-29
|
||||
-------------------------
|
||||
- The bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder):
|
||||
If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,
|
||||
decoder could access memory outside of allocated range.
|
||||
- Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).
|
||||
Old version of LZMA Decoder now is in file LzmaDecodeSize.c.
|
||||
LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c
|
||||
- Small speed optimization in LZMA C++ code
|
||||
- filter for SPARC's code was added
|
||||
- Simplified version of .7z ANSI-C Decoder was included
|
||||
|
||||
|
||||
4.06 2004-09-05
|
||||
-------------------------
|
||||
- The bug in v4.05 was fixed:
|
||||
LZMA-Encoder didn't release output stream in some cases.
|
||||
|
||||
|
||||
4.05 2004-08-25
|
||||
-------------------------
|
||||
- Source code of filters for x86, IA-64, ARM, ARM-Thumb
|
||||
and PowerPC code was included to SDK
|
||||
- Some internal minor changes
|
||||
|
||||
|
||||
4.04 2004-07-28
|
||||
-------------------------
|
||||
- More compatibility with some C++ compilers
|
||||
|
||||
|
||||
4.03 2004-06-18
|
||||
-------------------------
|
||||
- "Benchmark" command was added. It measures compressing
|
||||
and decompressing speed and shows rating values.
|
||||
Also it checks hardware errors.
|
||||
|
||||
|
||||
4.02 2004-06-10
|
||||
-------------------------
|
||||
- C++ LZMA Encoder/Decoder code now is more portable
|
||||
and it can be compiled by GCC on Linux.
|
||||
|
||||
|
||||
4.01 2004-02-15
|
||||
-------------------------
|
||||
- Some detection of data corruption was enabled.
|
||||
LzmaDecode.c / RangeDecoderReadByte
|
||||
.....
|
||||
{
|
||||
rd->ExtraBytes = 1;
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
|
||||
4.00 2004-02-13
|
||||
-------------------------
|
||||
- Original version of LZMA SDK
|
||||
|
||||
|
||||
|
||||
HISTORY of the LZMA
|
||||
-------------------
|
||||
2001-2008: Improvements to LZMA compressing/decompressing code,
|
||||
keeping compatibility with original LZMA format
|
||||
1996-2001: Development of LZMA compression format
|
||||
|
||||
Some milestones:
|
||||
|
||||
2001-08-30: LZMA compression was added to 7-Zip
|
||||
1999-01-02: First version of 7-Zip was released
|
||||
|
||||
|
||||
End of document
|
|
@ -0,0 +1,594 @@
|
|||
LZMA SDK 4.65
|
||||
-------------
|
||||
|
||||
LZMA SDK provides the documentation, samples, header files, libraries,
|
||||
and tools you need to develop applications that use LZMA compression.
|
||||
|
||||
LZMA is default and general compression method of 7z format
|
||||
in 7-Zip compression program (www.7-zip.org). LZMA provides high
|
||||
compression ratio and very fast decompression.
|
||||
|
||||
LZMA is an improved version of famous LZ77 compression algorithm.
|
||||
It was improved in way of maximum increasing of compression ratio,
|
||||
keeping high decompression speed and low memory requirements for
|
||||
decompressing.
|
||||
|
||||
|
||||
|
||||
LICENSE
|
||||
-------
|
||||
|
||||
LZMA SDK is written and placed in the public domain by Igor Pavlov.
|
||||
|
||||
|
||||
LZMA SDK Contents
|
||||
-----------------
|
||||
|
||||
LZMA SDK includes:
|
||||
|
||||
- ANSI-C/C++/C#/Java source code for LZMA compressing and decompressing
|
||||
- Compiled file->file LZMA compressing/decompressing program for Windows system
|
||||
|
||||
|
||||
UNIX/Linux version
|
||||
------------------
|
||||
To compile C++ version of file->file LZMA encoding, go to directory
|
||||
C++/7zip/Compress/LZMA_Alone
|
||||
and call make to recompile it:
|
||||
make -f makefile.gcc clean all
|
||||
|
||||
In some UNIX/Linux versions you must compile LZMA with static libraries.
|
||||
To compile with static libraries, you can use
|
||||
LIB = -lm -static
|
||||
|
||||
|
||||
Files
|
||||
---------------------
|
||||
lzma.txt - LZMA SDK description (this file)
|
||||
7zFormat.txt - 7z Format description
|
||||
7zC.txt - 7z ANSI-C Decoder description
|
||||
methods.txt - Compression method IDs for .7z
|
||||
lzma.exe - Compiled file->file LZMA encoder/decoder for Windows
|
||||
history.txt - history of the LZMA SDK
|
||||
|
||||
|
||||
Source code structure
|
||||
---------------------
|
||||
|
||||
C/ - C files
|
||||
7zCrc*.* - CRC code
|
||||
Alloc.* - Memory allocation functions
|
||||
Bra*.* - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code
|
||||
LzFind.* - Match finder for LZ (LZMA) encoders
|
||||
LzFindMt.* - Match finder for LZ (LZMA) encoders for multithreading encoding
|
||||
LzHash.h - Additional file for LZ match finder
|
||||
LzmaDec.* - LZMA decoding
|
||||
LzmaEnc.* - LZMA encoding
|
||||
LzmaLib.* - LZMA Library for DLL calling
|
||||
Types.h - Basic types for another .c files
|
||||
Threads.* - The code for multithreading.
|
||||
|
||||
LzmaLib - LZMA Library (.DLL for Windows)
|
||||
|
||||
LzmaUtil - LZMA Utility (file->file LZMA encoder/decoder).
|
||||
|
||||
Archive - files related to archiving
|
||||
7z - 7z ANSI-C Decoder
|
||||
|
||||
CPP/ -- CPP files
|
||||
|
||||
Common - common files for C++ projects
|
||||
Windows - common files for Windows related code
|
||||
|
||||
7zip - files related to 7-Zip Project
|
||||
|
||||
Common - common files for 7-Zip
|
||||
|
||||
Compress - files related to compression/decompression
|
||||
|
||||
Copy - Copy coder
|
||||
RangeCoder - Range Coder (special code of compression/decompression)
|
||||
LZMA - LZMA compression/decompression on C++
|
||||
LZMA_Alone - file->file LZMA compression/decompression
|
||||
Branch - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code
|
||||
|
||||
Archive - files related to archiving
|
||||
|
||||
Common - common files for archive handling
|
||||
7z - 7z C++ Encoder/Decoder
|
||||
|
||||
Bundles - Modules that are bundles of other modules
|
||||
|
||||
Alone7z - 7zr.exe: Standalone version of 7z.exe that supports only 7z/LZMA/BCJ/BCJ2
|
||||
Format7zR - 7zr.dll: Reduced version of 7za.dll: extracting/compressing to 7z/LZMA/BCJ/BCJ2
|
||||
Format7zExtractR - 7zxr.dll: Reduced version of 7zxa.dll: extracting from 7z/LZMA/BCJ/BCJ2.
|
||||
|
||||
UI - User Interface files
|
||||
|
||||
Client7z - Test application for 7za.dll, 7zr.dll, 7zxr.dll
|
||||
Common - Common UI files
|
||||
Console - Code for console archiver
|
||||
|
||||
|
||||
|
||||
CS/ - C# files
|
||||
7zip
|
||||
Common - some common files for 7-Zip
|
||||
Compress - files related to compression/decompression
|
||||
LZ - files related to LZ (Lempel-Ziv) compression algorithm
|
||||
LZMA - LZMA compression/decompression
|
||||
LzmaAlone - file->file LZMA compression/decompression
|
||||
RangeCoder - Range Coder (special code of compression/decompression)
|
||||
|
||||
Java/ - Java files
|
||||
SevenZip
|
||||
Compression - files related to compression/decompression
|
||||
LZ - files related to LZ (Lempel-Ziv) compression algorithm
|
||||
LZMA - LZMA compression/decompression
|
||||
RangeCoder - Range Coder (special code of compression/decompression)
|
||||
|
||||
|
||||
C/C++ source code of LZMA SDK is part of 7-Zip project.
|
||||
7-Zip source code can be downloaded from 7-Zip's SourceForge page:
|
||||
|
||||
http://sourceforge.net/projects/sevenzip/
|
||||
|
||||
|
||||
|
||||
LZMA features
|
||||
-------------
|
||||
- Variable dictionary size (up to 1 GB)
|
||||
- Estimated compressing speed: about 2 MB/s on 2 GHz CPU
|
||||
- Estimated decompressing speed:
|
||||
- 20-30 MB/s on 2 GHz Core 2 or AMD Athlon 64
|
||||
- 1-2 MB/s on 200 MHz ARM, MIPS, PowerPC or other simple RISC
|
||||
- Small memory requirements for decompressing (16 KB + DictionarySize)
|
||||
- Small code size for decompressing: 5-8 KB
|
||||
|
||||
LZMA decoder uses only integer operations and can be
|
||||
implemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).
|
||||
|
||||
Some critical operations that affect the speed of LZMA decompression:
|
||||
1) 32*16 bit integer multiply
|
||||
2) Misspredicted branches (penalty mostly depends from pipeline length)
|
||||
3) 32-bit shift and arithmetic operations
|
||||
|
||||
The speed of LZMA decompressing mostly depends from CPU speed.
|
||||
Memory speed has no big meaning. But if your CPU has small data cache,
|
||||
overall weight of memory speed will slightly increase.
|
||||
|
||||
|
||||
How To Use
|
||||
----------
|
||||
|
||||
Using LZMA encoder/decoder executable
|
||||
--------------------------------------
|
||||
|
||||
Usage: LZMA <e|d> inputFile outputFile [<switches>...]
|
||||
|
||||
e: encode file
|
||||
|
||||
d: decode file
|
||||
|
||||
b: Benchmark. There are two tests: compressing and decompressing
|
||||
with LZMA method. Benchmark shows rating in MIPS (million
|
||||
instructions per second). Rating value is calculated from
|
||||
measured speed and it is normalized with Intel's Core 2 results.
|
||||
Also Benchmark checks possible hardware errors (RAM
|
||||
errors in most cases). Benchmark uses these settings:
|
||||
(-a1, -d21, -fb32, -mfbt4). You can change only -d parameter.
|
||||
Also you can change the number of iterations. Example for 30 iterations:
|
||||
LZMA b 30
|
||||
Default number of iterations is 10.
|
||||
|
||||
<Switches>
|
||||
|
||||
|
||||
-a{N}: set compression mode 0 = fast, 1 = normal
|
||||
default: 1 (normal)
|
||||
|
||||
d{N}: Sets Dictionary size - [0, 30], default: 23 (8MB)
|
||||
The maximum value for dictionary size is 1 GB = 2^30 bytes.
|
||||
Dictionary size is calculated as DictionarySize = 2^N bytes.
|
||||
For decompressing file compressed by LZMA method with dictionary
|
||||
size D = 2^N you need about D bytes of memory (RAM).
|
||||
|
||||
-fb{N}: set number of fast bytes - [5, 273], default: 128
|
||||
Usually big number gives a little bit better compression ratio
|
||||
and slower compression process.
|
||||
|
||||
-lc{N}: set number of literal context bits - [0, 8], default: 3
|
||||
Sometimes lc=4 gives gain for big files.
|
||||
|
||||
-lp{N}: set number of literal pos bits - [0, 4], default: 0
|
||||
lp switch is intended for periodical data when period is
|
||||
equal 2^N. For example, for 32-bit (4 bytes)
|
||||
periodical data you can use lp=2. Often it's better to set lc0,
|
||||
if you change lp switch.
|
||||
|
||||
-pb{N}: set number of pos bits - [0, 4], default: 2
|
||||
pb switch is intended for periodical data
|
||||
when period is equal 2^N.
|
||||
|
||||
-mf{MF_ID}: set Match Finder. Default: bt4.
|
||||
Algorithms from hc* group doesn't provide good compression
|
||||
ratio, but they often works pretty fast in combination with
|
||||
fast mode (-a0).
|
||||
|
||||
Memory requirements depend from dictionary size
|
||||
(parameter "d" in table below).
|
||||
|
||||
MF_ID Memory Description
|
||||
|
||||
bt2 d * 9.5 + 4MB Binary Tree with 2 bytes hashing.
|
||||
bt3 d * 11.5 + 4MB Binary Tree with 3 bytes hashing.
|
||||
bt4 d * 11.5 + 4MB Binary Tree with 4 bytes hashing.
|
||||
hc4 d * 7.5 + 4MB Hash Chain with 4 bytes hashing.
|
||||
|
||||
-eos: write End Of Stream marker. By default LZMA doesn't write
|
||||
eos marker, since LZMA decoder knows uncompressed size
|
||||
stored in .lzma file header.
|
||||
|
||||
-si: Read data from stdin (it will write End Of Stream marker).
|
||||
-so: Write data to stdout
|
||||
|
||||
|
||||
Examples:
|
||||
|
||||
1) LZMA e file.bin file.lzma -d16 -lc0
|
||||
|
||||
compresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)
|
||||
and 0 literal context bits. -lc0 allows to reduce memory requirements
|
||||
for decompression.
|
||||
|
||||
|
||||
2) LZMA e file.bin file.lzma -lc0 -lp2
|
||||
|
||||
compresses file.bin to file.lzma with settings suitable
|
||||
for 32-bit periodical data (for example, ARM or MIPS code).
|
||||
|
||||
3) LZMA d file.lzma file.bin
|
||||
|
||||
decompresses file.lzma to file.bin.
|
||||
|
||||
|
||||
Compression ratio hints
|
||||
-----------------------
|
||||
|
||||
Recommendations
|
||||
---------------
|
||||
|
||||
To increase the compression ratio for LZMA compressing it's desirable
|
||||
to have aligned data (if it's possible) and also it's desirable to locate
|
||||
data in such order, where code is grouped in one place and data is
|
||||
grouped in other place (it's better than such mixing: code, data, code,
|
||||
data, ...).
|
||||
|
||||
|
||||
Filters
|
||||
-------
|
||||
You can increase the compression ratio for some data types, using
|
||||
special filters before compressing. For example, it's possible to
|
||||
increase the compression ratio on 5-10% for code for those CPU ISAs:
|
||||
x86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.
|
||||
|
||||
You can find C source code of such filters in C/Bra*.* files
|
||||
|
||||
You can check the compression ratio gain of these filters with such
|
||||
7-Zip commands (example for ARM code):
|
||||
No filter:
|
||||
7z a a1.7z a.bin -m0=lzma
|
||||
|
||||
With filter for little-endian ARM code:
|
||||
7z a a2.7z a.bin -m0=arm -m1=lzma
|
||||
|
||||
It works in such manner:
|
||||
Compressing = Filter_encoding + LZMA_encoding
|
||||
Decompressing = LZMA_decoding + Filter_decoding
|
||||
|
||||
Compressing and decompressing speed of such filters is very high,
|
||||
so it will not increase decompressing time too much.
|
||||
Moreover, it reduces decompression time for LZMA_decoding,
|
||||
since compression ratio with filtering is higher.
|
||||
|
||||
These filters convert CALL (calling procedure) instructions
|
||||
from relative offsets to absolute addresses, so such data becomes more
|
||||
compressible.
|
||||
|
||||
For some ISAs (for example, for MIPS) it's impossible to get gain from such filter.
|
||||
|
||||
|
||||
LZMA compressed file format
|
||||
---------------------------
|
||||
Offset Size Description
|
||||
0 1 Special LZMA properties (lc,lp, pb in encoded form)
|
||||
1 4 Dictionary size (little endian)
|
||||
5 8 Uncompressed size (little endian). -1 means unknown size
|
||||
13 Compressed data
|
||||
|
||||
|
||||
ANSI-C LZMA Decoder
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Please note that interfaces for ANSI-C code were changed in LZMA SDK 4.58.
|
||||
If you want to use old interfaces you can download previous version of LZMA SDK
|
||||
from sourceforge.net site.
|
||||
|
||||
To use ANSI-C LZMA Decoder you need the following files:
|
||||
1) LzmaDec.h + LzmaDec.c + Types.h
|
||||
LzmaUtil/LzmaUtil.c is example application that uses these files.
|
||||
|
||||
|
||||
Memory requirements for LZMA decoding
|
||||
-------------------------------------
|
||||
|
||||
Stack usage of LZMA decoding function for local variables is not
|
||||
larger than 200-400 bytes.
|
||||
|
||||
LZMA Decoder uses dictionary buffer and internal state structure.
|
||||
Internal state structure consumes
|
||||
state_size = (4 + (1.5 << (lc + lp))) KB
|
||||
by default (lc=3, lp=0), state_size = 16 KB.
|
||||
|
||||
|
||||
How To decompress data
|
||||
----------------------
|
||||
|
||||
LZMA Decoder (ANSI-C version) now supports 2 interfaces:
|
||||
1) Single-call Decompressing
|
||||
2) Multi-call State Decompressing (zlib-like interface)
|
||||
|
||||
You must use external allocator:
|
||||
Example:
|
||||
void *SzAlloc(void *p, size_t size) { p = p; return malloc(size); }
|
||||
void SzFree(void *p, void *address) { p = p; free(address); }
|
||||
ISzAlloc alloc = { SzAlloc, SzFree };
|
||||
|
||||
You can use p = p; operator to disable compiler warnings.
|
||||
|
||||
|
||||
Single-call Decompressing
|
||||
-------------------------
|
||||
When to use: RAM->RAM decompressing
|
||||
Compile files: LzmaDec.h + LzmaDec.c + Types.h
|
||||
Compile defines: no defines
|
||||
Memory Requirements:
|
||||
- Input buffer: compressed size
|
||||
- Output buffer: uncompressed size
|
||||
- LZMA Internal Structures: state_size (16 KB for default settings)
|
||||
|
||||
Interface:
|
||||
int LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
|
||||
const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
|
||||
ELzmaStatus *status, ISzAlloc *alloc);
|
||||
In:
|
||||
dest - output data
|
||||
destLen - output data size
|
||||
src - input data
|
||||
srcLen - input data size
|
||||
propData - LZMA properties (5 bytes)
|
||||
propSize - size of propData buffer (5 bytes)
|
||||
finishMode - It has meaning only if the decoding reaches output limit (*destLen).
|
||||
LZMA_FINISH_ANY - Decode just destLen bytes.
|
||||
LZMA_FINISH_END - Stream must be finished after (*destLen).
|
||||
You can use LZMA_FINISH_END, when you know that
|
||||
current output buffer covers last bytes of stream.
|
||||
alloc - Memory allocator.
|
||||
|
||||
Out:
|
||||
destLen - processed output size
|
||||
srcLen - processed input size
|
||||
|
||||
Output:
|
||||
SZ_OK
|
||||
status:
|
||||
LZMA_STATUS_FINISHED_WITH_MARK
|
||||
LZMA_STATUS_NOT_FINISHED
|
||||
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
|
||||
SZ_ERROR_DATA - Data error
|
||||
SZ_ERROR_MEM - Memory allocation error
|
||||
SZ_ERROR_UNSUPPORTED - Unsupported properties
|
||||
SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
|
||||
|
||||
If LZMA decoder sees end_marker before reaching output limit, it returns OK result,
|
||||
and output value of destLen will be less than output buffer size limit.
|
||||
|
||||
You can use multiple checks to test data integrity after full decompression:
|
||||
1) Check Result and "status" variable.
|
||||
2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
|
||||
3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
|
||||
You must use correct finish mode in that case. */
|
||||
|
||||
|
||||
Multi-call State Decompressing (zlib-like interface)
|
||||
----------------------------------------------------
|
||||
|
||||
When to use: file->file decompressing
|
||||
Compile files: LzmaDec.h + LzmaDec.c + Types.h
|
||||
|
||||
Memory Requirements:
|
||||
- Buffer for input stream: any size (for example, 16 KB)
|
||||
- Buffer for output stream: any size (for example, 16 KB)
|
||||
- LZMA Internal Structures: state_size (16 KB for default settings)
|
||||
- LZMA dictionary (dictionary size is encoded in LZMA properties header)
|
||||
|
||||
1) read LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) to header:
|
||||
unsigned char header[LZMA_PROPS_SIZE + 8];
|
||||
ReadFile(inFile, header, sizeof(header)
|
||||
|
||||
2) Allocate CLzmaDec structures (state + dictionary) using LZMA properties
|
||||
|
||||
CLzmaDec state;
|
||||
LzmaDec_Constr(&state);
|
||||
res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc);
|
||||
if (res != SZ_OK)
|
||||
return res;
|
||||
|
||||
3) Init LzmaDec structure before any new LZMA stream. And call LzmaDec_DecodeToBuf in loop
|
||||
|
||||
LzmaDec_Init(&state);
|
||||
for (;;)
|
||||
{
|
||||
...
|
||||
int res = LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
|
||||
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode);
|
||||
...
|
||||
}
|
||||
|
||||
|
||||
4) Free all allocated structures
|
||||
LzmaDec_Free(&state, &g_Alloc);
|
||||
|
||||
For full code example, look at C/LzmaUtil/LzmaUtil.c code.
|
||||
|
||||
|
||||
How To compress data
|
||||
--------------------
|
||||
|
||||
Compile files: LzmaEnc.h + LzmaEnc.c + Types.h +
|
||||
LzFind.c + LzFind.h + LzFindMt.c + LzFindMt.h + LzHash.h
|
||||
|
||||
Memory Requirements:
|
||||
- (dictSize * 11.5 + 6 MB) + state_size
|
||||
|
||||
Lzma Encoder can use two memory allocators:
|
||||
1) alloc - for small arrays.
|
||||
2) allocBig - for big arrays.
|
||||
|
||||
For example, you can use Large RAM Pages (2 MB) in allocBig allocator for
|
||||
better compression speed. Note that Windows has bad implementation for
|
||||
Large RAM Pages.
|
||||
It's OK to use same allocator for alloc and allocBig.
|
||||
|
||||
|
||||
Single-call Compression with callbacks
|
||||
--------------------------------------
|
||||
|
||||
Check C/LzmaUtil/LzmaUtil.c as example,
|
||||
|
||||
When to use: file->file decompressing
|
||||
|
||||
1) you must implement callback structures for interfaces:
|
||||
ISeqInStream
|
||||
ISeqOutStream
|
||||
ICompressProgress
|
||||
ISzAlloc
|
||||
|
||||
static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
|
||||
static void SzFree(void *p, void *address) { p = p; MyFree(address); }
|
||||
static ISzAlloc g_Alloc = { SzAlloc, SzFree };
|
||||
|
||||
CFileSeqInStream inStream;
|
||||
CFileSeqOutStream outStream;
|
||||
|
||||
inStream.funcTable.Read = MyRead;
|
||||
inStream.file = inFile;
|
||||
outStream.funcTable.Write = MyWrite;
|
||||
outStream.file = outFile;
|
||||
|
||||
|
||||
2) Create CLzmaEncHandle object;
|
||||
|
||||
CLzmaEncHandle enc;
|
||||
|
||||
enc = LzmaEnc_Create(&g_Alloc);
|
||||
if (enc == 0)
|
||||
return SZ_ERROR_MEM;
|
||||
|
||||
|
||||
3) initialize CLzmaEncProps properties;
|
||||
|
||||
LzmaEncProps_Init(&props);
|
||||
|
||||
Then you can change some properties in that structure.
|
||||
|
||||
4) Send LZMA properties to LZMA Encoder
|
||||
|
||||
res = LzmaEnc_SetProps(enc, &props);
|
||||
|
||||
5) Write encoded properties to header
|
||||
|
||||
Byte header[LZMA_PROPS_SIZE + 8];
|
||||
size_t headerSize = LZMA_PROPS_SIZE;
|
||||
UInt64 fileSize;
|
||||
int i;
|
||||
|
||||
res = LzmaEnc_WriteProperties(enc, header, &headerSize);
|
||||
fileSize = MyGetFileLength(inFile);
|
||||
for (i = 0; i < 8; i++)
|
||||
header[headerSize++] = (Byte)(fileSize >> (8 * i));
|
||||
MyWriteFileAndCheck(outFile, header, headerSize)
|
||||
|
||||
6) Call encoding function:
|
||||
res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable,
|
||||
NULL, &g_Alloc, &g_Alloc);
|
||||
|
||||
7) Destroy LZMA Encoder Object
|
||||
LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);
|
||||
|
||||
|
||||
If callback function return some error code, LzmaEnc_Encode also returns that code.
|
||||
|
||||
|
||||
Single-call RAM->RAM Compression
|
||||
--------------------------------
|
||||
|
||||
Single-call RAM->RAM Compression is similar to Compression with callbacks,
|
||||
but you provide pointers to buffers instead of pointers to stream callbacks:
|
||||
|
||||
HRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
|
||||
CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
|
||||
ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
|
||||
|
||||
Return code:
|
||||
SZ_OK - OK
|
||||
SZ_ERROR_MEM - Memory allocation error
|
||||
SZ_ERROR_PARAM - Incorrect paramater
|
||||
SZ_ERROR_OUTPUT_EOF - output buffer overflow
|
||||
SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
|
||||
|
||||
|
||||
|
||||
LZMA Defines
|
||||
------------
|
||||
|
||||
_LZMA_SIZE_OPT - Enable some optimizations in LZMA Decoder to get smaller executable code.
|
||||
|
||||
_LZMA_PROB32 - It can increase the speed on some 32-bit CPUs, but memory usage for
|
||||
some structures will be doubled in that case.
|
||||
|
||||
_LZMA_UINT32_IS_ULONG - Define it if int is 16-bit on your compiler and long is 32-bit.
|
||||
|
||||
_LZMA_NO_SYSTEM_SIZE_T - Define it if you don't want to use size_t type.
|
||||
|
||||
|
||||
C++ LZMA Encoder/Decoder
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
C++ LZMA code use COM-like interfaces. So if you want to use it,
|
||||
you can study basics of COM/OLE.
|
||||
C++ LZMA code is just wrapper over ANSI-C code.
|
||||
|
||||
|
||||
C++ Notes
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
If you use some C++ code folders in 7-Zip (for example, C++ code for .7z handling),
|
||||
you must check that you correctly work with "new" operator.
|
||||
7-Zip can be compiled with MSVC 6.0 that doesn't throw "exception" from "new" operator.
|
||||
So 7-Zip uses "CPP\Common\NewHandler.cpp" that redefines "new" operator:
|
||||
operator new(size_t size)
|
||||
{
|
||||
void *p = ::malloc(size);
|
||||
if (p == 0)
|
||||
throw CNewException();
|
||||
return p;
|
||||
}
|
||||
If you use MSCV that throws exception for "new" operator, you can compile without
|
||||
"NewHandler.cpp". So standard exception will be used. Actually some code of
|
||||
7-Zip catches any exception in internal code and converts it to HRESULT code.
|
||||
So you don't need to catch CNewException, if you call COM interfaces of 7-Zip.
|
||||
|
||||
---
|
||||
|
||||
http://www.7-zip.org
|
||||
http://www.7-zip.org/sdk.html
|
||||
http://www.7-zip.org/support.html
|
|
@ -0,0 +1,47 @@
|
|||
/** @file
|
||||
LZMA UEFI header file
|
||||
|
||||
Allows LZMA code to build under UEFI (edk2) build environment
|
||||
|
||||
Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef __UEFILZMA_H__
|
||||
#define __UEFILZMA_H__
|
||||
|
||||
#include <Uefi.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#undef _WIN32
|
||||
#endif
|
||||
|
||||
#ifndef _SIZE_T_DEFINED
|
||||
#if !defined(_WIN64) || defined(__GNUC__)
|
||||
typedef unsigned int size_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN64
|
||||
#undef _WIN64
|
||||
#endif
|
||||
|
||||
#ifndef _PTRDIFF_T_DEFINED
|
||||
typedef int ptrdiff_t;
|
||||
#endif
|
||||
|
||||
#define memcpy CopyMem
|
||||
#define memmove CopyMem
|
||||
|
||||
#define _LZMA_SIZE_OPT
|
||||
|
||||
#endif // __UEFILZMA_H__
|
||||
|
|
@ -0,0 +1,461 @@
|
|||
/** @file
|
||||
Debug Library based on report status code library.
|
||||
|
||||
Note that if the debug message length is larger than the maximum allowable
|
||||
record length, then the debug message will be ignored directly.
|
||||
|
||||
Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include <PiPei.h>
|
||||
|
||||
#include <Guid/StatusCodeDataTypeId.h>
|
||||
#include <Guid/StatusCodeDataTypeDebug.h>
|
||||
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/ReportStatusCodeLib.h>
|
||||
#include <Library/PcdLib.h>
|
||||
#include <Library/DebugPrintErrorLevelLib.h>
|
||||
|
||||
/**
|
||||
Prints a debug message to the debug output device if the specified error level is enabled.
|
||||
|
||||
If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
|
||||
GetDebugPrintErrorLevel (), then print the message specified by Format and the
|
||||
associated variable argument list to the debug output device.
|
||||
|
||||
If Format is NULL, then ASSERT().
|
||||
|
||||
If the length of the message string specificed by Format is larger than the maximum allowable
|
||||
record length, then directly return and not print it.
|
||||
|
||||
@param ErrorLevel The error level of the debug message.
|
||||
@param Format Format string for the debug message to print.
|
||||
@param ... Variable argument list whose contents are accessed
|
||||
based on the format string specified by Format.
|
||||
|
||||
**/
|
||||
VOID
|
||||
EFIAPI
|
||||
DebugPrint (
|
||||
IN UINTN ErrorLevel,
|
||||
IN CONST CHAR8 *Format,
|
||||
...
|
||||
)
|
||||
{
|
||||
UINT64 Buffer[(EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof (UINT64)) + 1];
|
||||
EFI_DEBUG_INFO *DebugInfo;
|
||||
UINTN TotalSize;
|
||||
VA_LIST VaListMarker;
|
||||
BASE_LIST BaseListMarker;
|
||||
CHAR8 *FormatString;
|
||||
BOOLEAN Long;
|
||||
|
||||
//
|
||||
// If Format is NULL, then ASSERT().
|
||||
//
|
||||
ASSERT (Format != NULL);
|
||||
|
||||
//
|
||||
// Check driver Debug Level value and global debug level
|
||||
//
|
||||
if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Compute the total size of the record.
|
||||
// Note that the passing-in format string and variable parameters will be constructed to
|
||||
// the following layout:
|
||||
//
|
||||
// Buffer->|------------------------|
|
||||
// | Padding | 4 bytes
|
||||
// DebugInfo->|------------------------|
|
||||
// | EFI_DEBUG_INFO | sizeof(EFI_DEBUG_INFO)
|
||||
// BaseListMarker->|------------------------|
|
||||
// | ... |
|
||||
// | variable arguments | 12 * sizeof (UINT64)
|
||||
// | ... |
|
||||
// |------------------------|
|
||||
// | Format String |
|
||||
// |------------------------|<- (UINT8 *)Buffer + sizeof(Buffer)
|
||||
//
|
||||
TotalSize = 4 + sizeof (EFI_DEBUG_INFO) + 12 * sizeof (UINT64) + AsciiStrSize (Format);
|
||||
|
||||
//
|
||||
// If the TotalSize is larger than the maximum record size, then return
|
||||
//
|
||||
if (TotalSize > sizeof (Buffer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Fill in EFI_DEBUG_INFO
|
||||
//
|
||||
// Here we skip the first 4 bytes of Buffer, because we must ensure BaseListMarker is
|
||||
// 64-bit aligned, otherwise retrieving 64-bit parameter from BaseListMarker will cause
|
||||
// exception on IPF. Buffer starts at 64-bit aligned address, so skipping 4 types (sizeof(EFI_DEBUG_INFO))
|
||||
// just makes address of BaseListMarker, which follows DebugInfo, 64-bit aligned.
|
||||
//
|
||||
DebugInfo = (EFI_DEBUG_INFO *)(Buffer) + 1;
|
||||
DebugInfo->ErrorLevel = (UINT32)ErrorLevel;
|
||||
BaseListMarker = (BASE_LIST)(DebugInfo + 1);
|
||||
FormatString = (CHAR8 *)((UINT64 *)(DebugInfo + 1) + 12);
|
||||
|
||||
//
|
||||
// Copy the Format string into the record
|
||||
//
|
||||
AsciiStrCpy (FormatString, Format);
|
||||
|
||||
//
|
||||
// The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments
|
||||
// of format in DEBUG string, which is followed by the DEBUG format string.
|
||||
// Here we will process the variable arguments and pack them in this area.
|
||||
//
|
||||
VA_START (VaListMarker, Format);
|
||||
for (; *Format != '\0'; Format++) {
|
||||
//
|
||||
// Only format with prefix % is processed.
|
||||
//
|
||||
if (*Format != '%') {
|
||||
continue;
|
||||
}
|
||||
Long = FALSE;
|
||||
//
|
||||
// Parse Flags and Width
|
||||
//
|
||||
for (Format++; TRUE; Format++) {
|
||||
if (*Format == '.' || *Format == '-' || *Format == '+' || *Format == ' ') {
|
||||
//
|
||||
// These characters in format field are omitted.
|
||||
//
|
||||
continue;
|
||||
}
|
||||
if (*Format >= '0' && *Format <= '9') {
|
||||
//
|
||||
// These characters in format field are omitted.
|
||||
//
|
||||
continue;
|
||||
}
|
||||
if (*Format == 'L' || *Format == 'l') {
|
||||
//
|
||||
// 'L" or "l" in format field means the number being printed is a UINT64
|
||||
//
|
||||
Long = TRUE;
|
||||
continue;
|
||||
}
|
||||
if (*Format == '*') {
|
||||
//
|
||||
// '*' in format field means the precision of the field is specified by
|
||||
// a UINTN argument in the argument list.
|
||||
//
|
||||
BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);
|
||||
continue;
|
||||
}
|
||||
if (*Format == '\0') {
|
||||
//
|
||||
// Make no output if Format string terminates unexpectedly when
|
||||
// looking up for flag, width, precision and type.
|
||||
//
|
||||
Format--;
|
||||
}
|
||||
//
|
||||
// When valid argument type detected or format string terminates unexpectedly,
|
||||
// the inner loop is done.
|
||||
//
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Pack variable arguments into the storage area following EFI_DEBUG_INFO.
|
||||
//
|
||||
if ((*Format == 'p') && (sizeof (VOID *) > 4)) {
|
||||
Long = TRUE;
|
||||
}
|
||||
if (*Format == 'p' || *Format == 'X' || *Format == 'x' || *Format == 'd') {
|
||||
if (Long) {
|
||||
BASE_ARG (BaseListMarker, INT64) = VA_ARG (VaListMarker, INT64);
|
||||
} else {
|
||||
BASE_ARG (BaseListMarker, int) = VA_ARG (VaListMarker, int);
|
||||
}
|
||||
} else if (*Format == 's' || *Format == 'S' || *Format == 'a' || *Format == 'g' || *Format == 't') {
|
||||
BASE_ARG (BaseListMarker, VOID *) = VA_ARG (VaListMarker, VOID *);
|
||||
} else if (*Format == 'c') {
|
||||
BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);
|
||||
} else if (*Format == 'r') {
|
||||
BASE_ARG (BaseListMarker, RETURN_STATUS) = VA_ARG (VaListMarker, RETURN_STATUS);
|
||||
}
|
||||
|
||||
//
|
||||
// If the converted BASE_LIST is larger than the 12 * sizeof (UINT64) allocated bytes, then ASSERT()
|
||||
// This indicates that the DEBUG() macro is passing in more argument than can be handled by
|
||||
// the EFI_DEBUG_INFO record
|
||||
//
|
||||
ASSERT ((CHAR8 *)BaseListMarker <= FormatString);
|
||||
|
||||
//
|
||||
// If the converted BASE_LIST is larger than the 12 * sizeof (UINT64) allocated bytes, then return
|
||||
//
|
||||
if ((CHAR8 *)BaseListMarker > FormatString) {
|
||||
VA_END (VaListMarker);
|
||||
return;
|
||||
}
|
||||
}
|
||||
VA_END (VaListMarker);
|
||||
|
||||
//
|
||||
// Send the DebugInfo record
|
||||
//
|
||||
REPORT_STATUS_CODE_EX (
|
||||
EFI_DEBUG_CODE,
|
||||
(EFI_SOFTWARE_DXE_BS_DRIVER | EFI_DC_UNSPECIFIED),
|
||||
0,
|
||||
NULL,
|
||||
&gEfiStatusCodeDataTypeDebugGuid,
|
||||
DebugInfo,
|
||||
TotalSize
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
Prints an assert message containing a filename, line number, and description.
|
||||
This may be followed by a breakpoint or a dead loop.
|
||||
|
||||
Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
|
||||
to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
|
||||
PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
|
||||
DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
|
||||
CpuDeadLoop() is called. If neither of these bits are set, then this function
|
||||
returns immediately after the message is printed to the debug output device.
|
||||
DebugAssert() must actively prevent recursion. If DebugAssert() is called while
|
||||
processing another DebugAssert(), then DebugAssert() must return immediately.
|
||||
|
||||
If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
|
||||
If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
|
||||
|
||||
@param FileName Pointer to the name of the source file that generated the assert condition.
|
||||
@param LineNumber The line number in the source file that generated the assert condition
|
||||
@param Description Pointer to the description of the assert condition.
|
||||
|
||||
**/
|
||||
VOID
|
||||
EFIAPI
|
||||
DebugAssert (
|
||||
IN CONST CHAR8 *FileName,
|
||||
IN UINTN LineNumber,
|
||||
IN CONST CHAR8 *Description
|
||||
)
|
||||
{
|
||||
UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof(UINT64)];
|
||||
EFI_DEBUG_ASSERT_DATA *AssertData;
|
||||
UINTN HeaderSize;
|
||||
UINTN TotalSize;
|
||||
CHAR8 *Temp;
|
||||
UINTN FileNameSize;
|
||||
UINTN DescriptionSize;
|
||||
|
||||
//
|
||||
// Get string size
|
||||
//
|
||||
HeaderSize = sizeof (EFI_DEBUG_ASSERT_DATA);
|
||||
FileNameSize = AsciiStrSize (FileName);
|
||||
DescriptionSize = AsciiStrSize (Description);
|
||||
|
||||
//
|
||||
// Make sure it will all fit in the passed in buffer.
|
||||
//
|
||||
if (HeaderSize + FileNameSize + DescriptionSize > sizeof (Buffer)) {
|
||||
//
|
||||
// FileName + Description is too long to be filled into buffer.
|
||||
//
|
||||
if (HeaderSize + FileNameSize < sizeof (Buffer)) {
|
||||
//
|
||||
// Description has enough buffer to be truncated.
|
||||
//
|
||||
DescriptionSize = sizeof (Buffer) - HeaderSize - FileNameSize;
|
||||
} else {
|
||||
//
|
||||
// FileName is too long to be filled into buffer.
|
||||
// FileName will be truncated. Reserved one byte for Description NULL terminator.
|
||||
//
|
||||
DescriptionSize = 1;
|
||||
FileNameSize = sizeof (Buffer) - HeaderSize - DescriptionSize;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Fill in EFI_DEBUG_ASSERT_DATA
|
||||
//
|
||||
AssertData = (EFI_DEBUG_ASSERT_DATA *)Buffer;
|
||||
AssertData->LineNumber = (UINT32)LineNumber;
|
||||
TotalSize = sizeof (EFI_DEBUG_ASSERT_DATA);
|
||||
|
||||
//
|
||||
// Copy Ascii FileName including NULL terminator.
|
||||
//
|
||||
Temp = CopyMem (AssertData + 1, FileName, FileNameSize);
|
||||
Temp[FileNameSize - 1] = 0;
|
||||
TotalSize += FileNameSize;
|
||||
|
||||
//
|
||||
// Copy Ascii Description include NULL terminator.
|
||||
//
|
||||
Temp = CopyMem (Temp + FileNameSize, Description, DescriptionSize);
|
||||
Temp[DescriptionSize - 1] = 0;
|
||||
TotalSize += DescriptionSize;
|
||||
|
||||
REPORT_STATUS_CODE_EX (
|
||||
(EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED),
|
||||
(EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE),
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
AssertData,
|
||||
TotalSize
|
||||
);
|
||||
|
||||
//
|
||||
// Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
|
||||
//
|
||||
if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {
|
||||
CpuBreakpoint ();
|
||||
} else if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {
|
||||
CpuDeadLoop ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
|
||||
|
||||
This function fills Length bytes of Buffer with the value specified by
|
||||
PcdDebugClearMemoryValue, and returns Buffer.
|
||||
|
||||
If Buffer is NULL, then ASSERT().
|
||||
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
|
||||
|
||||
@param Buffer Pointer to the target buffer to be filled with PcdDebugClearMemoryValue.
|
||||
@param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
|
||||
|
||||
@return Buffer Pointer to the target buffer filled with PcdDebugClearMemoryValue.
|
||||
|
||||
**/
|
||||
VOID *
|
||||
EFIAPI
|
||||
DebugClearMemory (
|
||||
OUT VOID *Buffer,
|
||||
IN UINTN Length
|
||||
)
|
||||
{
|
||||
ASSERT (Buffer != NULL);
|
||||
|
||||
return SetMem (Buffer, Length, PcdGet8 (PcdDebugClearMemoryValue));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Returns TRUE if ASSERT() macros are enabled.
|
||||
|
||||
This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
|
||||
PcdDebugProperyMask is set. Otherwise FALSE is returned.
|
||||
|
||||
@retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
|
||||
@retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
DebugAssertEnabled (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Returns TRUE if DEBUG() macros are enabled.
|
||||
|
||||
This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
|
||||
PcdDebugProperyMask is set. Otherwise FALSE is returned.
|
||||
|
||||
@retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
|
||||
@retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
DebugPrintEnabled (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Returns TRUE if DEBUG_CODE() macros are enabled.
|
||||
|
||||
This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
|
||||
PcdDebugProperyMask is set. Otherwise FALSE is returned.
|
||||
|
||||
@retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
|
||||
@retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
DebugCodeEnabled (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.
|
||||
|
||||
This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of
|
||||
PcdDebugProperyMask is set. Otherwise FALSE is returned.
|
||||
|
||||
@retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
|
||||
@retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
DebugClearMemoryEnabled (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.
|
||||
|
||||
This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.
|
||||
|
||||
@retval TRUE Current ErrorLevel is supported.
|
||||
@retval FALSE Current ErrorLevel is not supported.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
DebugPrintLevelEnabled (
|
||||
IN CONST UINTN ErrorLevel
|
||||
)
|
||||
{
|
||||
return (BOOLEAN) ((ErrorLevel & PcdGet32(PcdFixedDebugPrintErrorLevel)) != 0);
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
## @file
|
||||
# Debug Library based on report status code library
|
||||
#
|
||||
# Debug Library for PEIMs and DXE drivers that sends debug messages to ReportStatusCode
|
||||
# Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
BASE_NAME = PeiDxeDebugLibReportStatusCode
|
||||
MODULE_UNI_FILE = PeiDxeDebugLibReportStatusCode.uni
|
||||
FILE_GUID = bda39d3a-451b-4350-8266-81ab10fa0523
|
||||
MODULE_TYPE = PEIM
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = DebugLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER SMM_CORE PEIM SEC PEI_CORE UEFI_APPLICATION UEFI_DRIVER
|
||||
|
||||
#
|
||||
# The following information is for reference only and not required by the build tools.
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
|
||||
#
|
||||
|
||||
[Sources]
|
||||
DebugLib.c
|
||||
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
PcdLib
|
||||
ReportStatusCodeLib
|
||||
BaseMemoryLib
|
||||
BaseLib
|
||||
DebugPrintErrorLevelLib
|
||||
|
||||
[Pcd]
|
||||
gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue ## SOMETIMES_CONSUMES
|
||||
gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask ## CONSUMES
|
||||
gEfiMdePkgTokenSpaceGuid.PcdFixedDebugPrintErrorLevel ## CONSUMES
|
||||
|
||||
[Guids]
|
||||
gEfiStatusCodeDataTypeDebugGuid ## SOMETIMES_CONSUMES ## GUID
|
||||
|
Binary file not shown.
|
@ -261,6 +261,8 @@
|
|||
MdeModulePkg/Library/PeiDebugPrintHobLib/PeiDebugPrintHobLib.inf
|
||||
MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLibNull.inf
|
||||
MdeModulePkg/Library/PlatformHookLibSerialPortPpi/PlatformHookLibSerialPortPpi.inf
|
||||
MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
|
||||
MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf
|
||||
|
||||
MdeModulePkg/Universal/CapsulePei/CapsulePei.inf
|
||||
MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
|
||||
|
@ -365,6 +367,7 @@
|
|||
MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf
|
||||
MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
|
||||
MdeModulePkg/Library/SmmCorePlatformHookLibNull/SmmCorePlatformHookLibNull.inf
|
||||
MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaArchCustomDecompressLib.inf
|
||||
MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
|
||||
MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf
|
||||
MdeModulePkg/Universal/Acpi/SmmS3SaveState/SmmS3SaveState.inf
|
||||
|
|
Loading…
Reference in New Issue