[英]I am unable to extract an executable correctly with libzip
我正在嘗試使用下面的代碼從 zip 存檔中提取可執行文件,但由於某種原因,它沒有將文件正確輸出到磁盤。 當我嘗試運行提取的文件時,出現錯誤“此應用程序無法在您的 PC 上運行”提取時文件大小為 309 KB,因此看起來所有數據都在那里。 我的代碼有什么問題? 當我手動提取它時,它運行得很好。 此外,當我嘗試提取 .txt 文件時,它為每個換行符寫入 2 個換行符而不是 1 個。
int error = 0;
zip *z = zip_open("pathtozip.zip", 0, &error);
struct zip_stat st;
zip_stat_init(&st);
zip_stat(z, "file.exe", 0, &st);
char *contents = new char[st.size];
zip_file *f = zip_fopen(z, "file.exe", ZIP_FL_COMPRESSED);
zip_fread(f, contents, st.size);
zip_fclose(f);
if (std::ofstream("C:\\users\\admin\\desktop\\test.exe", std::ofstream::binary).write(contents, st.size))
std::cout << "File Extracted" << std::endl;
zip_close(z);
ZIP_FL_COMPRESSED
-讀取壓縮數據。 否則數據未壓縮...
這意味着您以壓縮形式從存檔中讀取數據。
只需刪除該標志即可獲得未壓縮的內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.