Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DarkCoderSc/9e2315127122a0df3c5227af95600fc3 to your computer and use it in GitHub Desktop.
Save DarkCoderSc/9e2315127122a0df3c5227af95600fc3 to your computer and use it in GitHub Desktop.
https://unprotect.it/technique/file-melt/ - (Author: Jean-Pierre LESUEUR (@DarkCoderSc)
program NtQueryProcessInformation;
{$APPTYPE CONSOLE}
{$R *.res}
uses
Winapi.Windows,
System.SysUtils;
function NtQueryInformationProcess(
ProcessHandle : THandle;
ProcessInformationClass : DWORD;
ProcessInformation : Pointer;
ProcessInformationLength : ULONG;
ReturnLength : PULONG
): LongInt; stdcall; external 'ntdll.dll';
// https://docs.microsoft.com/en-gb/windows/win32/api/winternl/nf-winternl-ntqueryinformationprocess
function isDebuggerPresent(): Boolean;
var hProcess : THandle;
APortNumber : DWORD;
ARetLen : Cardinal;
const ProcessDebugPort = 7;
begin
hProcess := GetCurrentProcess();
if hProcess = 0 then
Exit();
///
if NtQueryInformationProcess(hProcess, ProcessDebugPort, @APortNumber, sizeOf(DWORD), @ARetLen) <> ERROR_SUCCESS then
Exit();
result := APortNumber <> 0;
end;
begin
try
if isDebuggerPresent() then
raise Exception.Create('Debugger Detected !');
WriteLn('No Debugger Detected :)');
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
WriteLn('Press a return key to close application.');
ReadLn;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment