Skip to content

Instantly share code, notes, and snippets.

@evernick
Created June 18, 2015 08:53
Show Gist options
  • Save evernick/fb3c194fcc18b910c2f6 to your computer and use it in GitHub Desktop.
Save evernick/fb3c194fcc18b910c2f6 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <windows.h>
#include <tlhelp32.h>
#include <psapi.h>
#pragma comment(lib, "psapi.lib")
int GetProcssName(DWORD PID, char *buff, int size)
{
int len = 0;
HANDLE hProc = NULL;
if ( (hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, PID)) != NULL)
{
len = GetModuleBaseName(hProc, NULL, buff, size);
CloseHandle (hProc);
}
return len;
}
bool anti_debug()
{
int pid = -1, len;
HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pe = { 0 };
char name[100];
pe.dwSize = sizeof(PROCESSENTRY32);
pid = GetCurrentProcessId();
if( Process32First(h, &pe)) {
do {
if (pe.th32ProcessID == pid) {
break;
}
} while( Process32Next(h, &pe));
}
CloseHandle(h);
len = GetProcssName(pe.th32ParentProcessID, name, sizeof(name)-1);
name[len]=0;
if(!memcmp(name, "Olly",4)){
return 1;
}
return 0;
}
int main(int argc, char **argv)
{
if(anti_debug())
printf("Debugger Detected\n");
else
printf("No Debugger...\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment