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

📄 cexprmanage.cpp

📁 将exe等可执行文件转化成c程序的反编译程序,先到汇编再到c
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{
    if (v->type == v_Immed)
    {
        prt_var_Immed(v, out);
        return;
    }
    out->XMLbegin(XT_Symbol, v->thevar);
    out->prtt(VarName(v));
    out->XMLend(XT_Symbol);
}
void CExprManage::prt_var_declares(CXmlOutPro* out)
{
	MLIST* list = this->vList;
	POSITION pos = list->GetHeadPosition();
	while (pos)
	{
		M_t* p = list->GetNext(pos);
        if (p->type != MTT_reg)
            continue;

        out->prtspace(4);
        
        out->XMLbegin(XT_DataType, p);
        out->prtt(GG_VarType_ID2Name(p->m_DataTypeID));
        out->XMLend(XT_DataType);
        
        out->XMLbegin(XT_Symbol, p);
        out->prtt(p->namestr);
        out->XMLend(XT_Symbol);
        
        if (GG_id2_VarType(p->m_DataTypeID)->type == vtt_array)
        {
            out->prtt("[");
            out->prtf("%d", GG_id2_VarType(p->m_DataTypeID)->m_array.arraynum);
            out->prtt("]");
        }
		out->prtt(";");
        out->endline();
	}
	
	pos = list->GetHeadPosition();
	while (pos)
	{
		M_t* p = list->GetNext(pos);
        if (p->type != MTT_var)
            continue;
        if (p->bTem)
            continue;

        out->prtspace(4);
        
        out->XMLbegin(XT_DataType, p);
        out->prtt(GG_VarType_ID2Name(p->m_DataTypeID));
        out->XMLend(XT_DataType);
		
        out->prtspace();
        out->XMLbegin(XT_Symbol, p);
        out->prtt(p->namestr);
        out->XMLend(XT_Symbol);
        if (GG_id2_VarType(p->m_DataTypeID)->type == vtt_array)
        {
            out->prtt("[");
            out->prtf("%d", GG_id2_VarType(p->m_DataTypeID)->m_array.arraynum);
            out->prtt("]");
        }
		out->prtt(";");
        out->endline();

	}
}
void CExprManage::prt_parameters(CXmlOutPro* out)
{
	bool first = true;
	
    assert(this);
	MLIST* list = this->vList;
    assert(list);
	POSITION pos = list->GetHeadPosition();
	while (pos)
	{
		M_t* p = list->GetNext(pos);
        if (p->type != MTT_par)
            continue;
        
		if (first)
			first = false;
		else
        {
            out->nospace();
			out->prtt(", ");
        }

        out->XMLbegin(XT_DataType, (PVOID)p->m_DataTypeID);
        out->prtt(GG_VarType_ID2Name(p->m_DataTypeID));
        out->XMLend(XT_DataType);

        out->XMLbegin(XT_Symbol, p);
        out->prtt(p->namestr);
        out->XMLend(XT_Symbol);
	}
}

M_t* CExprManage::AddRef_immed(DWORD d, DWORD size)
{
	M_t* pnew = new M_t;    //new_M_t
    pnew->type = MTT_immed;
    pnew->immed.d = d;
    pnew->size = size;
    pnew->m_DataTypeID = g_VarTypeManage->NewSimpleVarType(pnew->size);

    vList->AddTail(pnew);

    return pnew;
}
M_t* CExprManage::AddRef_tem(DWORD temno, DWORD size)
{
    POSITION pos = vList->GetHeadPosition();
    while (pos)
    {
        M_t* p = vList->GetNext(pos);
        if (p->type == MTT_tem && p->tem.temno == temno)
        {
            return p;
        }
    }
    //没找到,就new一个
	M_t* pnew = new M_t;    //new_M_t
    pnew->type = MTT_tem;
    pnew->tem.temno = temno;
    sprintf(pnew->namestr, "t_%x", temno);
    pnew->size = size;
    pnew->m_DataTypeID = g_VarTypeManage->NewSimpleVarType(pnew->size);

    vList->AddTail(pnew);

    return pnew;
}
void Replace_Var(INSTR_LIST* instr_list, M_t* pvar, M_t* thevar);
M_t* CExprManage::AddRef_with_name(en_MTTYPE type, DWORD off, DWORD size, PCSTR tj_name)
//SuperC_func: 只在<CExprManage::AddRef>中使用
{
    assert(type != MTT_tem);


    {//先找一找是不是已经有了
        POSITION pos = vList->GetHeadPosition();
        while (pos)
        {
            M_t* p = vList->GetNext(pos);
            if (p->type == type && p->s_off == off && p->size == size)
            {
                if (!p->iThrowned)
                    return p;
            }
        }
    }

	M_t* pnew = new M_t;    //new_M_t
    pnew->type = type;
	pnew->s_off = off;
    pnew->size = size;
    pnew->m_DataTypeID = g_VarTypeManage->NewSimpleVarType(pnew->size);

    vList->AddTail(pnew);

    this->Enlarge_Var(pnew, ::g_Cur_Func->m_instr_list);

    strcpy(pnew->namestr, tj_name);

    return pnew;
}

signed int varoff2stack(UINT off);
void CExprManage::EspReport(signed int esplevel)
{
    static int static_iThrown = 1;
    static_iThrown++;

    POSITION pos = vList->GetHeadPosition();
    while (pos)
    {
        M_t* p = vList->GetNext(pos);
        if (p->type != MTT_var)
            continue;
        
        if (esplevel > varoff2stack(p->s_off))
        {
            p->iThrowned = static_iThrown;    //扔掉
        }
    }
}

    
M_t* CExprManage::SearchMT(en_MTTYPE type, DWORD off)
{
	POSITION pos = vList->GetHeadPosition();
	while (pos)
	{
		M_t* p = vList->GetNext(pos);
        if (p->type == type && p->s_off == off)
            return p;
    }
    return NULL;
}

