2015年8月8日

反組譯c# Usercontrol的修改要點

有時很無奈需要維護沒有原始碼的.net DLL/EXE, 以下提供經驗供參考

工具:
JetBrain dotpeek 1.4, 是個免費軟體, 效果比teleric just decompile好, 基本上這兩個軟體都可直些輸出專案檔
dotpeek 轉出來程式碼,UI的designer會不見, 但到控制項的classe裡, 共有以下
InitializeComponent, dispose, 畫面的控制項宣告
註解和region不存在
修改
1. 去除goto
2. Reflection
3. 判斷式改寫
4. UI 部分會出現錯誤
到這邊應該 compile是沒錯誤,但是在visual studio打開form uservontrol, 會發生以下錯誤
a. 原本的控制項類別class前加partial, 增加designer.cs
自行新增一個usercontrol,  將其designer複製, 更名成我們要修改的XXcontrol.designer.cs
刪除原本private IContainer components;
刪除原本dispose method
搬移InitializeComponent,  畫面的控制項宣告進去designer, 可能需要using
desinger加上
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

b.  'InitializeComponent' 中的程式碼是由設計工具產生的,不能以手動方式修改。請移除任何變更,然後再次嘗試開啟設計工具。
image
以上只要在該錯誤方屬性BorderStyle前加上System.Windows.Forms.
.BorderStyle =System.Windows.Forms.BorderStyle.FixedSingle;
c. ComponentResourceManager前加上
System.ComponentModel.
ComponentResourceManager  宣告變數改成
resources
d.  XX cintrol未起始化
所引用control加上designer.cs
5. resx 從專案移除再加入

1 則留言: