Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.4 KiB

  1. /* Lzma86Dec.c -- LZMA + x86 (BCJ) Filter Decoder
  2. 2009-08-14 : Igor Pavlov : Public domain */
  3. #include "Lzma86.h"
  4. #include "Alloc.h"
  5. #include "Bra.h"
  6. #include "LzmaDec.h"
  7. static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
  8. static void SzFree(void *p, void *address) { p = p; MyFree(address); }
  9. SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize)
  10. {
  11. unsigned i;
  12. if (srcLen < LZMA86_HEADER_SIZE)
  13. return SZ_ERROR_INPUT_EOF;
  14. *unpackSize = 0;
  15. for (i = 0; i < sizeof(UInt64); i++)
  16. *unpackSize += ((UInt64)src[LZMA86_SIZE_OFFSET + i]) << (8 * i);
  17. return SZ_OK;
  18. }
  19. SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen)
  20. {
  21. ISzAlloc g_Alloc = { SzAlloc, SzFree };
  22. SRes res;
  23. int useFilter;
  24. SizeT inSizePure;
  25. ELzmaStatus status;
  26. if (*srcLen < LZMA86_HEADER_SIZE)
  27. return SZ_ERROR_INPUT_EOF;
  28. useFilter = src[0];
  29. if (useFilter > 1)
  30. {
  31. *destLen = 0;
  32. return SZ_ERROR_UNSUPPORTED;
  33. }
  34. inSizePure = *srcLen - LZMA86_HEADER_SIZE;
  35. res = LzmaDecode(dest, destLen, src + LZMA86_HEADER_SIZE, &inSizePure,
  36. src + 1, LZMA_PROPS_SIZE, LZMA_FINISH_ANY, &status, &g_Alloc);
  37. *srcLen = inSizePure + LZMA86_HEADER_SIZE;
  38. if (res != SZ_OK)
  39. return res;
  40. if (useFilter == 1)
  41. {
  42. UInt32 x86State;
  43. x86_Convert_Init(x86State);
  44. x86_Convert(dest, *destLen, 0, &x86State, 0);
  45. }
  46. return SZ_OK;
  47. }