Thema: Delphi File patchen

Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.691 Beiträge
 
Delphi 11 Alexandria
 
#41

AW: File patchen

  Alt 27. Jan 2023, 12:03
Hier das ganze nochmal, sorry keine UI, alles unter der Console.
Als Ziel nahm ich einfach mein vorigen Post als Kompilat in der Hoffnung das er bei Dir exakt so ist wie bei mir.
Delphi-Quellcode:
program Patcher;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils, System.Classes;

const
  CFName = string('Patch.exe');
  CFSize = UInt64(58880);
  CPatches = UInt64($23);
  COffsets: array[0..CPatches] of UInt64 = ($50,$51,$52,$53,$54,$55,$56,$57,$58,$59,$5A,$5B,$5C,$5D,$5E,$5F,$60,$61,$62,$63,$64,$65,$66,$67,$68,$69,$6A,$6B,$6C,$6D,$6E,$6F,$70,$71,$72,$73);
  //This program must be run under Win32
  COrgBytes: array[0..CPatches] of Byte = ($54,$68,$69,$73,$20,$70,$72,$6f,$67,$72,$61,$6d,$20,$6d,$75,$73,$74,$20,$62,$65,$20,$72,$75,$6e,$20,$75,$6e,$64,$65,$72,$20,$57,$69,$6e,$33,$32);
  //Hier steht jetzt etwas total cooles!
  CNewBytes: array[0..CPatches] of Byte = ($48,$69,$65,$72,$20,$73,$74,$65,$68,$74,$20,$6a,$65,$74,$7a,$74,$20,$65,$74,$77,$61,$73,$20,$74,$6f,$74,$61,$6c,$20,$63,$6f,$6f,$6c,$65,$73,$21);

var
  fs: TFileStream;
  FName: string;
  i: Integer;
  b: Byte;
  Org, New, Diff: UInt64;
begin
  FName := ExtractFilePath(ParamStr(0)) + CFName;
  if (not FileExists(FName)) then
    begin
      WriteLn(FName + ' not found!');
      ReadLn;
      Exit;
    end;
  try
    fs := TFileStream.Create(FName, fmOpenReadWrite or fmShareExclusive);
    try
      Org := 0; New := 0; Diff := 0;
      if (fs.Size <> CFSize) then
        begin
          WriteLn('Wrong Filesize!');
          ReadLn;
          Exit;
        end;
      for i := 0 to CPatches do
        begin
          fs.Position := COffsets[i];
          fs.Read(b, 1);
          if (b = COrgBytes[i]) then
            Inc(Org);
          if (b = CNewBytes[i]) then
            Inc(New);
          if ((b <> COrgBytes[i]) and (b <> CNewBytes[i])) then
            Inc(Diff);
        end;
      if Org = Succ(CPatches) then
        begin
          for i := 0 to CPatches do
            begin
              fs.Position := COffsets[i];
              fs.Write(CNewBytes[i], 1);
            end;
          WriteLn('Patch applied!');
        end;
      if New = Succ(CPatches) then
        begin
          for i := 0 to CPatches do
            begin
              fs.Position := COffsets[i];
              fs.Write(COrgBytes[i], 1);
            end;
          WriteLn('Patch removed!');
        end;
      if Diff <> 0 then
        WriteLn('Wrong Version!');
    finally
      fs.Free;
    end;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  ReadLn;
end.
Ich hoffe das es Dir hilft, so jedenfalls sieht bei mir ein simpler Byte-Patcher aus.
Falls es noch Fragen gibt, nur keine Scheu
Gruß vom KodeZwerg

Geändert von KodeZwerg (27. Jan 2023 um 12:06 Uhr)
  Mit Zitat antworten Zitat