Merge branch 'streaming'

This commit is contained in:
yanczi 2025-12-23 21:43:41 +01:00
commit f9ea960cf0
24 changed files with 582 additions and 722 deletions

View file

@ -1,114 +0,0 @@
#include "ChunkManager.h"
ChunkManager::ChunkManager(EncryptionManager& em)
:eman(em)
{ }
ChunkManager::~ChunkManager()
{ }
//-----------------------------------------------------------------------------
// Kompresja blokowa
//
// Dzielenie vectora na chunki dok³adnie po 128KB
// Kompresowanie chunków bez nag³ówka
//-----------------------------------------------------------------------------
std::vector<char> ChunkManager::chunked(const std::vector<char>& raw, const bool& compress, const bool& encrypt)
{
//std::vector<BlockSize> blockSizes;
// Maksymalny rozmiar chunka
const size_t maxBlockSize = BLOCK_SIZE;
const size_t rawSize = raw.size();
uint16_t blockLen = 0;
uint32_t lastChunkRawSize;
std::vector<char> compressedBlocks;
for (size_t offset = 0; offset < rawSize; offset += maxBlockSize)
{
// Rozmiar chunka
const size_t chunkSize = std::min(maxBlockSize, rawSize - offset);
auto begin = raw.begin() + offset;
auto end = begin + chunkSize;
// Skopiuj fragment danych do chunka
std::vector<char> chunk(begin, end);
std::vector<char> outChunk;
// Przetwórz chunki i przetwórz
if (compress)
{
// Zaszyfruj i skompresuj lub tylko skompresuj
outChunk = encrypt ? eman.encrypt(cman.compress(chunk)) : cman.compress(chunk);
}
else
{
// Zaszyfruj lub skopiuj
outChunk = encrypt ? eman.encrypt(chunk) : std::move(chunk);
}
uint32_t chs = chunk.size();
uint32_t zch = outChunk.size();
//addIntToVector<uint32_t>(compressedBlocks, chs);
lastChunkRawSize = chs;
addIntToVector<uint32_t>(compressedBlocks, zch);
compressedBlocks.insert(compressedBlocks.end(), outChunk.begin(), outChunk.end());
blockLen++;
}
std::vector<char> zip;
// Wstaw liczbê o iloœci bloków do vectora;
// Przekonpwertuj usigned int32 na ci¹g znkaów
// uint16_t blockLen = blockSizes .size();
addIntToVector<uint16_t>(zip, blockLen);
addIntToVector<uint32_t>(zip, maxBlockSize);
addIntToVector<uint32_t>(zip, lastChunkRawSize);
// Dodaj skompresowane dane
zip.insert(zip.end(), compressedBlocks.begin(), compressedBlocks.end());
return zip;
}
//////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
// Dekompresja blokowa
//-----------------------------------------------------------------------------
std::vector<char> ChunkManager::dechunked(const std::vector<char>& zip, const bool& compress, const bool& encrypt)
{
size_t offset = 0;
const uint16_t chunkLen = getIntFromVector<uint16_t>(zip, offset);
const uint32_t chunkBeforeSize = getIntFromVector<uint32_t>(zip, offset);
const uint32_t chunkLastSize = getIntFromVector<uint32_t>(zip, offset);
std::vector<char> chunksString;
// Dekompresja bloków
for (size_t i = 0; i < chunkLen; ++i)
{
// Pobierz rozmiar chunków przed i po skompresowaniem
uint32_t chunkSize = i < chunkLen - 1 ? chunkBeforeSize : chunkLastSize;
uint32_t chunkZipSize = getIntFromVector<uint32_t>(zip, offset);
// Pobierz blok chunka
std::vector<char> inChunk(chunkZipSize);
std::memcpy(inChunk.data(), zip.data() + offset, chunkZipSize);
offset += chunkZipSize;
// Jeœli flaga encrypt jest aktywna najpierw zdeszyfruj blok
std::vector<char> zipChunk = encrypt ? eman.decrypt(inChunk) : std::move(inChunk);
// Zdeklarój pusty chunk
std::vector<char> chunk = compress ? cman.decompress(zipChunk, chunkSize) : std::move(zipChunk);
// Scal chunki
chunksString.insert(chunksString.end(), chunk.begin(), chunk.end());
}
return chunksString;
}

View file

@ -1,51 +0,0 @@
#pragma once
#include <vector>
#include <cstdint>
#include <cstring>
#include <stdexcept>
#include <algorithm>
#include <iostream>
#include "EncryptionManager.h"
#include "CompressionManager.h"
#define BLOCK_SIZE 131072 // 128KB
class ChunkManager
{
public:
ChunkManager(EncryptionManager& em);
~ChunkManager();
// Kompresja danych
std::vector<char> chunked(const std::vector<char>&, const bool&, const bool&);
// Dekompresja
std::vector<char> dechunked(const std::vector<char>&, const bool&, const bool&);
private:
EncryptionManager eman;
CompressionManager cman;
// Przekonwertuj zmienn¹ na ci¹g na vector
template <typename T>
void addIntToVector(std::vector<char>& vec, const T& val)
{
size_t tmpSize = vec.size();
vec.resize(tmpSize + sizeof(val));
std::memcpy(vec.data() + tmpSize, &val, sizeof(val));
}
// Pobierz zmienn¹ z vectora
template <typename T>
T getIntFromVector(const std::vector<char>& vec, size_t& offset)
{
T tmp{};
std::memcpy(&tmp, vec.data() + offset, sizeof(tmp));
offset += sizeof(tmp);
return tmp;
}
};

View file