CExprManage g_GlobalExpr;

void CExprManage::AddRef(VAR* pvar)
{	//	告诉一声CExprManage,这个var 有人用
    // 确保所有var都会产生一个thevar
	switch (pvar->type)
	{
	case v_Invalid: return;
    case v_Immed: 
        if (pvar->d == 4)
        {
            pvar->d = 4;
        }
        pvar->thevar = this->AddRef_immed(pvar->d, pvar->opsize);
        return;
    case v_Global:
        {
            char name[20];
    		sprintf(name,"g_%x",pvar->off);
            pvar->thevar = g_GlobalExpr.AddRef_with_name(MTT_global, pvar->off, pvar->opsize, name);
            return;
        }
    case v_Volatile:
    case v_Tem: 
        {
            pvar->thevar = this->AddRef_tem(pvar->temno, pvar->opsize);
            pvar->thevar->bTem = true;
            return;		
        }
    case v_Var:
        {
            this->m_VarRange_H;
            this->m_VarRange_L;
            char name[20];
            if (0x7ffff - (signed int)pvar->var_off + 1 > -this->m_VarRange_L)
            {
                sprintf(name,"tem_%x",0x7ffff - pvar->var_off + 1);	//0x7ffff - p->s_off + 1
                pvar->thevar = this->AddRef_with_name(MTT_var, pvar->var_off, pvar->opsize, name);
                //pvar->thevar = this->CreateNewTemVar(pvar->opsize);
                pvar->thevar->bTem = true;
            }
            else
            {
                sprintf(name,"v_%x",0x7ffff - pvar->var_off + 1);	//0x7ffff - p->s_off + 1
                pvar->thevar = this->AddRef_with_name(MTT_var, pvar->var_off, pvar->opsize, name);
            }
        }
        break;
    case v_Par:
        {
            char name[20];
    		sprintf(name,"a_%x",pvar->par_off);
            pvar->thevar = this->AddRef_with_name(MTT_par, pvar->par_off, pvar->opsize, name);
        }
        break;
    case v_Reg:
        {
            PCSTR pname = RegName(pvar->reg, pvar->opsize);
            pvar->thevar = this->AddRef_with_name(MTT_reg, pvar->reg, pvar->opsize, pname);
        }
        break;
    default:
        assert(0);
    }
}
DWORD	stack2varoff(signed long stackoff)
{
	assert(stackoff < 0);
	DWORD off = (DWORD)stackoff;		//	BYTE 转为 DWORD
	off &= 0x7ffff;				//	够了吧?
	return off;
}
signed int varoff2stack(UINT off)
{
    return -(0x7ffff - (signed int)off + 1);
}

    
int g_newtemno = 737;
    //每次使用都加2,这样就把偶数的值留出来了

M_t* CExprManage::CreateNewTemVar(UINT size)
{
    M_t* pnew = new M_t;
    pnew->type = MTT_tem;
    pnew->size = size;

    pnew->tem.temno = g_newtemno;
    g_newtemno += 2;
    sprintf(pnew->namestr, "tem_%x", pnew->tem.temno);
    pnew->m_DataTypeID = g_VarTypeManage->NewSimpleVarType(pnew->size);

    vList->AddTail(pnew);
    return pnew;
}

void Replace_Var_1(VAR* var, M_t* pvar, M_t* thevar)
{
    if (var->thevar != pvar)
        return;
        
    var->thevar = thevar;
    if (var->opsize != thevar->size)
    {
        switch (var->type)
        {
        case v_Var:
            var->part_flag = 1+var->var_off-thevar->s_off;
            break;
        default:
            var->part_flag = 1;
            break;
        }
    }
}
void Replace_Var(INSTR_LIST* instr_list, M_t* pvar, M_t* thevar)
{
	assert(instr_list != NULL);
    POSITION pos = instr_list->GetHeadPosition();
    while (pos)
    {
        PINSTR p = instr_list->GetNext(pos);
        Replace_Var_1(&p->var_w,pvar,thevar);
        Replace_Var_1(&p->var_r1,pvar,thevar);
        Replace_Var_1(&p->var_r2,pvar,thevar);
    }
}
void CExprManage::Enlarge_Var(M_t* thevar, INSTR_LIST* instr_list)
{
    //下面,要删被我占了的var

	assert(instr_list != NULL);
    MLIST*	list = vList;
    POSITION pos = list->GetHeadPosition();
    while (pos)
    {
        POSITION savpos = pos;
        M_t* p = list->GetNext(pos);
        if (p == thevar)
        {
            Replace_Var(instr_list, p, thevar); //replace myself
            continue;
        }
        if (p->type != thevar->type)
            continue;
        if (p->iThrowned != 0 && p->iThrowned != thevar->iThrowned)
            continue;
        
        if (thevar->IfInclude(p->s_off) 
            && thevar->IfInclude(p->s_off + p->size))
        {
            list->RemoveAt(savpos);
            //仅仅删掉是不行的,还要更新instrlist

            Replace_Var(instr_list, p, thevar);
        }
    }
}

void CExprManage::ClearUse()
{
    POSITION pos = vList->GetHeadPosition();
    while (pos)
    {
        M_t* p = vList->GetNext(pos);
        p->tem_useno = 0;
    }
}

⌨️ 快捷键说明

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