Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <ostream>
  4. #include <string>
  5. #include <openssl/evp.h>
  6. #include <openssl/err.h>
  7. #include <openssl/ssl.h>
  8. #define _CRT_SECURE_NO_WARNINGS
  9.  
  10. using namespace std;
  11. typedef std::basic_string<unsigned char> u_string;
  12.  
  13.  
  14. static u_string decode(u_string key, u_string data)
  15. {
  16. EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
  17. EVP_CIPHER_CTX_init(ctx);
  18. EVP_DecryptInit_ex(ctx, EVP_aes_128_ecb(), NULL, key.c_str(), NULL);
  19. EVP_CIPHER_CTX_set_padding(ctx, false);
  20. unsigned char buffer[1024], * pointer = buffer;
  21. int outlen;
  22. EVP_DecryptUpdate(ctx, pointer, &outlen, data.c_str(), data.length()) or abort;
  23. pointer += outlen;
  24. EVP_DecryptFinal_ex(ctx, pointer, &outlen) or abort;
  25. pointer += outlen;
  26. return u_string(buffer, pointer - buffer);
  27. }
  28.  
  29. std::string hexToASCII(string hex)
  30. {
  31. int len = hex.length();
  32. std::string newString;
  33. for (int i = 0; i < len; i += 2)
  34. {
  35. string byte = hex.substr(i, 2);
  36. char chr = (char)(int)strtol(byte.c_str(), nullptr, 16);
  37. newString.push_back(chr);
  38. }
  39. return newString;
  40. }
  41.  
  42. string getFileName(const string& s) {
  43.  
  44. char sep = '/';
  45.  
  46. size_t i = s.rfind(sep, s.length());
  47. if (i != string::npos) {
  48. return(s.substr(i + 1, s.length() - i));
  49. }
  50.  
  51. return("");
  52. }
  53.  
  54. int main(int argc, char* argv[])
  55. {
  56. u_string key = (unsigned char *) (hexToASCII("1c4c1ea3a12531ae491b21bb31613c11")).c_str();
  57. const char* path = "C:\\Users\\mauro\\source\\repos\\testifstream\\RMX1901EX_11_OTA_0060_all_RkncSf3tpNqEtest.ozip";
  58. int pk = 0;
  59. if (argc != 1)
  60. {
  61. printf("Usage: ozipdecrypt [*.ozip]");
  62. return 0;
  63. }
  64. else
  65. {
  66.  
  67.  
  68. FILE* fp;
  69. char magic[13];
  70. char data[17];
  71. FILE* fp2;
  72.  
  73. fp = fopen(path, "rb");
  74. fgets(magic, sizeof(magic), fp);
  75.  
  76.  
  77. if (strcmp(magic, "OPPOENCRYPT!") == 0)
  78. {
  79. fseek(fp, 4176, SEEK_SET);
  80. fgets(data, sizeof(data), fp);
  81. u_string test = decode(key, (unsigned char*)data);
  82. u_string checktest = test.substr(0, 4);
  83. if (checktest == ((unsigned char*) "\x50\x4B\x03\x04") || checktest ==((unsigned char*) "\x41\x4E\x44\x52"))
  84. {
  85. printf("Key is good!");
  86. const char* destpath = "romdecrypted.zip";
  87. fp2 = fopen(destpath, "wb");
  88. fseek(fp, 4176, SEEK_SET);
  89. char data2[16385];
  90. string temp;
  91. u_string temp2;
  92. long check = ftell(fp);
  93. while (true)
  94. {
  95. check = ftell(fp);
  96. fgets(data, sizeof(data), fp);
  97. if (sizeof(data) == 0)
  98. {
  99. break;
  100. }
  101. temp2 = decode(key, (unsigned char*)data);
  102. const char* ddata=(const char*)temp2.c_str();
  103. fwrite(ddata, sizeof(char), sizeof(ddata), fp2);
  104.  
  105. fseek(fp, check + 16, SEEK_SET);
  106. fgets(data2, sizeof(data2), fp);
  107. if (sizeof(data2) == 0)
  108. {
  109. break;
  110. }
  111. fwrite(data2, sizeof(char), sizeof(data2), fp2);
  112.  
  113. fseek(fp, check+16384+16, SEEK_SET);
  114. }
  115. fclose(fp2);
  116. }
  117. else
  118. {
  119. printf("Key is not good!");
  120. return 0;
  121. }
  122. }
  123. else
  124. {
  125. pk = 1;
  126. }
  127. fclose(fp);
  128. return 0;
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement