软件试用 防破解 防软件调试(C# )

[复制链接]
发表于 2025-10-21 05:06:44 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
防破解&防软件调试 实现思绪

这里接纳C#语言为例:
      
  • 获取网络北京时间:向百度发送 HTTP 哀求,从相应头中提取日期时间信息,将其转换为本地时间。  
  • 记载试用开始时间:初次运行软件时,将获取的百度北京时间作为试用开始时间,并加密存储在本地文件中。  
  • 查抄试用是否逾期:每次运行软件时,再次获取百度北京时间,与存储的试用开始时间举行比力,判断试用是否逾期。  
  • 防破解步伐
         
    • 查抄文件是否被窜改:通过盘算文件的哈希值并与之前存储的哈希值举行比力,判断文件是否被修改。   
    • 查抄体系时间是否被窜改:比力当前获取的百度北京时间和体系时间,假如差别过大,则以为体系时间大概被窜改。   
    • 软件代码肴杂和加壳处置处罚。(防破解 这条很紧张,这条做不好,其他都是徒劳)。   
    • 防软件调试。   
      

  1. using System;
  2. using System.IO;
  3. using System.Net;
  4. using System.Security.Cryptography;
  5. using System.Runtime.Serialization.Formatters.Binary;
  6. class Program
  7. {
  8.     private static readonly string trialInfoFilePath = "trialInfo.dat";
  9.     private static readonly string hashFilePath = "hash.dat";
  10.     static void Main()
  11.     {
  12.         // 获取百度北京时间
  13.         DateTime beijingTime = GetBeijingTimeFromBaidu();
  14.         if (IsSystemTimeTampered(beijingTime))
  15.         {
  16.             Console.WriteLine("检测到系统时间被篡改,软件无法正常使用。");
  17.             return;
  18.         }
  19.         if (IsTrialExpired(beijingTime))
  20.         {
  21.             Console.WriteLine("试用已到期,请购买正式版本。");
  22.         }
  23.         else
  24.         {
  25.             Console.WriteLine("当前北京时间:" + beijingTime);
  26.             Console.WriteLine("软件仍在试用期限内。");
  27.         }
  28.         Console.ReadLine();
  29.     }
  30.     // 从百度获取北京时间
  31.     private static DateTime GetBeijingTimeFromBaidu()
  32.     {
  33.         try
  34.         {
  35.             HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.baidu.com");
  36.             request.Method = "HEAD";
  37.             using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  38.             {
  39.                 string dateHeader = response.GetResponseHeader("Date");
  40.                 return DateTime.ParseExact(dateHeader, "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeUniversal | System.Globalization.DateTimeStyles.AdjustToUniversal).ToLocalTime();
  41.             }
  42.         }
  43.         catch (Exception ex)
  44.         {
  45.             Console.WriteLine($"获取北京时间时出错:{ex.Message},将使用本地时间。");
  46.             return DateTime.Now;
  47.         }
  48.     }
  49.     // 检查系统时间是否被篡改
  50.     private static bool IsSystemTimeTampered(DateTime beijingTime)
  51.     {
  52.         TimeSpan difference = beijingTime - DateTime.Now;
  53.         return Math.Abs(difference.TotalHours) > 1; // 允许 1 小时的误差
  54.     }
  55.     // 检查试用是否到期
  56.     private static bool IsTrialExpired(DateTime currentTime)
  57.     {
  58.         DateTime startTrialTime;
  59.         if (File.Exists(trialInfoFilePath))
  60.         {
  61.             if (IsFileTampered(trialInfoFilePath))
  62.             {
  63.                 Console.WriteLine("检测到试用信息文件被篡改,软件无法正常使用。");
  64.                 return true;
  65.             }
  66.             using (FileStream fs = new FileStream(trialInfoFilePath, FileMode.Open))
  67.             {
  68.                 BinaryFormatter formatter = new BinaryFormatter();
  69.                 startTrialTime = (DateTime)formatter.Deserialize(fs);
  70.             }
  71.         }
  72.         else
  73.         {
  74.             // 首次运行,记录开始试用时间
  75.             startTrialTime = currentTime;
  76.             using (FileStream fs = new FileStream(trialInfoFilePath, FileMode.Create))
  77.             {
  78.                 BinaryFormatter formatter = new BinaryFormatter();
  79.                 formatter.Serialize(fs, startTrialTime);
  80.             }
  81.             SaveFileHash(trialInfoFilePath);
  82.         }
  83.         // 计算试用天数
  84.         int trialDays = (currentTime - startTrialTime).Days;
  85.         return trialDays >= 15;
  86.     }
  87.     // 检查文件是否被篡改
  88.     private static bool IsFileTampered(string filePath)
  89.     {
  90.         if (!File.Exists(hashFilePath))
  91.         {
  92.             return true;
  93.         }
  94.         string storedHash = File.ReadAllText(hashFilePath);
  95.         string currentHash = CalculateFileHash(filePath);
  96.         return storedHash != currentHash;
  97.     }
  98.     // 计算文件的哈希值
  99.     private static string Calcu
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
继续阅读请点击广告
回复

使用道具 举报

×
登录参与点评抽奖,加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表