forked from czajowaty/ad_resources_dumper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdResourceUnpacker.hpp
48 lines (41 loc) · 1.22 KB
/
AdResourceUnpacker.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef ADRESOURCEUNPACKER_HPP
#define ADRESOURCEUNPACKER_HPP
#include "BitsHelper.hpp"
#include <QByteArray>
#include <QString>
#include <cstdint>
class AdResourceUnpacker
{
static constexpr uint32_t DEFAULT_OUT_BUFFER_SIZE = 0x2000;
public:
AdResourceUnpacker(uint8_t const* buffer, uint32_t size);
void setOutBufferSize(uint32_t outBufferSize);
QByteArray unpack();
private:
void resetInternalVariables();
void duplicateWrittenBytes(uint16_t offset, uint16_t bytesNumber);
void resizeBufferToWrittenData();
uint8_t readByte();
uint16_t readTwoBytes();
uint8_t readControlBit();
uint8_t readTwoControlBits();
bool readControlBoolFlag();
inline void writeByte(uint8_t byte)
{
if (outPtr_ >= outBufferEnd_)
{ throw QString("Trying to write beyond output buffer."); }
*outPtr_ = byte;
++outPtr_;
}
uint8_t const* inBuffer_;
uint32_t inBufferSize_;
uint8_t const* inBufferEnd_;
uint32_t outBufferSize_{DEFAULT_OUT_BUFFER_SIZE};
uint8_t const* inPtr_;
uint8_t controlByte_;
uint8_t controlByteBitIndex_;
QByteArray outBuffer_;
uint8_t* outPtr_;
uint8_t const* outBufferEnd_;
};
#endif // ADRESOURCEUNPACKER_HPP