Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <ostream>
- #include <string>
- #include <openssl/evp.h>
- #include <openssl/err.h>
- #include <openssl/ssl.h>
- #define _CRT_SECURE_NO_WARNINGS
- using namespace std;
- typedef std::basic_string<unsigned char> u_string;
- static u_string decode(u_string key, u_string data)
- {
- EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
- EVP_CIPHER_CTX_init(ctx);
- EVP_DecryptInit_ex(ctx, EVP_aes_128_ecb(), NULL, key.c_str(), NULL);
- EVP_CIPHER_CTX_set_padding(ctx, false);
- unsigned char buffer[1024], * pointer = buffer;
- int outlen;
- EVP_DecryptUpdate(ctx, pointer, &outlen, data.c_str(), data.length()) or abort;
- pointer += outlen;
- EVP_DecryptFinal_ex(ctx, pointer, &outlen) or abort;
- pointer += outlen;
- return u_string(buffer, pointer - buffer);
- }
- std::string hexToASCII(string hex)
- {
- int len = hex.length();
- std::string newString;
- for (int i = 0; i < len; i += 2)
- {
- string byte = hex.substr(i, 2);
- char chr = (char)(int)strtol(byte.c_str(), nullptr, 16);
- newString.push_back(chr);
- }
- return newString;
- }
- string getFileName(const string& s) {
- char sep = '/';
- size_t i = s.rfind(sep, s.length());
- if (i != string::npos) {
- return(s.substr(i + 1, s.length() - i));
- }
- return("");
- }
- int main(int argc, char* argv[])
- {
- u_string key = (unsigned char *) (hexToASCII("1c4c1ea3a12531ae491b21bb31613c11")).c_str();
- const char* path = "C:\\Users\\mauro\\source\\repos\\testifstream\\RMX1901EX_11_OTA_0060_all_RkncSf3tpNqEtest.ozip";
- int pk = 0;
- if (argc != 1)
- {
- printf("Usage: ozipdecrypt [*.ozip]");
- return 0;
- }
- else
- {
- FILE* fp;
- char magic[13];
- char data[17];
- FILE* fp2;
- fp = fopen(path, "rb");
- fgets(magic, sizeof(magic), fp);
- if (strcmp(magic, "OPPOENCRYPT!") == 0)
- {
- fseek(fp, 4176, SEEK_SET);
- fgets(data, sizeof(data), fp);
- u_string test = decode(key, (unsigned char*)data);
- u_string checktest = test.substr(0, 4);
- if (checktest == ((unsigned char*) "\x50\x4B\x03\x04") || checktest ==((unsigned char*) "\x41\x4E\x44\x52"))
- {
- printf("Key is good!");
- const char* destpath = "romdecrypted.zip";
- fp2 = fopen(destpath, "wb");
- fseek(fp, 4176, SEEK_SET);
- char data2[16385];
- string temp;
- u_string temp2;
- long check = ftell(fp);
- while (true)
- {
- check = ftell(fp);
- fgets(data, sizeof(data), fp);
- if (sizeof(data) == 0)
- {
- break;
- }
- temp2 = decode(key, (unsigned char*)data);
- const char* ddata=(const char*)temp2.c_str();
- fwrite(ddata, sizeof(char), sizeof(ddata), fp2);
- fseek(fp, check + 16, SEEK_SET);
- fgets(data2, sizeof(data2), fp);
- if (sizeof(data2) == 0)
- {
- break;
- }
- fwrite(data2, sizeof(char), sizeof(data2), fp2);
- fseek(fp, check+16384+16, SEEK_SET);
- }
- fclose(fp2);
- }
- else
- {
- printf("Key is not good!");
- return 0;
- }
- }
- else
- {
- pk = 1;
- }
- fclose(fp);
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement