Esempio n. 1
0
//------------------------------------------------------------------------
// process import table for one dll
inline int pe_loader_t::process_import_table(
    linput_t *li,
    const peheader_t &pe,
    ea_t atable,
    ea_t ltable,
    pe_import_visitor_t &piv)
{
    bool is_pe_plus = pe.is_pe_plus();
    int elsize = piv.elsize = is_pe_plus ? 8 : 4;
    const uint64 mask = is_pe_plus ? IMP_BY_ORD64 : IMP_BY_ORD32;
    bool ok = true;
    int i;
    for ( i=0; ok; i++, atable += elsize )
    {
        char buf[MAXSTR];
        ea_t rva = ltable + i * elsize;
        if ( piv.withbase )
            rva -= (uval_t)pe.imagebase();
        uint32 fof = uint32(rva);
        uint64 entry = is_pe_plus ? vaint64(li, fof, &ok) : valong(li, fof, &ok);
        if ( entry == 0 )
            break;
        showAddr(atable);

        int code;
        if( (entry & mask) == 0 )   // by name
        {
            ea_t nrva = (uval_t)entry + sizeof(short);
            if ( piv.withbase )
                nrva -= (uval_t)pe.imagebase();
            uint32 fof = uint32(nrva);
            asciiz(li, fof, buf, sizeof(buf), &ok);
            if ( !win_utf2idb(buf) )
                ansi2idb(buf);
            code = piv.visit_import(atable, entry, buf);
        }
        else
        {
            code = piv.visit_import(atable, entry & ~mask, NULL);
        }
        if ( code != 0 )
            return code;
    }
    return piv.leave_module(i);
}
Esempio n. 2
0
void super_event(rcs_Event event) {
        if (event.type == EVENT_BUTTON_RELEASE) {
          pressed='N'; 
          if (inPressed=='Y') {
            inPressed='N';
            }
          }
        if (event.type == EVENT_BUTTON_PRESS && pressed=='N') {
          if (event.d1==3) printf("%d %d\n",event.d2,event.d3);
    /* power switch */
          else if (event.d2>=462 && event.d2<=482 &&
              event.d3>=44 && event.d3<=61) {
            toggleSetState(&power,(toggleGetState(&power))?0:1);
            togglePaint(&power,display,window);
            control = OFF;
            }
    /* Load Button */
          else if (event.d2>=435 && event.d2<=462 &&
              event.d3>=234 && event.d3<=259) {
            if (cpu.mode != 'L') showAddr(0); 
            lastMode2 = cpu.mode;
            cdp1802SetClear(&cpu,0);
            cdp1802SetWait(&cpu,0);
            if (lastMode2 == 'R' && cpu.mode != 'R') showClock();
            }
    /* Reset Button */
          else if (event.d2>=435 && event.d2<=462 &&
              event.d3>=265 && event.d3<=291) {
            lastMode2 = cpu.mode;
            cdp1802SetClear(&cpu,0);
            cdp1802SetWait(&cpu,1);
            if (cpu.mode == 'I') showAddr(0);
            if (lastMode2 == 'R' && cpu.mode != 'R') showClock();
            singleStep = 0;
            toggleSetState(&mp,0);
            monitor = 'N';
            state = 'F';
            vt100Reset();
            }
    /* Go Button */
          else if (event.d2>=435 && event.d2<=462 &&
              event.d3>=298 && event.d3<=324) {
            cdp1802SetClear(&cpu,1);
            cdp1802SetWait(&cpu,1);
            }
    /* Pause Button */
          else if (event.d2>=435 && event.d2<=462 &&
              event.d3>=329 && event.d3<=355) {
            cdp1802SetClear(&cpu,1);
            cdp1802SetWait(&cpu,0);
            toggleSetState(&mp,0);
            singleStep = 0;
            }
    /* Single Step Button */
          else if (event.d2>=467 && event.d2<=492 &&
              event.d3>=267 && event.d3<=290) {
/*
            cdp1802SetClear(&cpu,1);
            cdp1802SetWait(&cpu,1);
*/
            singleStep = 1;
            }
    /* Monitor Button */
          else if (event.d2>=467 && event.d2<=492 &&
              event.d3>=234 && event.d3<=259) {
            if (superBoard == 'Y') {
              cdp1802SetClear(&cpu,1);
              cdp1802SetWait(&cpu,1);
              cpu.r[0] = 0x8000;
              } else monitor = 'Y';
            }
    /* 0 Button */
          else if (event.d2>=306 && event.d2<=333 &&
              event.d3>=233 && event.d3<=259) {
            switches = ((switches << 4) & 0xf0) | 0;
            }
    /* 1 Button */
          else if (event.d2>=338 && event.d2<=363 &&
              event.d3>=233 && event.d3<=259) {
            switches = ((switches << 4) & 0xf0) | 1;
            }
    /* 2 Button */
          else if (event.d2>=370 && event.d2<=396 &&
              event.d3>=233 && event.d3<=259) {
            switches = ((switches << 4) & 0xf0) | 2;
            }
    /* 3 Button */
          else if (event.d2>=402 && event.d2<=428 &&
              event.d3>=233 && event.d3<=259) {
            switches = ((switches << 4) & 0xf0) | 3;
            }
    /* 4 Button */
          else if (event.d2>=306 && event.d2<=333 &&
              event.d3>=265 && event.d3<=291) {
            switches = ((switches << 4) & 0xf0) | 4;
            }
    /* 5 Button */
          else if (event.d2>=338 && event.d2<=363 &&
              event.d3>=265 && event.d3<=291) {
            switches = ((switches << 4) & 0xf0) | 5;
            }
    /* 6 Button */
          else if (event.d2>=370 && event.d2<=396 &&
              event.d3>=265 && event.d3<=291) {
            switches = ((switches << 4) & 0xf0) | 6;
            }
    /* 7 Button */
          else if (event.d2>=402 && event.d2<=428 &&
              event.d3>=265 && event.d3<=291) {
            switches = ((switches << 4) & 0xf0) | 7;
            }
    /* 8 Button */
          else if (event.d2>=306 && event.d2<=333 &&
              event.d3>=297 && event.d3<=324) {
            switches = ((switches << 4) & 0xf0) | 8;
            }
    /* 9 Button */
          else if (event.d2>=338 && event.d2<=363 &&
              event.d3>=297 && event.d3<=324) {
            switches = ((switches << 4) & 0xf0) | 9;
            }
    /* A Button */
          else if (event.d2>=370 && event.d2<=396 &&
              event.d3>=297 && event.d3<=324) {
            switches = ((switches << 4) & 0xf0) | 10;
            }
    /* B Button */
          else if (event.d2>=402 && event.d2<=428 &&
              event.d3>=297 && event.d3<=324) {
            switches = ((switches << 4) & 0xf0) | 11;
            }
    /* C Button */
          else if (event.d2>=306 && event.d2<=333 &&
              event.d3>=329 && event.d3<=355) {
            switches = ((switches << 4) & 0xf0) | 12;
            }
    /* D Button */
          else if (event.d2>=338 && event.d2<=363 &&
              event.d3>=329 && event.d3<=355) {
            switches = ((switches << 4) & 0xf0) | 13;
            }
    /* E Button */
          else if (event.d2>=370 && event.d2<=396 &&
              event.d3>=329 && event.d3<=355) {
            switches = ((switches << 4) & 0xf0) | 14;
            }
    /* F Button */
          else if (event.d2>=402 && event.d2<=428 &&
              event.d3>=329 && event.d3<=355) {
            switches = ((switches << 4) & 0xf0) | 15;
            }
    /* P Button */
          else if (event.d2>=467 && event.d2<=493 &&
              event.d3>=297 && event.d3<=323) {
            toggleSetState(&mp,1);
            }
    /* in button */
          else if (event.d2>=467 && event.d2<=492 &&
              event.d3>=329 && event.d3<=355) {
            inPressed='Y';
            if (cpu.mode == 'L') {
              cdp1802DmaIn(&cpu,getData());
              showData(getData());
              } else {
              toggleSetState(&ef[3],0);
              }
            }
          }
  }
