Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _GNU_SOURCE
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <dlfcn.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <sys/select.h>
- #include <string.h>
- #include <termios.h>
- #include <pthread.h>
- #include <sys/epoll.h>
- #include <jni.h>
- #include <stdlib.h>
- #include <android/log.h>
- #include "../../base/hook.h"
- #include "../../base/base.h"
- #include "log.h"
- void __attribute__ ((constructor)) my_init(void);
- static struct hook_t eph;
- static struct hook_t name_eph;
- static void my_log(char* msg){
- LOG("%s",msg);
- }
- void write_png_data_to_file(const char* data,size_t len){
- LOG("data file length:%d",len);
- char buffer[40] = {0};
- char buffer2[200] = {0};
- char* uuid_path = "/proc/sys/kernel/random/uuid";
- FILE* f_uuid = fopen(uuid_path,"r");
- if(f_uuid){
- fread(buffer,1,36,f_uuid);
- fclose(f_uuid);
- LOG("get uuid ok");
- }
- else{
- LOG("read uuid failed");
- }
- char* filename = "/mnt/sdcard/game_dump/%s.png";
- sprintf(buffer2,filename,buffer);
- LOG("filename:%s",buffer2);
- FILE* fd = fopen(buffer2,"wb");
- if(fd){
- int i =0;
- for(i;i<len;i+=2){
- fwrite(data + i,1,1,fd);
- fwrite(data + i + 1, 1,1,fd);
- }
- fclose(fd);
- fd = NULL;
- }
- else{
- LOG("write png data failed");
- }
- }
- unsigned long hook_dete_format(void* this,const unsigned char * data, ssize_t dataLen){
- unsigned long (*origin_dete_format)(void* this,const unsigned char * data, ssize_t dataLen);
- origin_dete_format = (void*)eph.orig;
- hook_precall(&eph);
- LOG("hook deteformat ==> start to write png data");
- write_png_data_to_file(data,dataLen);
- LOG("write ok");
- unsigned long r = origin_dete_format(this,data,dataLen);
- hook_postcall(&eph);
- return r;
- }
- void hook_init_with_image_file(int str){
- void (*origin)(int);
- LOG("%d",str);
- origin = (void*) name_eph.orig;
- hook_precall(&name_eph);
- LOG("hook init with file name");
- if(origin){
- origin(str);
- LOG("origin execute");
- }
- hook_postcall(&name_eph);
- LOG("origin hook_postcall");
- }
- void my_init(){
- LOG("===== hook start library load success ========");
- set_logfunction(my_log);
- hook(&eph,getpid(),"libcocos2dcpp","_ZN7cocos2d5Image12detectFormatEPKhl",
- hook_dete_format,
- hook_dete_format);
- hook(&name_eph,getpid(),"libcocos2dcpp","_ZN7cocos2d5Image17initWithImageFileERKSs",
- hook_init_with_image_file,
- hook_init_with_image_file);
- LOG(" ==== hook init end ===== ");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement