tid_t create_vtbl_struct(ea_t vtbl_addr, ea_t vtbl_addr_end, char* vtbl_name, uval_t idx, unsigned int* vtbl_len)
{
	qstring struc_name = vtbl_name;
	tid_t id = add_struc(BADADDR, struc_name.c_str());
	if (id == BADADDR)
	{
		struc_name.clear();
		struc_name = askstr(HIST_IDENT, NULL, "Default name %s not correct. Enter other structure name: ", struc_name.c_str());
		id = add_struc(BADADDR, struc_name.c_str());
		set_struc_cmt(id, vtbl_name, true);
	}

	struc_t* new_struc = get_struc(id);
	if (!new_struc)
		return BADNODE;

	ea_t ea = vtbl_addr;
	int offset = 0;
	while (ea < vtbl_addr_end)
	{
		offset = ea - vtbl_addr;
		qstring method_name;
		ea_t method_ea = get_long(ea);

		if (method_ea == 0) break;
		if (!isEnabled(method_ea)) break;

		flags_t method_flags = getFlags(method_ea);
		char* struc_member_name = NULL;
		if (isFunc(method_flags))
		{
			method_name = get_short_name(method_ea);
			if (method_name.length() != 0)
				struc_member_name = (char*)method_name.c_str();
		}

		add_struc_member(new_struc, NULL, offset, dwrdflag(), NULL, 4);
		if (struc_member_name)
		{
			if (!set_member_name(new_struc, offset, struc_member_name))
			{
				//get_name(NULL, method_ea, method_name, sizeof(method_name));
				get_ea_name(&method_name, method_ea);
				set_member_name(new_struc, offset, struc_member_name);
			}
		}

		ea = ea + 4;
		flags_t ea_flags = getFlags(ea);
		if (has_any_name(ea_flags)) break;
	}

	return id;
}
tid_t create_vtbl_struct(ea_t vtbl_addr, ea_t vtbl_addr_end, char* vtbl_name, uval_t idx, unsigned int* vtbl_len)
{


	qstring struc_name = vtbl_name;
	//struc_name.append(qstring("_vtbl_struct"));
	tid_t id = add_struc(BADADDR, struc_name.c_str());
	if (id == BADADDR)
	{
		struc_name.clear();
		struc_name = askstr(HIST_IDENT, NULL, "Default name %s not correct. Enter other structure name: ", struc_name.c_str());
		id = add_struc(BADADDR, struc_name.c_str());
		set_struc_cmt(id, vtbl_name, true);
	}

	struc_t* new_struc = get_struc(id);
	if (!new_struc)
		return BADNODE;

	ea_t ea = vtbl_addr;
	
	ea_t offset = 0;
	
	while (ea < vtbl_addr_end)
	{
		offset = ea - vtbl_addr;
		qstring method_name;
#ifndef __EA64__
		ea_t method_ea = get_long(ea); // get function ea
#else
		ea_t method_ea = get_64bit(ea);
#endif


		if (method_ea == 0) break;
		if (!isEnabled(method_ea)) break;

		flags_t method_flags = getFlags(method_ea);
		char* struc_member_name = NULL;
		if (isFunc(method_flags))
		{
			method_name = f_get_short_name(method_ea);
			// this line crash ida when compare qstring with null
			if (method_name.length() != 0) {
				struc_member_name = (char*)method_name.c_str();
			}

		}
#ifndef __EA64__
		add_struc_member(new_struc, NULL, offset, dwrdflag(), NULL, 4);
#else
		add_struc_member(new_struc, NULL, offset, qwrdflag(), NULL, sizeof(UINT64));
#endif

		if (struc_member_name)
		{
			if (!set_member_name(new_struc, offset, struc_member_name))
			{
				//get_name(NULL, method_ea, method_name, sizeof(method_name));
				f_get_ea_name(&method_name, method_ea);
				set_member_name(new_struc, offset, struc_member_name);
			}
		}
#ifndef __EA64__
		ea = ea + 4;
#else
		ea = ea + sizeof(UINT64);
#endif

		flags_t ea_flags = getFlags(ea);
		if (has_any_name(ea_flags)) break;
	}

	return id;
}
示例#3
0
文件: emu.cpp 项目: nealey/vera
// Emulate an operand.
static void handle_operand(op_t &op, bool write) {
    switch ( op.type ) {
        // Code address
        case o_near:
            {
                cref_t mode;
                ea_t ea = toEA(cmd.cs, op.addr);

                // call or jump ?
                if ( cmd.itype == st9_call || cmd.itype == st9_calls )
                {
                  if ( !func_does_return(ea) )
                    flow = false;
                  mode = fl_CN;
                }
                else
                {
                  mode = fl_JN;
                }
                ua_add_cref(op.offb, ea, mode);
            }
            break;

        // Memory address
        case o_mem:
            {
                enum dref_t mode;

                mode = write ? dr_W: dr_R;

                ua_add_dref(op.offb, toEA(cmd.cs, op.addr), mode);
                ua_dodata2(op.offb, op.addr, op.dtyp);
            }
            break;

        // Immediate value
        case o_imm:
            doImmd(cmd.ea);
            // create a comment if this immediate is represented in the .cfg file
            {
                const ioport_t * port = find_sym(op.value);

                if ( port != NULL && !has_cmt(uFlag) ) {
                    set_cmt(cmd.ea, port->cmt, false);
                }
            }
            // if the value was converted to an offset, then create a data xref:
            if ( isOff(uFlag, op.n) )
              ua_add_off_drefs2(op, dr_O, 0);
            break;

        // Displacement
        case o_displ:
            doImmd(cmd.ea);
            if ( isOff(uFlag, op.n) ) {
                ua_add_off_drefs2(op, dr_O, OOF_ADDR);
                ua_dodata2(op.offb, op.addr, op.dtyp);
            }

            // create stack variables if required
            if ( may_create_stkvars() && !isDefArg(uFlag, op.n) ) {
                func_t *pfn = get_func(cmd.ea);
                if ( pfn != NULL && pfn->flags & FUNC_FRAME ) {
                    if ( ua_stkvar2(op, op.addr, STKVAR_VALID_SIZE) ) {
                        op_stkvar(cmd.ea, op.n);
                        if ( cmd.Op2.type == o_reg ) {
                            regvar_t *r = find_regvar(pfn, cmd.ea, ph.regNames[cmd.Op2.reg]);
                            if ( r != NULL ) {
                                struc_t *s = get_frame(pfn);
                                member_t *m = get_stkvar(op, op.addr, NULL);
                                char b[20];
                                qsnprintf(b, sizeof b, "%scopy", r->user);
                                set_member_name(s, m->soff, b);
                            }
                        }
                    }
                }
            }
            break;

        // Register - Phrase - Void: do nothing
        case o_reg:
        case o_phrase:
        case o_void:
            break;

        default:
            IDA_ERROR("Invalid op.type in handle_operand()");
    }
}