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

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