提升软件安全性 - 运用Inno Setup打包技术实现序列号与机器绑定
企业开发
2023-12-17 14:49:05
阅读次数: 0
背景
- 随着数字化时代的到来,软件已成为日常生活中不可或缺的一部分。无论是企业级应用还是个人用户,都需要通过软件实现各种功能。然而,在这种情况下,软件的安全性变得越来越重要。
- 为了防止未经授权的复制和传播,许多软件开发商选择对他们的产品实施许可证管理策略。这其中的一种常见方法就是使用序列号,只有当用户输入正确的序列号时,才能激活并正常使用该软件。
- 在此背景下,本文将介绍如何使用Inno Setup打包工具,在生成安装包时加入序列号并与用户机器进行绑定。
- inno setup打包入门
意义
- 通过使用Inno Setup将序列号与机器绑定,开发者可以有效防止软件被非法复制或滥用,从而提高软件的安全性和收益。此外,这一方法还能帮助企业更好地跟踪软件的安装情况,以了解产品的实际使用情况并制定合理的市场营销策略。因此,掌握这一技能对于软件开发人员来说具有重要的实践意义。
效果
- 可以看下,不输入序列号或者输入无效序列号,都是无法进行下一步的
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/cd065d04bd1d4117882b73251b2cfc8c.png)
- 只有输入有效的序列号,才能进行下一步,继续安装
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/6e405fea78044e9fbd685fe82662e988.png)
方案说明
方案一
- 直接在打包脚本中写死一个序列号。这样比较简单,也能实现输入注册码才能安装的功能,但缺点也很明显,注册码没有唯一性,只要序列号公布出去,任何人都可以拿到,仍然阻止不了软件的非法复制和滥用。
方案二
- 打包过程中,获取一个唯一性标识,要保证这个标识每一台机器都不一样。
- 在 Windows 注册表这个位置 计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography,有一个MachineGuid项,这个项的值每一个系统都是不一样的,可以作为唯一性标识。
- 然后安装过程中,在安装界面获取这个唯一性标识,让用户把唯一性标识发给我们,我们再对这个标识作摘要计算,计算的结果作为序列号,发送给用户。
- 这样就能保证每一个系统的序列号都是唯一的。但很容易被破解,稍微有点密码学基础的人,就可以看出这个序列号是对唯一性标识作简单摘要得到的,他们完全可以自己计算获取序列号。
方案三
- 在方案二的基础上,拿到用户的唯一性标识后,在后面拼接一段冗余数据,再对拼接完成的数据作摘要计算,计算的结果发送给用户作为序列号。
- 这个冗余数据可以看成是密钥,只要密钥没有泄露,那序列号就无法被破解或者说破解的难度将大大增加。
代码
-
#define MyDebugAppName "TCP调试助手"
#define MyDebAppVersion "1.0.2"
#define tcpDebugPackDateTimeString GetDateTimeString('yyyymmdd','','')
#define serialNumberData GetDateTimeString('yyyy','','')
[setup]
; 安装应用程序的标题
AppName={
#MyDebugAppName}
; 安装应用程序版本号
AppVersion = {
#MyDebAppVersion}
; 默认安装目录
DefaultDirName={
pf}
; 控制面板中显示
CreateUninstallRegKey=yes
; 编译输出文件夹
OutputDir=.\output
; 编译后的安装包文件名
OutputBaseFilename=TcpDebugTools_{
#MyDebAppVersion}_{
#tcpDebugPackDateTimeString}
; 允许安装过程中取消进程
AllowCancelDuringInstall=yes
;卸载程序路径
UninstallFilesDir={
app}\TcpDebugTools
; 不显示开始菜单文档向导页面
DisableProgramGroupPage=yes
; 默认包含卸载程序在安装程序中
Uninstallable=yes
; 设置为no,表示显示欢迎向导页面
DisableWelcomePage=no
SetupIconFile=.\candy.ico
UserInfoPage=yes
[Languages]
Name: "Chinese"; MessagesFile: "compiler:Languages\Chinese.isl"
[Icons]
;创建卸载程序
Name: "{group}\卸载"; Filename: "{app}\TcpDebugTools\unins000.exe"
;创建桌面图标
Name: {
commondesktop}\{
#MyDebugAppName}; Filename: "{app}\TcpDebugTools\networkDebugTools.exe"; WorkingDir: "{app}\TcpDebugTools"; IconFilename:"{app}\TcpDebugTools\image\logo.ico"
[Files]
Source: "..\bin\Release\*"; DestDir: "{app}\TcpDebugTools"
Source: "..\bin\Release\image\*"; DestDir: "{app}\TcpDebugTools\image"
Source: "..\bin\Release\platforms\*"; DestDir: "{app}\TcpDebugTools\platforms"
Source: "..\bin\Release\config\*"; DestDir: "{app}\TcpDebugTools\config"
[code]
procedure InitializeWizard();
begin
WizardForm.WelcomeLabel1.Caption:= '欢迎使用 TCP调试助手';
WizardForm.WelcomeLabel2.Caption:= '版本 {#MyDebAppVersion}';
WizardForm.USERINFOSERIALLABEL.top := WizardForm.USERINFOORGLABEL.top+2*(WizardForm.USERINFOORGLABEL.top - WizardForm.USERINFONAMELABEL.top);
WizardForm.USERINFOSERIALEDIT.top := WizardForm.USERINFOORGEDIT.top+2*(WizardForm.USERINFOORGEDIT.top - WizardForm.USERINFONAMEEDIT.top);
WizardForm.USERINFOSERIALLABEL.Font.Color := clblack;
end;
function InitializeSetup(): Boolean;
var strCmdKill: String;
var ErrorCode: Integer;
begin
strCmdKill := Format('/c taskkill /f /t /im networkDebugTools.exe', []);
ShellExec('open', ExpandConstant('{cmd}'), strCmdKill, '', SW_HIDE, ewNoWait, ErrorCode);
Result := true;
end;
function getMachineGuid(): String;
var strMachineGUID: String;
begin
if RegValueExists(HKLM64, 'SOFTWARE\Microsoft\Cryptography', 'MachineGuid') then
begin
RegQueryStringValue(HKLM64, 'SOFTWARE\Microsoft\Cryptography', 'MachineGuid', strMachineGUID)
end
else
begin
strMachineGUID := '{#serialNumberData}'
end;
Result := strMachineGUID;
end;
function CheckSerial(Serial: String): Boolean;
var strMachineGUID: String;
var serialNumber: String;
var serialNumberEncrypt: String;
var encryptKey: String;
begin
encryptKey := '20240101';
serialNumber := getMachineGuid() + encryptKey;
serialNumberEncrypt := GetMD5OfString(serialNumber);
if Serial = serialNumberEncrypt then
Result := True;
end;
procedure curpagechanged(curpage: integer);
var IDLabel, RegAdr : TLabel;
IDEdit: TEdit;
RefDisk: String;
begin
IDLabel:= TLabel.Create(WizardForm);
IDLabel.parent:= WizardForm.USERINFONAMELABEL.parent;
IDLabel.top:= WizardForm.USERINFONAMELABEL.top+2*(WizardForm.USERINFOORGLABEL.top - WizardForm.USERINFONAMELABEL.top);
IDLabel.left:= WizardForm.USERINFOSERIALLABEL.left;
IDLabel.autosize:= true;
IDLabel.font.color:= clblack;
IDLabel.caption:= '机器码:';
RegAdr:= TLabel.Create(WizardForm);
RegAdr.parent:= WizardForm.USERINFONAMELABEL.parent;
RegAdr.top:= WizardForm.USERINFOSERIALLABEL.top+(WizardForm.USERINFOORGLABEL.top - WizardForm.USERINFONAMELABEL.top) - 7;
RegAdr.left:= WizardForm.USERINFOSERIALLABEL.left + 195;
RegAdr.autosize:= true;
RegAdr.caption:= '注册请联系 : https:
IDEdit:= TEdit.Create(WizardForm);
IDEdit.parent:= WizardForm.USERINFONAMEEDIT.parent;
IDEdit.top:= WizardForm.USERINFONAMEEDIT.top+2*(WizardForm.USERINFOORGEDIT.top - WizardForm.USERINFONAMEEDIT.top);
IDEdit.left:= WizardForm.USERINFOSERIALEDIT.left;
IDEdit.width:= WizardForm.USERINFOSERIALEDIT.width;
IDEdit.readonly:= true;
IDEdit.text := getMachineGuid();
end;
[UninstallRun]
; 卸载前杀掉进程
Filename: taskkill;Parameters:"/t /f /im networkDebugTools.exe";Flags: runhidden
[UninstallDelete]
; 卸载后删除安装目录下所有文件
Type: filesandordirs; Name: "{app}\TcpDebugTools"
转载自blog.csdn.net/new9232/article/details/134981415