以前從沒干過破解的勾當,這次確實必須要去破解一個,於是下了個反編譯工具。 最終拿到反編譯出來的文件,欣賞了一把它的license檢測代碼。原諒我的無知,以下代碼在我看來還是比較新鮮,犬神請不要鄙視:
internal static void CheckLicense() { if (!License.licenseChecked) { try { using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForAssembly()) { using (IsolatedStorageFileStream isolatedStorageFileStream = new IsolatedStorageFileStream("xxx.lic", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite, isolatedStorageFile)) { long storageLength = isolatedStorageFileStream.Length; if (storageLength == (long)0) { Encoding uTF8 = Encoding.UTF8; DateTime dateTime = DateTime.Now.AddDays(30); byte[] bytes = uTF8.GetBytes(dateTime.Ticks.ToString()); isolatedStorageFileStream.Write(bytes, 0, (int)bytes.Length); } else { byte[] bytes = new byte[checked(storageLength)]; int bytesRead = isolatedStorageFileStream.Read(bytes, 0, (int)bytes.Length); DateTime expiryDateTime = new DateTime(long.Parse(Encoding.UTF8.GetString(bytes, 0, bytesRead))); if (DateTime.Now > expiryDateTime) { License.licenseExpired = true; } } } } License.licenseChecked = true; } catch (Exception exception) { } } if (License.licenseExpired) { throw new InvalidOperationException("The trial period has expired. Please contact us at xxx.com for further information."); } }
CheckLicense()方法可以放在代碼中任何地方使用。
基本原理就是在第一次運行時,檢測是否生成了license,並把過期日期算好寫進去,以后每次檢測是否到期。
關鍵類是IsolatedStorageFile 。它創建的文件在文件系統中,不需要特殊路徑,一般權限的托管代碼是不能訪問其他dll文件的IsolatedStorageFile 文件的,高級權限的托管代碼可以訪問其他dll的文件,非托管代碼可以訪問任何IsolatedStorageFile 文件。