• 标 题:.net下程序的暴力修改2
  • 作 者:turbowang
  • 时 间:004-09-23,22:08
  • 链 接:http://bbs.pediy.com

最近为了使单片机的通信扩展到Internet使用了Lantronix公司生产的XPort(串口—网络口数据转发模块),在使用它带的软件DeviceInstaller进行软件的配置的时候,发现安装完毕启动时出现异常,异常信息如下

未处理的“System.NotSupportedException”类型的异常出现在 mscorlib.dll 中。

其他信息: 区域性“zh-CHS”是非特定区域性。它不能用于格式化和分析,因此不能设置为线程的当前区域性。

使用。Net反编译工具,打开主程序XTool.exe,找到主窗体,此软件没有经过混淆,代码很清晰,在Form1种
public Form1()
{   
CultureInfo info1;
Version version1;
string text1;
DialogResult result1;
DialogResult result2;
string text2;
string text3;
string[] array1;
int num1;
ListViewColumnSorter sorter1;
base..ctor();
CultureInfo.CurrentCulture.ClearCachedData();
info1 = CultureInfo.CurrentCulture;
if (info1.TwoLetterISOLanguageName == "zh")
{
 Thread.CurrentThread.CurrentCulture = new CultureInfo(info1.Parent.LCID);// //此部分出错
Thread.CurrentThread.CurrentUICulture = new CultureInfo(info1.Parent.LCID);// 
 }
this.InitializeComponent();
 
}
就是Thread.CurrentThread.CurrentCulture = new CultureInfo(info1.Parent.LCID);将new 的
CultureInfo(info1.Parent.LCID)赋给Thread.CurrentThread.CurrentCulture,出现了异常,因此不能设置为线程的当前区域性的异常。可能是程序为了比较好的支持国际化,而这样写的带代码,看来有些多余。看来只要不让出错的语句运行即可,而这最好的实现方式就是修改比较条件。

可以使用两种方法进行修改
1.  使用ildasm进行反汇编,得到中间代码,修改中间代码,然后重新编译即可。
使用ildasm进行反汇编后得到一大堆代码,下面仅仅列出相关的
// 相关的汇编代码
.maxstack 6
.locals (CultureInfo V_0, Version V_1, string V_2, Exception V_3, DialogResult V_4, DialogResult V_5, string V_6, string V_7, string[] V_8, int V_9, ListViewColumnSorter V_10)
.try L_0132 to L_014a catch object L_014a to L_014d
.try L_014d to L_0574 catch Exception L_0574 to L_0584
.try L_0739 to L_0754 catch object L_0754 to L_0768
L_0000: ldarg.0 
L_0001: call Form..ctor
L_0006: call CultureInfo.get_CurrentCulture
L_000b: callvirt CultureInfo.ClearCachedData
L_0010: call CultureInfo.get_CurrentCulture
L_0015: stloc.0 
L_0016: ldloc.0 
L_0017: callvirt CultureInfo.get_TwoLetterISOLanguageName
L_001c: ldstr "zh" ------------将此处的字符串改为aa


再使用ilasm 将修改后的相关代码进行编译得到新程序即可。重新编译后,生成的程序比原来的小了(可能有部分资源没有编译进去),不知道什么原因,但是没有发现影响使用的状况

2.  简单的处理方式,一般的.net程序中使用的常量字符串,在.net程序中都有相应的储存位置(存储格式为unicode 形式),所以使用WinHex打开程序,查找字符串zh,选中unicode项,发现文件中仅能搜索到一次,毫无疑问,就是他了,直接将字符串
7A 00 68 00 改为其他的不同字节即可。存盘后,程序正常运行