Osadziłem w extraktorze wykrywanie metody pakowania na podstawie wartości flagi. Klucz jest importowany w momęcie jego wykrycia, Podmieniłem poprzednią metodę pliku konfiguracyjnego z txt na json (nie przetestowano). Brak flagi do generowania pliku HPP z tablicami kluczy.
This commit is contained in:
parent
8402ce1b65
commit
293c1412ad
10 changed files with 18 additions and 34 deletions
|
|
@ -180,22 +180,18 @@ void CreateCargo::computingBytes(const int8_t& flag, std::vector<char>& input, s
|
||||||
switch (flag)
|
switch (flag)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
std::cout << "COMPRESSING" << std::endl;
|
|
||||||
output = cm.compress(input);
|
output = cm.compress(input);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
std::cout << "ENCRYPTION" << std::endl;
|
|
||||||
output = crypt.encrypt(input);
|
output = crypt.encrypt(input);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
std::cout << "ZIP ENC" << std::endl;
|
|
||||||
output = crypt.encrypt(cm.compress(input));
|
output = crypt.encrypt(cm.compress(input));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
std::cout << "RAW" << std::endl;
|
|
||||||
output = std::move(input);
|
output = std::move(input);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ public:
|
||||||
private:
|
private:
|
||||||
const std::string signature;
|
const std::string signature;
|
||||||
const std::string extension;
|
const std::string extension;
|
||||||
const uint8_t version;
|
const short version;
|
||||||
|
|
||||||
int8_t methodFlags;
|
int8_t methodFlags;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,9 @@ enum StoreMethod
|
||||||
|
|
||||||
//Prgoram title
|
//Prgoram title
|
||||||
#define PROGRAM_TITLE "eXtendet PAK"
|
#define PROGRAM_TITLE "eXtendet PAK"
|
||||||
#define PROGRAM_VERSION "v1.1"
|
#define PROGRAM_VERSION "v1.2"
|
||||||
#define PROGRAM_AUTHOR "Yanczi"
|
#define PROGRAM_AUTHOR "Yanczi"
|
||||||
#define PROGRAM_COMPILING "24 October 2025"
|
#define PROGRAM_COMPILING "08 November 2025"
|
||||||
#define PROGRAM_LICENSE "GNU LGPL v3"
|
#define PROGRAM_LICENSE "GNU LGPL v3"
|
||||||
|
|
||||||
//Limity
|
//Limity
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,6 @@ void EncryptionManager::generateKeys()
|
||||||
{
|
{
|
||||||
if (keyReady) return;
|
if (keyReady) return;
|
||||||
|
|
||||||
std::cout << "GENEROWANIE KLUCZA" << std::endl;
|
|
||||||
|
|
||||||
//randombytes_buf(key.data(), key.size());
|
//randombytes_buf(key.data(), key.size());
|
||||||
crypto_stream_chacha20_ietf_keygen(key.data());
|
crypto_stream_chacha20_ietf_keygen(key.data());
|
||||||
randombytes_buf(nonce.data(), nonce.size());
|
randombytes_buf(nonce.data(), nonce.size());
|
||||||
|
|
@ -44,8 +42,6 @@ void EncryptionManager::generateKeys()
|
||||||
|
|
||||||
void EncryptionManager::saveKey(const std::string& path)
|
void EncryptionManager::saveKey(const std::string& path)
|
||||||
{
|
{
|
||||||
std::cout << "ZAPISYWANIE KLUCZA" << std::endl;
|
|
||||||
|
|
||||||
const int sig = SIGNATURE_KEY_FILE;
|
const int sig = SIGNATURE_KEY_FILE;
|
||||||
const short ver = VERSION;
|
const short ver = VERSION;
|
||||||
|
|
||||||
|
|
@ -65,7 +61,7 @@ void EncryptionManager::saveKey(const std::string& path)
|
||||||
|
|
||||||
// Zapisz ten œmietnik do pliku KEY
|
// Zapisz ten œmietnik do pliku KEY
|
||||||
std::ofstream file(path + ".key", std::ios::binary);
|
std::ofstream file(path + ".key", std::ios::binary);
|
||||||
if (!file) { std::cout << "Dupa nie zapisa³o" << std::endl; }
|
if (!file) { std::cout << "Failed to save encryption key to file" << std::endl; }
|
||||||
|
|
||||||
file.write(reinterpret_cast<const char*>(&sig), sizeof(sig));
|
file.write(reinterpret_cast<const char*>(&sig), sizeof(sig));
|
||||||
file.write(reinterpret_cast<const char*>(&ver), sizeof(ver));
|
file.write(reinterpret_cast<const char*>(&ver), sizeof(ver));
|
||||||
|
|
@ -75,8 +71,6 @@ void EncryptionManager::saveKey(const std::string& path)
|
||||||
file.write(reinterpret_cast<const char*>(nonceVec.data()), nonceVec.size());
|
file.write(reinterpret_cast<const char*>(nonceVec.data()), nonceVec.size());
|
||||||
file.write(reinterpret_cast<const char*>(&crcNonce), sizeof(crcNonce));
|
file.write(reinterpret_cast<const char*>(&crcNonce), sizeof(crcNonce));
|
||||||
|
|
||||||
if (!file.good()) { std::cout << "Dupa nie zapisa³o" << std::endl; }
|
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
//saveCppHeadFile(path);
|
//saveCppHeadFile(path);
|
||||||
|
|
@ -129,7 +123,6 @@ std::string EncryptionManager::toHex(const std::vector<unsigned char>& data)
|
||||||
// Wczytaj klucz
|
// Wczytaj klucz
|
||||||
void EncryptionManager::loadKey(const std::string& path)
|
void EncryptionManager::loadKey(const std::string& path)
|
||||||
{
|
{
|
||||||
std::cout << "ODCZYT KLUCZA" << std::endl;
|
|
||||||
std::ifstream file(path + ".key", std::ios::binary);
|
std::ifstream file(path + ".key", std::ios::binary);
|
||||||
|
|
||||||
int sig;
|
int sig;
|
||||||
|
|
@ -157,8 +150,6 @@ void EncryptionManager::loadKey(const std::string& path)
|
||||||
file.read(nonceVec.data(), nonceVec.size());
|
file.read(nonceVec.data(), nonceVec.size());
|
||||||
file.read(reinterpret_cast<char*>(&crcNonce), sizeof(crcNonce));
|
file.read(reinterpret_cast<char*>(&crcNonce), sizeof(crcNonce));
|
||||||
|
|
||||||
std::cout << crcKey << " - " << XXH64(keyVec.data(), keyVec.size(), VERSION) << std::endl;
|
|
||||||
|
|
||||||
// SprawdŸ integralnoœæ klucza
|
// SprawdŸ integralnoœæ klucza
|
||||||
if (XXH64(keyVec.data(), keyVec.size(), VERSION) != crcKey
|
if (XXH64(keyVec.data(), keyVec.size(), VERSION) != crcKey
|
||||||
|| XXH64(nonceVec.data(), nonceVec.size(), VERSION) != crcNonce)
|
|| XXH64(nonceVec.data(), nonceVec.size(), VERSION) != crcNonce)
|
||||||
|
|
|
||||||
|
|
@ -62,8 +62,12 @@ bool ExtractCargo::Extract(const std::string& cFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wczytaj klucz deszyfruj¹cy
|
// Wczytaj klucz deszyfruj¹cy
|
||||||
//std::filesystem::path kdir = cargoFileName.stem();
|
std::filesystem::path kdir = cargoFileName.stem();
|
||||||
//eman.loadKey(kdir.string());
|
if (std::filesystem::exists(kdir.string() + ".key"))
|
||||||
|
{
|
||||||
|
std::cout << "Decryption key detected" << std::endl;
|
||||||
|
eman.loadKey(kdir.string());
|
||||||
|
}
|
||||||
|
|
||||||
//Otwieranie kontenera
|
//Otwieranie kontenera
|
||||||
cargoFile.open(cargoFileName, std::ios::binary);
|
cargoFile.open(cargoFileName, std::ios::binary);
|
||||||
|
|
@ -85,7 +89,7 @@ bool ExtractCargo::Extract(const std::string& cFile)
|
||||||
bool ExtractCargo::CheckCargoFile()
|
bool ExtractCargo::CheckCargoFile()
|
||||||
{
|
{
|
||||||
std::vector<char> magic(signature.size());
|
std::vector<char> magic(signature.size());
|
||||||
uint16_t cargoVer = 0;
|
short cargoVer = 0;
|
||||||
|
|
||||||
if (!cargoFile.is_open())
|
if (!cargoFile.is_open())
|
||||||
{
|
{
|
||||||
|
|
@ -98,8 +102,6 @@ bool ExtractCargo::CheckCargoFile()
|
||||||
cargoFile.read(reinterpret_cast<char*>(&filesLen), sizeof(filesLen));
|
cargoFile.read(reinterpret_cast<char*>(&filesLen), sizeof(filesLen));
|
||||||
cargoFile.read(reinterpret_cast<char*>(&tablePosition), sizeof(tablePosition));
|
cargoFile.read(reinterpret_cast<char*>(&tablePosition), sizeof(tablePosition));
|
||||||
|
|
||||||
std::cout << std::string(magic.begin(), magic.end()) << std::endl;
|
|
||||||
|
|
||||||
if (std::string(magic.begin(), magic.end()) != signature)
|
if (std::string(magic.begin(), magic.end()) != signature)
|
||||||
{
|
{
|
||||||
std::cerr << "Error: Corrupted Cargo" << std::endl;
|
std::cerr << "Error: Corrupted Cargo" << std::endl;
|
||||||
|
|
@ -154,7 +156,7 @@ void ExtractCargo::computingBytes(const std::vector<char>& input, std::vector<ch
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
output = std::move(input);
|
output = input;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -165,7 +167,6 @@ void ExtractCargo::computingBytes(const std::vector<char>& input, std::vector<ch
|
||||||
void ExtractCargo::LoadFilesTable()
|
void ExtractCargo::LoadFilesTable()
|
||||||
{
|
{
|
||||||
cargoFile.seekg(tablePosition);
|
cargoFile.seekg(tablePosition);
|
||||||
std::cout << "TU TABLICA" << std::endl;
|
|
||||||
for (uint32_t i = 0; i < filesLen; ++i)
|
for (uint32_t i = 0; i < filesLen; ++i)
|
||||||
{
|
{
|
||||||
FilesTable fhTmp;
|
FilesTable fhTmp;
|
||||||
|
|
@ -175,8 +176,6 @@ void ExtractCargo::LoadFilesTable()
|
||||||
cargoFile.read(nameBuffor.data(), fhTmp.nameLen);
|
cargoFile.read(nameBuffor.data(), fhTmp.nameLen);
|
||||||
fhTmp.nameFile = std::string(nameBuffor.begin(), nameBuffor.end());
|
fhTmp.nameFile = std::string(nameBuffor.begin(), nameBuffor.end());
|
||||||
|
|
||||||
std::cout << fhTmp.nameFile << std::endl;
|
|
||||||
|
|
||||||
cargoFile.read(reinterpret_cast<char*>(&fhTmp.hashName), sizeof(fhTmp.hashName));
|
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.offset), sizeof(fhTmp.offset));
|
||||||
cargoFile.read(reinterpret_cast<char*>(&fhTmp.size), sizeof(fhTmp.size));
|
cargoFile.read(reinterpret_cast<char*>(&fhTmp.size), sizeof(fhTmp.size));
|
||||||
|
|
@ -192,14 +191,10 @@ void ExtractCargo::LoadFilesTable()
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void ExtractCargo::ExtractingFilesFromCargo()
|
void ExtractCargo::ExtractingFilesFromCargo()
|
||||||
{
|
{
|
||||||
CompressingManager cm;
|
|
||||||
|
|
||||||
for (const auto& fh : filesHeads)
|
for (const auto& fh : filesHeads)
|
||||||
{
|
{
|
||||||
std::filesystem::path dir = cargoFileName.stem() / fh.nameFile;
|
std::filesystem::path dir = cargoFileName.stem() / fh.nameFile;
|
||||||
CreateDirections(dir);
|
CreateDirections(dir);
|
||||||
std::cout << "TU EXTRAT" << std::endl;
|
|
||||||
std::cout << dir << std::endl;
|
|
||||||
std::ofstream file(dir, std::ios::binary);
|
std::ofstream file(dir, std::ios::binary);
|
||||||
|
|
||||||
cargoFile.seekg(fh.offset);
|
cargoFile.seekg(fh.offset);
|
||||||
|
|
@ -208,7 +203,7 @@ void ExtractCargo::ExtractingFilesFromCargo()
|
||||||
cargoFile.read(buffor.data(), fh.size);
|
cargoFile.read(buffor.data(), fh.size);
|
||||||
|
|
||||||
std::vector<char> rawBuffor;
|
std::vector<char> rawBuffor;
|
||||||
computingBytes(buffor, rawBuffor, fh.size);
|
computingBytes(buffor, rawBuffor, fh.flag);
|
||||||
|
|
||||||
if (!HashValid(rawBuffor, fh.crc))
|
if (!HashValid(rawBuffor, fh.crc))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -47,9 +47,9 @@ private:
|
||||||
|
|
||||||
uint32_t filesLen;
|
uint32_t filesLen;
|
||||||
uint64_t tablePosition;
|
uint64_t tablePosition;
|
||||||
uint8_t filesHeadsOffset;
|
int filesHeadsOffset;
|
||||||
|
|
||||||
const uint8_t version;
|
const short version;
|
||||||
const std::string signature;
|
const std::string signature;
|
||||||
|
|
||||||
std::vector<FilesTable> filesHeads;
|
std::vector<FilesTable> filesHeads;
|
||||||
|
|
|
||||||
1
test3/plik1.bin
Normal file
1
test3/plik1.bin
Normal file
File diff suppressed because one or more lines are too long
1
test3/plik2.bin
Normal file
1
test3/plik2.bin
Normal file
File diff suppressed because one or more lines are too long
BIN
test3/plik3.bin
Normal file
BIN
test3/plik3.bin
Normal file
Binary file not shown.
|
|
@ -68,7 +68,7 @@ void RenderHelp()
|
||||||
//tui.TextBorder(HelpTitle, HelpInstruction);
|
//tui.TextBorder(HelpTitle, HelpInstruction);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmptyPath(std::string path)
|
static bool EmptyPath(std::string path)
|
||||||
{
|
{
|
||||||
if (path == "")
|
if (path == "")
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue