2013-10-25 17:19:00 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <jni.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <inttypes.h>
|
2014-03-27 15:25:53 +01:00
|
|
|
#include <stdlib.h>
|
2015-09-24 22:52:02 +02:00
|
|
|
#include <openssl/aes.h>
|
2014-03-27 15:25:53 +01:00
|
|
|
#include "utils.h"
|
|
|
|
#include "sqlite.h"
|
2015-01-02 23:15:07 +01:00
|
|
|
#include "image.h"
|
2014-03-27 15:25:53 +01:00
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
int registerNativeTgNetFunctions(JavaVM *vm, JNIEnv *env);
|
2016-01-11 18:19:48 +01:00
|
|
|
int gifvideoOnJNILoad(JavaVM *vm, JNIEnv *env);
|
2015-09-24 22:52:02 +02:00
|
|
|
|
2014-03-27 15:25:53 +01:00
|
|
|
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
|
|
|
JNIEnv *env = 0;
|
|
|
|
srand(time(NULL));
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
if ((*vm)->GetEnv(vm, (void **) &env, JNI_VERSION_1_6) != JNI_OK) {
|
2014-03-27 15:25:53 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sqliteOnJNILoad(vm, reserved, env) == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
if (imageOnJNILoad(vm, reserved, env) == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
|
|
|
|
if (gifvideoOnJNILoad(vm, env) == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
|
|
|
|
if (registerNativeTgNetFunctions(vm, env) != JNI_TRUE) {
|
|
|
|
return -1;
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
|
|
|
|
return JNI_VERSION_1_6;
|
2014-03-27 15:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void JNI_OnUnload(JavaVM *vm, void *reserved) {
|
2016-01-11 18:19:48 +01:00
|
|
|
|
2014-03-27 15:25:53 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
JNIEXPORT void Java_org_telegram_messenger_Utilities_aesIgeEncryption(JNIEnv *env, jclass class, jobject buffer, jbyteArray key, jbyteArray iv, jboolean encrypt, int offset, int length) {
|
|
|
|
jbyte *what = (*env)->GetDirectBufferAddress(env, buffer) + offset;
|
|
|
|
unsigned char *keyBuff = (unsigned char *)(*env)->GetByteArrayElements(env, key, NULL);
|
|
|
|
unsigned char *ivBuff = (unsigned char *)(*env)->GetByteArrayElements(env, iv, NULL);
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
AES_KEY akey;
|
|
|
|
if (!encrypt) {
|
2014-07-03 00:39:05 +02:00
|
|
|
AES_set_decrypt_key(keyBuff, 32 * 8, &akey);
|
|
|
|
AES_ige_encrypt(what, what, length, &akey, ivBuff, AES_DECRYPT);
|
2014-02-28 23:28:25 +01:00
|
|
|
} else {
|
2014-07-03 00:39:05 +02:00
|
|
|
AES_set_encrypt_key(keyBuff, 32 * 8, &akey);
|
|
|
|
AES_ige_encrypt(what, what, length, &akey, ivBuff, AES_ENCRYPT);
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
(*env)->ReleaseByteArrayElements(env, key, keyBuff, JNI_ABORT);
|
|
|
|
(*env)->ReleaseByteArrayElements(env, iv, ivBuff, 0);
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|