Unity3d 反编译破解游戏 简单示例 (使用ildasm反编译DLL修改然后重新编译DLL)

来源:互联网 发布:mac安装软件是什么格式 编辑:程序博客网 时间:2024/05/29 10:16

原文 http://blog.csdn.net/huutu/article/details/46573327

因为这几天碰到一个Unity的Bug,不得不去反编译DLL看看C#代码的生成中间件代码。这也用到了一些反编译以及重新编译DLL的一些知识,意味到Unity是如此的不安全。


首先我们新建一个工程,创建一个脚本,写一句很简单的代码:

[csharp] view plain copy
  1. using UnityEngine;  
  2. using System.Collections;  
  3.   
  4. public class crack1 : MonoBehaviour {  
  5.   
  6.     // Use this for initialization  
  7.     void Start () {  
  8.         Debug.Log("123");  
  9.     }  
  10.       
  11.     // Update is called once per frame  
  12.     void Update () {  
  13.       
  14.     }  
  15. }  

代码逻辑就是输出一个字符串 "123" ,这次的目的就是修改掉 这个字符串,改成其它的。

好了。先运行一下,让Unity把代码编译成DLL。



很好,输出了代码中的字符串 123 。

然后停掉游戏。我们来修改Unity 生成的DLL。


Unity生成的DLL存储在

[html] view plain copy
  1. \Library\ScriptAssemblies\Assembly-CSharp.dll  

打包之后存储在Data/Manager 文件夹。


下面开始反编译&&破解&&重新编译


反编译DLL

在开始菜单找到Visual Studio,然后在子目录找到 开发人员命令提示 ,如下图:


然后切换目录到 Unity 生成的 DLL 文件夹

输入命令:

[html] view plain copy
  1. cd C:\Users\Administrator\Documents\Crack\Library\ScriptAssemblies  

如下图:



然后输入以下命令来反编译 DLL 为 il 文件:

[html] view plain copy
  1. ildasm Assembly-CSharp.dll /output:Assembly-CSharp.il  

如下图:


然后在我们的文件夹中可以看到生成的 il  文件和 res 文件


OK,下面开始我们的破解步骤


破解

用文本编辑器打开生成的 il 文件 Assembly-CSharp.il 

内容如下:

[csharp] view plain copy
  1. //  Microsoft (R) .NET Framework IL Disassembler.  Version 4.0.30319.33440  
  2.   
  3.   
  4.   
  5.   
  6. // Metadata version: v2.0.50727  
  7. .assembly extern UnityEngine  
  8. {  
  9.   .ver 0:0:0:0  
  10. }  
  11. .assembly extern mscorlib  
  12. {  
  13.   .publickeytoken = (7C EC 85 D7 BE A7 79 8E )                         // |.....y.  
  14.   .ver 2:0:5:0  
  15. }  
  16. .assembly 'Assembly-CSharp'  
  17. {  
  18.   .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78   // ....T..WrapNonEx  
  19.                                                                                                              63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 )       // ceptionThrows.  
  20.   .hash algorithm 0x00008004  
  21.   .ver 0:0:0:0  
  22. }  
  23. .module 'Assembly-CSharp.dll'  
  24. // MVID: {7D0848C2-160C-47E9-84F0-C61E5C59B615}  
  25. .imagebase 0x00400000  
  26. .file alignment 0x00000200  
  27. .stackreserve 0x00100000  
  28. .subsystem 0x0003       // WINDOWS_CUI  
  29. .corflags 0x00000001    //  ILONLY  
  30. // Image base: 0x00220000  
  31.   
  32.   
  33. // =============== CLASS MEMBERS DECLARATION ===================  
  34.   
  35. .class public auto ansi beforefieldinit crack1  
  36.        extends [UnityEngine]UnityEngine.MonoBehaviour  
  37. {  
  38.   .method public hidebysig specialname rtspecialname   
  39.           instance void  .ctor() cil managed  
  40.   {  
  41.     // 代码大小       7 (0x7)  
  42.     .maxstack  8  
  43.     IL_0000:  ldarg.0  
  44.     IL_0001:  call       instance void [UnityEngine]UnityEngine.MonoBehaviour::.ctor()  
  45.     IL_0006:  ret  
  46.   } // end of method crack1::.ctor  
  47.   
  48.   .method private hidebysig instance void   
  49.           Start() cil managed  
  50.   {  
  51.     // 代码大小       11 (0xb)  
  52.     .maxstack  8  
  53.     IL_0000:  ldstr      "123"  
  54.     IL_0005:  call       void [UnityEngine]UnityEngine.Debug::Log(object)  
  55.     IL_000a:  ret  
  56.   } // end of method crack1::Start  
  57.   
  58.   .method private hidebysig instance void   
  59.           Update() cil managed  
  60.   {  
  61.     // 代码大小       1 (0x1)  
  62.     .maxstack  8  
  63.     IL_0000:  ret  
  64.   } // end of method crack1::Update  
  65.   
  66. // end of class crack1  
  67.   
  68.   
  69. // =============================================================  
  70.   
  71. // *********** 反汇编完成 ***********************  
  72. // 警告: 创建了 Win32 资源文件 Assembly-CSharp.res  

如果代码很多而生成的这个 il 文件太大,可以直接搜索 类名 然后再到类里面查找 函数名

我们看到 Start() 函数


il 代码还是具有一定可读性,就算不写上注释大家也能把意思猜的一半,这段代码的 大意就是引用一个字符串,然后调用方法去输出。


那么我们的目的就是修改 代码中指定的字符串 123 ,修改为其它的,这里就修改为 "you have been cracked!"。

直接修改 。如下图


重新编译为DLL

保存下上面的修改,然后继续在 控制台中执行以下命令

[html] view plain copy
  1. ilasm /dll /res:Assembly-CSharp.res Assembly-CSharp.il /out:Assembly-CSharp.dll  

编译DLL成功,会覆盖掉原来的 DLL。可以通过DLL的修改时间来判断。


再次运行 游戏,查看输出的Log,发现已经被修改了。


更多关于IL 指令的介绍:

[html] view plain copy
  1. http://blog.csdn.net/huutu/article/details/46573435  

[html] view plain copy
  1. http://blog.csdn.net/huutu/article/details/46573417  


0 0
原创粉丝点击