static int GetTypeOf(ea_t ea)
{
	flags_t flags = getFlags(ea);

	if (isTail(flags)) {
		// check if it's a struct ptr
		ea_t head = get_item_head(ea);
		if (head == ea) return T_UNK;
		flags = getFlags(head);
		if (!isData(flags) || !isStruct(flags)) return T_UNK;
		return GetTypeOfStructInstance(ea, head, flags);
	}

	if (!isData(flags)) return T_UNK;
	
	if (isStruct(flags)) return GetTypeOfStructInstance(ea, ea, flags);

	if (isByte(flags)) {
		char s;
		if (has_cmt(flags) && (get_cmt(ea, false, &s, 1) != -1) && s == 'S') return T_I8;
		return T_U8;
	}
	if (isWord(flags)) {
		char s;
		if (has_cmt(flags) && (get_cmt(ea, false, &s, 1) != -1) && s == 'S') return T_I16;
		return T_U16;
	}
	if (isDwrd(flags))  return T_I32;

	return T_UNK;
}
Esempio n. 2
0
void idaapi run(int arg)
{
    char buf[MAXSTR];
    char cmt[MAXSTR];
    char *valid_cmt = NULL;
    char ext[0x20];
    FILE *f = NULL;
    short checkboxes = OPTION_NAMES | OPTION_COMMENTS;
    sval_t bank = 1; // default
    bool first = true;
    bool hasName = false;
    flags_t flags;
    ea_t ea = 0x0;


    if( AskUsingForm_c( madnes_options, &checkboxes, &bank ) != 1 || checkboxes == 0 )
        return;

    // prepare filename for namelist (.nl) file
    get_input_file_path( buf, sizeof( buf ) );
    qsnprintf( ext, sizeof( ext ),".%X.nl",--bank );
    qstrncat( buf, ext, sizeof( buf )-strlen( buf ) );

    // (always) create file
    f = qfopen( buf, "w" );
    if( f == NULL )
    {
        warning( "%s could not be created!", buf );
        return;
    }

    msg( "Writing to file %s..", buf );

    while( ea <= 0xFFFF )
    {
        hasName = false;

        // get flags
        if( isCode( getFlags( ea ) ) )
            flags = getFlags( ea );
        else
            flags = getFlags( get_item_head( ea ) );

        // if user either chose to export names or anynames
        if( ( ( checkboxes & OPTION_NAMES ) && has_name( flags ) ) || ( ( checkboxes & OPTION_ANYNAME ) && has_any_name( flags ) ) )
        {
            // if current item is code or if current item is head of item
            if( isCode( flags ) || ea==get_item_head( ea ) )
            {
                // get name
                get_name( ea, ea, buf, sizeof( buf ) );
                // write to file
                qfprintf( f, "$%04X#%s#", ea, buf );
            }
            else // if not code or not head of item (must be an array)
            {
                // get name of item start
                get_name( get_item_head( ea ), get_item_head( ea ), buf, sizeof( buf ) );
                // calc displacement, write to file (example: "password+$04")
                qfprintf( f, "$%04X#%s+$%X#", ea, buf, ea-get_item_head( ea ) );
            }
            hasName = true;
        }

        // if user chose to export cross references
        if( checkboxes & OPTION_XREFS )
        {
            xrefblk_t xb;

            first = true;
            // cycle through all xrefs except ordinary flow xrefs
            for ( bool ok=xb.first_to( ea, XREF_FAR/*XREF_ALL*/); ok; ok=xb.next_to() )
            {
                if( first ) // if first xref
                {
                    if( !hasName ) // if this location hasn't a name yet, add symbol stub
                    {
                        qfprintf( f, "$%04X##", ea );
                        hasName = true;
                    }
                    qfprintf( f, "XREFS:\n\\"); // append XREFS
                    first = false;
                }
                qfprintf( f, "  $%04X\n\\", xb.from );
            }
        }

        // if user chose to export comments
        if( checkboxes & OPTION_COMMENTS )
        {
            if( has_cmt( flags ) ) // if current item has comment
            {
                // get comment
                // workaround for get_any_indeted_cmt()
                // -> unresolved external symbol "char * __stdcall get_any_indented_cmt(unsigned long,unsigned char *)" (?get_any_indented_cmt@@YGPADKPAE@Z)
                if( get_cmt( ea, false, cmt, sizeof( cmt ) ) == -1 )
                    get_cmt( ea, true, cmt, sizeof( cmt ) );

                // validate comment (replace invalid chars, add room for additional chars)
                valid_cmt = validate_comment( cmt );

                if( valid_cmt != NULL )
                {
                    if( !hasName )
                    {
                        qfprintf( f, "$%04X##", ea ); // add symbol stub if no name yet
                        hasName = true;
                    }
                    qfprintf( f, "%s", valid_cmt ); // write comment to file
                    qfree( valid_cmt );
                }
            }
        }

        if( hasName) qfprintf( f, "\n" );
        ea++; // get name of each byte
    }
    qfclose( f );
    msg( "done.\n" );
}
Esempio n. 3
0
File: emu.cpp Progetto: nealey/vera
//------------------------------------------------------------------------
static void TouchArg(op_t &x,int isAlt,int isload) {
  ea_t jmpa;
  switch ( x.type ) {
  case o_near:       // Jcc/ [jmp/call 37/67]
  case o_mem:        // 37/67/77
  case o_far:
      jmpa = toEA(x.type == o_far ? x.segval : codeSeg(x.addr16,x.n), x.addr16);
      if ( x.phrase == 0) { ua_add_cref(x.offb,jmpa,fl_JN ); break; } //Jcc
extxref:
      if ( (x.phrase & 070) == 070 ) goto xrefset;
      if ( cmd.itype == pdp_jmp) ua_add_cref(x.offb,jmpa,fl_JF );
      else if ( cmd.itype == pdp_jsr || cmd.itype == pdp_call ) {
             ua_add_cref(x.offb,jmpa,fl_CF);
             if ( !func_does_return(jmpa) )
               flow = false;
           } else {
xrefset:
             ua_dodata2(x.offb, jmpa, x.dtyp);
             ua_add_dref(x.offb, jmpa, isload ? dr_R : dr_W);
           }
      break;
  case o_displ:     // 6x/7x (!67/!77)
      doImmdValue();
      if ( !isload && x.phrase == (060 + rR0) && x.addr16 <= 1 )
                                                  loadR0data(&x, x.addr16);
      if ( !isAlt && isOff(emuFlg,x.n ) &&
         (jmpa = get_offbase(cmd.ea, x.n)) != BADADDR) {
        jmpa += x.addr16;
        goto extxref;
      }
      break;
  case o_imm:        // 27
      if ( !x.ill_imm )
      {
         doImmdValue();
         if ( op_adds_xrefs(uFlag, x.n) )
           ua_add_off_drefs2(x, dr_O, OOF_SIGNED);
      }
      break;
  case o_number:      // EMT/TRAP/MARK/SPL
      if ( cmd.itype == pdp_emt && get_cmt(cmd.ea, false, NULL, 0) <= 0 ) {
         if ( x.value >= 0374 && x.value <= 0375 ) {
           cmd.Op2.value = (x.value == 0375) ? emuR0data.b[1] : (emuR0 >> 8);
           cmd.Op2.type = o_imm;
         }
         char buf[MAXSTR];
         if ( get_predef_insn_cmt(cmd, buf, sizeof(buf)) > 0 )
           set_cmt(cmd.ea, buf, false);
        cmd.Op2.type = o_void;
      }
      break;
  case o_reg:        // 0
      if ( x.reg == rR0 ) {
        if ( cmd.Op2.type == o_void ) { // one operand cmd
          if ( cmd.itype != pdp_clr ) {
            goto undefall;
          } else {
            if ( cmd.bytecmd ) emuR0 &= 0xFF00;
            else            emuR0 = 0;
            goto undefdata;
          }
        }
        if ( &x == &cmd.Op2 ) {
          if ( cmd.itype != pdp_mov ) {
            if ( cmd.bytecmd ) { emuR0 |= 0xFF; goto undefdata; }
            else            goto undefall;
          }
          if ( cmd.bytecmd ) goto undefall;
          if ( cmd.Op1.type == o_imm ) {
            if ( (emuR0 = (ushort)cmd.Op1.value) & 1 ) goto undefdata;
            emuR0data.w = get_word(toEA(cmd.cs, emuR0));
          } else {
undefall:
            emuR0 = 0xFFFF;
undefdata:
            emuR0data.w = 0xFFFF;
          }
        }
      }
      break;
  case o_phrase:     // 1x/2x/3x/4x/5x (!27/!37)
      if ( (x.phrase & 7) == rR0 )
      {
        if ( !isload && x.phrase == (010 + rR0)) loadR0data(&x, 0 );
        else if ( cmd.Op2.type == o_void || &x == &cmd.Op2 ) goto undefall;
      }
  case o_fpreg:      // FPP
    break;
  default:
    warning("%" FMT_EA "o (%s): bad optype %d", cmd.ip, cmd.get_canon_mnem(), x.type);
    break;
  }
Esempio n. 4
0
File: emu.cpp Progetto: nealey/vera
//----------------------------------------------------------------------
static void attach_bit_comment(ea_t addr, int bit)
{
  const ioport_bit_t *predef = find_bit(addr, bit);
  if ( predef != NULL && get_cmt(cmd.ea, false, NULL, 0) <= 0 )
    set_cmt(cmd.ea, predef->cmt, false);
}