determine if debugger is enabled/disabled

Share your advanced PureBasic knowledge/code with the community.
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

determine if debugger is enabled/disabled

Post by traumatic »

Somone on IRC asked if there's a way to determine whether the
debugger is being used or not. Since there's no "#compilerif-flag"
for this purpose, I came up with this:

Code: Select all

;
; returns #TRUE if debugger is enabled
; #FALSE otherwise
;
Procedure DebuggerEnabled()
  !if defined _PB_DEBUGGER_Control
  !mov eax, 1
  !else
  !mov eax, 0
  !end if
  ProcedureReturn
EndProcedure
Don't know, maybe it's useful to others as well (that's why I'm posting it here ;) ).
Good programmers don't comment their code. It was hard to write, should be hard to read.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Yes it is useful. As is, and for expanding knowledge/horizons.

Thanks. :)
@}--`--,-- A rose by any other name ..
dige
Addict
Addict
Posts: 1410
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Post by dige »

Great!!! That's exactly what Im looking for... Thank you :D
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

dige, didn't we meet on IRC lately? :lol:
Good programmers don't comment their code. It was hard to write, should be hard to read.
Fred
Administrator
Administrator
Posts: 18247
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

:lol:
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Another (generic) one :

Code: Select all

;
; Inline ASM enabled
;
Procedure TestDebugger()
  !RDTSC 
  XOR Ecx,Ecx 
  ADD Ecx,Eax 
  !RDTSC 
  SUB Eax,Ecx 
  CMP Eax,$96 
  JB l_testdebuggerfast
  ProcedureReturn 1 ; debugger present
  testdebuggerfast:
  ProcedureReturn 0 ; no debugger
EndProcedure
;
MessageRequester("", Str(TestDebugger()))
Seems to work for me.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Here on PB 3.94, AMD 64 proc, traumatic code reports correctly, gnozal code says 0 in all cases.
Last edited by netmaestro on Tue Feb 21, 2006 5:55 pm, edited 2 times in total.
BERESHEIT
Max.
Enthusiast
Enthusiast
Posts: 225
Joined: Fri Apr 25, 2003 8:39 pm

Post by Max. »

netmaestro wrote:Here on PB 3.94, AMD 64 proc, traumatic code reports correctly, gnozal code says 0 in all cases.
AFAIK, gnozal's code times execution speed (which is slower with enabled debuggers). You probably need to adjust the CMP Eax,$96 for a correct result, but probably it does not work with the PB debugger at all.
Athlon64 3800+ · 1 GB RAM · Radeon X800 XL · Win XP Prof/SP1+IE6.0/Firefox · PB 3.94/4.0
Intel Centrino 1.4 MHz · 1.5 GB RAM · Radeon 9000 Mobility · Win XP Prof/SP2+IE6.0/Firefox · PB 3.94/4.0
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

Well i did this:

Code: Select all

Procedure isdebugger()
label:
a=1
If PeekB(?label)=104
ProcedureReturn 1
EndIf
EndProcedure

MessageRequester(Str(isdebugger()),"")
It simply looks at the byte in memory @the label. If the debugger is there it adds some instructions between your own, and then the result isnt the same. This of course only works with the pb debugger, as f.ex ollydbg does not add such stuff.

To detect other debuggers you can use the api command IsDebuggerPresent_().. :

Code: Select all

If IsDebuggerPresent_()
MessageRequester("","Debugger is active!")
Else
MessageRequester("","No debugger")
EndIf
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

What if you want to keep other debuggers from attaching?
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

SFSxOI wrote:What if you want to keep other debuggers from attaching?
Please read what i post ;)
To detect other debuggers you can use the api command IsDebuggerPresent_().. :

Code:
If IsDebuggerPresent_()
MessageRequester("","Debugger is active!")
Else
MessageRequester("","No debugger")
EndIf
notice that its not hard to overrule that check so better hide it. And the api command isnt that hard to find, however its one method to get rid of totally newbie crackers.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

OK i see it now...duh! :)
Post Reply