static void TestCreateSuspendedProcessAndInjectDll(string cmdLine, string dllName) { DeviareLiteInterop.HookLib.STARTUPINFO si; DeviareLiteInterop.HookLib.ProcessInfo pi; uint exitCode; pi.threadHandle = null; MessageBox.Show("Launching suspended NOTEPAD, injecting DLL and resume\r\r(close Notepad to next test)", "Dll Inject Test", MessageBoxButtons.OK); try { si = new DeviareLiteInterop.HookLib.STARTUPINFO(); pi = cHook.CreateProcess(cmdLine, "", null, null, false, DeviareLiteInterop.HookLib.ProcessCreationFlags.CREATE_SUSPENDED, null, null, si); cHook.InjectDll(pi.procId, dllName, ""); cHook.ResumeThread(pi.threadHandle); WaitForSingleObject(pi.procHandle.DangerousGetHandle(), 0xFFFFFFFF); } catch (Exception ex) { if (pi.threadHandle != null && pi.threadHandle.IsInvalid == false) { cHook.ResumeThread(pi.threadHandle); } MessageBox.Show("Couldn't complete operation\r\rError: " + ex.ToString(), "Dll Inject Test", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void TestCreateProcessWithDll(string cmdLine, string dllName) { DeviareLiteInterop.HookLib.STARTUPINFO si; DeviareLiteInterop.HookLib.ProcessInfo pi; MessageBox.Show("Launching CALC with a DLL injected\r\r(close Calc to next test)", "Dll Inject Test", MessageBoxButtons.OK); try { si = new DeviareLiteInterop.HookLib.STARTUPINFO(); pi = cHook.CreateProcessWithDll(cmdLine, "", null, null, false, 0, null, null, si, dllName); WaitForSingleObject(pi.procHandle.DangerousGetHandle(), 0xFFFFFFFF); } catch (Exception ex) { MessageBox.Show("Couldn't complete operation\r\rError: " + ex.ToString(), "Dll Inject Test", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void TestCreateProcessAndInjectDll(string cmdLine, string dllName) { DeviareLiteInterop.HookLib.STARTUPINFO si; DeviareLiteInterop.HookLib.ProcessInfo pi; MessageBox.Show("Launching CALC and injecting DLL after startup\r\r(close Calc to next test)", "Dll Inject Test", MessageBoxButtons.OK); try { si = new DeviareLiteInterop.HookLib.STARTUPINFO(); pi = cHook.CreateProcess(cmdLine, "", null, null, false, 0, null, null, si); System.Threading.Thread.Sleep(1000); //sleep for a while in order to let the process initialize properly cHook.InjectDll(pi.procId, dllName); WaitForSingleObject(pi.procHandle.DangerousGetHandle(), 0xFFFFFFFF); } catch (Exception ex) { MessageBox.Show("Couldn't complete operation\r\rError: " + ex.ToString(), "Dll Inject Test", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void TestCreateSuspendedProcessAndInjectDll(string cmdLine, string dllName) { DeviareLiteInterop.HookLib.STARTUPINFO si; DeviareLiteInterop.HookLib.ProcessInfo pi; pi.threadHandle = null; MessageBox.Show("Launching suspended CALC, injecting DLL and resume\r\r(close Calc to next test)", "Dll Inject Test", MessageBoxButtons.OK); try { si = new DeviareLiteInterop.HookLib.STARTUPINFO(); pi = cHook.CreateProcess(cmdLine, "", null, null, false, DeviareLiteInterop.HookLib.ProcessCreationFlags.CREATE_SUSPENDED, null, null, si); cHook.InjectDll(pi.procId, dllName); cHook.ResumeThread(pi.threadHandle); WaitForSingleObject(pi.procHandle.DangerousGetHandle(), 0xFFFFFFFF); } catch (Exception ex) { if (pi.threadHandle != null && pi.threadHandle.IsInvalid == false) cHook.ResumeThread(pi.threadHandle); MessageBox.Show("Couldn't complete operation\r\rError: " + ex.ToString(), "Dll Inject Test", MessageBoxButtons.OK, MessageBoxIcon.Error); } }