]> git.proxmox.com Git - mirror_edk2.git/commitdiff
IntelFrameworkModulePkg LzmaDecompressLib: Update LZMA to new 16.04 version
authorLiming Gao <liming.gao@intel.com>
Thu, 27 Oct 2016 06:54:27 +0000 (14:54 +0800)
committerLiming Gao <liming.gao@intel.com>
Thu, 3 Nov 2016 02:21:22 +0000 (10:21 +0800)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
21 files changed:
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LZMA-SDK-README.txt
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaArchCustomDecompressLib.inf
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/7zTypes.h [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/7zVersion.h
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Bra.h
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Bra86.c
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Compiler.h [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/CpuArch.h
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzFind.c
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzFind.h
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzHash.h
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzmaDec.c
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzmaDec.h
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Precomp.h [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Types.h [deleted file]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/DOC/lzma-history.txt [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/DOC/lzma-sdk.txt [new file with mode: 0644]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/history.txt [deleted file]
IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/lzma.txt [deleted file]

index e05b3bb85357900cc45cf767a00ea4dfea4a1824..7a6a77f952ac25a44d2dcfc9b12989d8a057153d 100644 (file)
@@ -1,4 +1,4 @@
-LzmaCustomDecompressLib is based on the LZMA SDK 4.65.\r
-LZMA SDK 4.65 was placed in the public domain on\r
-2009-02-03.  It was released on the\r
+LzmaCustomDecompressLib is based on the LZMA SDK 16.04.\r
+LZMA SDK 16.04 was placed in the public domain on\r
+2016-10-04.  It was released on the\r
 http://www.7-zip.org/sdk.html website.
\ No newline at end of file
index ec7585d55b20fd7c4d6fdfcf6837a50d344983f1..ccd620b280343b77da4e7511bd72810630b7a43e 100644 (file)
@@ -1,11 +1,11 @@
 ## @file\r
 #  LzmaArchCustomDecompressLib produces LZMA custom decompression algorithm with the converter for the different arch code.\r
 #\r
-#  It is based on the LZMA SDK 4.65.\r
-#  LZMA SDK 4.65 was placed in the public domain on 2009-02-03.\r
+#  It is based on the LZMA SDK 16.04\r
+#  LZMA SDK 16.04 was placed in the public domain on 2016-10-04.\r
 #  It was released on the http://www.7-zip.org/sdk.html website.\r
 #\r
-#  Copyright (c) 2012 - 2015, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -43,7 +43,9 @@
   Sdk/C/LzFind.h\r
   Sdk/C/LzHash.h\r
   Sdk/C/LzmaDec.h\r
-  Sdk/C/Types.h  \r
+  Sdk/C/7zTypes.h\r
+  Sdk/C/Precomp.h\r
+  Sdk/C/Compiler.h\r
   UefiLzma.h\r
   LzmaDecompressLibInternal.h\r
 \r
index f5624fd039223b3648d8518c21e2ede7790e1062..127c7ded86f684eb8568ac223ae80764cc257ab5 100644 (file)
@@ -1,11 +1,11 @@
 ## @file\r
 #  LzmaCustomDecompressLib produces LZMA custom decompression algorithm.\r
 #\r
-#  It is based on the LZMA SDK 4.65.\r
-#  LZMA SDK 4.65 was placed in the public domain on 2009-02-03.\r
+#  It is based on the LZMA SDK 16.04.\r
+#  LZMA SDK 16.04 was placed in the public domain on 2016-10-04.\r
 #  It was released on the http://www.7-zip.org/sdk.html website.\r
 #\r
-#  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -42,7 +42,9 @@
   Sdk/C/LzFind.h\r
   Sdk/C/LzHash.h\r
   Sdk/C/LzmaDec.h\r
-  Sdk/C/Types.h  \r
+  Sdk/C/7zTypes.h\r
+  Sdk/C/Precomp.h\r
+  Sdk/C/Compiler.h\r
   GuidedSectionExtraction.c\r
   UefiLzma.h\r
   LzmaDecompressLibInternal.h\r
index e32b6a3025b07f39a485e62dfc8917293ab4e6e5..cdf4c08cab37f74007ab7bf8cb7c39ab26ac9bb9 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   LZMA Decompress interfaces\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -13,7 +13,7 @@
 **/\r
 \r
 #include "LzmaDecompressLibInternal.h"\r
-#include "Sdk/C/Types.h"\r
+#include "Sdk/C/7zTypes.h"\r
 #include "Sdk/C/7zVersion.h"\r
 #include "Sdk/C/LzmaDec.h"\r
 \r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/7zTypes.h b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/7zTypes.h
new file mode 100644 (file)
index 0000000..838dac7
--- /dev/null
@@ -0,0 +1,260 @@
+/* 7zTypes.h -- Basic types\r
+2013-11-12 : Igor Pavlov : Public domain */\r
+\r
+#ifndef __7Z_TYPES_H\r
+#define __7Z_TYPES_H\r
+\r
+#ifdef _WIN32\r
+/* #include <windows.h> */\r
+#endif\r
+\r
+#ifdef EFIAPI\r
+#include "UefiLzma.h"\r
+#else\r
+#include <stddef.h>\r
+#endif\r
+\r
+#ifndef EXTERN_C_BEGIN\r
+#ifdef __cplusplus\r
+#define EXTERN_C_BEGIN extern "C" {\r
+#define EXTERN_C_END }\r
+#else\r
+#define EXTERN_C_BEGIN\r
+#define EXTERN_C_END\r
+#endif\r
+#endif\r
+\r
+EXTERN_C_BEGIN\r
+\r
+#define SZ_OK 0\r
+\r
+#define SZ_ERROR_DATA 1\r
+#define SZ_ERROR_MEM 2\r
+#define SZ_ERROR_CRC 3\r
+#define SZ_ERROR_UNSUPPORTED 4\r
+#define SZ_ERROR_PARAM 5\r
+#define SZ_ERROR_INPUT_EOF 6\r
+#define SZ_ERROR_OUTPUT_EOF 7\r
+#define SZ_ERROR_READ 8\r
+#define SZ_ERROR_WRITE 9\r
+#define SZ_ERROR_PROGRESS 10\r
+#define SZ_ERROR_FAIL 11\r
+#define SZ_ERROR_THREAD 12\r
+\r
+#define SZ_ERROR_ARCHIVE 16\r
+#define SZ_ERROR_NO_ARCHIVE 17\r
+\r
+typedef int SRes;\r
+\r
+#ifdef _WIN32\r
+/* typedef DWORD WRes; */\r
+typedef unsigned WRes;\r
+#else\r
+typedef int WRes;\r
+#endif\r
+\r
+#ifndef RINOK\r
+#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }\r
+#endif\r
+\r
+typedef unsigned char Byte;\r
+typedef short Int16;\r
+typedef unsigned short UInt16;\r
+\r
+#ifdef _LZMA_UINT32_IS_ULONG\r
+typedef long Int32;\r
+typedef unsigned long UInt32;\r
+#else\r
+typedef int Int32;\r
+typedef unsigned int UInt32;\r
+#endif\r
+\r
+#ifdef _SZ_NO_INT_64\r
+\r
+/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.\r
+   NOTES: Some code will work incorrectly in that case! */\r
+\r
+typedef long Int64;\r
+typedef unsigned long UInt64;\r
+\r
+#else\r
+\r
+#if defined(_MSC_VER) || defined(__BORLANDC__)\r
+typedef __int64 Int64;\r
+typedef unsigned __int64 UInt64;\r
+#define UINT64_CONST(n) n\r
+#else\r
+typedef long long int Int64;\r
+typedef unsigned long long int UInt64;\r
+#define UINT64_CONST(n) n ## ULL\r
+#endif\r
+\r
+#endif\r
+\r
+#ifdef _LZMA_NO_SYSTEM_SIZE_T\r
+typedef UInt32 SizeT;\r
+#else\r
+typedef size_t SizeT;\r
+#endif\r
+\r
+typedef int Bool;\r
+#define True 1\r
+#define False 0\r
+\r
+\r
+#ifdef _WIN32\r
+#define MY_STD_CALL __stdcall\r
+#else\r
+#define MY_STD_CALL\r
+#endif\r
+\r
+#ifdef _MSC_VER\r
+\r
+#if _MSC_VER >= 1300\r
+#define MY_NO_INLINE __declspec(noinline)\r
+#else\r
+#define MY_NO_INLINE\r
+#endif\r
+\r
+#define MY_CDECL __cdecl\r
+#define MY_FAST_CALL __fastcall\r
+\r
+#else\r
+\r
+#define MY_NO_INLINE\r
+#define MY_CDECL\r
+#define MY_FAST_CALL\r
+\r
+#endif\r
+\r
+\r
+/* The following interfaces use first parameter as pointer to structure */\r
+\r
+typedef struct\r
+{\r
+  Byte (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */\r
+} IByteIn;\r
+\r
+typedef struct\r
+{\r
+  void (*Write)(void *p, Byte b);\r
+} IByteOut;\r
+\r
+typedef struct\r
+{\r
+  SRes (*Read)(void *p, void *buf, size_t *size);\r
+    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r
+       (output(*size) < input(*size)) is allowed */\r
+} ISeqInStream;\r
+\r
+/* it can return SZ_ERROR_INPUT_EOF */\r
+SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);\r
+SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);\r
+SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);\r
+\r
+typedef struct\r
+{\r
+  size_t (*Write)(void *p, const void *buf, size_t size);\r
+    /* Returns: result - the number of actually written bytes.\r
+       (result < size) means error */\r
+} ISeqOutStream;\r
+\r
+typedef enum\r
+{\r
+  SZ_SEEK_SET = 0,\r
+  SZ_SEEK_CUR = 1,\r
+  SZ_SEEK_END = 2\r
+} ESzSeek;\r
+\r
+typedef struct\r
+{\r
+  SRes (*Read)(void *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */\r
+  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r
+} ISeekInStream;\r
+\r
+typedef struct\r
+{\r
+  SRes (*Look)(void *p, const void **buf, size_t *size);\r
+    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r
+       (output(*size) > input(*size)) is not allowed\r
+       (output(*size) < input(*size)) is allowed */\r
+  SRes (*Skip)(void *p, size_t offset);\r
+    /* offset must be <= output(*size) of Look */\r
+\r
+  SRes (*Read)(void *p, void *buf, size_t *size);\r
+    /* reads directly (without buffer). It's same as ISeqInStream::Read */\r
+  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r
+} ILookInStream;\r
+\r
+SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);\r
+SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);\r
+\r
+/* reads via ILookInStream::Read */\r
+SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);\r
+SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);\r
+\r
+#define LookToRead_BUF_SIZE (1 << 14)\r
+\r
+typedef struct\r
+{\r
+  ILookInStream s;\r
+  ISeekInStream *realStream;\r
+  size_t pos;\r
+  size_t size;\r
+  Byte buf[LookToRead_BUF_SIZE];\r
+} CLookToRead;\r
+\r
+void LookToRead_CreateVTable(CLookToRead *p, int lookahead);\r
+void LookToRead_Init(CLookToRead *p);\r
+\r
+typedef struct\r
+{\r
+  ISeqInStream s;\r
+  ILookInStream *realStream;\r
+} CSecToLook;\r
+\r
+void SecToLook_CreateVTable(CSecToLook *p);\r
+\r
+typedef struct\r
+{\r
+  ISeqInStream s;\r
+  ILookInStream *realStream;\r
+} CSecToRead;\r
+\r
+void SecToRead_CreateVTable(CSecToRead *p);\r
+\r
+typedef struct\r
+{\r
+  SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);\r
+    /* Returns: result. (result != SZ_OK) means break.\r
+       Value (UInt64)(Int64)-1 for size means unknown value. */\r
+} ICompressProgress;\r
+\r
+typedef struct\r
+{\r
+  void *(*Alloc)(void *p, size_t size);\r
+  void (*Free)(void *p, void *address); /* address can be 0 */\r
+} ISzAlloc;\r
+\r
+#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)\r
+#define IAlloc_Free(p, a) (p)->Free((p), a)\r
+\r
+#ifdef _WIN32\r
+\r
+#define CHAR_PATH_SEPARATOR '\\'\r
+#define WCHAR_PATH_SEPARATOR L'\\'\r
+#define STRING_PATH_SEPARATOR "\\"\r
+#define WSTRING_PATH_SEPARATOR L"\\"\r
+\r
+#else\r
+\r
+#define CHAR_PATH_SEPARATOR '/'\r
+#define WCHAR_PATH_SEPARATOR L'/'\r
+#define STRING_PATH_SEPARATOR "/"\r
+#define WSTRING_PATH_SEPARATOR L"/"\r
+\r
+#endif\r
+\r
+EXTERN_C_END\r
+\r
+#endif\r
index 5a6bcadac6784ab39bd6730f74e1985b1ec3c3fd..acb67a94e5db1f9bbb1bf37f3c3e8a765176ee6c 100644 (file)
@@ -1,7 +1,19 @@
-#define MY_VER_MAJOR 4\r
-#define MY_VER_MINOR 65\r
+#define MY_VER_MAJOR 16\r
+#define MY_VER_MINOR 04\r
 #define MY_VER_BUILD 0\r
-#define MY_VERSION "4.65"\r
-#define MY_DATE "2009-02-03"\r
-#define MY_COPYRIGHT ": Igor Pavlov : Public domain"\r
-#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " : " MY_DATE\r
+#define MY_VERSION_NUMBERS "16.04"\r
+#define MY_VERSION "16.04"\r
+#define MY_DATE "2016-10-04"\r
+#undef MY_COPYRIGHT\r
+#undef MY_VERSION_COPYRIGHT_DATE\r
+#define MY_AUTHOR_NAME "Igor Pavlov"\r
+#define MY_COPYRIGHT_PD "Igor Pavlov : Public domain"\r
+#define MY_COPYRIGHT_CR "Copyright (c) 1999-2016 Igor Pavlov"\r
+\r
+#ifdef USE_COPYRIGHT_CR\r
+  #define MY_COPYRIGHT MY_COPYRIGHT_CR\r
+#else\r
+  #define MY_COPYRIGHT MY_COPYRIGHT_PD\r
+#endif\r
+\r
+#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " : " MY_COPYRIGHT " : " MY_DATE\r
index b9018eb991f5712d917b8e11b3f2b3a2fe36b4a5..aba8dce14f19cf33840b18d92a376789d920360d 100644 (file)
@@ -1,10 +1,12 @@
 /* Bra.h -- Branch converters for executables\r
-2008-10-04 : Igor Pavlov : Public domain */\r
+2013-01-18 : Igor Pavlov : Public domain */\r
 \r
 #ifndef __BRA_H\r
 #define __BRA_H\r
 \r
-#include "Types.h"\r
+#include "7zTypes.h"\r
+\r
+EXTERN_C_BEGIN\r
 \r
 /*\r
 These functions convert relative addresses to absolute addresses\r
@@ -57,4 +59,6 @@ SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
 SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r
 SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r
 \r
+EXTERN_C_END\r
+\r
 #endif\r
index 93566cb212043d435b367b250e41ba39292a2255..8dd3ed48d9aba8788489a5ba4ec3fb102694a4b7 100644 (file)
@@ -1,85 +1,82 @@
 /* Bra86.c -- Converter for x86 code (BCJ)\r
-2008-10-04 : Igor Pavlov : Public domain */\r
+2013-11-12 : Igor Pavlov : Public domain */\r
 \r
-#include "Bra.h"\r
+#include "Precomp.h"\r
 \r
-#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)\r
+#include "Bra.h"\r
 \r
-const Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};\r
-const Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};\r
+#define Test86MSByte(b) ((((b) + 1) & 0xFE) == 0)\r
 \r
 SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)\r
 {\r
-  SizeT bufferPos = 0, prevPosT;\r
-  UInt32 prevMask = *state & 0x7;\r
+  SizeT pos = 0;\r
+  UInt32 mask = *state & 7;\r
   if (size < 5)\r
     return 0;\r
+  size -= 4;\r
   ip += 5;\r
-  prevPosT = (SizeT)0 - 1;\r
 \r
   for (;;)\r
   {\r
-    Byte *p = data + bufferPos;\r
-    Byte *limit = data + size - 4;\r
+    Byte *p = data + pos;\r
+    const Byte *limit = data + size;\r
     for (; p < limit; p++)\r
       if ((*p & 0xFE) == 0xE8)\r
         break;\r
-    bufferPos = (SizeT)(p - data);\r
-    if (p >= limit)\r
-      break;\r
-    prevPosT = bufferPos - prevPosT;\r
-    if (prevPosT > 3)\r
-      prevMask = 0;\r
-    else\r
+\r
     {\r
-      prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7;\r
-      if (prevMask != 0)\r
+      SizeT d = (SizeT)(p - data - pos);\r
+      pos = (SizeT)(p - data);\r
+      if (p >= limit)\r
       {\r
-        Byte b = p[4 - kMaskToBitNumber[prevMask]];\r
-        if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b))\r
+        *state = (d > 2 ? 0 : mask >> (unsigned)d);\r
+        return pos;\r
+      }\r
+      if (d > 2)\r
+        mask = 0;\r
+      else\r
+      {\r
+        mask >>= (unsigned)d;\r
+        if (mask != 0 && (mask > 4 || mask == 3 || Test86MSByte(p[(mask >> 1) + 1])))\r
         {\r
-          prevPosT = bufferPos;\r
-          prevMask = ((prevMask << 1) & 0x7) | 1;\r
-          bufferPos++;\r
+          mask = (mask >> 1) | 4;\r
+          pos++;\r
           continue;\r
         }\r
       }\r
     }\r
-    prevPosT = bufferPos;\r
 \r
     if (Test86MSByte(p[4]))\r
     {\r
-      UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);\r
-      UInt32 dest;\r
-      for (;;)\r
+      UInt32 v = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);\r
+      UInt32 cur = ip + (UInt32)pos;\r
+      pos += 5;\r
+      if (encoding)\r
+        v += cur;\r
+      else\r
+        v -= cur;\r
+      if (mask != 0)\r
       {\r
-        Byte b;\r
-        int index;\r
-        if (encoding)\r
-          dest = (ip + (UInt32)bufferPos) + src;\r
-        else\r
-          dest = src - (ip + (UInt32)bufferPos);\r
-        if (prevMask == 0)\r
-          break;\r
-        index = kMaskToBitNumber[prevMask] * 8;\r
-        b = (Byte)(dest >> (24 - index));\r
-        if (!Test86MSByte(b))\r
-          break;\r
-        src = dest ^ ((1 << (32 - index)) - 1);\r
+        unsigned sh = (mask & 6) << 2;\r
+        if (Test86MSByte((Byte)(v >> sh)))\r
+        {\r
+          v ^= (((UInt32)0x100 << sh) - 1);\r
+          if (encoding)\r
+            v += cur;\r
+          else\r
+            v -= cur;\r
+        }\r
+        mask = 0;\r
       }\r
-      p[4] = (Byte)(~(((dest >> 24) & 1) - 1));\r
-      p[3] = (Byte)(dest >> 16);\r
-      p[2] = (Byte)(dest >> 8);\r
-      p[1] = (Byte)dest;\r
-      bufferPos += 5;\r
+      p[1] = (Byte)v;\r
+      p[2] = (Byte)(v >> 8);\r
+      p[3] = (Byte)(v >> 16);\r
+      p[4] = (Byte)(0 - ((v >> 24) & 1));\r
     }\r
     else\r
     {\r
-      prevMask = ((prevMask << 1) & 0x7) | 1;\r
-      bufferPos++;\r
+      mask = (mask >> 1) | 4;\r
+      pos++;\r
     }\r
   }\r
