用ildasm和ilasm对.net下的exe程序进行破解初探
1、对ildasm和ilasm的解释和用法在msdn上有。
ildasm:MSIL 反汇编程序是 MSIL 汇编程序 (Ilasm.exe) 的伙伴工具。 Ildasm.exe 采用包含 Microsoft 中间语言 (MSIL) 代码的可迁移可执行 (PE) 文件,并创建相应的 文本文件作为 Ilasm.exe 的输入
ilasm:MSIL 汇编程序从 Microsoft 中间语言 (MSIL) 生成可迁移可执行的 (PE) 文件。 (有关 MSIL 的更多信息,请参见 托管执行过程。)可以运行结果可执行文件(该文件包含 MSIL 和所需的元数据)以确定 MSIL 是否按预期执行。
2、如下是控制台程序ClassLibrary.exe的原代码
namespace ClassLibrary
{
class Class1
{
public static void Main()
{
string input;
do
{ input = System.Console.ReadLine();
if (input == "admin")
{
System.Console.WriteLine("登录成功\n");
}
else
{
System.Console.WriteLine("登录失败\n");
}
} while (input!="end"); }
}
}
3、用ildasm对ClassLibrary.exe程序进行反汇编
可以直接在Vs2012开发人员工具命令里用命令:C:\Program Files\Microsoft Visual Studio 11.0>ildasm D:\快盘\StudyNoteOfCsharp\ClassLibrary\bin\Debug\ClassLibrary.exe /output:D:\快盘\StudyNoteOfCsharp\ClassLibrary\bin\Debug\broker.il 将ClassLibrary.exe生成broder.il文件
也可以找到ildasm.exe,运行界面,存储为il文件

4、用记事本修改.il文件

5、用ilasm将修改后的il文件编辑成exe文件
运行命令:C:\Program Files\Microsoft Visual Studio 11.0>ilasm D:\快盘\StudyNoteOfCsharp\CassLibrary\bin\Debug\broker
将broker.il文件在当前目录下生成broker.exe程序
修改后的exe和原exe程序的对比

6、破解程序实例
6.1、一个程序登录界面点登录后运行的是如下代码。
private void bdl_Click(object sender, EventArgs e)
{ //用户名不为空,才进行登录操作
if (this.tbyhm.Text.Length > 0)
{
//用户验证
if (this.yhdljc())
{
string user = this.tbyhm.Text.Trim();
if (!this.tbyhm.AutoCompleteCustomSource.Contains(user))
{
this.tbyhm.AutoCompleteCustomSource.Add(user);
}
this.IsLogIn = true;
this.Close();
}
} } public bool yhdljc()
{
bool re = false; ArrayList ap = new ArrayList();
ap.Add(new UProcPara("@yhdm", SqlDbType.NVarChar, 20, tbyhm.Text.ToUpper()));
ap.Add(new UProcPara("@yhmm", SqlDbType.NVarChar, 50, tbmm.Text));
DataTable dt = USql.getInstance().procedure("p_yhdljc", ap); if (dt.Rows[0]["sm"].ToString().Length > 0)
{
MessageBoxEx.Show(dt.Rows[0]["sm"].ToString());
tbyhm.SelectAll();
tbyhm.Focus();
}
else
{
//初始化登录人员的信息 UInf._yhdm = dt.Rows[0]["yhdm"].ToString();
UInf._yhmc = dt.Rows[0]["yhmc"].ToString();
UInf._ryid = int.Parse(dt.Rows[0]["ryid"].ToString());
UInf._hisdm = dt.Rows[0]["hisdm"].ToString();
UInf._hismc = dt.Rows[0]["hismc"].ToString();
UInf._ddid = int.Parse(dt.Rows[0]["ddid"].ToString());
UInf._ddmc = dt.Rows[0]["ddmc"].ToString();
UInf._bmid = int.Parse(dt.Rows[0]["bmid"].ToString());
UInf._bmdm = dt.Rows[0]["bmdm"].ToString();
UInf._bmmc = dt.Rows[0]["bmmc"].ToString();
UInf.dlbz = 1; re = true;
}
return re;
}
6.2、在程序反编译后的.il文件找到yhdjc()函数
.method public hidebysig instance bool
yhdljc() cil managed
{
// 代码大小 554 (0x22a)
.maxstack 6
.locals init ([0] bool re,
[1] class [mscorlib]System.Collections.ArrayList ap,
[2] class [System.Data]System.Data.DataTable dt,
[3] bool CS$1$0000,
[4] bool CS$4$0001)
IL_0000: nop
IL_0001: ldc.i4.0
IL_0002: stloc.0
IL_0003: newobj instance void [mscorlib]System.Collections.ArrayList::.ctor()
IL_0008: stloc.1
IL_0009: ldloc.1
IL_000a: ldstr "@yhdm"
IL_000f: ldc.i4.s 12
IL_0011: ldc.i4.s 20
IL_0013: ldarg.0
IL_0014: ldfld class [DevComponents.DotNetBar2]DevComponents.DotNetBar.Controls.ComboBoxEx yywlxt.ui.LoginForm::tbyhm
IL_0019: callvirt instance string [System.Windows.Forms]System.Windows.Forms.Control::get_Text()
IL_001e: callvirt instance string [mscorlib]System.String::ToUpper()
IL_0023: newobj instance void yywlxt.conn.UProcPara::.ctor(string,
valuetype [System.Data]System.Data.SqlDbType,
int32,
object)
IL_0028: callvirt instance int32 [mscorlib]System.Collections.ArrayList::Add(object)
IL_002d: pop
IL_002e: ldloc.1
IL_002f: ldstr "@yhmm"
IL_0034: ldc.i4.s 12
IL_0036: ldc.i4.s 50
IL_0038: ldarg.0
IL_0039: ldfld class [DevComponents.DotNetBar2]DevComponents.DotNetBar.Controls.TextBoxX yywlxt.ui.LoginForm::tbmm
IL_003e: callvirt instance string [System.Windows.Forms]System.Windows.Forms.Control::get_Text()
IL_0043: newobj instance void yywlxt.conn.UProcPara::.ctor(string,
valuetype [System.Data]System.Data.SqlDbType,
int32,
object)
IL_0048: callvirt instance int32 [mscorlib]System.Collections.ArrayList::Add(object)
IL_004d: pop
IL_004e: call class yywlxt.conn.USql yywlxt.conn.USql::getInstance()
IL_0053: ldstr "p_yhdljc"
IL_0058: ldloc.1
IL_0059: callvirt instance class [System.Data]System.Data.DataTable yywlxt.conn.USql::procedure(string,
class [mscorlib]System.Collections.ArrayList)
IL_005e: stloc.2
IL_005f: ldloc.2
IL_0060: callvirt instance class [System.Data]System.Data.DataRowCollection [System.Data]System.Data.DataTable::get_Rows()
IL_0065: ldc.i4.0
IL_0066: callvirt instance class [System.Data]System.Data.DataRow [System.Data]System.Data.DataRowCollection::get_Item(int32)
IL_006b: ldstr "sm"
IL_0070: callvirt instance object [System.Data]System.Data.DataRow::get_Item(string)
IL_0075: callvirt instance string [mscorlib]System.Object::ToString()
IL_007a: callvirt instance int32 [mscorlib]System.String::get_Length()
IL_007f: ldc.i4.0
IL_0080: cgt
IL_0082: ldc.i4.0
IL_0083: ceq
IL_0085: stloc.s CS$4$0001
IL_0087: ldloc.s CS$4$0001
IL_0089: brtrue.s IL_00cb IL_008b: nop
IL_008c: ldloc.2
IL_008d: callvirt instance class [System.Data]System.Data.DataRowCollection [System.Data]System.Data.DataTable::get_Rows()
IL_0092: ldc.i4.0
IL_0093: callvirt instance class [System.Data]System.Data.DataRow [System.Data]System.Data.DataRowCollection::get_Item(int32)
IL_0098: ldstr "sm"
IL_009d: callvirt instance object [System.Data]System.Data.DataRow::get_Item(string)
IL_00a2: callvirt instance string [mscorlib]System.Object::ToString()
IL_00a7: call valuetype [System.Windows.Forms_6]System.Windows.Forms.DialogResult [DevComponents.DotNetBar2]DevComponents.DotNetBar.MessageBoxEx::Show(string)
IL_00ac: pop
IL_00ad: ldarg.0
IL_00ae: ldfld class [DevComponents.DotNetBar2]DevComponents.DotNetBar.Controls.ComboBoxEx yywlxt.ui.LoginForm::tbyhm
IL_00b3: callvirt instance void [System.Windows.Forms]System.Windows.Forms.ComboBox::SelectAll()
IL_00b8: nop
IL_00b9: ldarg.0
IL_00ba: ldfld class [DevComponents.DotNetBar2]DevComponents.DotNetBar.Controls.ComboBoxEx yywlxt.ui.LoginForm::tbyhm
IL_00bf: callvirt instance bool [System.Windows.Forms]System.Windows.Forms.Control::Focus()
IL_00c4: pop
IL_00c5: nop
IL_00c6: br IL_0224 IL_00cb: nop
IL_00cc: ldloc.2
IL_00cd: callvirt instance class [System.Data]System.Data.DataRowCollection [System.Data]System.Data.DataTable::get_Rows()
IL_00d2: ldc.i4.0
IL_00d3: callvirt instance class [System.Data]System.Data.DataRow [System.Data]System.Data.DataRowCollection::get_Item(int32)
IL_00d8: ldstr "yhdm"
IL_00dd: callvirt instance object [System.Data]System.Data.DataRow::get_Item(string)
IL_00e2: callvirt instance string [mscorlib]System.Object::ToString()
IL_00e7: stsfld string yywlxt.conn.UInf::_yhdm
IL_00ec: ldloc.2
IL_00ed: callvirt instance class [System.Data]System.Data.DataRowCollection [System.Data]System.Data.DataTable::get_Rows()
IL_00f2: ldc.i4.0
IL_00f3: callvirt instance class [System.Data]System.Data.DataRow [System.Data]System.Data.DataRowCollection::get_Item(int32)
IL_00f8: ldstr "yhmc"
IL_00fd: callvirt instance object [System.Data]System.Data.DataRow::get_Item(string)
IL_0102: callvirt instance string [mscorlib]System.Object::ToString()
IL_0107: stsfld string yywlxt.conn.UInf::_yhmc
IL_010c: ldloc.2
IL_010d: callvirt instance class [System.Data]System.Data.DataRowCollection [System.Data]System.Data.DataTable::get_Rows()
IL_0112: ldc.i4.0
IL_0113: callvirt instance class [System.Data]System.Data.DataRow [System.Data]System.Data.DataRowCollection::get_Item(int32)
IL_0118: ldstr "ryid"
IL_011d: callvirt instance object [System.Data]System.Data.DataRow::get_Item(string)
IL_0122: callvirt instance string [mscorlib]System.Object::ToString()
IL_0127: call int32 [mscorlib]System.Int32::Parse(string)
IL_012c: stsfld int32 yywlxt.conn.UInf::_ryid
IL_0131: ldloc.2
IL_0132: callvirt instance class [System.Data]System.Data.DataRowCollection [System.Data]System.Data.DataTable::get_Rows()
IL_0137: ldc.i4.0
IL_0138: callvirt instance class [System.Data]System.Data.DataRow [System.Data]System.Data.DataRowCollection::get_Item(int32)
IL_013d: ldstr "hisdm"
IL_0142: callvirt instance object [System.Data]System.Data.DataRow::get_Item(string)
IL_0147: callvirt instance string [mscorlib]System.Object::ToString()
IL_014c: stsfld string yywlxt.conn.UInf::_hisdm
IL_0151: ldloc.2
IL_0152: callvirt instance class [System.Data]System.Data.DataRowCollection [System.Data]System.Data.DataTable::get_Rows()
IL_0157: ldc.i4.0
IL_0158: callvirt instance class [System.Data]System.Data.DataRow [System.Data]System.Data.DataRowCollection::get_Item(int32)
IL_015d: ldstr "hismc"
IL_0162: callvirt instance object [System.Data]System.Data.DataRow::get_Item(string)
IL_0167: callvirt instance string [mscorlib]System.Object::ToString()
IL_016c: stsfld string yywlxt.conn.UInf::_hismc
IL_0171: ldloc.2
IL_0172: callvirt instance class [System.Data]System.Data.DataRowCollection [System.Data]System.Data.DataTable::get_Rows()
IL_0177: ldc.i4.0
IL_0178: callvirt instance class [System.Data]System.Data.DataRow [System.Data]System.Data.DataRowCollection::get_Item(int32)
IL_017d: ldstr "ddid"
IL_0182: callvirt instance object [System.Data]System.Data.DataRow::get_Item(string)
IL_0187: callvirt instance string [mscorlib]System.Object::ToString()
IL_018c: call int32 [mscorlib]System.Int32::Parse(string)
IL_0191: stsfld int32 yywlxt.conn.UInf::_ddid
IL_0196: ldloc.2
IL_0197: callvirt instance class [System.Data]System.Data.DataRowCollection [System.Data]System.Data.DataTable::get_Rows()
IL_019c: ldc.i4.0
IL_019d: callvirt instance class [System.Data]System.Data.DataRow [System.Data]System.Data.DataRowCollection::get_Item(int32)
IL_01a2: ldstr "ddmc"
IL_01a7: callvirt instance object [System.Data]System.Data.DataRow::get_Item(string)
IL_01ac: callvirt instance string [mscorlib]System.Object::ToString()
IL_01b1: stsfld string yywlxt.conn.UInf::_ddmc
IL_01b6: ldloc.2
IL_01b7: callvirt instance class [System.Data]System.Data.DataRowCollection [System.Data]System.Data.DataTable::get_Rows()
IL_01bc: ldc.i4.0
IL_01bd: callvirt instance class [System.Data]System.Data.DataRow [System.Data]System.Data.DataRowCollection::get_Item(int32)
IL_01c2: ldstr "bmid"
IL_01c7: callvirt instance object [System.Data]System.Data.DataRow::get_Item(string)
IL_01cc: callvirt instance string [mscorlib]System.Object::ToString()
IL_01d1: call int32 [mscorlib]System.Int32::Parse(string)
IL_01d6: stsfld int32 yywlxt.conn.UInf::_bmid
IL_01db: ldloc.2
IL_01dc: callvirt instance class [System.Data]System.Data.DataRowCollection [System.Data]System.Data.DataTable::get_Rows()
IL_01e1: ldc.i4.0
IL_01e2: callvirt instance class [System.Data]System.Data.DataRow [System.Data]System.Data.DataRowCollection::get_Item(int32)
IL_01e7: ldstr "bmdm"
IL_01ec: callvirt instance object [System.Data]System.Data.DataRow::get_Item(string)
IL_01f1: callvirt instance string [mscorlib]System.Object::ToString()
IL_01f6: stsfld string yywlxt.conn.UInf::_bmdm
IL_01fb: ldloc.2
IL_01fc: callvirt instance class [System.Data]System.Data.DataRowCollection [System.Data]System.Data.DataTable::get_Rows()
IL_0201: ldc.i4.0
IL_0202: callvirt instance class [System.Data]System.Data.DataRow [System.Data]System.Data.DataRowCollection::get_Item(int32)
IL_0207: ldstr "bmmc"
IL_020c: callvirt instance object [System.Data]System.Data.DataRow::get_Item(string)
IL_0211: callvirt instance string [mscorlib]System.Object::ToString()
IL_0216: stsfld string yywlxt.conn.UInf::_bmmc
IL_021b: ldc.i4.1
IL_021c: stsfld int32 yywlxt.conn.UInf::dlbz
IL_0221: ldc.i4.1
IL_0222: stloc.0
IL_0223: nop
IL_0224: ldloc.0
IL_0225: stloc.3
IL_0226: br.s IL_0228 IL_0228: ldloc.3
IL_0229: ret
} // end of method LoginForm::yhdljc
将上面的代码改成如下:
.method public hidebysig instance bool
yhdljc() cil managed
{
// 代码大小 7 (0x7)
.maxstack 1
.locals init ([0] bool CS$1$0000)
IL_0000: nop
IL_0001: ldc.i4.1
IL_0002: stloc.0
IL_0003: br.s IL_0005 IL_0005: ldloc.0
IL_0006: ret
} // end of method LoginForm::yhdljc
上面函数里的汇编代码对应:return true;
改过后,相当于原yhdljc()函数改成了总返回true的新函数:
public bool yhdljc()
{
return true;
}
6.3、编辑反汇编后的.il文件,生成新的exe执行程序,现在直接点“登录”就能进系统了。
用ildasm和ilasm对.net下的exe程序进行破解初探的更多相关文章
- Windows 下 把EXE 程序变成服务运行
1. 下载 instsrv.exe 和 srvany.exe 我下载的地址 [点击打开链接][https://www.cr173.com/soft/64394.html] 2. cmd cd ...
- 反编译.net下的exe程序
1. 什么叫.net平台 .NET框架是一个多语言组件开发和执行环境,它提供了一个跨语言的统一编程环境..NET框架的目的是便于开发人员更容易地建立Web应用程序和Web服务,使得Internet上的 ...
- WIn7系统下 打开.exe程序出现已停止工作关闭程序之解决办法
新装WIN7系统出现 .NET组建没有安装 可到官网下载安装 NETFx4.0 运行MVB 上位机SIM.EXE出现应用程序已停止工作问题 解决办法: 需关闭WIN7 DEP 如下 开始-运行( ...
- Qt ------ window下工程项目打包成一个exe程序
最近,在学习QT5的过程中,想尝试着把自己写的工程程序给打包发布出来,在任何一台windows系统都能运行,这样就不会限于电脑需不需要安装QT安装包了. 首先,先介绍自己使用的环境.我使用的QT版本是 ...
- VB.net 2010下关联与程序图标设置
'*************************************************************************'**模 块 名:VB.net 2010下关联与程序 ...
- 在linux命令行下执行php 程序
如何在linux命令行下,执行php程序. 例子 打印当前时间 php -r "echo time()" 随机输出一个数字 php -r "echo rand(1,20) ...
- 使用Code::blocks在windows下写网络程序
使用Code::blocks在windows下写网络程序 作者 He YiJun – storysnail<at>gmail.com 团队 ls 版权 转载请保留本声明! 本文档包含的原创 ...
- windows下调用外部exe程序 SHELLEXECUTEINFO
本文主要介绍两种在windows下调用外部exe程序的方法: 1.使用SHELLEXECUTEINFO 和 ShellExecuteEx SHELLEXECUTEINFO 结构体的定义如下: type ...
- linux 下恢复后台程序的方法
一直以为这个东西不怎么重要,所以一直没怎么去记,已经第三次百度了,不想再有第四次. 如果你在终端下运行一个程序,如果这个程序正在运行,我们可以用 ctrl + z 的命令将这个程序挂到后台. desk ...
随机推荐
- Material04 MdCardModule和MdButtonModule综合运用
设计需求:设计一个登陆页面 1 模块导入 1.1 将MdCardModule和MdButtonModule模块导入到共享模块中 import { NgModule } from '@angular/c ...
- hdu4893 Wow! Such Sequence!
线段树结点上保存一个一般的sum值,再同一时候保存一个fbsum,表示这个结点表示的一段数字若为斐波那契数时的和 当进行3操作时,仅仅用将sum = fbsum就可以 其它操作照常进行,仅仅是单点更新 ...
- hdu 5225 Tom and permutation(回溯)
题目链接:hdu 5225 Tom and permutation #include <cstdio> #include <cstring> #include <algo ...
- 第一次面试&第一次霸面
哈哈哈哈,第一次面试和第一次都献给了CVTE! CVTE的招聘流程有点特别:网測-- 一面--笔试--二面--offer 想起网測那天就心酸.那先在做第三部分的专业測试.计时器突然出错........ ...
- 在dotnet core web api中支持CORS(跨域访问)
最近在写的Office add-in开发系列中,其中有一个比较共性的问题就是在add-in的客户端脚本中访问远程服务时,要特别注意跨域访问的问题. 关于CORS的一些基本知识,请参考维基百科的说明:h ...
- 数据库——MySQL——>Java篇
MySQL MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品.MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是 ...
- (转)java中的方法区
首先要说明的是,此文章转载自 http://blog.csdn.net/zzhangxiaoyun/article/details/7518917 谢谢作者.是本人认为对方法区解释得比较清楚的一篇文章 ...
- Java加密与解密笔记(三) 非对称加密
非对称的特点是加密和解密时使用的是不同的钥匙.密钥分为公钥和私钥,用公钥加密的数据只能用私钥进行解密,反之亦然. 另外,密钥还可以用于数字签名.数字签名跟上文说的消息摘要是一个道理,通过一定方法对数据 ...
- mybatis中#和$符号的区别(转)
mybatis做为一个轻量级ORM框架在许多项目中使用,因其简单的入门受到了广大开发者的热爱.在近期项目中再做一个相关的开发,碰到了#.$符号这样的问题,之前没怎么注意过,通过学习之后,有了点感悟,分 ...
- 前端MVC Vue2学习总结(三)——模板语法、过滤器、计算属性、观察者、Class 与 Style 绑定
Vue.js 使用了基于 HTML 的模版语法,允许开发者声明式地将 DOM 绑定至底层 Vue 实例的数据.所有 Vue.js 的模板都是合法的 HTML ,所以能被遵循规范的浏览器和 HTML 解 ...