Może ktoś pomoże i podpowie jak dodać dodatkowe sBytes1 i rBytes1 by można było wykonać np. pętle, która znajdzie odpowiednie dodatkowe bajty w pliku i je zamieni?
procedure SearchBytePattern(tfile: string; hWnd: hWnd);
const
sBytes : array[0..14] of byte = ($8A,$5D,$E7,$84,$DB,$74,$2E,$8D,$7D,$80,$83,$C9,$FF,$33,$C0);
rBytes : array[0..14] of byte = ($CC,$CC,$CC,$CC,$CC,$EB,$24,$CC,$CC,$CC,$CC,$CC,$CC,$CC,$CC);
mByte : Byte = $CC;
//sBytes1 : array[0..14] of byte = ($8A,$5D,$E7,$84,$DB,$EB,$24,$8D,$7D,$80,$83,$C9,$FF,$33,$C0);
//rBytes1 : array[0..14] of byte = ($CC,$CC,$CC,$CC,$CC,$74,$2E,$CC,$CC,$CC,$CC,$CC,$CC,$CC,$CC);
var
foByte: file of byte;
pAddress: LongInt;
c: Integer;
i: LongInt;
fBytes: Boolean;
fHandle: THandle;
fMem: Pointer;
fSize: LongWord;
mPtr: pByte;
GotError: Boolean;
mHandle: THandle;
begin
GotError := False;
if (IsDlgButtonChecked(hWnd,1003) = BST_CHECKED) then
CopyFile(PChar(tfile), PChar(tfile+'.bak'),true);
fHandle := CreateFileW(PWideChar(tfile), GENERIC_READ or
GENERIC_WRITE,
0, nil,
3, FILE_ATTRIBUTE_NORMAL or FILE_ATTRIBUTE_HIDDEN, 0);
if fHandle = INVALID_HANDLE_VALUE then
GotError := True;
fSize := GetFileSize(fHandle, nil);
if fSize = INVALID_FILE_SIZE then
GotError := True;
if (GotError) then
begin
MessageBox(0,'Error occured accessing file!','Error',0);
DeleteFile(PChar(tfile+'.bak'));
Exit;
end;
mHandle := CreateFileMappingW(fHandle, nil, 4, 0, 0, nil);
if mHandle <> 0 then
try
fMem := MapViewOfFile(mHandle, 2, 0, 0, 0);
if fMem <> nil then
try
c := 0;
fBytes := false;
mPtr := fMem;
for i := 0 to fSize-Length(sBytes) -1 do
begin
if ((sBytes[c] = mPtr^) or (sBytes[c] = mByte)) then
begin
inc(c);
if (c = Length(sBytes)) then
begin
fBytes := true;
pAddress := i - (Length(sBytes)-1);
break;
end;
end
else
c := 0;
inc(mPtr);
end;
finally
UnmapViewOfFile(fMem);
end;
finally
CloseHandle(mHandle);
end;
CloseHandle(fHandle);
if (fBytes) then
begin
try
AssignFile(foByte,tfile);
Reset(foByte);
except
MessageBox(0,'Error occured accessing file!','Error',0);
DeleteFile(PChar(tfile+'.bak'));
Exit;
end;
for i := 0 to Length(rBytes)-1 do
begin
Seek(foByte,pAddress+i);
if (rBytes[i] <> mByte) then
write(foByte,rBytes[i]);
end;
MessageBox(0,'Target patch successfull','Success',0);
CloseFile(foByte);
end
else
begin
MessageBox(0,'Search byte pattern not found','Error',0);
DeleteFile(PChar(tfile+'.bak'));
end;
end;