new pack system

This commit is contained in:
d1str4ught
2025-09-21 05:28:55 +02:00
parent 775cb2f927
commit 5b1d3c6bce
100 changed files with 5269 additions and 5825 deletions

View File

@@ -1,4 +1,3 @@
#include <cstdint>
#include <map>
#include <fstream>
#include <iostream>
@@ -7,36 +6,7 @@
#include <zstd.h>
#include <argparse.hpp>
#include <gcm.h>
#include <modes.h>
#include <osrng.h>
#include <secblock.h>
#include <camellia.h>
constexpr std::array<uint8_t, 32> PACK_KEY = {
0x00,0x11,0x22,0x33, 0x44,0x55,0x66,0x77,
0x88,0x99,0xAA,0xBB, 0xCC,0xDD,0xEE,0xFF,
0x01,0x23,0x45,0x67, 0x89,0xAB,0xCD,0xEF,
0xFE,0xDC,0xBA,0x98, 0x76,0x54,0x32,0x10
};
#pragma pack(push, 1)
struct TPackFileHeader
{
uint64_t entry_num;
uint64_t data_begin;
uint8_t iv[CryptoPP::Camellia::BLOCKSIZE];
};
struct TPackFileEntry
{
char file_name[FILENAME_MAX];
uint64_t offset;
uint64_t file_size;
uint64_t compressed_size;
uint8_t encryption;
uint8_t iv[CryptoPP::Camellia::BLOCKSIZE];
};
#pragma pack(pop)
#include "PackLib/config.h"
int main(int argc, char* argv[])
{
@@ -110,7 +80,7 @@ int main(int argc, char* argv[])
CryptoPP::CTR_Mode<CryptoPP::Camellia>::Encryption encryption;
encryption.SetKeyWithIV(PACK_KEY.data(), PACK_KEY.size(), header.iv, CryptoPP::Camellia::BLOCKSIZE);
uint64_t offset = header.data_begin;
uint64_t offset = 0;
for (auto& [path, entry] : entries) {
std::ifstream ifs(input / path, std::ios::binary);
if (!ifs.is_open()) {
@@ -151,18 +121,14 @@ int main(int argc, char* argv[])
offset += entry.compressed_size;
}
std::vector<char> entry_buffer(sizeof(TPackFileEntry) * entries.size());
char* ptr = entry_buffer.data();
ofs.seekp(sizeof(TPackFileHeader), std::ios::beg);
encryption.Resynchronize(header.iv, sizeof(header.iv));
for (auto& [path, entry] : entries) {
memcpy(ptr, &entry, sizeof(entry));
ptr += sizeof(entry);
TPackFileEntry tmp = entry;
encryption.ProcessData((uint8_t*)&tmp, (uint8_t*)&tmp, sizeof(TPackFileEntry));
ofs.write((const char*)&tmp, sizeof(TPackFileEntry));
}
encryption.Resynchronize(header.iv, sizeof(header.iv));
encryption.ProcessData((uint8_t*)entry_buffer.data(), (uint8_t*)entry_buffer.data(), entry_buffer.size());
ofs.seekp(sizeof(TPackFileHeader), std::ios::beg);
ofs.write(entry_buffer.data(), entry_buffer.size());
return EXIT_SUCCESS;
}