⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ccodelist.cpp

📁 将exe等可执行文件转化成c程序的反编译程序,先到汇编再到c
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			p->call.esp_level = cur->esp_level;
			p->call.call_func = g_Cexe2c->GetFunc(pxcpu->op[0].nearptr.offset);
            p->call.p_callpara = NULL;
            p->call.p_callret = NULL;
			InstrAddTail(p);
		}
        else if (pxcpu->op[0].mode == OP_Address)
		{
			if (pxcpu->op[0].addr.base_reg_index == _NOREG_ &&
				pxcpu->op[0].addr.off_reg_index == _NOREG_)
			{
				ea_t address = pxcpu->op[0].addr.off_value;
				CApi* papi = g_ApiManage->get_api(address);	//find it
				if (papi)
				{
					PINSTR	p = new INSTR;  //new_INSTR
					p->type = i_CallApi;
					p->call.papi = papi;
					p->call.esp_level = cur->esp_level;
                    p->call.p_callpara = NULL;
                    p->call.p_callret = NULL;
					InstrAddTail(p);
				}
				else
					Code_general(0, i_Unknown);
			}
			else
				Code_general(0, i_Unknown);
		}
        else if (pxcpu->op[0].mode == OP_Register)
        {
            ea_t address = FindApiAddress_Reg(pxcpu->op[0].reg.reg_index, pxcpu, this->Q->m_asmlist);
            CApi* papi = g_ApiManage->get_api(address);	//find it
            if (papi)
            {
                PINSTR	p = new INSTR;  //new_INSTR
                p->type = i_CallApi;
                p->call.papi = papi;
                p->call.esp_level = cur->esp_level;
                p->call.p_callpara = NULL;
                p->call.p_callret = NULL;
                InstrAddTail(p);
            }
            else
                Code_general(0, i_Unknown);
        }
        else
            Code_general(0, i_Unknown);
		break;
	case C_RET:	Code_general(0, i_Return);	break;
	default:	Code_general(0, i_Unknown);	break;

	}
}

void	CCodeList_Maker::Code_Jxx(JxxType t)
{
	PINSTR p = new INSTR;   //new_INSTR
	p->type = i_Jump;
	p->jmp.jmp_type = t;
	p->jmp.jmpto_off = cur->xcpu.op[0].nearptr.offset;
	InstrAddTail(p);
}

PINSTR	CCodeList_Maker::Code_general(int type, HLType t)
{	//	只有type == enum_RR时,返回值才有用
    if (t == i_Unknown)
    {
        t=i_Unknown;
    }
	PINSTR	p = new INSTR;  //new_INSTR
	p->type = t;
	switch (type)
	{
	case enum_00:
		InstrAddTail(p);
		return p;
	case enum_RR:
		{
			TransVar(&p->var_r1, 0);	//	0 means	xcpu.op[0]
			TransVar(&p->var_r2, 1);	//	1 means	xcpu.op[1]
			VarRead(p->va_r1);
			VarRead(p->va_r2);
		}
		InstrAddTail(p);
		return p;
	case enum_WR:
		{
			TransVar(&p->var_w, 0);	//	0 means	xcpu.op[0]
			TransVar(&p->var_r1, 1);	//	1 means	xcpu.op[1]
			if (t == i_Lea)
			{
				p->type = i_Assign;
				if (p->var_r1.type != v_Tem)
				{	//	比如象 lea eax,[ebp]
					p->type = i_GetAddr;
				}
			}
			else
			{
				VarRead(p->va_r1);
				//VarWrite(&p->var_w);
				if (p->var_w.type == v_Tem)
				{
					WriteToAddress(p);
					return NULL;	//	因为这里没人会用这个返回值
				}
			}
		}
		InstrAddTail(p);
		return p;
	case enum_AR:
		{
			VAR v;
			TransVar(&v, 0);	//	0 means	xcpu.op[0]
			TransVar(&p->var_r2, 1);	//	1 means	xcpu.op[1]
			p->var_r1 = v;
			p->var_w = v;
			VarRead(p->va_r2);
			VarRead(p->va_r1);
			//VarWrite(&p->var_w);
			if (p->var_w.type == v_Tem)
			{
				WriteToAddress(p);
				return NULL;	//	因为这里没人会用这个返回值
			}
		}
		InstrAddTail(p);
		return p;
	default:
		alert("why here 325426");
		return NULL;
	}
	//return NULL;
}
void	CCodeList_Maker::TransVar(VAR* pvar,int no)
{
	TransVar_(pvar,no);
	if (pvar->type)
	{
		assert(pvar->opsize);
	}
}
void	CCodeList_Maker::TransVar_(VAR* pvar,int no)
//SuperC_func: 只在<CCodeList_Maker::TransVar>中使用
{
	OPERITEM* op = &this->cur->xcpu.op[no];
	switch (op->mode)
	{
	case OP_Register:
		pvar->type = v_Reg;
		pvar->opsize = op->opersize;
		pvar->reg = regindex_2_regoff(op->reg.reg_index);
		return;
	case OP_Immed:
		pvar->type = v_Immed;
		pvar->opsize = op->opersize;
		pvar->d = op->immed.immed_value;
		return;
	case OP_Address:
		if (op->addr.base_reg_index == _NOREG_
			&& op->addr.off_reg_index == _NOREG_)
		{
            if (op->addr.off_value == 0 && op->addr.seg_index == _FS_)
            {//判断 fs:[0]
                pvar->type = v_Volatile;    //现在只用于 fs:0
                pvar->opsize = op->opersize;
                pvar->temno = 222;  //只要是偶数就行
                return;
            }
			pvar->type = v_Global;
			pvar->opsize = op->opersize;
			pvar->off = op->addr.off_value;
			return;
		}
		if (op->addr.base_reg_index == _ESP_
			&& op->addr.off_reg_index == _NOREG_)
		{
			pvar->opsize = op->opersize;
			signed long l = this->cur->esp_level + (signed int)op->addr.off_value;
			if (l >= 0)
			{
				pvar->par_off = l;
				pvar->type = v_Par;
			}
			else
			{
				pvar->var_off = stack2varoff(l);
				pvar->type = v_Var;
			}
			return;
		}
		if (op->addr.base_reg_index == _EBP_
			&& this->m_EBP_base != Not_EBP_based
			&& op->addr.off_reg_index == _NOREG_)
		{
			pvar->opsize = op->opersize;
			signed long l = this->m_EBP_base + (signed int)op->addr.off_value;
			if (l >= 0)
			{
				pvar->par_off = l;
				pvar->type = v_Par;
			}
			else
			{
				pvar->var_off = stack2varoff(l);
				pvar->type = v_Var;
			}
			return;
		}
		//	now, really stuff
		{
			VAR v;
			new_temp(&v);

			PINSTR p = new INSTR;   //new_INSTR
			p->type = i_Address;
			
			p->var_w = v;

			set_address(op, p);

			InstrAddTail(p);

			*pvar = v;
		}
		return;
	default:
		//warn_msg(0,"op mode unknown");
		break;
	}
}


void	CCodeList_Maker::VarRead(VAR_ADDON& va)
{	//	这个函数的意思是,如果这是个v_Tem,则加一条 i_Readpointto
    VAR* pvar = va.pv;
    Pst_InstrAddOn &pAddOn = va.pao;
	if (pvar->type != v_Tem)
		return;

    Pst_InstrAddOn pnew = new st_InstrAddOn;
    pnew->type = IA_ReadPointTo;
    pnew->pChild = pAddOn;
    pAddOn = pnew;

    return;
}

void	CCodeList_Maker::WriteToAddress(PINSTR p)
{	//	这个函数的意思是,如果是向一个address写,则加一条 i_Writepointto
	
//	对于add [ebx+4],6,变为
//		tem_1 = i_addr(ebx,4);
//		tem_2 = i_readpointto(tem_1);
//		tem_3 = tem_2 + 6;
//		i_writepointto(tem_1, tem_3);

	
	//	当前的情况是:
	//		tem1 addr eax,ebx*4,401000
	//		tem1 = ????
	//	要改成
	//		tem1 addr eax,ebx*4,401000
	//		tem2 = ????
	//		Writepointto(tem1, tem2);
	if (p->var_w.type != v_Tem)
	{	//	实际上不会来这里
		InstrAddTail(p);
		return;
	}
	
	VAR tem1 = p->var_w;	//	sav it
	VAR tem2;

	new_temp(&tem2);

	p->var_w = tem2;
	InstrAddTail(p);	//	add this

	PINSTR pnew = new INSTR;    //new_INSTR
	pnew->type = i_Writepointto;
	pnew->var_r1 = tem1;				// the pointer
	pnew->var_r2 = tem2;					// the value
		//	对 i_Writepointto, 是var_r1是指针,var_r2是值
	InstrAddTail(pnew);
	
}

extern int g_newtemno;
void	CCodeList_Maker::new_temp(VAR* pvar)
{
    pvar->type = v_Tem;
    pvar->temno = g_newtemno;
    g_newtemno += 2;
	pvar->opsize = BIT32_is_4;	//	temp var always DWORD
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -