因爲公司業務須要簡單的把代碼加密混淆,因而瞭解了一下相關的工具而後打算用ConfuserEx試試。git
開源地址:https://github.com/yck1509/ConfuserEx/github
下載地址:https://github.com/yck1509/ConfuserEx/releasesdom
開始工做編輯器
1.簡單編寫一個產生隨機數的Winform窗口程序ide
代碼以下工具
using System; using System.Windows.Forms; namespace ConfuserEx_Test { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { var max = (double)numericUpDown1.Value; var min = (double)numericUpDown2.Value; Random random = new Random(); double v = random.NextDouble() * (max -min) + min; label1.Text = v.ToString(); textBox1.AppendText(v.ToString() + "\r\n"); } } }
namespace ConfuserEx_Test { partial class Form1 { /// <summary> /// 必需的設計器變量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理全部正在使用的資源。 /// </summary> /// <param name="disposing">若是應釋放託管資源,爲 true;不然爲 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗體設計器生成的代碼 /// <summary> /// 設計器支持所需的方法 - 不要修改 /// 使用代碼編輯器修改此方法的內容。 /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.textBox1 = new System.Windows.Forms.TextBox(); this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(225, 140); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(213, 53); this.button1.TabIndex = 0; this.button1.Text = "生成隨機數"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(12, 9); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(35, 13); this.label1.TabIndex = 1; this.label1.Text = "label1"; // // textBox1 // this.textBox1.Location = new System.Drawing.Point(12, 36); this.textBox1.Multiline = true; this.textBox1.Name = "textBox1"; this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both; this.textBox1.Size = new System.Drawing.Size(207, 157); this.textBox1.TabIndex = 2; // // numericUpDown1 // this.numericUpDown1.Location = new System.Drawing.Point(298, 68); this.numericUpDown1.Maximum = new decimal(new int[] { 100000, 0, 0, 0}); this.numericUpDown1.Minimum = new decimal(new int[] { 100000, 0, 0, -2147483648}); this.numericUpDown1.Name = "numericUpDown1"; this.numericUpDown1.Size = new System.Drawing.Size(84, 20); this.numericUpDown1.TabIndex = 3; this.numericUpDown1.Value = new decimal(new int[] { 100, 0, 0, 0}); // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(247, 70); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(43, 13); this.label2.TabIndex = 5; this.label2.Text = "最大值"; // // label3 // this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(247, 96); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(43, 13); this.label3.TabIndex = 6; this.label3.Text = "最小值"; // // numericUpDown2 // this.numericUpDown2.Location = new System.Drawing.Point(298, 94); this.numericUpDown2.Maximum = new decimal(new int[] { 100000, 0, 0, 0}); this.numericUpDown2.Minimum = new decimal(new int[] { 100000, 0, 0, -2147483648}); this.numericUpDown2.Name = "numericUpDown2"; this.numericUpDown2.Size = new System.Drawing.Size(84, 20); this.numericUpDown2.TabIndex = 7; this.numericUpDown2.Value = new decimal(new int[] { 100, 0, 0, -2147483648}); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(444, 205); this.Controls.Add(this.numericUpDown2); this.Controls.Add(this.label3); this.Controls.Add(this.label2); this.Controls.Add(this.numericUpDown1); this.Controls.Add(this.textBox1); this.Controls.Add(this.label1); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "ConfuserEx加密混淆測試"; ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Button button1; private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.NumericUpDown numericUpDown1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.NumericUpDown numericUpDown2; } }
其功能如圖:測試
2.下載打開ConfuserEx使用this
2.1 將生成的exe文件拖拽到ConfuserEx的Project中加密
2.2在Settings中選中Packer(聽說dll文件不是這樣的),再點擊exe文件,添加一個True。spa
2.3點擊Protect!看到Finished at xx:xx, xx:xx elapsed.表示完成
3.測試加密混淆結果
3.1下載ILSpy--(百度百科:ILspy是一個開源的.net反編譯軟件,使用十分方便。)
3.2將保護前編譯出的exe文件拖拉到ILSpy中
很方便就可以看到源碼
3.2 將保護後的exe文件拖拉到ILSpy中與以前的作對比
4.結論
簡單的測試了一下,這種保護便於操做,有明顯的保護效果,可以防止只會下載反編譯軟件來得到源碼的人,可是可能不是全部反編譯軟件都能防止。只是作個簡單保護。
後面我會作一個Reflector反編譯實驗以及脫殼後再來反編譯。
附加1
Reflector反編譯實驗結果,保護後的直接打不開