[Tool]使用PreEmptive的Dotfuscator來做模糊化

[Tool]使用PreEmptive的Dotfuscator來做模糊化

前言

今天下載PreEmptive的Dotfuscator來做模糊化,主要目的是因為有些加解密的Logic是寫在組件之中,怕被反組譯來看,這樣加密就沒有效果了!

實作

1.先寫個Windows Form測試程式(裡面2個字串,一個Method,按下button1會顯示這2個字串的值),如下,

private const string str1 = "This is str1";
private string str2 = "This is str2";
private void ShowStrings(string s1, string s2)
{
    MessageBox.Show(str1);
    MessageBox.Show(str2);
}
private void button1_Click(object sender, EventArgs e)
{
    ShowStrings(str1, str2);
}

 

 

 

show1

2.使用反組譯程式來將Form1反組譯出來,結果跟Source Code簡直就一模一樣了!

private const string str1 = "This is str1";
private string str2 = "This is str2";
private void ShowStrings(string s1, string s2)
{
    MessageBox.Show("This is str1");
    MessageBox.Show(this.str2);
}
private void button1_Click(object sender, EventArgs e)
{
    this.ShowStrings("This is str1", this.str2);
}

 

 

 

3.使用Dotfuscator來模糊化

3.1.建立新專案

3_1

3.2.選取要模糊化的檔案

3_2

3.3.點選Settings Tab,將Settings=>Global Options=>Disable String Encryption的值設成No

3_3

3.4.點選String Encryption Tab,勾選要Encryption的物件。

3_4

3.5.按下「arrow」Build就可以了

3_5

4.使用反組譯程式來將Form1反組譯出來,結果完全看不下去! 如下的Code,

private const string a = "This is str1";
private string b;
public Form1()
{
    int num = 4;
    this.b = b("닥胧菩鿫컭駯臱퓳藵賷裹컻", num);
    this.c = null;
    this.a();
}
private void a(object A_0, EventArgs A_1)
{
    // This item is obfuscated and can not be translated.
}

	
private void a(string A_0, string A_1)
{
    // This item is obfuscated and can not be translated.
}

	
internal static string b(string A_0, int A_1)
{
    char ch2;
    int num2;
    int expressionStack_47_0;
    int expressionStack_14_0;
    char[] chArray = A_0.ToCharArray();
    int num = 0x2acad2e1 + A_1;
    if (0 < 1)
    {
        expressionStack_47_0 = 0;
        goto Label_0047;
    }
    else
    {
        expressionStack_14_0 = 0;
    }
Label_0014:
    ch2 = chArray[num2];
    byte num3 = (byte) ((ch2 & '\x00ff') ^ num++);
    byte num4 = (byte) ((ch2 >> 8) ^ num++);
    num4 = num3;
    num3 = num4;
    chArray[num2] = (char) ((num4 << 8) | num3);
    expressionStack_47_0 = (num2 = expressionStack_14_0) + 1;
Label_0047:
    if (expressionStack_47_0 < chArray.Length)
    {
        expressionStack_14_0 = expressionStack_47_0;
        goto Label_0014;
    }
    else
    {
        int expressionStack_4D_0 = expressionStack_47_0;
    }
    return string.Intern(new string(chArray));
}

 

 

 

以上簡單的設定,就能達到模糊化,真的很方便!

 

不過,如果您連常數都要變不見的話! 那可以在Command Line中使用/prune:on或是/prune:const哦! 如下,

dotfuscator /in:f:\WindowsApplication1.exe /prune:on

dotfuscator /in:f:\WindowsApplication1.exe /prune:const

 

使用反組譯程式來將Form1反組譯出來,string a也不見了!

private static List<WeakReference> a;
private IContainer b;
[AccessedThroughProperty("Button1")]
private Button c;
private string d;

 

附上 Dotfuscator版本比較

 

 

Hi, 

亂馬客Blog已移到了 「亂馬客​ : Re:從零開始的軟體開發生活

請大家繼續支持 ^_^