Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Library: Windows API / MS.NET Framework API (https://www.delphipraxis.net/20-library-windows-api-ms-net-framework-api/)
-   -   Delphi Debugger-Meldung "ntdll.DbgBreakPoint" verhindern (https://www.delphipraxis.net/20982-debugger-meldung-ntdll-dbgbreakpoint-verhindern.html)

Matze 26. Apr 2004 12:47


Debugger-Meldung "ntdll.DbgBreakPoint" verhindern
 
Es kann vorkommen, dass sich ein Programm einwandfrei kompillieren lässt, jedoch beim Start aus Delphi nach einiger Zeit das CPU-Fenster geöffnet wird.

Dort steht dann häufig
Zitat:

ntdll.DbgBreakPoint:

...
Dies liegt daran, da Microsoft in manchen Dlls die Funktion ntdll.DbgBreakPoint vergessen hat.

Microsoft hat ein paar Dlls versehentlich mit Debug-Informationen ausgeliefert, die noch Breakpoints enthalten, was der Debugger natürlich meldet.

Man muss in so einem Falle zur Laufzeit den Code patchen. ;)

Das macht man folgendermaßen:

Delphi-Quellcode:
procedure PatchINT3;
var
  NOP : Byte;
  NTDLL: THandle;
  BytesWritten: DWORD;
  Address: Pointer;
begin
  if Win32Platform <> VER_PLATFORM_WIN32_NT then Exit;
  NTDLL := GetModuleHandle('NTDLL.DLL');
  if NTDLL = 0 then Exit;
  Address := GetProcAddress(NTDLL, 'DbgBreakPoint');
  if Address = nil then Exit;
  try
    if Char(Address^) <> #$CC then Exit;

    NOP := $90;
    if WriteProcessMemory(GetCurrentProcess, Address, @NOP, 1, BytesWritten) and
      (BytesWritten = 1) then
      FlushInstructionCache(GetCurrentProcess, Address, 1);
  except
    //Do not panic if you see an EAccessViolation here, it is perfectly harmless! 
    on EAccessViolation do ;
    else raise;
  end;
end;

initialization

// nur wenn ein Debugger vorhanden, den Patch ausführen
if DebugHook<>0 then
   PatchINT3;

end.
Diesen Code hat shmia in diesem Thread veröffentlicht.


Alle Zeitangaben in WEZ +1. Es ist jetzt 03:16 Uhr.

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