@ -1,3 +1,22 @@
/*
* This file is part of VoidArchiveTool.
*
* Copyright (C) 2025 Yanczi
*
* Void Archive Toolis free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "CompressionManager.h"
CompressionManager::CompressionManager()

View file

@ -1,3 +1,22 @@
/*
* This file is part of VoidArchiveTool.
*
* Copyright (C) 2025 Yanczi
*
* Void Archive Toolis free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <iostream>

View file

@ -20,14 +20,16 @@
#include "CreateCargo.h"
CreateCargo::CreateCargo()
: signature(SIGNATURE)
, extension(EXTENSION)
: signature(fl::sigpak)
, extension(fl::extpak)
, version(VERSION)
, methodFlags(0)
, xxhState(XXH64_createState())
, offset(0)
, hppKey(false)
{
// TODO Auto-generated constructor stub
XXH64_reset(xxhState, 0);
}
CreateCargo::~CreateCargo() {
@ -38,7 +40,7 @@ CreateCargo::~CreateCargo() {
//-----------------------------------------------------------------------------
// Punk wej𦣇ia do tworzenia archivum
//-----------------------------------------------------------------------------
bool CreateCargo::Create(const std::string& path, const int16_t& flag)
bool CreateCargo::Create(const std::string& path, const uint8_t& flag)
{
cargoFile = path + "." + extension;
catalogPath = path;
@ -88,9 +90,9 @@ bool CreateCargo::Create(const std::string& path, const int16_t& flag)
}
// Zapisywanie klucza szyfruj鉍ego
if (flag == 2 || flag == 3 || encList.size() > 0)
if (flag == flag::enc || flag == flag::ezd || encList.size() > 0)
{
crypt.saveKey(catalogPath, hppKey);
eman.saveKey(catalogPath, hppKey);
}
return true;
@ -111,29 +113,37 @@ bool CreateCargo::GetFileList(const std::string& path)
else
{
std::string fileRef = RemoveStartPath(PathToUnixLike(tmpPath));
PathConf pc;
if (methodFlags > -1)
if (fileRef.length() > 255)
{
pc.path = PathToUnixLike(tmpPath);
pc.parameter = methodFlags;
filesPaths.push_back(pc);
std::cerr << "The file path is too long. It exceeds 255 characters." << std::endl;
}
else
{
if (!FindOnTheList(ignoreList, fileRef) || !CheckFileExtension(fileRef, ignoreList))
PathConf pc;
if (methodFlags != 0xAB)
{
if (FindOnTheList(zipList, fileRef) || CheckFileExtension(fileRef, zipList))
{
pc.parameter = FindOnTheList(encList, fileRef) || CheckFileExtension(fileRef, encList) ? 3 : 1;
}
else
{
pc.parameter = FindOnTheList(encList, fileRef) || CheckFileExtension(fileRef, encList) ? 2 : 0;
}
pc.path = PathToUnixLike(tmpPath);
std::cout << pc.path << " - " << pc.parameter << std::endl;
pc.parameter = methodFlags;
filesPaths.push_back(pc);
}
else
{
if (!FindOnTheList(ignoreList, fileRef) || !CheckFileExtension(fileRef, ignoreList))
{
if (FindOnTheList(zipList, fileRef) || CheckFileExtension(fileRef, zipList))
{
pc.parameter = FindOnTheList(encList, fileRef) || CheckFileExtension(fileRef, encList) ? FILE_FLAG_ZIPENC : FILE_FLAG_COMPRESS;
}
else
{
pc.parameter = FindOnTheList(encList, fileRef) || CheckFileExtension(fileRef, encList) ? FILE_FLAG_ENCRYPT : FILE_FLAG_RAW;
}
pc.path = PathToUnixLike(tmpPath);
std::cout << pc.path << " - " << pc.parameter << std::endl;
filesPaths.push_back(pc);
}
}
}
}
}
@ -175,47 +185,13 @@ CargoHead CreateCargo::CreateCargoHead(const uint32_t& filesLen, const uint64_t&
{
CargoHead ch;
ch.signature = signature;
ch.version = version;
ch.files = filesLen;
ch.signature = fl::sigpak;
ch.table = table;
ch.files = filesLen;
return ch;
}
//-----------------------------------------------------------------------------
// Sprawdza czy plik znajduje siê na liœcie
//-----------------------------------------------------------------------------
void CreateCargo::computingBytes(const int16_t& flag, std::vector<char>& input, std::vector<char>& output)
{
//Flaga aktywna sprawdza czy plik jest na liœcie. Jeœli jest to zwraca surowedane
//Przeciwnie kompresuje dane
ChunkManager cm(crypt);
switch (flag)
{
case 1:
output = cm.chunked(input, true, false);
break;
case 2:
output = cm.chunked(input, false, true);
break;
case 3:
output = cm.chunked(input, true, true);
break;
case 4:
output = cm.chunked(input, false, false);
break;
default:
output = std::move(input);
break;
}
}
//-----------------------------------------------------------------------------
// Przygotowanie nag堯wk闚 i plik闚
//-----------------------------------------------------------------------------
@ -223,13 +199,12 @@ std::vector<FilesTable> CreateCargo::ComputingHeadFiles()
{
//Utw鏎z header TMP. Zabezpiecza Pierwsze bajty na w豉𦣇iwy nag堯wek
CargoHead cargoHead = CreateCargoHead(0, 0);
offset += cargoHead.signature.length() + sizeof(cargoHead.version) + sizeof(cargoHead.files) + sizeof(cargoHead.table);
offset += cargoHead.signature.length() + sizeof(cargoHead.files) + sizeof(cargoHead.table);
//Zapisanie tymczasowego nag這wka jako rezerwacja miejsca
cargo.write(cargoHead.signature.data(), cargoHead.signature.length());
cargo.write(reinterpret_cast<const char*>(&cargoHead.version), sizeof(cargoHead.version));
cargo.write(reinterpret_cast<const char*>(&cargoHead.files), sizeof(cargoHead.files));
cargo.write(reinterpret_cast<const char*>(&cargoHead.table), sizeof(cargoHead.table));
cargo.write(reinterpret_cast<const char*>(&cargoHead.files), sizeof(cargoHead.files));
std::vector<FilesTable> filesTable;
@ -239,36 +214,108 @@ std::vector<FilesTable> CreateCargo::ComputingHeadFiles()
std::string path = PathToUnixLike(RemoveStartPath(file.path));
std::ifstream f(file.path, std::ios::binary | std::ios::ate);
std::cout << path << std::endl;
//Obliczanie rozmiaru pliku
size_t size = f.tellg();
f.seekg(0, std::ios::beg);
//Wczytanie pliku do pamiêci
std::vector<char> buffer(size);
f.read(buffer.data(), size);
f.close();
if (size > ds::maxFileSize)
{
std::cerr << path << " is too large. It exceeds " << ds::maxFileSize / 1024 / 1024 / 1024 << "GB!" << std::endl;
}
else
{
XXH64_reset(xxhState, 0);
//Tworzenie hashu CRC
const uint64_t crc = XXH64(buffer.data(), buffer.size(), VERSION);
//Wczytanie pliku do pamiêci
std::vector<char> buffer(ds::chunk_stream);
//Kompresjia
std::vector<char> pakBuffer;
computingBytes(file.parameter, buffer, pakBuffer);
uint64_t sizeFile = 0;
FilesTable ft;
ft.nameFile = path;
ft.nameLen = path.length();
ft.hashName = fnv64(path);
ft.offset = offset;
ft.size = pakBuffer.size();
ft.flag = file.parameter;
ft.crc = crc;
const uint32_t chunkBlockSize = ds::block_size;
const uint32_t quantity = (size + chunkBlockSize) / chunkBlockSize;
const uint32_t lastChunkSize = size - (chunkBlockSize * (quantity - 1));
cargo.write(reinterpret_cast<const char*>(pakBuffer.data()), pakBuffer.size());
// Jeœli jest ustawiona flaga inna ni¿ RAW
// Dodaj do kontenera konfiguracjê chunków
if (file.parameter != flag::raw)
{
cargo.write(reinterpret_cast<const char*>(&quantity), sizeof(quantity));
cargo.write(reinterpret_cast<const char*>(&chunkBlockSize), sizeof(chunkBlockSize));
cargo.write(reinterpret_cast<const char*>(&lastChunkSize), sizeof(lastChunkSize));
sizeFile = sizeof(quantity) + sizeof(chunkBlockSize) + sizeof(lastChunkSize);
}
filesTable.push_back(ft);
offset += pakBuffer.size();
// Strumieniowanie danych
while (f.read(buffer.data(), ds::chunk_stream) || f.gcount() > 0)
{
const int bufferSize = f.gcount();
buffer.resize(bufferSize);
// Aktualizacja XXH64
XXH64_update(xxhState, buffer.data(), buffer.size());
if (file.parameter == flag::raw)
{
// Zapisywanie strumienia do kontenera
cargo.write(reinterpret_cast<const char*>(buffer.data()), buffer.size());
sizeFile += bufferSize;
}
else
{
for (uint32_t ofs = 0; ofs < bufferSize; ofs += chunkBlockSize)
{
// Rozmiar chunka
const uint32_t chunkSize = std::min(chunkBlockSize, bufferSize - ofs);
auto begin = buffer.begin() + ofs;
auto end = begin + chunkSize;
// Skopiuj fragment danych do chunka
std::vector<char> chunk(begin, end);
std::vector<char> outChunk;
// Przetwórz chunki i przetwórz
if ((file.parameter & flag::zip) == flag::zip)
{
// Zaszyfruj i skompresuj lub tylko skompresuj
outChunk = (file.parameter & flag::enc) == flag::enc ?
eman.encrypt(cman.compress(chunk)) : cman.compress(chunk);
}
else
{
// Zaszyfruj lub skopiuj
outChunk = eman.encrypt(chunk);
}
const uint32_t outSize = outChunk.size();
cargo.write(reinterpret_cast<const char*>(&outSize), sizeof(outSize));
sizeFile += sizeof(outSize);
cargo.write(reinterpret_cast<const char*>(outChunk.data()), outChunk.size());
sizeFile += outSize;
}
}
}
f.close();
FilesTable ft;
ft.nameFile = path;
ft.nameLen = path.length();
ft.offset = offset;
ft.size = sizeFile;
ft.flag = file.parameter;
ft.crc = XXH64_digest(xxhState);
filesTable.push_back(ft);
offset += sizeFile;
}
}
return filesTable;
}
@ -285,24 +332,25 @@ void CreateCargo::GetFilters(const std::string& filterFile)
file.close();
// Lista plik闚 do skompresowania
if (jslist.contains(KEY_ZIP))
if (jslist.contains(key::zip))
{
zipList = jslist[KEY_ZIP].get<std::vector<std::string>>();
zipList = jslist[key::zip].get<std::vector<std::string>>();
}
// Lista plik闚 do zaszyfrowania
if (jslist.contains(KEY_ENCRYPT))
if (jslist.contains(key::enc))
{
encList = jslist[KEY_ENCRYPT].get<std::vector<std::string>>();
encList = jslist[key::enc].get<std::vector<std::string>>();
}
// Lista plik闚 do pomini璚ia
if (jslist.contains(KEY_IGNORE))
if (jslist.contains(key::ignore))
{
ignoreList = jslist[KEY_IGNORE].get<std::vector<std::string>>();
ignoreList = jslist[key::ignore].get<std::vector<std::string>>();
}
hppKey = jslist.value("keyhpp", false);
// Flaga tworzenia klucza jako plik nag³ówka c++
hppKey = jslist.value(key::hpp, false);
}
//-----------------------------------------------------------------------------
@ -342,24 +390,6 @@ std::string CreateCargo::UpperString(std::string s) {
return s;
}
//-----------------------------------------------------------------------------
// Wygenerój FNV-1a HASH
//-----------------------------------------------------------------------------
uint64_t CreateCargo::fnv64(const std::string& data)
{
const uint64_t fnvOffset = 14695981039346656037u;
const uint64_t fnvPrime = 1099511628211u;
uint64_t hash = fnvOffset;
for (unsigned char c : data)
{
hash ^= c;
hash *= fnvPrime;
}
return hash;
}
//-----------------------------------------------------------------------------
// Trworzenie archiwum
//-----------------------------------------------------------------------------
@ -386,7 +416,6 @@ bool CreateCargo::WriteCargo()
cargo.write(reinterpret_cast<const char*>(&head.nameLen), sizeof(head.nameLen));
cargo.write(head.nameFile.data(), head.nameLen);
cargo.write(reinterpret_cast<const char*>(&head.hashName), sizeof(head.hashName));
cargo.write(reinterpret_cast<const char*>(&head.offset), sizeof(head.offset));
cargo.write(reinterpret_cast<const char*>(&head.size), sizeof(head.size));
cargo.write(reinterpret_cast<const char*>(&head.crc), sizeof(head.crc));
@ -401,9 +430,8 @@ bool CreateCargo::WriteCargo()
//Nadpisz tymczasowy nag堯wek
cargo.write(cargoHead.signature.data(), cargoHead.signature.length());
cargo.write(reinterpret_cast<const char*>(&cargoHead.version), sizeof(cargoHead.version));
cargo.write(reinterpret_cast<const char*>(&cargoHead.files), sizeof(cargoHead.files));
cargo.write(reinterpret_cast<const char*>(&cargoHead.table), sizeof(cargoHead.table));
cargo.write(reinterpret_cast<const char*>(&cargoHead.files), sizeof(cargoHead.files));
cargo.close();

View file

@ -33,8 +33,8 @@
#include <nlohmann/json.hpp>
#include "DataStruct.h"
#include "ChunkManager.h"
#include "EncryptionManager.h"
#include "CompressionManager.h"
#define KEY_ZIP "compress" // Pliki do skompresowania
@ -44,10 +44,21 @@
#define ALL_FILE ".*" // Wszystkie pliki
namespace key
{
inline constexpr std::string_view zip = "compress";
inline constexpr std::string_view raw = "raw";
inline constexpr std::string_view enc = "encrypt";
inline constexpr std::string_view ignore = "ignore";
inline constexpr std::string_view all = ".*";
inline constexpr std::string_view hpp = "keyhpp";
}
struct PathConf
{
std::string path;
int16_t parameter;
uint8_t parameter;
};
class CreateCargo {
@ -56,14 +67,16 @@ public:
virtual ~CreateCargo();
// Punk wejœcia do tworzenia archivum
bool Create(const std::string&, const int16_t&);
bool Create(const std::string&, const uint8_t&);
private:
const std::string signature;
const std::string extension;
const short version;
const signed char version;
short methodFlags;
uint8_t methodFlags;
XXH64_state_t* xxhState;
std::string catalogPath;
@ -72,7 +85,8 @@ private:
std::vector<std::string> filesList;
EncryptionManager crypt;
EncryptionManager eman;
CompressionManager cman;
bool hppKey;
// listy wyj¹tków
@ -88,7 +102,6 @@ private:
uint64_t offset;
// Tworzenie listy plików do spakowania
bool GetFileList(const std::string&);
@ -110,18 +123,12 @@ private:
// Wczytanie filtrów wyj¹tków
void GetFilters(const std::string&);
// Sprawdza czy plik znajduje siê na liœcie
void computingBytes(const int16_t&, std::vector<char>&, std::vector<char>&);
// Sprawdzanie rozsze¿eñ plików
bool CheckFileExtension(const std::string&, const std::vector<std::string>&);
// Zamieñ ca³y ci¹g na du¿e litery
std::string UpperString(std::string);
// Wygenerój FNV-1a HASH
uint64_t fnv64(const std::string& data);
// ZnajdŸ wskazany element na liœcie
bool FindOnTheList(const std::vector<std::string>&, const std::string&);
};

View file

@ -25,52 +25,80 @@
#define EXTENSION "pak"
#define SIGNATURE "XPAK"
#define SIGNATURE_KEY_FILE 1497713496 // XKEY
#define SIGNATURE_KEY_FILE "XKEY"
#define VERSION 300
#define VERSION 0x03
enum StoreMethod
{
FILTERING = -1,
RAW = 0,
COMPRESS = 1,
ENCRYPT = 2,
COMPRESSxENCRYPT = 3
};
// WielkoϾ pojedynczego bloku strumienia
#define CHUNK_STREAM_512KB 524288 // 512KB
#define CHUNK_STREAM_16MB 16777216 // 16MB
#define CHUNK_STREAM_256MB 268435456 // 256MB
// Rozmiar pojedynczego bloku
#define CHUNK_BLOCK_SIZE 131072 // 128KB
#define FILE_FLAG_RAW 0x00
#define FILE_FLAG_COMPRESS 0x0F
#define FILE_FLAG_ENCRYPT 0xF0
#define FILE_FLAG_ZIPENC 0xFF
#define FILE_FLAG_FILTERING 0xAB
//Prgoram title
#define PROGRAM_TITLE "eXtendet PAK"
#define PROGRAM_VERSION "v1.3"
#define PROGRAM_VERSION "v0.5"
#define PROGRAM_AUTHOR "Yanczi"
#define PROGRAM_COMPILING "16 November 2025"
#define PROGRAM_COMPILING "19 December 2025"
#define PROGRAM_LICENSE "GNU LGPL v3"
//Limity
#define MAX_FILE_SIZE 2147483648 // 2GB
#define MAX_PAK_SIZE 8796093022208 // 8TB
// Pliki
namespace fl {
inline constexpr std::string_view sigpak = "XPAK";
inline constexpr std::string_view sigkey = "XKEY";
// Metody zapisania pliku
#define RAW_FILE 0
#define ZIP_FILE 1
#define CRYPT_FILE 2
#define CRYPT_ZIP 3
inline constexpr std::string_view extpak = "pak";
inline constexpr std::string_view extkey = "key";
}
// Size
namespace ds
{
// Chunki streamowania
inline constexpr uint32_t chunk_stream = 268435456; // 256MB
// Blok chunków
inline constexpr uint32_t block_size = 131072; // 128KB
// Maksymalny rozmiar pliku do spakowania
inline constexpr uint64_t maxFileSize = 8589934592; // 8GB
}
// Flagi
namespace flag
{
inline constexpr uint8_t raw = 0x00; // Surowy plik
inline constexpr uint8_t zip = 0x0F; // Kompresja
inline constexpr uint8_t enc = 0xF0; // Szyfrowanie
inline constexpr uint8_t ezd = 0xFF; // Kompresja z szyfrowaniem
// Flaga do aktywacji filtra zdefiniowanego w json
inline constexpr uint8_t filter = 0xAB;
}
struct CargoHead
{
std::string signature;
int16_t version;
uint32_t files;
uint8_t version;
uint64_t table;
uint32_t files;
};
struct FilesTable
{
int16_t nameLen;
uint8_t nameLen;
std::string nameFile;
uint64_t hashName;
uint64_t offset;
uint32_t size;
uint64_t size;
uint64_t crc;
int16_t flag;
uint8_t flag;
};

View file

@ -1,3 +1,22 @@
/*
* This file is part of VoidArchiveTool.
*
* Copyright (C) 2025 Yanczi
*
* Void Archive Toolis free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "EncryptionManager.h"
EncryptionManager::EncryptionManager()
@ -48,8 +67,8 @@ void EncryptionManager::generateKeys()
void EncryptionManager::saveKey(const std::string& path, bool hpp)
{
const int sig = SIGNATURE_KEY_FILE;
const short ver = VERSION;
const std::string sig = SIGNATURE_KEY_FILE;
const int8_t ver = VERSION;
// Wygeneruj time stamp
std::time_t now = std::time(nullptr);
@ -65,7 +84,7 @@ void EncryptionManager::saveKey(const std::string& path, bool hpp)
std::ofstream file(path + ".key", std::ios::binary);
if (!file) { std::cout << "Failed to save encryption key to file" << std::endl; }
file.write(reinterpret_cast<const char*>(&sig), sizeof(sig));
file.write(sig.data(), sig.length());
file.write(reinterpret_cast<const char*>(&ver), sizeof(ver));
file.write(reinterpret_cast<const char*>(&time), sizeof(time));
file.write(reinterpret_cast<const char*>(keyVec.data()), keyVec.size());
@ -119,16 +138,17 @@ void EncryptionManager::loadKey(const std::string& path)
{
std::ifstream file(path + ".key", std::ios::binary);
int sig;
short ver;
const std::string signature = SIGNATURE_KEY_FILE;
std::vector<char> sig(signature.size());
int8_t ver;
int time;
// Wczytaj
file.read(reinterpret_cast<char*>(&sig), sizeof(sig));
file.read(sig.data(), sig.size());
file.read(reinterpret_cast<char*>(&ver), sizeof(ver));
// SprawdŸ czy plik klucza jest poprawny
if (sig != SIGNATURE_KEY_FILE || ver != VERSION)
if (std::string(sig.begin(), sig.end()) != signature || ver != VERSION)
{
throw std::runtime_error("Invalid key file!");
}

View file

@ -1,3 +1,22 @@
/*
* This file is part of VoidArchiveTool.
*
* Copyright (C) 2025 Yanczi
*
* Void Archive Toolis free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <sodium.h>
@ -26,6 +45,10 @@ public:
void saveKey(const std::string&, bool);
void loadKey(const std::string&);
// Generowanie hash BLAKE2b
//static std::array<char, 16> hashBlake(const std::vector<char>&);
//static bool compareBlake(const std::vector<char>&, const std::array<char, 16>&);
private:
std::array<unsigned char, crypto_stream_chacha20_ietf_KEYBYTES> key{};
bool keyReady;

View file

@ -22,12 +22,11 @@
ExtractCargo::ExtractCargo()
:filesLen(0)
, tablePosition(0)
, filesHeadsOffset(0)
, version(VERSION)
, xxhState(XXH64_createState())
, signature(SIGNATURE)
{
// TODO Auto-generated constructor stub
XXH64_reset(xxhState, 0);
}
ExtractCargo::~ExtractCargo()
@ -89,7 +88,7 @@ bool ExtractCargo::Extract(const std::string& cFile)
bool ExtractCargo::CheckCargoFile()
{
std::vector<char> magic(signature.size());
short cargoVer = 0;
int8_t cargoVer = 0;
if (!cargoFile.is_open())
{
@ -98,73 +97,19 @@ bool ExtractCargo::CheckCargoFile()
}
cargoFile.read(magic.data(), magic.size());
cargoFile.read(reinterpret_cast<char*>(&cargoVer), sizeof(cargoVer));
cargoFile.read(reinterpret_cast<char*>(&filesLen), sizeof(filesLen));
cargoFile.read(reinterpret_cast<char*>(&tablePosition), sizeof(tablePosition));
if (std::string(magic.begin(), magic.end()) != signature)
{
std::cerr << "Error: Corrupted Cargo" << std::endl;
return false;
}
if (cargoVer != version)
{
std::cerr << "Error: Wrong cargo version" << std::endl;
return false;
}
filesHeadsOffset = signature.length() + sizeof(cargoVer) + sizeof(filesLen);
// Pobierz pozycjê tablicy plików i jej rozmiar
cargoFile.read(reinterpret_cast<char*>(&tablePosition), sizeof(tablePosition));
cargoFile.read(reinterpret_cast<char*>(&filesLen), sizeof(filesLen));
return true;
}
//-----------------------------------------------------------------------------
// Sprawdzanie sumy kontrolnej
//-----------------------------------------------------------------------------
bool ExtractCargo::HashValid(const std::vector<char>& data, const uint64_t& crc)
{
uint64_t actualCrc = XXH64(data.data(), data.size(), VERSION);
if (actualCrc != crc)
{
return false;
}
return true;
}
//-----------------------------------------------------------------------------
// Magiczna funkcja do dekompresji i deszyfracji danych
//-----------------------------------------------------------------------------
void ExtractCargo::computingBytes(const std::vector<char>& input, std::vector<char>& output, const int16_t& flag)
{
ChunkManager cm(eman);
switch (flag)
{
case 1:
output = cm.dechunked(input, true, false);
break;
case 2:
output = cm.dechunked(input, false, true);
break;
case 3:
output = cm.dechunked(input, true, true);
break;
case 4:
output = cm.dechunked(input, false, false);
break;
default:
output = input;
break;
}
}
//-----------------------------------------------------------------------------
// Pobieranie nag³ówków plików
//-----------------------------------------------------------------------------
@ -180,7 +125,6 @@ void ExtractCargo::LoadFilesTable()
cargoFile.read(nameBuffor.data(), fhTmp.nameLen);
fhTmp.nameFile = std::string(nameBuffor.begin(), nameBuffor.end());
cargoFile.read(reinterpret_cast<char*>(&fhTmp.hashName), sizeof(fhTmp.hashName));
cargoFile.read(reinterpret_cast<char*>(&fhTmp.offset), sizeof(fhTmp.offset));
cargoFile.read(reinterpret_cast<char*>(&fhTmp.size), sizeof(fhTmp.size));
cargoFile.read(reinterpret_cast<char*>(&fhTmp.crc), sizeof(fhTmp.crc));
@ -199,24 +143,76 @@ void ExtractCargo::ExtractingFilesFromCargo()
{
std::filesystem::path dir = cargoFileName.stem() / fh.nameFile;
CreateDirections(dir);
std::cout << dir.string() << std::endl;
std::ofstream file(dir, std::ios::binary);
cargoFile.seekg(fh.offset);
std::vector<char> buffor(fh.size);
cargoFile.read(buffor.data(), fh.size);
XXH64_reset(xxhState, 0);
std::vector<char> rawBuffor;
computingBytes(buffor, rawBuffor, fh.flag);
if (!HashValid(rawBuffor, fh.crc))
// Strumieñ wyci¹gaj¹cy
if (fh.flag == flag::raw)
{
std::cerr << fh.nameFile << " Error: Corrupted data integration CRC" << std::endl;
for (uint64_t sc = 0; sc < fh.size; sc += ds::chunk_stream)
{
const uint32_t streamChunk = std::min(ds::chunk_stream, static_cast<uint32_t>(fh.size - sc));
std::vector<char> buffer(streamChunk);
cargoFile.read(buffer.data(), streamChunk);
XXH64_update(xxhState, buffer.data(), buffer.size());
file.write(reinterpret_cast<const char*>(buffer.data()), streamChunk);
}
}
else
{
uint32_t chunkLen;
uint32_t chunkBeforeSize;
uint32_t chunkLastSize;
cargoFile.read(reinterpret_cast<char*>(&chunkLen), sizeof(chunkLen));
cargoFile.read(reinterpret_cast<char*>(&chunkBeforeSize), sizeof(chunkBeforeSize));
cargoFile.read(reinterpret_cast<char*>(&chunkLastSize), sizeof(chunkLastSize));
std::vector<char> chunksString;
// Dekompresja bloków
for (size_t i = 0; i < chunkLen; ++i)
{
// Pobierz rozmiar chunków przed i po skompresowaniem
uint32_t chunkSize = i < chunkLen - 1 ? chunkBeforeSize : chunkLastSize;
uint32_t chunkZipSize;
cargoFile.read(reinterpret_cast<char*>(&chunkZipSize), sizeof(chunkZipSize));
// Pobierz blok chunka
std::vector<char> buffer(chunkZipSize);
cargoFile.read(buffer.data(), chunkZipSize);
std::vector<char> rawBuffer(chunkSize);
if ((fh.flag & flag::zip) == flag::zip)
{
rawBuffer = (fh.flag & flag::enc) == flag::enc ?
cman.decompress(eman.decrypt(buffer), chunkSize) :
cman.decompress(buffer, chunkSize);
}
else
{
rawBuffer = eman.decrypt(buffer);
}
XXH64_update(xxhState, rawBuffer.data(), rawBuffer.size());
file.write(reinterpret_cast<const char*>(rawBuffer.data()), chunkSize);
}
}
file.write(reinterpret_cast<const char*>(rawBuffor.data()), rawBuffor.size());
file.close();
if (XXH64_digest(xxhState) != fh.crc)
{
std::cerr << dir.string() << " Error: Corrupted data integration CRC" << std::endl;
}
}
std::cout << "Unpacking complete!" << std::endl;

View file

@ -28,11 +28,12 @@
#include <sstream>
#include <cstdint>
#include <string>
#include <utility>
#include <xxhash.h>
#include "DataStruct.h"
#include "ChunkManager.h"
#include "EncryptionManager.h"
#include "CompressionManager.h"
class ExtractCargo {
public:
@ -47,9 +48,8 @@ private:
uint32_t filesLen;
uint64_t tablePosition;
int filesHeadsOffset;
XXH64_state_t* xxhState;
const short version;
const std::string signature;
std::vector<FilesTable> filesHeads;
@ -58,7 +58,7 @@ private:
std::ifstream cargoFile;
EncryptionManager eman;
CompressionManager cman;
// Sprawdzenie poprawnoœci archiwum
bool CheckCargoFile();
@ -69,13 +69,7 @@ private:
// Pobieranie nag³ówków plików
void LoadFilesTable();
// Sprawdzanie sumy kontrolnej
bool HashValid(const std::vector<char>&, const uint64_t&);
// Utwórz katalog
void CreateDirections(std::filesystem::path);
// Magiczna funkcja do dekompresji i deszyfracji danych
void computingBytes(const std::vector<char>&, std::vector<char>&, const int16_t&);
};

View file

@ -1,18 +0,0 @@
#include "Interface.h"
Interface::Interface() {
// TODO Auto-generated constructor stub
}
Interface::~Interface() {
// TODO Auto-generated destructor stub
}
void Interface::TextBorder(const std::string& title, const std::string& text)
{
auto element = ftxui::window(ftxui::text(title), ftxui::paragraphAlignLeft(text));
auto screen = ftxui::Screen::Create(ftxui::Dimension::Fit(element));
ftxui::Render(screen, element);
screen.Print();
}

View file

@ -1,14 +0,0 @@
#pragma once
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <string>
class Interface {
public:
Interface();
virtual ~Interface();
void TextBorder(const std::string&, const std::string&);
};

71
Tui.cpp Normal file
View file

@ -0,0 +1,71 @@
/*
* This file is part of VoidArchiveTool.
*
* Copyright (C) 2025 Yanczi
*
* Void Archive Toolis free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Tui.h"
Tui::Tui() {
// TODO Auto-generated constructor stub
}
Tui::~Tui() {
// TODO Auto-generated destructor stub
}
void Tui::TextBorder(const std::string& title, const std::string& text)
{
auto element = ftxui::window(ftxui::text(title), ftxui::paragraphAlignLeft(text));
auto screen = ftxui::Screen::Create(ftxui::Dimension::Fit(element));
ftxui::Render(screen, element);
screen.Print();
}
void Tui::table(const std::vector<std::vector<std::string>>& data)
{
ftxui::Table table(data);
// Styl ogólny tabeli (ramki)
table.SelectAll().Border(ftxui::LIGHT);
// Oddzielenie nag³ówka od danych podwójn¹ lini¹
table.SelectRow(0).Border(ftxui::LIGHT);
table.SelectRow(0).Decorate(ftxui::bold); // Pogrubienie nag³ówka
table.SelectRow(0).SeparatorVertical(ftxui::LIGHT);
table.SelectRow(0).Border(ftxui::LIGHT);
table.SelectColumn(0).DecorateCells(ftxui::center);
table.SelectColumn(1).DecorateCells(ftxui::center);
table.SelectColumn(2).DecorateCells([](ftxui::Element e) {
return e | ftxui::flex;
});
table.SelectColumn(3).DecorateCells(ftxui::center);
table.SelectColumn(0).BorderRight(ftxui::LIGHT);
table.SelectColumn(1).BorderRight(ftxui::LIGHT);
table.SelectColumn(2).BorderRight(ftxui::LIGHT);
auto document = table.Render();
auto screen = ftxui::Screen::Create(ftxui::Dimension::Full(), ftxui::Dimension::Fit(document));
ftxui::Render(screen, document);
screen.Print();
}

34
Tui.h Normal file
View file

@ -0,0 +1,34 @@
/*
* This file is part of VoidArchiveTool.
*
* Copyright (C) 2025 Yanczi
*
* Void Archive Toolis free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <ftxui/dom/elements.hpp>
#include <ftxui/dom/table.hpp>
#include <ftxui/screen/screen.hpp>
#include <string>
class Tui {
public:
Tui();
virtual ~Tui();
void TextBorder(const std::string&, const std::string&);
void table(const std::vector<std::vector<std::string>>&);
};

View file

@ -20,14 +20,7 @@
#include "ViewCargo.h"
ViewCargo::ViewCargo()
:signature(SIGNATURE)
, version(VERSION)
, filesLen(0)
, tablePos(0)
{
// TODO Auto-generated constructor stub
}
{}
//-----------------------------------------------------------------------------
// Wywoływanie
@ -49,39 +42,26 @@ bool ViewCargo::View(const std::string& path)
}
//Sprawdź czy kontener jest prawidłowy
if (!CheckCargoFile(path))
if (!ViewFiles(path))
{
std::cerr << "Nie prawidlowa struktura kontenera Void" << std::endl;
return false;
}
//Table Header
std::vector<ftxui::Element> headElements;
headElements.push_back(ftxui::text(" Compressed ") | ftxui::bold);
headElements.push_back(ftxui::text(" Encrypted ") | ftxui::bold);
headElements.push_back(ftxui::text("Nazwa pliku") | ftxui::bold | ftxui::size(ftxui::WIDTH, ftxui::EQUAL, 56));
headElements.push_back(ftxui::text("Hash Name") | ftxui::bold | ftxui::size(ftxui::WIDTH, ftxui::EQUAL, 20));
filesList.push_back(hbox(std::move(headElements)));
//Pobieranie listy plików
GetFileList(path);
//Renderowanie listy plików
RenderList();
return true;
}
//-----------------------------------------------------------------------------
// Sprawdzenie poprawności kontenera
//-----------------------------------------------------------------------------
bool ViewCargo::CheckCargoFile(const std::string& path)
bool ViewCargo::ViewFiles(const std::string& path)
{
uint64_t tabPos = 0;
uint32_t tabSize = 0;
const std::string signature = SIGNATURE;
std::vector<char> magic(signature.length());
short cargoVer = 0;
int8_t cargoVer = 0;
std::ifstream cargo(path, std::ios::binary);
@ -92,15 +72,14 @@ bool ViewCargo::CheckCargoFile(const std::string& path)
}
//---------------------------------------------------------------
// Odczytywanie pierwszych 11 bajtów nagłówka pliku
// 6 pierwszych to sygnatura
// 1 wersja kontenera
// 4 ilość plików w kontenerze
// Odczytywanie pierwszych 16 bajtów nag³ówka pliku
// 4 Sygnatura kontenera XPAK
// 8 Offset tablicy plików
// 4 Rozmiar tablicy plików
//---------------------------------------------------------------
cargo.read(magic.data(), magic.size());
cargo.read(reinterpret_cast<char*>(&cargoVer), sizeof(cargoVer));
cargo.read(reinterpret_cast<char*>(&filesLen), sizeof(filesLen));
cargo.read(reinterpret_cast<char*>(&tablePos), sizeof(tablePos));
cargo.read(reinterpret_cast<char*>(&tabPos), sizeof(tabPos));
cargo.read(reinterpret_cast<char*>(&tabSize), sizeof(tabSize));
//Sprawdź czy kontener ma poprawną sygnature
if (std::string(magic.begin(), magic.end()) != signature)
@ -110,28 +89,13 @@ bool ViewCargo::CheckCargoFile(const std::string& path)
return false;
}
//Sprawdź spójność wersji kontenera
if (cargoVer != version)
{
std::cerr << "Error: Wrong cargo version" << std::endl;
cargo.close();
return false;
}
std::cout << "ZIP" << " " << "ENC" << " " << "Path" << std::endl;
cargo.close();
// Przeskocz do tablicy plików
cargo.seekg(tabPos);
return true;
}
//-----------------------------------------------------------------------------
// Pobieranie listy plików z kontenera
//-----------------------------------------------------------------------------
void ViewCargo::GetFileList(const std::string& path)
{
std::ifstream cargo(path, std::ios::binary);
cargo.seekg(tablePos);
for (uint32_t i = 0; i < filesLen; ++i)
// Za³aduj dane o plikach
for (uint32_t i = 0; i < tabSize; ++i)
{
FilesTable fhTmp;
cargo.read(reinterpret_cast<char*>(&fhTmp.nameLen), sizeof(fhTmp.nameLen));
@ -140,76 +104,50 @@ void ViewCargo::GetFileList(const std::string& path)
cargo.read(nameBuffor.data(), fhTmp.nameLen);
fhTmp.nameFile = std::string(nameBuffor.begin(), nameBuffor.end());
cargo.read(reinterpret_cast<char*>(&fhTmp.hashName), sizeof(fhTmp.hashName));
cargo.read(reinterpret_cast<char*>(&fhTmp.offset), sizeof(fhTmp.offset));
cargo.read(reinterpret_cast<char*>(&fhTmp.size), sizeof(fhTmp.size));
cargo.read(reinterpret_cast<char*>(&fhTmp.crc), sizeof(fhTmp.crc));
cargo.read(reinterpret_cast<char*>(&fhTmp.flag), sizeof(fhTmp.flag));
//Tworzenie wierszy tabeli
CreateTableRow(fhTmp.nameFile, fhTmp.flag, fhTmp.hashName);
ShowFile(fhTmp.nameFile, fhTmp.flag);
}
cargo.close();
return true;
}
//-----------------------------------------------------------------------------
// Generowanie wierszy do tabeli
//-----------------------------------------------------------------------------
void ViewCargo::CreateTableRow(const std::string& file, const uint8_t& zip, const uint64_t& hash)
void ViewCargo::ShowFile(const std::string& file, const uint8_t& flag)
{
//Zamiania crc liczbowej na hex string
std::stringstream ss;
ss << "0x" << std::hex << std::uppercase << hash;
std::vector<ftxui::Element> cell;
ftxui::Element eZip;
ftxui::Element eEnc;
std::string compresedCheck = "[ ]";
std::string encryptedCheck = "[ ]";
// Ustawianie checkboxów
switch (zip)
switch (flag)
{
case 1:
eZip = ftxui::text(" [x] ") | ftxui::color(ftxui::Color::Cyan);
eEnc = ftxui::text(" [ ] ") | ftxui::color(ftxui::Color::White);
case FILE_FLAG_COMPRESS:
compresedCheck = "[x]";
break;
case 2:
eZip = ftxui::text(" [ ] ") | ftxui::color(ftxui::Color::White);
eEnc = ftxui::text(" [x] ") | ftxui::color(ftxui::Color::Cyan);
case FILE_FLAG_ENCRYPT:
encryptedCheck = "[x]";
break;
case 3:
eZip = ftxui::text(" [x] ") | ftxui::color(ftxui::Color::Cyan);
eEnc = ftxui::text(" [x] ") | ftxui::color(ftxui::Color::Cyan);
case FILE_FLAG_ZIPENC:
compresedCheck = "[x]";
encryptedCheck = "[x]";
break;
default:
eZip = ftxui::text(" [ ] ") | ftxui::color(ftxui::Color::White);
eEnc = ftxui::text(" [ ] ") | ftxui::color(ftxui::Color::White);
compresedCheck = "[ ]";
encryptedCheck = "[ ]";
break;
}
//Dodawanie komurek
cell.push_back(eZip);
cell.push_back(eEnc | ftxui::size(ftxui::WIDTH, ftxui::EQUAL, 7));
cell.push_back(ftxui::text(file) | ftxui::size(ftxui::WIDTH, ftxui::EQUAL, 56));
cell.push_back(ftxui::text(ss.str()) | ftxui::size(ftxui::WIDTH, ftxui::EQUAL, 20));
//Konwersja komurek na wiersz
filesList.push_back(ftxui::hbox(std::move(cell)));
}
//-----------------------------------------------------------------------------
// Renderowanie listy plików
//-----------------------------------------------------------------------------
void ViewCargo::RenderList()
{
//Dodawanie wierszy do kolumn
ftxui::Element table = ftxui::vbox(std::move(filesList));
auto screen = ftxui::Screen::Create(ftxui::Dimension::Fit(table));
ftxui::Render(screen, table);
screen.Print();
// Wyœwietlanie
std::cout << compresedCheck << " " << encryptedCheck << " " << file << std::endl;
}

View file

@ -27,6 +27,7 @@
#include <sstream>
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#include <ftxui/dom/table.hpp>
#include "DataStruct.h"
@ -38,17 +39,8 @@ public:
bool View(const std::string&);
private:
const std::string signature;
const uint16_t version;
uint32_t filesLen;
uint64_t tablePos;
std::vector<ftxui::Element> filesList;
bool CheckCargoFile(const std::string&);
void GetFileList(const std::string&);
void RenderList();
void CreateTableRow(const std::string&, const uint8_t&, const uint64_t&);
bool ViewFiles(const std::string&);
void ShowFile(const std::string&, const uint8_t&);
};

21
license/FTXUI/LICENSE.txt Normal file
View file

@ -0,0 +1,21 @@
The MIT License
Copyright (c) 2019 Arthur Sonzogni.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View file

@ -1,12 +0,0 @@
This repository uses 2 different licenses :
- all files in the `lib` directory use a BSD 2-Clause license
- all other files use a GPL-2.0-or-later license, unless explicitly stated otherwise
Relevant license is reminded at the top of each source file,
and with presence of COPYING or LICENSE file in associated directories.
This model is selected to emphasize that
files in the `lib` directory are designed to be included into 3rd party applications,
while all other files, in `programs`, `tests` or `examples`,
are intended to be used "as is", as part of their intended scenarios,
with no intention to support 3rd party integration use cases.

30
license/zstd/LICENSE.txt Normal file
View file

@ -0,0 +1,30 @@
BSD License
For Zstandard software
Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name Facebook, nor Meta, nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View file

@ -1,251 +1,126 @@
Nam strzelać nie kazano. - Wstąpiłem na działo
I spójrzałem na pole; dwieście armat grzmiało.
Artyleryi ruskiej ciągną się szeregi,
Prosto, długo, daleko, jako morza brzegi;
I widziałem ich wodza: przybiegł, mieczem skinął
I jak ptak jedno skrzydło wojska swego zwinął;
Wylewa się spod skrzydła ściśniona piechota
Długą czarną kolumną, jako lawa błota,
Nasypana iskrami bagnetów. Jak sępy
Czarne chorągwie na śmierć prowadzą zastępy.
Przeciw nim sterczy biała, wąska, zaostrzona,
Jak głaz bodzący morze, reduta Ordona.
Sześć tylko miała armat; wciąż dymią i świecą;
I nie tyle prędkich słów gniewne usta miecą,
Nie tyle przejdzie uczuć przez duszę w rozpaczy,
Ile z tych dział leciało bomb, kul i kartaczy.
Patrz, tam granat w sam środek kolumny się nurza,
Jak w fale bryła lawy, pułk dymem zachmurza;
Pęka śród dymu granat, szyk pod niebo leci
I ogromna łysina śród kolumny świeci.
Tam kula, lecąc, z dala grozi, szumi, wyje.
Ryczy jak byk przed bitwą, miota się, grunt ryje; -
Już dopadła; jak boa śród kolumn się zwija,
Pali piersią, rwie zębem, oddechem zabija.
Najstraszniejszej nie widać, lecz słychać po dźwięku,
Po waleniu się trupów, po ranionych jęku:
Gdy kolumnę od końca do końca przewierci,
Jak gdyby środkiem wojska przeszedł anioł śmierci.
Gdzież jest król, co na rzezie tłumy te wyprawia?
Czy dzieli ich odwagę, czy pierś sam nadstawia?
Nie, on siedzi o pięćset mil na swej stolicy,
Król wielki, samowładnik świata połowicy;
Zmarszczył brwi, - i tysiące kibitek wnet leci;
Podpisał, - tysiąc matek opłakuje dzieci;
Skinął, - padają knuty od Niemna do Chiwy.
Mocarzu, jak Bóg silny, jak szatan złośliwy,
Gdy Turków za Bałkanem twoje straszą spiże,
Gdy poselstwo paryskie twoje stopy liże, -
Warszawa jedna twojej mocy się urąga,
Podnosi na cię rękę i koronę ściąga,
Koronę Kazimierzów, Chrobrych z twojej głowy,
Boś ją ukradł i skrwawił, synu Wasilowy!
Car dziwi się - ze strachu. drzą Petersburczany,
Car gniewa się - ze strachu mrą jego dworzany;
Ale sypią się wojska, których Bóg i wiara
Jest Car. - Car gniewny: umrzem, rozweselim Cara.
Posłany wódz kaukaski z siłami pół-świata,
Wierny, czynny i sprawny - jak knut w ręku kata.
Ura! ura! Patrz, blisko reduty, już w rowy
Walą się, na faszynę kładąc swe tułowy;
Już czernią się na białych palisadach wałów.
Jeszcze reduta w środku, jasna od wystrzałów,
Czerwieni się nad czernią: jak w środek mrowiaka
Wrzucony motyl błyska, - mrowie go naciska, -
Zgasł - tak zgasła reduta. Czyż ostatnie działo
Strącone z łoża w piasku paszczę zagrzebało?
Czy zapał krwią ostatni bombardyjer zalał?
Zgasnął ogień. - Już Moskal rogatki wywalał.
Gdzież ręczna broń? - Ach, dzisiaj pracowała więcej
Niż na wszystkich przeglądach za władzy książęcej;
Zgadłem, dlaczego milczy, - bo nieraz widziałem
Garstkę naszych walczącą z Moskali nawałem.
Gdy godzinę wołano dwa słowa: pal, nabij;
Gdy oddechy dym tłumi, trud ramiona słabi;
A wciąż grzmi rozkaz wodzów, wre żołnierza czynność;
Na koniec bez rozkazu pełnią swą powinność,
Na koniec bez rozwagi, bez czucia, pamięci,
Żołnierz jako młyn palny nabija - grzmi - kręci
Broń od oka do nogi, od nogi na oko:
Aż ręka w ładownicy długo i głęboko
Szukała, nie znalazła - i żołnierz pobladnął,
Nie znalazłszy ładunku, już bronią nie władnął;
I uczuł, że go pali strzelba rozogniona;
Upuścił ją i upadł; - nim dobiją, skona.
Takem myślił, - a w szaniec nieprzyjaciół kupa
Już łazła, jak robactwo na świeżego trupa.
Pociemniało mi w oczach - a gdym łzy ocierał,
Słyszałem, że coś do mnie mówił mój Jenerał.
On przez lunetę wspartą na moim ramieniu
Długo na szturm i szaniec poglądał w milczeniu.
Na koniec rzekł; "Stracona". - Spod lunety jego
Wymknęło się łez kilka, - rzekł do mnie: "Kolego,
Wzrok młody od szkieł lepszy; patrzaj, tam na wale,
Znasz Ordona, czy widzisz, gdzie jest?" - "Jenerale,
Czy go znam? - Tam stał zawsze, to działo kierował.
Nie widzę - znajdę - dojrzę! - śród dymu się schował:
Lecz śród najgęstszych kłębów dymu ileż razy
Widziałem rękę jego, dającą rozkazy. -
Widzę go znowu, - widzę rękę - błyskawicę,
Wywija, grozi wrogom, trzyma palną świécę,
Biorą go - zginął - o nie, - skoczył w dół, - do lochów"!
"Dobrze - rzecze Jenerał - nie odda im prochów".
Tu blask - dym - chwila cicho - i huk jak stu gromów.
Zaćmiło się powietrze od ziemi wylomów,
Harmaty podskoczyły i jak wystrzelone
Toczyły się na kołach - lonty zapalone
Nie trafiły do swoich panew. I dym wionął
Prosto ku nam; i w gęstej chmurze nas ochłonął.
I nie było nic widać prócz granatów blasku,
I nie było nic widać prócz granatów blasku
I powoli dym rzedniał, opadał deszcz piasku.
Spojrzałem na redutę; - wały, palisady,
Działa i naszych garstka, i wrogów gromady;
Wszystko jako sen znikło. - Tylko czarna bryła
Ziemi niekształtnej leży - rozjemcza mogiła.
Tam i ci, co bronili, -i ci, co się wdarli,
Pierwszy raz pokój szczery i wieczny zawarli.
Choćby cesarz Moskalom kazał wstać, już dusza
Moskiewska. tam raz pierwszy, cesarza nie słusza.
Tam zagrzebane tylu set ciała, imiona:
Dusze gdzie? nie wiem; lecz wiem, gdzie dusza Ordona.
On będzie Patron szańców! - Bo dzieło zniszczenia
W dobrej sprawie jest święte, Jak dzieło tworzenia;
Bóg wyrzekł słowo stań się, Bóg i zgiń wyrzecze.
Kiedy od ludzi wiara i wolność uciecze,
Kiedy ziemię despotyzm i duma szalona
Obleją, jak Moskale redutę Ordona -
Karząc plemię zwyciężców zbrodniami zatrute,
Bóg wysadzi tę ziemię, jak on swą redutę.

View file

@ -32,7 +32,7 @@
#include "CreateCargo.h"
#include "ExtractCargo.h"
#include "ViewCargo.h"
#include "Interface.h"
#include "Tui.h"
void RenderHelp()
{
@ -82,17 +82,7 @@ static bool EmptyPath(std::string path)
int main(int argc, char* argv[]) {
std::string path = "";
std::cout <<
" 8888888b. d8888 888 d8P \n"
" 888 Y88b d88888 888 d8P \n"
" 888 888 d88P888 888 d8P \n"
" .d88b. 888 888 888 d88P d88P 888 888d88K \n"
"d8P Y8b `Y8bd8P' 8888888P\" d88P 888 8888888b \n"
"88888888 X88K 888 d88P 888 888 Y88b \n"
"Y8b. .d8\"\"8b. 888 d8888888888 888 Y88b \n"
" \"Y8888 888 888 888 d88P 888 888 Y88b\n"
<< std::endl;
std::cout << "\n" << PROGRAM_VERSION << " Release " << PROGRAM_COMPILING << std::endl;
std::cout << PROGRAM_VERSION << " Release " << PROGRAM_COMPILING << std::endl;
std::cout << "Author: " << PROGRAM_AUTHOR << std::endl;
std::cout << "License: " << PROGRAM_LICENSE << "\n" << std::endl;
@ -110,7 +100,7 @@ int main(int argc, char* argv[]) {
if (!EmptyPath(path)) { return 1; }
if (!cargo.Create(path, 1))
if (!cargo.Create(path, 0x0F))
{
return 1;
}
@ -120,7 +110,7 @@ int main(int argc, char* argv[]) {
if (arg == "-r" && i + 1 < argc)
{
path = argv[i + 1];
if (!cargo.Create(path, 0))
if (!cargo.Create(path, 0x00))
{
return 1;
}
@ -130,7 +120,7 @@ int main(int argc, char* argv[]) {
if (arg == "-e" && i + 1 < argc)
{
path = argv[i + 1];
if (!cargo.Create(path, 2))
if (!cargo.Create(path, 0xF0))
{
return 1;
}
@ -140,7 +130,7 @@ int main(int argc, char* argv[]) {
if (arg == "-s" && i + 1 < argc)
{
path = argv[i + 1];
if (!cargo.Create(path, 3))
if (!cargo.Create(path, 0xFF))
{
return 1;
}
@ -151,7 +141,7 @@ int main(int argc, char* argv[]) {
{
path = argv[i + 1];
if (!EmptyPath(path)) { return 1; }
if (!cargo.Create(path, -1))
if (!cargo.Create(path, 0xAB))
{
return 1;
}

View file

@ -101,16 +101,16 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions);SODIUM_STATIC</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>3rd\ftxui\include;3rd\libsodium\include;3rd\json\include;3rd\zstd\include;3rd\xxhash\include;3rd\xxhash\include</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalIncludeDirectories>3rd\libsodium\include;3rd\json\include;3rd\zstd\include;3rd\xxhash\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>3rd\zstd\lib\Debug;3rd\ftxui\Debug;3rd\xxhash\lib\Debug;3rd\libsodium\lib\Debug</AdditionalLibraryDirectories>
<AdditionalDependencies>ftxui-component.lib;ftxui-dom.lib;ftxui-screen.lib;libsodium.lib;zstd_static.lib;xxhash.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>3rd\zstd\lib\Debug;3rd\xxhash\lib\Debug;3rd\libsodium\x64\Debug\v143\static</AdditionalLibraryDirectories>
<AdditionalDependencies>libsodium.lib;zstd_static.lib;xxhash.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@ -119,36 +119,32 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions);SODIUM_STATIC</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>3rd\ftxui\include;3rd\libsodium\include;3rd\json\include;3rd\zstd\include;3rd\xxhash\include;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>3rd\libsodium\include;3rd\json\include;3rd\zstd\include;3rd\xxhash\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>3rd\zstd\lib\Release;3rd\libsodium\lib\Release;3rd\xxhash\lib\Release;3rd\ftxui\Release</AdditionalLibraryDirectories>
<AdditionalDependencies>ftxui-component.lib;ftxui-dom.lib;ftxui-screen.lib;libsodium.lib;zstd_static.lib;xxhash.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>3rd\zstd\lib\Release;3rd\libsodium\x64\Release\v143\static;3rd\xxhash\lib\Release</AdditionalLibraryDirectories>
<AdditionalDependencies>libsodium.lib;zstd_static.lib;xxhash.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="ChunkManager.cpp" />
<ClCompile Include="CompressionManager.cpp" />
<ClCompile Include="CreateCargo.cpp" />
<ClCompile Include="EncryptionManager.cpp" />
<ClCompile Include="ExtractCargo.cpp" />
<ClCompile Include="Interface.cpp" />
<ClCompile Include="ViewCargo.cpp" />
<ClCompile Include="voidcmd.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ChunkManager.h" />
<ClInclude Include="CompressionManager.h" />
<ClInclude Include="CreateCargo.h" />
<ClInclude Include="DataStruct.h" />
<ClInclude Include="EncryptionManager.h" />
<ClInclude Include="ExtractCargo.h" />
<ClInclude Include="Interface.h" />
<ClInclude Include="ViewCargo.h" />
</ItemGroup>
<ItemGroup>

View file

@ -27,12 +27,6 @@
<ClCompile Include="ViewCargo.cpp">
<Filter>Pliki źródłowe</Filter>
</ClCompile>
<ClCompile Include="Interface.cpp">
<Filter>Pliki źródłowe</Filter>
</ClCompile>
<ClCompile Include="ChunkManager.cpp">
<Filter>Pliki źródłowe</Filter>
</ClCompile>
<ClCompile Include="EncryptionManager.cpp">
<Filter>Pliki źródłowe</Filter>
</ClCompile>
@ -53,12 +47,6 @@
<ClInclude Include="DataStruct.h">
<Filter>Pliki nagłówkowe</Filter>
</ClInclude>
<ClInclude Include="Interface.h">
<Filter>Pliki nagłówkowe</Filter>
</ClInclude>
<ClInclude Include="ChunkManager.h">
<Filter>Pliki nagłówkowe</Filter>
</ClInclude>
<ClInclude Include="EncryptionManager.h">
<Filter>Pliki nagłówkowe</Filter>
</ClInclude>