static SRes Decode(ISeqOutStream *outStream, ISeqInStream *inStream) { UInt64 unpackSize; int i; SRes res = 0; CLzmaDec state; /* header: 5 bytes of LZMA properties and 8 bytes of uncompressed size */ unsigned char header[LZMA_PROPS_SIZE + 8]; /* Read and parse header */ RINOK(SeqInStream_Read(inStream, header, sizeof(header))); unpackSize = 0; for (i = 0; i < 8; i++) unpackSize += (UInt64)header[LZMA_PROPS_SIZE + i] << (i * 8); LzmaDec_Construct(&state); RINOK(LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc)); res = Decode2(&state, outStream, inStream, unpackSize); LzmaDec_Free(&state, &g_Alloc); return res; }
static SRes Decode(ISeqOutStream *outStream, ISeqInStream *inStream, Gate2<int64, int64> progress) { UInt64 unpackSize; int i; SRes res = 0; CLzmaDec state; /* header: 5 bytes of LZMA properties and 8 bytes of uncompressed size */ unsigned char header[LZMA_PROPS_SIZE + 8]; /* Read and parse header */ IUppInStream *is = (IUppInStream *)inStream; if(is->in.Get(header, sizeof(header)) != sizeof(header)) return SZ_ERROR_READ; unpackSize = 0; for(i = 0; i < 8; i++) unpackSize += (UInt64)header[LZMA_PROPS_SIZE + i] << (i * 8); LzmaDec_Construct(&state); RINOK(LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc)); res = Decode2(&state, outStream, inStream, unpackSize, progress); LzmaDec_Free(&state, &g_Alloc); return res; }
/// Decode /// /// Remark: pvSrc can be used to decrypt the first part /// /// @param archive Archive /// @param src Compressed data /// @param src_size Compressed data size /// bool CPB2A::Decode(CArcFile* archive, u8* src, size_t src_size) { // Decrypt Decrypt(src, src_size); // Get image information const u16 type = *reinterpret_cast<u16*>(&src[16]); const s32 width = *reinterpret_cast<u16*>(&src[18]); const s32 height = *reinterpret_cast<u16*>(&src[20]); const u16 bpp = *reinterpret_cast<u16*>(&src[22]); // Decompression switch (type) { case 1: Decode1(archive, src, src_size, width, height, bpp); break; case 2: Decode2(archive, src, src_size, width, height, bpp); break; case 3: case 4: Decode4(archive, src, src_size, width, height, bpp); break; case 5: Decode5(archive, src, src_size, width, height, bpp); break; case 6: Decode6(archive, src, src_size, width, height, bpp); break; default: // Unknown archive->OpenFile(); archive->WriteFile(src, src_size); break; } return true; }