diff --git a/android/dalvik/libdex/DexSwapVerify.cpp b/android/dalvik/libdex/DexSwapVerify.cpp
old mode 100644
new mode 100755
index ff47ab5..aac9f3b
--- a/android/dalvik/libdex/DexSwapVerify.cpp
+++ b/android/dalvik/libdex/DexSwapVerify.cpp
@@ -31,6 +31,9 @@
#include <stdlib.h>
#include <string.h>
+#include <openssl/aes.h>
+#include <openssl/pkcs7.h>
+
#ifndef __BYTE_ORDER
# error "byte ordering not defined"
#endif
@@ -2799,7 +2802,7 @@ bool dexHasValidMagic(const DexHeader* pHeader)
const u1* magic = pHeader->magic;
const u1* version = &magic[4];
- if (memcmp(magic, DEX_MAGIC, 4) != 0) {
+ if (memcmp(magic, DEX_MAGIC, 4) != 0 && memcmp(magic, DEX_MY_MAGIC, 4) != 0) {
ALOGE("ERROR: unrecognized magic number (%02x %02x %02x %02x)",
magic[0], magic[1], magic[2], magic[3]);
return false;
@@ -2819,6 +2822,26 @@ bool dexHasValidMagic(const DexHeader* pHeader)
return true;
}
+void decryptDex(u1* addr, int len)
+{
+ ALOGE("decryptDex");
+ AES_KEY aes;
+ unsigned char ivec[17] = "AESmyencryptokey";
+ unsigned char key[17] = "myencryptokeyAES";
+ AES_set_decrypt_key(key, 128, &aes);
+
+ int Len = (len-0x70)/16;
+ int iLen = Len*16;
+ unsigned char* tmp = new unsigned char[iLen];
+// ALOGE("decrypt, byte[0x70]=%x byte[0x71]=%x byte[0x72]=%x byte[0x73]=%x byte[0x74]=%x byte[75]=%x byte[76]=%x byte[77]=%x",
+// addr[0x70], addr[0x71], addr[0x72], addr[0x73], addr[0x74], addr[0x75], addr[0x76], addr[0x77]);
+ AES_cbc_encrypt((const unsigned char*)(addr+len-iLen), tmp, iLen, &aes, ivec, AES_DECRYPT);
+// ALOGE("tmp, byte[0x70]=%x byte[0x71]=%x byte[0x72]=%x byte[0x73]=%x byte[0x74]=%x byte[75]=%x byte[76]=%x byte[77]=%x",
+// tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5], tmp[6], tmp[7]);
+ memcpy(addr+len-iLen, tmp, iLen);
+ delete tmp;
+}
+
/*
* Fix the byte ordering of all fields in the DEX file, and do
* structural verification. This is only required for code that opens
@@ -2846,6 +2869,12 @@ int dexSwapAndVerify(u1* addr, int len)
}
if (okay) {
+ if(memcmp(pHeader->magic, DEX_MY_MAGIC, 4) == 0) {
+ decryptDex(addr, len);
+ }
+ }
+
+ if (okay) {
int expectedLen = (int) SWAP4(pHeader->fileSize);
if (len < expectedLen) {
ALOGE("ERROR: Bad length: expected %d, got %d", expectedLen, len);
@@ -2959,7 +2988,7 @@ int dexSwapAndVerifyIfNecessary(u1* addr, int len)
return 0;
}
- if (memcmp(addr, DEX_MAGIC, 4) == 0) {
+ if (memcmp(addr, DEX_MAGIC, 4) == 0 || memcmp(addr, DEX_MY_MAGIC, 4) == 0) {
// It is an unoptimized dex file.
return dexSwapAndVerify(addr, len);
}