8

How can I detect if my application is running under the IDE "Delphi 2007 .Net", there is something like DebugHook?

Bye.

RRUZ
  • 134,889
  • 20
  • 356
  • 483

6 Answers6

6

Answer my own question.

uses System.Diagnostics; 

function IDEDelphiNetRunning:Boolean; 
Begin 
Result:=Debugger.IsAttached; 
End; 

works fine for me.

Bye.

RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • So this would detect if IDE is attached to process, but not if a hacker switched process CPU mode to debug ? – nurettin May 10 '18 at 09:08
4

The IsDebuggerPresent() WinAPI call.

Icebob
  • 1,132
  • 7
  • 14
  • This isn't really an answer to the question though, as running the application under Delphi and running it under any other debugger can not be distinguished this way. Maybe that's not important for the OP, but the question should have been worded differently then. Also there is Debugger.IsAttached in System.Diagnostics, no need to call the Windows API. – mghie Jun 30 '09 at 04:18
4

Something like:

Function IDEIsRunning : boolean;
begin
  result := DebugHook <> 0;
end;

Might Suit.

Alister
  • 6,527
  • 4
  • 46
  • 70
  • Alister, DebugHook does not exist in "Delphi 2007.Net", so look for some alternative. – RRUZ Jun 30 '09 at 03:39
  • Well, I was searching for how to do exactly the same thing as OP... but in Delphi 5. So naturally this worked perfectly for me. :) +1 – Disillusioned Jun 14 '10 at 15:10
3

The JEDI JclDebug.pas unit contains the following:

function IsDebuggerAttached: Boolean;
var
  IsDebuggerPresent: function: Boolean; stdcall;
  KernelHandle: THandle;
  P: Pointer;
begin
  KernelHandle := GetModuleHandle(kernel32);
  @IsDebuggerPresent := GetProcAddress(KernelHandle, 'IsDebuggerPresent');
  if @IsDebuggerPresent <> nil then
  begin
    // Win98+ / NT4+
    Result := IsDebuggerPresent
  end
  else
  begin
    // Win9x uses thunk pointer outside the module when under a debugger
    P := GetProcAddress(KernelHandle, 'GetProcAddress');
    Result := DWORD(P) < KernelHandle;
  end;
end;
Kris De Decker
  • 669
  • 5
  • 8
1

I found this more general answer, from embarcadero

Use the IsDebuggerPresent() WinAPI call. Example in C++:

if (IsDebuggerPresent())
    Label1->Caption = "debug";
else
    Label1->Caption = "no debug";
Roman Marusyk
  • 23,328
  • 24
  • 73
  • 116
fvel
  • 189
  • 2
  • 7
-5
function IsDebugMode():Boolean;
begin
  Result:=False;
 {$IFDEF DEBUG}
  Result:=True;
 {$ENDIF}
end;
SuatDmk
  • 1
  • 1
  • 3
    This does not tell you if you're running under the debugger. It simply tells you if DEBUG was defined at compile time. So you've posted a totally incorrect answer to a 6 year old question that already had multiple correct answers existing. – Ken White May 23 '16 at 14:48