Ask no questions:
This is the core LZMA depacker and compressor code from the private build of my EXE/DLL packer. Figured it might be useful to some people. Decided not to use LZMA2 since that seems to be just focused on format changes and not actual algorithm changes.
The depacker code is modified from the original to save size and the main compression function focuses on compression ratio.
Example (using lzma.cpp to pack and LzmaDecodeSize.c to depack):
Prototype of decoder is:
Code:
extern "C" { void LzmaDecode(UInt16* workmem,
const unsigned char *inStream, SizeT inSize,
unsigned char *outStream, SizeT outSize);
}
Example:
Code:
DWORD compressed;
DWORD original_sz;
BYTE *Original = Load_Input_File("unpacker.bin", &original_sz);
BYTE* compressed_data = compress_lzma(Original, original_sz, &compressed);
PVOID testmem = (unsigned char*)malloc(original_sz);
unsigned char* workmem = (unsigned char*)malloc(0xC4000);
LzmaDecode((UInt16*)workmem, compressed_data + LZMA_PROPS_SIZE, (SizeT)compressed - LZMA_PROPS_SIZE, (unsigned char*)testmem, (SizeT)original_sz);
free(Original);
free(compressed_data);
free(workmem);
free(testmem);
There is a ASM version as well of the C function which is slightly modified for more space savings, which was decompiled from the original MSVC2015 compiled code.