//-------------------------------------------------------------------------- static void load_symbols(const char *file) { free_syms(); if ( file == NULL ) return; char cfgpath[QMAXPATH]; const char *rfile = getsysfile(cfgpath, sizeof(cfgpath), file, CFG_SUBDIR); if ( rfile == NULL ) { NOFILE: // warning("Can't open %s, symbol definitions are not loaded", file); return; } FILE *fp = fopenRT(rfile); if ( fp == NULL ) goto NOFILE; int ln = 0; char line[MAXSTR]; while ( qfgets(line, sizeof(line), fp) ) { ln++; line[strlen(line)-1] = '\0'; trim(line); if ( line[0] == ';' || line[0] == ' ' || line[0] == '\0' ) continue; char word[MAXSTR]; int addr; if ( sscanf(line, "%s %i", word, &addr) != 2 ) { warning("%s: syntax error at line %d", file, ln); break; } int i; for ( i=0; i < numsyms; i++) { if ( syms[i].address == addr && strcmp(syms[i].name, word) != 0 ) { warning("%s: duplicate address %#x at line %d", file, addr, ln); break; } } if ( i != numsyms ) break; syms = qrealloc_array<sym_t>(syms, numsyms + 1); if ( syms == NULL ) nomem("h8/500 symbols"); syms[numsyms].address = addr; syms[numsyms].name = qstrdup(word); numsyms++; } qfclose(fp); }
//------------------------------------------------------------------ static bool apply_config_file(int _respect_info) { if ( strcmp(device, NONEPROC) == 0 ) // processor not selected return true; char cfgfile[QMAXFILE]; char cfgpath[QMAXPATH]; get_cfg_filename(cfgfile, sizeof(cfgfile)); if ( getsysfile(cfgpath, sizeof(cfgpath), cfgfile, CFG_SUBDIR) == NULL ) { #ifndef SILENT warning("ICON ERROR\n" "Can not open %s, I/O port definitions are not loaded", cfgfile); #endif return false; } deviceparams[0] = '\0'; if ( !CHECK_IORESP ) _respect_info = 0; respect_info = _respect_info; free_ioports(ports, numports); ports = read_ioports(&numports, cfgpath, device, sizeof(device), callback); if ( respect_info & IORESP_PORT ) { for ( int i=0; i < numports; i++ ) { ioport_t *p = ports + i; #ifdef I8051 segment_t *s = get_segm_by_name("FSR"); if ( s != NULL ) { set_name(p->address + s->startEA - 0x80, p->name); set_cmt(p->address + s->startEA - 0x80, p->cmt, true); } #else set_name(p->address, p->name); set_cmt(p->address, p->cmt, true); #endif } } return true; }
//-------------------------------------------------------------------------- // check and send to the remote server the specified stub // do it only if its crc does not match the specified crc // this function runs on the local machine with ida interface static uchar *sync_stub(const char *fname, uint32 crc, size_t *psize) { char path[QMAXPATH]; bool told = false; if ( getsysfile(path, sizeof(path), fname, NULL) != NULL ) { linput_t *li = open_linput(path, false); if ( li != NULL ) { int32 size = qlsize(li); if ( size > 0 ) { uchar *buf = qnewarray(uchar, size); if ( buf != NULL ) { if ( qlread(li, buf, size) == size ) { if ( calc_crc32(0, buf, size) != crc ) { close_linput(li); *psize = size; return buf; } else { msg("Kernel debugger stub is up to date...\n"); told = true; *psize = 1; // signal ok } } qfree(buf); } } close_linput(li); } } if ( !told ) warning("AUTOHIDE NONE\nCould not find/read debugger stub %s", fname); return NULL; }
/* Dumb algorithm of filename searching: * 1) get filename of currently disassembled filename * 2) chomp ext * 3) add our ext and try to open * 4) if failed - get name and add our exe * 5) and apply standard IDA file search mechanism (over getsysfile) * That`s all folks */ char * RP_mapping::find_path(const char *my_ext) { int my_ext_len = 0; /* lets in beginning cut all initial dots from proposed extentsion */ if ( my_ext != NULL ) { while ( *my_ext && *my_ext == '.' ) my_ext++; if ( *my_ext ) my_ext_len = strlen(my_ext); } /* try to find filename of current database */ char own_name[_MAX_PATH]; get_input_file_path(own_name, sizeof(own_name)); if ( NULL == own_name ) { return NULL; } /* main processing */ char *path = NULL, *file = NULL, *ext = NULL; qsplitpath(own_name, &path, &file); if ( file == NULL ) return NULL; char *filebase = NULL; qsplitfile(file, NULL, &ext); if ( ext != NULL ) { int base_len = ext - file; filebase = (char *)qalloc(base_len); strncpy(filebase, file, base_len - 1); filebase[base_len - 1] = 0x0; } else filebase = qstrdup(file); int filebase_len = strlen(filebase); /* O`k lets try p 1) */ if ( NULL != path ) { int need_len; int base_len = file - own_name; need_len = base_len + 3 + filebase_len + my_ext_len; char *res = (char *)qalloc(need_len); strncpy(res, path, base_len); res[base_len - 1] = '\\'; strcpy(res + base_len, filebase); if ( my_ext != NULL ) { strcat(res, "."); strcat(res, my_ext); } struct stat st; #ifdef RP_DEBUG msg("Try %s\n", res); #endif if ( -1 != stat(res, &st) ) { #ifdef RP_DEBUG msg("Find %s (time %X)\n", res, st.st_mtime ); #endif qfree(filebase); return res; } qfree(res); } /* next part do same thing as qmakefile missed by Ilfak */ char *st_buf = filebase; if ( my_ext_len ) { st_buf = (char *)qalloc(2 + my_ext_len + filebase_len); strcpy(st_buf, filebase); st_buf[filebase_len] = '.'; strcpy(st_buf + filebase_len + 1, my_ext); } #ifdef RP_DEBUG msg("st_buf '%s', my_ext_len %d, filebase_len %d, my_ext %s\n", st_buf, my_ext_len, filebase_len, my_ext); #endif char *res = (char *)qalloc(_MAX_PATH + 1); char *ret_val = getsysfile(res, _MAX_PATH, st_buf, CFG_SUBDIR); if ( NULL == ret_val ) qfree(res); if ( st_buf != filebase ) qfree(st_buf); if ( filebase != NULL ) qfree(filebase); return ret_val; }