Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/dep/lzma/src/Lzma86Dec.c
4253 views
1
/* Lzma86Dec.c -- LZMA + x86 (BCJ) Filter Decoder
2
2023-03-03 : Igor Pavlov : Public domain */
3
4
#include "Precomp.h"
5
6
#include "Lzma86.h"
7
8
#include "Alloc.h"
9
#include "Bra.h"
10
#include "LzmaDec.h"
11
12
SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize)
13
{
14
unsigned i;
15
if (srcLen < LZMA86_HEADER_SIZE)
16
return SZ_ERROR_INPUT_EOF;
17
*unpackSize = 0;
18
for (i = 0; i < sizeof(UInt64); i++)
19
*unpackSize += ((UInt64)src[LZMA86_SIZE_OFFSET + i]) << (8 * i);
20
return SZ_OK;
21
}
22
23
SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen)
24
{
25
SRes res;
26
int useFilter;
27
SizeT inSizePure;
28
ELzmaStatus status;
29
30
if (*srcLen < LZMA86_HEADER_SIZE)
31
return SZ_ERROR_INPUT_EOF;
32
33
useFilter = src[0];
34
35
if (useFilter > 1)
36
{
37
*destLen = 0;
38
return SZ_ERROR_UNSUPPORTED;
39
}
40
41
inSizePure = *srcLen - LZMA86_HEADER_SIZE;
42
res = LzmaDecode(dest, destLen, src + LZMA86_HEADER_SIZE, &inSizePure,
43
src + 1, LZMA_PROPS_SIZE, LZMA_FINISH_ANY, &status, &g_Alloc);
44
*srcLen = inSizePure + LZMA86_HEADER_SIZE;
45
if (res != SZ_OK)
46
return res;
47
if (useFilter == 1)
48
{
49
UInt32 x86State = Z7_BRANCH_CONV_ST_X86_STATE_INIT_VAL;
50
z7_BranchConvSt_X86_Dec(dest, *destLen, 0, &x86State);
51
}
52
return SZ_OK;
53
}
54
55