?? archiveeditunit.pas
字號:
NowProcess:=0;
AttachedNum:=0;
//////////////////////////////////////
OldScanType:=ScanType;
OldVarType:=VarType;
if ArchiveEditForm.checkAndgetFilesize(FilepathName)=0 then exit;
totalProcess:=ArchiveEditForm.checkAndgetFilesize(FilepathName);
tempFileMemStream:=TmemoryStream.Create;
try
begin
tempFileMemStream.LoadFromFile(FilePathName);
tempFileMemStream.Seek(0,sofrombeginning);
/////////Lets Real Start !真正開始!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//////////
////////////////////////////////////////////////////////////
if ScanType=Number_Scan then
begin
Time1:=GetTickCount;
TempLength:=tempFileMemStream.Size;
if vartype=Byte_value then //byte
begin
TempSize:=TempLength;
for i:=0 to TempSize-1 do
begin
tempFileMemStream.Seek(i,sofrombeginning);
tempFileMemStream.ReadBuffer(readByte,1);
if readByte=ByteValue then
begin
inc(AttachedNum);
tempAddress:=i;
AddressmemStream.WriteBuffer(tempAddress,Sizeof(tempAddress));
end;
inc(NowProcess);
end;
end; //byte end
if vartype=Word_value then //word
begin
TempSize:=TempLength;
for i:=0 to TempSize-2 do
begin
tempFileMemStream.Seek(i,sofrombeginning);
tempFileMemStream.ReadBuffer(readWord,2);
if readWord=WordValue then
begin
inc(AttachedNum);
tempAddress:=i;
AddressmemStream.WriteBuffer(tempAddress,Sizeof(tempAddress));
end;
inc(NowProcess);
end;
end; //word end
if vartype=Dword_value then //dword
begin
TempSize:=TempLength;
for i:=0 to TempSize-4 do
begin
tempFileMemStream.Seek(i,sofrombeginning);
tempFileMemStream.ReadBuffer(readDWord,4);
if readDWord=DWordValue then
begin
inc(AttachedNum);
tempAddress:=i;
AddressmemStream.WriteBuffer(tempAddress,Sizeof(tempAddress));
end;
inc(NowProcess);
end;
end; //dowrd end
if vartype=Int64_value then //int64
begin
TempSize:=TempLength;
for i:=0 to TempSize-8 do
begin
tempFileMemStream.Seek(i,sofrombeginning);
tempFileMemStream.ReadBuffer(readInt64,8);
if readInt64=Int64Value then
begin
inc(AttachedNum);
tempAddress:=i;
AddressmemStream.WriteBuffer(tempAddress,Sizeof(tempAddress));
end;
inc(NowProcess);
end;
end; //int64 end
if vartype=Single_value then //Single
begin
PHelpSingleDword:=@singlevalue;
HelpSingleDword1:=(PHelpSingleDword^ shr 23);
TempSize:=TempLength;
for i:=0 to TempSize-4 do
begin
tempFileMemStream.Seek(i,sofrombeginning);
tempFileMemStream.ReadBuffer(HelpsingleDword2,4);
///single的1位符號位與8位指數(shù)為相同
HelpsingleDWord2:=HelpsingleDWord2 shr 23;
if helpsingleDWord2=helpsingleDWord1 then
begin
inc(AttachedNum);
tempAddress:=i;
AddressmemStream.WriteBuffer(tempAddress,Sizeof(tempAddress));
end;
inc(NowProcess);
end;
end; ///single end
if vartype=Double_value then //Double
begin
PHelpDoubleint64:=@Doublevalue;
HelpDoubleint641:=(PHelpDoubleInt64^ shr 52);
TempLength:=tempFileMemStream.Size;
TempSize:=TempLength;
for i:=0 to TempSize-8 do
begin
tempFileMemStream.Seek(i,sofrombeginning);
tempFileMemStream.ReadBuffer(HelpDoubleInt642,8);
///double的1位符號位與11位指數(shù)為相同
HelpDoubleInt642:=HelpDoubleint642 shr 52;
if helpDoubleInt642=helpDoubleInt641 then
begin
inc(AttachedNum);
tempAddress:=i;
AddressmemStream.WriteBuffer(tempAddress,Sizeof(tempAddress));
end;
inc(NowProcess);
end;
end;//double end
NowProcess:=totalProcess;
time2:=getTickCount;
CanUpdateFileTask:=messageBox(Application.handle,
pchar(Format(String_FileTaskResult,[name,AttachedNum,(Time2-Time1)/1000])), //pchar('任務(wù):'+name+#13#10+'總共找到'+intToStr(AttachedNum)+'個結(jié)果 耗時'+FloattoStr((Time2-Time1)/1000)+'秒'),
pchar(String_FileTaskResultTitle),
MB_OK);
end; //Number_Scan end
//text String scan
if scantype=string_scan then
begin
time1:=getTickCount;
helpStringLength:=length(scanvalue);
TempLength:=tempFileMemStream.Size;
TempSize:=TempLength;
CharToFind:=1;
for i:=0 to TempLength-1 do
begin
tempFileMemStream.Seek(i,sofrombeginning);
tempFileMemStream.ReadBuffer(ReadcharByte,1);
if chr(readcharByte)=scanvalue[CharToFind] then
begin
inc(charToFind);
if CharToFind>=Dword(helpStringLength)+1 then //found the string
begin
inc(AttachedNum);
tempAddress:=i-helpStringLength+1;
AddressmemStream.WriteBuffer(tempAddress,Sizeof(tempAddress));
CharToFind:=1;
end;
end else CharToFind:=1;
inc(NowProcess);
end;
NowProcess:=totalProcess;
time2:=getTickCount;
CanUpdateFileTask:=messageBox(Application.handle,
pchar(Format(String_FileTaskResult,[name,AttachedNum,(Time2-Time1)/1000])), //pchar('任務(wù):'+name+#13#10+'總共找到'+intToStr(AttachedNum)+'個結(jié)果 耗時'+FloattoStr((Time2-Time1)/1000)+'秒'),
pchar(String_FileTaskResultTitle),
MB_OK);
end; //text String scan
///低階掃描初始化////////////
//if (scantype<>Number_scan) and (scantype<>String_scan) then
if (VarType=LowLevel_Value) then
begin
tempFileMemStream.SaveToFile(SaveFileName);
NowProcess:=totalProcess;
CanUpdateFileTask:=messageBox(Application.handle,
pchar(format(String_FileInitialLowLevel,[name])),
pchar(String_FileTaskResultTitle),
MB_OK);
end;
InSearchProcess:=False;
end; ///try end;
finally
FreeAndNil(tempFileMemStream);
end;
end;//with scan end;
end;
//////////////////////////////////////////////////////////////////////////////////////////
constructor TFileNextScanThread.Create(theIndex:integer);
begin
TheTaskIndex:=theIndex;
inherited Create(False);
end;
///////////////////第二次三次..的掃描///////////////////////////////////////////////////////////////
Procedure TFileNextScanThread.Execute;
var TempLength: DWORD;
TempSize:DWORD;
ReadByte: Byte;
ReadWord: Word;
ReadDWord: Dword;
ReadInt64: Int64;
// ReadSingle: Single;
// Readdouble: double;
ReadCharByte:Byte;
PhelpSingleDword:^Dword;
helpsingleDWord1:DWord; //存放原數(shù)的符號位與指數(shù)位
HelpSingleDword2:Dword;
PhelpDoubleint64:^int64;
helpDoubleint641:int64; //存放原數(shù)的符號位與指數(shù)位
HelpDoubleint642:int64;
// ReadMemory_ArrayStringByte:Array[0..$FF] of Byte;
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;
FileReadByte:Byte;
FileReadByteNew:Byte;
TempAddress:Dword;
AddressMemStreamNew:TmemoryStream; //////新地址
tempFileMemStream:TmemoryStream; ///打開文件
tempFileMemStreamNew:TmemoryStream; ///保存的低階文件
begin
FreeOnTerminate:=True;
with theFileTask[theTaskIndex] do
begin
/////////////////////////////////////////////////
/////////////再次并得到最終數(shù)據(jù)/////////////////////////////////////////
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
////////////////////////////////////////////////////////////////////////////
InSearchProcess:=True;
NowProcess:=0;
AttachedNum:=0;
INC(SearchTimes);
OldScanType:=ScanType;
AddressMemStream.Seek(0,soFromBeginning);
OldScanType:=ScanType;
OldVarType:=VarType;
/////////NextScan真正開始!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//////////
tempFileMemStream:=TmemoryStream.Create;
tempFileMemStream.LoadFromFile(FilePathName);
AddressMemStreamNew:=TmemoryStream.Create;
////////////////////////////////////////////////////////////
if (scanType=number_Scan) then
begin
Time1:=GetTickCount;
TempLength:=AddressMemStream.Size;
TempSize:=TempLength shr 2;
if vartype=Byte_value then //Byte
begin
for i:=0 to TempSize-1 do
begin
AddressMemStream.ReadBuffer(TempAddress,Sizeof(TempAddress));
tempFileMemStream.Seek(TempAddress,sofrombeginning);
TRY
tempFileMemStream.ReadBuffer(readByte,1);
EXCEPT
continue;
END;
if readByte=ByteValue then
begin
inc(AttachedNum);
AddressMemStreamNew.WriteBuffer(tempAddress,Sizeof(tempAddress));
end;
inc(NowProcess);
end;
end; //byte end
if vartype=Word_value then //Word
begin
for i:=0 to TempSize-1 do
begin
AddressMemStream.ReadBuffer(TempAddress,Sizeof(TempAddress));
tempFileMemStream.Seek(TempAddress,sofrombeginning);
Try
tempFileMemStream.ReadBuffer(readWord,2);
except
continue;
end;
if readWord=WordValue then
begin
inc(AttachedNum);
AddressMemStreamNew.WriteBuffer(tempAddress,Sizeof(tempAddress));
end;
inc(NowProcess);
end;
end; //word end
if vartype=DWord_value then //DWord
begin
for i:=0 to TempSize-1 do
begin
AddressMemStream.ReadBuffer(TempAddress,Sizeof(TempAddress));
tempFileMemStream.Seek(TempAddress,sofrombeginning);
try
tempFileMemStream.ReadBuffer(readDWord,4);
except
continue;
end;
if readDWord=DWordValue then
begin
inc(AttachedNum);
AddressMemStreamNew.WriteBuffer(tempAddress,Sizeof(tempAddress));
end;
inc(NowProcess);
end;
end;
if vartype=int64_value then //int64
begin
for i:=0 to TempSize-1 do
begin
AddressMemStream.ReadBuffer(TempAddress,Sizeof(TempAddress));
tempFileMemStream.Seek(TempAddress,sofrombeginning);
try
tempFileMemStream.ReadBuffer(readInt64,8);
except
continue;
end;
if readInt64=Int64Value then
begin
inc(AttachedNum);
AddressMemStreamNew.WriteBuffer(tempAddress,Sizeof(tempAddress));
end;
inc(NowProcess);
end;
end;
if vartype=Single_value then //Single
begin
PHelpSingleDword:=@singlevalue;
HelpSingleDword1:=(PHelpSingleDword^ shr 23);
for i:=0 to TempSize-1 do
begin
AddressMemStream.ReadBuffer(TempAddress,Sizeof(TempAddress));
tempFileMemStream.Seek(TempAddress,sofrombeginning);
try
tempFileMemStream.ReadBuffer(HelpSingleDword2,4);
except
continue;
end;
///single的1位符號位與8位指數(shù)為相同
HelpsingleDWord2:=HelpsingleDWord2 shr 23;
if HelpSingleDword2=HelpSingleDword1 then
begin
inc(AttachedNum);
AddressMemStreamNew.WriteBuffer(tempAddress,Sizeof(tempAddress));
end;
inc(NowProcess);
end;
end;
if vartype=Double_value then //Double
begin
PHelpDoubleInt64:=@Doublevalue;
HelpDoubleint641:=(PHelpDoubleInt64^ shr 52);
for i:=0 to TempSize-1 do
begin
AddressMemStream.ReadBuffer(TempAddress,Sizeof(TempAddress));
tempFileMemStream.Seek(TempAddress,sofrombeginning);
try
tempFileMemStream.ReadBuffer(HelpDoubleint642,8);
except
continue;
end;
///Double的1位符號位與11位指數(shù)為相同
HelpDoubleint642:=HelpDoubleint642 shr 52;
if HelpDoubleint642=HelpDoubleint641 then
begin
inc(AttachedNum);
AddressMemStreamNew.WriteBuffer(tempAddress,Sizeof(tempAddress));
end;
inc(NowProcess);
end;
end;
AddressMemStream.Clear;
AddressMemStream.CopyFrom(AddressMemStreamNew,0);
NowProcess:=totalProcess;
time2:=getTickCount;
CanUpdateFileTask:=messageBox(Application.handle,
pchar(Format(String_FileTaskResult,[name,AttachedNum,(Time2-Time1)/1000])),
pchar(String_FileTaskResultTitle),
MB_OK);
end; //Number_Scan end
//text String scan
if scantype=string_scan then
begin
time1:=getTickCount;
TempLength:=AddressMemStream.Size;
TempSize:=TempLength shr 2;
helpStringLength:=length(scanvalue);
CharToFind:=1;
for i:=0 to TempSize-1 do
begin
AddressMemStream.ReadBuffer(TempAddress,sizeof(TempAddress));
tempFileMemStream.Seek(TempAddress,sofrombeginning);
for j:=1 to helpStringLength do
begin
try
tempFileMemStream.ReadBuffer(ReadcharByte,1);
except
continue;
end;
if chr(readcharByte)=scanvalue[CharToFind] then
begin
inc(charToFind);
if CharToFind>=Dword(helpStringLength)+1 then //found the string
begin
inc(AttachedNum);
AddressmemStreamNew.WriteBuffer(tempAddress,Sizeof(tempAddress));
CharToFind:=1;
break;
end;
end else
begin
CharToFind:=1;
break;
end;
end;
inc(NowProcess);
end;
AddressMemStream.Clear;
AddressMemStream.CopyFrom(AddressMemStreamNew,0);
NowProcess:=totalProcess;
time2:=getTickCount;
CanUpdateFileTask:=messageBox(Application.handle,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -