?? onguard.pas
字號:
{*********************************************************}
{* ONGUARD.PAS 1.13 *}
{* Copyright (c) 1996-02 TurboPower Software Co *}
{* All rights reserved. *}
{*********************************************************}
{$I ONGUARD.INC}
{$B-} {Complete Boolean Evaluation}
{$I+} {Input/Output-Checking}
{$P+} {Open Parameters}
{$T-} {Typed @ Operator}
{$W-} {Windows Stack Frame}
{$X+} {Extended Syntax}
{$IFNDEF Win32}
{$G+} {286 Instructions}
{$N+} {Numeric Coprocessor}
{$C MOVEABLE,DEMANDLOAD,DISCARDABLE}
{$ELSE}
{$J+} {Assignable Typed Constants} {!!.11}
{$ENDIF}
unit OnGuard;
{-code and key classes and routines}
interface
uses
{$IFDEF Win32} Windows, {$ELSE} WinTypes, WinProcs, {$ENDIF}
Classes, Controls, SysUtils,
OgConst,
OgUtil;
const
{magic values}
DaysCheckCode = $649B;
DateCheckCode = $A4CB;
NetCheckCode = $9341;
RegCheckCode = $D9F6;
SerialCheckCode = $3C69;
UsageCheckCode = $F3D5;
SpecialCheckCode = $9C5B;
type
{code tyes}
PCode = ^TCode;
TCode = packed record
CheckValue : Word; {magic value}
Expiration : Word; {expiration date or 0, if none}
case Byte of
0 : (FirstDate : Word; {for date code}
EndDate : Word);
1 : (Days : Word; {for days code}
LastAccess : Word);
2 : (RegString : LongInt); {for reg code}
3 : (SerialNumber : LongInt); {for serial number code}
4 : (UsageCount : Word; {for usage count code} {!!.02}
LastChange : Word); {!!.02}
5 : (Value : LongInt); {for specail codes}
6 : (NetIndex : LongInt); {for net codes}
end;
type
TCodeType = (ctDate, ctDays, ctRegistration, ctSerialNumber,
ctUsage, ctNetwork, ctSpecial, ctUnknown);
{order must match tab order for code generation notebook}
type
TKey = array [0..15] of Byte;
TKeyType = (ktRandom, ktMessageDigest, ktMessageDigestCS);
{order must match order for key generation combobox string list}
type
{contexts}
TTMDContext = array [0..279] of Byte;
TMD5Context = array [0..87] of Byte;
TMD5Digest = array [0..15] of Byte;
{bit mixing types}
T128Bit = array [0..3] of LongInt;
T256Bit = array [0..7] of LongInt;
const
DefCodeType = ctDate;
DefKeyType = ktRandom;
type
TEsMachineInfoSet = {!!.05}
set of (midUser, midSystem, midNetwork, midDrives); {!!.05}
type
{result of code verification}
TCodeStatus = (ogValidCode, {code is valid but may still be expired}
ogInvalidCode, {code is invalid}
ogPastEndDate, {end date has been reached}
ogDayCountUsed, {number of days authorized have been used}
ogRunCountUsed, {number of runs authorized have been used}
ogNetCountUsed, {number of authorized users has been exceeded}
ogCodeExpired); {expiration date has been reached}
type
EOnGuardException = class(Exception);
type
TChangeCodeEvent =
procedure(Sender : TObject; Code : TCode)
of object;
TCheckedCodeEvent =
procedure(Sender : TObject; Status : TCodeStatus)
of object;
TGetCodeEvent =
procedure(Sender : TObject; var Code : TCode)
of object;
TGetKeyEvent =
procedure(Sender : TObject; var Key : TKey)
of object;
TGetModifierEvent =
procedure(Sender : TObject; var Value : LongInt)
of object;
TGetRegStringEvent =
procedure(Sender : TObject; var Value : string)
of object;
{base regisration code component}
TOgCodeBase = class(TComponent)
protected {private}
{property variables}
FAutoCheck : Boolean; {true to test code when loaded}
FCode : TCode; {release code}
FModifier : LongInt; {key modifier}
FStoreCode : Boolean; {true to store release code on stream}
FStoreModifier : Boolean; {true to store key modifier on stream}
{event variables}
FOnChecked : TCheckedCodeEvent;{called after auto check is made}
FOnGetCode : TGetCodeEvent; {called to retrieve release code}
FOnGetKey : TGetKeyEvent; {called to retrieve key}
FOnGetModifier : TGetModifierEvent;{called to retrieve key modifier}
{property methods}
function GetCode : string;
function GetModifier : string;
function GetAbout : string; {!!.08}
procedure SetCode(const Value : string);
procedure SetModifier(const Value : string);
procedure SetAbout(const Value : string); {!!.08}
protected
procedure Loaded;
override;
procedure DoOnChecked(Value : TCodeStatus);
dynamic;
function DoOnGetCode : TCode;
dynamic;
procedure DoOnGetKey(var Key : TKey);
dynamic;
function DoOnGetModifier : LongInt;
dynamic;
{protected properties}
property Code : string
read GetCode
write SetCode;
property StoreCode : Boolean
read FStoreCode
write FStoreCode;
public
constructor Create(AOwner : TComponent);
override;
function CheckCode(Report : Boolean) : TCodeStatus;
virtual; abstract;
function IsCodeValid : Boolean;
{-return true if code is valid}
published
{properties}
property AutoCheck : Boolean
read FAutoCheck
write FAutoCheck
default DefAutoCheck;
property Modifier : string
read GetModifier
write SetModifier
stored FStoreModifier;
property StoreModifier : Boolean
read FStoreModifier
write FStoreModifier
default DefStoreModifier;
property About : string {!!.08}
read GetAbout {!!.08}
write SetAbout {!!.08}
stored False;
{events}
property OnChecked : TCheckedCodeEvent
read FOnChecked
write FOnChecked;
property OnGetKey : TGetKeyEvent
read FOnGetKey
write FOnGetKey;
property OnGetCode : TGetCodeEvent
read FOnGetCode
write FOnGetCode;
property OnGetModifier : TGetModifierEvent
read FOnGetModifier
write FOnGetModifier;
end;
TOgMakeCodes = class(TComponent)
protected {private}
{property variables}
FCode : TCode;
FCodeType : TCodeType;
FKey : TKey;
FKeyFileName : string;
FKeyType : TKeyType;
FShowHints : Boolean;
{property methods}
function GetAbout : string; {!!.08}
procedure SetAbout(const Value : string); {!!.08}
public
constructor Create(AOwner : TComponent);
override;
function Execute : Boolean;
procedure GetCode(var Value : TCode); {!!.08}
procedure SetCode(Value : TCode); {!!.08}
procedure GetKey(var Value : TKey); {!!.08}
procedure SetKey(Value : TKey); {!!.08}
property KeyType : TKeyType
read FKeyType
write FKeyType;
published
{properties}
property CodeType : TCodeType
read FCodeType
write FCodeType
default DefCodeType;
property KeyFileName : string
read FKeyFileName
write FKeyFileName;
property ShowHints : Boolean
read FShowHints
write FShowHints
default False;
property About : string {!!.08}
read GetAbout {!!.08}
write SetAbout {!!.08}
stored False;
end;
type
TOgMakeKeys = class(TComponent)
protected {private}
{property variables}
FKeyFileName : string;
FKey : TKey;
FKeyType : TKeyType;
FShowHints : Boolean;
{property methods}
function GetAbout : string; {!!.08}
procedure SetAbout(const Value : string); {!!.08}
public
constructor Create(AOwner : TComponent);
override;
function Execute : Boolean;
procedure ApplyModifierToKey(Modifier : LongInt; var Key; KeySize : Cardinal);
{-signs the key with the modifier}
function GenerateDateModifier(D : TDateTime) : LongInt;
{-returns a modifier based on the current date}
function GenerateMachineModifier : LongInt;
{-returns a modifier based on hardware information}
procedure GenerateMDKey(var Key; KeySize : Cardinal; const Str : string);
{-generate a key based on the message digest of Str}
procedure GenerateRandomKey(var Key; KeySize : Cardinal);
{-generate a random key}
function GenerateStringModifier(const S : string) : LongInt;
{-returns a modifier based on S}
function GenerateUniqueModifier : LongInt;
{-returns a unique/random modifier}
procedure SetKey(Value : TKey); {!!.08}
procedure GetKey(var Value : TKey); {!!.08}
published
{properties}
property About : string {!!.08}
read GetAbout {!!.08}
write SetAbout {!!.08}
stored False;
property KeyFileName : string
read FKeyFileName
write FKeyFileName;
property KeyType : TKeyType
read FKeyType
write FKeyType
default DefKeyType;
property ShowHints : Boolean
read FShowHints
write FShowHints
default False;
end;
TOgDateCode = class(TOgCodeBase)
public
function CheckCode(Report : Boolean) : TCodeStatus;
override;
function GetValue : TDateTime;
{-return expiration date (0 for error)}
published
{properties}
property Code
stored FStoreCode;
property StoreCode
default DefStoreCode;
end;
TOgDaysCode = class(TOgCodeBase)
protected {private}
{property variables}
FAutoDecrease : Boolean;
{event variables}
FOnChangeCode : TChangeCodeEvent;
protected
procedure Loaded;
override;
procedure DoOnChangeCode(Value : TCode);
dynamic;
public
constructor Create(AOwner : TComponent);
override;
function CheckCode(Report : Boolean) : TCodeStatus;
override;
procedure Decrease;
{-reduce days and generate modified code}
function GetValue : LongInt;
{-return number of days remaining}
published
{properties}
property AutoDecrease : Boolean
read FAutoDecrease
write FAutoDecrease
default DefAutoDecrease;
{events}
property OnChangeCode : TChangeCodeEvent
read FOnChangeCode
write FOnChangeCode;
end;
TOgRegistrationCode = class(TOgCodeBase)
protected {private}
{property variables}
FRegString : string;
FStoreRegString : Boolean;
{event variables}
FOnGetRegString : TGetRegStringEvent;
protected
function DoOnGetRegString : string;
dynamic;
public
constructor Create(AOwner : TComponent);
override;
function CheckCode(Report : Boolean) : TCodeStatus;
override;
published
{properties}
property Code
stored FStoreCode;
property StoreCode
default DefStoreCode;
property RegString : string
read FRegString
write FRegString
stored FStoreRegString;
property StoreRegString : Boolean
read FStoreRegString
write FStoreRegString
default DefStoreRegString;
{events}
property OnGetRegString : TGetRegStringEvent
read FOnGetRegString
write FOnGetRegString;
end;
TOgSerialNumberCode = class(TOgCodeBase)
public
function CheckCode(Report : Boolean) : TCodeStatus;
override;
function GetValue : LongInt;
{-return serial number (0 for error)}
published
{properties}
property Code
stored FStoreCode;
property StoreCode
default DefStoreCode;
end;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -