| 5 |
| #include <inttypes.h> |
| 6 | #include <stdlib.h> |
| 7 | #include <openssl/aes.h> |
| 8 | #include "utils.h" |
| 9 | #include "sqlite.h" |
| 10 | #include "gif.h" |
| 11 | #include "image.h" |
| 12 |
| 13 | int registerNativeTgNetFunctions(JavaVM *vm, JNIEnv *env); |
| 14 |
| 15 | jint JNI_OnLoad(JavaVM *vm, void *reserved) { |
| 16 | JNIEnv *env = 0; |
| 17 | srand(time(NULL)); |
| 18 |
| 19 | if ((*vm)->GetEnv(vm, (void **) &env, JNI_VERSION_1_6) != JNI_OK) { |
| 20 | return -1; |
| 21 | } |
| 22 |
| 23 | if (sqliteOnJNILoad(vm, reserved, env) == -1) { |
| 24 | return -1; |
| 25 | } |
| 26 |
| 27 | if (imageOnJNILoad(vm, reserved, env) == -1) { |
| 28 | return -1; |
| 29 | } |
| 30 |
| 31 | if (registerNativeTgNetFunctions(vm, env) != JNI_TRUE) { |
| 32 | return -1; |
| 33 | } |
| 34 |
| 35 | gifOnJNILoad(vm, reserved, env); |
| 36 |
| 37 | return JNI_VERSION_1_6; |
| 38 | } |
| 39 |
| 40 | void JNI_OnUnload(JavaVM *vm, void *reserved) { |
| 41 | gifOnJNIUnload(vm, reserved); |
| 42 | } |
| 43 |
| 44 | JNIEXPORT void Java_org_telegram_messenger_Utilities_aesIgeEncryption(JNIEnv *env, jclass class, jobject buffer, jbyteArray key, jbyteArray iv, jboolean encrypt, int offset, int length) { |
| 45 | jbyte *what = (*env)->GetDirectBufferAddress(env, buffer) + offset; |
| 46 | unsigned char *keyBuff = (unsigned char *)(*env)->GetByteArrayElements(env, key, NULL); |
| 47 | unsigned char *ivBuff = (unsigned char *)(*env)->GetByteArrayElements(env, iv, NULL); |
| 48 |
| 49 | AES_KEY akey; |
| 50 | if (!encrypt) { |
| 51 | AES_set_decrypt_key(keyBuff, 32 * 8, &akey); |
| 52 | AES_ige_encrypt(what, what, length, &akey, ivBuff, AES_DECRYPT); |
| 53 | } else { |
| 54 | AES_set_encrypt_key(keyBuff, 32 * 8, &akey); |
| 55 | AES_ige_encrypt(what, what, length, &akey, ivBuff, AES_ENCRYPT); |
| 56 | } |
| 57 | (*env)->ReleaseByteArrayElements(env, key, keyBuff, JNI_ABORT); |
| 58 | (*env)->ReleaseByteArrayElements(env, iv, ivBuff, 0); |
| 59 | } |
| 60 |