• 软件加license的一种实现方法


    以前从没干过破解的勾当,这次确实必须要去破解一个,于是下了个反编译工具。 最终拿到反编译出来的文件,欣赏了一把它的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 文件。
    
    
    
    
  • 相关阅读:
    通过 ANE(Adobe Native Extension) 启动Andriod服务 推送消息(三)
    通过 ANE(Adobe Native Extension) 启动Andriod服务 推送消息(二)
    stepper组件使用
    解决循环删除list中元素ConcurrentModificationException异常问题
    简单选择排序SelectSort
    用js写出简单的计算器
    在一个项目中,添加.js文件出现错误
    弹出当前值以及修改
    映射:表之间的关联
    置换(用递归的方法执行置换)
  • 原文地址:https://www.cnblogs.com/wusong/p/3339178.html
Copyright © 2020-2023  润新知