-  prevPosT = bufferPos - prevPosT;\r
-  *state = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));\r
-  return bufferPos;\r
 }\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Compiler.h b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Compiler.h
new file mode 100644 (file)
index 0000000..de8fab3
--- /dev/null
@@ -0,0 +1,32 @@
+/* Compiler.h\r
+2015-08-02 : Igor Pavlov : Public domain */\r
+\r
+#ifndef __7Z_COMPILER_H\r
+#define __7Z_COMPILER_H\r
+\r
+#ifdef _MSC_VER\r
+\r
+  #ifdef UNDER_CE\r
+    #define RPC_NO_WINDOWS_H\r
+    /* #pragma warning(disable : 4115) // '_RPC_ASYNC_STATE' : named type definition in parentheses */\r
+    #pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union\r
+    #pragma warning(disable : 4214) // nonstandard extension used : bit field types other than int\r
+  #endif\r
+\r
+  #if _MSC_VER >= 1300\r
+    #pragma warning(disable : 4996) // This function or variable may be unsafe\r
+  #else\r
+    #pragma warning(disable : 4511) // copy constructor could not be generated\r
+    #pragma warning(disable : 4512) // assignment operator could not be generated\r
+    #pragma warning(disable : 4514) // unreferenced inline function has been removed\r
+    #pragma warning(disable : 4702) // unreachable code\r
+    #pragma warning(disable : 4710) // not inlined\r
+    #pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information\r
+  #endif\r
+\r
+#endif\r
+\r
+#define UNUSED_VAR(x) (void)x;\r
+/* #define UNUSED_VAR(x) x=x; */\r
+\r
+#endif\r
index 006361f2f2de769f2731f9e3840f1dbf7906946f..ef6083c3b8ba468bb4c793c774c28c2fea757a90 100644 (file)
-/* CpuArch.h\r
-2008-08-05\r
-Igor Pavlov\r
-Public domain */\r
+/* CpuArch.h -- CPU specific code\r
+2016-06-09: Igor Pavlov : Public domain */\r
 \r
-#ifndef __CPUARCH_H\r
-#define __CPUARCH_H\r
+#ifndef __CPU_ARCH_H\r
+#define __CPU_ARCH_H\r
+\r
+#include "7zTypes.h"\r
+\r
+EXTERN_C_BEGIN\r
 \r
 /*\r
-LITTLE_ENDIAN_UNALIGN means:\r
-  1) CPU is LITTLE_ENDIAN\r
-  2) it's allowed to make unaligned memory accesses\r
-if LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know\r
-about these properties of platform.\r
+MY_CPU_LE means that CPU is LITTLE ENDIAN.\r
+MY_CPU_BE means that CPU is BIG ENDIAN.\r
+If MY_CPU_LE and MY_CPU_BE are not defined, we don't know about ENDIANNESS of platform.\r
+\r
+MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned memory accesses.\r
 */\r
 \r
-#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)\r
-#define LITTLE_ENDIAN_UNALIGN\r
+#if defined(_M_X64) \\r
+   || defined(_M_AMD64) \\r
+   || defined(__x86_64__) \\r
+   || defined(__AMD64__) \\r
+   || defined(__amd64__)\r
+  #define MY_CPU_AMD64\r
+#endif\r
+\r
+#if defined(MY_CPU_AMD64) \\r
+    || defined(_M_IA64) \\r
+    || defined(__AARCH64EL__) \\r
+    || defined(__AARCH64EB__)\r
+  #define MY_CPU_64BIT\r
+#endif\r
+\r
+#if defined(_M_IX86) || defined(__i386__)\r
+#define MY_CPU_X86\r
+#endif\r
+\r
+#if defined(MY_CPU_X86) || defined(MY_CPU_AMD64)\r
+#define MY_CPU_X86_OR_AMD64\r
+#endif\r
+\r
+#if defined(MY_CPU_X86) \\r
+    || defined(_M_ARM) \\r
+    || defined(__ARMEL__) \\r
+    || defined(__THUMBEL__) \\r
+    || defined(__ARMEB__) \\r
+    || defined(__THUMBEB__)\r
+  #define MY_CPU_32BIT\r
+#endif\r
+\r
+#if defined(_WIN32) && defined(_M_ARM)\r
+#define MY_CPU_ARM_LE\r
 #endif\r
 \r
-#ifdef LITTLE_ENDIAN_UNALIGN\r
+#if defined(_WIN32) && defined(_M_IA64)\r
+#define MY_CPU_IA64_LE\r
+#endif\r
+\r
+#if defined(MY_CPU_X86_OR_AMD64) \\r
+    || defined(MY_CPU_ARM_LE) \\r
+    || defined(MY_CPU_IA64_LE) \\r
+    || defined(__LITTLE_ENDIAN__) \\r
+    || defined(__ARMEL__) \\r
+    || defined(__THUMBEL__) \\r
+    || defined(__AARCH64EL__) \\r
+    || defined(__MIPSEL__) \\r
+    || defined(__MIPSEL) \\r
+    || defined(_MIPSEL) \\r
+    || defined(__BFIN__) \\r
+    || (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))\r
+  #define MY_CPU_LE\r
+#endif\r
+\r
+#if defined(__BIG_ENDIAN__) \\r
+    || defined(__ARMEB__) \\r
+    || defined(__THUMBEB__) \\r
+    || defined(__AARCH64EB__) \\r
+    || defined(__MIPSEB__) \\r
+    || defined(__MIPSEB) \\r
+    || defined(_MIPSEB) \\r
+    || defined(__m68k__) \\r
+    || defined(__s390__) \\r
+    || defined(__s390x__) \\r
+    || defined(__zarch__) \\r
+    || (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))\r
+  #define MY_CPU_BE\r
+#endif\r
+\r
+#if defined(MY_CPU_LE) && defined(MY_CPU_BE)\r
+Stop_Compiling_Bad_Endian\r
+#endif\r
+\r
+\r
+#ifdef MY_CPU_LE\r
+  #if defined(MY_CPU_X86_OR_AMD64) \\r
+      /* || defined(__AARCH64EL__) */\r
+    #define MY_CPU_LE_UNALIGN\r
+  #endif\r
+#endif\r
+\r
+\r
+#ifdef MY_CPU_LE_UNALIGN\r
 \r
-#define GetUi16(p) (*(const UInt16 *)(p))\r
-#define GetUi32(p) (*(const UInt32 *)(p))\r
-#define GetUi64(p) (*(const UInt64 *)(p))\r
-#define SetUi32(p, d) *(UInt32 *)(p) = (d);\r
+#define GetUi16(p) (*(const UInt16 *)(const void *)(p))\r
+#define GetUi32(p) (*(const UInt32 *)(const void *)(p))\r
+#define GetUi64(p) (*(const UInt64 *)(const void *)(p))\r
+\r
+#define SetUi16(p, v) { *(UInt16 *)(p) = (v); }\r
+#define SetUi32(p, v) { *(UInt32 *)(p) = (v); }\r
+#define SetUi64(p, v) { *(UInt64 *)(p) = (v); }\r
 \r
 #else\r
 \r
-#define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8))\r
+#define GetUi16(p) ( (UInt16) ( \\r
+             ((const Byte *)(p))[0] | \\r
+    ((UInt16)((const Byte *)(p))[1] << 8) ))\r
 \r
 #define GetUi32(p) ( \\r
              ((const Byte *)(p))[0]        | \\r
@@ -37,21 +123,43 @@ about these properties of platform.
 \r
 #define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))\r
 \r
-#define SetUi32(p, d) { UInt32 _x_ = (d); \\r
-    ((Byte *)(p))[0] = (Byte)_x_; \\r
-    ((Byte *)(p))[1] = (Byte)(_x_ >> 8); \\r
-    ((Byte *)(p))[2] = (Byte)(_x_ >> 16); \\r
-    ((Byte *)(p))[3] = (Byte)(_x_ >> 24); }\r
+#define SetUi16(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \\r
+    _ppp_[0] = (Byte)_vvv_; \\r
+    _ppp_[1] = (Byte)(_vvv_ >> 8); }\r
+\r
+#define SetUi32(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \\r
+    _ppp_[0] = (Byte)_vvv_; \\r
+    _ppp_[1] = (Byte)(_vvv_ >> 8); \\r
+    _ppp_[2] = (Byte)(_vvv_ >> 16); \\r
+    _ppp_[3] = (Byte)(_vvv_ >> 24); }\r
+\r
+#define SetUi64(p, v) { Byte *_ppp2_ = (Byte *)(p); UInt64 _vvv2_ = (v); \\r
+    SetUi32(_ppp2_    , (UInt32)_vvv2_); \\r
+    SetUi32(_ppp2_ + 4, (UInt32)(_vvv2_ >> 32)); }\r
 \r
 #endif\r
 \r
-#if defined(LITTLE_ENDIAN_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)\r
+\r
+#if defined(MY_CPU_LE_UNALIGN) && /* defined(_WIN64) && */ (_MSC_VER >= 1300)\r
+\r
+/* Note: we use bswap instruction, that is unsupported in 386 cpu */\r
+\r
+#include <stdlib.h>\r
 \r
 #pragma intrinsic(_byteswap_ulong)\r
 #pragma intrinsic(_byteswap_uint64)\r
 #define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))\r
 #define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))\r
 \r
+#define SetBe32(p, v) (*(UInt32 *)(void *)(p)) = _byteswap_ulong(v)\r
+\r
+#elif defined(MY_CPU_LE_UNALIGN) && defined (__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))\r
+\r
+#define GetBe32(p) __builtin_bswap32(*(const UInt32 *)(const Byte *)(p))\r
+#define GetBe64(p) __builtin_bswap64(*(const UInt64 *)(const Byte *)(p))\r
+\r
+#define SetBe32(p, v) (*(UInt32 *)(void *)(p)) = __builtin_bswap32(v)\r
+\r
 #else\r
 \r
 #define GetBe32(p) ( \\r
@@ -62,8 +170,54 @@ about these properties of platform.
 \r
 #define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))\r
 \r
+#define SetBe32(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \\r
+    _ppp_[0] = (Byte)(_vvv_ >> 24); \\r
+    _ppp_[1] = (Byte)(_vvv_ >> 16); \\r
+    _ppp_[2] = (Byte)(_vvv_ >> 8); \\r
+    _ppp_[3] = (Byte)_vvv_; }\r
+\r
+#endif\r
+\r
+\r
+#define GetBe16(p) ( (UInt16) ( \\r
+    ((UInt16)((const Byte *)(p))[0] << 8) | \\r
+             ((const Byte *)(p))[1] ))\r
+\r
+\r
+\r
+#ifdef MY_CPU_X86_OR_AMD64\r
+\r
+typedef struct\r
+{\r
+  UInt32 maxFunc;\r
+  UInt32 vendor[3];\r
+  UInt32 ver;\r
+  UInt32 b;\r
+  UInt32 c;\r
+  UInt32 d;\r
+} Cx86cpuid;\r
+\r
+enum\r
+{\r
+  CPU_FIRM_INTEL,\r
+  CPU_FIRM_AMD,\r
+  CPU_FIRM_VIA\r
+};\r
+\r
+void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d);\r
+\r
+Bool x86cpuid_CheckAndRead(Cx86cpuid *p);\r
+int x86cpuid_GetFirm(const Cx86cpuid *p);\r
+\r
+#define x86cpuid_GetFamily(ver) (((ver >> 16) & 0xFF0) | ((ver >> 8) & 0xF))\r
+#define x86cpuid_GetModel(ver)  (((ver >> 12) &  0xF0) | ((ver >> 4) & 0xF))\r
+#define x86cpuid_GetStepping(ver) (ver & 0xF)\r
+\r
+Bool CPU_Is_InOrder();\r
+Bool CPU_Is_Aes_Supported();\r
+\r
 #endif\r
 \r
-#define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])\r
+EXTERN_C_END\r
 \r
 #endif\r
index 492cea2e416ff56c0e1c8fe83bb5c4cf3dd016f8..a860e068e4b9df322b3a7e2fa5913c7ef15e20d3 100644 (file)
@@ -1,26 +1,11 @@
-/** @file\r
-  LzFind.c\r
+/* LzFind.c -- Match finder for LZ algorithms\r
+2015-10-15 : Igor Pavlov : Public domain */\r
 \r
-  Based on LZMA SDK 4.65:\r
-    LzFind.c -- Match finder for LZ algorithms\r
-    2008-10-04 : Igor Pavlov : Public domain\r
-\r
-  Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
+#include "Precomp.h"\r
 \r
 #ifndef EFIAPI\r
-\r
 #include <string.h>\r
-\r
-#endif // !EFIAPI\r
+#endif\r
 \r
 #include "LzFind.h"\r
 #include "LzHash.h"\r
@@ -28,8 +13,8 @@
 #define kEmptyHashValue 0\r
 #define kMaxValForNormalize ((UInt32)0xFFFFFFFF)\r
 #define kNormalizeStepMin (1 << 10) /* it must be power of 2 */\r
-#define kNormalizeMask (~(kNormalizeStepMin - 1))\r
-#define kMaxHistorySize ((UInt32)3 << 30)\r
+#define kNormalizeMask (~(UInt32)(kNormalizeStepMin - 1))\r
+#define kMaxHistorySize ((UInt32)7 << 29)\r
 \r
 #define kStartMaxLen 3\r
 \r
@@ -38,7 +23,7 @@ static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)
   if (!p->directInput)\r
   {\r
     alloc->Free(alloc, p->bufferBase);\r
-    p->bufferBase = 0;\r
+    p->bufferBase = NULL;\r
   }\r
 }\r
 \r
@@ -52,17 +37,16 @@ static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *a
     p->blockSize = blockSize;\r
     return 1;\r
   }\r
-  if (p->bufferBase == 0 || p->blockSize != blockSize)\r
+  if (!p->bufferBase || p->blockSize != blockSize)\r
   {\r
     LzInWindow_Free(p, alloc);\r
     p->blockSize = blockSize;\r
     p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);\r
   }\r
-  return (p->bufferBase != 0);\r
+  return (p->bufferBase != NULL);\r
 }\r
 \r
 Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }\r
-Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }\r
 \r
 UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }\r
 \r
@@ -77,12 +61,28 @@ static void MatchFinder_ReadBlock(CMatchFinder *p)
 {\r
   if (p->streamEndWasReached || p->result != SZ_OK)\r
     return;\r
+\r
+  /* We use (p->streamPos - p->pos) value. (p->streamPos < p->pos) is allowed. */\r
+\r
+  if (p->directInput)\r
+  {\r
+    UInt32 curSize = 0xFFFFFFFF - (p->streamPos - p->pos);\r
+    if (curSize > p->directInputRem)\r
+      curSize = (UInt32)p->directInputRem;\r
+    p->directInputRem -= curSize;\r
+    p->streamPos += curSize;\r
+    if (p->directInputRem == 0)\r
+      p->streamEndWasReached = 1;\r
+    return;\r
+  }\r
+  \r
   for (;;)\r
   {\r
     Byte *dest = p->buffer + (p->streamPos - p->pos);\r
     size_t size = (p->bufferBase + p->blockSize - dest);\r
     if (size == 0)\r
       return;\r
+\r
     p->result = p->stream->Read(p->stream, dest, &size);\r
     if (p->result != SZ_OK)\r
       return;\r
@@ -100,13 +100,15 @@ static void MatchFinder_ReadBlock(CMatchFinder *p)
 void MatchFinder_MoveBlock(CMatchFinder *p)\r
 {\r
   memmove(p->bufferBase,\r
-    p->buffer - p->keepSizeBefore,\r
-    (size_t)(p->streamPos - p->pos + p->keepSizeBefore));\r
+      p->buffer - p->keepSizeBefore,\r
+      (size_t)(p->streamPos - p->pos) + p->keepSizeBefore);\r
   p->buffer = p->bufferBase + p->keepSizeBefore;\r
 }\r
 \r
 int MatchFinder_NeedMove(CMatchFinder *p)\r
 {\r
+  if (p->directInput)\r
+    return 0;\r
   /* if (p->streamEndWasReached) return 0; */\r
   return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);\r
 }\r
@@ -131,8 +133,6 @@ static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
   p->cutValue = 32;\r
   p->btMode = 1;\r
   p->numHashBytes = 4;\r
-  /* p->skipModeBits = 0; */\r
-  p->directInput = 0;\r
   p->bigHash = 0;\r
 }\r
 \r
@@ -141,15 +141,15 @@ static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
 void MatchFinder_Construct(CMatchFinder *p)\r
 {\r
   UInt32 i;\r
-  p->bufferBase = 0;\r
+  p->bufferBase = NULL;\r
   p->directInput = 0;\r
-  p->hash = 0;\r
+  p->hash = NULL;\r
   MatchFinder_SetDefaultSettings(p);\r
 \r
   for (i = 0; i < 256; i++)\r
   {\r
     UInt32 r = i;\r
-    int j;\r
+    unsigned j;\r
     for (j = 0; j < 8; j++)\r
       r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r
     p->crc[i] = r;\r
@@ -159,7 +159,7 @@ void MatchFinder_Construct(CMatchFinder *p)
 static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)\r
 {\r
   alloc->Free(alloc, p->hash);\r
-  p->hash = 0;\r
+  p->hash = NULL;\r
 }\r
 \r
 void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)\r
@@ -168,11 +168,11 @@ void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)
   LzInWindow_Free(p, alloc);\r
 }\r
 \r
-static CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)\r
+static CLzRef* AllocRefs(size_t num, ISzAlloc *alloc)\r
 {\r
   size_t sizeInBytes = (size_t)num * sizeof(CLzRef);\r
   if (sizeInBytes / sizeof(CLzRef) != num)\r
-    return 0;\r
+    return NULL;\r
   return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);\r
 }\r
 \r
@@ -181,22 +181,27 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
     ISzAlloc *alloc)\r
 {\r
   UInt32 sizeReserv;\r
+  \r
   if (historySize > kMaxHistorySize)\r
   {\r
     MatchFinder_Free(p, alloc);\r
     return 0;\r
   }\r
+  \r
   sizeReserv = historySize >> 1;\r
-  if (historySize > ((UInt32)2 << 30))\r
-    sizeReserv = historySize >> 2;\r
+       if (historySize >= ((UInt32)3 << 30)) sizeReserv = historySize >> 3;\r
+  else if (historySize >= ((UInt32)2 << 30)) sizeReserv = historySize >> 2;\r
+  \r
   sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);\r
 \r
   p->keepSizeBefore = historySize + keepAddBufferBefore + 1;\r
   p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;\r
+  \r
   /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */\r
+  \r
   if (LzInWindow_Create(p, sizeReserv, alloc))\r
   {\r
-    UInt32 newCyclicBufferSize = (historySize /* >> p->skipModeBits */) + 1;\r
+    UInt32 newCyclicBufferSize = historySize + 1;\r
     UInt32 hs;\r
     p->matchMaxLen = matchMaxLen;\r
     {\r
@@ -211,7 +216,6 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
         hs |= (hs >> 4);\r
         hs |= (hs >> 8);\r
         hs >>= 1;\r
-        /* hs >>= p->skipModeBits; */\r
         hs |= 0xFFFF; /* don't change it! It's required for Deflate */\r
         if (hs > (1 << 24))\r
         {\r
@@ -219,6 +223,7 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
             hs = (1 << 24) - 1;\r
           else\r
             hs >>= 1;\r
+          /* if (bigHash) mode, GetHeads4b() in LzFindMt.c needs (hs >= ((1 << 24) - 1))) */\r
         }\r
       }\r
       p->hashMask = hs;\r
@@ -230,24 +235,32 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
     }\r
 \r
     {\r
-      UInt32 prevSize = p->hashSizeSum + p->numSons;\r
-      UInt32 newSize;\r
+      size_t newSize;\r
+      size_t numSons;\r
       p->historySize = historySize;\r
       p->hashSizeSum = hs;\r
       p->cyclicBufferSize = newCyclicBufferSize;\r
-      p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize);\r
-      newSize = p->hashSizeSum + p->numSons;\r
-      if (p->hash != 0 && prevSize == newSize)\r
+      \r
+      numSons = newCyclicBufferSize;\r
+      if (p->btMode)\r
+        numSons <<= 1;\r
+      newSize = hs + numSons;\r
+\r
+      if (p->hash && p->numRefs == newSize)\r
         return 1;\r
+      \r
       MatchFinder_FreeThisClassMemory(p, alloc);\r
+      p->numRefs = newSize;\r
       p->hash = AllocRefs(newSize, alloc);\r
-      if (p->hash != 0)\r
+      \r
+      if (p->hash)\r
       {\r
         p->son = p->hash + p->hashSizeSum;\r
         return 1;\r
       }\r
     }\r
   }\r
+\r
   MatchFinder_Free(p, alloc);\r
   return 0;\r
 }\r
@@ -256,9 +269,11 @@ static void MatchFinder_SetLimits(CMatchFinder *p)
 {\r
   UInt32 limit = kMaxValForNormalize - p->pos;\r
   UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;\r
+  \r
   if (limit2 < limit)\r
     limit = limit2;\r
   limit2 = p->streamPos - p->pos;\r
+  \r
   if (limit2 <= p->keepSizeAfter)\r
   {\r
     if (limit2 > 0)\r
@@ -266,8 +281,10 @@ static void MatchFinder_SetLimits(CMatchFinder *p)
   }\r
   else\r
     limit2 -= p->keepSizeAfter;\r
+  \r
   if (limit2 < limit)\r
     limit = limit2;\r
+  \r
   {\r
     UInt32 lenLimit = p->streamPos - p->pos;\r
     if (lenLimit > p->matchMaxLen)\r
@@ -277,28 +294,39 @@ static void MatchFinder_SetLimits(CMatchFinder *p)
   p->posLimit = p->pos + limit;\r
 }\r
 \r
-void MatchFinder_Init(CMatchFinder *p)\r
+void MatchFinder_Init_2(CMatchFinder *p, int readData)\r
 {\r
   UInt32 i;\r
-  for (i = 0; i < p->hashSizeSum; i++)\r
-    p->hash[i] = kEmptyHashValue;\r
+  UInt32 *hash = p->hash;\r
+  UInt32 num = p->hashSizeSum;\r
+  for (i = 0; i < num; i++)\r
+    hash[i] = kEmptyHashValue;\r
+  \r
   p->cyclicBufferPos = 0;\r
   p->buffer = p->bufferBase;\r
   p->pos = p->streamPos = p->cyclicBufferSize;\r
   p->result = SZ_OK;\r
   p->streamEndWasReached = 0;\r
-  MatchFinder_ReadBlock(p);\r
+  \r
+  if (readData)\r
+    MatchFinder_ReadBlock(p);\r
+  \r
   MatchFinder_SetLimits(p);\r
 }\r
 \r
+void MatchFinder_Init(CMatchFinder *p)\r
+{\r
+  MatchFinder_Init_2(p, True);\r
+}\r
+  \r
 static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)\r
 {\r
   return (p->pos - p->historySize - 1) & kNormalizeMask;\r
 }\r
 \r
-void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)\r
+void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems)\r
 {\r
-  UInt32 i;\r
+  size_t i;\r
   for (i = 0; i < numItems; i++)\r
   {\r
     UInt32 value = items[i];\r
@@ -313,7 +341,7 @@ void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
 static void MatchFinder_Normalize(CMatchFinder *p)\r
 {\r
   UInt32 subValue = MatchFinder_GetSubValue(p);\r
-  MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);\r
+  MatchFinder_Normalize3(subValue, p->hash, p->numRefs);\r
   MatchFinder_ReduceOffsets(p, subValue);\r
 }\r
 \r
@@ -474,7 +502,7 @@ static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const
 static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }\r
 \r
 #define GET_MATCHES_HEADER2(minLen, ret_op) \\r
-  UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \\r
+  UInt32 lenLimit; UInt32 hv; const Byte *cur; UInt32 curMatch; \\r
   lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \\r
   cur = p->buffer;\r
 \r
@@ -490,13 +518,20 @@ static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
 #define SKIP_FOOTER \\r
   SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;\r
 \r
+#define UPDATE_maxLen { \\r
+    ptrdiff_t diff = (ptrdiff_t)0 - d2; \\r
+    const Byte *c = cur + maxLen; \\r
+    const Byte *lim = cur + lenLimit; \\r
+    for (; c != lim; c++) if (*(c + diff) != *c) break; \\r
+    maxLen = (UInt32)(c - cur); }\r
+\r
 static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
 {\r
   UInt32 offset;\r
   GET_MATCHES_HEADER(2)\r
   HASH2_CALC;\r
-  curMatch = p->hash[hashValue];\r
-  p->hash[hashValue] = p->pos;\r
+  curMatch = p->hash[hv];\r
+  p->hash[hv] = p->pos;\r
   offset = 0;\r
   GET_MATCHES_FOOTER(offset, 1)\r
 }\r
@@ -506,35 +541,38 @@ UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
   UInt32 offset;\r
   GET_MATCHES_HEADER(3)\r
   HASH_ZIP_CALC;\r
-  curMatch = p->hash[hashValue];\r
-  p->hash[hashValue] = p->pos;\r
+  curMatch = p->hash[hv];\r
+  p->hash[hv] = p->pos;\r
   offset = 0;\r
   GET_MATCHES_FOOTER(offset, 2)\r
 }\r
 \r
 static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
 {\r
-  UInt32 hash2Value, delta2, maxLen, offset;\r
+  UInt32 h2, d2, maxLen, offset, pos;\r
+  UInt32 *hash;\r
   GET_MATCHES_HEADER(3)\r
 \r
   HASH3_CALC;\r
 \r
-  delta2 = p->pos - p->hash[hash2Value];\r
-  curMatch = p->hash[kFix3HashSize + hashValue];\r
-  \r
-  p->hash[hash2Value] =\r
-  p->hash[kFix3HashSize + hashValue] = p->pos;\r
+  hash = p->hash;\r
+  pos = p->pos;\r
+\r
+  d2 = pos - hash[h2];\r
 \r
+  curMatch = hash[kFix3HashSize + hv];\r
+  \r
+  hash[h2] = pos;\r
+  hash[kFix3HashSize + hv] = pos;\r
 \r
   maxLen = 2;\r
   offset = 0;\r
-  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r
+\r
+  if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)\r
   {\r
-    for (; maxLen != lenLimit; maxLen++)\r
-      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r
-        break;\r
+    UPDATE_maxLen\r
     distances[0] = maxLen;\r
-    distances[1] = delta2 - 1;\r
+    distances[1] = d2 - 1;\r
     offset = 2;\r
     if (maxLen == lenLimit)\r
     {\r
@@ -542,44 +580,51 @@ static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
       MOVE_POS_RET;\r
     }\r
   }\r
+  \r
   GET_MATCHES_FOOTER(offset, maxLen)\r
 }\r
 \r
 static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
 {\r
-  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r
+  UInt32 h2, h3, d2, d3, maxLen, offset, pos;\r
+  UInt32 *hash;\r
   GET_MATCHES_HEADER(4)\r
 \r
   HASH4_CALC;\r
 \r
-  delta2 = p->pos - p->hash[                hash2Value];\r
-  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r
-  curMatch = p->hash[kFix4HashSize + hashValue];\r
-  \r
-  p->hash[                hash2Value] =\r
-  p->hash[kFix3HashSize + hash3Value] =\r
-  p->hash[kFix4HashSize + hashValue] = p->pos;\r
+  hash = p->hash;\r
+  pos = p->pos;\r
 \r
-  maxLen = 1;\r
+  d2 = pos - hash[                h2];\r
+  d3 = pos - hash[kFix3HashSize + h3];\r
+\r
+  curMatch = hash[kFix4HashSize + hv];\r
+\r
+  hash[                h2] = pos;\r
+  hash[kFix3HashSize + h3] = pos;\r
+  hash[kFix4HashSize + hv] = pos;\r
+\r
+  maxLen = 0;\r
   offset = 0;\r
-  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r
+  \r
+  if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)\r
   {\r
     distances[0] = maxLen = 2;\r
-    distances[1] = delta2 - 1;\r
+    distances[1] = d2 - 1;\r
     offset = 2;\r
   }\r
-  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r
+  \r
+  if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur)\r
   {\r
     maxLen = 3;\r
-    distances[offset + 1] = delta3 - 1;\r
+    distances[offset + 1] = d3 - 1;\r
     offset += 2;\r
-    delta2 = delta3;\r
+    d2 = d3;\r
   }\r
+  \r
   if (offset != 0)\r
   {\r
-    for (; maxLen != lenLimit; maxLen++)\r
-      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r
-        break;\r
+    UPDATE_maxLen\r
     distances[offset - 2] = maxLen;\r
     if (maxLen == lenLimit)\r
     {\r
@@ -587,46 +632,131 @@ static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
       MOVE_POS_RET;\r
     }\r
   }\r
+  \r
   if (maxLen < 3)\r
     maxLen = 3;\r
+  \r
   GET_MATCHES_FOOTER(offset, maxLen)\r
 }\r
 \r
+/*\r
+static UInt32 Bt5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
+{\r
+  UInt32 h2, h3, h4, d2, d3, d4, maxLen, offset, pos;\r
+  UInt32 *hash;\r
+  GET_MATCHES_HEADER(5)\r
+\r
+  HASH5_CALC;\r
+\r
+  hash = p->hash;\r
+  pos = p->pos;\r
+\r
+  d2 = pos - hash[                h2];\r
+  d3 = pos - hash[kFix3HashSize + h3];\r
+  d4 = pos - hash[kFix4HashSize + h4];\r
+\r
+  curMatch = hash[kFix5HashSize + hv];\r
+\r
+  hash[                h2] = pos;\r
+  hash[kFix3HashSize + h3] = pos;\r
+  hash[kFix4HashSize + h4] = pos;\r
+  hash[kFix5HashSize + hv] = pos;\r
+\r
+  maxLen = 0;\r
+  offset = 0;\r
+\r
+  if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)\r
+  {\r
+    distances[0] = maxLen = 2;\r
+    distances[1] = d2 - 1;\r
+    offset = 2;\r
+    if (*(cur - d2 + 2) == cur[2])\r
+      distances[0] = maxLen = 3;\r
+    else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)\r
+    {\r
+      distances[2] = maxLen = 3;\r
+      distances[3] = d3 - 1;\r
+      offset = 4;\r
+      d2 = d3;\r
+    }\r
+  }\r
+  else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)\r
+  {\r
+    distances[0] = maxLen = 3;\r
+    distances[1] = d3 - 1;\r
+    offset = 2;\r
+    d2 = d3;\r
+  }\r
+  \r
+  if (d2 != d4 && d4 < p->cyclicBufferSize\r
+      && *(cur - d4) == *cur\r
+      && *(cur - d4 + 3) == *(cur + 3))\r
+  {\r
+    maxLen = 4;\r
+    distances[offset + 1] = d4 - 1;\r
+    offset += 2;\r
+    d2 = d4;\r
+  }\r
+  \r
+  if (offset != 0)\r
+  {\r
+    UPDATE_maxLen\r
+    distances[offset - 2] = maxLen;\r
+    if (maxLen == lenLimit)\r
+    {\r
+      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r
+      MOVE_POS_RET;\r
+    }\r
+  }\r
+\r
+  if (maxLen < 4)\r
+    maxLen = 4;\r
+  \r
+  GET_MATCHES_FOOTER(offset, maxLen)\r
+}\r
+*/\r
+\r
 static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
 {\r
-  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r
+  UInt32 h2, h3, d2, d3, maxLen, offset, pos;\r
+  UInt32 *hash;\r
   GET_MATCHES_HEADER(4)\r
 \r
   HASH4_CALC;\r
 \r
-  delta2 = p->pos - p->hash[                hash2Value];\r
-  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r
-  curMatch = p->hash[kFix4HashSize + hashValue];\r
+  hash = p->hash;\r
+  pos = p->pos;\r
+  \r
+  d2 = pos - hash[                h2];\r
+  d3 = pos - hash[kFix3HashSize + h3];\r
+  \r
+  curMatch = hash[kFix4HashSize + hv];\r
 \r
-  p->hash[                hash2Value] =\r
-  p->hash[kFix3HashSize + hash3Value] =\r
-  p->hash[kFix4HashSize + hashValue] = p->pos;\r
+  hash[                h2] = pos;\r
+  hash[kFix3HashSize + h3] = pos;\r
+  hash[kFix4HashSize + hv] = pos;\r
 \r
-  maxLen = 1;\r
+  maxLen = 0;\r
   offset = 0;\r
-  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r
+\r
+  if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)\r
   {\r
     distances[0] = maxLen = 2;\r
-    distances[1] = delta2 - 1;\r
+    distances[1] = d2 - 1;\r
     offset = 2;\r
   }\r
-  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r
+  \r
+  if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur)\r
   {\r
     maxLen = 3;\r
-    distances[offset + 1] = delta3 - 1;\r
+    distances[offset + 1] = d3 - 1;\r
     offset += 2;\r
-    delta2 = delta3;\r
+    d2 = d3;\r
   }\r
+  \r
   if (offset != 0)\r
   {\r
-    for (; maxLen != lenLimit; maxLen++)\r
-      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r
-        break;\r
+    UPDATE_maxLen\r
     distances[offset - 2] = maxLen;\r
     if (maxLen == lenLimit)\r
     {\r
@@ -634,22 +764,103 @@ static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
       MOVE_POS_RET;\r
     }\r
   }\r
+  \r
   if (maxLen < 3)\r
     maxLen = 3;\r
+\r
   offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r
-    distances + offset, maxLen) - (distances));\r
+      distances + offset, maxLen) - (distances));\r
   MOVE_POS_RET\r
 }\r
 \r
+/*\r
+static UInt32 Hc5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
+{\r
+  UInt32 h2, h3, h4, d2, d3, d4, maxLen, offset, pos\r
+  UInt32 *hash;\r
+  GET_MATCHES_HEADER(5)\r
+\r
+  HASH5_CALC;\r
+\r
+  hash = p->hash;\r
+  pos = p->pos;\r
+  \r
+  d2 = pos - hash[                h2];\r
+  d3 = pos - hash[kFix3HashSize + h3];\r
+  d4 = pos - hash[kFix4HashSize + h4];\r
+\r
+  curMatch = hash[kFix5HashSize + hv];\r
+\r
+  hash[                h2] = pos;\r
+  hash[kFix3HashSize + h3] = pos;\r
+  hash[kFix4HashSize + h4] = pos;\r
+  hash[kFix5HashSize + hv] = pos;\r
+\r
+  maxLen = 0;\r
+  offset = 0;\r
+\r
+  if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)\r
+  {\r
+    distances[0] = maxLen = 2;\r
+    distances[1] = d2 - 1;\r
+    offset = 2;\r
+    if (*(cur - d2 + 2) == cur[2])\r
+      distances[0] = maxLen = 3;\r
+    else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)\r
+    {\r
+      distances[2] = maxLen = 3;\r
+      distances[3] = d3 - 1;\r
+      offset = 4;\r
+      d2 = d3;\r
+    }\r
+  }\r
+  else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)\r
+  {\r
+    distances[0] = maxLen = 3;\r
+    distances[1] = d3 - 1;\r
+    offset = 2;\r
+    d2 = d3;\r
+  }\r
+  \r
+  if (d2 != d4 && d4 < p->cyclicBufferSize\r
+      && *(cur - d4) == *cur\r
+      && *(cur - d4 + 3) == *(cur + 3))\r
+  {\r
+    maxLen = 4;\r
+    distances[offset + 1] = d4 - 1;\r
+    offset += 2;\r
+    d2 = d4;\r
+  }\r
+  \r
+  if (offset != 0)\r
+  {\r
+    UPDATE_maxLen\r
+    distances[offset - 2] = maxLen;\r
+    if (maxLen == lenLimit)\r
+    {\r
+      p->son[p->cyclicBufferPos] = curMatch;\r
+      MOVE_POS_RET;\r
+    }\r
+  }\r
+  \r
+  if (maxLen < 4)\r
+    maxLen = 4;\r
+\r
+  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r
+      distances + offset, maxLen) - (distances));\r
+  MOVE_POS_RET\r
+}\r
+*/\r
+\r
 UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
 {\r
   UInt32 offset;\r
   GET_MATCHES_HEADER(3)\r
   HASH_ZIP_CALC;\r
-  curMatch = p->hash[hashValue];\r
-  p->hash[hashValue] = p->pos;\r
+  curMatch = p->hash[hv];\r
+  p->hash[hv] = p->pos;\r
   offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r
-    distances, 2) - (distances));\r
+      distances, 2) - (distances));\r
   MOVE_POS_RET\r
 }\r
 \r
@@ -659,8 +870,8 @@ static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
   {\r
     SKIP_HEADER(2)\r
     HASH2_CALC;\r
-    curMatch = p->hash[hashValue];\r
-    p->hash[hashValue] = p->pos;\r
+    curMatch = p->hash[hv];\r
+    p->hash[hv] = p->pos;\r
     SKIP_FOOTER\r
   }\r
   while (--num != 0);\r
@@ -672,8 +883,8 @@ void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
   {\r
     SKIP_HEADER(3)\r
     HASH_ZIP_CALC;\r
-    curMatch = p->hash[hashValue];\r
-    p->hash[hashValue] = p->pos;\r
+    curMatch = p->hash[hv];\r
+    p->hash[hv] = p->pos;\r
     SKIP_FOOTER\r
   }\r
   while (--num != 0);\r
@@ -683,12 +894,14 @@ static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
 {\r
   do\r
   {\r
-    UInt32 hash2Value;\r
+    UInt32 h2;\r
+    UInt32 *hash;\r
     SKIP_HEADER(3)\r
     HASH3_CALC;\r
-    curMatch = p->hash[kFix3HashSize + hashValue];\r
-    p->hash[hash2Value] =\r
-    p->hash[kFix3HashSize + hashValue] = p->pos;\r
+    hash = p->hash;\r
+    curMatch = hash[kFix3HashSize + hv];\r
+    hash[h2] =\r
+    hash[kFix3HashSize + hv] = p->pos;\r
     SKIP_FOOTER\r
   }\r
   while (--num != 0);\r
@@ -698,34 +911,81 @@ static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
 {\r
   do\r
   {\r
-    UInt32 hash2Value, hash3Value;\r
+    UInt32 h2, h3;\r
+    UInt32 *hash;\r
     SKIP_HEADER(4)\r
     HASH4_CALC;\r
-    curMatch = p->hash[kFix4HashSize + hashValue];\r
-    p->hash[                hash2Value] =\r
-    p->hash[kFix3HashSize + hash3Value] = p->pos;\r
-    p->hash[kFix4HashSize + hashValue] = p->pos;\r
+    hash = p->hash;\r
+    curMatch = hash[kFix4HashSize + hv];\r
+    hash[                h2] =\r
+    hash[kFix3HashSize + h3] =\r
+    hash[kFix4HashSize + hv] = p->pos;\r
+    SKIP_FOOTER\r
+  }\r
+  while (--num != 0);\r
+}\r
+\r
+/*\r
+static void Bt5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
+{\r
+  do\r
+  {\r
+    UInt32 h2, h3, h4;\r
+    UInt32 *hash;\r
+    SKIP_HEADER(5)\r
+    HASH5_CALC;\r
+    hash = p->hash;\r
+    curMatch = hash[kFix5HashSize + hv];\r
+    hash[                h2] =\r
+    hash[kFix3HashSize + h3] =\r
+    hash[kFix4HashSize + h4] =\r
+    hash[kFix5HashSize + hv] = p->pos;\r
     SKIP_FOOTER\r
   }\r
   while (--num != 0);\r
 }\r
+*/\r
 \r
 static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
 {\r
   do\r
   {\r
-    UInt32 hash2Value, hash3Value;\r
+    UInt32 h2, h3;\r
+    UInt32 *hash;\r
     SKIP_HEADER(4)\r
     HASH4_CALC;\r
-    curMatch = p->hash[kFix4HashSize + hashValue];\r
-    p->hash[                hash2Value] =\r
-    p->hash[kFix3HashSize + hash3Value] =\r
-    p->hash[kFix4HashSize + hashValue] = p->pos;\r
+    hash = p->hash;\r
+    curMatch = hash[kFix4HashSize + hv];\r
+    hash[                h2] =\r
+    hash[kFix3HashSize + h3] =\r
+    hash[kFix4HashSize + hv] = p->pos;\r
+    p->son[p->cyclicBufferPos] = curMatch;\r
+    MOVE_POS\r
+  }\r
+  while (--num != 0);\r
+}\r
+\r
+/*\r
+static void Hc5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
+{\r
+  do\r
+  {\r
+    UInt32 h2, h3, h4;\r
+    UInt32 *hash;\r
+    SKIP_HEADER(5)\r
+    HASH5_CALC;\r
+    hash = p->hash;\r
+    curMatch = p->hash[kFix5HashSize + hv];\r
+    hash[                h2] =\r
+    hash[kFix3HashSize + h3] =\r
+    hash[kFix4HashSize + h4] =\r
+    hash[kFix5HashSize + hv] = p->pos;\r
     p->son[p->cyclicBufferPos] = curMatch;\r
     MOVE_POS\r
   }\r
   while (--num != 0);\r
 }\r
+*/\r
 \r
 void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
 {\r
@@ -733,8 +993,8 @@ void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
   {\r
     SKIP_HEADER(3)\r
     HASH_ZIP_CALC;\r
-    curMatch = p->hash[hashValue];\r
-    p->hash[hashValue] = p->pos;\r
+    curMatch = p->hash[hv];\r
+    p->hash[hv] = p->pos;\r
     p->son[p->cyclicBufferPos] = curMatch;\r
     MOVE_POS\r
   }\r
@@ -744,13 +1004,22 @@ void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)\r
 {\r
   vTable->Init = (Mf_Init_Func)MatchFinder_Init;\r
-  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;\r
   vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;\r
   vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;\r
   if (!p->btMode)\r
   {\r
-    vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;\r
-    vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;\r
+    /* if (p->numHashBytes <= 4) */\r
+    {\r
+      vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;\r
+      vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;\r
+    }\r
+    /*\r
+    else\r
+    {\r
+      vTable->GetMatches = (Mf_GetMatches_Func)Hc5_MatchFinder_GetMatches;\r
+      vTable->Skip = (Mf_Skip_Func)Hc5_MatchFinder_Skip;\r
+    }\r
+    */\r
   }\r
   else if (p->numHashBytes == 2)\r
   {\r
@@ -762,9 +1031,16 @@ void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)
     vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;\r
     vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;\r
   }\r
-  else\r
+  else /* if (p->numHashBytes == 4) */\r
   {\r
     vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;\r
     vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;\r
   }\r
+  /*\r
+  else\r
+  {\r
+    vTable->GetMatches = (Mf_GetMatches_Func)Bt5_MatchFinder_GetMatches;\r
+    vTable->Skip = (Mf_Skip_Func)Bt5_MatchFinder_Skip;\r
+  }\r
+  */\r
 }\r
index 423d67e0c3e0cb9db952c1c99b4a2e53415c5c8b..2ff667377166b6bb54b5306a4641515c9ccf1039 100644 (file)
@@ -1,10 +1,12 @@
 /* LzFind.h -- Match finder for LZ algorithms\r
-2008-10-04 : Igor Pavlov : Public domain */\r
+2015-10-15 : Igor Pavlov : Public domain */\r
 \r
-#ifndef __LZFIND_H\r
-#define __LZFIND_H\r
+#ifndef __LZ_FIND_H\r
+#define __LZ_FIND_H\r
 \r
-#include "Types.h"\r
+#include "7zTypes.h"\r
+\r
+EXTERN_C_BEGIN\r
 \r
 typedef UInt32 CLzRef;\r
 \r
@@ -19,6 +21,11 @@ typedef struct _CMatchFinder
   UInt32 cyclicBufferPos;\r
   UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */\r
 \r
+  Byte streamEndWasReached;\r
+  Byte btMode;\r
+  Byte bigHash;\r
+  Byte directInput;\r
+\r
   UInt32 matchMaxLen;\r
   CLzRef *hash;\r
   CLzRef *son;\r
@@ -27,30 +34,30 @@ typedef struct _CMatchFinder
 \r
   Byte *bufferBase;\r
   ISeqInStream *stream;\r
-  int streamEndWasReached;\r
-\r
+  \r
   UInt32 blockSize;\r
   UInt32 keepSizeBefore;\r
   UInt32 keepSizeAfter;\r
 \r
   UInt32 numHashBytes;\r
-  int directInput;\r
-  int btMode;\r
-  /* int skipModeBits; */\r
-  int bigHash;\r
+  size_t directInputRem;\r
   UInt32 historySize;\r
   UInt32 fixedHashSize;\r
   UInt32 hashSizeSum;\r
-  UInt32 numSons;\r
   SRes result;\r
   UInt32 crc[256];\r
+  size_t numRefs;\r
 } CMatchFinder;\r
 \r
 #define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)\r
-#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])\r
 \r
 #define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)\r
 \r
+#define Inline_MatchFinder_IsFinishedOK(p) \\r
+    ((p)->streamEndWasReached \\r
+        && (p)->streamPos == (p)->pos \\r
+        && (!(p)->directInput || (p)->directInputRem == 0))\r
+      \r
 int MatchFinder_NeedMove(CMatchFinder *p);\r
 Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);\r
 void MatchFinder_MoveBlock(CMatchFinder *p);\r
@@ -66,7 +73,7 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
     UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r
     ISzAlloc *alloc);\r
 void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);\r
-void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);\r
+void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems);\r
 void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);\r
 \r
 UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,\r
@@ -80,7 +87,6 @@ Conditions:
 */\r
 \r
 typedef void (*Mf_Init_Func)(void *object);\r
-typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);\r
 typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);\r
 typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);\r
 typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);\r
@@ -89,7 +95,6 @@ typedef void (*Mf_Skip_Func)(void *object, UInt32);
 typedef struct _IMatchFinder\r
 {\r
   Mf_Init_Func Init;\r
-  Mf_GetIndexByte_Func GetIndexByte;\r
   Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;\r
   Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;\r
   Mf_GetMatches_Func GetMatches;\r
@@ -98,10 +103,15 @@ typedef struct _IMatchFinder
 \r
 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);\r
 \r
+void MatchFinder_Init_2(CMatchFinder *p, int readData);\r
 void MatchFinder_Init(CMatchFinder *p);\r
+\r
 UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r
 UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r
+\r
 void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r
 void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r
 \r
+EXTERN_C_END\r
+\r
 #endif\r
index c923417501689882dfd773a91c412f993f6272a4..2191444072a13a459ea9bbee411329e65e42f1fe 100644 (file)
@@ -1,8 +1,8 @@
 /* LzHash.h -- HASH functions for LZ algorithms\r
-2008-10-04 : Igor Pavlov : Public domain */\r
+2015-04-12 : Igor Pavlov : Public domain */\r
 \r
-#ifndef __LZHASH_H\r
-#define __LZHASH_H\r
+#ifndef __LZ_HASH_H\r
+#define __LZ_HASH_H\r
 \r
 #define kHash2Size (1 << 10)\r
 #define kHash3Size (1 << 16)\r
 #define kFix4HashSize (kHash2Size + kHash3Size)\r
 #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)\r
 \r
-#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);\r
+#define HASH2_CALC hv = cur[0] | ((UInt32)cur[1] << 8);\r
 \r
 #define HASH3_CALC { \\r
   UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\r
-  hash2Value = temp & (kHash2Size - 1); \\r
-  hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }\r
+  h2 = temp & (kHash2Size - 1); \\r
+  hv = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }\r
 \r
 #define HASH4_CALC { \\r
   UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\r
-  hash2Value = temp & (kHash2Size - 1); \\r
-  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\r
-  hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }\r
+  h2 = temp & (kHash2Size - 1); \\r
+  temp ^= ((UInt32)cur[2] << 8); \\r
+  h3 = temp & (kHash3Size - 1); \\r
+  hv = (temp ^ (p->crc[cur[3]] << 5)) & p->hashMask; }\r
 \r
 #define HASH5_CALC { \\r
   UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\r
-  hash2Value = temp & (kHash2Size - 1); \\r
-  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\r
-  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \\r
-  hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \\r
-  hash4Value &= (kHash4Size - 1); }\r
+  h2 = temp & (kHash2Size - 1); \\r
+  temp ^= ((UInt32)cur[2] << 8); \\r
+  h3 = temp & (kHash3Size - 1); \\r
+  temp ^= (p->crc[cur[3]] << 5); \\r
+  h4 = temp & (kHash4Size - 1); \\r
+  hv = (temp ^ (p->crc[cur[4]] << 3)) & p->hashMask; }\r
 \r
-/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */\r
-#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;\r
+/* #define HASH_ZIP_CALC hv = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */\r
+#define HASH_ZIP_CALC hv = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;\r
 \r
 \r
 #define MT_HASH2_CALC \\r
-  hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);\r
+  h2 = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);\r
 \r
 #define MT_HASH3_CALC { \\r
   UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\r
-  hash2Value = temp & (kHash2Size - 1); \\r
-  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }\r
+  h2 = temp & (kHash2Size - 1); \\r
+  h3 = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }\r
 \r
 #define MT_HASH4_CALC { \\r
   UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\r
-  hash2Value = temp & (kHash2Size - 1); \\r
-  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\r
-  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }\r
+  h2 = temp & (kHash2Size - 1); \\r
+  temp ^= ((UInt32)cur[2] << 8); \\r
+  h3 = temp & (kHash3Size - 1); \\r
+  h4 = (temp ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }\r
 \r
 #endif\r
index e3db4edbb413a707a38c033b87d2cae4cfb4f0a6..1c1f83ba605da7c349fbe492db6f690bc7d3bb5b 100644 (file)
@@ -1,28 +1,13 @@
-/** @file\r
-  LzmaDec.c\r
+/* LzmaDec.c -- LZMA Decoder\r
+2016-05-16 : Igor Pavlov : Public domain */\r
 \r
-  Based on LZMA SDK 4.65:\r
-    LzmaDec.c -- LZMA Decoder\r
-    2008-11-06 : Igor Pavlov : Public domain\r
-\r
-  Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
+#include "Precomp.h"\r
 \r
 #include "LzmaDec.h"\r
 \r
 #ifndef EFIAPI\r
-\r
 #include <string.h>\r
-\r
-#endif // !EFIAPI\r
+#endif\r
 \r
 #define kNumTopBits 24\r
 #define kTopValue ((UInt32)1 << kNumTopBits)\r
   i -= 0x40; }\r
 #endif\r
 \r
+#define NORMAL_LITER_DEC GET_BIT(prob + symbol, symbol)\r
+#define MATCHED_LITER_DEC \\r
+  matchByte <<= 1; \\r
+  bit = (matchByte & offs); \\r
+  probLit = prob + offs + bit + symbol; \\r
+  GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)\r
+\r
 #define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }\r
 \r
 #define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r
 #define Literal (RepLenCoder + kNumLenProbs)\r
 \r
 #define LZMA_BASE_SIZE 1846\r
-#define LZMA_LIT_SIZE 768\r
-\r
-#define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))\r
+#define LZMA_LIT_SIZE 0x300\r
 \r
 #if Literal != LZMA_BASE_SIZE\r
 StopCompilingDueBUG\r
 #endif\r
 \r
-static const Byte kLiteralNextStates[kNumStates * 2] =\r
-{\r
-  0, 0, 0, 0, 1, 2, 3,  4,  5,  6,  4,  5,\r
-  7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10\r
-};\r
+#define LzmaProps_GetNumProbs(p) (Literal + ((UInt32)LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))\r
 \r
 #define LZMA_DIC_MIN (1 << 12)\r
 \r
@@ -149,8 +135,8 @@ Out:
   p->remainLen:\r
     < kMatchSpecLenStart : normal remain\r
     = kMatchSpecLenStart : finished\r
-    = kMatchSpecLenStart + 1 : Flush marker\r
-    = kMatchSpecLenStart + 2 : State Init Marker\r
+    = kMatchSpecLenStart + 1 : Flush marker (unused now)\r
+    = kMatchSpecLenStart + 2 : State Init Marker (unused now)\r
 */\r
 \r
 static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\r
@@ -188,39 +174,62 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
       unsigned symbol;\r
       UPDATE_0(prob);\r
       prob = probs + Literal;\r
-      if (checkDicSize != 0 || processedPos != 0)\r
-        prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +\r
-        (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));\r
+      if (processedPos != 0 || checkDicSize != 0)\r
+        prob += ((UInt32)LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +\r
+            (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));\r
+      processedPos++;\r
 \r
       if (state < kNumLitStates)\r
       {\r
+        state -= (state < 4) ? state : 3;\r
         symbol = 1;\r
-        do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100);\r
+        #ifdef _LZMA_SIZE_OPT\r
+        do { NORMAL_LITER_DEC } while (symbol < 0x100);\r
+        #else\r
+        NORMAL_LITER_DEC\r
+        NORMAL_LITER_DEC\r
+        NORMAL_LITER_DEC\r
+        NORMAL_LITER_DEC\r
+        NORMAL_LITER_DEC\r
+        NORMAL_LITER_DEC\r
+        NORMAL_LITER_DEC\r
+        NORMAL_LITER_DEC\r
+        #endif\r
       }\r
       else\r
       {\r
-        unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r
+        unsigned matchByte = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];\r
         unsigned offs = 0x100;\r
+        state -= (state < 10) ? 3 : 6;\r
         symbol = 1;\r
+        #ifdef _LZMA_SIZE_OPT\r
         do\r
         {\r
           unsigned bit;\r
           CLzmaProb *probLit;\r
-          matchByte <<= 1;\r
-          bit = (matchByte & offs);\r
-          probLit = prob + offs + bit + symbol;\r
-          GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)\r
+          MATCHED_LITER_DEC\r
         }\r
         while (symbol < 0x100);\r
+        #else\r
+        {\r
+          unsigned bit;\r
+          CLzmaProb *probLit;\r
+          MATCHED_LITER_DEC\r
+          MATCHED_LITER_DEC\r
+          MATCHED_LITER_DEC\r
+          MATCHED_LITER_DEC\r
+          MATCHED_LITER_DEC\r
+          MATCHED_LITER_DEC\r
+          MATCHED_LITER_DEC\r
+          MATCHED_LITER_DEC\r
+        }\r
+        #endif\r
       }\r
-      dic[dicPos++] = (Byte)symbol;\r
-      processedPos++;\r
 \r
-      state = kLiteralNextStates[state];\r
-      /* if (state < 4) state = 0; else if (state < 10) state -= 3; else state -= 6; */\r
+      dic[dicPos++] = (Byte)symbol;\r
       continue;\r
     }\r
-    else\r
+    \r
     {\r
       UPDATE_1(prob);\r
       prob = probs + IsRep + state;\r
@@ -243,7 +252,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
           IF_BIT_0(prob)\r
           {\r
             UPDATE_0(prob);\r
-            dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r
+            dic[dicPos] = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];\r
             dicPos++;\r
             processedPos++;\r
             state = state < kNumLitStates ? 9 : 11;\r
@@ -284,15 +293,17 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
         state = state < kNumLitStates ? 8 : 11;\r
         prob = probs + RepLenCoder;\r
       }\r
+      \r
+      #ifdef _LZMA_SIZE_OPT\r
       {\r
-        unsigned limit2, offset;\r
+        unsigned lim, offset;\r
         CLzmaProb *probLen = prob + LenChoice;\r
         IF_BIT_0(probLen)\r
         {\r
           UPDATE_0(probLen);\r
           probLen = prob + LenLow + (posState << kLenNumLowBits);\r
           offset = 0;\r
-          limit2 = (1 << kLenNumLowBits);\r
+          lim = (1 << kLenNumLowBits);\r
         }\r
         else\r
         {\r
@@ -303,19 +314,55 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
             UPDATE_0(probLen);\r
             probLen = prob + LenMid + (posState << kLenNumMidBits);\r
             offset = kLenNumLowSymbols;\r
-            limit2 = (1 << kLenNumMidBits);\r
+            lim = (1 << kLenNumMidBits);\r
           }\r
           else\r
           {\r
             UPDATE_1(probLen);\r
             probLen = prob + LenHigh;\r
             offset = kLenNumLowSymbols + kLenNumMidSymbols;\r
-            limit2 = (1 << kLenNumHighBits);\r
+            lim = (1 << kLenNumHighBits);\r
           }\r
         }\r
-        TREE_DECODE(probLen, limit2, len);\r
+        TREE_DECODE(probLen, lim, len);\r
         len += offset;\r
       }\r
+      #else\r
+      {\r
+        CLzmaProb *probLen = prob + LenChoice;\r
+        IF_BIT_0(probLen)\r
+        {\r
+          UPDATE_0(probLen);\r
+          probLen = prob + LenLow + (posState << kLenNumLowBits);\r
+          len = 1;\r
+          TREE_GET_BIT(probLen, len);\r
+          TREE_GET_BIT(probLen, len);\r
+          TREE_GET_BIT(probLen, len);\r
+          len -= 8;\r
+        }\r
+        else\r
+        {\r
+          UPDATE_1(probLen);\r
+          probLen = prob + LenChoice2;\r
+          IF_BIT_0(probLen)\r
+          {\r
+            UPDATE_0(probLen);\r
+            probLen = prob + LenMid + (posState << kLenNumMidBits);\r
+            len = 1;\r
+            TREE_GET_BIT(probLen, len);\r
+            TREE_GET_BIT(probLen, len);\r
+            TREE_GET_BIT(probLen, len);\r
+          }\r
+          else\r
+          {\r
+            UPDATE_1(probLen);\r
+            probLen = prob + LenHigh;\r
+            TREE_DECODE(probLen, (1 << kLenNumHighBits), len);\r
+            len += kLenNumLowSymbols + kLenNumMidSymbols;\r
+          }\r
+        }\r
+      }\r
+      #endif\r
 \r
       if (state >= kNumStates)\r
       {\r
@@ -326,7 +373,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
         if (distance >= kStartPosModelIndex)\r
         {\r
           unsigned posSlot = (unsigned)distance;\r
-          int numDirectBits = (int)(((distance >> 1) - 1));\r
+          unsigned numDirectBits = (unsigned)(((distance >> 1) - 1));\r
           distance = (2 | (distance & 1));\r
           if (posSlot < kEndPosModelIndex)\r
           {\r
@@ -385,6 +432,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
             }\r
           }\r
         }\r
+        \r
         rep3 = rep2;\r
         rep2 = rep1;\r
         rep1 = rep0;\r
