Delphi-PRAXiS
Seite 5 von 5   « Erste     345   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi File patchen (https://www.delphipraxis.net/132027-file-patchen.html)

KodeZwerg 27. Jan 2023 12:03

AW: File patchen
 
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 :thumb:

Andreas13 27. Jan 2023 12:49

AW: File patchen
 
Vielen-viele Dank für Deine Hilfe & Mühe, KodeZwerg! :-D :thumb: :angel:
Aber eine Frag habe ich immer noch: An welchem Befehl liegt es im Code, daß ich es bei mir immer noch nach höheren Rechten verlangt und sich von der IDE nicht starten läßt?

Grüße, Andreas

KodeZwerg 27. Jan 2023 12:53

AW: File patchen
 
Liste der Anhänge anzeigen (Anzahl: 1)
Zitat:

Zitat von Andreas13 (Beitrag 1517949)
Vielen-viele Dank für Deine Hilfe & Mühe, KodeZwerg! :-D :thumb: :angel:
Aber eine Frag habe ich immer noch: An welchem Befehl liegt es im Code, daß ich es bei mir immer noch nach höheren Rechten verlangt und sich von der IDE nicht starten läßt?

Grüße, Andreas

Geh in der IDE unter Project -> Options -> Manifest und aktiviere "Auto Generate" und schalte Execution Level auf "AsInvoker".

Andreas13 27. Jan 2023 13:05

AW: File patchen
 
Zitat:

Geh in der IDE unter Project -> Options -> Manifest und aktiviere "Auto Generate" und schalte Execution Level auf "AsInvoker".
Diese Option ist in XE5 (noch) nicht vorhanden, oder ganz woanders versteckt. Bin noch auf der Suche ... :oops:

KodeZwerg 27. Jan 2023 13:20

AW: File patchen
 
Liste der Anhänge anzeigen (Anzahl: 1)
Ok, nur keine Panik! :lol:
Im Anhang ist eine .res datei namens "AsInvoker.res", kopiere diese in dein Projekt Verzeichnis.
Ändere das hier
Delphi-Quellcode:
{$R *.res}
nach das hier
Delphi-Quellcode:
{$R AsInvoker.res}

Theoretisch sollte es funktionieren aber da ich kein XE besitze kann ich es nicht überprüfen!

Andreas13 27. Jan 2023 13:33

AW: File patchen
 
Toll! Es funktioniert mit
Delphi-Quellcode:
{$R AsInvoker.res}
von der IDE aus. Und auch von der Kommandozeile werden "keine höheren Rechte" mehr eingefordert!
Danke KodeZwerg! :-D :thumb:

Viele Grüße
Andreas

KodeZwerg 27. Jan 2023 14:06

AW: File patchen
 
Zitat:

Zitat von Andreas13 (Beitrag 1517963)
Toll! Es funktioniert

Nice! Es freut mich das du happy bist, viel Spaß mit dem ganzen :angel:


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:06 Uhr.
Seite 5 von 5   « Erste     345   

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