root/platform/generic/main.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. core_hook_task_create
  2. core_hook_task_delete
  3. spytask
  4. task_start_hook
  5. remount_filesystem
  6. init_file_modules_hook
  7. capt_seq_hook
  8. physw_hook
  9. movie_record_hook
  10. my_ncmp
  11. createHook
  12. deleteHook
  13. startup
  14. hook_tyWriteOrig
  15. cam_console_init

   1 #include "camera.h"
   2 #include "lolevel.h"
   3 #include "platform.h"
   4 #include "core.h"
   5 #include "keyboard.h"
   6 #include "stdlib.h"
   7 
   8 /* Ours stuff */
   9 extern long link_bss_start;
  10 extern long link_bss_end;
  11 extern void boot();
  12 
  13 static void core_hook_task_create(void *tcb)
  14 {
  15 }
  16 
  17 static void core_hook_task_delete(void *tcb)
  18 {
  19     char *name = (char*)(*(long*)((char*)tcb+0x34));
  20     if (strcmp(name,"tInitFileM")==0) core_spytask_can_start();
  21 }
  22 
  23 
  24 static int stop_hooking;
  25 
  26 static void (*task_prev)(
  27     long p0,    long p1,    long p2,    long p3,    long p4,
  28     long p5,    long p6,    long p7,    long p8,    long p9);
  29 
  30 static void (*init_file_modules_prev)(
  31     long p0,    long p1,    long p2,    long p3,    long p4,
  32     long p5,    long p6,    long p7,    long p8,    long p9);
  33 
  34 
  35 
  36 void spytask(long ua, long ub, long uc, long ud, long ue, long uf)
  37 {
  38     core_spytask();
  39 }
  40 
  41 
  42 static void task_start_hook(
  43     long p0,    long p1,    long p2,    long p3,    long p4,
  44     long p5,    long p6,    long p7,    long p8,    long p9)
  45 {
  46     _CreateTask("SpyTask", 0x19, 0x2000, spytask, 0);
  47 
  48     task_prev(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 );
  49 }
  50 
  51 
  52 static void remount_filesystem()
  53 {
  54     _Unmount_FileSystem();
  55     _Mount_FileSystem();
  56 }
  57 
  58 
  59 static void init_file_modules_hook(
  60     long p0,    long p1,    long p2,    long p3,    long p4,
  61     long p5,    long p6,    long p7,    long p8,    long p9)
  62 {
  63     remount_filesystem();
  64     init_file_modules_prev(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 );
  65 }
  66 
  67 
  68 static void capt_seq_hook(
  69     long p0,    long p1,    long p2,    long p3,    long p4,
  70     long p5,    long p6,    long p7,    long p8,    long p9)
  71 {
  72     capt_seq_task();
  73 }
  74 
  75 
  76 static void physw_hook(
  77     long p0,    long p1,    long p2,    long p3,    long p4,
  78     long p5,    long p6,    long p7,    long p8,    long p9)
  79 {
  80     mykbd_task();
  81 }
  82 
  83 static void movie_record_hook(
  84     long p0,    long p1,    long p2,    long p3,    long p4,
  85     long p5,    long p6,    long p7,    long p8,    long p9)
  86 {
  87     movie_record_task();
  88 }
  89 
  90 
  91 
  92 static int my_ncmp(const char *s1, const char *s2, long len)
  93 {
  94     int i;
  95     for (i=0;i<len;i++){
  96     if (s1[i] != s2[i])
  97         return 1;
  98     }
  99     return 0;
 100 }
 101 
 102 void createHook (void *pNewTcb)
 103 {
 104     char *name = (char*)(*(long*)((char*)pNewTcb+0x34));
 105     long *entry = (long*)((char*)pNewTcb+0x74);
 106 
 107     // always hook first task creation
 108     // to create SpyProc
 109     if (!stop_hooking){
 110         task_prev = (void*)(*entry);
 111         *entry = (long)task_start_hook;
 112         stop_hooking = 1;
 113     } else {
 114         // hook/replace another tasks
 115         if (my_ncmp(name, "tPhySw", 6) == 0){
 116             *entry = (long)physw_hook;
 117         }
 118 
 119         if (my_ncmp(name, "tInitFileM", 10) == 0){
 120             init_file_modules_prev = (void*)(*entry);
 121 #if CAM_MULTIPART
 122             *entry = (long)init_file_modules_task;
 123 #else
 124             *entry = (long)init_file_modules_hook;
 125 #endif
 126         }
 127 
 128         if (my_ncmp(name, "tCaptSeqTa", 10) == 0){
 129             *entry = (long)capt_seq_hook;
 130         }
 131 
 132 #if CAM_CHDK_HAS_EXT_VIDEO_MENU
 133         if (my_ncmp(name, "tMovieReco", 10) == 0){
 134             *entry = (long)movie_record_hook;
 135         }
 136 #endif
 137 
 138 #if CAM_EXT_TV_RANGE
 139         if (my_ncmp(name, "tExpDrvTas", 10) == 0){
 140             *entry = (long)exp_drv_task;
 141         }
 142 #endif
 143 
 144 #if CAM_HAS_FILEWRITETASK_HOOK
 145         if (my_ncmp(name, "tFileWrite", 10) == 0){
 146             *entry = (long)filewritetask;
 147         }
 148 #endif
 149 
 150 // for cameras that have a "touch control dial" with 'TouchW' task.
 151 // some cameras may use a different task name
 152 #ifdef HOOK_TOUCHW
 153         if (my_ncmp(name, "tTouchW", 7) == 0){
 154             *entry = (long)my_touchw_task;
 155         }
 156 #endif
 157 
 158         core_hook_task_create(pNewTcb);
 159     }
 160 }
 161 
 162 void deleteHook (void *pTcb)
 163 {
 164     core_hook_task_delete(pTcb);
 165 }
 166 
 167 void startup()
 168 {
 169     long *bss = &link_bss_start;
 170 
 171     // sanity check
 172     if ((long)&link_bss_end > (MEMISOSTART + MEMISOSIZE)){
 173         started();
 174         shutdown();
 175     }
 176 
 177     // initialize .bss senment
 178     while (bss<&link_bss_end)
 179         *bss++ = 0;
 180 
 181     // fill memory with this magic value so we could see what
 182     // parts of memory were or not used
 183 #if 0
 184     long *ptr;
 185     for (ptr=(void*)MEMBASEADDR;((long)ptr)<MEMISOSTART;ptr+=4){
 186     ptr[0]=0x55555555;
 187     ptr[1]=0x55555555;
 188     ptr[2]=0x55555555;
 189     ptr[3]=0x55555555;
 190     }
 191 #endif
 192 
 193     boot();
 194 }
 195 
 196 #if CAM_CONSOLE_LOG_ENABLED
 197 
 198 #define DEV_HDR_WRITE_OFFSET (0x14C/4)
 199 
 200 typedef int DEV_HDR;
 201 
 202 int (*_tyWriteOrig)(DEV_HDR *hdr, char *buf, int len);
 203 
 204 
 205 int hook_tyWriteOrig(DEV_HDR *hdr, char *buf, int len)
 206 {
 207     // Slow, but stable writes
 208     FILE *fd = fopen("A/stdout.txt", "a");
 209     if (fd) {
 210         fwrite(buf, 1, len, fd);
 211         fclose(fd);
 212     }
 213 
 214     return _tyWriteOrig(hdr, buf, len);
 215 
 216 }
 217 
 218 void cam_console_init()
 219 {
 220     DEV_HDR *DRV_struct;
 221 
 222     extern DEV_HDR* _iosDevFind(char*, int);
 223     DRV_struct = _iosDevFind("/tyCo/0", 0);
 224 
 225     _tyWriteOrig = (void*)DRV_struct[DEV_HDR_WRITE_OFFSET];
 226 
 227     FILE *fd = fopen("A/chdklog.txt", "a");
 228     if (fd) {
 229         // can't be used with "Fut" API
 230         //fprintf(fd, "DRV_struct: %x, _tyWriteOrig: %x\n", DRV_struct, _tyWriteOrig);
 231         char buf[256];
 232         int buflen = sprintf(buf, "DRV_struct: %x, _tyWriteOrig: %x\n", DRV_struct, _tyWriteOrig);
 233         fwrite(buf, 1, buflen, fd);
 234     }
 235 
 236     FILE *fdout = fopen("A/stdout.txt", "r");
 237     if (fdout)
 238     {
 239         DRV_struct[DEV_HDR_WRITE_OFFSET] = (int)hook_tyWriteOrig;
 240         fclose(fdout);
 241         // fprintf(fd, "tyWrite replaced, camera log enabled\n");
 242         fwrite("tyWrite replaced, camera log enabled\n", 1, sizeof("tyWrite replaced, camera log enabled\n"), fd);
 243     }
 244 
 245     if (fd)
 246     {
 247         fclose(fd);
 248     }
 249 
 250 }
 251 
 252 #endif

/* [<][>][^][v][top][bottom][index][help] */