@@ -392,34 +440,46 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
         if (checkDicSize == 0)\r
         {\r
           if (distance >= processedPos)\r
+          {\r
+            p->dicPos = dicPos;\r
             return SZ_ERROR_DATA;\r
+          }\r
         }\r
         else if (distance >= checkDicSize)\r
+        {\r
+          p->dicPos = dicPos;\r
           return SZ_ERROR_DATA;\r
+        }\r
         state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;\r
-        /* state = kLiteralNextStates[state]; */\r
       }\r
 \r
       len += kMatchMinLen;\r
 \r
-      if (limit == dicPos)\r
-        return SZ_ERROR_DATA;\r
       {\r
-        SizeT rem = limit - dicPos;\r
-        unsigned curLen = ((rem < len) ? (unsigned)rem : len);\r
-        SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0);\r
+        SizeT rem;\r
+        unsigned curLen;\r
+        SizeT pos;\r
+        \r
+        if ((rem = limit - dicPos) == 0)\r
+        {\r
+          p->dicPos = dicPos;\r
+          return SZ_ERROR_DATA;\r
+        }\r
+        \r
+        curLen = ((rem < len) ? (unsigned)rem : len);\r
+        pos = dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0);\r
 \r
         processedPos += curLen;\r
 \r
         len -= curLen;\r
-        if (pos + curLen <= dicBufSize)\r
+        if (curLen <= dicBufSize - pos)\r
         {\r
           Byte *dest = dic + dicPos;\r
           ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;\r
           const Byte *lim = dest + curLen;\r
           dicPos += curLen;\r
           do\r
-            *((volatile Byte *)dest) = (Byte)*(dest + src);\r
+            *(dest) = (Byte)*(dest + src);\r
           while (++dest != lim);\r
         }\r
         else\r
@@ -436,7 +496,9 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
     }\r
   }\r
   while (dicPos < limit && buf < bufLimit);\r
+\r
   NORMALIZE;\r
+  \r
   p->buf = buf;\r
   p->range = range;\r
   p->code = code;\r
@@ -460,18 +522,20 @@ static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
     SizeT dicPos = p->dicPos;\r
     SizeT dicBufSize = p->dicBufSize;\r
     unsigned len = p->remainLen;\r
-    UInt32 rep0 = p->reps[0];\r
-    if (limit - dicPos < len)\r
-      len = (unsigned)(limit - dicPos);\r
+    SizeT rep0 = p->reps[0]; /* we use SizeT to avoid the BUG of VC14 for AMD64 */\r
+    SizeT rem = limit - dicPos;\r
+    if (rem < len)\r
+      len = (unsigned)(rem);\r
 \r
     if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)\r
       p->checkDicSize = p->prop.dicSize;\r
 \r
     p->processedPos += len;\r
     p->remainLen -= len;\r
-    while (len-- != 0)\r
+    while (len != 0)\r
     {\r
-      dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r
+      len--;\r
+      dic[dicPos] = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];\r
       dicPos++;\r
     }\r
     p->dicPos = dicPos;\r
@@ -489,17 +553,19 @@ static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte
       if (limit - p->dicPos > rem)\r
         limit2 = p->dicPos + rem;\r
     }\r
+    \r
     RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit));\r
-    if (p->processedPos >= p->prop.dicSize)\r
+    \r
+    if (p->checkDicSize == 0 && p->processedPos >= p->prop.dicSize)\r
       p->checkDicSize = p->prop.dicSize;\r
+    \r
     LzmaDec_WriteRem(p, limit);\r
   }\r
   while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);\r
 \r
   if (p->remainLen > kMatchSpecLenStart)\r
-  {\r
     p->remainLen = kMatchSpecLenStart;\r
-  }\r
+\r
   return 0;\r
 }\r
 \r
@@ -516,12 +582,12 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
   UInt32 range = p->range;\r
   UInt32 code = p->code;\r
   const Byte *bufLimit = buf + inSize;\r
-  CLzmaProb *probs = p->probs;\r
+  const CLzmaProb *probs = p->probs;\r
   unsigned state = p->state;\r
   ELzmaDummy res;\r
 \r
   {\r
-    CLzmaProb *prob;\r
+    const CLzmaProb *prob;\r
     UInt32 bound;\r
     unsigned ttt;\r
     unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);\r
@@ -535,9 +601,9 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
 \r
       prob = probs + Literal;\r
       if (p->checkDicSize != 0 || p->processedPos != 0)\r
-        prob += (LZMA_LIT_SIZE *\r
-          ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +\r
-          (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));\r
+        prob += ((UInt32)LZMA_LIT_SIZE *\r
+            ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +\r
+            (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));\r
 \r
       if (state < kNumLitStates)\r
       {\r
@@ -547,13 +613,13 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
       else\r
       {\r
         unsigned matchByte = p->dic[p->dicPos - p->reps[0] +\r
-            ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];\r
+            (p->dicPos < p->reps[0] ? p->dicBufSize : 0)];\r
         unsigned offs = 0x100;\r
         unsigned symbol = 1;\r
         do\r
         {\r
           unsigned bit;\r
-          CLzmaProb *probLit;\r
+          const CLzmaProb *probLit;\r
           matchByte <<= 1;\r
           bit = (matchByte & offs);\r
           probLit = prob + offs + bit + symbol;\r
@@ -623,7 +689,7 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
       }\r
       {\r
         unsigned limit, offset;\r
-        CLzmaProb *probLen = prob + LenChoice;\r
+        const CLzmaProb *probLen = prob + LenChoice;\r
         IF_BIT_0_CHECK(probLen)\r
         {\r
           UPDATE_0_CHECK;\r
@@ -663,7 +729,7 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
         TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);\r
         if (posSlot >= kStartPosModelIndex)\r
         {\r
-          int numDirectBits = ((posSlot >> 1) - 1);\r
+          unsigned numDirectBits = ((posSlot >> 1) - 1);\r
 \r
           /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */\r
 \r
@@ -701,12 +767,6 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
   return res;\r
 }\r
 \r
-static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)\r
-{\r
-  p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]);\r
-  p->range = 0xFFFFFFFF;\r
-  p->needFlush = 0;\r
-}\r
 \r
 void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)\r
 {\r
@@ -732,8 +792,8 @@ void LzmaDec_Init(CLzmaDec *p)
 \r
 static void LzmaDec_InitStateReal(CLzmaDec *p)\r
 {\r
-  UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));\r
-  UInt32 i;\r
+  SizeT numProbs = LzmaProps_GetNumProbs(&p->prop);\r
+  SizeT i;\r
   CLzmaProb *probs = p->probs;\r
   for (i = 0; i < numProbs; i++)\r
     probs[i] = kBitModelTotal >> 1;\r
@@ -755,7 +815,7 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr
   {\r
       int checkEndMarkNow;\r
 \r
-      if (p->needFlush != 0)\r
+      if (p->needFlush)\r
       {\r
         for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)\r
           p->tempBuf[p->tempBufSize++] = *src++;\r
@@ -766,8 +826,13 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr
         }\r
         if (p->tempBuf[0] != 0)\r
           return SZ_ERROR_DATA;\r
-\r
-        LzmaDec_InitRc(p, p->tempBuf);\r
+        p->code =\r
+              ((UInt32)p->tempBuf[1] << 24)\r
+            | ((UInt32)p->tempBuf[2] << 16)\r
+            | ((UInt32)p->tempBuf[3] << 8)\r
+            | ((UInt32)p->tempBuf[4]);\r
+        p->range = 0xFFFFFFFF;\r
+        p->needFlush = 0;\r
         p->tempBufSize = 0;\r
       }\r
 \r
@@ -851,7 +916,16 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr
         p->buf = p->tempBuf;\r
         if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)\r
           return SZ_ERROR_DATA;\r
-        lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));\r
+        \r
+        {\r
+          unsigned kkk = (unsigned)(p->buf - p->tempBuf);\r
+          if (rem < kkk)\r
+            return SZ_ERROR_FAIL; /* some internal error */\r
+          rem -= kkk;\r
+          if (lookAhead < rem)\r
+            return SZ_ERROR_FAIL; /* some internal error */\r
+          lookAhead -= rem;\r
+        }\r
         (*srcLen) += lookAhead;\r
         src += lookAhead;\r
         inSize -= lookAhead;\r
@@ -906,13 +980,13 @@ SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *sr
 void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)\r
 {\r
   alloc->Free(alloc, p->probs);\r
-  p->probs = 0;\r
+  p->probs = NULL;\r
 }\r
 \r
 static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)\r
 {\r
   alloc->Free(alloc, p->dic);\r
-  p->dic = 0;\r
+  p->dic = NULL;\r
 }\r
 \r
 void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)\r
@@ -950,12 +1024,12 @@ SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
 static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)\r
 {\r
   UInt32 numProbs = LzmaProps_GetNumProbs(propNew);\r
-  if (p->probs == 0 || numProbs != p->numProbs)\r
+  if (!p->probs || numProbs != p->numProbs)\r
   {\r
     LzmaDec_FreeProbs(p, alloc);\r
     p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb));\r
     p->numProbs = numProbs;\r
-    if (p->probs == 0)\r
+    if (!p->probs)\r
       return SZ_ERROR_MEM;\r
   }\r
   return SZ_OK;\r
@@ -976,12 +1050,22 @@ SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAll
   SizeT dicBufSize;\r
   RINOK(LzmaProps_Decode(&propNew, props, propsSize));\r
   RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));\r
-  dicBufSize = propNew.dicSize;\r
-  if (p->dic == 0 || dicBufSize != p->dicBufSize)\r
+\r
+  {\r
+    UInt32 dictSize = propNew.dicSize;\r
+    SizeT mask = ((UInt32)1 << 12) - 1;\r
+         if (dictSize >= ((UInt32)1 << 30)) mask = ((UInt32)1 << 22) - 1;\r
+    else if (dictSize >= ((UInt32)1 << 22)) mask = ((UInt32)1 << 20) - 1;;\r
+    dicBufSize = ((SizeT)dictSize + mask) & ~mask;\r
+    if (dicBufSize < dictSize)\r
+      dicBufSize = dictSize;\r
+  }\r
+\r
+  if (!p->dic || dicBufSize != p->dicBufSize)\r
   {\r
     LzmaDec_FreeDict(p, alloc);\r
     p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);\r
-    if (p->dic == 0)\r
+    if (!p->dic)\r
     {\r
       LzmaDec_FreeProbs(p, alloc);\r
       return SZ_ERROR_MEM;\r
@@ -998,29 +1082,21 @@ SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
 {\r
   CLzmaDec p;\r
   SRes res;\r
-  SizeT inSize = *srcLen;\r
-  SizeT outSize = *destLen;\r
-  *srcLen = *destLen = 0;\r
+  SizeT outSize = *destLen, inSize = *srcLen;\r
+  *destLen = *srcLen = 0;\r
+  *status = LZMA_STATUS_NOT_SPECIFIED;\r
   if (inSize < RC_INIT_SIZE)\r
     return SZ_ERROR_INPUT_EOF;\r
-\r
   LzmaDec_Construct(&p);\r
-  res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc);\r
-  if (res != 0)\r
-    return res;\r
+  RINOK(LzmaDec_AllocateProbs(&p, propData, propSize, alloc));\r
   p.dic = dest;\r
   p.dicBufSize = outSize;\r
-\r
   LzmaDec_Init(&p);\r
-  \r
   *srcLen = inSize;\r
   res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);\r
-\r
+  *destLen = p.dicPos;\r
   if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)\r
     res = SZ_ERROR_INPUT_EOF;\r
-\r
-  (*destLen) = p.dicPos;\r
   LzmaDec_FreeProbs(&p, alloc);\r
   return res;\r
 }\r
-\r
index ad7d7057a4f18570383a66ad5039b4b80d5834e5..2633abeac9db432a032c28083ed0382e1ad1826b 100644 (file)
@@ -1,10 +1,12 @@
 /* LzmaDec.h -- LZMA Decoder\r
-2008-10-04 : Igor Pavlov : Public domain */\r
+2013-01-18 : Igor Pavlov : Public domain */\r
 \r
-#ifndef __LZMADEC_H\r
-#define __LZMADEC_H\r
+#ifndef __LZMA_DEC_H\r
+#define __LZMA_DEC_H\r
 \r
