using System;
using System.Runtime.InteropServices;
namespace SharpHellsGate.Win32 {
///
/// Contains all the delegates used to execute the system calls.
///
public class DFunctions {
///
/// Managed wrapper around the NtAllocateVirtualMemory native Windows function
///
/// A handle for the process for which the mapping should be done.
/// A pointer to a variable that will receive the base address of the allocated region of pages.
/// The number of high-order address bits that must be zero in the base address of the section view.
/// A pointer to a variable that will receive the actual size, in bytes, of the allocated region of pages.
/// A bitmask containing flags that specify the type of allocation to be performed for the specified region of pages.
/// A bitmask containing page protection flags that specify the protection desired for the committed region of pages.
/// NtAllocateVirtualMemory returns either STATUS_SUCCESS or an error status code.
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate uint NtAllocateVirtualMemory(
IntPtr ProcessHandle,
ref IntPtr BaseAddress,
IntPtr ZeroBits,
ref IntPtr RegionSize,
UInt32 AllocationType,
UInt32 Protect
);
///
/// Managed wrapper around the NtProtectVirtualMemory native Windows function.
///
/// Handle to Process Object opened with PROCESS_VM_OPERATION access.
/// Pointer to base address to protect. Protection will change on all page containing specified address. On output, BaseAddress will point to page start address.
/// Pointer to size of region to protect. On output will be round to page size (4KB).
/// One or some of PAGE_... attributes.
/// Receive previous protection.
/// NtProtectVirtualMemory returns either STATUS_SUCCESS or an error status code.
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate uint NtProtectVirtualMemory(
IntPtr ProcessHandle,
ref IntPtr BaseAddress,
ref IntPtr RegionSize,
UInt32 NewProtect,
out UInt32 OldProtect
);
///
/// Managed wrapper around the NtCreateThreadEx native Windows function.
///
/// Caller supplied storage for the resulting handle.
/// Specifies the allowed or desired access to the thread.
/// Initialized attributes for the object.
/// Handle to the threads parent process.
/// Address of the function to execute.
/// Parameters to pass to the function.
/// Whether the thread will be in suspended mode and has to be resumed later.
///
/// Initial stack memory to commit.
/// Initial stack memory to reserve.
///
/// NtCreateThreadEx returns either STATUS_SUCCESS or an error status code.
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate uint NtCreateThreadEx(
ref IntPtr hThread,
uint DesiredAccess,
IntPtr ObjectAttributes,
IntPtr ProcessHandle,
IntPtr lpStartAddress,
IntPtr lpParameter,
bool CreateSuspended,
uint StackZeroBits,
uint SizeOfStackCommit,
uint SizeOfStackReserve,
IntPtr lpBytesBuffer
);
///
/// Managed wrapper around the NtWaitForSingleObject native Windows function.
///
/// Open handle to a alertable executive object.
/// If set, calling thread is signaled, so all queued APC routines are executed.
/// Time-out interval, in microseconds. NULL means infinite.
/// NtWaitForSingleObject returns either STATUS_SUCCESS or an error status code.
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate uint NtWaitForSingleObject(
IntPtr ObjectHandle,
bool Alertable,
ref Structures.LARGE_INTEGER TimeOut
);
}
}