I have a zip archive encrypted on disk. I read the file into a buffer, decrypt it (using some custom algorythm), and make a zip out of it in memory.
Now I can modify the archive but how do I write back the changes to disk ? Am I missing something ? The archive is created with zip_source_buffer_create(...)
and when calling zip_close(...)
the changes are made to memory.
mcve:
#include <zip.h>
#include <fstream>
#include <filesystem>
#include <vector>
#include <string>
int main(int argc, char** argv) {
std::string zip_file = "test.zip";
size_t file_sz = std::filesystem::file_size("test.zip");
std::vector<char> buf(file_sz);
std::ifstream ifs{ zip_file, std::ios::binary };
ifs.read(buf.data(), file_sz);
/*
buffer is decrypted here
*/
zip_error_t ze;
zip_error_init(&ze);
zip_source_t* zip_source = zip_source_buffer_create(buf.data(), buf.size(), 1, &ze);
zip_t* zip = zip_open_from_source(zip_source, NULL, &ze);
zip_source_t* file_source = zip_source_buffer(zip, "hello", 6, 0);
zip_file_add(zip, "hello.txt", file_source, ZIP_FL_ENC_GUESS);
zip_source_free(file_source);
zip_error_fini(&ze);
zip_close(zip); //modifications are written to memory but how do I retrieve the data?
/*
zip data should be acquired here, encrypted, and written to disk
*/
return 0;
}