软件加license的一种实现方法
2024-08-29 16:53:06
以前从没干过破解的勾当,这次确实必须要去破解一个,于是下了个反编译工具。 最终拿到反编译出来的文件,欣赏了一把它的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))
{
Encoding uTF8 = Encoding.UTF8;
DateTime dateTime = DateTime.Now.AddDays();
byte[] bytes = uTF8.GetBytes(dateTime.Ticks.ToString());
isolatedStorageFileStream.Write(bytes, , (int)bytes.Length);
}
else
{
byte[] bytes = new byte[checked(storageLength)];
int bytesRead = isolatedStorageFileStream.Read(bytes, , (int)bytes.Length);
DateTime expiryDateTime = new DateTime(long.Parse(Encoding.UTF8.GetString(bytes, , 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 文件。
最新文章
- nodejs开发指南demo
- 一起买beta版PHP单元测试
- Swift 玩转 3D Touch 之 Peek &; Pop
- Java中的内存分配机制
- 创建ubuntu软件源
- XE5 Android 开发数据访问手机端 解决乱码的办法
- 【转】Android自定义Adapter的ListView的思路及代码
- 在纯C工程的main函数之前跑代码(手工找到程序入口点, 替换为我们自己的函数)
- Android Studio Gradle 添加.so 支持文件
- J Dp
- 零基础入门学习UI设计指南
- 学点Groovy来理解build.gradle代码
- CentOS安装配置MySql数据库
- python作用域与命名空间
- Seattle Traffic construction projects punlication
- 第一章 Java程序设计概述
- 洛谷P1848 书架
- [sqoop] sqoop2 使用
- java学习之路--多线程实现的方法
- 剑指offer-顺时针打印矩阵-二维数组