minlzlib.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*++
  2. Copyright (c) Alex Ionescu. All rights reserved.
  3. Module Name:
  4. minlzlib.h
  5. Abstract:
  6. This header file is the main include for the minlz library. It contains the
  7. internal function definitions for the history \& input buffers, the LZMA and
  8. LZMA2 decoders, and the arithmetic (de)coder.
  9. Author:
  10. Alex Ionescu (@aionescu) 15-Apr-2020 - Initial version
  11. Environment:
  12. Windows & Linux, user mode and kernel mode.
  13. --*/
  14. #pragma once
  15. //
  16. // C Standard Headers
  17. //
  18. #include <stddef.h>
  19. #include <stdint.h>
  20. #include <stdbool.h>
  21. #include <assert.h>
  22. //
  23. // Input Buffer Management
  24. //
  25. bool BfRead(uint8_t* Byte);
  26. bool BfSeek(uint32_t Length, const uint8_t** Bytes);
  27. bool BfAlign(void);
  28. void BfInitialize(const uint8_t* InputBuffer, uint32_t InputSize);
  29. bool BfSetSoftLimit(uint32_t Remaining);
  30. void BfResetSoftLimit(void);
  31. //
  32. // Dictionary (History Buffer) Management
  33. //
  34. bool DtRepeatSymbol(uint32_t Length, uint32_t Distance);
  35. void DtInitialize(uint8_t* HistoryBuffer, uint32_t Position, uint32_t Offset);
  36. bool DtSetLimit(uint32_t Limit);
  37. void DtPutSymbol(uint8_t Symbol);
  38. uint8_t DtGetSymbol(uint32_t Distance);
  39. bool DtCanWrite(uint32_t* Position);
  40. bool DtIsComplete(uint32_t* BytesProcessed);
  41. //
  42. // Range Decoder
  43. //
  44. uint8_t RcGetBitTree(uint16_t* BitModel, uint16_t Limit);
  45. uint8_t RcGetReverseBitTree(uint16_t* BitModel, uint8_t HighestBit);
  46. uint8_t RcDecodeMatchedBitTree(uint16_t* BitModel, uint8_t MatchByte);
  47. uint32_t RcGetFixed(uint8_t HighestBit);
  48. bool RcInitialize(uint16_t* ChunkSize);
  49. uint8_t RcIsBitSet(uint16_t* Probability);
  50. void RcNormalize(void);
  51. bool RcCanRead(void);
  52. bool RcIsComplete(uint32_t* Offset);
  53. void RcSetDefaultProbability(uint16_t* Probability);
  54. //
  55. // LZMA Decoder
  56. //
  57. bool LzDecode(void);
  58. bool LzInitialize(uint8_t Properties);
  59. void LzResetState(void);
  60. //
  61. // LZMA2 Decoder
  62. //
  63. bool Lz2DecodeStream(uint32_t* BytesProcessed, bool GetSizeOnly);
  64. #ifdef MINLZ_INTEGRITY_CHECKS
  65. //
  66. // Integrity checks require metadata parsing and validation
  67. //
  68. #define MINLZ_META_CHECKS 1
  69. //
  70. // Checksum Management
  71. //
  72. uint32_t XzCrc32(uint32_t Crc, const uint8_t* Buffer, uint32_t Length);
  73. uint64_t XzCrc64(uint64_t Crc, const uint8_t* Buffer, uint32_t Length);
  74. #define Crc32(Buffer, Length) XzCrc32(0, (const uint8_t*)Buffer, Length)
  75. #define Crc64(Buffer, Length) XzCrc64(0, (const uint8_t*)Buffer, Length)
  76. #endif