[go: up one dir, main page]

Menu

[r19]: / source / onguard1.pas  Maximize  Restore  History

Download this file

245 lines (213 with data), 7.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
(* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is TurboPower OnGuard
*
* The Initial Developer of the Original Code is
* TurboPower Software
*
* Portions created by the Initial Developer are Copyright (C) 1996-2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** *)
{*********************************************************}
{* ONGUARD1.PAS 1.15 *}
{* Copyright (c) 1996-02 TurboPower Software Co *}
{* All rights reserved. *}
{*********************************************************}
{$I onguard.inc}
unit onguard1;
{-Key generation dialog}
interface
uses
{$IFDEF MSWINDOWS}
Windows, SysUtils, Classes, Controls, Forms, Dialogs, Graphics, Buttons, ExtCtrls, StdCtrls,
{$ENDIF}
{$IFDEF UseOgFMX}
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Objects, FMX.ExtCtrls,
FMX.Memo, FMX.Edit, FMX.Platform, Fmx.StdCtrls, FMX.Header, FMX.Graphics,
FMX.ListBox,
{$ENDIF}
ogutil, onguard;
type
TKeyGenerateFrm = class(TForm)
Panel1: TPanel;
Label2: TLabel;
CopyBlockSb: TSpeedButton;
Label3: TLabel;
Label4: TLabel;
CopyByteKeySb: TSpeedButton;
KeyStringMe: TMemo;
BlockKeyEd: TEdit;
GenerateBtn: TButton;
KeyTypeCb: TComboBox;
ByteKeyEd: TEdit;
CancelBtn: {$IFDEF MSWINDOWS}TBitBtn{$ENDIF}{$IFDEF UseOgFMX}TButton{$ENDIF};
OKBtn: {$IFDEF MSWINDOWS}TBitBtn{$ENDIF}{$IFDEF UseOgFMX}TButton{$ENDIF};
procedure FormCreate(Sender: TObject);
procedure KeyStringMeChange(Sender: TObject);
procedure KeyTypeCbChange(Sender: TObject);
procedure BlockKeyEdChange(Sender: TObject);
procedure CopyBlockSbClick(Sender: TObject);
procedure ByteKeyEdChange(Sender: TObject);
procedure CopyByteKeySbClick(Sender: TObject);
procedure GenerateBtnClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
FKey : TKey;
FKeyType : TKeyType;
procedure SetKeyType(Value : TKeyType);
public
{ Public declarations }
procedure SetKey(Value : TKey); {!!.08}
procedure GetKey(var Value : TKey); {!!.08}
property KeyType : TKeyType
read FKeyType
write SetKeyType;
end;
implementation
{$IFDEF MSWINDOWS}{$R *.DFM}{$ENDIF}
{$IFDEF UseOgFMX}{$R *.fmx}{$ENDIF}
procedure TKeyGenerateFrm.FormCreate(Sender: TObject);
begin
KeyTypeCb.ItemIndex := Ord(FKeyType);
{set state of memo and generate button}
KeyStringMe.Enabled := (KeyTypeCb.ItemIndex <> 0);
{$IFNDEF UseOgFMX}
case KeyStringMe.Enabled of
True : KeyStringMe.Color := clWindow;
False : KeyStringMe.Color := clBtnFace;
end;
{$ENDIF}
GenerateBtn.Enabled := (KeyTypeCb.ItemIndex = 0) or
(KeyStringMe.Lines.Count > 0);
end;
procedure TKeyGenerateFrm.KeyStringMeChange(Sender: TObject);
begin
BlockKeyEd.Text := '';
ByteKeyEd.Text := '';
{set state of generate button}
GenerateBtn.Enabled := (KeyTypeCb.ItemIndex = 0) or
(KeyStringMe.Lines.Count > 0);
end;
procedure TKeyGenerateFrm.KeyTypeCbChange(Sender: TObject);
begin
BlockKeyEd.Text := '';
ByteKeyEd.Text := '';
{set state of memo and generate button}
KeyStringMe.Enabled := (KeyTypeCb.ItemIndex <> 0);
{$IFNDEF UseOgFMX}
case KeyStringMe.Enabled of
True : KeyStringMe.Color := clWindow;
False : KeyStringMe.Color := clBtnFace;
end;
{$ENDIF}
GenerateBtn.Enabled := (KeyTypeCb.ItemIndex = 0) or
(KeyStringMe.Lines.Count > 0);
if KeyTypeCb.ItemIndex > -1 then
FKeyType := TKeyType(KeyTypeCb.ItemIndex);
end;
procedure TKeyGenerateFrm.BlockKeyEdChange(Sender: TObject);
begin
CopyBlockSb.Enabled := (BlockKeyEd.Text <> '');
end;
procedure TKeyGenerateFrm.CopyBlockSbClick(Sender: TObject);
var
OldSelStart: Integer;
begin
if (BlockKeyEd.SelLength > 0) then
BlockKeyEd.CopyToClipboard
else begin
OldSelStart := BlockKeyEd.SelStart;
BlockKeyEd.SelStart := 0;
BlockKeyEd.SelLength := MaxInt;
BlockKeyEd.CopyToClipboard;
BlockKeyEd.SelStart := OldSelStart;
BlockKeyEd.SelLength := 0;
end;
end;
procedure TKeyGenerateFrm.ByteKeyEdChange(Sender: TObject);
begin
CopyByteKeySb.Enabled := (ByteKeyEd.Text <> '');
end;
procedure TKeyGenerateFrm.CopyByteKeySbClick(Sender: TObject);
var
OldSelStart: Integer;
begin
if (ByteKeyEd.SelLength > 0) then
ByteKeyEd.CopyToClipboard
else begin
OldSelStart := ByteKeyEd.SelStart;
ByteKeyEd.SelStart := 0;
ByteKeyEd.SelLength := MaxInt;
ByteKeyEd.CopyToClipboard;
ByteKeyEd.SelStart := OldSelStart;
ByteKeyEd.SelLength := 0;
end;
end;
procedure TKeyGenerateFrm.GenerateBtnClick(Sender: TObject);
begin
case KeyTypeCb.ItemIndex of
0:
begin
{$IFDEF MSWINDOWS}
Screen.Cursor := crHourGlass;
{$ENDIF}
try
GenerateRandomKeyPrim(FKey, SizeOf(FKey));
BlockKeyEd.Text := BufferToHex(FKey, SizeOf(FKey));
ByteKeyEd.Text := BufferToHexBytes(FKey, SizeOf(FKey));
finally
{$IFDEF MSWINDOWS}
Screen.Cursor := crDefault;
{$ENDIF}
end;
end;
1:
begin
GenerateTMDKeyPrim(FKey, SizeOf(FKey), AnsiUpperCase(KeyStringMe.Text));
BlockKeyEd.Text := BufferToHex(FKey, SizeOf(FKey));
ByteKeyEd.Text := BufferToHexBytes(FKey, SizeOf(FKey));
end;
2:
begin
GenerateTMDKeyPrim(FKey, SizeOf(FKey), KeyStringMe.Text);
BlockKeyEd.Text := BufferToHex(FKey, SizeOf(FKey));
ByteKeyEd.Text := BufferToHexBytes(FKey, SizeOf(FKey));
end;
end;
end;
procedure TKeyGenerateFrm.SetKeyType(Value : TKeyType);
begin
if Value <> FKeyType then begin
FKeyType := Value;
KeyTypeCb.ItemIndex := Ord(FKeyType);
end;
end;
procedure TKeyGenerateFrm.GetKey(var Value : TKey);
begin
Value := FKey;
end;
procedure TKeyGenerateFrm.SetKey(Value : TKey);
begin
FKey := Value;
end;
procedure TKeyGenerateFrm.FormShow(Sender: TObject);
begin
KeyTypeCbChange(Sender);
end;
end.