Einzelnen Beitrag anzeigen

Benutzerbild von Zacherl
Zacherl

Registriert seit: 3. Sep 2004
4.629 Beiträge
 
Delphi 10.2 Tokyo Starter
 
#18

AW: Hooken der RecvFrom() Methode mittels uALLCollection

  Alt 9. Jun 2010, 14:34
Aber beim AppSniffer gibt es doch auch keine Probleme.
Versuch testweise vielleicht mal eine andere Hooking Unit.
Was benutzt der AppSniffer denn zum hooken? Da du außer den Hook & Unhook Funktionen nichts anderes aufrufst, scheint es da wohl mit der uallHook Unit irgendwie Probleme geben. Das Teil hat früher bei mir immer gut funktioniert, aber probier einfach mal meine eigenen Hooking Funktionen aus:
Delphi-Quellcode:
function HookCodeInline(SourceFunction, CallbackFunction: Pointer;
  var OldFunction: Pointer): Boolean;
function UnhookCodeInline(var OldFunction: Pointer): Boolean;
function IsInlineHooked(Address: Pointer): Boolean;
Delphi-Quellcode:
type
  TJumpCode = packed record
    Push: Byte;
    Addr: Pointer;
    Ret: Byte;
  end;

function HookCodeInline(SourceFunction, CallbackFunction: Pointer;
  var OldFunction: Pointer): Boolean;
var
  HDE: hde32s;
  JumpCode: TJumpCode;
  dwAllocSize,
  dwOldProtect: DWord;
begin
  Result := false;
  if (not Assigned(SourceFunction)) or (not Assigned(CallbackFunction)) then
    Exit;
  // Anzahl der Bytes ermitteln
  dwAllocSize := 0;
  repeat
    HDE32.hde32_disasm(Pointer(Cardinal(SourceFunction) + dwAllocSize), HDE);
    Inc(dwAllocSize, HDE.len);
  until dwAllocSize >= SizeOf(TJumpCode);
  // JumpCode initialisieren
  JumpCode.Push := $68;
  JumpCode.Ret := $C3;
  // Code Protection ändern
  if not VirtualProtect(SourceFunction, dwAllocSize, PAGE_EXECUTE_READWRITE,
    dwOldProtect) then
    Exit;
  try
    // Speicher für die neue Funktion alloziieren
    OldFunction := VirtualAlloc(nil, dwAllocSize + SizeOf(TJumpCode),
      MEM_COMMIT or MEM_RESERVE, PAGE_EXECUTE_READWRITE);
    if not Assigned(OldFunction) then
      Exit;
    // Alte Opcodes sichern
    CopyMemory(OldFunction, SourceFunction, dwAllocSize);
    JumpCode.Addr := Pointer(DWord(SourceFunction) + dwAllocSize);
    CopyMemory(Pointer(DWord(OldFunction) + dwAllocSize), @JumpCode, SizeOf(
      TJumpCode));
    // Originalfunktion hooken
    JumpCode.Addr := CallbackFunction;
    CopyMemory(SourceFunction, @JumpCode, SizeOf(TJumpCode));
    Result := true;
  except
    // Speicher freigeben
    VirtualFree(OldFunction, dwAllocSize + SizeOf(TJumpCode), MEM_RELEASE);
  end;
  // Code Protection wiederherstellen
  VirtualProtect(SourceFunction, SizeOf(TJumpCode), dwOldProtect, dwOldProtect);
end;

function UnhookCodeInline(var OldFunction: Pointer): Boolean;
var
  HDE: hde32s;
  JumpCode: TJumpCode;
  dwAllocSize,
  dwOldProtect: DWord;
begin
  Result := false;
  if not Assigned(OldFunction) then
    Exit;
  // Anzahl der Bytes ermitteln
  dwAllocSize := 0;
  repeat
    HDE32.hde32_disasm(Pointer(Cardinal(OldFunction) + dwAllocSize), HDE);
    Inc(dwAllocSize, HDE.len);
  until dwAllocSize >= SizeOf(TJumpCode);
  // Originalfunktion ermitteln
  CopyMemory(@JumpCode, Pointer(DWord(OldFunction) + dwAllocSize), SizeOf(
    TJumpCode));
  if (JumpCode.Push <> $68) or (JumpCode.Ret <> $C3) then
    Exit;
  // Code Protection ändern
  if (not VirtualProtect(Pointer(DWord(JumpCode.Addr) - dwAllocSize), SizeOf(
    TJumpCode), PAGE_EXECUTE_READWRITE, dwOldProtect)) then
    Exit;
  // Opcode wiederherstellen
  CopyMemory(Pointer(DWord(JumpCode.Addr) - dwAllocSize), OldFunction, SizeOf(
    TJumpCode));
  // Code Protection wiederherstellen
  Result := VirtualProtect(Pointer(DWord(JumpCode.Addr) - dwAllocSize), SizeOf(
    TJumpCode), dwOldProtect, dwOldProtect);
  // Speicher freigeben
  VirtualFree(OldFunction, dwAllocSize + SizeOf(TJumpCode), MEM_RELEASE);
  OldFunction := nil;
end;

function IsInlineHooked(Address: Pointer): Boolean;
var
  JumpCode: TJumpCode;
begin
  CopyMemory(@JumpCode, Address, SizeOf(TJumpCode));
  Result := (JumpCode.Push = $68) or (JumpCode.Ret = $C3);
end;
Du brauchst außerdem noch die HDE32.pas und HDE32.obj, die du im Anhang findest.
Angehängte Dateien
Dateityp: rar HDE32.rar (2,0 KB, 31x aufgerufen)
  Mit Zitat antworten Zitat