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

📄 cfuncprt.cpp

📁 将exe等可执行文件转化成c程序的反编译程序,先到汇编再到c
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        return;
    }
    this->prt_para_1(ppara->var_r1.thevar, out);
}
#undef m_funcname
void CFunc_Prt::prt_instr_call(PINSTR p, CXmlOutPro* out)
{
    if (p->type == i_CallApi)
    {
        out->XMLbegin(XT_FuncName, p->call.papi);
        out->prtt(p->call.papi->name);
    }
    else
    {
        out->XMLbegin(XT_FuncName, p->call.call_func);
        out->prtt(p->call.call_func->m_funcname);
    }
    out->XMLend(XT_FuncName);
    out->prtt("(");

	if (p->call.p_callpara)
    {
		this->prt_parameter(p->call.p_callpara, out);
    }
    out->prtt(")");
}
void	CFunc_Prt::prt_instr(PINSTR p, POSITION &nextpos, CXmlOutPro* out)
{
    CFunc_InstrList instrl(m_instr_list);

    g_PrtOut.SetHline(p);
    if (p->var_w.type == v_Tem)
        nop();
	switch (p->type)
	{
	case i_CplxBegin:
		{
			//char buf[140];
			//prt_partern(this->m_instr_list,p,buf);
			//prtl_ident("// complex partern = %s",buf);
			switch (p->begin.type)
			{
			case COMP_if:
				{
                    out->ident();
                    out->XMLbegin(XT_Keyword, NULL);
                    out->prtt("if");
                    out->XMLend(XT_Keyword);
					out->prtt("(");
					PINSTR p1 = instrl.instr_next_in_func(p);
					prt_jxx_compare_false(p1, out);
					out->prtl(")");
					p1 = instrl.instr_next_in_func(p1);
					prt_one_statement(p1, out);
				}
				break;
			case COMP_long_if:
				{
                    out->ident();
                    out->XMLbegin(XT_Keyword, NULL);
                    out->prtt("if");
                    out->XMLend(XT_Keyword);
                    out->prtt("(");
					PINSTR p1 = instrl.instr_next_in_func(p);
					prt_jxx_compare_true(p1, out);
					out->prtl(")");
					p1 = instrl.instr_next_in_func(p1);	//	skip the jxx
					p1 = instrl.instr_next_in_func(p1);	//	skip the jmp
					p1 = instrl.instr_next_in_func(p1);	//	skip the label
					prt_one_statement(p1, out);
				}
				break;
			case COMP_if_else:
				{	// = "0_jxx1_0_jmp2_from1_0_from2_";
                    out->ident();
                    out->XMLbegin(XT_Keyword, NULL);
                    out->prtt("if");
                    out->XMLend(XT_Keyword);
                    out->prtt("(");
					PINSTR p1 = instrl.instr_next_in_func(p);
					prt_jxx_compare_false(p1, out);
					out->prtl(")");

					p1 = instrl.instr_next_in_func(p1);
					prt_one_statement(p1, out);

                    out->ident();
                    out->XMLbegin(XT_Keyword, NULL);
                    out->prtt("else");
                    out->XMLend(XT_Keyword);
                    out->endline();					

					p1 = instrl.instr_next_in_func(p1->begin.m_end);	//jmp2
					p1 = instrl.instr_next_in_func(p1);				//from1
					p1 = instrl.instr_next_in_func(p1);				//the statement

					prt_one_statement(p1, out);
				}
				break;
			case COMP_while:
				{
                    out->ident();
                    out->XMLbegin(XT_Keyword, NULL);
                    out->prtt("while");
                    out->XMLend(XT_Keyword);
                    out->prtt("(");
					
					PINSTR p1 = instrl.instr_next_in_func(p);
					p1 = instrl.instr_next_in_func(p1);	//	skip the first, its label
					prt_jxx_compare_false(p1, out);
					out->prtl(")");
					//prtl_ident("//while begin");
					p1 = instrl.instr_next_in_func(p1);
					prt_one_statement(p1, out);
					//prtl_ident("//while end");
				}
				break;
			case COMP_do_while:
				{
                    out->ident();
                    out->XMLbegin(XT_Keyword, NULL);
                    out->prtt("do");
                    out->XMLend(XT_Keyword);
                    out->endline();

					PINSTR p1 = instrl.instr_next_in_func(p);
					p1 = instrl.instr_next_in_func(p1);	//	skip the first, its label
					prt_one_statement(p1, out);

                    out->ident();
                    out->XMLbegin(XT_Keyword, NULL);
                    out->prtt("while");
                    out->XMLend(XT_Keyword);
                    out->prtt("(");

					p1 = instrl.instr_next_in_func(p1->begin.m_end);
					prt_jxx_compare_true(p1, out);
					out->prtt(")");
					out->EOL();
				}
				break;
            case COMP_for1:
                {
                    out->ident();
                    out->XMLbegin(XT_Keyword, NULL);
                    out->prtt("for");
                    out->XMLend(XT_Keyword);
                    out->prtt("(");
					
					PINSTR p1 = instrl.instr_next_in_func(p);

					prt_statement_in_1_line(p1, out);
					assert(p1->type == i_Label);
					PINSTR p2 = instrl.instr_next_in_func(p1);
                    p1 = p1->label.ref_instr;
					prt_jxx_compare_true(p1, out);
					out->prtt("; ");
                    {
                        PINSTR p3 = instrl.skip_compl(p2);
                        prt_statement_in_1_line(p3, out);
                        out->prtl(")");
                    }
					prt_one_statement(p2, out);			//	the main body
                    break;
                }
			case COMP_for:
				//cpp_prtl("//for find");
				//break;
				{	//	finger_for[] = "0_jmp1_from2_0_from1_0_jxx3_0_jmp2_from3_";
                    out->ident();
                    out->XMLbegin(XT_Keyword, NULL);
                    out->prtt("for");
                    out->XMLend(XT_Keyword);
                    out->prtt("(");
					
					PINSTR p1 = instrl.instr_next_in_func(p);

					prt_statement_in_1_line(p1, out);
					if (p1->type != i_Jump)
					{
						alert_prtf("type is %s",hlcode_name(p1->type));
					}
					assert(p1->type == i_Jump);
					out->prtt("; ");

					PINSTR p2 = instrl.instr_next_in_func(p1);
					p2 = instrl.instr_next_in_func(p2);	//	skip the label

					assert(p1->type == i_Jump);
					p1 = p1->jmp.the_label;
					p1 = instrl.instr_next_in_func(p1);	//	skip the label
					prt_jxx_compare_false(p1, out);
					out->prtt("; ");

					prt_statement_in_1_line(p2, out);
					out->prtl(")");


					assert(p1->type == i_Jump);
					p1 = instrl.instr_next_in_func(p1);	//	skip this jxx
					prt_one_statement(p1, out);			//	the main body
				}
				break;
			case COMP_switch_case:
				{	//	小心了,swith_case的显示很困难的
					out->prtf_ident("switch (");
					PINSTR p1 = instrl.instr_next_in_func(p);
					assert(p1->type == i_Jump);		//	开头肯定是个条件跳
					//while (p1->type != i_JmpAddr)
					//{
					//	p1 = instrl.instr_next_in_func(p1);
					//}
                    this->prt_va(p1->va_r1, out);
					out->prtl(")");
					out->prtl_ident("{");
                    CasePrt_List lstt;
					while (p1->type != i_Jump || p1->jmp.jmp_type != JMP_case)
					{
						p1 = instrl.instr_next_in_func(p1);
					}
					int n = 0;
					while (p1->type == i_Jump && p1->jmp.jmp_type == JMP_case)
					{
						//prtl_ident("case %d:",n++);
						//prt_case(p,p1->jmp.the_label);
						Add_case_entry(&lstt, n++, p1->jmp.the_label);
						p1 = instrl.instr_next_in_func(p1);
					}
					p1 = instrl.instr_next_in_func(p);
					//prtl_ident("default:");
					//prt_case(p,p1->jmp.the_label);
					add_default_entry(&lstt, p1->jmp.the_label);
					prt_switch_case(&lstt,p,out);
					out->prtl_ident("}");
				}
				break;
			case COMP_switch_case_multcomp:
				{	//	小心了,swith_case的显示很困难的
					out->prtf_ident("switch (");
					PINSTR p1 = instrl.instr_next_in_func(p);
					assert(p1->type == i_Jump);		//	开头肯定是个条件跳
					//while (p1->type != i_JmpAddr)
					//{
					//	p1 = instrl.instr_next_in_func(p1);
					//}
                    this->prt_va(p1->va_r1, out);
					out->prtl(")");
					out->prtl_ident("{");
		//	这里还有一点小麻烦,不能按case的次序打印,而要按实际处理地址的次序打印
		//	才能解决case延续和default问题
                    CasePrt_List lstt;
					while (p1->type == i_Jump && p1->jmp.jmp_type == JMP_jz)
					{
						assert(p1->var_r2.type == v_Immed);
						Add_case_entry(&lstt, p1->var_r2.d, p1->jmp.the_label);
						//prtl_ident("case %d:", p1->var_r2.d);
						//prt_case(p,p1->jmp.the_label);
						p1 = instrl.instr_next_in_func(p1);
					}
					if (p1->type == i_Jump && p1->jmp.jmp_type == JMP_jmp)
					{
						//prtl_ident("default:");
						//prt_case(p,p1->jmp.the_label);
						add_default_entry(&lstt, p1->jmp.the_label);
					}
					else
                    {
						add_default_entry(&lstt, p1);
						//error("default error");
                    }
					prt_switch_case(&lstt,p,out);
					out->prtl_ident("}");
				}
				break;
			default:
				out->prtl("//unknow cmplx statement");
				break;
			}
			//if (p->begin.type != COMP_unknown && p->begin.type != COMP_for)
			//if (p->begin.type != COMP_unknown && p->begin.type != COMP_switch_case)
			if (p->begin.type != COMP_unknown)
			{
				nextpos = this->m_instr_list->Find(p->begin.m_end);
				this->m_instr_list->GetNext(nextpos);
			}
			else
			{
				out->prtl_ident("{");
				out->ident_add1();
			}
		}
		break;
		
	case i_Begin:
		out->prtl_ident("{");
		out->ident_add1();
		break;
	case i_CplxEnd:
	case i_End:
		out->ident_sub1();
		out->prtl_ident("}");
		break;
	case i_Label:
        out->XMLbegin(XT_AsmLabel, (void*)p->label.label_off);
        out->prtf("L_%08x", p->label.label_off);
        out->XMLend(XT_AsmLabel);
        out->prtl(":");
		break;
	case i_Jump:
		if (p->jmp.jmp_type == JMP_jmp)
		{
			PINSTR p1 = p;
			while (p1->type != i_Begin && p1->type != i_CplxBegin)
			{
				p1 = instrl.instr_prev_in_func(p1);
			}
			if (p->jmp.the_label == p1->begin.m_break)
			{
				out->prtf_ident("break");
				out->EOL();
			}
			else if (p->jmp.the_label == p1->begin.m_conti
					 && p != p1->begin.m_not_conti)
			{
				out->prtf_ident("continue");
				out->EOL();
			}
			else
			{
				out->prtf_ident("JMP ");
                out->XMLbegin(XT_AsmLabel, (void*)p->jmp.jmpto_off);
                out->prtf("L_%08x", p->jmp.jmpto_off);
                out->XMLend(XT_AsmLabel);
				out->EOL();
			}
		}
		else
		{
			out->prtf_ident("Jxx ");
            out->XMLbegin(XT_AsmLabel, (void*)p->jmp.jmpto_off);
            out->prtf("L_%08x", p->jmp.jmpto_off);
            out->XMLend(XT_AsmLabel);
            if (p->var_r1.thevar != NULL)
            {
                out->prtt("(");
                this->prt_va(p->va_r1, out);
                out->prtt(" ");
                this->prt_va(p->va_r2, out);
                out->prtt(")");
            }
			out->EOL();
		}
		break;

#undef m_funcname
	case i_CallApi:
    case i_Call:
        if (prt_instr_callret(nextpos, out))
            break;  //这是因为i_CallRet是一个tem
        prt_instr_callthis(nextpos, out);
        prt_instr_call(p, out);
        out->EOL();
	
		break;
    case i_CallPara:
    case i_CallThis:
    case i_CallRet:
        break;
	case i_RetPar:
		{
            out->ident();
            out->XMLbegin(XT_Keyword, NULL);
			out->prtt("return");
            out->XMLend(XT_Keyword);
            this->prt_va(p->va_r1, out);
			POSITION pos = nextpos;
			bool ffirst = true;
			for (;;)
			{
				PINSTR p1 = this->m_instr_list->GetNext(pos);
				if (p1->type == i_RetPar)
				{
					//alert("prt here");
					nextpos = pos;
					if (! ffirst)
                    {
                        out->nospace();
						out->prtt(",");
                    }
                    this->prt_va(p1->va_r1, out);
					ffirst = false;
				}
				else if (p1->type == i_Return)
				{
					nextpos = pos;
					break;
				}
				else
					break;
			}
			out->EOL();
		}
		break;
    case i_EspReport:   //nothing
        break;
    default:

        if (!IfTemVar(&p->var_w))
        {
            out->ident(); prt_the_instr_1(p, out); out->EOL(); 
        }
        break;
	}
}
//---------------------
    
CPrtOut::CPrtOut()
{
    hline = NULL;
    b_Indent = true;
    b_Endl = true;
    b_OneLine = false;
    strcpy(m_buf.strbuf, "");
    m_buf.linesyntax[0].pos = -1;
}




⌨️ 快捷键说明

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