跳到主要內容
      打從前陣子就一直在思考怎麼作 source encrypt,看了很多 unity forum 卻總是沒看到實際作法跟可用的方式,standalone 跟 webplayer 似乎都有確切解法了,但 android / ios 一直沒有,總算看到有人使用 Crypto Obfuscator 的案例,在這邊講解一下作法跟設
定。



      上圖是我參考網路資訊作的,有幾點需要注意:
      (1) Test Mode 可以用來作測試用,但實際 Release 版本千萬別用這個。
      (2) 採用 Unprintable Mode,我試過 Cryptographic、Normal 也都可行。
      (3) Encrypt String 不勾選,主要是打亂後會造成很多 Unity call method 問題。
      (4) rename symbol 勾選 For Fields、For Methods。
      (5) 其他就參考上圖吧,也可以自行測試看看,依自己喜好設定。

      在實際測試中發現打亂後執行 apk 預到非預期問題,大多都是 function name 被打亂了,但 regist function name 沒打亂的緣故,所以我們需要設立一些 pass 規則。



      如上圖,在 Obfuscation Rules 中設立了滿多規則,像是 Monobehaviour::Update、LateUpdate、Awake....等都加入規則內;在這邊列出了打亂後會遇到問題的 case 供大家參考:

      1. ScriptableObject      2. Coroutine function name      3. Invoke function name
      4. SendMessage function name
      5. AddComponent             採用 AddComponent<Type>() 而不是 AddComponent("Type")


      有關 Crypto Obfuscator Q & A 中提:

Crypto Obfuscator does not automatically suppress the warning even after you add proper obfuscation rules/attributes for it. You have to 'suppress' that warning explicitly by right-clicking on the warning and selecting the proper menu item from the context menu. You may ask why this is so or why it does not exclude the type/member from renaming in the first place? Because it is impossible to determine, just by doing static analysis of your code, the exact type/member to exclude. It can only detect the use of a potentially dangerous method call or a property get/set. For example, while it can detect the use of the System.Type.Name property, it has no way of knowing on which System.Type instance the Name property is being retrieved - this can only be determined at run-time and the System.Type instance may very well change from run to run.

      主要是說明,Crypto obfuscator 可以幫你偵測到一些立即的危險,像是 Reflection.Get/Set,但程式執行中動態產生或修改的則很難發現。目前會卡在一個問題,也就是目前的版本真的沒問題嗎?其實沒辦法保證,因為必須遊戲執行中剛好跑到錯誤的程式才會造成問題,這是無法保證的,目前有待思考解決方案。

留言

這個網誌中的熱門文章

comfyUI 運行出錯 FATAL: kernel fmha_cutlassF_f32_aligned_64x64_rf_sm80 is for sm80-sm100, but was built for sm37

在公司的圖形機器上運行 ComfyUI + WAN 時出現下面問題   FATAL: kernel fmha_cutlassF_f32_aligned_64x64_rf_sm80 is for sm80-sm100, but was built for sm37 算圖機使用的 torch 版本如下 torch 2.7.1+cu118 torchaudio 2.7.1+cu118 torchsde 0.2.6 torchvision 0.22.1+cu118 檢查 cuda 版本 GeForce RTX 5090 CUDA Version: 13.0 從官網看 RTX 5090 支持 12.0 版本 CUDA 這是因爲本地的 pytorch 版本太舊 到官網查詢版本 https://pytorch.org/get-started/locally/ $ pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cu126 查詢目前版本 $ pip list | findstr torch 使用這個版本后出現下面問題 後面查詢 no kernel image 問題其實還是 pytorch 並不支持 sm_120( Blackwell架構) 查看后發現并沒有支持 sm_120 CUDA architectures : [' sm_37 ', 'sm_50', 'sm_60', 'sm_61', 'sm_70', 'sm_75', 'sm_80', 'sm_86', 'sm_90', 'compute_37'] sm_50, sm_52, sm_53 : Maxwell (GTX 900 系列) sm_60, sm_61, sm_62 : Pascal (GTX 1000, P100) sm_70, sm_72, sm_75 : Volta/Turing (V100, RTX ...
仔細回想最近的作的 stripping level,還是回頭來說說 import dll 這回事吧;因為從事遊戲改版所以很多事情是言不由衷的,某天發現 server 發送給 client 封包是 big5 encode,第一時間覺得為何不用 unicode 呢?但仔細想也許是遊戲剛規劃時 DB 都已經存了 big5 編碼字串可能已經改不動了,想想也是就算了,結果一包到 android 就發生了 GetEncoding error,因為 android 是採用 unicode 編碼的,在網路上找了找終於找到解法,可以參考底下網址的討論串,主要是下載  I18N.dll、I18N.CJK.dll、I18N.West.dll 並丟到 Assets 資料夾下就可以了,當時還不是很了解為什麼只知道把 dll 都丟進去在手機上就可以跑,直到使用 stripping level 後整個又掛了,才認真去 trace, 問題在於勾選 strip asm 包檔後 I18N.CJK 就沒被包到 apk 裡面,而要解決 strip asm(~"~ 沒辦法 strip asm 很吸引我,一定要想辦法克服)採用了 link.xml 的方式,但這樣要怎麼知道弄進哪些 lib 呢?

熟悉 Unity Memory

    打開始跟 app memory 奮戰,摸索了好一陣子,不管是跑在 andorid 還是 Ios,之前做 WebPlayer 的經驗都派不上用場,也好在網路上資源很多,只要不恥繁找就能找到你所想要的,在此分享的主要是 android(ps. ~"~ 手頭上只有兩台 android 設備)。