was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

84 Visitors Online


 
...eine Funktion hooken (in eigener App)?
Autor: Thomas Stutz
[ Tip ausdrucken ]  

Tip Bewertung (13):  
     



type
  
TSaveRedir = packed record
    
Addr: Pointer;
    Bytes: array[0..4] of Byte;
  end;
  PSaveRedir = ^TSaveRedir;

procedure RedirectCall(FromAddr, ToAddr: Pointer; SaveRedir: PSaveRedir);
var
  
OldProtect: Cardinal;
  NewCode: packed record
    
JMP: Byte;
    Distance: Integer;
  end;
begin
  if not 
VirtualProtect(FromAddr, 5, PAGE_EXECUTE_READWRITE, OldProtect) then
    
RaiseLastWin32Error;
  if Assigned(SaveRedir) then
  begin
    
SaveRedir^.Addr := FromAddr;
    Move(FromAddr^, SaveRedir^.Bytes, 5);
  end;
  NewCode.JMP := $E9;
  NewCode.Distance := PChar(ToAddr) - PChar(FromAddr) - 5;
  Move(NewCode, FromAddr^, 5);
  if not VirtualProtect(FromAddr, 5, OldProtect, OldProtect) then
    
RaiseLastWin32Error;
end;

procedure UndoRedirectCall(const SaveRedir: TSaveRedir);
var
  
OldProtect: Cardinal;
begin
  if not 
VirtualProtect(SaveRedir.Addr, 5, PAGE_EXECUTE_READWRITE, OldProtect) then
    
RaiseLastWin32Error;
  Move(SaveRedir.Bytes, SaveRedir.Addr^, 5);
  if not VirtualProtect(SaveRedir.Addr, 5, OldProtect, OldProtect) then
    
RaiseLastWin32Error;
end;


// Example: Replace Application.MessageBox with your own.

function MyNewMessageBox(Self: TApplication; const Text, Caption: PChar;
  Flags: Longint): Integer;
begin
  
ShowMessage('New Messagebox');
  //....
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  
Application.MessageBox('You'll never see this Text /
    Diesen Text wirst du nie sehen', '...', MB_OK);
end;

var
  
S: TSaveRedir;

initialization
  
RedirectCall(@TApplication.MessageBox, @MyNewMessageBox, @S);

finalization
  
UndoRedirectCall(S);

 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners