AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

API Hook funktioniert nicht global

Ein Thema von Neutral General · begonnen am 18. Jan 2011 · letzter Beitrag vom 18. Jan 2011
 
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#1

API Hook funktioniert nicht global

  Alt 18. Jan 2011, 14:27
Hallo,

Das hier ist Teil 2 zu Kleine Verständnisfrage zu globalen Hooks.

Jetzt wollte ich eine API Funktion in der fremden Anwendung in der DLL hooken.
Und zwar so (PS: Ich muss nur in meine "Ersatzfunktion" springen. Ein Rücksprung in den Originalcode ist in meinem Fall nicht notwendig):

Delphi-Quellcode:
function HookIsClipboardFormatAvailable: Boolean;
var func: Pointer;
    hProc: THandle;
    jmp: TJump;
    bw: Cardinal;
begin
  func := GetProcPtr('user32.dll','IsClipboardFormatAvailable');

  hProc := GetCurrentProcess;
  try
    // VirtualProtect(func,4096,PAGE_EXECUTE_READWRITE,nil);
    jmp := Jump(@NewIsClipboardFormatAvailable);
    WriteProcessMemory(hProc,func,@jmp,SizeOf(TJump),bw);
    Result := bw = SizeOf(TJump);
  finally
    CloseHandle(hProc);
  end;
end;

function NewIsClipboardFormatAvailable(AFormat: Cardinal): BOOL; stdcall;
begin
  Result := true;
end;
Verwendete Funktionen/Typen:

Delphi-Quellcode:
type
  TJump = packed record
    Push: Byte;
    Dest: Pointer;
    Retn: Byte;
    Nops: Array[0..3] of Byte;
  end;

implementation

function Jump(ADest: Pointer): TJump;
begin
  Result.Push := $68;
  Result.Dest := ADest;
  Result.Retn := $C3;
  FillChar(Result.Nops[0],SizeOf(Result.Nops),$90);
end;

function GetProcPtr(ADll: String; AProc: String): Pointer;
var hLib: HModule;
begin
  hLib := LoadLibrary(PChar(ADll));
  if hLib <> 0 then
  begin
    try
      Result := GetProcAddress(hLib,PChar(AProc));
    finally
      FreeLibrary(hLib);
    end;
  end
  else
    Result := nil;
end;
Dieser Code funktioniert wenn ich ihn lokal aus meinem Prozess aufrufe und auch in meiner eigenen Anwendung per Hook. In fremden Anwendungen scheints aber nicht zu funktionieren (Originalfunktion wird scheinbar aufgerufen).

Allerdings liefert mir HookIsClipboardFormatAvailable in allen Prozessen true zurück. Bin jetzt etwas verwundert warum das nicht funktioniert.

Gruß
Neutral General
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:14 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz