XPKMain.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Copyright (C) Teemu Suutari */
  2. #ifndef XPKMAIN_HPP
  3. #define XPKMAIN_HPP
  4. #include "Decompressor.hpp"
  5. #include "XPKDecompressor.hpp"
  6. #include <vector>
  7. namespace ancient::internal
  8. {
  9. class XPKMain : public Decompressor
  10. {
  11. friend class XPKDecompressor;
  12. public:
  13. XPKMain(const Buffer &packedData,bool verify,uint32_t recursionLevel);
  14. virtual ~XPKMain();
  15. virtual const std::string &getName() const noexcept override final;
  16. virtual size_t getPackedSize() const noexcept override final;
  17. virtual size_t getRawSize() const noexcept override final;
  18. virtual void decompressImpl(Buffer &rawData,bool verify) override final;
  19. static bool detectHeader(uint32_t hdr) noexcept;
  20. static std::shared_ptr<Decompressor> create(const Buffer &packedData,bool exactSizeKnown,bool verify);
  21. // Can be used to create directly decoder for chunk (needed by CYB2)
  22. static std::shared_ptr<XPKDecompressor> createDecompressor(uint32_t type,uint32_t recursionLevel,const Buffer &buffer,std::shared_ptr<XPKDecompressor::State> &state,bool verify);
  23. private:
  24. static void registerDecompressor(bool(*detect)(uint32_t),std::shared_ptr<XPKDecompressor>(*create)(uint32_t,uint32_t,const Buffer&,std::shared_ptr<XPKDecompressor::State>&,bool));
  25. static constexpr uint32_t getMaxRecursionLevel() noexcept { return 4; }
  26. template <typename F>
  27. void forEachChunk(F func) const;
  28. const Buffer &_packedData;
  29. uint32_t _packedSize=0;
  30. uint32_t _rawSize=0;
  31. uint32_t _headerSize=0;
  32. uint32_t _type=0;
  33. bool _longHeaders=false;
  34. uint32_t _recursionLevel=0;
  35. };
  36. }
  37. #endif