Android直接执行so里的函数

https://mabin004.github.io/2018/02/06/Android直接执行so里的函数/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>

int main(int argc, char *argv[])
{
//decrypt_db in.db out.db key

//char key_in[256] = "thMSot/QNM/iFsDVNksPtXHiqi0wxjD0m2SMLipLEQ4=";
char *in_db = argv[1];
char *out_db = argv[2];

char *key_in = argv[3];
char key_out[256] = {0};

void *p;
void (*key_func)(char *, char *);
void (*decrypt)(char *, char *, char *);

//dlopen
p=dlopen("./libdatabase_sqlcrypto.so",RTLD_NOW);
if(p==NULL)
{
printf("dlopen error!\n");
exit(0);
}
else
printf("dlopen ok!\n");

//dlsym aes_decrypt_key128
key_func=dlsym(p, "aes_decrypt_key128");
key_func(key_in, key_out);
//printf("key_in:%s\n", key_in);
//printf("key_out:%s\n", key_out);

char cipher[16] = {0};
char plain[16] = {0};

//read cipher
FILE *fp_read;
fp_read = fopen(in_db, "rb");
FILE *fp_write;
fp_write = fopen(out_db, "wb");

//dlsym aes_decrypt
decrypt=dlsym(p, "aes_decrypt");

while(fread(cipher, 1, 16, (FILE*)fp_read) == 16) //read cipher
{
//decrypt
decrypt(cipher, plain, key_out);

//write plain
fwrite(plain, 1, 16, (FILE*)fp_write);
}

fclose(fp_read);
fclose(fp_write);
dlclose(p);
}

转载注明原文:Android直接执行so里的函数