-#include "Types.h"\r
+#include "7zTypes.h"\r
+\r
+EXTERN_C_BEGIN\r
 \r
 /* #define _LZMA_PROB32 */\r
 /* _LZMA_PROB32 can increase the speed on some CPUs,\r
@@ -220,4 +222,6 @@ SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
     const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,\r
     ELzmaStatus *status, ISzAlloc *alloc);\r
 \r
+EXTERN_C_END\r
+\r
 #endif\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Precomp.h b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Precomp.h
new file mode 100644 (file)
index 0000000..edb5814
--- /dev/null
@@ -0,0 +1,10 @@
+/* Precomp.h -- StdAfx\r
+2013-11-12 : Igor Pavlov : Public domain */\r
+\r
+#ifndef __7Z_PRECOMP_H\r
+#define __7Z_PRECOMP_H\r
+\r
+#include "Compiler.h"\r
+/* #include "7zTypes.h" */\r
+\r
+#endif\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Types.h b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Types.h
deleted file mode 100644 (file)
index 30b16e3..0000000
+++ /dev/null
@@ -1,231 +0,0 @@
-/** @file\r
-  Types.h\r
-\r
-  Based on LZMA SDK 4.65:\r
-    Types.h -- Basic types\r
-    2008-11-23 : Igor Pavlov : Public domain\r
-\r
-  Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#ifndef __7Z_TYPES_H\r
-#define __7Z_TYPES_H\r
-\r
-#ifdef EFIAPI\r
-\r
-#include "UefiLzma.h"\r
-\r
-#else\r
-\r
-#include <stddef.h>\r
-\r
-#ifdef _WIN32\r
-#include <windows.h>\r
-#endif\r
-\r
-#endif\r
-\r
-#define SZ_OK 0\r
-\r
-#define SZ_ERROR_DATA 1\r
-#define SZ_ERROR_MEM 2\r
-#define SZ_ERROR_CRC 3\r
-#define SZ_ERROR_UNSUPPORTED 4\r
-#define SZ_ERROR_PARAM 5\r
-#define SZ_ERROR_INPUT_EOF 6\r
-#define SZ_ERROR_OUTPUT_EOF 7\r
-#define SZ_ERROR_READ 8\r
-#define SZ_ERROR_WRITE 9\r
-#define SZ_ERROR_PROGRESS 10\r
-#define SZ_ERROR_FAIL 11\r
-#define SZ_ERROR_THREAD 12\r
-\r
-#define SZ_ERROR_ARCHIVE 16\r
-#define SZ_ERROR_NO_ARCHIVE 17\r
-\r
-typedef int SRes;\r
-\r
-#ifdef _WIN32\r
-typedef DWORD WRes;\r
-#else\r
-typedef int WRes;\r
-#endif\r
-\r
-#ifndef RINOK\r
-#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }\r
-#endif\r
-\r
-typedef unsigned char Byte;\r
-typedef short Int16;\r
-typedef unsigned short UInt16;\r
-\r
-#ifdef _LZMA_UINT32_IS_ULONG\r
-typedef long Int32;\r
-typedef unsigned long UInt32;\r
-#else\r
-typedef int Int32;\r
-typedef unsigned int UInt32;\r
-#endif\r
-\r
-#ifdef _SZ_NO_INT_64\r
-\r
-/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.\r
-   NOTES: Some code will work incorrectly in that case! */\r
-\r
-typedef long Int64;\r
-typedef unsigned long UInt64;\r
-\r
-#else\r
-\r
-#if defined(_MSC_VER) || defined(__BORLANDC__)\r
-typedef __int64 Int64;\r
-typedef unsigned __int64 UInt64;\r
-#else\r
-typedef long long int Int64;\r
-typedef unsigned long long int UInt64;\r
-#endif\r
-\r
-#endif\r
-\r
-#ifdef _LZMA_NO_SYSTEM_SIZE_T\r
-typedef UInt32 SizeT;\r
-#else\r
-typedef size_t SizeT;\r
-#endif\r
-\r
-typedef int Bool;\r
-#define True 1\r
-#define False 0\r
-\r
-\r
-#ifdef _MSC_VER\r
-\r
-#if _MSC_VER >= 1300\r
-#define MY_NO_INLINE __declspec(noinline)\r
-#else\r
-#define MY_NO_INLINE\r
-#endif\r
-\r
-#define MY_CDECL __cdecl\r
-#define MY_STD_CALL __stdcall\r
-#define MY_FAST_CALL MY_NO_INLINE __fastcall\r
-\r
-#else\r
-\r
-#define MY_CDECL\r
-#define MY_STD_CALL\r
-#define MY_FAST_CALL\r
-\r
-#endif\r
-\r
-\r
-/* The following interfaces use first parameter as pointer to structure */\r
-\r
-typedef struct\r
-{\r
-  SRes (*Read)(void *p, void *buf, size_t *size);\r
-    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r
-       (output(*size) < input(*size)) is allowed */\r
-} ISeqInStream;\r
-\r
-/* it can return SZ_ERROR_INPUT_EOF */\r
-SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);\r
-SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);\r
-SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);\r
-\r
-typedef struct\r
-{\r
-  size_t (*Write)(void *p, const void *buf, size_t size);\r
-    /* Returns: result - the number of actually written bytes.\r
-       (result < size) means error */\r
-} ISeqOutStream;\r
-\r
-typedef enum\r
-{\r
-  SZ_SEEK_SET = 0,\r
-  SZ_SEEK_CUR = 1,\r
-  SZ_SEEK_END = 2\r
-} ESzSeek;\r
-\r
-typedef struct\r
-{\r
-  SRes (*Read)(void *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */\r
-  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r
-} ISeekInStream;\r
-\r
-typedef struct\r
-{\r
-  SRes (*Look)(void *p, void **buf, size_t *size);\r
-    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r
-       (output(*size) > input(*size)) is not allowed\r
-       (output(*size) < input(*size)) is allowed */\r
-  SRes (*Skip)(void *p, size_t offset);\r
-    /* offset must be <= output(*size) of Look */\r
-\r
-  SRes (*Read)(void *p, void *buf, size_t *size);\r
-    /* reads directly (without buffer). It's same as ISeqInStream::Read */\r
-  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r
-} ILookInStream;\r
-\r
-SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);\r
-SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);\r
-\r
-/* reads via ILookInStream::Read */\r
-SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);\r
-SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);\r
-\r
-#define LookToRead_BUF_SIZE (1 << 14)\r
-\r
-typedef struct\r
-{\r
-  ILookInStream s;\r
-  ISeekInStream *realStream;\r
-  size_t pos;\r
-  size_t size;\r
-  Byte buf[LookToRead_BUF_SIZE];\r
-} CLookToRead;\r
-\r
-void LookToRead_CreateVTable(CLookToRead *p, int lookahead);\r
-void LookToRead_Init(CLookToRead *p);\r
-\r
-typedef struct\r
-{\r
-  ISeqInStream s;\r
-  ILookInStream *realStream;\r
-} CSecToLook;\r
-\r
-void SecToLook_CreateVTable(CSecToLook *p);\r
-\r
-typedef struct\r
-{\r
-  ISeqInStream s;\r
-  ILookInStream *realStream;\r
-} CSecToRead;\r
-\r
-void SecToRead_CreateVTable(CSecToRead *p);\r
-\r
-typedef struct\r
-{\r
-  SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);\r
-    /* Returns: result. (result != SZ_OK) means break.\r
-       Value (UInt64)(Int64)-1 for size means unknown value. */\r
-} ICompressProgress;\r
-\r
-typedef struct\r
-{\r
-  void *(*Alloc)(void *p, size_t size);\r
-  void (*Free)(void *p, void *address); /* address can be 0 */\r
-} ISzAlloc;\r
-\r
-#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)\r
-#define IAlloc_Free(p, a) (p)->Free((p), a)\r
-\r
-#endif\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/DOC/lzma-history.txt b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/DOC/lzma-history.txt
new file mode 100644 (file)
index 0000000..7aaeb07
--- /dev/null
@@ -0,0 +1,363 @@
+HISTORY of the LZMA SDK\r
+-----------------------\r
+\r
+16.04          2016-10-04\r
+-------------------------\r
+- The bug was fixed in DllSecur.c.\r
+\r
+\r
+16.03          2016-09-28\r
+-------------------------\r
+- SFX modules now use some protection against DLL preloading attack.\r
+- Some bugs in 7z code were fixed.\r
+\r
+\r
+16.02          2016-05-21\r
+-------------------------\r
+- The BUG in 16.00 - 16.01 was fixed:\r
+  Split Handler (SplitHandler.cpp) returned incorrect \r
+  total size value (kpidSize) for split archives.\r
+\r
+\r
+16.01          2016-05-19\r
+-------------------------      \r
+- Some internal changes to reduce the number of compiler warnings.\r
+\r
+\r
+16.00          2016-05-10\r
+-------------------------      \r
+- Some bugs were fixed.\r
+\r
+\r
+15.12          2015-11-19\r
+-------------------------      \r
+- The BUG in C version of 7z decoder was fixed:\r
+  7zDec.c : SzDecodeLzma2()\r
+  7z decoder could mistakenly report about decoding error for some 7z archives\r
+  that use LZMA2 compression method.\r
+  The probability to get that mistaken decoding error report was about \r
+  one error per 16384 solid blocks for solid blocks larger than 16 KB (compressed size). \r
+- The BUG (in 9.26-15.11) in C version of 7z decoder was fixed:\r
+  7zArcIn.c : SzReadHeader2()\r
+  7z decoder worked incorrectly for 7z archives that contain \r
+  empty solid blocks, that can be placed to 7z archive, if some file is \r
+  unavailable for reading during archive creation.\r
+\r
+\r
+15.09 beta     2015-10-16\r
+-------------------------      \r
+- The BUG in LZMA / LZMA2 encoding code was fixed.\r
+  The BUG in LzFind.c::MatchFinder_ReadBlock() function.\r
+  If input data size is larger than (4 GiB - dictionary_size),\r
+  the following code worked incorrectly:\r
+  -  LZMA : LzmaEnc_MemEncode(), LzmaEncode() : LZMA encoding functions \r
+     for compressing from memory to memory. \r
+     That BUG is not related to LZMA encoder version that works via streams.\r
+  -  LZMA2 : multi-threaded version of LZMA2 encoder worked incorrectly, if \r
+     default value of chunk size (CLzma2EncProps::blockSize) is changed \r
+     to value larger than (4 GiB - dictionary_size).\r
+\r
+\r
+9.38 beta      2015-01-03\r
+-------------------------      \r
+- The BUG in 9.31-9.37 was fixed:\r
+  IArchiveGetRawProps interface was disabled for 7z archives.\r
+- The BUG in 9.26-9.36 was fixed:\r
+  Some code in CPP\7zip\Archive\7z\ worked correctly only under Windows.\r
+\r
+\r
+9.36 beta      2014-12-26\r
+-------------------------      \r
+- The BUG in command line version was fixed:\r
+  7-Zip created temporary archive in current folder during update archive\r
+  operation, if -w{Path} switch was not specified. \r
+  The fixed 7-Zip creates temporary archive in folder that contains updated archive.\r
+- The BUG in 9.33-9.35 was fixed:\r
+  7-Zip silently ignored file reading errors during 7z or gz archive creation,\r
+  and the created archive contained only part of file that was read before error.\r
+  The fixed 7-Zip stops archive creation and it reports about error.\r
+\r
+\r
+9.35 beta      2014-12-07\r
+-------------------------      \r
+- 7zr.exe now support AES encryption.\r
+- SFX mudules were added to LZMA SDK\r
+- Some bugs were fixed.\r
+\r
+\r
+9.21 beta      2011-04-11\r
+-------------------------      \r
+- New class FString for file names at file systems.\r
+- Speed optimization in CRC code for big-endian CPUs.\r
+- The BUG in Lzma2Dec.c was fixed:\r
+    Lzma2Decode function didn't work.\r
+\r
+\r
+9.18 beta      2010-11-02\r
+-------------------------      \r
+- New small SFX module for installers (SfxSetup).\r
+\r
+\r
+9.12 beta      2010-03-24\r
+-------------------------\r
+- The BUG in LZMA SDK 9.* was fixed: LZMA2 codec didn't work,\r
+  if more than 10 threads were used (or more than 20 threads in some modes).\r
+\r
+\r
+9.11 beta      2010-03-15\r
+-------------------------\r
+- PPMd compression method support\r
+   \r
+\r
+9.09           2009-12-12\r
+-------------------------\r
+- The bug was fixed:\r
+   Utf16_To_Utf8 funstions in UTFConvert.cpp and 7zMain.c\r
+   incorrectly converted surrogate characters (the code >= 0x10000) to UTF-8.\r
+- Some bugs were fixed\r
+\r
+\r
+9.06           2009-08-17\r
+-------------------------\r
+- Some changes in ANSI-C 7z Decoder interfaces.\r
+\r
+\r
+9.04           2009-05-30\r
+-------------------------\r
+- LZMA2 compression method support\r
+- xz format support\r
+\r
+\r
+4.65           2009-02-03\r
+-------------------------\r
+- Some minor fixes\r
+\r
+\r
+4.63           2008-12-31\r
+-------------------------\r
+- Some minor fixes\r
+\r
+\r
+4.61 beta      2008-11-23\r
+-------------------------\r
+- The bug in ANSI-C LZMA Decoder was fixed:\r
+    If encoded stream was corrupted, decoder could access memory \r
+    outside of allocated range.\r
+- Some changes in ANSI-C 7z Decoder interfaces.\r
+- LZMA SDK is placed in the public domain.\r
+\r
+\r
+4.60 beta      2008-08-19\r
+-------------------------\r
+- Some minor fixes.\r
+\r
+\r
+4.59 beta      2008-08-13\r
+-------------------------\r
+- The bug was fixed:\r
+    LZMA Encoder in fast compression mode could access memory outside of \r
+    allocated range in some rare cases.\r
+\r
+\r
+4.58 beta      2008-05-05\r
+-------------------------\r
+- ANSI-C LZMA Decoder was rewritten for speed optimizations.\r
+- ANSI-C LZMA Encoder was included to LZMA SDK.\r
+- C++ LZMA code now is just wrapper over ANSI-C code.\r
+\r
+\r
+4.57           2007-12-12\r
+-------------------------\r
+- Speed optimizations in C++ LZMA Decoder. \r
+- Small changes for more compatibility with some C/C++ compilers.\r
+\r
+\r
+4.49 beta      2007-07-05\r
+-------------------------\r
+- .7z ANSI-C Decoder:\r
+     - now it supports BCJ and BCJ2 filters\r
+     - now it supports files larger than 4 GB.\r
+     - now it supports "Last Write Time" field for files.\r
+- C++ code for .7z archives compressing/decompressing from 7-zip \r
+  was included to LZMA SDK.\r
+  \r
+\r
+4.43           2006-06-04\r
+-------------------------\r
+- Small changes for more compatibility with some C/C++ compilers.\r
+  \r
+\r
+4.42           2006-05-15\r
+-------------------------\r
+- Small changes in .h files in ANSI-C version.\r
+  \r
+\r
+4.39 beta      2006-04-14\r
+-------------------------\r
+- The bug in versions 4.33b:4.38b was fixed:\r
+  C++ version of LZMA encoder could not correctly compress \r
+  files larger than 2 GB with HC4 match finder (-mfhc4).\r
+  \r
+\r
+4.37 beta      2005-04-06\r
+-------------------------\r
+- Fixes in C++ code: code could no be compiled if _NO_EXCEPTIONS was defined. \r
+\r
+\r
+4.35 beta      2005-03-02\r
+-------------------------\r
+- The bug was fixed in C++ version of LZMA Decoder:\r
+    If encoded stream was corrupted, decoder could access memory \r
+    outside of allocated range.\r
+\r
+\r
+4.34 beta      2006-02-27\r
+-------------------------\r
+- Compressing speed and memory requirements for compressing were increased\r
+- LZMA now can use only these match finders: HC4, BT2, BT3, BT4\r
+\r
+\r
+4.32           2005-12-09\r
+-------------------------\r
+- Java version of LZMA SDK was included\r
+\r
+\r
+4.30           2005-11-20\r
+-------------------------\r
+- Compression ratio was improved in -a2 mode\r
+- Speed optimizations for compressing in -a2 mode\r
+- -fb switch now supports values up to 273\r
+- The bug in 7z_C (7zIn.c) was fixed:\r
+  It used Alloc/Free functions from different memory pools.\r
+  So if program used two memory pools, it worked incorrectly.\r
+- 7z_C: .7z format supporting was improved\r
+- LZMA# SDK (C#.NET version) was included\r
+\r
+\r
+4.27 (Updated) 2005-09-21\r
+-------------------------\r
+- Some GUIDs/interfaces in C++ were changed.\r
+ IStream.h:\r
+   ISequentialInStream::Read now works as old ReadPart\r
+   ISequentialOutStream::Write now works as old WritePart\r
+\r
+\r
+4.27           2005-08-07\r
+-------------------------\r
+- The bug in LzmaDecodeSize.c was fixed:\r
+   if _LZMA_IN_CB and _LZMA_OUT_READ were defined,\r
+   decompressing worked incorrectly.\r
+\r
+\r
+4.26           2005-08-05\r
+-------------------------\r
+- Fixes in 7z_C code and LzmaTest.c:\r
+  previous versions could work incorrectly,\r
+  if malloc(0) returns 0\r
+\r
+\r
+4.23           2005-06-29\r
+-------------------------\r
+- Small fixes in C++ code\r
+\r
+\r
+4.22           2005-06-10\r
+-------------------------\r
+- Small fixes\r
+\r
+\r
+4.21           2005-06-08\r
+-------------------------\r
+- Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed\r
+- New additional version of ANSI-C LZMA Decoder with zlib-like interface:\r
+    - LzmaStateDecode.h\r
+    - LzmaStateDecode.c\r
+    - LzmaStateTest.c\r
+- ANSI-C LZMA Decoder now can decompress files larger than 4 GB\r
+\r
+\r
+4.17           2005-04-18\r
+-------------------------\r
+- New example for RAM->RAM compressing/decompressing: \r
+  LZMA + BCJ (filter for x86 code):\r
+    - LzmaRam.h\r
+    - LzmaRam.cpp\r
+    - LzmaRamDecode.h\r
+    - LzmaRamDecode.c\r
+    - -f86 switch for lzma.exe\r
+\r
+\r
+4.16           2005-03-29\r
+-------------------------\r
+- The bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder): \r
+   If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,\r
+   decoder could access memory outside of allocated range.\r
+- Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).\r
+  Old version of LZMA Decoder now is in file LzmaDecodeSize.c. \r
+  LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c\r
+- Small speed optimization in LZMA C++ code\r
+- filter for SPARC's code was added\r
+- Simplified version of .7z ANSI-C Decoder was included\r
+\r
+\r
+4.06           2004-09-05\r
+-------------------------\r
+- The bug in v4.05 was fixed:\r
+    LZMA-Encoder didn't release output stream in some cases.\r
+\r
+\r
+4.05           2004-08-25\r
+-------------------------\r
+- Source code of filters for x86, IA-64, ARM, ARM-Thumb \r
+  and PowerPC code was included to SDK\r
+- Some internal minor changes\r
+\r
+\r
+4.04           2004-07-28\r
+-------------------------\r
+- More compatibility with some C++ compilers\r
+\r
+\r
+4.03           2004-06-18\r
+-------------------------\r
+- "Benchmark" command was added. It measures compressing \r
+  and decompressing speed and shows rating values. \r
+  Also it checks hardware errors.\r
+\r
+\r
+4.02           2004-06-10\r
+-------------------------\r
+- C++ LZMA Encoder/Decoder code now is more portable\r
+  and it can be compiled by GCC on Linux.\r
+\r
+\r
+4.01           2004-02-15\r
+-------------------------\r
+- Some detection of data corruption was enabled.\r
+    LzmaDecode.c / RangeDecoderReadByte\r
+    .....\r
+    {\r
+      rd->ExtraBytes = 1;\r
+      return 0xFF;\r
+    }\r
+\r
+\r
+4.00           2004-02-13\r
+-------------------------\r
+- Original version of LZMA SDK\r
+\r
+\r
+\r
+HISTORY of the LZMA\r
+-------------------\r
+  2001-2008:  Improvements to LZMA compressing/decompressing code, \r
+              keeping compatibility with original LZMA format\r
+  1996-2001:  Development of LZMA compression format\r
+\r
+  Some milestones:\r
+\r
+  2001-08-30: LZMA compression was added to 7-Zip\r
+  1999-01-02: First version of 7-Zip was released\r
+  \r
+\r
+End of document\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/DOC/lzma-sdk.txt b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/DOC/lzma-sdk.txt
new file mode 100644 (file)
index 0000000..86fef24
--- /dev/null
@@ -0,0 +1,357 @@
+LZMA SDK 16.04\r
+--------------\r
+\r
+LZMA SDK provides the documentation, samples, header files,\r
+libraries, and tools you need to develop applications that \r
+use 7z / LZMA / LZMA2 / XZ compression.\r
+\r
+LZMA is an improved version of famous LZ77 compression algorithm. \r
+It was improved in way of maximum increasing of compression ratio,\r
+keeping high decompression speed and low memory requirements for \r
+decompressing.\r
+\r
+LZMA2 is a LZMA based compression method. LZMA2 provides better \r
+multithreading support for compression than LZMA and some other improvements.\r
+\r
+7z is a file format for data compression and file archiving.\r
+7z is a main file format for 7-Zip compression program (www.7-zip.org).\r
+7z format supports different compression methods: LZMA, LZMA2 and others.\r
+7z also supports AES-256 based encryption.\r
+\r
+XZ is a file format for data compression that uses LZMA2 compression.\r
+XZ format provides additional features: SHA/CRC check, filters for \r
+improved compression ratio, splitting to blocks and streams,\r
+\r
+\r
+\r
+LICENSE\r
+-------\r
+\r
+LZMA SDK is written and placed in the public domain by Igor Pavlov.\r
+\r
+Some code in LZMA SDK is based on public domain code from another developers:\r
+  1) PPMd var.H (2001): Dmitry Shkarin\r
+  2) SHA-256: Wei Dai (Crypto++ library)\r
+\r
+Anyone is free to copy, modify, publish, use, compile, sell, or distribute the \r
+original LZMA SDK code, either in source code form or as a compiled binary, for \r
+any purpose, commercial or non-commercial, and by any means.\r
+\r
+LZMA SDK code is compatible with open source licenses, for example, you can \r
+include it to GNU GPL or GNU LGPL code.\r
+\r
+\r
+LZMA SDK Contents\r
+-----------------\r
+\r
+  Source code:\r
+\r
+    - C / C++ / C# / Java   - LZMA compression and decompression\r
+    - C / C++               - LZMA2 compression and decompression\r
+    - C / C++               - XZ compression and decompression\r
+    - C                     - 7z decompression\r
+    -     C++               - 7z compression and decompression\r
+    - C                     - small SFXs for installers (7z decompression)\r
+    -     C++               - SFXs and SFXs for installers (7z decompression)\r
+\r
+  Precomiled binaries:\r
+\r
+    - console programs for lzma / 7z / xz compression and decompression\r
+    - SFX modules for installers.\r
+\r
+\r
+UNIX/Linux version \r
+------------------\r
+To compile C++ version of file->file LZMA encoding, go to directory\r
+CPP/7zip/Bundles/LzmaCon\r
+and call make to recompile it:\r
+  make -f makefile.gcc clean all\r
+\r
+In some UNIX/Linux versions you must compile LZMA with static libraries.\r
+To compile with static libraries, you can use \r
+LIB = -lm -static\r
+\r
+Also you can use p7zip (port of 7-Zip for POSIX systems like Unix or Linux):\r
+  \r
+  http://p7zip.sourceforge.net/\r
+\r
+\r
+Files\r
+-----\r
+\r
+DOC/7zC.txt          - 7z ANSI-C Decoder description\r
+DOC/7zFormat.txt     - 7z Format description\r
+DOC/installer.txt    - information about 7-Zip for installers\r
+DOC/lzma.txt         - LZMA compression description\r
+DOC/lzma-sdk.txt     - LZMA SDK description (this file)\r
+DOC/lzma-history.txt - history of LZMA SDK\r
+DOC/lzma-specification.txt - Specification of LZMA\r
+DOC/Methods.txt      - Compression method IDs for .7z\r
+\r
+bin/installer/   - example script to create installer that uses SFX module,\r
+\r
+bin/7zdec.exe    - simplified 7z archive decoder\r
+bin/7zr.exe      - 7-Zip console program (reduced version)\r
+bin/x64/7zr.exe  - 7-Zip console program (reduced version) (x64 version)\r
+bin/lzma.exe     - file->file LZMA encoder/decoder for Windows\r
+bin/7zS2.sfx     - small SFX module for installers (GUI version)\r
+bin/7zS2con.sfx  - small SFX module for installers (Console version)\r
+bin/7zSD.sfx     - SFX module for installers.\r
+\r
+\r
+7zDec.exe\r
+---------\r
+7zDec.exe is simplified 7z archive decoder.\r
+It supports only LZMA, LZMA2, and PPMd methods.\r
+7zDec decodes whole solid block from 7z archive to RAM.\r
+The RAM consumption can be high.\r
+\r
+\r
+\r
+\r
+Source code structure\r
+---------------------\r
+\r
+\r
+Asm/ - asm files (optimized code for CRC calculation and Intel-AES encryption)\r
+\r
+C/  - C files (compression / decompression and other)\r
+  Util/\r
+    7z       - 7z decoder program (decoding 7z files)\r
+    Lzma     - LZMA program (file->file LZMA encoder/decoder).\r
+    LzmaLib  - LZMA library (.DLL for Windows)\r
+    SfxSetup - small SFX module for installers \r
+\r
+CPP/ -- CPP files\r
+\r
+  Common  - common files for C++ projects\r
+  Windows - common files for Windows related code\r
+\r
+  7zip    - files related to 7-Zip\r
+\r
+    Archive - files related to archiving\r
+\r
+      Common   - common files for archive handling\r
+      7z       - 7z C++ Encoder/Decoder\r
+\r
+    Bundles  - Modules that are bundles of other modules (files)\r
+  \r
+      Alone7z       - 7zr.exe: Standalone 7-Zip console program (reduced version)\r
+      Format7zExtractR  - 7zxr.dll: Reduced version of 7z DLL: extracting from 7z/LZMA/BCJ/BCJ2.\r
+      Format7zR         - 7zr.dll:  Reduced version of 7z DLL: extracting/compressing to 7z/LZMA/BCJ/BCJ2\r
+      LzmaCon       - lzma.exe: LZMA compression/decompression\r
+      LzmaSpec      - example code for LZMA Specification\r
+      SFXCon        - 7zCon.sfx: Console 7z SFX module\r
+      SFXSetup      - 7zS.sfx: 7z SFX module for installers\r
+      SFXWin        - 7z.sfx: GUI 7z SFX module\r
+\r
+    Common   - common files for 7-Zip\r
+\r
+    Compress - files for compression/decompression\r
+\r
+    Crypto   - files for encryption / decompression\r
+\r
+    UI       - User Interface files\r
+         \r
+      Client7z - Test application for 7za.dll, 7zr.dll, 7zxr.dll\r
+      Common   - Common UI files\r
+      Console  - Code for console program (7z.exe)\r
+      Explorer    - Some code from 7-Zip Shell extension\r
+      FileManager - Some GUI code from 7-Zip File Manager\r
+      GUI         - Some GUI code from 7-Zip\r
+\r
+\r
+CS/ - C# files\r
+  7zip\r
+    Common   - some common files for 7-Zip\r
+    Compress - files related to compression/decompression\r
+      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\r
+      LZMA         - LZMA compression/decompression\r
+      LzmaAlone    - file->file LZMA compression/decompression\r
+      RangeCoder   - Range Coder (special code of compression/decompression)\r
+\r
+Java/  - Java files\r
+  SevenZip\r
+    Compression    - files related to compression/decompression\r
+      LZ           - files related to LZ (Lempel-Ziv) compression algorithm\r
+      LZMA         - LZMA compression/decompression\r
+      RangeCoder   - Range Coder (special code of compression/decompression)\r
+\r
+\r
+Note: \r
+  Asm / C / C++ source code of LZMA SDK is part of 7-Zip's source code.\r
+  7-Zip's source code can be downloaded from 7-Zip's SourceForge page:\r
+\r
+  http://sourceforge.net/projects/sevenzip/\r
+\r
+\r
+\r
+LZMA features\r
+-------------\r
+  - Variable dictionary size (up to 1 GB)\r
+  - Estimated compressing speed: about 2 MB/s on 2 GHz CPU\r
+  - Estimated decompressing speed: \r
+      - 20-30 MB/s on modern 2 GHz cpu\r
+      - 1-2 MB/s on 200 MHz simple RISC cpu: (ARM, MIPS, PowerPC)\r
+  - Small memory requirements for decompressing (16 KB + DictionarySize)\r
+  - Small code size for decompressing: 5-8 KB\r
+\r
+LZMA decoder uses only integer operations and can be \r
+implemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).\r
+\r
+Some critical operations that affect the speed of LZMA decompression:\r
+  1) 32*16 bit integer multiply\r
+  2) Mispredicted branches (penalty mostly depends from pipeline length)\r
+  3) 32-bit shift and arithmetic operations\r
+\r
+The speed of LZMA decompressing mostly depends from CPU speed.\r
+Memory speed has no big meaning. But if your CPU has small data cache, \r
+overall weight of memory speed will slightly increase.\r
+\r
+\r
+How To Use\r
+----------\r
+\r
+Using LZMA encoder/decoder executable\r
+--------------------------------------\r
+\r
+Usage:  LZMA <e|d> inputFile outputFile [<switches>...]\r
+\r
+  e: encode file\r
+\r
+  d: decode file\r
+\r
+  b: Benchmark. There are two tests: compressing and decompressing \r
+     with LZMA method. Benchmark shows rating in MIPS (million \r
+     instructions per second). Rating value is calculated from \r
+     measured speed and it is normalized with Intel's Core 2 results.\r
+     Also Benchmark checks possible hardware errors (RAM \r
+     errors in most cases). Benchmark uses these settings:\r
+     (-a1, -d21, -fb32, -mfbt4). You can change only -d parameter. \r
+     Also you can change the number of iterations. Example for 30 iterations:\r
+       LZMA b 30\r
+     Default number of iterations is 10.\r
+\r
+<Switches>\r
+  \r
+\r
+  -a{N}:  set compression mode 0 = fast, 1 = normal\r
+          default: 1 (normal)\r
+\r
+  d{N}:   Sets Dictionary size - [0, 30], default: 23 (8MB)\r
+          The maximum value for dictionary size is 1 GB = 2^30 bytes.\r
+          Dictionary size is calculated as DictionarySize = 2^N bytes. \r
+          For decompressing file compressed by LZMA method with dictionary \r
+          size D = 2^N you need about D bytes of memory (RAM).\r
+\r
+  -fb{N}: set number of fast bytes - [5, 273], default: 128\r
+          Usually big number gives a little bit better compression ratio \r
+          and slower compression process.\r
+\r
+  -lc{N}: set number of literal context bits - [0, 8], default: 3\r
+          Sometimes lc=4 gives gain for big files.\r
+\r
+  -lp{N}: set number of literal pos bits - [0, 4], default: 0\r
+          lp switch is intended for periodical data when period is \r
+          equal 2^N. For example, for 32-bit (4 bytes) \r
+          periodical data you can use lp=2. Often it's better to set lc0, \r
+          if you change lp switch.\r
+\r
+  -pb{N}: set number of pos bits - [0, 4], default: 2\r
+          pb switch is intended for periodical data \r
+          when period is equal 2^N.\r
+\r
+  -mf{MF_ID}: set Match Finder. Default: bt4. \r
+              Algorithms from hc* group doesn't provide good compression \r
+              ratio, but they often works pretty fast in combination with \r
+              fast mode (-a0).\r
+\r
+              Memory requirements depend from dictionary size \r
+              (parameter "d" in table below). \r
+\r
+               MF_ID     Memory                   Description\r
+\r
+                bt2    d *  9.5 + 4MB  Binary Tree with 2 bytes hashing.\r
+                bt3    d * 11.5 + 4MB  Binary Tree with 3 bytes hashing.\r
+                bt4    d * 11.5 + 4MB  Binary Tree with 4 bytes hashing.\r
+                hc4    d *  7.5 + 4MB  Hash Chain with 4 bytes hashing.\r
+\r
+  -eos:   write End Of Stream marker. By default LZMA doesn't write \r
+          eos marker, since LZMA decoder knows uncompressed size \r
+          stored in .lzma file header.\r
+\r
+  -si:    Read data from stdin (it will write End Of Stream marker).\r
+  -so:    Write data to stdout\r
+\r
+\r
+Examples:\r
+\r
+1) LZMA e file.bin file.lzma -d16 -lc0 \r
+\r
+compresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)  \r
+and 0 literal context bits. -lc0 allows to reduce memory requirements \r
+for decompression.\r
+\r
+\r
+2) LZMA e file.bin file.lzma -lc0 -lp2\r
+\r
+compresses file.bin to file.lzma with settings suitable \r
+for 32-bit periodical data (for example, ARM or MIPS code).\r
+\r
+3) LZMA d file.lzma file.bin\r
+\r
+decompresses file.lzma to file.bin.\r
+\r
+\r
+Compression ratio hints\r
+-----------------------\r
+\r
+Recommendations\r
+---------------\r
+\r
+To increase the compression ratio for LZMA compressing it's desirable \r
+to have aligned data (if it's possible) and also it's desirable to locate\r
+data in such order, where code is grouped in one place and data is \r
+grouped in other place (it's better than such mixing: code, data, code,\r
+data, ...).\r
+\r
+\r
+Filters\r
+-------\r
+You can increase the compression ratio for some data types, using\r
+special filters before compressing. For example, it's possible to \r
+increase the compression ratio on 5-10% for code for those CPU ISAs: \r
+x86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.\r
+\r
+You can find C source code of such filters in C/Bra*.* files\r
+\r
+You can check the compression ratio gain of these filters with such \r
+7-Zip commands (example for ARM code):\r
+No filter:\r
+  7z a a1.7z a.bin -m0=lzma\r
+\r
+With filter for little-endian ARM code:\r
+  7z a a2.7z a.bin -m0=arm -m1=lzma        \r
+\r
+It works in such manner:\r
+Compressing    = Filter_encoding + LZMA_encoding\r
+Decompressing  = LZMA_decoding + Filter_decoding\r
+\r
+Compressing and decompressing speed of such filters is very high,\r
+so it will not increase decompressing time too much.\r
+Moreover, it reduces decompression time for LZMA_decoding, \r
+since compression ratio with filtering is higher.\r
+\r
+These filters convert CALL (calling procedure) instructions \r
+from relative offsets to absolute addresses, so such data becomes more \r
+compressible.\r
+\r
+For some ISAs (for example, for MIPS) it's impossible to get gain from such filter.\r
+\r
+\r
+\r
+---\r
+\r
+http://www.7-zip.org\r
+http://www.7-zip.org/sdk.html\r
+http://www.7-zip.org/support.html\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/history.txt b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/history.txt
deleted file mode 100644 (file)
index 9bed5eb..0000000
+++ /dev/null
@@ -1,236 +0,0 @@
-HISTORY of the LZMA SDK\r
------------------------\r
-\r
-4.65           2009-02-03\r
--------------------------\r
-- Some minor fixes\r
-\r
-\r
-4.63           2008-12-31\r
--------------------------\r
-- Some minor fixes\r
-\r
-\r
-4.61 beta      2008-11-23\r
--------------------------\r
-- The bug in ANSI-C LZMA Decoder was fixed:\r
-    If encoded stream was corrupted, decoder could access memory \r
-    outside of allocated range.\r
-- Some changes in ANSI-C 7z Decoder interfaces.\r
-- LZMA SDK is placed in the public domain.\r
-\r
-\r
-4.60 beta      2008-08-19\r
--------------------------\r
-- Some minor fixes.\r
-\r
-\r
-4.59 beta      2008-08-13\r
--------------------------\r
-- The bug was fixed:\r
-    LZMA Encoder in fast compression mode could access memory outside of \r
-    allocated range in some rare cases.\r
-\r
-\r
-4.58 beta      2008-05-05\r
--------------------------\r
-- ANSI-C LZMA Decoder was rewritten for speed optimizations.\r
-- ANSI-C LZMA Encoder was included to LZMA SDK.\r
-- C++ LZMA code now is just wrapper over ANSI-C code.\r
-\r
-\r
-4.57           2007-12-12\r
--------------------------\r
-- Speed optimizations in Ã‘++ LZMA Decoder. \r
-- Small changes for more compatibility with some C/C++ compilers.\r
-\r
-\r
-4.49 beta      2007-07-05\r
--------------------------\r
-- .7z ANSI-C Decoder:\r
-     - now it supports BCJ and BCJ2 filters\r
-     - now it supports files larger than 4 GB.\r
-     - now it supports "Last Write Time" field for files.\r
-- C++ code for .7z archives compressing/decompressing from 7-zip \r
-  was included to LZMA SDK.\r
-  \r
-\r
-4.43           2006-06-04\r
--------------------------\r
-- Small changes for more compatibility with some C/C++ compilers.\r
-  \r
-\r
-4.42           2006-05-15\r
--------------------------\r
-- Small changes in .h files in ANSI-C version.\r
-  \r
-\r
-4.39 beta      2006-04-14\r
--------------------------\r
-- The bug in versions 4.33b:4.38b was fixed:\r
-  C++ version of LZMA encoder could not correctly compress \r
-  files larger than 2 GB with HC4 match finder (-mfhc4).\r
-  \r
-\r
-4.37 beta      2005-04-06\r
--------------------------\r
-- Fixes in C++ code: code could no be compiled if _NO_EXCEPTIONS was defined. \r
-\r
-\r
-4.35 beta      2005-03-02\r
--------------------------\r
-- The bug was fixed in C++ version of LZMA Decoder:\r
-    If encoded stream was corrupted, decoder could access memory \r
-    outside of allocated range.\r
-\r
-\r
-4.34 beta      2006-02-27\r
--------------------------\r
-- Compressing speed and memory requirements for compressing were increased\r
-- LZMA now can use only these match finders: HC4, BT2, BT3, BT4\r
-\r
-\r
-4.32           2005-12-09\r
--------------------------\r
-- Java version of LZMA SDK was included\r
-\r
-\r
-4.30           2005-11-20\r
--------------------------\r
-- Compression ratio was improved in -a2 mode\r
-- Speed optimizations for compressing in -a2 mode\r
-- -fb switch now supports values up to 273\r
-- The bug in 7z_C (7zIn.c) was fixed:\r
-  It used Alloc/Free functions from different memory pools.\r
-  So if program used two memory pools, it worked incorrectly.\r
-- 7z_C: .7z format supporting was improved\r
-- LZMA# SDK (C#.NET version) was included\r
-\r
-\r
-4.27 (Updated) 2005-09-21\r
--------------------------\r
-- Some GUIDs/interfaces in C++ were changed.\r
- IStream.h:\r
-   ISequentialInStream::Read now works as old ReadPart\r
-   ISequentialOutStream::Write now works as old WritePart\r
-\r
-\r
-4.27           2005-08-07\r
--------------------------\r
-- The bug in LzmaDecodeSize.c was fixed:\r
-   if _LZMA_IN_CB and _LZMA_OUT_READ were defined,\r
-   decompressing worked incorrectly.\r
-\r
-\r
-4.26           2005-08-05\r
--------------------------\r
-- Fixes in 7z_C code and LzmaTest.c:\r
-  previous versions could work incorrectly,\r
-  if malloc(0) returns 0\r
-\r
-\r
-4.23           2005-06-29\r
--------------------------\r
-- Small fixes in C++ code\r
-\r
-\r
-4.22           2005-06-10\r
--------------------------\r
-- Small fixes\r
-\r
-\r
-4.21           2005-06-08\r
--------------------------\r
-- Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed\r
-- New additional version of ANSI-C LZMA Decoder with zlib-like interface:\r
-    - LzmaStateDecode.h\r
-    - LzmaStateDecode.c\r
-    - LzmaStateTest.c\r
-- ANSI-C LZMA Decoder now can decompress files larger than 4 GB\r
-\r
-\r
-4.17           2005-04-18\r
--------------------------\r
-- New example for RAM->RAM compressing/decompressing: \r
-  LZMA + BCJ (filter for x86 code):\r
-    - LzmaRam.h\r
-    - LzmaRam.cpp\r
-    - LzmaRamDecode.h\r
-    - LzmaRamDecode.c\r
-    - -f86 switch for lzma.exe\r
-\r
-\r
-4.16           2005-03-29\r
--------------------------\r
-- The bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder): \r
-   If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,\r
-   decoder could access memory outside of allocated range.\r
-- Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).\r
-  Old version of LZMA Decoder now is in file LzmaDecodeSize.c. \r
-  LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c\r
-- Small speed optimization in LZMA C++ code\r
-- filter for SPARC's code was added\r
-- Simplified version of .7z ANSI-C Decoder was included\r
-\r
-\r
-4.06           2004-09-05\r
--------------------------\r
-- The bug in v4.05 was fixed:\r
-    LZMA-Encoder didn't release output stream in some cases.\r
-\r
-\r
-4.05           2004-08-25\r
--------------------------\r
-- Source code of filters for x86, IA-64, ARM, ARM-Thumb \r
-  and PowerPC code was included to SDK\r
-- Some internal minor changes\r
-\r
-\r
-4.04           2004-07-28\r
--------------------------\r
-- More compatibility with some C++ compilers\r
-\r
-\r
-4.03           2004-06-18\r
--------------------------\r
-- "Benchmark" command was added. It measures compressing \r
-  and decompressing speed and shows rating values. \r
-  Also it checks hardware errors.\r
-\r
-\r
-4.02           2004-06-10\r
--------------------------\r
-- C++ LZMA Encoder/Decoder code now is more portable\r
-  and it can be compiled by GCC on Linux.\r
-\r
-\r
-4.01           2004-02-15\r
--------------------------\r
-- Some detection of data corruption was enabled.\r
-    LzmaDecode.c / RangeDecoderReadByte\r
-    .....\r
-    {\r
-      rd->ExtraBytes = 1;\r
-      return 0xFF;\r
-    }\r
-\r
-\r
-4.00           2004-02-13\r
--------------------------\r
-- Original version of LZMA SDK\r
-\r
-\r
-\r
-HISTORY of the LZMA\r
--------------------\r
-  2001-2008:  Improvements to LZMA compressing/decompressing code, \r
-              keeping compatibility with original LZMA format\r
-  1996-2001:  Development of LZMA compression format\r
-\r
-  Some milestones:\r
-\r
-  2001-08-30: LZMA compression was added to 7-Zip\r
-  1999-01-02: First version of 7-Zip was released\r
-  \r
-\r
-End of document\r
diff --git a/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/lzma.txt b/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/Sdk/lzma.txt
deleted file mode 100644 (file)
index d4f4af9..0000000
+++ /dev/null
@@ -1,594 +0,0 @@
-LZMA SDK 4.65\r
--------------\r
-\r
-LZMA SDK provides the documentation, samples, header files, libraries, \r
-and tools you need to develop applications that use LZMA compression.\r
-\r
-LZMA is default and general compression method of 7z format\r
-in 7-Zip compression program (www.7-zip.org). LZMA provides high \r
-compression ratio and very fast decompression.\r
-\r
-LZMA is an improved version of famous LZ77 compression algorithm. \r
-It was improved in way of maximum increasing of compression ratio,\r
-keeping high decompression speed and low memory requirements for \r
-decompressing.\r
-\r
-\r
-\r
-LICENSE\r
--------\r
-\r
-LZMA SDK is written and placed in the public domain by Igor Pavlov.\r
-\r
-\r
-LZMA SDK Contents\r
------------------\r
-\r
-LZMA SDK includes:\r
-\r
-  - ANSI-C/C++/C#/Java source code for LZMA compressing and decompressing\r
-  - Compiled file->file LZMA compressing/decompressing program for Windows system\r
-\r
-\r
-UNIX/Linux version \r
-------------------\r
-To compile C++ version of file->file LZMA encoding, go to directory\r
-C++/7zip/Compress/LZMA_Alone \r
-and call make to recompile it:\r
-  make -f makefile.gcc clean all\r
-\r
-In some UNIX/Linux versions you must compile LZMA with static libraries.\r
-To compile with static libraries, you can use \r
-LIB = -lm -static\r
-\r
-\r
-Files\r
----------------------\r
-lzma.txt     - LZMA SDK description (this file)\r
-7zFormat.txt - 7z Format description\r
-7zC.txt      - 7z ANSI-C Decoder description\r
-methods.txt  - Compression method IDs for .7z\r
-lzma.exe     - Compiled file->file LZMA encoder/decoder for Windows\r
-history.txt  - history of the LZMA SDK\r
-\r
-\r
-Source code structure\r
----------------------\r
-\r
-C/  - C files\r
-        7zCrc*.*   - CRC code\r
-        Alloc.*    - Memory allocation functions\r
-        Bra*.*     - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\r
-        LzFind.*   - Match finder for LZ (LZMA) encoders \r
-        LzFindMt.* - Match finder for LZ (LZMA) encoders for multithreading encoding\r
-        LzHash.h   - Additional file for LZ match finder\r
-        LzmaDec.*  - LZMA decoding\r
-        LzmaEnc.*  - LZMA encoding\r
-        LzmaLib.*  - LZMA Library for DLL calling\r
-        Types.h    - Basic types for another .c files\r
-       Threads.*  - The code for multithreading.\r
-\r
-    LzmaLib  - LZMA Library (.DLL for Windows)\r
-    \r
-    LzmaUtil - LZMA Utility (file->file LZMA encoder/decoder).\r
-\r
-    Archive - files related to archiving\r
-      7z     - 7z ANSI-C Decoder\r
-\r
-CPP/ -- CPP files\r
-\r
-  Common  - common files for C++ projects\r
-  Windows - common files for Windows related code\r
-\r
-  7zip    - files related to 7-Zip Project\r
-\r
-    Common   - common files for 7-Zip\r
-\r
-    Compress - files related to compression/decompression\r
-\r
-      Copy         - Copy coder\r
-      RangeCoder   - Range Coder (special code of compression/decompression)\r
-      LZMA         - LZMA compression/decompression on C++\r
-      LZMA_Alone   - file->file LZMA compression/decompression\r
-      Branch       - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\r
-\r
-    Archive - files related to archiving\r
-\r
-      Common   - common files for archive handling\r
-      7z       - 7z C++ Encoder/Decoder\r
-\r
-    Bundles    - Modules that are bundles of other modules\r
-  \r
-      Alone7z           - 7zr.exe: Standalone version of 7z.exe that supports only 7z/LZMA/BCJ/BCJ2\r
-      Format7zR         - 7zr.dll: Reduced version of 7za.dll: extracting/compressing to 7z/LZMA/BCJ/BCJ2\r
-      Format7zExtractR  - 7zxr.dll: Reduced version of 7zxa.dll: extracting from 7z/LZMA/BCJ/BCJ2.\r
-\r
-    UI        - User Interface files\r
-         \r
-      Client7z - Test application for 7za.dll,  7zr.dll, 7zxr.dll\r
-      Common   - Common UI files\r
-      Console  - Code for console archiver\r
-\r
-\r
-\r
-CS/ - C# files\r
-  7zip\r
-    Common   - some common files for 7-Zip\r
-    Compress - files related to compression/decompression\r
-      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\r
-      LZMA         - LZMA compression/decompression\r
-      LzmaAlone    - file->file LZMA compression/decompression\r
-      RangeCoder   - Range Coder (special code of compression/decompression)\r
-\r
-Java/  - Java files\r
-  SevenZip\r
-    Compression    - files related to compression/decompression\r
-      LZ           - files related to LZ (Lempel-Ziv) compression algorithm\r
-      LZMA         - LZMA compression/decompression\r
-      RangeCoder   - Range Coder (special code of compression/decompression)\r
-\r
-\r
-C/C++ source code of LZMA SDK is part of 7-Zip project.\r
-7-Zip source code can be downloaded from 7-Zip's SourceForge page:\r
-\r
-  http://sourceforge.net/projects/sevenzip/\r
-\r
-\r
-\r
-LZMA features\r
--------------\r
-  - Variable dictionary size (up to 1 GB)\r
-  - Estimated compressing speed: about 2 MB/s on 2 GHz CPU\r
-  - Estimated decompressing speed: \r
-      - 20-30 MB/s on 2 GHz Core 2 or AMD Athlon 64\r
-      - 1-2 MB/s on 200 MHz ARM, MIPS, PowerPC or other simple RISC\r
-  - Small memory requirements for decompressing (16 KB + DictionarySize)\r
-  - Small code size for decompressing: 5-8 KB\r
-\r
-LZMA decoder uses only integer operations and can be \r
-implemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).\r
-\r
-Some critical operations that affect the speed of LZMA decompression:\r
-  1) 32*16 bit integer multiply\r
-  2) Misspredicted branches (penalty mostly depends from pipeline length)\r
-  3) 32-bit shift and arithmetic operations\r
-\r
-The speed of LZMA decompressing mostly depends from CPU speed.\r
-Memory speed has no big meaning. But if your CPU has small data cache, \r
-overall weight of memory speed will slightly increase.\r
-\r
-\r
-How To Use\r
-----------\r
-\r
-Using LZMA encoder/decoder executable\r
---------------------------------------\r
-\r
-Usage:  LZMA <e|d> inputFile outputFile [<switches>...]\r
-\r
-  e: encode file\r
-\r
-  d: decode file\r
-\r
-  b: Benchmark. There are two tests: compressing and decompressing \r
-     with LZMA method. Benchmark shows rating in MIPS (million \r
-     instructions per second). Rating value is calculated from \r
-     measured speed and it is normalized with Intel's Core 2 results.\r
-     Also Benchmark checks possible hardware errors (RAM \r
-     errors in most cases). Benchmark uses these settings:\r
-     (-a1, -d21, -fb32, -mfbt4). You can change only -d parameter. \r
-     Also you can change the number of iterations. Example for 30 iterations:\r
-       LZMA b 30\r
-     Default number of iterations is 10.\r
-\r
-<Switches>\r
-  \r
-\r
-  -a{N}:  set compression mode 0 = fast, 1 = normal\r
-          default: 1 (normal)\r
-\r
-  d{N}:   Sets Dictionary size - [0, 30], default: 23 (8MB)\r
-          The maximum value for dictionary size is 1 GB = 2^30 bytes.\r
-          Dictionary size is calculated as DictionarySize = 2^N bytes. \r
-          For decompressing file compressed by LZMA method with dictionary \r
-          size D = 2^N you need about D bytes of memory (RAM).\r
-\r
-  -fb{N}: set number of fast bytes - [5, 273], default: 128\r
-          Usually big number gives a little bit better compression ratio \r
-          and slower compression process.\r
-\r
-  -lc{N}: set number of literal context bits - [0, 8], default: 3\r
-          Sometimes lc=4 gives gain for big files.\r
-\r
-  -lp{N}: set number of literal pos bits - [0, 4], default: 0\r
-          lp switch is intended for periodical data when period is \r
-          equal 2^N. For example, for 32-bit (4 bytes) \r
-          periodical data you can use lp=2. Often it's better to set lc0, \r
-          if you change lp switch.\r
-\r
-  -pb{N}: set number of pos bits - [0, 4], default: 2\r
-          pb switch is intended for periodical data \r
-          when period is equal 2^N.\r
-\r
-  -mf{MF_ID}: set Match Finder. Default: bt4. \r
-              Algorithms from hc* group doesn't provide good compression \r
-              ratio, but they often works pretty fast in combination with \r
-              fast mode (-a0).\r
-\r
-              Memory requirements depend from dictionary size \r
-              (parameter "d" in table below). \r
-\r
-               MF_ID     Memory                   Description\r
-\r
-                bt2    d *  9.5 + 4MB  Binary Tree with 2 bytes hashing.\r
-                bt3    d * 11.5 + 4MB  Binary Tree with 3 bytes hashing.\r
-                bt4    d * 11.5 + 4MB  Binary Tree with 4 bytes hashing.\r
-                hc4    d *  7.5 + 4MB  Hash Chain with 4 bytes hashing.\r
-\r
-  -eos:   write End Of Stream marker. By default LZMA doesn't write \r
-          eos marker, since LZMA decoder knows uncompressed size \r
-          stored in .lzma file header.\r
-\r
-  -si:    Read data from stdin (it will write End Of Stream marker).\r
-  -so:    Write data to stdout\r
-\r
-\r
-Examples:\r
-\r
-1) LZMA e file.bin file.lzma -d16 -lc0 \r
-\r
-compresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)  \r
-and 0 literal context bits. -lc0 allows to reduce memory requirements \r
-for decompression.\r
-\r
-\r
-2) LZMA e file.bin file.lzma -lc0 -lp2\r
-\r
-compresses file.bin to file.lzma with settings suitable \r
-for 32-bit periodical data (for example, ARM or MIPS code).\r
-\r
-3) LZMA d file.lzma file.bin\r
-\r
-decompresses file.lzma to file.bin.\r
-\r
-\r
-Compression ratio hints\r
------------------------\r
-\r
-Recommendations\r
----------------\r
-\r
-To increase the compression ratio for LZMA compressing it's desirable \r
-to have aligned data (if it's possible) and also it's desirable to locate\r
-data in such order, where code is grouped in one place and data is \r
-grouped in other place (it's better than such mixing: code, data, code,\r
-data, ...).\r
-\r
-\r
-Filters\r
--------\r
-You can increase the compression ratio for some data types, using\r
-special filters before compressing. For example, it's possible to \r
-increase the compression ratio on 5-10% for code for those CPU ISAs: \r
-x86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.\r
-\r
-You can find C source code of such filters in C/Bra*.* files\r
-\r
-You can check the compression ratio gain of these filters with such \r
-7-Zip commands (example for ARM code):\r
-No filter:\r
-  7z a a1.7z a.bin -m0=lzma\r
-\r
-With filter for little-endian ARM code:\r
-  7z a a2.7z a.bin -m0=arm -m1=lzma        \r
-\r
-It works in such manner:\r
-Compressing    = Filter_encoding + LZMA_encoding\r
-Decompressing  = LZMA_decoding + Filter_decoding\r
-\r
-Compressing and decompressing speed of such filters is very high,\r
-so it will not increase decompressing time too much.\r
-Moreover, it reduces decompression time for LZMA_decoding, \r
-since compression ratio with filtering is higher.\r
-\r
-These filters convert CALL (calling procedure) instructions \r
-from relative offsets to absolute addresses, so such data becomes more \r
-compressible.\r
-\r
-For some ISAs (for example, for MIPS) it's impossible to get gain from such filter.\r
-\r
-\r
-LZMA compressed file format\r
----------------------------\r
-Offset Size Description\r
-  0     1   Special LZMA properties (lc,lp, pb in encoded form)\r
-  1     4   Dictionary size (little endian)\r
-  5     8   Uncompressed size (little endian). -1 means unknown size\r
- 13         Compressed data\r
-\r
-\r
-ANSI-C LZMA Decoder\r
-~~~~~~~~~~~~~~~~~~~\r
-\r
-Please note that interfaces for ANSI-C code were changed in LZMA SDK 4.58.\r
-If you want to use old interfaces you can download previous version of LZMA SDK\r
-from sourceforge.net site.\r
-\r
-To use ANSI-C LZMA Decoder you need the following files:\r
-1) LzmaDec.h + LzmaDec.c + Types.h\r
-LzmaUtil/LzmaUtil.c is example application that uses these files.\r
-\r
-\r
-Memory requirements for LZMA decoding\r
--------------------------------------\r
-\r
-Stack usage of LZMA decoding function for local variables is not \r
-larger than 200-400 bytes.\r
-\r
-LZMA Decoder uses dictionary buffer and internal state structure.\r
-Internal state structure consumes\r
-  state_size = (4 + (1.5 << (lc + lp))) KB\r
-by default (lc=3, lp=0), state_size = 16 KB.\r
-\r
-\r
-How To decompress data\r
-----------------------\r
-\r
-LZMA Decoder (ANSI-C version) now supports 2 interfaces:\r
-1) Single-call Decompressing\r
-2) Multi-call State Decompressing (zlib-like interface)\r
-\r
-You must use external allocator:\r
-Example:\r
-void *SzAlloc(void *p, size_t size) { p = p; return malloc(size); }\r
-void SzFree(void *p, void *address) { p = p; free(address); }\r
-ISzAlloc alloc = { SzAlloc, SzFree };\r
-\r
-You can use p = p; operator to disable compiler warnings.\r
-\r
-\r
-Single-call Decompressing\r
--------------------------\r
-When to use: RAM->RAM decompressing\r
-Compile files: LzmaDec.h + LzmaDec.c + Types.h\r
-Compile defines: no defines\r
-Memory Requirements:\r
-  - Input buffer: compressed size\r
-  - Output buffer: uncompressed size\r
-  - LZMA Internal Structures: state_size (16 KB for default settings) \r
-\r
-Interface:\r
-  int LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r
-      const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, \r
-      ELzmaStatus *status, ISzAlloc *alloc);\r
-  In: \r
-    dest     - output data\r
-    destLen  - output data size\r
-    src      - input data\r
-    srcLen   - input data size\r
-    propData - LZMA properties  (5 bytes)\r
-    propSize - size of propData buffer (5 bytes)\r
-    finishMode - It has meaning only if the decoding reaches output limit (*destLen).\r
-        LZMA_FINISH_ANY - Decode just destLen bytes.\r
-        LZMA_FINISH_END - Stream must be finished after (*destLen).\r
-                           You can use LZMA_FINISH_END, when you know that \r
-                           current output buffer covers last bytes of stream. \r
-    alloc    - Memory allocator.\r
-\r
-  Out: \r
-    destLen  - processed output size \r
-    srcLen   - processed input size \r
-\r
-  Output:\r
-    SZ_OK\r
-      status:\r
-        LZMA_STATUS_FINISHED_WITH_MARK\r
-        LZMA_STATUS_NOT_FINISHED \r
-        LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r
-    SZ_ERROR_DATA - Data error\r
-    SZ_ERROR_MEM  - Memory allocation error\r
-    SZ_ERROR_UNSUPPORTED - Unsupported properties\r
-    SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).\r
-\r
-  If LZMA decoder sees end_marker before reaching output limit, it returns OK result,\r
-  and output value of destLen will be less than output buffer size limit.\r
-\r
-  You can use multiple checks to test data integrity after full decompression:\r
-    1) Check Result and "status" variable.\r
-    2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.\r
-    3) Check that output(srcLen) = compressedSize, if you know real compressedSize. \r
-       You must use correct finish mode in that case. */ \r
-\r
-\r
-Multi-call State Decompressing (zlib-like interface)\r
-----------------------------------------------------\r
-\r
-When to use: file->file decompressing \r
-Compile files: LzmaDec.h + LzmaDec.c + Types.h\r
-\r
-Memory Requirements:\r
- - Buffer for input stream: any size (for example, 16 KB)\r
- - Buffer for output stream: any size (for example, 16 KB)\r
- - LZMA Internal Structures: state_size (16 KB for default settings) \r
- - LZMA dictionary (dictionary size is encoded in LZMA properties header)\r
-\r
-1) read LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) to header:\r
-   unsigned char header[LZMA_PROPS_SIZE + 8];\r
-   ReadFile(inFile, header, sizeof(header)\r
-\r
-2) Allocate CLzmaDec structures (state + dictionary) using LZMA properties\r
-\r
-  CLzmaDec state;\r
-  LzmaDec_Constr(&state);\r
-  res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc);\r
-  if (res != SZ_OK)\r
-    return res;\r
-\r
-3) Init LzmaDec structure before any new LZMA stream. And call LzmaDec_DecodeToBuf in loop\r
-\r
-  LzmaDec_Init(&state);\r
-  for (;;)\r
-  {\r
-    ... \r
-    int res = LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, \r
-       const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode);\r
-    ...\r
-  }\r
-\r
-\r
-4) Free all allocated structures\r
-  LzmaDec_Free(&state, &g_Alloc);\r
-\r
-For full code example, look at C/LzmaUtil/LzmaUtil.c code.\r
-\r
-\r
-How To compress data\r
---------------------\r
-\r
-Compile files: LzmaEnc.h + LzmaEnc.c + Types.h +\r
-LzFind.c + LzFind.h + LzFindMt.c + LzFindMt.h + LzHash.h\r
-\r
-Memory Requirements:\r
-  - (dictSize * 11.5 + 6 MB) + state_size\r
-\r
-Lzma Encoder can use two memory allocators:\r
-1) alloc - for small arrays.\r
-2) allocBig - for big arrays.\r
-\r
-For example, you can use Large RAM Pages (2 MB) in allocBig allocator for \r
-better compression speed. Note that Windows has bad implementation for \r
-Large RAM Pages. \r
-It's OK to use same allocator for alloc and allocBig.\r
-\r
-\r
-Single-call Compression with callbacks\r
---------------------------------------\r
-\r
-Check C/LzmaUtil/LzmaUtil.c as example, \r
-\r
-When to use: file->file decompressing \r
-\r
-1) you must implement callback structures for interfaces:\r
-ISeqInStream\r
-ISeqOutStream\r
-ICompressProgress\r
-ISzAlloc\r
-\r
-static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r
-static void SzFree(void *p, void *address) {  p = p; MyFree(address); }\r
-static ISzAlloc g_Alloc = { SzAlloc, SzFree };\r
-\r
-  CFileSeqInStream inStream;\r
-  CFileSeqOutStream outStream;\r
-\r
-  inStream.funcTable.Read = MyRead;\r
-  inStream.file = inFile;\r
-  outStream.funcTable.Write = MyWrite;\r
-  outStream.file = outFile;\r
-\r
-\r
-2) Create CLzmaEncHandle object;\r
-\r
-  CLzmaEncHandle enc;\r
-\r
-  enc = LzmaEnc_Create(&g_Alloc);\r
-  if (enc == 0)\r
-    return SZ_ERROR_MEM;\r
-\r
-\r
-3) initialize CLzmaEncProps properties;\r
-\r
-  LzmaEncProps_Init(&props);\r
-\r
-  Then you can change some properties in that structure.\r
-\r
-4) Send LZMA properties to LZMA Encoder\r
-\r
-  res = LzmaEnc_SetProps(enc, &props);\r
-\r
-5) Write encoded properties to header\r
-\r
-    Byte header[LZMA_PROPS_SIZE + 8];\r
-    size_t headerSize = LZMA_PROPS_SIZE;\r
-    UInt64 fileSize;\r
-    int i;\r
-\r
-    res = LzmaEnc_WriteProperties(enc, header, &headerSize);\r
-    fileSize = MyGetFileLength(inFile);\r
-    for (i = 0; i < 8; i++)\r
-      header[headerSize++] = (Byte)(fileSize >> (8 * i));\r
-    MyWriteFileAndCheck(outFile, header, headerSize)\r
-\r
-6) Call encoding function:\r
-      res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable, \r
-        NULL, &g_Alloc, &g_Alloc);\r
-\r
-7) Destroy LZMA Encoder Object\r
-  LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);\r
-\r
-\r
-If callback function return some error code, LzmaEnc_Encode also returns that code.\r
-\r
-\r
-Single-call RAM->RAM Compression\r
---------------------------------\r
-\r
-Single-call RAM->RAM Compression is similar to Compression with callbacks,\r
-but you provide pointers to buffers instead of pointers to stream callbacks:\r
-\r
-HRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r
-    CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, \r
-    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r
-\r
-Return code:\r
-  SZ_OK               - OK\r
-  SZ_ERROR_MEM        - Memory allocation error \r
-  SZ_ERROR_PARAM      - Incorrect paramater\r
-  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r
-  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r
-\r
-\r
-\r
-LZMA Defines\r
-------------\r
-\r
-_LZMA_SIZE_OPT - Enable some optimizations in LZMA Decoder to get smaller executable code.\r
-\r
-_LZMA_PROB32   - It can increase the speed on some 32-bit CPUs, but memory usage for \r
-                 some structures will be doubled in that case.\r
-\r
-_LZMA_UINT32_IS_ULONG  - Define it if int is 16-bit on your compiler and long is 32-bit.\r
-\r
-_LZMA_NO_SYSTEM_SIZE_T  - Define it if you don't want to use size_t type.\r
-\r
-\r
-C++ LZMA Encoder/Decoder \r
-~~~~~~~~~~~~~~~~~~~~~~~~\r
-C++ LZMA code use COM-like interfaces. So if you want to use it, \r
-you can study basics of COM/OLE.\r
-C++ LZMA code is just wrapper over ANSI-C code.\r
-\r
-\r
-C++ Notes\r
-~~~~~~~~~~~~~~~~~~~~~~~~\r
-If you use some C++ code folders in 7-Zip (for example, C++ code for .7z handling),\r
-you must check that you correctly work with "new" operator.\r
-7-Zip can be compiled with MSVC 6.0 that doesn't throw "exception" from "new" operator.\r
-So 7-Zip uses "CPP\Common\NewHandler.cpp" that redefines "new" operator:\r
-operator new(size_t size)\r
-{\r
-  void *p = ::malloc(size);\r
-  if (p == 0)\r
-    throw CNewException();\r
-  return p;\r
-}\r
-If you use MSCV that throws exception for "new" operator, you can compile without \r
-"NewHandler.cpp". So standard exception will be used. Actually some code of \r
-7-Zip catches any exception in internal code and converts it to HRESULT code.\r
-So you don't need to catch CNewException, if you call COM interfaces of 7-Zip.\r
-\r
----\r
-\r
-http://www.7-zip.org\r
-http://www.7-zip.org/sdk.html\r
-http://www.7-zip.org/support.html\r