📄 judgesn.dpr
字号:
library JudgeSN;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
ShareMem,
SysUtils,
Classes,
Registry,windows,Forms;
{$R *.res}
CONST B36 : PChar = ('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ');
function IntToBase(iValue: integer; Base: byte; Digits: byte): string;
begin //base 进制数
result := '';
repeat
result := B36[iValue MOD BASE]+result;
iValue := iValue DIV Base;
until (iValue DIV Base = 0);
result := B36[iValue MOD BASE]+result;
while length(Result) < Digits do
Result := '0' + Result;
end;
function BaseToint(iValue: String; Base: byte): integer;
var
i: byte;
begin
result := 0;
for i := 1 to length(iValue) do begin
if (pos(iValue[i], B36)-1) < Base then
result := result * Base + (pos(iValue[i], B36)-1)
else begin
result := 0;
break;
end;
end;
end;
function ReadANDCompare_RegistryInfo(PermissionTimes:Integer):string;stdcall; //读取注册表和INI文件并比较数据
var
reg_SysValue : TRegistry;
VS_1,VS_2,VS_3,VS_4 : STRING;
VS_G1,VS_G2,VS_G3,VS_G4 :string;
//以下为INI文件所需
F : TextFile;
s_FileName : string;
c_FilePath :Array[0..128] of char;
c_FileFull : Array[0..128] of char;
begin
//1 读取注册表 无信息->写入第一次信息
// 有信息->读出->保存到变量A
//2、读取INI文件 无信息->写入第一次信息->退出
// 有信息->读出->保存到变量B
//变量A和B比较,不相同->退出
// 相同->是已经注册->继续
// 相同->未注册但次数满->退出
// 未注册 ->是否到使用次数->否 ->增加次数->写入注册表和INI
// 是 ->退出->写入注册表和INI
//0、读取注册表
reg_SysValue := TRegistry.Create;
reg_SysValue.RootKey:=HKEY_lOCAL_MACHINE;
try
IF reg_SysValue.OpenKey('SOFTWARE\MICROSOFT\SYSTEN',FALSE) THEN
BEGIN //有注册值 ->>>开始判断是否正确
vs_1 := reg_SysValue.ReadString('SysVal1');
vs_2 := reg_SysValue.ReadString('SysVal2');
reg_SysValue.CloseKey;
END
ELSE BEGIN //当前没有注册值,要写入第一次的值
reg_SysValue.OpenKey('SOFTWARE\MICROSOFT\SYSTEN',True);
reg_SysValue.WriteString('SysVal1',inttobase(987654325,2,1));
reg_SysValue.WriteString('Sysval2',inttobase((1 shl 2)+1,20,1));
reg_SysValue.CloseKey;
END;
except
Application.MessageBox('注册信息出错误!ErrorID:E001','错误',mb_iconError+mb_OK);
Application.Terminate;
end;
//1.读取ini文件
try
GetSystemDirectory(c_FilePath,Sizeof(c_FilePath));
s_fileName :=strpas(c_FilePath)+'\Systen.ini';
if FileExists(s_fileName) then //文件存在读取数据
begin
AssignFile(F,s_FileName);
Reset(F);
Readln(F,vs_3);
Readln(F,vs_4);
closefile(F);
end
else begin //文件不存在写入第一次数据
AssignFile(F,s_FileName);
Rewrite(F);
Writeln(F,inttobase(1234567895,2,1));
Writeln(F,inttobase((1 shl 2)+1,20,1));
CloseFile(F);
exit;
end;
except
Application.MessageBox('注册信息出错误!ErrorID:E002','错误',mb_iconError+mb_OK);
Application.Terminate;
end;
//2、比较读出的信息
vs_1 :=trim(vs_1);
vs_2 :=trim(vs_2);
vs_3 :=trim(vs_3);
vs_4 :=trim(vs_4);
if (vs_1='') or (vs_2='') or (vs_3='') or (vs_4='') then //读出的注册信息出错
begin
Application.MessageBox('注册信息出错误!ErrorID:E003','错误',mb_iconError+mb_OK);
Application.Terminate;
end
else begin
//2.1 判断获取的信息
// 是否已经注册
VS_G1 := inttobase(987654326,2,1); //以下四句获取正确的已经注册信息
VS_G2 := inttobase(99,8,1);
VS_G3 := inttobase(1234567896,2,1);
VS_G4 := inttobase(99,5,1);
if (vs_1=vs_g1) and (vs_2=vs_g2) and (vs_3=vs_g3) and (vs_4=vs_g4) then //核对正确,已经正确注册,不做其它处理,程序正常运行
begin
Result :='1';
exit;
end;
//核对未注册信息
VS_G1 := inttobase(987654325,2,1); //以下两句获得正确的未注册信息"头"
VS_G3 := inttobase(1234567895,2,1);
if (vs_1=vs_3) or (vs_2<>vs_4) then //正确的未注册信息应满足所列条件
begin
Application.MessageBox('注册信息出错误!ErrorID:E005','错误',mb_iconError+mb_OK); //已经受到人为修改
Result :='0';
Application.Terminate;
end
else begin
if (vs_g1<>vs_1) or (vs_g3<>vs_3) then
begin
Application.MessageBox('注册信息出错误!ErrorID:E006','错误',mb_iconError+mb_OK); //已经受到人为修改
Result :='0';
Application.Terminate;
end;
try
vs_4 := inttostr(basetoint(vs_2,20) shr 2); //将系统记录的次数复原
except
Application.MessageBox('注册信息出错误!ErrorID:E007','错误',mb_iconError+mb_OK); //已经受到人为修改
Result :='0';
Application.Terminate;
end;
if strtoint(vs_4)<1 then
begin
Application.MessageBox('注册信息出错误!ErrorID:E008','错误',mb_iconError+mb_OK); //已经受到人为修改
Result :='0';
Application.Terminate;
end
else if strtoint(vs_4)>PermissionTimes then
begin
Application.MessageBox('该系统没注册,已经到了使用期限!','错误',mb_iconError+mb_OK); //已经受到人为修改
Result :='0';
Application.Terminate;
end
else begin //将次数增加1并写入
vs_4 :=inttostr(strtoint(vs_4)+1);
try
//写入注册表
reg_SysValue.OpenKey('SOFTWARE\MICROSOFT\SYSTEN',False);
reg_SysValue.DeleteValue('Sysval2');
reg_SysValue.WriteString('Sysval2',inttobase((strtoint(vs_4) shl 2)+1,20,1));
reg_SysValue.CloseKey;
//写入INI文件
strpcopy(c_FileFull,s_FileName);
deleteFile(c_FileFull);
AssignFile(F,s_FileName);
Rewrite(F);
Writeln(F,inttobase(1234567895,2,1));
Writeln(F,inttobase((strtoint(vs_4) shl 2)+1,20,1));
CloseFile(F);
except
vs_4 :=inttostr(strtoint(vs_4)-1);
//恢复注册表
reg_SysValue.OpenKey('SOFTWARE\MICROSOFT\SYSTEN',False);
reg_SysValue.DeleteValue('Sysval2');
reg_SysValue.WriteString('Sysval2',inttobase((strtoint(vs_4) shl 2)+1,20,1));
reg_SysValue.CloseKey;
reg_SysValue.Free;
//恢复INI文件
strpcopy(c_FileFull,s_FileName);
deleteFile(c_FileFull);
AssignFile(F,s_FileName);
Rewrite(F);
Writeln(F,inttobase(1234567895,2,1));
Writeln(F,inttobase((strtoint(vs_4) shl 2)+1,20,1));
CloseFile(F);
Application.MessageBox('注册信息出错误!ErrorID:E009!','错误',mb_iconError+mb_OK); //已经受到人为修改
Result :='0';
Application.Terminate;
end;
reg_SysValue.Free;
end;
end;
end;
end;
exports
ReadANDCompare_RegistryInfo;
begin
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -