From 332cf282c2d6a2f96575e05244c3a282d7382a57 Mon Sep 17 00:00:00 2001 From: James Forshaw Date: Mon, 4 Feb 2019 22:36:24 +0000 Subject: [PATCH] Added fix for waiting for infinite time. --- NtApiDotNet/NtObjectUtils.cs | 2 +- NtApiDotNet/NtThread.cs | 8 ++++---- NtApiDotNet/NtTransaction.cs | 2 +- NtApiDotNet/NtWait.cs | 17 +++++++++-------- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/NtApiDotNet/NtObjectUtils.cs b/NtApiDotNet/NtObjectUtils.cs index 9d754c0fd..a944345a7 100644 --- a/NtApiDotNet/NtObjectUtils.cs +++ b/NtApiDotNet/NtObjectUtils.cs @@ -644,7 +644,7 @@ internal static LargeInteger ToLargeInteger(this long? l) internal static LargeInteger ToLargeInteger(this NtWaitTimeout timeout) { - return ToLargeInteger(timeout?.Timeout); + return timeout?.Timeout; } internal static int GetLength(this SafeBuffer buffer) diff --git a/NtApiDotNet/NtThread.cs b/NtApiDotNet/NtThread.cs index e2d515d63..2ff5735aa 100644 --- a/NtApiDotNet/NtThread.cs +++ b/NtApiDotNet/NtThread.cs @@ -1045,9 +1045,9 @@ public IContext GetContext(ContextFlags flags) /// Set if the thread should be alertable /// The delay, negative values indicate relative times. /// True if the thread was alerted before the delay expired. - public static bool Sleep(bool alertable, long delay) + public static bool Sleep(bool alertable, NtWaitTimeout delay) { - NtStatus status = NtSystemCalls.NtDelayExecution(alertable, new LargeInteger(delay)); + NtStatus status = NtSystemCalls.NtDelayExecution(alertable, delay?.Timeout); if (!status.IsSuccess()) { throw new NtException(status); @@ -1062,9 +1062,9 @@ public static bool Sleep(bool alertable, long delay) /// Set if the thread should be alertable /// The delay, negative values indicate relative times. /// True if the thread was alerted before the delay expired. - public static bool Sleep(bool alertable, NtWaitTimeout delay) + public static bool Sleep(bool alertable, long delay) { - return Sleep(alertable, delay.Timeout); + return Sleep(alertable, new NtWaitTimeout(delay)); } /// diff --git a/NtApiDotNet/NtTransaction.cs b/NtApiDotNet/NtTransaction.cs index 64622cc18..9a641f02a 100644 --- a/NtApiDotNet/NtTransaction.cs +++ b/NtApiDotNet/NtTransaction.cs @@ -733,7 +733,7 @@ private void SetProperties(int? isolation_level, int? isolation_flags, NtWaitTim } if (timeout != null) { - init_value.Timeout = new LargeIntegerStruct() { QuadPart = timeout.Timeout }; + init_value.Timeout = new LargeIntegerStruct() { QuadPart = timeout.Timeout.QuadPart }; } buffer.Write(0, init_value); diff --git a/NtApiDotNet/NtWait.cs b/NtApiDotNet/NtWait.cs index 200099bbb..9830905f3 100644 --- a/NtApiDotNet/NtWait.cs +++ b/NtApiDotNet/NtWait.cs @@ -57,13 +57,13 @@ internal NtWaitTimeout() internal NtWaitTimeout(long value) { - Timeout = value; + Timeout = new LargeInteger(value); } /// /// Get a timeout which will wait indefinitely. /// - public static NtWaitTimeout Infinite { get { return new NtWaitTimeout(); } } + public static NtWaitTimeout Infinite => new NtWaitTimeout(); /// /// Get a relative timeout in seconds. @@ -108,7 +108,7 @@ public static NtWaitTimeout FromRelative(long relative) /// /// The timeout as a long. /// - public long Timeout { get; } + public LargeInteger Timeout { get; } /// /// Overridden ToString method. @@ -116,15 +116,16 @@ public static NtWaitTimeout FromRelative(long relative) /// The timeout as a string. public override string ToString() { - if (Timeout < 0) + if (Timeout == null) { - return $"Relative: {-Timeout}"; + return "Infinite"; } - else if (Timeout > 0) + + if (Timeout.QuadPart <= 0) { - return $"Absolute: {Timeout}"; + return $"Relative: {-Timeout.QuadPart}"; } - return "Infinite"; + return $"Absolute: {Timeout.QuadPart}"; } }