Mega Code Archive

 
Categories / Delphi / Examples
 

How to detect if an application is being debugged

Have you ever wondered if the user is trying to debug your application? Don?t count on getting feedback from that user, but a registration code, crack, and/or key generator are more likely. Let?s face it: if the user debugging your application is not part of development or testing team chances are he or she is trying to crack it. Of course, your users may feel committed to helping create bug-free programs but don?t count on it =) There is no need for sophisticated assembly code or any self-written routines. All you need is pretty much provided by Windows API. IsDebuggerPresent() is supported by Windows 98, ME, and of course all new versions of Windows based on the NT kernel (2000, XP). Just call IsDebuggerPresent() and you can use the result of this function to change the behavior of your application if a debugger is present. Also keep in mind that procedure names are stored in the executable, so you might want to change to name of IsDebuggerPresent() to something less obvious like UpdateEditor() or CalculateArray(). function DebuggerPresent : boolean; type TDebugProc = function : boolean; stdcall; var Kernel32: HMODULE; DebugProc: TDebugProc; begin { DebuggerPresent } Result := False; Kernel32 := GetModuleHandle('kernel32'); if Kernel32<>0 then begin @DebugProc := GetProcAddress(Kernel32, 'IsDebuggerPresent'); if Assigned(DebugProc) then Result := DebugProc end; { Kernel32<>0 } end; { DebuggerPresent }