Skip to content

Instantly share code, notes, and snippets.

@Barakat
Created January 19, 2019 08:29
Show Gist options
  • Save Barakat/eeff552350e69fbb5dccc364c5685a73 to your computer and use it in GitHub Desktop.
Save Barakat/eeff552350e69fbb5dccc364c5685a73 to your computer and use it in GitHub Desktop.
Visual Studio 2005 CRT imports IsDebuggerPresent which is missing on Windows 95. This is a workaround, compile the following code as static library and pass it to the linker before kernel32.lib
.386
.model flat
extern _IsDebuggerPresentProxy@0:proc
public __imp__IsDebuggerPresent@0
public _IsDebuggerPresent@0
.data
__imp__IsDebuggerPresent@0 dd flat:_IsDebuggerPresent@0
.code
_IsDebuggerPresent@0:
jmp _IsDebuggerPresentProxy@0
end
#include "stdafx.h" // Includes Windows.h
EXTERN_C BOOL WINAPI IsDebuggerPresentProxy()
{
HMODULE kernel32 = LoadLibraryA("KERNEL32.DLL");
if (kernel32)
{
typedef BOOL (WINAPI *IsDebuggerPresent_t)();
IsDebuggerPresent_t is_debugger_present = reinterpret_cast<IsDebuggerPresent_t>(
GetProcAddress(kernel32, "IsDebuggerPresent")
);
BOOL debugger_present = FALSE;
// KERNEL32.IsDebuggerPresent is missing on Windows 95
if (is_debugger_present)
{
debugger_present = is_debugger_present();
}
FreeLibrary(kernel32);
return debugger_present;
}
return FALSE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment