procedure TForm1.FormCreate(Sender: TObject);
const
sMutx:string = '%sMUTEX';
sPreFix:String = 'MAMA'; //this is a custom name
var
sBuffer:array[0..511] of Byte;
hHandle:Cardinal;
pPointer:Pointer;
si:TStartupInfo;
Pi:TProcessInformation;
dDebug:TDebugEvent;
begin
//The whole following code is a recode of ARMadillo's Debug Blocker
//======================================================================
//Couldnt managee to get it work with Delphi Code so used Inline ASM
asm
push sPreFix
push sMutx
lea eax, sBuffer[0]
push eax
call wsprintf
end;
//Use OpenMutex to check if Mutex is existing
hHandle := OpenMutex(MUTEX_ALL_ACCESS,False,@sBuffer[0]);
if hHandle <> 0 then
CloseHandle(hHandle)
else begin
CreateMutex(nil,False,@sBuffer[0]); //Create Mutex to show that we are the parentprocess
pPointer := GetCommandLine; //Get own File Path
ZeroMemory(@si,SizeOf(si)); //Needed for CreateProcess
if CreateProcess(nil,pPointer,nil,nil,False,DEBUG_PROCESS,nil,nil,si,Pi) then begin //Create own Process with Debug-Access
repeat
WaitForDebugEvent(dDebug,INFINITE); //Needed for Debugee
if dDebug.dwDebugEventCode = EXIT_PROCESS_DEBUG_EVENT then begin
ExitProcess(0); //Exit own Process if the Debugged Process exists
end;
ContinueDebugEvent(dDebug.dwProcessId,dDebug.dwThreadId,DBG_CONTINUE);
until 1 = 3;
end;
end;
//Add here your Code (Start of the Code)
end;