Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. #define _GNU_SOURCE
  2. #include <stdio.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6. #include <dlfcn.h>
  7. #include <sys/socket.h>
  8. #include <netinet/in.h>
  9. #include <sys/select.h>
  10. #include <string.h>
  11. #include <termios.h>
  12. #include <pthread.h>
  13. #include <sys/epoll.h>
  14.  
  15. #include <jni.h>
  16. #include <stdlib.h>
  17. #include <android/log.h>
  18. #include "../../base/hook.h"
  19. #include "../../base/base.h"
  20. #include "log.h"
  21.  
  22.  
  23. void __attribute__ ((constructor)) my_init(void);
  24.  
  25. static struct hook_t eph;
  26. static struct hook_t name_eph;
  27.  
  28. static void my_log(char* msg){
  29. LOG("%s",msg);
  30. }
  31.  
  32.  
  33. void write_png_data_to_file(const char* data,size_t len){
  34. LOG("data file length:%d",len);
  35. char buffer[40] = {0};
  36. char buffer2[200] = {0};
  37.  
  38. char* uuid_path = "/proc/sys/kernel/random/uuid";
  39. FILE* f_uuid = fopen(uuid_path,"r");
  40. if(f_uuid){
  41. fread(buffer,1,36,f_uuid);
  42. fclose(f_uuid);
  43. LOG("get uuid ok");
  44. }
  45. else{
  46. LOG("read uuid failed");
  47. }
  48.  
  49. char* filename = "/mnt/sdcard/game_dump/%s.png";
  50. sprintf(buffer2,filename,buffer);
  51.  
  52. LOG("filename:%s",buffer2);
  53.  
  54. FILE* fd = fopen(buffer2,"wb");
  55. if(fd){
  56. int i =0;
  57. for(i;i<len;i+=2){
  58. fwrite(data + i,1,1,fd);
  59. fwrite(data + i + 1, 1,1,fd);
  60. }
  61. fclose(fd);
  62. fd = NULL;
  63. }
  64. else{
  65. LOG("write png data failed");
  66. }
  67. }
  68.  
  69. unsigned long hook_dete_format(void* this,const unsigned char * data, ssize_t dataLen){
  70.  
  71. unsigned long (*origin_dete_format)(void* this,const unsigned char * data, ssize_t dataLen);
  72.  
  73. origin_dete_format = (void*)eph.orig;
  74.  
  75. hook_precall(&eph);
  76.  
  77. LOG("hook deteformat ==> start to write png data");
  78.  
  79. write_png_data_to_file(data,dataLen);
  80.  
  81. LOG("write ok");
  82.  
  83. unsigned long r = origin_dete_format(this,data,dataLen);
  84.  
  85. hook_postcall(&eph);
  86.  
  87. return r;
  88. }
  89.  
  90.  
  91. void hook_init_with_image_file(int str){
  92. void (*origin)(int);
  93.  
  94. LOG("%d",str);
  95.  
  96. origin = (void*) name_eph.orig;
  97.  
  98. hook_precall(&name_eph);
  99.  
  100. LOG("hook init with file name");
  101.  
  102. if(origin){
  103. origin(str);
  104. LOG("origin execute");
  105. }
  106.  
  107. hook_postcall(&name_eph);
  108.  
  109. LOG("origin hook_postcall");
  110.  
  111. }
  112.  
  113.  
  114. void my_init(){
  115.  
  116. LOG("===== hook start library load success ========");
  117. set_logfunction(my_log);
  118.  
  119. hook(&eph,getpid(),"libcocos2dcpp","_ZN7cocos2d5Image12detectFormatEPKhl",
  120. hook_dete_format,
  121. hook_dete_format);
  122.  
  123. hook(&name_eph,getpid(),"libcocos2dcpp","_ZN7cocos2d5Image17initWithImageFileERKSs",
  124. hook_init_with_image_file,
  125. hook_init_with_image_file);
  126.  
  127. LOG(" ==== hook init end ===== ");
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement