Re: File patchen
Du musst das doch nur exakt wie in ScanFile schon gezeigt machen. Nur eben statt nur suchen ggf. auch ersetzen. :gruebel:
Wobei ich mich allerdings frage was für einen Sinn das hat. Außer um einen Virus zu schreiben. Denn schließlich bringt das ja keinerlei Vorteil für die Sicherheit oder Benutzung des Systems, verhindert aber ggf. die Reparatur des Systems. |
Re: File patchen
Zitat:
Der KIOSK PC läuft in einer virtuellen Maschine, daher muss F8 ausser Kraft gesetzt werden ! Die Information mit der F8 Taste kommt selbstverständlich von Microsoft und ist eigentlich nicht für Virenhersteller gedacht. Die Reparatur des System erfolgt ggf. durch Barts PE :zwinker: KUBA |
Re: File patchen
Zitat:
Trotzdem: es ist wie gesagt ja eigentlich fast nichts zu ändern im Vergleich zu dem verlinkten ScanFile. :gruebel: Hier mal eine Version, die auch für Delphi 2009 eine byteweise Ersetzung mittels AnsiStrings zulässt. 3 Zeilen und ein Parameter sind neu und eine Zeile geändert, sonst nur String durch AnsiString und PChar durch PAnsiChar ersetzt.
Delphi-Quellcode:
function ReplaceInFile(const FileName, SearchString, NewString: AnsiString;
CaseSensitive: Boolean): Longint; { returns position of string in file or -1, if not found } const BufferSize = $8001; { 32K+1 bytes } var pBuf, pEnd, pScan, pPos: PAnsiChar; filesize: LongInt; bytesRemaining: LongInt; bytesToRead: Integer; F: file; SearchFor: PAnsiChar; oldMode: Word; begin Result := -1; { assume failure } // NEW (first line): if length of string to search and new string does not match, cancel. // Of course one could move the rest of the file accordingly instead. if (Length(SearchString) <> Length(NewString)) or (Length(SearchString) = 0) or (Length(FileName) = 0) then Exit; SearchFor := nil; pBuf := nil; { open file as binary, 1 byte recordsize } AssignFile(F, FileName); oldMode := FileMode; FileMode := fmOpenReadWrite; { NEW: access to read and write } Reset(F, 1); FileMode := oldMode; try { allocate memory for buffer and pchar search string } SearchFor := StrAlloc(Length(SearchString) + 1); StrPCopy(SearchFor, SearchString); if not caseSensitive then { convert to upper case } AnsiUpper(SearchFor); GetMem(pBuf, BufferSize); filesize := System.Filesize(F); bytesRemaining := filesize; pPos := nil; while bytesRemaining > 0 do begin { calc how many bytes to read this round } if bytesRemaining >= BufferSize then bytesToRead := Pred(BufferSize) else bytesToRead := bytesRemaining; { read a buffer full and zero-terminate the buffer } BlockRead(F, pBuf^, bytesToRead, bytesToRead); pEnd := @pBuf[bytesToRead]; pEnd^ := #0; { scan the buffer. Problem: buffer may contain #0 chars! So we treat it as a concatenation of zero-terminated strings. } pScan := pBuf; while pScan < pEnd do begin if not caseSensitive then { convert to upper case } AnsiUpper(pScan); pPos := StrPos(pScan, SearchFor); { search for substring } if pPos <> nil then begin { Found it! } Result := FileSize - bytesRemaining + Longint(pPos) - Longint(pBuf); // NEW: replace it Seek(F, Result); BlockWrite(F, PAnsiChar(NewString)^, Length(NewString)); Break; end; pScan := StrEnd(pScan); Inc(pScan); end; if pPos <> nil then Break; bytesRemaining := bytesRemaining - bytesToRead; if bytesRemaining > 0 then begin { no luck in this buffers load. We need to handle the case of the search string spanning two chunks of file now. We simply go back a bit in the file and read from there, thus inspecting some characters twice } Seek(F, FilePos(F) - Length(SearchString)); bytesRemaining := bytesRemaining + Length(SearchString); end; end; { While } finally CloseFile(F); if SearchFor <> nil then StrDispose(SearchFor); if pBuf <> nil then FreeMem(pBuf, BufferSize); end; end; { ScanFile } |
Re: File patchen
Liste der Anhänge anzeigen (Anzahl: 1)
Hallo,
vielen, vielen Dank !!! Es funktioniert prima, anbei der "Patcher" KUBA :cheers: PS: winexec ersetzt durch FileSetReadOnly('c:\ntldr', False); |
Re: File patchen
Zitat:
kuba |
Re: File patchen
Na hast du natürlich Recht.
Nur nebenbei: Kennst oder benutzt du eigentlich schon Windows SteadyState? http://www.microsoft.com/windows/pro...s/default.mspx Das hilft beim Einrichten eines solchen öffentlichen PCs ja sehr viel weiter und ist ja kostenlos. |
Re: File patchen
Zitat:
KUBA PS: ist ja auch kostenlos :zwinker: |
Re: File patchen
Ich hoffe du weißt den Benutzer auch daraufhin, dass du original Systemdateien manipulierst. Ich würde solch eine Software nämlich nicht installieren.
|
Re: File patchen
Hi,
wäre noch schön, wenn Du anstatt WinExec ShellExecute benutzt, WinExec ist mittlerweile veraltet. |
Re: File patchen
Dass WinExec veraltet ist, ist sicher richtig, schon seit 14 Jahren, aber wo steht hier im Thread etwas davon? :wiejetzt:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:56 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz