VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Setup/SelfExtract.c
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2022-02-09 23:47:25 +0100
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2022-02-10 01:21:17 +0100
commit1ef05f24e28938c7a0608b4c6b369094d1dccaa6 (patch)
tree680a5b679c78cd999045abf207bfc7363aa1d9b9 /src/Setup/SelfExtract.c
parent302dc37fb9baa45c5864af533664c4139e209590 (diff)
downloadVeraCrypt-1ef05f24e28938c7a0608b4c6b369094d1dccaa6.tar.gz
VeraCrypt-1ef05f24e28938c7a0608b4c6b369094d1dccaa6.zip
Windows: Reduce the size of installers by almost 50% by using LZMA compression instead of DEFLATE
Diffstat (limited to 'src/Setup/SelfExtract.c')
-rw-r--r--src/Setup/SelfExtract.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/src/Setup/SelfExtract.c b/src/Setup/SelfExtract.c
index acb2a625..d5dd3d2c 100644
--- a/src/Setup/SelfExtract.c
+++ b/src/Setup/SelfExtract.c
@@ -22,6 +22,7 @@
#include "Dir.h"
#include "Language.h"
#include "Resource.h"
+#include "LzmaLib.h"
#include <tchar.h>
#include <Strsafe.h>
@@ -94,24 +95,43 @@ static void PkgInfo (wchar_t *msg)
// Returns 0 if decompression fails or, if successful, returns the size of the decompressed data
static int DecompressBuffer (unsigned char *out, int outSize, unsigned char *in, int len)
{
- uLongf outlen = (uLongf) outSize;
- int ret = uncompress (out, &outlen, in, (uLong) len);
- if (Z_OK == ret)
- return (int) outlen;
- else
- return 0;
+ int outlen = 0;
+ int status;
+ if (len > 5)
+ {
+ // the first 5 bytes of in contain props parameter
+ size_t srcLen = len - 5;
+ size_t outputLen = (size_t) outSize;
+ status = LzmaUncompress (out, &outputLen, in + 5, &srcLen, in, 5);
+ if (status == SZ_OK)
+ {
+ outlen = (int) outputLen;
+ }
+ }
+
+ return outlen;
}
// Returns 0 if compression fails or, if successful, the size of the compressed data
static int CompressBuffer (unsigned char *out, int outSize, unsigned char *in, int len)
{
- uLongf outlen = (uLongf) outSize;
- int ret = compress2 (out, &outlen, in, (uLong) len, Z_BEST_COMPRESSION);
- if (Z_OK == ret)
- return (int) outlen;
- else
- return 0;
+ unsigned char outProps[5];
+ size_t outPropsSize = 5;
+ int outlen = 0;
+ int status;
+ if (outSize > 5)
+ {
+ size_t outputLen = (size_t) (outSize - 5);
+ status = LzmaCompress (out + 5, &outputLen, in, len, outProps, &outPropsSize, 9, 0, -1, -1, -1, -1, -1);
+ if (status == SZ_OK)
+ {
+ memcpy (out, outProps, outPropsSize);
+ outlen = (int) (outputLen + 5);
+ }
+ }
+
+ return outlen;
}