1*f6dc9357SAndroid Build Coastguard WorkerLZMA compression 2*f6dc9357SAndroid Build Coastguard Worker---------------- 3*f6dc9357SAndroid Build Coastguard WorkerVersion: 24.07 4*f6dc9357SAndroid Build Coastguard Worker 5*f6dc9357SAndroid Build Coastguard WorkerThis file describes LZMA encoding and decoding functions written in C language. 6*f6dc9357SAndroid Build Coastguard Worker 7*f6dc9357SAndroid Build Coastguard WorkerLZMA is an improved version of famous LZ77 compression algorithm. 8*f6dc9357SAndroid Build Coastguard WorkerIt was improved in way of maximum increasing of compression ratio, 9*f6dc9357SAndroid Build Coastguard Workerkeeping high decompression speed and low memory requirements for 10*f6dc9357SAndroid Build Coastguard Workerdecompressing. 11*f6dc9357SAndroid Build Coastguard Worker 12*f6dc9357SAndroid Build Coastguard WorkerNote: you can read also LZMA Specification (lzma-specification.txt from LZMA SDK) 13*f6dc9357SAndroid Build Coastguard Worker 14*f6dc9357SAndroid Build Coastguard WorkerAlso you can look source code for LZMA encoding and decoding: 15*f6dc9357SAndroid Build Coastguard Worker C/Util/Lzma/LzmaUtil.c 16*f6dc9357SAndroid Build Coastguard Worker 17*f6dc9357SAndroid Build Coastguard Worker 18*f6dc9357SAndroid Build Coastguard WorkerLZMA compressed file format 19*f6dc9357SAndroid Build Coastguard Worker--------------------------- 20*f6dc9357SAndroid Build Coastguard WorkerOffset Size Description 21*f6dc9357SAndroid Build Coastguard Worker 0 1 Special LZMA properties (lc,lp, pb in encoded form) 22*f6dc9357SAndroid Build Coastguard Worker 1 4 Dictionary size (little endian) 23*f6dc9357SAndroid Build Coastguard Worker 5 8 Uncompressed size (little endian). -1 means unknown size 24*f6dc9357SAndroid Build Coastguard Worker 13 Compressed data 25*f6dc9357SAndroid Build Coastguard Worker 26*f6dc9357SAndroid Build Coastguard Worker 27*f6dc9357SAndroid Build Coastguard Worker 28*f6dc9357SAndroid Build Coastguard WorkerANSI-C LZMA Decoder 29*f6dc9357SAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~ 30*f6dc9357SAndroid Build Coastguard Worker 31*f6dc9357SAndroid Build Coastguard WorkerPlease note that interfaces for ANSI-C code were changed in LZMA SDK 4.58. 32*f6dc9357SAndroid Build Coastguard WorkerIf you want to use old interfaces you can download previous version of LZMA SDK 33*f6dc9357SAndroid Build Coastguard Workerfrom sourceforge.net site. 34*f6dc9357SAndroid Build Coastguard Worker 35*f6dc9357SAndroid Build Coastguard WorkerTo use ANSI-C LZMA Decoder you need the following files: 36*f6dc9357SAndroid Build Coastguard Worker1) LzmaDec.h + LzmaDec.c + 7zTypes.h + Precomp.h + Compiler.h 37*f6dc9357SAndroid Build Coastguard Worker 38*f6dc9357SAndroid Build Coastguard WorkerLook example code: 39*f6dc9357SAndroid Build Coastguard Worker C/Util/Lzma/LzmaUtil.c 40*f6dc9357SAndroid Build Coastguard Worker 41*f6dc9357SAndroid Build Coastguard Worker 42*f6dc9357SAndroid Build Coastguard WorkerMemory requirements for LZMA decoding 43*f6dc9357SAndroid Build Coastguard Worker------------------------------------- 44*f6dc9357SAndroid Build Coastguard Worker 45*f6dc9357SAndroid Build Coastguard WorkerStack usage of LZMA decoding function for local variables is not 46*f6dc9357SAndroid Build Coastguard Workerlarger than 200-400 bytes. 47*f6dc9357SAndroid Build Coastguard Worker 48*f6dc9357SAndroid Build Coastguard WorkerLZMA Decoder uses dictionary buffer and internal state structure. 49*f6dc9357SAndroid Build Coastguard WorkerInternal state structure consumes 50*f6dc9357SAndroid Build Coastguard Worker state_size = (4 + (1.5 << (lc + lp))) KB 51*f6dc9357SAndroid Build Coastguard Workerby default (lc=3, lp=0), state_size = 16 KB. 52*f6dc9357SAndroid Build Coastguard Worker 53*f6dc9357SAndroid Build Coastguard Worker 54*f6dc9357SAndroid Build Coastguard WorkerHow To decompress data 55*f6dc9357SAndroid Build Coastguard Worker---------------------- 56*f6dc9357SAndroid Build Coastguard Worker 57*f6dc9357SAndroid Build Coastguard WorkerLZMA Decoder (ANSI-C version) now supports 2 interfaces: 58*f6dc9357SAndroid Build Coastguard Worker1) Single-call Decompressing 59*f6dc9357SAndroid Build Coastguard Worker2) Multi-call State Decompressing (zlib-like interface) 60*f6dc9357SAndroid Build Coastguard Worker 61*f6dc9357SAndroid Build Coastguard WorkerYou must use external allocator: 62*f6dc9357SAndroid Build Coastguard WorkerExample: 63*f6dc9357SAndroid Build Coastguard Workervoid *SzAlloc(void *p, size_t size) { p = p; return malloc(size); } 64*f6dc9357SAndroid Build Coastguard Workervoid SzFree(void *p, void *address) { p = p; free(address); } 65*f6dc9357SAndroid Build Coastguard WorkerISzAlloc alloc = { SzAlloc, SzFree }; 66*f6dc9357SAndroid Build Coastguard Worker 67*f6dc9357SAndroid Build Coastguard WorkerYou can use p = p; operator to disable compiler warnings. 68*f6dc9357SAndroid Build Coastguard Worker 69*f6dc9357SAndroid Build Coastguard Worker 70*f6dc9357SAndroid Build Coastguard WorkerSingle-call Decompressing 71*f6dc9357SAndroid Build Coastguard Worker------------------------- 72*f6dc9357SAndroid Build Coastguard WorkerWhen to use: RAM->RAM decompressing 73*f6dc9357SAndroid Build Coastguard WorkerCompile files: LzmaDec.h + LzmaDec.c + 7zTypes.h 74*f6dc9357SAndroid Build Coastguard WorkerCompile defines: no defines 75*f6dc9357SAndroid Build Coastguard WorkerMemory Requirements: 76*f6dc9357SAndroid Build Coastguard Worker - Input buffer: compressed size 77*f6dc9357SAndroid Build Coastguard Worker - Output buffer: uncompressed size 78*f6dc9357SAndroid Build Coastguard Worker - LZMA Internal Structures: state_size (16 KB for default settings) 79*f6dc9357SAndroid Build Coastguard Worker 80*f6dc9357SAndroid Build Coastguard WorkerInterface: 81*f6dc9357SAndroid Build Coastguard Worker int LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, 82*f6dc9357SAndroid Build Coastguard Worker const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, 83*f6dc9357SAndroid Build Coastguard Worker ELzmaStatus *status, ISzAlloc *alloc); 84*f6dc9357SAndroid Build Coastguard Worker In: 85*f6dc9357SAndroid Build Coastguard Worker dest - output data 86*f6dc9357SAndroid Build Coastguard Worker destLen - output data size 87*f6dc9357SAndroid Build Coastguard Worker src - input data 88*f6dc9357SAndroid Build Coastguard Worker srcLen - input data size 89*f6dc9357SAndroid Build Coastguard Worker propData - LZMA properties (5 bytes) 90*f6dc9357SAndroid Build Coastguard Worker propSize - size of propData buffer (5 bytes) 91*f6dc9357SAndroid Build Coastguard Worker finishMode - It has meaning only if the decoding reaches output limit (*destLen). 92*f6dc9357SAndroid Build Coastguard Worker LZMA_FINISH_ANY - Decode just destLen bytes. 93*f6dc9357SAndroid Build Coastguard Worker LZMA_FINISH_END - Stream must be finished after (*destLen). 94*f6dc9357SAndroid Build Coastguard Worker You can use LZMA_FINISH_END, when you know that 95*f6dc9357SAndroid Build Coastguard Worker current output buffer covers last bytes of stream. 96*f6dc9357SAndroid Build Coastguard Worker alloc - Memory allocator. 97*f6dc9357SAndroid Build Coastguard Worker 98*f6dc9357SAndroid Build Coastguard Worker Out: 99*f6dc9357SAndroid Build Coastguard Worker destLen - processed output size 100*f6dc9357SAndroid Build Coastguard Worker srcLen - processed input size 101*f6dc9357SAndroid Build Coastguard Worker 102*f6dc9357SAndroid Build Coastguard Worker Output: 103*f6dc9357SAndroid Build Coastguard Worker SZ_OK 104*f6dc9357SAndroid Build Coastguard Worker status: 105*f6dc9357SAndroid Build Coastguard Worker LZMA_STATUS_FINISHED_WITH_MARK 106*f6dc9357SAndroid Build Coastguard Worker LZMA_STATUS_NOT_FINISHED 107*f6dc9357SAndroid Build Coastguard Worker LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK 108*f6dc9357SAndroid Build Coastguard Worker SZ_ERROR_DATA - Data error 109*f6dc9357SAndroid Build Coastguard Worker SZ_ERROR_MEM - Memory allocation error 110*f6dc9357SAndroid Build Coastguard Worker SZ_ERROR_UNSUPPORTED - Unsupported properties 111*f6dc9357SAndroid Build Coastguard Worker SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src). 112*f6dc9357SAndroid Build Coastguard Worker 113*f6dc9357SAndroid Build Coastguard Worker If LZMA decoder sees end_marker before reaching output limit, it returns OK result, 114*f6dc9357SAndroid Build Coastguard Worker and output value of destLen will be less than output buffer size limit. 115*f6dc9357SAndroid Build Coastguard Worker 116*f6dc9357SAndroid Build Coastguard Worker You can use multiple checks to test data integrity after full decompression: 117*f6dc9357SAndroid Build Coastguard Worker 1) Check Result and "status" variable. 118*f6dc9357SAndroid Build Coastguard Worker 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize. 119*f6dc9357SAndroid Build Coastguard Worker 3) Check that output(srcLen) = compressedSize, if you know real compressedSize. 120*f6dc9357SAndroid Build Coastguard Worker You must use correct finish mode in that case. */ 121*f6dc9357SAndroid Build Coastguard Worker 122*f6dc9357SAndroid Build Coastguard Worker 123*f6dc9357SAndroid Build Coastguard WorkerMulti-call State Decompressing (zlib-like interface) 124*f6dc9357SAndroid Build Coastguard Worker---------------------------------------------------- 125*f6dc9357SAndroid Build Coastguard Worker 126*f6dc9357SAndroid Build Coastguard WorkerWhen to use: file->file decompressing 127*f6dc9357SAndroid Build Coastguard WorkerCompile files: LzmaDec.h + LzmaDec.c + 7zTypes.h 128*f6dc9357SAndroid Build Coastguard Worker 129*f6dc9357SAndroid Build Coastguard WorkerMemory Requirements: 130*f6dc9357SAndroid Build Coastguard Worker - Buffer for input stream: any size (for example, 16 KB) 131*f6dc9357SAndroid Build Coastguard Worker - Buffer for output stream: any size (for example, 16 KB) 132*f6dc9357SAndroid Build Coastguard Worker - LZMA Internal Structures: state_size (16 KB for default settings) 133*f6dc9357SAndroid Build Coastguard Worker - LZMA dictionary (dictionary size is encoded in LZMA properties header) 134*f6dc9357SAndroid Build Coastguard Worker 135*f6dc9357SAndroid Build Coastguard Worker1) read LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) to header: 136*f6dc9357SAndroid Build Coastguard Worker unsigned char header[LZMA_PROPS_SIZE + 8]; 137*f6dc9357SAndroid Build Coastguard Worker ReadFile(inFile, header, sizeof(header) 138*f6dc9357SAndroid Build Coastguard Worker 139*f6dc9357SAndroid Build Coastguard Worker2) Allocate CLzmaDec structures (state + dictionary) using LZMA properties 140*f6dc9357SAndroid Build Coastguard Worker 141*f6dc9357SAndroid Build Coastguard Worker CLzmaDec state; 142*f6dc9357SAndroid Build Coastguard Worker LzmaDec_Constr(&state); 143*f6dc9357SAndroid Build Coastguard Worker res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc); 144*f6dc9357SAndroid Build Coastguard Worker if (res != SZ_OK) 145*f6dc9357SAndroid Build Coastguard Worker return res; 146*f6dc9357SAndroid Build Coastguard Worker 147*f6dc9357SAndroid Build Coastguard Worker3) Init LzmaDec structure before any new LZMA stream. And call LzmaDec_DecodeToBuf in loop 148*f6dc9357SAndroid Build Coastguard Worker 149*f6dc9357SAndroid Build Coastguard Worker LzmaDec_Init(&state); 150*f6dc9357SAndroid Build Coastguard Worker for (;;) 151*f6dc9357SAndroid Build Coastguard Worker { 152*f6dc9357SAndroid Build Coastguard Worker ... 153*f6dc9357SAndroid Build Coastguard Worker int res = LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, 154*f6dc9357SAndroid Build Coastguard Worker const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode); 155*f6dc9357SAndroid Build Coastguard Worker ... 156*f6dc9357SAndroid Build Coastguard Worker } 157*f6dc9357SAndroid Build Coastguard Worker 158*f6dc9357SAndroid Build Coastguard Worker 159*f6dc9357SAndroid Build Coastguard Worker4) Free all allocated structures 160*f6dc9357SAndroid Build Coastguard Worker LzmaDec_Free(&state, &g_Alloc); 161*f6dc9357SAndroid Build Coastguard Worker 162*f6dc9357SAndroid Build Coastguard WorkerLook example code: 163*f6dc9357SAndroid Build Coastguard Worker C/Util/Lzma/LzmaUtil.c 164*f6dc9357SAndroid Build Coastguard Worker 165*f6dc9357SAndroid Build Coastguard Worker 166*f6dc9357SAndroid Build Coastguard WorkerHow To compress data 167*f6dc9357SAndroid Build Coastguard Worker-------------------- 168*f6dc9357SAndroid Build Coastguard Worker 169*f6dc9357SAndroid Build Coastguard WorkerCompile files: 170*f6dc9357SAndroid Build Coastguard Worker 7zTypes.h 171*f6dc9357SAndroid Build Coastguard Worker Threads.h 172*f6dc9357SAndroid Build Coastguard Worker Threads.c 173*f6dc9357SAndroid Build Coastguard Worker LzmaEnc.h 174*f6dc9357SAndroid Build Coastguard Worker LzmaEnc.c 175*f6dc9357SAndroid Build Coastguard Worker LzFind.h 176*f6dc9357SAndroid Build Coastguard Worker LzFind.c 177*f6dc9357SAndroid Build Coastguard Worker LzFindMt.h 178*f6dc9357SAndroid Build Coastguard Worker LzFindMt.c 179*f6dc9357SAndroid Build Coastguard Worker LzFindOpt.c 180*f6dc9357SAndroid Build Coastguard Worker LzHash.h 181*f6dc9357SAndroid Build Coastguard Worker 182*f6dc9357SAndroid Build Coastguard WorkerMemory Requirements: 183*f6dc9357SAndroid Build Coastguard Worker - (dictSize * 11.5 + 6 MB) + state_size 184*f6dc9357SAndroid Build Coastguard Worker 185*f6dc9357SAndroid Build Coastguard WorkerLzma Encoder can use two memory allocators: 186*f6dc9357SAndroid Build Coastguard Worker1) alloc - for small arrays. 187*f6dc9357SAndroid Build Coastguard Worker2) allocBig - for big arrays. 188*f6dc9357SAndroid Build Coastguard Worker 189*f6dc9357SAndroid Build Coastguard WorkerFor example, you can use Large RAM Pages (2 MB) in allocBig allocator for 190*f6dc9357SAndroid Build Coastguard Workerbetter compression speed. Note that Windows has bad implementation for 191*f6dc9357SAndroid Build Coastguard WorkerLarge RAM Pages. 192*f6dc9357SAndroid Build Coastguard WorkerIt's OK to use same allocator for alloc and allocBig. 193*f6dc9357SAndroid Build Coastguard Worker 194*f6dc9357SAndroid Build Coastguard Worker 195*f6dc9357SAndroid Build Coastguard WorkerSingle-call Compression with callbacks 196*f6dc9357SAndroid Build Coastguard Worker-------------------------------------- 197*f6dc9357SAndroid Build Coastguard Worker 198*f6dc9357SAndroid Build Coastguard WorkerLook example code: 199*f6dc9357SAndroid Build Coastguard Worker C/Util/Lzma/LzmaUtil.c 200*f6dc9357SAndroid Build Coastguard Worker 201*f6dc9357SAndroid Build Coastguard WorkerWhen to use: file->file compressing 202*f6dc9357SAndroid Build Coastguard Worker 203*f6dc9357SAndroid Build Coastguard Worker1) you must implement callback structures for interfaces: 204*f6dc9357SAndroid Build Coastguard WorkerISeqInStream 205*f6dc9357SAndroid Build Coastguard WorkerISeqOutStream 206*f6dc9357SAndroid Build Coastguard WorkerICompressProgress 207*f6dc9357SAndroid Build Coastguard WorkerISzAlloc 208*f6dc9357SAndroid Build Coastguard Worker 209*f6dc9357SAndroid Build Coastguard Workerstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); } 210*f6dc9357SAndroid Build Coastguard Workerstatic void SzFree(void *p, void *address) { p = p; MyFree(address); } 211*f6dc9357SAndroid Build Coastguard Workerstatic ISzAlloc g_Alloc = { SzAlloc, SzFree }; 212*f6dc9357SAndroid Build Coastguard Worker 213*f6dc9357SAndroid Build Coastguard Worker CFileSeqInStream inStream; 214*f6dc9357SAndroid Build Coastguard Worker CFileSeqOutStream outStream; 215*f6dc9357SAndroid Build Coastguard Worker 216*f6dc9357SAndroid Build Coastguard Worker inStream.funcTable.Read = MyRead; 217*f6dc9357SAndroid Build Coastguard Worker inStream.file = inFile; 218*f6dc9357SAndroid Build Coastguard Worker outStream.funcTable.Write = MyWrite; 219*f6dc9357SAndroid Build Coastguard Worker outStream.file = outFile; 220*f6dc9357SAndroid Build Coastguard Worker 221*f6dc9357SAndroid Build Coastguard Worker 222*f6dc9357SAndroid Build Coastguard Worker2) Create CLzmaEncHandle object; 223*f6dc9357SAndroid Build Coastguard Worker 224*f6dc9357SAndroid Build Coastguard Worker CLzmaEncHandle enc; 225*f6dc9357SAndroid Build Coastguard Worker 226*f6dc9357SAndroid Build Coastguard Worker enc = LzmaEnc_Create(&g_Alloc); 227*f6dc9357SAndroid Build Coastguard Worker if (enc == 0) 228*f6dc9357SAndroid Build Coastguard Worker return SZ_ERROR_MEM; 229*f6dc9357SAndroid Build Coastguard Worker 230*f6dc9357SAndroid Build Coastguard Worker 231*f6dc9357SAndroid Build Coastguard Worker3) initialize CLzmaEncProps properties; 232*f6dc9357SAndroid Build Coastguard Worker 233*f6dc9357SAndroid Build Coastguard Worker LzmaEncProps_Init(&props); 234*f6dc9357SAndroid Build Coastguard Worker 235*f6dc9357SAndroid Build Coastguard Worker Then you can change some properties in that structure. 236*f6dc9357SAndroid Build Coastguard Worker 237*f6dc9357SAndroid Build Coastguard Worker4) Send LZMA properties to LZMA Encoder 238*f6dc9357SAndroid Build Coastguard Worker 239*f6dc9357SAndroid Build Coastguard Worker res = LzmaEnc_SetProps(enc, &props); 240*f6dc9357SAndroid Build Coastguard Worker 241*f6dc9357SAndroid Build Coastguard Worker5) Write encoded properties to header 242*f6dc9357SAndroid Build Coastguard Worker 243*f6dc9357SAndroid Build Coastguard Worker Byte header[LZMA_PROPS_SIZE + 8]; 244*f6dc9357SAndroid Build Coastguard Worker size_t headerSize = LZMA_PROPS_SIZE; 245*f6dc9357SAndroid Build Coastguard Worker UInt64 fileSize; 246*f6dc9357SAndroid Build Coastguard Worker int i; 247*f6dc9357SAndroid Build Coastguard Worker 248*f6dc9357SAndroid Build Coastguard Worker res = LzmaEnc_WriteProperties(enc, header, &headerSize); 249*f6dc9357SAndroid Build Coastguard Worker fileSize = MyGetFileLength(inFile); 250*f6dc9357SAndroid Build Coastguard Worker for (i = 0; i < 8; i++) 251*f6dc9357SAndroid Build Coastguard Worker header[headerSize++] = (Byte)(fileSize >> (8 * i)); 252*f6dc9357SAndroid Build Coastguard Worker MyWriteFileAndCheck(outFile, header, headerSize) 253*f6dc9357SAndroid Build Coastguard Worker 254*f6dc9357SAndroid Build Coastguard Worker6) Call encoding function: 255*f6dc9357SAndroid Build Coastguard Worker res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable, 256*f6dc9357SAndroid Build Coastguard Worker NULL, &g_Alloc, &g_Alloc); 257*f6dc9357SAndroid Build Coastguard Worker 258*f6dc9357SAndroid Build Coastguard Worker7) Destroy LZMA Encoder Object 259*f6dc9357SAndroid Build Coastguard Worker LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc); 260*f6dc9357SAndroid Build Coastguard Worker 261*f6dc9357SAndroid Build Coastguard Worker 262*f6dc9357SAndroid Build Coastguard WorkerIf callback function return some error code, LzmaEnc_Encode also returns that code 263*f6dc9357SAndroid Build Coastguard Workeror it can return the code like SZ_ERROR_READ, SZ_ERROR_WRITE or SZ_ERROR_PROGRESS. 264*f6dc9357SAndroid Build Coastguard Worker 265*f6dc9357SAndroid Build Coastguard Worker 266*f6dc9357SAndroid Build Coastguard WorkerSingle-call RAM->RAM Compression 267*f6dc9357SAndroid Build Coastguard Worker-------------------------------- 268*f6dc9357SAndroid Build Coastguard Worker 269*f6dc9357SAndroid Build Coastguard WorkerSingle-call RAM->RAM Compression is similar to Compression with callbacks, 270*f6dc9357SAndroid Build Coastguard Workerbut you provide pointers to buffers instead of pointers to stream callbacks: 271*f6dc9357SAndroid Build Coastguard Worker 272*f6dc9357SAndroid Build Coastguard WorkerSRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, 273*f6dc9357SAndroid Build Coastguard Worker const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, 274*f6dc9357SAndroid Build Coastguard Worker ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); 275*f6dc9357SAndroid Build Coastguard Worker 276*f6dc9357SAndroid Build Coastguard WorkerReturn code: 277*f6dc9357SAndroid Build Coastguard Worker SZ_OK - OK 278*f6dc9357SAndroid Build Coastguard Worker SZ_ERROR_MEM - Memory allocation error 279*f6dc9357SAndroid Build Coastguard Worker SZ_ERROR_PARAM - Incorrect paramater 280*f6dc9357SAndroid Build Coastguard Worker SZ_ERROR_OUTPUT_EOF - output buffer overflow 281*f6dc9357SAndroid Build Coastguard Worker SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) 282*f6dc9357SAndroid Build Coastguard Worker 283*f6dc9357SAndroid Build Coastguard Worker 284*f6dc9357SAndroid Build Coastguard Worker 285*f6dc9357SAndroid Build Coastguard WorkerDefines 286*f6dc9357SAndroid Build Coastguard Worker------- 287*f6dc9357SAndroid Build Coastguard Worker 288*f6dc9357SAndroid Build Coastguard WorkerZ7_LZMA_SIZE_OPT - Enable some code size optimizations in LZMA Decoder to get smaller executable code. 289*f6dc9357SAndroid Build Coastguard Worker 290*f6dc9357SAndroid Build Coastguard WorkerZ7_LZMA_PROB32 - It can increase the speed on some 32-bit CPUs, but memory usage for 291*f6dc9357SAndroid Build Coastguard Worker some structures will be doubled in that case. 292*f6dc9357SAndroid Build Coastguard Worker 293*f6dc9357SAndroid Build Coastguard WorkerZ7_DECL_Int32_AS_long - Define it if int is 16-bit on your compiler and long is 32-bit. 294*f6dc9357SAndroid Build Coastguard Worker 295*f6dc9357SAndroid Build Coastguard WorkerZ7_DECL_SizeT_AS_unsigned_int - Define it if you don't want to use size_t type. 296*f6dc9357SAndroid Build Coastguard Worker 297*f6dc9357SAndroid Build Coastguard Worker 298*f6dc9357SAndroid Build Coastguard WorkerDefines for 7z decoder written in C 299*f6dc9357SAndroid Build Coastguard Worker----------------------------------- 300*f6dc9357SAndroid Build Coastguard WorkerThese defines are for 7zDec.c only (the decoder in C). 301*f6dc9357SAndroid Build Coastguard WorkerC++ 7z decoder doesn't uses these macros. 302*f6dc9357SAndroid Build Coastguard Worker 303*f6dc9357SAndroid Build Coastguard WorkerZ7_PPMD_SUPPORT - define it if you need PPMD method support. 304*f6dc9357SAndroid Build Coastguard WorkerZ7_NO_METHODS_FILTERS - do not use filters (except of BCJ2 filter). 305*f6dc9357SAndroid Build Coastguard WorkerZ7_USE_NATIVE_BRANCH_FILTER - use filter for native ISA: 306*f6dc9357SAndroid Build Coastguard Worker use x86 filter, if compiled to x86 executable, 307*f6dc9357SAndroid Build Coastguard Worker use arm64 filter, if compiled to arm64 executable. 308*f6dc9357SAndroid Build Coastguard Worker 309*f6dc9357SAndroid Build Coastguard Worker 310*f6dc9357SAndroid Build Coastguard WorkerC++ LZMA Encoder/Decoder 311*f6dc9357SAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~ 312*f6dc9357SAndroid Build Coastguard WorkerC++ LZMA code use COM-like interfaces. So if you want to use it, 313*f6dc9357SAndroid Build Coastguard Workeryou can study basics of COM/OLE. 314*f6dc9357SAndroid Build Coastguard WorkerC++ LZMA code is just wrapper over ANSI-C code. 315*f6dc9357SAndroid Build Coastguard Worker 316*f6dc9357SAndroid Build Coastguard Worker 317*f6dc9357SAndroid Build Coastguard WorkerC++ Notes 318*f6dc9357SAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~ 319*f6dc9357SAndroid Build Coastguard WorkerIf you use some C++ code folders in 7-Zip (for example, C++ code for 7z archive handling), 320*f6dc9357SAndroid Build Coastguard Workeryou must check that you correctly work with "new" operator. 321*f6dc9357SAndroid Build Coastguard Worker7-Zip can be compiled with MSVC 6.0 that doesn't throw "exception" from "new" operator. 322*f6dc9357SAndroid Build Coastguard WorkerSo 7-Zip uses "CPP\Common\NewHandler.cpp" that redefines "new" operator, 323*f6dc9357SAndroid Build Coastguard Workerif compiled by old MSVC compilers (MSVC before version VS 2010): 324*f6dc9357SAndroid Build Coastguard Worker 325*f6dc9357SAndroid Build Coastguard Workeroperator new(size_t size) 326*f6dc9357SAndroid Build Coastguard Worker{ 327*f6dc9357SAndroid Build Coastguard Worker void *p = ::malloc(size); 328*f6dc9357SAndroid Build Coastguard Worker if (!p) 329*f6dc9357SAndroid Build Coastguard Worker throw CNewException(); 330*f6dc9357SAndroid Build Coastguard Worker return p; 331*f6dc9357SAndroid Build Coastguard Worker} 332*f6dc9357SAndroid Build Coastguard Worker 333*f6dc9357SAndroid Build Coastguard WorkerIf the compiler is VS 2010 or newer, NewHandler.cpp doesn't redefine "new" operator. 334*f6dc9357SAndroid Build Coastguard WorkerSp if you use new compiler (VS 2010 or newer), you still can include "NewHandler.cpp" 335*f6dc9357SAndroid Build Coastguard Workerto compilation, and it will not redefine operator new. 336*f6dc9357SAndroid Build Coastguard WorkerAlso you can compile without "NewHandler.cpp" with new compilers. 337*f6dc9357SAndroid Build Coastguard WorkerIf 7-zip doesn't redefine operator "new", standard exception will be used instead of CNewException. 338*f6dc9357SAndroid Build Coastguard WorkerSome code of 7-Zip catches any exception in internal code and converts it to HRESULT code. 339*f6dc9357SAndroid Build Coastguard WorkerSo you don't need to catch CNewException, if you call COM interfaces of 7-Zip. 340*f6dc9357SAndroid Build Coastguard Worker 341*f6dc9357SAndroid Build Coastguard Worker--- 342*f6dc9357SAndroid Build Coastguard Worker 343*f6dc9357SAndroid Build Coastguard Workerhttp://www.7-zip.org 344*f6dc9357SAndroid Build Coastguard Workerhttp://www.7-zip.org/sdk.html 345*f6dc9357SAndroid Build Coastguard Workerhttp://www.7-zip.org/support.html 346