Android直接执行so里的函数 发表于 2018-02-06 | 阅读次数: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960#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);}