| r197 vs r198 | ||
|---|---|---|
| ... | ... | |
| 57 | 57 | 아무리 생각해도 EnableAntiDebugChecks는 오탐지 가능성이 있다. 블랙 리스트에 추가되도록 할지 생각중... |
| 58 | 58 | GZipStream을 이용해서 저장 용량을 50% 줄여보기. |
| 59 | 59 | |
| 60 | === 본 | |
| 60 | === 본코드 === | |
| 61 | 61 | {{{#!syntax csharp |
| 62 | 62 | using System; |
| 63 | 63 | using System.IO; |
| 64 | 64 | using System.Security.Cryptography; |
| 65 | 65 | using System.Text; |
| 66 | 66 | using UnityEngine; |
| 67 | using System.Diagnostics; | |
| 68 | 67 | using System.Runtime.CompilerServices; |
| 69 | 68 | |
| 70 | 69 | [Serializable] |
| ... | ... | |
| 110 | 109 | Instance = this; |
| 111 | 110 | DontDestroyOnLoad(gameObject); |
| 112 | 111 | |
| 113 | sessionNonce = | |
| 112 | sessionNonce = LoadOrCreateSessionNonce(); | |
| 114 | 113 | filePath = Path.Combine(Application.persistentDataPath, ResolveFileName("playerData")); |
| 115 | 114 | Warmup(); |
| 116 | 115 | } |
| 117 | 116 | |
| 117 | private byte[] LoadOrCreateSessionNonce() | |
| 118 | { | |
| 119 | const string key = "SecureManager_SessionNonce_v1"; | |
| 120 | try | |
| 121 | { | |
| 122 | if (PlayerPrefs.HasKey(key)) | |
| 123 | { | |
| 124 | string b64 = PlayerPrefs.GetString(key); | |
| 125 | byte[] stored = Convert.FromBase64String(b64); | |
| 126 | if (stored != null && stored.Length > 0) return stored; | |
| 127 | } | |
| 128 | } | |
| 129 | catch { } | |
| 130 | ||
| 131 | byte[] nonce = GenerateRandomBytes(16); | |
| 132 | try | |
| 133 | { | |
| 134 | PlayerPrefs.SetString(key, Convert.ToBase64String(nonce)); | |
| 135 | PlayerPrefs.Save(); | |
| 136 | } | |
| 137 | catch { } | |
| 138 | return nonce; | |
| 139 | } | |
| 140 | ||
| 118 | 141 | private void Warmup() |
| 119 | 142 | { |
| 120 | 143 | try { _ = GetSecretBytes(); } catch { } |
| ... | ... | |
| 177 | 200 | } |
| 178 | 201 | |
| 179 | 202 | byte[] s1 = DumbMixA(k); |
| 180 | int d | |
| 181 | byte[] s2 = DumbMixB(s1, d | |
| 203 | ||
| 204 | // 시간 의존 제거, 디바이스 기반 결정적 시드 | |
| 205 | int deviceSeed = Application.identifier.GetHashCode() ^ SystemInfo.deviceUniqueIdentifier.GetHashCode(); | |
| 206 | ||
| 207 | byte[] s2 = DumbMixB(s1, deviceSeed); | |
| 182 | 208 | byte[] s3 = DumbMixC(s2, sessionNonce); |
| 183 | 209 | for (int r = 0; r < 2; r++) |
| 184 | 210 | { |
| 185 | 211 | byte[] t = DumbMixA(s3); |
| 186 | byte[] u = DumbMixB(t, d | |
| 212 | byte[] u = DumbMixB(t, deviceSeed ^ r); | |
| 187 | 213 | for (int i = 0; i < k.Length; i++) s3[i] = (byte)(s3[i] ^ u[i % u.Length]); |
| 188 | 214 | Array.Clear(t, 0, t.Length); |
| 189 | 215 | Array.Clear(u, 0, u.Length); |
| 190 | 216 | } |
| 191 | 217 | Array.Clear(s1, 0, s1.Length); |
| 192 | 218 | Array.Clear(s2, 0, s2.Length); |
| 219 | ||
| 193 | 220 | byte[] result = new byte[k.Length]; |
| 194 | 221 | for (int i = 0; i < k.Length; i++) result[i] = (byte)(k[i] ^ s3[i % s3.Length]); |
| 195 | 222 | Array.Clear(k, 0, k.Length); |
| ... | ... | |
| 382 | 409 | { |
| 383 | 410 | if (EnableAntiDebugChecks) |
| 384 | 411 | { |
| 385 | if ( | |
| 386 | if (De | |
| 412 | if (System.Diagnostics.Debugger.IsAttached) return true; | |
| 413 | if (System.Diagnostics.Process.GetCurrentProcess().ProcessName.ToLower().Contains("debug")) return true; | |
| 387 | 414 | } |
| 388 | 415 | } |
| 389 | 416 | catch { } |
| ... | ... | |
| 398 | 425 | catch { } |
| 399 | 426 | return false; |
| 400 | 427 | } |
| 401 | } | |
| 402 | ||
| 428 | } | |
| 429 | }}} | |
| 403 | 430 | === 실행 코드 === |
| 404 | 431 | {{{#!syntax csharp |
| 405 | 432 | using UnityEngine; |
| ... | ... |