-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unpacker.h
65 lines (50 loc) · 1.62 KB
/
Unpacker.h
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once
#include <vector>
#include <string>
#include <fstream>
#include <exception>
#include <filesystem>
#include "PakTypes.h"
#ifdef USE_LZ4
#include "lz4hc.h"
#endif
#ifdef USE_ZSTD
#include "zstd.h"
#endif
#ifdef USE_ZLIB
#include "External/miniz/miniz.h"
#endif
#ifdef USE_ENCRYPTION
#include "sodium.h"
#endif
class Unpacker {
public:
std::vector<char> ExtractFileToMemory(
PakTypes::PakFile &pakFile,
const std::string &filePath
);
void ExtractFileToDisk(
PakTypes::PakFile &pakFile,
const std::string &outputPath,
const std::string &filePath
);
static PakTypes::PakFile ParsePakFile(const std::string &inputPath);
#ifdef USE_ENCRYPTION
void Decrypt(std::vector<char> &dataBuffer) const;
[[nodiscard]] size_t getEncryptionOpsLimit() const { return encryptionOpsLimit; }
void setEncryptionOpsLimit(size_t limit) { encryptionOpsLimit = limit; }
[[nodiscard]] size_t getEncryptionMemLimit() const { return encryptionMemLimit; }
void setEncryptionMemLimit(size_t limit) { encryptionMemLimit = limit; }
[[nodiscard]] std::string getPassword() const { return password; }
void setPassword(std::string &pwd) { password = pwd; }
#endif
private:
#ifdef USE_ENCRYPTION
size_t encryptionOpsLimit = crypto_pwhash_OPSLIMIT_MIN;
size_t encryptionMemLimit = crypto_pwhash_MEMLIMIT_MIN;
std::string password;
unsigned char salt[crypto_pwhash_SALTBYTES];
unsigned char key[crypto_secretbox_xchacha20poly1305_KEYBYTES];
void GenerateEncryptionKey();
#endif
};