Skip to content

Commit fe5eacc

Browse files
committed
Added special user apc calls.
1 parent 31ce6c5 commit fe5eacc

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

NtApiDotNet/NtThread.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,64 @@ public NtToken OpenToken()
734734
return NtToken.OpenThreadToken(this);
735735
}
736736

737+
/// <summary>
738+
/// Queue a special user APC to the thread.
739+
/// </summary>
740+
/// <param name="apc_routine">The APC callback pointer.</param>
741+
/// <param name="normal_context">Context parameter.</param>
742+
/// <param name="system_argument1">System argument 1.</param>
743+
/// <param name="system_argument2">System argument 2.</param>
744+
/// <param name="throw_on_error">True to throw on error.</param>
745+
/// <returns>The NT status code.</returns>
746+
[SupportedVersion(SupportedVersion.Windows10_RS5)]
747+
public NtStatus QueueSpecialUserApc(IntPtr apc_routine, IntPtr normal_context, IntPtr system_argument1, IntPtr system_argument2, bool throw_on_error)
748+
{
749+
return NtSystemCalls.NtQueueApcThreadEx(Handle, new IntPtr(1), apc_routine, normal_context, system_argument1, system_argument2).ToNtException(throw_on_error);
750+
}
751+
752+
/// <summary>
753+
/// Queue a special user APC to the thread.
754+
/// </summary>
755+
/// <param name="apc_routine">The APC callback pointer.</param>
756+
/// <param name="normal_context">Context parameter.</param>
757+
/// <param name="system_argument1">System argument 1.</param>
758+
/// <param name="system_argument2">System argument 2.</param>
759+
/// <returns>The NT status code.</returns>
760+
[SupportedVersion(SupportedVersion.Windows10_RS5)]
761+
public void QueueSpecialUserApc(IntPtr apc_routine, IntPtr normal_context, IntPtr system_argument1, IntPtr system_argument2)
762+
{
763+
QueueSpecialUserApc(apc_routine, normal_context, system_argument1, system_argument2, true);
764+
}
765+
766+
/// <summary>
767+
/// Queue a special user APC to the thread.
768+
/// </summary>
769+
/// <param name="apc_routine">The APC callback pointer.</param>
770+
/// <param name="normal_context">Context parameter.</param>
771+
/// <param name="system_argument1">System argument 1.</param>
772+
/// <param name="system_argument2">System argument 2.</param>
773+
/// <param name="throw_on_error">True to throw on error.</param>
774+
/// <returns>The NT status code.</returns>
775+
[SupportedVersion(SupportedVersion.Windows10_RS5)]
776+
public NtStatus QueueSpecialUserApc(ApcCallback apc_routine, IntPtr normal_context, IntPtr system_argument1, IntPtr system_argument2, bool throw_on_error)
777+
{
778+
return QueueSpecialUserApc(Marshal.GetFunctionPointerForDelegate(apc_routine), normal_context, system_argument1, system_argument2, throw_on_error);
779+
}
780+
781+
/// <summary>
782+
/// Queue a special user APC to the thread.
783+
/// </summary>
784+
/// <param name="apc_routine">The APC callback pointer.</param>
785+
/// <param name="normal_context">Context parameter.</param>
786+
/// <param name="system_argument1">System argument 1.</param>
787+
/// <param name="system_argument2">System argument 2.</param>
788+
/// <returns>The NT status code.</returns>
789+
[SupportedVersion(SupportedVersion.Windows10_RS5)]
790+
public void QueueSpecialUserApc(ApcCallback apc_routine, IntPtr normal_context, IntPtr system_argument1, IntPtr system_argument2)
791+
{
792+
QueueSpecialUserApc(apc_routine, normal_context, system_argument1, system_argument2, true);
793+
}
794+
737795
/// <summary>
738796
/// Queue a user APC to the thread.
739797
/// </summary>

NtApiDotNet/NtThreadNative.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,15 @@ public static extern NtStatus NtQueueApcThreadEx(
632632
IntPtr ApcArgument2,
633633
IntPtr ApcArgument3);
634634

635+
[DllImport("ntdll.dll")]
636+
public static extern NtStatus NtQueueApcThreadEx(
637+
SafeKernelObjectHandle ThreadHandle,
638+
IntPtr UserApcReserveHandle,
639+
IntPtr ApcRoutine,
640+
IntPtr ApcArgument1,
641+
IntPtr ApcArgument2,
642+
IntPtr ApcArgument3);
643+
635644
[DllImport("ntdll.dll")]
636645
public static extern NtStatus NtGetContextThread(
637646
SafeKernelObjectHandle ThreadHandle,

0 commit comments

Comments
 (0)