Esempio n. 3
0
//--------------------------------------------------------------------------
void idaapi load_file(linput_t *li, ushort neflag, const char * /*fileformatname*/)
{
  char line[BUFFSIZE], bigaddr = 0;
  ea_t addr, startEA = toEA(inf.baseaddr, 0), endEA = 0, seg_start = 0;
  char rstart = (inf.filetype == f_SREC) ? 'S' :
                                     ((inf.filetype == f_HEX) ? ':' : ';');
  register char *p;

  memset(&lc, 0, sizeof(local_data));
  inf.startIP = BADADDR;          // f_SREC without start record

  bool iscode = (neflag & NEF_CODE) != 0;
  int nb = iscode ? ph.cnbits : ph.dnbits;      // number of bits in a byte
  int bs = (nb + 7) / 8;                        // number of bytes
  sel_t sel = setup_selector(startEA >> 4);
  bool segment_created = false;

  bool cvt_to_bytes = false;
  if ( ph.id == PLFM_PIC )
  {
    // pic12xx and pic16xx use 12-bit and 14-bit words in program memory
    // pic18xx uses 16-bit opcodes but byte addressing
    if ( strncmp(inf.procName, "PIC18", 5) != 0 )
    {
      static const char form[] =
//      "PIC HEX file addressing mode\n"
//      "\n"
      "There are two flavors of HEX files for PIC: with word addressing\n"
      "and with byte addressing. It is not possible to recognize the\n"
      "flavor automatically. Please specify what addressing mode should\n"
      "be used to load the input file. If you don't know, try both and\n"
      "choose the one which produces the more meaningful result\n";
      int code = askbuttons_c("~B~yte addressing",
                              "~W~ord addressing",
                              "~C~ancel", 1, form);
      switch ( code )
      {
        case 1:
          break;
        case 0:
          cvt_to_bytes = true;
          break;
        default:
          loader_failure(NULL);
      }
    }
  }

  ea_t subs_addr = 0;
  for(lc.ln = 1; qlgets(p = line, BUFFSIZE, li); lc.ln++)
  {
    while ( *p == ' ' ) ++p;
    if ( *p == '\n' || *p == '\r' ) continue;
    if ( *p++ != rstart) errfmt( );

    int sz = 2;
    int mode = (inf.filetype == f_SREC) ? (uchar)*p++ : 0x100;
    lc.ptr = p;
    hexdata(0);
    if ( mode == 0x100 )
    {
      if ( !lc.len ) break;
      lc.len += 2;
      if ( inf.filetype == f_HEX )
        ++lc.len;
    }
    else
    {
      switch ( mode )
      {
        default:
            errfmt();

        case '0':
        case '5':
          continue;

        case '3':
        case '7':
          ++sz;
        case '2':
        case '8':
          ++sz;
        case '1':
        case '9':
          if ( mode > '3' ) mode = 0;
          --lc.len;
          break;
      }
    }
    addr = hexdata(sz) / bs;
    if ( !mode )
    {
      inf.startIP = addr;
      continue;
    }

    if ( inf.filetype == f_HEX )
    {
      int type = hexdata(1);      // record type
      switch ( type )
      {
        case 0xFF:                // mitsubishi hex format
        case 4:                   // Extended linear address record
          subs_addr = hexdata(2) << 16;
          break;
        case 2:                   // Extended segment address record
          subs_addr = hexdata(2) << 4;
          break;
      }
      if ( type != 0 )
      {
        if ( type == 1 )
          break;                  // end of file record
        continue;                 // not a data record
      }
    }
    addr += subs_addr / bs;
    if ( lc.len )
    {
      ea_t top = addr + lc.len / bs;
      p = line;
      while ( lc.len )
      {
        *p++ = (uchar)hexdata(1);
        if ( cvt_to_bytes ) // pic
          *p++ = '\0';
      }
      if ( top >= 0x10000l ) bigaddr = 1;
      addr += startEA;
      showAddr(addr);
      if ( (top += startEA) > endEA || !segment_created )
      {
        endEA = top;
        if ( neflag & NEF_SEGS )
        {
          if ( !segment_created )
          {
            if ( !add_segm(sel, addr, endEA, NULL, iscode ? CLASS_CODE : CLASS_DATA)) loader_failure(NULL );
            segment_created = true;
            seg_start = addr;
          }
          else
            set_segm_end(get_first_seg()->startEA, endEA, SEGMOD_KILL);
        }
      }
      if ( seg_start > addr )
      {
        set_segm_start(get_first_seg()->startEA, addr, SEGMOD_KILL);
        seg_start = addr;
      }
      mem2base(line, addr, top, -1);
    }
    {
      ushort chi;       // checksum
      ++lc.len;
      switch ( inf.filetype ) {
        case f_SREC:
          chi = (uchar)(~lc.sum);
          chi ^= (uchar)hexdata(1);
          break;
        case f_HEX:
          hexdata(1);
          chi = (uchar)lc.sum;
          break;
        default:  //MEX
          ++lc.len;
          chi = lc.sum;
          chi -= (ushort)hexdata(2);
          break;
      }
      if ( chi ) {
        static char first = 0;
        if ( !first ) {
          ++first;
          warning("Bad hex input file checksum, line %u. Ignore?", lc.ln);
        }
      }
    }
  }

  if ( (neflag & NEF_SEGS) != 0 )
  {
    if ( bigaddr )
    {
      set_segm_addressing(get_first_seg(), 1);
      if ( ph.id == PLFM_386 )
        inf.lflags |= LFLG_PC_FLAT;
    }
    set_default_dataseg(sel);
    inf.start_cs  = sel;
  }
  else
  {
    enable_flags(startEA, endEA, STT_CUR);
  }
  inf.af &= ~AF_FINAL;                    // behave as a binary file

  create_filename_cmt();
}