-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArchiveEditUnit.pas
More file actions
1996 lines (1778 loc) · 57.3 KB
/
ArchiveEditUnit.pas
File metadata and controls
1996 lines (1778 loc) · 57.3 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
name:(1999.12.1 -jhx1)
江湖行 II jhx2
2002.10.13 renamed to 'GamePaladin II'
CopyRight:XuGanQuan gqxunet#163.com
Description:A game cheat tool
This program is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public
License along with this program; if not, write to the Free
Software Foundation, Inc.,
675 Mass Ave, Cambridge, MA 02139, USA.
}
unit ArchiveEditUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Gauges, ComCtrls, ToolWin, StdCtrls, Buttons, ExtCtrls,ChildFormUnit,
ImgList, Menus;
resourcestring
String_Filenotask='没有文件搜索任务,请新建加入;';
String_Filenoresult='搜索次数: 0 , 找到数目:0 ';
String_FileScanResult='搜索次数:%d , 找到数目:%d ';
String_FileInScan='当前的文件搜索任务正在进行,请等待.';
String_FileInScanTitle='文件搜索任务进行信息';
String_InvalidInput='无效的输入数据,请检查.';
String_Addtask='还没有文件搜索任务 ,是否现在创建?';
String_Addtasktitle='没有文件搜索任务信息';
String_InScan='当前的任务正在进行,请等待.';
String_InScanTitle='任务进行信息';
String_FileTaskinvalid='对应的存档文件不存在. ';
String_FileTypeNoMatch='输入的类型不匹配上次类型(高阶/低阶),'+
'你想进行新类型的搜索吗?';
String_FileTypeNoMatchTitle='输入的类型不匹配信息';
String_FileAskRepeatInitLowLevelTitle='文件低阶搜索重复初始化信息';
String_FileAskRepeatInitLowLevel='已经进行了初始化文件的低阶搜索,'#13#10+
'是否再次初始化?';
String_FileNoResultAgainTitle='无结果信息';
String_FileNoResultAgain='抱歉,找不到任何匹配的地址,是否再次搜索?';
String_InvalidByte='%s 不是合法的 Byte 类型数据,请检查';
String_InvalidWord='%s 不是合法的 Word 类型数据,请检查';
String_InvalidDword='%s 不是合法的 Dword 类型数据,请检查';
String_InvalidInt64='%s 不是合法的 Int64 类型数据,请检查k';
String_InvalidSingle='%s 不是合法的 Single 类型数据,请检查';
String_InvalidDouble='%s 不是合法的 Double 类型数据,请检查';
String_InvalidString='%s 不是合法的 Text 类型数据,请检查';
String_FileTaskResult='任务: %s '#13#10'找到 %d 个地址,'#13#10'用时 %f 秒.';
String_FileTaskResultTitle='搜索结果';
String_FileInitialLowLevel='文件搜索任务:%s'#13#10'低阶搜索初始化完成.';
type
TArchiveEditForm = class(TChildForm)
temp_Panel1: TPanel;
ToolBar1: TToolBar;
AddFIle_TB: TToolButton;
delFile_tb: TToolButton;
Filetasks_LV: TListView;
Splitter1: TSplitter;
Panel1: TPanel;
Splitter2: TSplitter;
Panel2: TPanel;
Scan_bn: TSpeedButton;
EditFile_Sb: TSpeedButton;
InputHelp_SB: TSpeedButton;
Value_Edit: TEdit;
VarType_CB: TComboBox;
Panel3: TPanel;
File_Info_SearchResult_LB: TLabel;
File_info_Name_LB: TLabel;
Edit_LV: TListView;
Found_LV: TListView;
Panel4: TPanel;
Scan_Gauge: TGauge;
ImageList1: TImageList;
DisplayFileScanProcess: TTimer;
PopupMenu1: TPopupMenu;
delFiletask_menu: TMenuItem;
N1: TMenuItem;
ClearFileTask_menu: TMenuItem;
PopupMenu2: TPopupMenu;
PopupMenu3: TPopupMenu;
Addtolists: TMenuItem;
N2: TMenuItem;
EditAddress: TMenuItem;
DeleteFileEditAddress: TMenuItem;
ClearAllAddress: TMenuItem;
N4: TMenuItem;
ModifyFileEdit: TMenuItem;
EditFileAddress: TMenuItem;
StaticText1: TStaticText;
procedure AddFIle_TBClick(Sender: TObject);
procedure delFile_tbClick(Sender: TObject);
procedure Filetasks_LVEdited(Sender: TObject; Item: TListItem;
var S: String);
procedure Filetasks_LVClick(Sender: TObject);
procedure Scan_bnClick(Sender: TObject);
procedure DisplayFileScanProcessTimer(Sender: TObject);
procedure InputHelp_SBClick(Sender: TObject);
procedure Value_EditKeyPress(Sender: TObject; var Key: Char);
procedure VarType_CBChange(Sender: TObject);
procedure ClearFileTask_menuClick(Sender: TObject);
procedure Found_LVDblClick(Sender: TObject);
procedure Found_LVMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure EditFile_SbClick(Sender: TObject);
procedure EditAddressClick(Sender: TObject);
procedure DeleteFileEditAddressClick(Sender: TObject);
procedure ClearAllAddressClick(Sender: TObject);
procedure ModifyFileEditClick(Sender: TObject);
procedure Edit_LVMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure EditFileAddressClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure InitFiletask(theID:Integer);
function checkandGetFileSize(FileName:string):Dword;
Procedure AddTasktoList(theIndex:integer);
Procedure UpdateTaskInfo(theIndex:integer);
Procedure AddFoundToListView(theIndex:integer);
Procedure RaiseInputError;
function AnalyseScan(theIndex:Integer):integer;
function CheckForScan:boolean;
function ReadFileData(theFileName:String;theAddress:Dword;Valuetype:integer):string;
end;
Type
TFileFirstScanThread=class(TThread)
private
TheTaskIndex:integer;
protected
procedure Execute; override;
public
constructor Create(theIndex:Integer);
end;
type
TFileNextScanThread=class(TThread)
private
TheTaskIndex:integer;
protected
procedure Execute; override;
public
constructor Create(theIndex:Integer);
end;
const
Auto_value=0;
Byte_value=1;
word_value=2;
Dword_value=3;
int64_value=4;
Single_value=5;
Double_Value=6;
String_Value=7;
CommonLevel_Value=10;
Number_Scan = 101;
String_Scan=102;
LowLevel_Value=20;
InitialLowLevel_Scan =201;
Increased_Scan =202;
Decreased_Scan = 203;
Changed_Scan = 204;
Unchanged_Scan = 205;
const Max_FileTaskNUm=255;
type
TFiletask=record
Applyed:Boolean; ///占用
name:String;
index:integer;
FilepathName:String;
ScanType:integer; //Number_Scan:= ]
OldScanType:integer;
VarType:integer; //选择某一类型后,实际搜索类型auto
OldVarType:integer;
ScanValue:string;
TotalProcess:Dword; ///应扫描总的地指数
NowProcess:Dword; ////扫描数量
InSearchProcess:Boolean; ///是否正在扫描,防止多次点击
SearchTimes:DWORD; //扫描次数
AttachedNum:DWORD;
SaveFileName:String; ///存档文件最新备份
AddressMemStream:TMemoryStream; //几下每个符合的地址
end;
var theFileTask:array[1..Max_FileTaskNUm]of TFiletask;
CurrentFileTaskIndex:Integer;
ListToFileTaskIndex:array[1..Max_FileTaskNUm] of Integer; //listview 对应任务Index
FileTaskNUm:Integer=0; ///任务个数
ErrorInputNum:BYTE;
CanUpdateFileTask:Integer=-999; ///防止更新闪烁,
var
ArchiveEditForm: TArchiveEditForm;
implementation
uses AddFileTaskUnit, InputhelpUnit, FileRecordUnit, FileEditUnit;
{$R *.dfm}
////
function TArchiveEditForm.checkAndGetFileSize(FileName:string):Dword;
var FHandle:Integer;
TempSize:Int64;
begin
result:=0;
if not FileExists(FileName) then
begin
showmessage(format(string_NotExists,[FileName]));
exit;
end;
FHandle := FileOpen(FileName, fmOpenWrite or fmShareDenyNone);
try
begin
if (FHandle<0) then
begin
showmessage(format(string_cannotopen,[FileName]));
exit;
end;
TempSize:=GetFileSize(FHandle,nil);
if (TempSize=0) or (TempSize>=$4000000) then
begin
showmessage(format(String_InvalidFile,[FileName]));
exit;
end else result:=Tempsize;
end;
finally
FileClose(FHandle);
end;
end;
//////////////初始化任务//////////////////////////////////
procedure TArchiveEditForm.InitFiletask(theID:Integer);
begin
with theFileTask[theId] do
begin
Applyed:=True;
name:='';
//index:integer;
FilepathName:='';
ScanType:=Number_Scan; //Number_Scan:= ]
OldScanType:=ScanType;
VarType:=Auto_value; //选择某一类型后,实际搜索类型auto
OldVarType:=Auto_value;
ScanValue:='';
TotalProcess:=0;
NowProcess:=0;
SearchTimes:=0;
AttachedNum:=0;
InSearchProcess:=False;
SaveFileName:='';
if Assigned(AddressmemStream)then
AddressMemStream.SetSize(0) else
AddressMemStream:=TmemoryStream.Create;
end;
end;
Procedure TArchiveEditForm.AddTasktoList(theIndex:integer);
begin
with FileTasks_LV.Items.Add do
begin
Caption:=theFileTask[theIndex].Name;
end;
end;
Procedure TArchiveEditForm.UpdateTaskInfo(theIndex:integer);
begin
if FiletaskNum=0 then
begin
File_info_Name_LB.Caption:=String_Filenotask;
File_Info_SearchResult_LB.Caption:=String_Filenoresult;
Found_lv.Clear;
end else
begin
With theFileTask[theIndex] do
begin
File_info_Name_LB.Caption:=Name;
File_Info_SearchResult_LB.Caption:=Format(String_FileScanResult,[SearchTimes,AttachedNum]);
end;
end;
end;
///////////////////////////////////
//////////根据输入的值判断scantype//////////////////////////////////////////////////
Function GetScanTypeAndTempVar(InputValue:String;theFiletaskIndex:integer):Integer;
var Len:integer;
begin
Result:=-999;
with theFiletask[theFiletaskIndex] do
begin
Len:=length(inputValue);
if InputValue='' then
Exit
else if inputvalue[1]='?' then
begin
VarType:=LowLevel_value;
Result:=InitialLowLevel_Scan;
end
else if InputValue[1]='!' then
begin
VarType:=LowLevel_value;
Result:=Changed_Scan;
end
else if InputValue[1]='=' then
begin
VarType:=LowLevel_value;
Result:=UnChanged_Scan;
end
else if InputValue[1]='+' then
begin
VarType:=LowLevel_value;
Result:=Increased_scan;
end
else if InputValue[1]='-' then
begin
VarType:=LowLevel_value;
Result:=Decreased_scan ;
end
else if (
((Len>2) and ( Len<255) ) and
(
((InputValue[1]='"') and (InputValue[Len]='"')) or
((InputValue[1]='''') and (InputValue[Len]=''''))
)
)
then
begin
ScanValue:=Copy(inputValue,2,Len-2);
VarType:=CommonLevel_value;
Result:=String_Scan;
end
else begin
ScanValue:=inputValue;
/////Vartype必须考虑Combobox的选择
Result:=Number_Scan;
end;
end; ///with end;
end;
//////////////////////////////////////////////////////////////////
/////////////hex to int///////////////////////////////////////////////////////////////////////////////
Function HexIntChange(inStr:string):String;
var Len:integer;
TempString:String;
begin
Len:=Length(inStr);
if (Len>2) and ( UpperCase(instr[1])+UpperCase(instr[2])='0X' )then
begin
TempString:='$'+Copy(Instr,3,Len-2);
try
Result:=inttoStr(Strtoint(TempString));
except
showmessage(String_InvalidInput);
end;
Exit;
end;
if (Len>1) and (instr[1]='$') then
begin
try
Result:=inttoStr(Strtoint(instr));
except
showmessage(String_InvalidInput);
end;
Exit;
end;
result:=instr;
end;
////////////根据输入值判断输出可用///////////////////////////////////////////////////////
Function GetVarTypeAndVarValue(InputValue:String;theFileTaskIndex:integer):Integer;
var ByteTemp:Byte;
WordTemp:word;
DwordTemp:Dword;
Int64Temp:int64;
SingleTemp:Single;
DoubleTemp:Double;
ECode:integer;
begin
Result:=-999; //error value
with theFileTask[theFileTaskIndex] do
begin
if (ScanType<>Number_Scan) and (ScanType<>String_Scan) then
begin
Result:=LowLevel_value;
Exit;
end;
if (ScanType=String_Scan) then
begin
ScanValue:=inputvalue;
Result:=CommonLevel_value;
Exit;
end;
if ScanType=Number_Scan then
begin
if (VarType=Auto_value) then
begin
//is integer
if pos('.',inputValue)=0 then
try
begin
inputValue:=HexIntChange(inputValue);
val(inputvalue,int64Temp,Ecode);
if Ecode>0 then Exit;
ScanValue:=inputValue;
if (int64Temp shr 8)=0 then Result:=Byte_value
else if (int64Temp shr 16)=0 then Result:=Word_value
else if (int64Temp shr 32)=0 then Result:=DWord_value
else if (int64Temp shr 64)=0 then Result:=Int64_value
else Result:=Int64_value;
exit;
end;
except
Exit;
end;
//is float
if pos('.',inputValue)>0 then
try
begin
val(inputValue,DoubleTemp,Ecode);
if Ecode>0 then Exit;
ScanValue:=inputValue;
if ( DoubleTemp-Exp(ln(2)*128)>0 ) or ( DoubleTemp-Exp(ln(2)*(-126))<0) then
Result:=Double_value else
Result:=single_value;
exit;
end;
except
exit;
end;
end///Auto_value
else
begin
case VarType of
Byte_value: begin
val(InputValue,ByteTemp,Ecode);
if Ecode<>0 then Exit else
begin
ScanValue:=InputValue;
Result:=Byte_value;
end;
end;
Word_value: begin
val(InputValue,WordTemp,Ecode);
if Ecode<>0 then Exit else
begin
ScanValue:=InputValue;
Result:=Word_value;
end;
end;
Dword_value: begin
val(InputValue,DwordTemp,Ecode);
if Ecode<>0 then Exit else
begin
ScanValue:=InputValue;
Result:=DWord_value;
end;
end;
Int64_value: begin
val(InputValue,int64Temp,Ecode);
if Ecode<>0 then Exit else
begin
ScanValue:=InputValue;
Result:=Int64_value;
end;
end;
Single_value:begin
val(InputValue,SingleTemp,Ecode);
if Ecode<>0 then Exit else
begin
ScanValue:=InputValue;
Result:=Single_value;
end;
end;
Double_value:begin
val(InputValue,DoubleTemp,Ecode);
if Ecode<>0 then Exit else
begin
ScanValue:=InputValue;
Result:=Double_value;
end;
end;
String_value:begin
ScanValue:=InputValue;
Result:=String_value;
end;
end; //case end;
end; ///not auto_value End;
end;///Extrac_scan end
end;///with end;
end;
///////////////////////////////////////////////////////////////////////////////////////////
///////////查找到的 地址数据加入列表
Procedure TArchiveEditForm.AddFoundToListView(theIndex:integer);
var FileSize:Dword;
BufSize:Int64;
AddressBuf:Dword;
i,j:Integer;
TempByte:Byte;
TempWord:Word;
TempDword:Dword;
Tempint64:int64;
TempSingle:Single;
TempDouble:Double;
TempStringBYTE:BYTE;
TempStringCount:byte;
Tempstring:string;
tempFileStream:TmemoryStream;
begin
Found_LV.Items.BeginUpdate;///防止闪烁
Found_LV.Items.Clear;
with theFiletask[theIndex] do
begin
FileSize:=checkAndGetFileSize(FilePathName);
if FileSize=0 then exit;
tempFileStream:=TmemoryStream.Create;
try
tempFileStream.LoadFromFile(FilePathName);
AddressmemStream.Seek(0,soFrombeginning); ////低阶搜索BufSize=0;
BufSize:= AddressMemStream.Size;
if (BufSize>0) and ( not theFiletask[theIndex].InSearchProcess) then
begin
BufSize:=BufSize shr 2;
if BufSize>200 then BufSize:=200; ///只显示前面200个值
For i:=1 to BufSize do
begin
try
AddressMemStream.ReadBuffer(AddressBuf,Sizeof(AddressBuf));
if (AddressBuf+1)<=FileSize then
begin
tempFileStream.Seek(AddressBuf,soFrombeginning);
tempFileStream.ReadBuffer(TempByte,1);
end;
if (AddressBuf+2)<=FileSize then
begin
tempFileStream.Seek(AddressBuf,soFrombeginning);
tempFileStream.ReadBuffer(TempWord,2);
end;
if (AddressBuf+4)<=FileSize then
begin
tempFileStream.Seek(AddressBuf,soFrombeginning);
tempFileStream.ReadBuffer(TempDWord,4);
end;
if (AddressBuf+8)<=FileSize then
begin
tempFileStream.Seek(AddressBuf,soFrombeginning);
tempFileStream.ReadBuffer(TempInt64,8);
end;
if (AddressBuf+4)<=FileSize then
begin
tempFileStream.Seek(AddressBuf,soFrombeginning);
tempFileStream.ReadBuffer(TempSingle,4);
end;
if (AddressBuf+8)<=FileSize then
begin
tempFileStream.Seek(AddressBuf,soFrombeginning);
tempFileStream.ReadBuffer(TempDouble,8);
end;
tempStringCount:=(FileSize-AddressBuf);
if tempStringCount>16 then tempStringCount:=16;
tempFileStream.Seek(AddressBuf,soFrombeginning);
Tempstring:='';
for j:=1 to tempStringCount do
begin
tempFileStream.ReadBuffer(TempStringBYTE,1);
Tempstring:=Tempstring+chr(TempstringBYTE);
end;
with Found_LV.Items.Add do
begin
Caption:=intTohex(AddressBuf,8);
SubItems.Add(intToStr(TempByte));
SubItems.Add(intToStr(TempWord));
SubItems.Add(intToStr(TempDword));
SubItems.Add(intToStr(TempInt64));
SubItems.Add(FloatToStr(TempSingle));
SubItems.Add(FloatToStr(TempDouble));
SubItems.Add(TempString);
end;
except
Continue;
end;
end;//for end
end; //if end
finally
FreeandNIl(tempFileStream);
end;
end;///with end
Found_lv.Items.EndUpdate;
end;
Procedure TArchiveEditForm.RaiseInputError;
begin
with theFileTask[CurrentFiletaskIndex] do
begin
inc(ErrorInputNum);
Value_Edit.SetFocus;
if ErrorInputNum>3 then
begin
Messagebeep(0);
ErrorInputNum:=0;
InputHelp_sb.click;
end;
end;
end;
procedure TArchiveEditForm.AddFIle_TBClick(Sender: TObject);
begin
AddFiletaskForm.Show;
end;
procedure TArchiveEditForm.delFile_tbClick(Sender: TObject);
var i,SelListIndex,theIndex:integer;
begin
if Filetasknum=0 then Exit;
if FIleTasks_LV.Selected<>nil then
begin
SelListIndex:=FIleTasks_LV.Selected.Index+1;
theIndex:=ListToFileTaskIndex[SelListIndex];
if theFileTask[theindex].InSearchProcess then
begin
MessageBox(Application.Handle,pchar(String_FileInScan),pchar(String_FileInScanTitle),
MB_OK or MB_ICONINFORMATION);
exit;
end;
theFileTask[theindex].Applyed:=False;
theFileTask[theIndex].AddressMemStream.Clear;
Dec(FiletaskNUm);
for i:=SelListIndex to FiletaskNum do
begin
ListToFileTaskIndex[i]:=ListToFileTaskIndex[i+1];
end;
FileTasks_lv.selected.Delete;
DeleteFile(theFileTask[theIndex].SaveFileName);
UpdateTaskInfo(theFileTask[theIndex].Index);
end;
end;
procedure TArchiveEditForm.Filetasks_LVEdited(Sender: TObject;
Item: TListItem; var S: String);
begin
theFileTask[CurrentFiletaskIndex].Name:=S;
UpdateTaskInfo(CurrentFiletaskIndex);
end;
procedure TArchiveEditForm.Filetasks_LVClick(Sender: TObject);
var selListIndex:Integer;
begin
if Filetasks_LV.Selected=nil then exit;
selListIndex:=Filetasks_LV.Selected.Index+1;
CurrentFiletaskIndex:=ListToFiletaskIndex[selListIndex];
Scan_Gauge.MaxValue:=theFileTask[CurrentFiletaskIndex].TotalProcess;
Value_Edit.Text:=theFileTask[CurrentFiletaskIndex].ScanValue;
if theFileTask[CurrentFileTaskIndex].ScanType=String_Scan then
Value_Edit.Text:=''''+theFileTask[CurrentFiletaskIndex].ScanValue+'''';
UpdateTaskInfo(CurrentFiletaskIndex);
VarType_cb.ItemIndex:=0;
AddFoundToListView(CurrentFiletaskIndex);
File_name:=theFileTask[CurrentFiletaskIndex].FilepathName;
EditFileName:=File_name;
FileRecordForm.FormRefresh;
end;
//////必须考虑前面的搜索类型
function TArchiveEditForm.AnalyseScan(theIndex:Integer):integer;
var TempLength:Dword;
TempSize:Dword;
begin
result:=-999;
with theFileTask[theIndex] do
begin
////////////////////检查文件是否存在/////////////////////////////////////
TempLength:=checkAndgetFilesize(FilepathName);
if TempLength=0 then
begin
result:=0;
exit;
end;
////////////////////////////////////////////////////////////
if SearchTimes=0 then
begin
tempSize:=tempLength;
TotalProcess:= TempSize;
Result:=4; ///ok
exit;
end;
/////////////////////是否重复低阶搜索初始化////////////////////////////////////////
if ((SearchTimes=1) and (OldVartype=LowLevel_value) and (ScanType=InitialLowLevel_Scan) )then
begin
Result:=1;
Exit;
end;
//////////////////高低阶是否匹配///////////////////////////////////////////////
if SearchTimes>0 then
begin
if ( (OldVarType=Lowlevel_Value) and (VarType<>Lowlevel_Value) ) or
( (OldVarType<>Lowlevel_Value) and (VarType=Lowlevel_Value))
then
begin
result:=2;
exit;
end;
end;
/////////////////////确定搜索范围大小,////////////////////////////////////////////////////////////
if SearchTimes>0 then
begin
if (SearchTimes=1) and (OldvarType=LowLevel_Value) then
begin
///TempLength:=checkAndgetFilesize(FilepathName);
TempSize:=TempLength;
end else
begin
TempLength:=AddressMemStream.Size;
TempSize:=TempLength shr 2;
end;
if TempSize=0 then begin Result:=3; exit; end;
TotalProcess:= TempSize;
Result:=4;/////ok
end;
///////////////////////////////
end;//////with end
end;
function TArchiveEditForm.CheckForScan:boolean;
begin
Result:=false;
with theFiletask[CurrentFileTaskIndex] do begin
case AnalyseScan(CurrentFileTaskIndex) of
0: begin
Raise Exception.Create(String_FileTaskinvalid);
end;
1: begin
if MessageBox(Application.Handle,pchar(String_FileAskRepeatInitLowLevel),
pchar(String_FileAskRepeatInitLowLevelTitle),
MB_YESNO or MB_ICONINFORMATION)=IDYES then
begin
TotalProcess:=0;
SearchTimes:=0;
AttachedNum:=0;
AddressMemStream.Clear;
Result:=True;
Exit;
end else exit;
end;
2: begin
if MessageBox(Application.Handle,pchar(String_FileTypeNoMatch),
pchar(String_FileTypeNoMatchTitle),
MB_YESNO or MB_ICONINFORMATION)=IDYES then
begin
TotalProcess:=0;
SearchTimes:=0;
AttachedNum:=0;
AddressMemStream.Clear;
Result:=True;
exit;
end else Exit;
end;
3: begin
if MessageBox(Application.Handle,pchar(String_FileNoResultAgain),
pchar(String_FileNoResultAgainTitle),
MB_YESNO or MB_ICONINFORMATION)=IDYES then
begin
TotalProcess:=0;
SearchTimes:=0;
AttachedNum:=0;
AddressMemStream.Clear;
Result:=True;
Exit;
end else Exit;
end;
4: Result:=True;
end; ///case end
end;///with edn
end;
procedure TArchiveEditForm.Scan_bnClick(Sender: TObject);
begin
if FileTaskNum=0 then
begin
if MessageBox(Application.Handle,pchar(String_Addtask),pchar(String_Addtasktitle),
MB_YESNO or MB_ICONINFORMATION)=IDYES then
AddFile_TB.Click;
Exit;
end;
with theFileTask[CurrentFiletaskIndex] do
begin
if InSearchProcess then
begin
MessageBox(Application.Handle,pchar(String_InScan),pchar(String_InScanTitle),
MB_OK or MB_ICONINFORMATION);
exit;
end;///防止搜索过程中不断点击
ScanType:=GetScanTypeAndTempVar(Value_Edit.text,CurrentFiletaskIndex);
if ScanType=-999 then begin RaiseInputError;exit;end;
/////Vartype必须考虑Combobox的选择
theFileTask[CurrentFiletaskIndex].VarType:=VarType_cb.ItemIndex;
varType:=GetVarTypeAndVarValue(ScanValue,CurrentFiletaskIndex);
if varType=-999 then begin RaiseInputError;exit;end;
if not CheckForScan then exit;
if SearchTimes=0 then
begin
TFileFirstScanThread.Create(CurrentFileTaskIndex);
end else
begin
TFileNextScanThread.Create(CurrentFileTaskIndex);
end;
end;///with end;
end;
//////////////////初次扫描////////////////////////////////
constructor TFileFirstScanThread.Create(theIndex:integer);
begin
TheTaskIndex:=theIndex;
inherited Create(False);
end;
Procedure TFileFirstScanThread.Execute;
var TempLength: DWORD; ////字节大小
TempSize:DWORD; //// 实际的读取尺寸
ReadByte: Byte;
ReadWord: Word;
ReadDWord: Dword;
ReadInt64: Int64;
// ReadSingle: Single;
// Readdouble: double;
ReadCharByte:Byte;
PhelpSingleDword:^Dword;
helpsingleDWord1:DWord; //存放原数的符号位与指数位
HelpSingleDword2:Dword;
PhelpDoubleint64:^int64;
helpDoubleint641:int64; //存放原数的符号位与指数位
HelpDoubleint642:int64;
HelpStringLength:Byte;
chartoFind:integer;
Time1:Dword;
Time2:Dword;
i: integer;
// j: integer;
// k: integer;
ByteValue: Byte;
WordValue: Word;
DWordValue: Dword;
Int64Value: Int64;
SingleValue: Single;
doubleValue: double;
tempFileMemStream:TmemoryStream;
tempAddress:Dword;
begin
FreeOnTerminate:=True;
/////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
/////////////再次并得到最终数据/////////////////////////////////////////
with theFileTask[theTaskIndex] do
begin
if (scanType=Number_Scan) then
begin
if Vartype=Byte_value then
begin
val(scanvalue,bytevalue,i);
if i>0 then raise Exception.Create(Format(String_InvalidByte,[scanvalue]));
end;
if vartype=word_value then
begin
val(scanvalue,wordvalue,i);
if i>0 then raise Exception.Create(Format(String_InvalidWord,[scanvalue]));
end;
if vartype=dword_value then
begin
val(scanvalue,dwordvalue,i);
if i>0 then raise Exception.Create(Format(String_InvalidDword,[scanvalue]));
end;
if vartype=Int64_value then
begin
val(scanvalue,Int64value,i);
if i>0 then raise Exception.Create(Format(String_InvalidInt64,[scanvalue]));
end;
if vartype=single_value then
begin
val(scanvalue,singlevalue,i);
if i>0 then raise Exception.Create(Format(String_InvalidSingle,[scanvalue]));
end;
if vartype=double_value then
begin
val(scanvalue,doublevalue,i);
if i>0 then raise Exception.create(Format(String_InvalidDouble,[scanvalue]));
end;
if vartype=String_value then
begin
if Length(scanvalue)>255 then raise Exception.create(Format(String_InvalidString,[scanvalue]));
end;
end;//if end;
////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
AddressMemStream.Seek(0,soFromBeginning);
OldScanType:=ScanType;
InSearchProcess:=True;
Searchtimes:=1;