Unity3d 反編譯破解遊戲 簡單樣本 (使用ildasm反編譯DLL修改然後重新編譯DLL)

來源:互聯網
上載者:User

標籤:unity3d   破解   反編譯   安全   彙編   

因為這幾天碰到一個Unity的Bug,不得不去反編譯DLL看看C#代碼的產生中介軟體代碼。這也用到了一些反編譯以及重新編譯DLL的一些知識,意味到Unity是如此的不安全。


首先我們建立一個工程,建立一個指令碼,寫一句很簡單的代碼:

using UnityEngine;using System.Collections;public class crack1 : MonoBehaviour {// Use this for initializationvoid Start () {Debug.Log("123");}// Update is called once per framevoid Update () {}}

代碼邏輯就是輸出一個字串 "123" ,這次的目的就是修改掉 這個字串,改成其它的。

好了。先運行一下,讓Unity把代碼編譯成DLL。



很好,輸出了代碼中的字串 123 。

然後停掉遊戲。我們來修改Unity 產生的DLL。


Unity產生的DLL儲存在

\Library\ScriptAssemblies\Assembly-CSharp.dll

打包之後儲存在Data/Manager 檔案夾。


下面開始反編譯&&破解&&重新編譯


反編譯DLL

在開始菜單找到Visual Studio,然後在子目錄找到 開發人員命令提示 ,如:


然後切換目錄到 Unity 產生的 DLL 檔案夾

輸入命令:

cd C:\Users\Administrator\Documents\Crack\Library\ScriptAssemblies

如:



然後輸入以下命令來反編譯 DLL 為 il 檔案:

ildasm Assembly-CSharp.dll /output:Assembly-CSharp.il

如:


然後在我們的檔案夾中可以看到產生的 il  檔案和 res 檔案


OK,下面開始我們的破解步驟


破解

用文字編輯器開啟產生的 il 檔案 Assembly-CSharp.il

內容如下:

//  Microsoft (R) .NET Framework IL Disassembler.  Version 4.0.30319.33440// Metadata version: v2.0.50727.assembly extern UnityEngine{  .ver 0:0:0:0}.assembly extern mscorlib{  .publickeytoken = (7C EC 85 D7 BE A7 79 8E )                         // |.....y.  .ver 2:0:5:0}.assembly 'Assembly-CSharp'{  .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                                                                                                             63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 )       // ceptionThrows.  .hash algorithm 0x00008004  .ver 0:0:0:0}.module 'Assembly-CSharp.dll'// MVID: {7D0848C2-160C-47E9-84F0-C61E5C59B615}.imagebase 0x00400000.file alignment 0x00000200.stackreserve 0x00100000.subsystem 0x0003       // WINDOWS_CUI.corflags 0x00000001    //  ILONLY// Image base: 0x00220000// =============== CLASS MEMBERS DECLARATION ===================.class public auto ansi beforefieldinit crack1       extends [UnityEngine]UnityEngine.MonoBehaviour{  .method public hidebysig specialname rtspecialname           instance void  .ctor() cil managed  {    // 代碼大小       7 (0x7)    .maxstack  8    IL_0000:  ldarg.0    IL_0001:  call       instance void [UnityEngine]UnityEngine.MonoBehaviour::.ctor()    IL_0006:  ret  } // end of method crack1::.ctor  .method private hidebysig instance void           Start() cil managed  {    // 代碼大小       11 (0xb)    .maxstack  8    IL_0000:  ldstr      "123"    IL_0005:  call       void [UnityEngine]UnityEngine.Debug::Log(object)    IL_000a:  ret  } // end of method crack1::Start  .method private hidebysig instance void           Update() cil managed  {    // 代碼大小       1 (0x1)    .maxstack  8    IL_0000:  ret  } // end of method crack1::Update} // end of class crack1// =============================================================// *********** 反組譯碼完成 ***********************// 警告: 建立了 Win32 資源檔 Assembly-CSharp.res

如果代碼很多而產生的這個 il 檔案太大,可以直接搜尋 類名 然後再到類裡面尋找 函數名

我們看到 Start() 函數


il 代碼還是具有一定可讀性,就算不寫上注釋大家也能把意思猜的一半,這段代碼的 大意就是引用一個字串,然後調用方法去輸出。


那麼我們的目的就是修改 代碼中指定的字串 123 ,修改為其它的,這裡就修改為 "you have been cracked!"。

直接修改 。如


重新編譯為DLL

儲存下上面的修改,然後繼續在 控制台中執行以下命令

ilasm /dll /res:Assembly-CSharp.res Assembly-CSharp.il /out:Assembly-CSharp.dll

編譯DLL成功,會覆蓋掉原來的 DLL。可以通過DLL的修改時間來判斷。


再次運行 遊戲,查看輸出的Log,發現已經被修改了。


更多關於IL 指令的介紹:

http://blog.csdn.net/huutu/article/details/46573435

http://blog.csdn.net/huutu/article/details/46573417


Unity3d 反編譯破解遊戲 簡單樣本 (使用ildasm反編譯DLL修改然後重新編譯DLL)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.