mirror of https://github.com/dahall/Vanara.git
Minor tweaks to PR #386
parent
a9ff5e3c8f
commit
44d9c2a3b2
|
@ -68,13 +68,13 @@ namespace Vanara.PInvoke.Tests
|
||||||
[Test]
|
[Test]
|
||||||
public void DbgUiSetThreadDebugObjectAndNtRemoveProcessDebugTest()
|
public void DbgUiSetThreadDebugObjectAndNtRemoveProcessDebugTest()
|
||||||
{
|
{
|
||||||
Kernel32.STARTUPINFO StartInfo = new Kernel32.STARTUPINFO
|
Kernel32.STARTUPINFO StartInfo = new()
|
||||||
{
|
{
|
||||||
dwFlags = Kernel32.STARTF.STARTF_USESHOWWINDOW,
|
dwFlags = Kernel32.STARTF.STARTF_USESHOWWINDOW,
|
||||||
wShowWindow = (ushort)ShowWindowCommand.SW_HIDE
|
wShowWindow = (ushort)ShowWindowCommand.SW_HIDE
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.IsTrue(Kernel32.CreateProcess("notepad.exe", dwCreationFlags: Kernel32.CREATE_PROCESS.DEBUG_PROCESS | Kernel32.CREATE_PROCESS.CREATE_UNICODE_ENVIRONMENT, lpStartupInfo: StartInfo, lpProcessInformation: out Kernel32.SafePROCESS_INFORMATION Information));
|
Assert.That(Kernel32.CreateProcess(@"C:\Program Files\Notepad++\notepad++.exe", dwCreationFlags: Kernel32.CREATE_PROCESS.DEBUG_PROCESS | Kernel32.CREATE_PROCESS.CREATE_UNICODE_ENVIRONMENT, lpStartupInfo: StartInfo, lpProcessInformation: out Kernel32.SafePROCESS_INFORMATION Information), ResultIs.Successful);
|
||||||
|
|
||||||
using (Information)
|
using (Information)
|
||||||
using (NtQueryResult<IntPtr> DebugObjectHandleQueryResult = NtQueryInformationProcess<IntPtr>(Information.hProcess, PROCESSINFOCLASS.ProcessDebugObjectHandle))
|
using (NtQueryResult<IntPtr> DebugObjectHandleQueryResult = NtQueryInformationProcess<IntPtr>(Information.hProcess, PROCESSINFOCLASS.ProcessDebugObjectHandle))
|
||||||
|
@ -84,7 +84,7 @@ namespace Vanara.PInvoke.Tests
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Assert.DoesNotThrow(() => DbgUiSetThreadDebugObject(DebugObjectHandleQueryResult.Value).ThrowIfFailed());
|
Assert.That(DbgUiSetThreadDebugObject(DebugObjectHandleQueryResult.Value), ResultIs.Successful);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -94,7 +94,7 @@ namespace Vanara.PInvoke.Tests
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Assert.IsTrue(Kernel32.WaitForDebugEvent(out Kernel32.DEBUG_EVENT Event, Kernel32.INFINITE));
|
Assert.That(Kernel32.WaitForDebugEvent(out Kernel32.DEBUG_EVENT Event, Kernel32.INFINITE), ResultIs.Successful);
|
||||||
|
|
||||||
if (Event.dwDebugEventCode == Kernel32.DEBUG_EVENT_CODE.CREATE_PROCESS_DEBUG_EVENT)
|
if (Event.dwDebugEventCode == Kernel32.DEBUG_EVENT_CODE.CREATE_PROCESS_DEBUG_EVENT)
|
||||||
{
|
{
|
||||||
|
@ -102,10 +102,10 @@ namespace Vanara.PInvoke.Tests
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.IsTrue(Kernel32.ContinueDebugEvent(Event.dwProcessId, Event.dwThreadId, Kernel32.DEBUG_CONTINUE.DBG_CONTINUE));
|
Assert.That(Kernel32.ContinueDebugEvent(Event.dwProcessId, Event.dwThreadId, Kernel32.DEBUG_CONTINUE.DBG_CONTINUE), ResultIs.Successful);
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.AreNotEqual(Kernel32.SafeHPROCESS.Null, DebugProcessHandle);
|
Assert.False(DebugProcessHandle.IsNull);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -114,13 +114,13 @@ namespace Vanara.PInvoke.Tests
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
Assert.DoesNotThrow(() => DbgUiSetThreadDebugObject(IntPtr.Zero).ThrowIfFailed());
|
Assert.That(DbgUiSetThreadDebugObject(IntPtr.Zero), ResultIs.Successful);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
Assert.IsTrue(Kernel32.TerminateProcess(Information.hProcess, 0));
|
Assert.That(Kernel32.TerminateProcess(Information.hProcess, 0), ResultIs.Successful);
|
||||||
Assert.DoesNotThrow(() => NtRemoveProcessDebug(Information.hProcess, DebugObjectHandleQueryResult.Value).ThrowIfFailed());
|
Assert.That(NtRemoveProcessDebug(Information.hProcess, DebugObjectHandleQueryResult.Value), ResultIs.Successful);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue