/* terminal.c */ #include typedef unsigned int uint; static char cmdbuf[64]; static char varbuf[64]; // for defining variables in external calls static char scrbuf[64]; // internal scratchbuffer //char *commands[12] = {"?","help","h","hexdump","w[w|l]","write","r[w|l]","read","p","portmap","c","u"}; static char termhelp[200] = "? - help\nh - hexdump\nq - quit\nw[w|l] - write [short|long]word\nr[w|l] - read[short|long]word\np - portmapper\nc arg1 arg2, ... - execute external command\n"; FILE *stdin,*stdout,*stderr; static unsigned long iargs[8]; static int ii; static const unsigned write_unaligned_longword_addrs[] = {0x1013b878, 0x1013d3b0}; #define write_unaligned_longword SYSCALL_CUSTOM(write_unaligned_longword_addrs,void, void *, unsigned long ) static const unsigned write_unaligned_word_addrs[] = {0x1013b860, 0x1013d398}; #define write_unaligned_word SYSCALL_CUSTOM(write_unaligned_word_addrs,void, void *, int ) static const unsigned strtoul_addrs[] = {0x102a73a4, 0x102a8ed4}; #define strtoul SYSCALL_CUSTOM(strtoul_addrs, unsigned long, const char *, char **, int,int) void sscanf(char *str){ // this will do, till I can find the real sscanf ? int indx = -1; int i = -1; do{ do{ ++indx; }while(strchr(str+indx, ' ') != str); // advance pointer to next nonwhitespace iargs[++i] = atoi(str+indx); }while(*(str+indx) != '\0'); } void docommand(char *cmd){ void *procptr; if (strncmp(cmdbuf,"?\x0a",2) == 0){ // help printf("%s",termhelp); return; } if (strncmp(cmdbuf,"rw ",3) == 0){ // read word printf("%04X\n",0xffff & read_unaligned_word((void*)strtoul(cmdbuf+3,NULL,16,0))); return; } if (strncmp(cmdbuf,"rl ",3) == 0){ // read longword printf("%08X\n",read_unaligned_longword((void*)strtoul(cmdbuf+3,NULL,16,0))); return; } if (strncmp(cmdbuf,"ww ",3) == 0){ // write word write_unaligned_word((void*)strtoul(cmdbuf+3,NULL,16,0),strtoul(cmdbuf+8,NULL,16,0)); printf("%08X\n",read_unaligned_longword((void*)strtoul(cmdbuf+3,NULL,16,0))); return; } if (strncmp(cmdbuf,"wl ",3) == 0){ // write longword write_unaligned_longword((void*)atoi(cmdbuf+3),(unsigned long)strtoul(cmdbuf+8,NULL,16,0)); printf("%08X\n",read_unaligned_longword((void*)strtoul(cmdbuf+3,NULL,16,0))); return; } if (strncmp(cmdbuf,"c ",2) == 0){ // execute external routine //sscanf(cmd); procptr = (void*)iargs[0]; //((void (*)(iargs[1],iargs[2],iargs[3],iargs[4]))(procptr));}; return; } if (strncmp(cmdbuf,"h ",2) == 0){ // hex-ascii dump procptr = (void*)(strtoul(cmd+1,NULL,16,0) & 0xfffffffc) ; // make it 4 byte aligned for(ii=0;ii<16;++ii){ if(isprint(*(char*)(procptr+ii))){ if(ii==0){ strncpy(scrbuf,(char*)(procptr+ii),1); }else{ strncat(scrbuf,(char*)(procptr+ii),1); } }else{ if(ii==0){ strcpy(scrbuf,"."); }else{ strncat(scrbuf,".",1); } } } printf("%08X: %08X %08X %08X %08X %s\n", (uint)procptr,*(uint*)procptr,*(uint*)procptr+4,*(uint*)procptr+8,*(uint*)procptr+12,scrbuf); return; } if (strcmp(cmdbuf,"q\x0a") == 0){ // quit printf("Exiting\n"); return; } printf("Unknown command\n"); } int main(void){ // required because stdout needs the interrupts currently disabled by Ndless unsigned intmask = TCT_Local_Control_Interrupts(0); if(read_unaligned_longword((void*)0x10000020) == 0x101a0c30){ // 1.3.2438NCAS stdin = (FILE *) 0x106c1620; stdout = (FILE *) 0x106c166c; stderr = (FILE *) 0x106c16b8; printf("NONCAS Model Detected\n"); } else if(read_unaligned_longword((void*)0x10000020) == 0x101a2760) { // 1.3.2437CAS stdin = (FILE *) 0x10685610; stdout = (FILE *) 0x1068565c; stderr = (FILE *) 0x106856a8; printf("CAS Model Detected\n"); } else { printf("Not compiled for this OS version\n"); TCT_Local_Control_Interrupts(intmask); return(1); } printf("Welcome to the Ti-Nspire RS232 Hacker Console\n"); printf("Press ? for help\n"); do{ printf("RS232> "); // terminal prompt fgets(cmdbuf,64,stdin); // get user input docommand(cmdbuf); }while(strcmp(cmdbuf,"q\x0a") != 0); // fgets takes carriage return as 0x0a TCT_Local_Control_Interrupts(intmask); return 0; }