I just wanted to be notified, when a process is to be created. I tried the following :
{main}
Code: Select all
procedure NotifyProc(name : pchar;
messageBuf : pointer; messageLen : dword;
answerBuf : pointer; answerLen : dword); stdcall;
begin
showmessage(pchar(messageBuf^));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
CreateIpcQueueEx('EsLogin',NotifyProc);
if InjectLibrary(ALL_SESSIONS,'EsLoginHook.dll') then showmessage('injected');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
UninjectLibrary(ALL_SESSIONS,'EsLoginHook.dll');
end;
Code: Select all
var
CreateProcessANext : function (appName, cmdLine: pchar;
processAttr, threadAttr: PSecurityAttributes;
inheritHandles: bool; creationFlags: dword;
environment: pointer; currentDir: pchar;
const startupInfo: TStartupInfo;
var processInfo: TProcessInformation) : bool; stdcall;
CreateProcessWNext : function (appName, cmdLine: pwidechar;
processAttr, threadAttr: PSecurityAttributes;
inheritHandles: bool; creationFlags: dword;
environment: pointer; currentDir: pwidechar;
const startupInfo: TStartupInfo;
var processInfo: TProcessInformation) : bool; stdcall;
WinExecNext : function (cmdLine: pchar; show: dword) : dword; stdcall;
function CreateProcessACallback(appName, cmdLine: pchar;
processAttr, threadAttr: PSecurityAttributes;
inheritHandles: bool; creationFlags: dword;
environment: pointer; currentDir: pchar;
const startupInfo: TStartupInfo;
var processInfo: TProcessInformation) : bool; stdcall;
begin
SendIpcMessage('EsLogin', cmdLine, Length(cmdLine));
result := CreateProcessANext(appName, cmdLine, processAttr, threadAttr,
inheritHandles, creationFlags,
environment, currentDir,
startupInfo, processInfo);
RenewHook(@CreateProcessANext);
end;
function CreateProcessWCallback(appName, cmdLine: pwidechar;
processAttr, threadAttr: PSecurityAttributes;
inheritHandles: bool; creationFlags: dword;
environment: pointer; currentDir: pwidechar;
const startupInfo: TStartupInfo;
var processInfo: TProcessInformation) : bool; stdcall;
begin
SendIpcMessage('EsLogin', cmdLine, Length(cmdLine));
result := CreateProcessWNext(appName, cmdLine, processAttr, threadAttr,
inheritHandles, creationFlags,
environment, currentDir,
startupInfo, processInfo);
RenewHook(@CreateProcessWNext);
end;
function WinExecCallback(cmdLine: pchar; show: dword) : dword; stdcall;
begin
SendIpcMessage('EsLogin', cmdLine, Length(cmdLine));
result := WinExecNext(cmdLine, show);
RenewHook(@WinExecNext);
end;
// ***************************************************************
begin
HookAPI('kernel32.dll', 'CreateProcessA', @CreateProcessACallback, @CreateProcessANext);
HookAPI('kernel32.dll', 'CreateProcessW', @CreateProcessWCallback, @CreateProcessWNext);
HookAPI('kernel32.dll', 'WinExec', @WinExecCallback, @WinExecNext );
end.
What do i do wrong?