From bbdd6a02b26cac774755df51b32896b6f3426b1e Mon Sep 17 00:00:00 2001 From: wangdongpo <544209413@qq.com> Date: Tue, 21 Jan 2025 15:02:34 +0800 Subject: [PATCH] =?UTF-8?q?(=E4=BC=98=E5=8C=96)=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=86=99=E4=B8=8E=E5=8A=A0=E5=AF=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model2mem.cpp | 64 ++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/src/model2mem.cpp b/src/model2mem.cpp index 65ec562..9c77ad6 100644 --- a/src/model2mem.cpp +++ b/src/model2mem.cpp @@ -7,77 +7,67 @@ using namespace std; // 加密密钥 string ENCRYPTION_KEY = ""; -static int write_file(const std::string & fname, std::vector& buf){ +static int write_file(const std::string& fname, std::vector& buf) { std::ofstream fs(fname, std::ios::binary | std::ios::out); - if(!fs.good()){ - std::cerr< 0) { + for (char& c : buf) { + c ^= ENCRYPTION_KEY[keyIndex]; + keyIndex = (keyIndex + 1) % ENCRYPTION_KEY.length(); + fs << (int)((unsigned char)c) << ","; + } + } + else { + for (char& c : buf) { + fs << (int)((unsigned char)c) << ","; + } } fs.close(); return 0; } -static int load_file(const std::string & fname, std::vector& buf){ +static int load_file(const std::string& fname, std::vector& buf) { std::ifstream fs(fname, std::ios::binary | std::ios::in); - if(!fs.good()){ - std::cerr<" << endl; return -1; } vector content; load_file(argv[1], content); - if(content.size() <= 0) { + if (content.size() <= 0) { cout << "do not read any content" << endl; return -1; } // 如果提供了密码,则进行加密操作 - if(argc == 4) { + if (argc == 4) { ENCRYPTION_KEY = argv[3]; - write_file(argv[2], content); - } else { - // 否则,直接写入文件 - std::ofstream fs(argv[2], std::ios::binary | std::ios::out); - if(!fs.good()) - { - std::cerr<