上一回我们提到“InFaceMaxtoCode.Startup正常启动后,在整个程序集中只会运行一次。”。
当时这种说法是很武断的,如果“InFaceMaxtoCode.C______(num2,num3)”的返回值总是false的话,该函数就会被执行多次,
不过根据后来动态调试的结果,我们证实了“InFaceMaxtoCode.C______(num2,num3)”的返回值为true,因此上次的说法是正确的。
现在言归正传,怎么取得解密后的代码呢?大概两个方向,
1.正面交锋,直接攻破maxtocode的运行库。
这就将问题直接回到了传统的win32层面,不过这个东西是业内人士写的在这方面的保护工作做得很好,像我这样的菜鸟就很难直接攻破了。
我曾有一个设想,就是通过分析运行库找到解密函数的入口,然后弄一个stubdll,hook这个地方,把解密后的il代码dump出来。
实际跟踪几次后我就放弃了。从跟踪到的信息来看,我猜测,运行库是通过mscorwks.dll挂接到jit,在jit的前面实时解密代码。
理论上我们也可以挂一个到jit前面,在那里dump解密的il代码,不过这个实现的方式,还不清楚,如果弄明白了,也就能写一个同样原理的加密软件了。
这个难度比较大,所以我最终放弃了这个方案。
2.避开运行库,我们直接利用dotNet2.0的特性获取IL代码。
如是我就试着用2.0写了一个winform程序,加密,运行,发现报错。
maxtocode3.1不支持2.0的winform程序,这就使我的这个方案实验夭折了。
两个月过去了,发现maxtocode升级到3.11了修正了这个bug,今天终于可以继续实验了。
我们来建一个简单的winform程序。一个窗体,然后一个按钮。
代码如下:
1usingSystem;
2usingSystem.Collections.Generic;
3usingSystem.ComponentModel;
4usingSystem.Data;
5usingSystem.Drawing;
6usingSystem.Text;
7usingSystem.Windows.Forms;
8usingSystem.Reflection;
9usingSpaces;
10namespaceTest5
11{
12 publicpartialclassForm1:Form
13 {
14 publicForm1()
15 {
16 InitializeComponent();
17 }
18
19 privatevoidTestMethod()
20 {
21 // [7/17/2006]
22 inti=0;
23 i=1;
24 i++;
25 if(i>0)
26 {
27 MessageBox.Show("OK");
28 }
29 }
30
31 privatevoidbutton1_Click(objectsender,EventArgse)
32 {
33 Typetp=this.GetType();
34
35 MethodInfomi=tp.GetMethod("TestMethod",
36 BindingFlags.NonPublic|BindingFlags.DeclaredOnly|
37 BindingFlags.Public|BindingFlags.Static
38 |BindingFlags.Instance);
39 if(mi==null)
40 {
41 MessageBox.Show("err");
42 return;
43 }
44 MethodBodymb=mi.GetMethodBody();
45 byte[]bt=mb.GetILAsByteArray();
46 StringBuildersb=newStringBuilder();
47 for(inti=0;i<bt.Length;i++)
48 {
49 sb.Append(bt[i].ToString("X2"));
50 sb.Append("");
51 }
52 stringstxt=sb.ToString();
53 MessageBox.Show(stxt);
54
55 }
56
57 }
58}