Skip to content

NativeMethods ​

Provides P/Invoke declarations and helper methods for interacting with native Windows APIs.

Kind: Static class

Namespace: ConnectorLib

Public Static Functions

IntPtr

GetCurrentProcess()

Retrieves a handle for the current process.

bool

OpenProcessToken(IntPtr processHandle, uint desiredAccess, IntPtr out tokenHandle)

Opens the access token associated with a process.

IntPtr

OpenProcess(ProcessAccessFlagsEnum dwDesiredAccess, bool bInheritHandle, int dwProcessId)

Opens an existing local process object.

IntPtr

OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId)

Opens an existing local process object.

IntPtr

CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId)

Creates a thread that runs in the virtual address space of another process.

bool

GetThreadContext(IntPtr hThread, ThreadContext ref lpContext)

Retrieves the context of a thread.

bool

SetThreadContext(IntPtr hThread, ThreadContext ref lpContext)

Sets the context of a thread.

bool

Wow64GetThreadContext(IntPtr hThread, WOW64ThreadContext ref lpContext)

Retrieves the context of a WOW64 thread (32-bit thread running under 64-bit Windows).

bool

Wow64SetThreadContext(IntPtr hThread, WOW64ThreadContext ref lpContext)

Sets the context of a WOW64 thread (32-bit thread running under 64-bit Windows).

bool

CloseHandle(IntPtr hProcess)

Closes an open object handle.

bool

LookupPrivilegeValue(string lpSystemName, string lpName, LUID ref lpLuid)

Retrieves the locally unique identifier (LUID) for a specified privilege on a system.

bool

AdjustTokenPrivileges(IntPtr hToken, bool disableAllPrivileges, TOKEN_PRIVILEGES ref newState, uint zero, IntPtr null1, IntPtr null2)

Enables or disables privileges in the specified access token.

NtStatus

NtQueryInformationProcess(IntPtr hProcess, PROCESSINFOCLASS pic, PROCESS_BASIC_INFORMATION out pbi, int cb, int out pSize)

Represents the basic information about a process.

bool

ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, Span lpBuffer, int dwSize, int out lpNumberOfBytesRead)

Reads data from the memory of a specified process.

bool

ReadProcessMemory(IntPtr hProcess, long lpBaseAddress, Span lpBuffer, int dwSize, int out lpNumberOfBytesRead)

Reads data from the memory of a specified process.

bool

ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, int dwSize, int out lpNumberOfBytesRead)

Reads data from the memory of a specified process.

bool

ReadProcessMemory(IntPtr hProcess, long lpBaseAddress, byte[] lpBuffer, int dwSize, int out lpNumberOfBytesRead)

Reads data from the memory of a specified process.

bool

ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, IntPtr lpBuffer, int dwSize, int out lpNumberOfBytesRead)

Reads data from the memory of a specified process.

bool

ReadProcessMemory(IntPtr hProcess, long lpBaseAddress, IntPtr lpBuffer, int dwSize, int out lpNumberOfBytesRead)

Reads data from the memory of a specified process.

bool

WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, ReadOnlySpan lpBuffer, int dwSize, int out lpNumberOfBytesWritten)

Writes data to the memory of a specified process.

bool

WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, ReadOnlySpan lpBuffer, int out lpNumberOfBytesWritten)

Writes data to the memory of a specified process.

bool

WriteProcessMemory(IntPtr hProcess, long lpBaseAddress, ReadOnlySpan lpBuffer, int dwSize, int out lpNumberOfBytesWritten)

Writes data to the memory of a specified process.

bool

WriteProcessMemory(IntPtr hProcess, long lpBaseAddress, ReadOnlySpan lpBuffer, int out lpNumberOfBytesWritten)

Writes data to the memory of a specified process.

bool

WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, int dwSize, int out lpNumberOfBytesWritten)

Writes data to the memory of a specified process.

bool

WriteProcessMemory(IntPtr hProcess, long lpBaseAddress, byte[] lpBuffer, int dwSize, int out lpNumberOfBytesWritten)

Writes data to the memory of a specified process.

bool

WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, IntPtr lpBuffer, int dwSize, int out lpNumberOfBytesWritten)

Writes data to the memory of a specified process.

bool

WriteProcessMemory(IntPtr hProcess, long lpBaseAddress, IntPtr lpBuffer, int dwSize, int out lpNumberOfBytesWritten)

Writes data to the memory of a specified process.

void

GetSystemInfo(SYSTEM_INFO out info)

Retrieves information about the current system.

int

VirtualQueryEx(IntPtr hProcess, IntPtr lpAddress, MEMORY_BASIC_INFORMATION out lpBuffer, uint dwLength)

Retrieves information about a range of pages in the virtual address space of a specified process.

int

VirtualQueryEx(IntPtr hProcess, IntPtr lpAddress, MEMORY_BASIC_INFORMATION out lpBuffer)

Retrieves information about a range of pages in the virtual address space of a specified process.

IntPtr

VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, AllocationTypeEnum flAllocationType, AllocationProtectEnum flProtect)

Reserves, commits, or changes the state of a region of memory within the virtual address space of a specified process.

IntPtr

VirtualAllocExNear(IntPtr hProcess, IntPtr nearAddress, uint dwSize, AllocationTypeEnum flAllocationType, AllocationProtectEnum flProtect)

Reserves, commits, or changes the state of a region of memory within the virtual address space of a specified process.

bool

VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress, int dwSize, AllocationTypeEnum dwFreeType)

Releases, decommits, or frees a region of memory within the virtual address space of a specified process.

bool

GetExitCodeThread(IntPtr hThread, uint out lpExitCode)

Retrieves the exit code of a specified thread.

bool

GetExitCodeThread(IntPtr hThread, IntPtr out lpExitCode)

Retrieves the exit code of a specified thread.

bool

FlushInstructionCache(IntPtr hProcess, IntPtr lpBaseAddress, uint dwSize)

Flushes the instruction cache for a specified process.

uint

WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds)

Waits until the specified object is in the signaled state or the time-out interval elapses.

bool

IsWow64Process(IntPtr process, bool out wow64Process)

Determines whether the specified process is running under WOW64.

bool

GetClientRect(IntPtr hWnd, RECT out lpRect)

Retrieves the client area of a specified window.

Public Attributes

uint

INFINITE

Indicates that the wait operation should not time out.