xwindows

package module
v0.0.0-...-5b0740b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2025 License: MIT Imports: 5 Imported by: 0

README

xwindows

Go interface to DLLs functions

Base on golang.org/x/sys/windows

Note

Please do not consider this code, particularly the autogenerated code, as stable. Identifiers names may still be subject to change.

Description

This package makes selected DLLs functions directly available in Go programs. At the moment, types and functions for accessing kernel objects and the Registry are included. The goal is to, eventually, cover all available functions.

What’s Changed

2025.9.19
  1. 新增多个API,Bugs 修复
  2. 新增多个常量值,规范文件命名
  3. 支持查询 teb, peb,支持 teb.Call 基于基址的 API 调用
  4. 新增 ekko 动态异步睡眠加密(实验性)
2025.2.7
  1. 新增多个函数,Bugs 修复

  2. 尝试使用 CGO 调用部分 API (实验性)

    // filename: cgo_winmm.go
    package xwindows
    
    /*
       #cgo LDFLAGS: -lwinmm
       #include <windows.h>
       #include <mmsystem.h>
    
       DWORD TimeGetTimeCGO() {
           return timeGetTime();
       }
    */
    import "C"
    
    func TimeGetTimeC() uint32 {
    	return uint32(C.TimeGetTimeCGO())
    }
    
  3. 新增type_xwindows.goxwindows风格的预定义变量

2025.1.26
  1. 修复调用错误,新增多个函数
  2. 新增统一错误类型
  3. 规范文件名,符合xwindows风格
  4. 完善文档支持内容
  5. 暂不支持syscall.SyscallN()作为syscall的原生调用的函数,提供以Z为后缀且使用Call()调用的方法
2024.8.14
  1. 新增mkwinsyscall工具实现API代码生成 - 待完善
  2. 新增actived, advapi, winmm等DLL
  3. 修复多个API参数类型不对应
2024.3.1
  1. 修复多个函数的Bug
  2. 添加文档
  3. 新增多个未公开的函数
2024.2.26

variant 项目衍生库

  1. 基于golang.org/x/sys/windows
  2. 使用syscall.SyscallN()作为syscall的调用,增加了绝大多数Go loader所使用的函数
  3. 包含了variant 项目所有的函数,同步更新

Uasge

xwindows.EnumPageFilesW()

Documentation

Index

Constants

View Source
const (
	IMAGE_DOS_SIGNATURE                  = 0x5A4D
	IMAGE_NT_SIGNATURE                   = 0x00004550
	IMAGE_NT_OPTIONAL_HDR32_MAGIC        = 0x10B
	IMAGE_NT_OPTIONAL_HDR64_MAGIC        = 0x20B
	IMAGE_FILE_MACHINE_I386              = 0x14c
	IMAGE_FILE_MACHINE_AMD64             = 0x8664
	IMAGE_SCN_MEM_EXECUTE                = 0x20000000
	IMAGE_SCN_MEM_READ                   = 0x40000000
	IMAGE_SCN_MEM_WRITE                  = 0x80000000
	IMAGE_DIRECTORY_ENTRY_EXPORT         = 0
	IMAGE_DIRECTORY_ENTRY_IMPORT         = 1
	IMAGE_DIRECTORY_ENTRY_RESOURCE       = 2
	IMAGE_DIRECTORY_ENTRY_EXCEPTION      = 3
	IMAGE_DIRECTORY_ENTRY_SECURITY       = 4
	IMAGE_DIRECTORY_ENTRY_BASERELOC      = 5
	IMAGE_DIRECTORY_ENTRY_DEBUG          = 6
	IMAGE_DIRECTORY_ENTRY_ARCHITECTURE   = 7
	IMAGE_DIRECTORY_ENTRY_GLOBALPTR      = 8
	IMAGE_DIRECTORY_ENTRY_TLS            = 9
	IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG    = 10
	IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT   = 11
	IMAGE_DIRECTORY_ENTRY_IAT            = 12
	IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT   = 13
	IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR = 14
	IMAGE_SIZEOF_SHORT_NAME              = 8
	IMAGE_NUMBEROF_DIRECTORY_ENTRIES     = 16
)
View Source
const (
	IMAGE_DOS_SIGNATURE                  = 0x5A4D
	IMAGE_NT_SIGNATURE                   = 0x00004550
	IMAGE_NT_OPTIONAL_HDR32_MAGIC        = 0x10B
	IMAGE_NT_OPTIONAL_HDR64_MAGIC        = 0x20B
	IMAGE_FILE_MACHINE_I386              = 0x14c
	IMAGE_FILE_MACHINE_AMD64             = 0x8664
	IMAGE_SCN_MEM_EXECUTE                = 0x20000000
	IMAGE_SCN_MEM_READ                   = 0x40000000
	IMAGE_SCN_MEM_WRITE                  = 0x80000000
	IMAGE_DIRECTORY_ENTRY_EXPORT         = 0
	IMAGE_DIRECTORY_ENTRY_IMPORT         = 1
	IMAGE_DIRECTORY_ENTRY_RESOURCE       = 2
	IMAGE_DIRECTORY_ENTRY_EXCEPTION      = 3
	IMAGE_DIRECTORY_ENTRY_SECURITY       = 4
	IMAGE_DIRECTORY_ENTRY_BASERELOC      = 5
	IMAGE_DIRECTORY_ENTRY_DEBUG          = 6
	IMAGE_DIRECTORY_ENTRY_ARCHITECTURE   = 7
	IMAGE_DIRECTORY_ENTRY_GLOBALPTR      = 8
	IMAGE_DIRECTORY_ENTRY_TLS            = 9
	IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG    = 10
	IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT   = 11
	IMAGE_DIRECTORY_ENTRY_IAT            = 12
	IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT   = 13
	IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR = 14
	IMAGE_SIZEOF_SHORT_NAME              = 8
	IMAGE_NUMBEROF_DIRECTORY_ENTRIES     = 16
)

Variables

View Source
var (
	// 内存操作类错误
	ErrAllocFailed    = errors.New("memory allocation failed")
	ErrFreeFailed     = errors.New("memory release failed")
	ErrLockFailed     = errors.New("memory locking failed")
	ErrProtectFailed  = errors.New("memory protection failed")
	ErrInvalidAddress = errors.New("invalid memory address")

	// 权限相关错误
	ErrAccessDenied      = errors.New("access denied")
	ErrPrivilegeRequired = errors.New("privilege not held")

	// 参数验证类错误
	ErrInvalidHandle    = errors.New("invalid handle")
	ErrInvalidParameter = errors.New("invalid parameter")
	ErrInvalidSize      = errors.New("invalid size parameter")
	ErrNullPointer      = errors.New("null pointer reference")

	// 系统API通用错误
	ErrAPICallFailed  = errors.New("system API call failed")
	ErrTimeout        = errors.New("operation timed out")
	ErrNotImplemented = errors.New("function not implemented")

	// 资源管理类错误
	ErrResourceNotFound = errors.New("specified resource not found")
	ErrResourceExists   = errors.New("resource already exists")
	ErrResourceBusy     = errors.New("resource is in use")

	// 安全相关错误
	ErrInvalidSignature = errors.New("invalid digital signature")
	ErrMemoryNotExec    = errors.New("memory is not executable")

	// 进程/线程操作错误
	ErrProcessCreate   = errors.New("process creation failed")
	ErrThreadOperation = errors.New("thread operation failed")

	// 系统状态错误
	ErrInsufficientBuffer = errors.New("buffer size insufficient")
	ErrNotReady           = errors.New("system not in ready state")
)

Functions

func AllocADsMem

func AllocADsMem(cb uintptr) (value uintptr, err error)

AllocADsMem 函数分配指定大小的内存块。

LPVOID AllocADsMem(

[in] DWORD cb
);

返回值 类型: LPVOID 如果成功,该函数将返回指向已分配内存的非 NULL 指针。 当不再需要此内存时,调用方必须通过将返回的指针传递给 FreeADsMem 来释放此内存。 如果未成功,则返回 NULL 。 调用 ADsGetLastError 以获取扩展错误状态。 有关错误代码值的详细信息,请参阅 ADSI 错误代码。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/adshlp/nf-adshlp-allocadsmem

func Beep

func Beep(dwFreq uint32, dwDuration uint32) (value uintptr, err error)

Beep 在扬声器上生成简单的音调。 函数是同步的;它执行可警报等待,在声音完成之前不会将控制权返回到其调用方。

BOOL Beep(

[in] DWORD dwFreq,		// 声音的频率,以Hz为单位。 此参数的范围必须介于 37 到 32,767 (0x25 到 0x7FFF) 。
[in] DWORD dwDuration   // 声音的持续时间(以毫秒为单位)。
);

如果该函数成功,则返回值为非零值。 如果函数失败,则返回值为零。

Links: https://learn.microsoft.com/zh-cn/windows/win32/api/utilapiset/nf-utilapiset-beep

func CloseHandle

func CloseHandle(handle windows.Handle) (err error)

CloseHandle 关闭打开的对象句柄

BOOL CloseHandle(

[in] HANDLE hObject
);

如果该函数成功,则返回值为非零值 如果函数失败,则返回值为零

Link: https://learn.microsoft.com/zh-CN/windows/win32/api/handleapi/nf-handleapi-closehandle

func ConvertThreadToFiber

func ConvertThreadToFiber(lpParameter uintptr) (value uintptr, err error)

ConvertThreadToFiber Converts the current thread into a fiber. You must convert a thread into a fiber before you can schedule other fibers.

LPVOID ConvertThreadToFiber(

  [in, optional] LPVOID lpParameter
);

If the function succeeds, the return value is the address of the fiber.

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/winbase/nf-winbase-convertthreadtofiber

func CreateFiber

func CreateFiber(dwStackSize uintptr, lpStartAddress uintptr, lpParameter uintptr) (value uintptr, err error)

CreateFiber Allocates a fiber object, assigns it a stack, and sets up execution to begin at the specified start address, typically the fiber function. This function does not schedule the fiber.

LPVOID CreateFiber(

  [in]           SIZE_T                dwStackSize,
  [in]           LPFIBER_START_ROUTINE lpStartAddress,
  [in, optional] LPVOID                lpParameter
);

If the function succeeds, the return value is the address of the fiber.

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/winbase/nf-winbase-createfiber

func CreatePipe

func CreatePipe(readHandle *windows.Handle, writeHandle *windows.Handle, sa *windows.SecurityAttributes, size uint32) (err error)

CreatePipe 创建匿名管道,并将句柄返回到管道的读取和写入端

BOOL CreatePipe(

[out]          PHANDLE               hReadPipe,         // 指向接收管道读取句柄的变量的指针
[out]          PHANDLE               hWritePipe,        // 指向接收管道写入句柄的变量的指针
[in, optional] LPSECURITY_ATTRIBUTES lpPipeAttributes,  // 指向 SECURITY_ATTRIBUTES 结构的指针
[in]           DWORD                 nSize              // 管道的缓冲区大小(以字节为单位)

);

返回值 如果函数成功,则返回值为非零 如果函数失败,则返回值为零

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/namedpipeapi/nf-namedpipeapi-createpipe

func CreateProcessA

func CreateProcessA(appName *uint16, commandLine *uint16, procSecurity *windows.SecurityAttributes, threadSecurity *windows.SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *windows.StartupInfo, outProcInfo *windows.ProcessInformation) (err error)

CreateProcessA 创建新进程及其主线程。 新进程在调用进程的安全上下文中运行。 如果调用进程正在模拟其他用户,则新进程将令牌用于调用进程,而不是模拟令牌。 若要在模拟令牌表示的用户的安全上下文中运行新进程,请使用 CreateProcessAsUser 或 CreateProcessWithLogonW 函数。

BOOL CreateProcessA(

[in, optional]      LPCSTR                lpApplicationName,    // 要执行的模块的名称
[in, out, optional] LPSTR                 lpCommandLine,        // 要执行的命令行
[in, optional]      LPSECURITY_ATTRIBUTES lpProcessAttributes,  // 指向 SECURITY_ATTRIBUTES 结构的指针
[in, optional]      LPSECURITY_ATTRIBUTES lpThreadAttributes,   // 指向 SECURITY_ATTRIBUTES 结构的指针
[in]                BOOL                  bInheritHandles,      // 参数为 TRUE,则调用进程中的每个可继承句柄都由新进程继承
[in]                DWORD                 dwCreationFlags,      // 控制优先级类和进程的创建的标志
[in, optional]      LPVOID                lpEnvironment,        // 指向新进程的环境块的指针
[in, optional]      LPCSTR                lpCurrentDirectory,   // 进程当前目录的完整路径
[in]                LPSTARTUPINFOA        lpStartupInfo,		// 指向 STARTUPINFO 或 STARTUPINFOEX 结构的指针
[out]               LPPROCESS_INFORMATION lpProcessInformation  // 指向接收有关新进程的标识信息的 PROCESS_INFORMATION 结构的指针
);

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa

func CreateProcessW

func CreateProcessW(appName *uint16, commandLine *uint16, procSecurity *windows.SecurityAttributes, threadSecurity *windows.SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *windows.StartupInfo, outProcInfo *windows.ProcessInformation) (err error)

CreateProcessW 创建一个新进程及其主线程,新进程在调用进程的安全上下文中运行

BOOL CreateProcessW(

[in, optional]      LPCWSTR               lpApplicationName, // 要执行的模块的名称
[in, out, optional] LPWSTR                lpCommandLine, // 要执行的命令行
[in, optional]      LPSECURITY_ATTRIBUTES lpProcessAttributes, // 指向 SECURITY_ATTRIBUTES 结构的指针,该结构确定新进程对象的返回句柄是否可以由子进程继承
[in, optional]      LPSECURITY_ATTRIBUTES lpThreadAttributes, // 指向 SECURITY_ATTRIBUTES 结构的指针,该结构确定新线程对象的返回句柄是否可以由子进程继承
[in]                BOOL                  bInheritHandles, // 如果此参数为 TRUE,则调用进程中的每个可继承句柄都由新进程继承
[in]                DWORD                 dwCreationFlags, // 控制优先级类和创建进程的标志
[in, optional]      LPVOID                lpEnvironment, // 指向新进程的环境块的指针
[in, optional]      LPCWSTR               lpCurrentDirectory, // 进程的当前目录的完整路径
[in]                LPSTARTUPINFOW        lpStartupInfo, // 指向 STARTUPINFO 或 STARTUPINFOEX 结构的指针
[out]               LPPROCESS_INFORMATION lpProcessInformation // 指向接收有关新进程的标识信息的 PROCESS_INFORMATION 结构的指针

);

返回值 如果函数成功,则返回值为非零 如果函数失败,则返回值为零

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw

func CreateRemoteThread

func CreateRemoteThread(hProcess windows.Handle, lpThreadAttributes uintptr, dwStackSize uintptr, lpStartAddress uintptr, lpParameter uintptr, dwCreationFlags uintptr, lpThreadId uintptr) (value uintptr, err error)

CreateRemoteThread 创建在另一个进程的虚拟地址空间中运行的线程。 使用 CreateRemoteThreadEx 函数创建在另一个进程的虚拟地址空间中运行的线程,并选择性地指定扩展属性。

HANDLE CreateRemoteThread(

  [in]  HANDLE                 hProcess,
  [in]  LPSECURITY_ATTRIBUTES  lpThreadAttributes,
  [in]  SIZE_T                 dwStackSize,
  [in]  LPTHREAD_START_ROUTINE lpStartAddress,
  [in]  LPVOID                 lpParameter,
  [in]  DWORD                  dwCreationFlags,
  [out] LPDWORD                lpThreadId
);

如果函数成功,则返回值是新线程的句柄。 如果函数失败,则返回值为 NULL。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/processthreadsapi/nf-processthreadsapi-createremotethread

func CreateRemoteThreadEx

func CreateRemoteThreadEx(hProcess windows.Handle, lpThreadAttributes uintptr, dwStackSize uintptr, lpStartAddress uintptr, lpParameter uintptr, dwCreationFlags uint32, lpAttributeList uintptr, lpThreadId uintptr) (handle windows.Handle, err error)

CreateRemoteThreadEx 创建一个线程,该线程在另一个进程的虚拟地址空间中运行,并选择性地指定扩展属性,例如处理器组相关性

HANDLE CreateRemoteThreadEx(

[in]            HANDLE                       hProcess,
[in, optional]  LPSECURITY_ATTRIBUTES        lpThreadAttributes,
[in]            SIZE_T                       dwStackSize,
[in]            LPTHREAD_START_ROUTINE       lpStartAddress,
[in, optional]  LPVOID                       lpParameter,
[in]            DWORD                        dwCreationFlags,
[in, optional]  LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList,
[out, optional] LPDWORD                      lpThreadId
);

如果函数成功,则返回值是新线程的句柄 如果函数失败,则返回值为 NULL

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/processthreadsapi/nf-processthreadsapi-createremotethreadex

func CreateThread

func CreateThread(lpThreadAttributes uintptr, dwStackSize uintptr, lpStartAddress uintptr, lpParameter uintptr, dwCreationFlags uint32, lpThreadId uintptr) (handle windows.Handle, err error)

CreateThread 创建在调用进程的虚拟地址空间内执行的线程。 若要创建在另一个进程的虚拟地址空间中运行的线程,请使用 CreateRemoteThread 函数

HANDLE CreateThread(

[in, optional]  LPSECURITY_ATTRIBUTES   lpThreadAttributes,
[in]            SIZE_T                  dwStackSize,
[in]            LPTHREAD_START_ROUTINE  lpStartAddress,
[in, optional]  __drv_aliasesMem LPVOID lpParameter,
[in]            DWORD                   dwCreationFlags,
[out, optional] LPDWORD                 lpThreadId
);

如果函数成功,则返回值是新线程的句柄 如果函数失败,则返回值为 NULL

type pCreateThread func(lpThreadAttributes *windows.SecurityAttributes, dwStackSize uintptr, lpStartAddress uintptr, lpParameter uintptr, dwCreationFlags uint32, lpThreadId *uint32) uintptr

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/processthreadsapi/nf-processthreadsapi-createthread

func CreateToolhelp32Snapshot

func CreateToolhelp32Snapshot(flags uint32, processId uint32) (handle windows.Handle, err error)

CreateToolhelp32Snapshot 获取指定进程以及这些进程使用的堆、模块和线程的快照

HANDLE CreateToolhelp32Snapshot(

[in] DWORD dwFlags,
[in] DWORD th32ProcessID
);

如果函数成功,它将返回指定快照的打开句柄。 如果函数失败,它将返回 INVALID_HANDLE_VALUE。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/tlhelp32/nf-tlhelp32-createtoolhelp32snapshot

func CryptDecrypt

func CryptDecrypt(hKey HCRYPTKEY, hHash HCRYPTHASH, final bool, dwFlags DWORD, pbData *byte, pdwDataLen *DWORD) (err error)

CryptDecrypt 使用 CryptEncrypt 函数解密以前加密的数据

BOOL CryptDecrypt(

[in]      HCRYPTKEY  hKey,
[in]      HCRYPTHASH hHash,
[in]      BOOL       Final,
[in]      DWORD      dwFlags,
[in, out] BYTE       *pbData,
[in, out] DWORD      *pdwDataLen

);

返回值

  • 如果函数成功,该函数将返回非零(TRUE)
  • 如果函数失败,则返回零(FALSE)。 有关扩展错误信息,请调用 GetLastError

Link : https://learn.microsoft.com/zh-cn/windows/win32/api/wincrypt/nf-wincrypt-cryptdecrypt

func CryptEncrypt

func CryptEncrypt(hKey HCRYPTKEY, hHash HCRYPTHASH, final bool, dwFlags uint32, pbData *byte, pdwDataLen *uint32, dwBufLen uint32) (err error)

CryptEncrypt 用于加密数据的算法由 CSP 模块持有的密钥指定,并由 hKey 参数引用

BOOL CryptEncrypt(

[in]      HCRYPTKEY  hKey,  // 加密密钥的句柄
[in]      HCRYPTHASH hHash, // 哈希对象的句柄
[in]      BOOL       Final,
[in]      DWORD      dwFlags,
[in, out] BYTE       *pbData,
[in, out] DWORD      *pdwDataLen,
[in]      DWORD      dwBufLen

);

返回值

  • 如果函数成功,该函数将返回非零(TRUE)。
  • 如果函数失败,则返回零(FALSE)。 有关扩展错误信息,请调用 GetLastError。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/wincrypt/nf-wincrypt-cryptencrypt

func EnumChildWindows

func EnumChildWindows(hwnd windows.HWND, enumFunc uintptr, param unsafe.Pointer)

EnumChildWindows 通过将每个子窗口的句柄依次传递给应用程序定义的回调函数,枚举属于指定父窗口的子窗口 EnumChildWindows 会一直持续到枚举最后一个子窗口或回调函数返回 FALSE

BOOL EnumChildWindows(

[in, optional] HWND        hWndParent, // 要枚举其子窗口的父窗口的句柄
[in]           WNDENUMPROC lpEnumFunc, // 指向应用程序定义的回调函数的指针
[in]           LPARAM      lParam // 要传递给回调函数的应用程序定义值

);

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/winuser/nf-winuser-enumchildwindows

func EnumDesktopWindows

func EnumDesktopWindows(hDESK windows.Handle, lpfn uintptr, lParam uintptr) (value uintptr, err error)

EnumDesktopWindows 枚举与指定桌面关联的所有顶级窗口

BOOL EnumDesktopWindows(

[in, optional] HDESK       hDesktop, // 要枚举其顶级窗口的桌面的句柄
[in]           WNDENUMPROC lpfn, // 指向应用程序定义的 EnumWindowsProc 回调函数的指针
[in]           LPARAM      lParam // 要传递给回调函数的应用程序定义值

); 返回值 如果函数失败或无法执行枚举,则返回值为零。 要获得更多的错误信息,请调用 GetLastError。 必须确保回调函数设置 SetLastError (如果失败)。 Windows Server 2003 和 Windows XP/2000: 如果桌面上没有窗口, GetLastError 将返回 ERROR_INVALID_HANDLE。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/winuser/nf-winuser-enumdesktopwindowss

func EnumPageFilesW

func EnumPageFilesW(pCallBackRoutine uintptr, pContext uintptr) (value uintptr, err error)

EnumPageFilesW 为系统中每个已安装的页面文件调用回调例程

BOOL EnumPageFilesW(

[out] PENUM_PAGE_FILE_CALLBACKW pCallBackRoutine,
[in]  LPVOID                    pContext
);

返回值 如果函数成功,则返回值为 TRUE。 如果函数失败,则返回值为 FALSE。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/psapi/nf-psapi-enumpagefilesw

func EnumSystemLocalesA

func EnumSystemLocalesA(lpLocaleEnumProc uintptr, dwFlags uint32) (value uintptr, err error)

EnumSystemLocalesA 枚举操作系统所安装或受支持的区域设置

BOOL EnumSystemLocalesA(

[in] LOCALE_ENUMPROCA lpLocaleEnumProc, // 指向应用程序定义的回调函数的指针
[in] DWORD            dwFlags // 指定要枚举的区域设置标识符的标志

);

返回值 如果成功,则返回非零值,否则返回 0。 若要获取扩展的错误信息,应用程序可以调用 GetLastError,这会返回以下错误代码之一: ERROR_BADDB: 该函数无法访问数据。 这种情况通常不应发生,通常表示安装错误、磁盘问题或类似情况。 ERROR_INVALID_FLAGS: 为标志提供的值无效。 ERROR_INVALID_PARAMETER: 任何参数值都无效。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/winnls/nf-winnls-enumsystemlocalesa

func EnumSystemLocalesEx

func EnumSystemLocalesEx(lpLocaleEnumProcEx uintptr, dwFlags uint32, lParam uintptr, lpReserved uintptr) (value uintptr, err error)

EnumSystemLocalesEx 枚举安装在操作系统上或受操作系统支持的区域设置 注意:如果设计为仅在 Windows Vista 及更高版本上运行,则应用程序应优先调用此函数,而不是 EnumSystemLocales

BOOL EnumSystemLocalesEx(

[in]           LOCALE_ENUMPROCEX lpLocaleEnumProcEx,
[in]           DWORD             dwFlags,
[in]           LPARAM            lParam,
[in, optional] LPVOID            lpReserved
);

如果成功,则返回非零值,否则返回 0。 若要获取扩展错误信息,应用程序可以调用 GetLastError,这会返回以下错误代码之一:

ERROR_BADDB: 函数无法访问数据。 这种情况通常不应发生,通常表示安装错误、磁盘问题或类似问题。 ERROR_INVALID_FLAGS: 为标志提供的值无效。 ERROR_INVALID_PARAMETER: 任何参数值都无效。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/winnls/nf-winnls-enumsystemlocalesex

func EnumSystemLocalesW

func EnumSystemLocalesW(lpLocaleEnumProc uintptr, dwFlags uint32) (value uintptr, err error)

EnumSystemLocalesW 枚举安装在操作系统上或受操作系统支持的区域设置

BOOL EnumSystemLocalesW(

[in] LOCALE_ENUMPROCW lpLocaleEnumProc,
[in] DWORD            dwFlags
);

如果成功,则返回非零值,否则返回 0。 若要获取扩展错误信息,应用程序可以调用 GetLastError,这会返回以下错误代码之一: ERROR_BADDB: 函数无法访问数据,这种情况通常不应发生,通常表示安装错误、磁盘问题或类似问题。 ERROR_INVALID_FLAGS: 为标志提供的值无效。 ERROR_INVALID_PARAMETER: 任何参数值都无效。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/winnls/nf-winnls-enumsystemlocalesw

func EnumThreadWindows

func EnumThreadWindows(dwThreadId uint32, lpfn uintptr, lParam uintptr) (value uintptr, err error)

EnumThreadWindows 通过将句柄传递到每个窗口,再将传递给应用程序定义的回调函数,枚举与线程关联的所有非子窗口 EnumThreadWindows 一直持续到枚举最后一个窗口或回调函数返回 FALSE

BOOL EnumThreadWindows(

[in] DWORD       dwThreadId, // 要枚举其窗口的线程的标识符
[in] WNDENUMPROC lpfn, // 指向应用程序定义的回调函数的指针
[in] LPARAM      lParam // 要传递给回调函数的应用程序定义值

);

返回值 类型: BOOL 如果回调函数为 dwThreadId 指定的线程中的所有窗口返回 TRUE,则返回值为 TRUE。 如果回调函数在任何枚举窗口上返回 FALSE ,或者如果在 dwThreadId 指定的线程中找不到任何窗口,则返回值为 FALSE

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/winuser/nf-winuser-enumthreadwindows

func EnumThreadWindowsC

func EnumThreadWindowsC(dwThreadId uint32, lpfn uintptr, lParam uintptr) bool

func EnumTimeFormatsA

func EnumTimeFormatsA(lpTimeFmtEnumProc windows.HWND, locale uintptr, dwFlags uint32) (value uintptr, err error)

EnumTimeFormatsA 枚举可用于由标识符指定的区域设置的时间格式

BOOL EnumTimeFormatsA(

[in] TIMEFMT_ENUMPROCA lpTimeFmtEnumProc, // 指向应用程序定义的回调函数的指针
[in] LCID              Locale, // 区域设置标识符,用于指定要为其检索时间格式信息的区域设置
[in] DWORD             dwFlags // 时间格式

);

返回值 如果成功,则返回非零值,否则返回 0。 若要获取扩展的错误信息,应用程序可以调用 GetLastError,这会返回以下错误代码之一: ERROR_INVALID_FLAGS: 为标志提供的值无效。 ERROR_INVALID_PARAMETER: 任何参数值都无效。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/winnls/nf-winnls-enumtimeformatsa

func EnumWindows

func EnumWindows(lpEnumFunc windows.Handle, lParam uintptr) (value uintptr, err error)

EnumWindows 通过将句柄传递到每个窗口,进而将传递给应用程序定义的回调函数,枚举屏幕上的所有顶级窗口 枚举窗口 将一直持续到最后一个顶级窗口被枚举或回调函数返回 FALSE

BOOL EnumWindows(

[in] WNDENUMPROC lpEnumFunc, // 指向应用程序定义的回调函数的指针
[in] LPARAM      lParam      // 要传递给回调函数的应用程序定义值

);

返回值 类型: BOOL 如果该函数成功,则返回值为非零值。 如果函数失败,则返回值为零。 要获得更多的错误信息,请调用 GetLastError。 如果 EnumWindowsProc 返回零,则返回值也为零。 在这种情况下,回调函数应调用 SetLastError 以获取要返回到 EnumWindows 调用方有意义的错误代码。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/winuser/nf-winuser-enumwindows

func EnumerateLoadedModules

func EnumerateLoadedModules(hProcess windows.Handle, enumLoadedModulesCallback uintptr, userContext uintptr) (value uintptr, err error)

EnumerateLoadedModules 枚举指定进程的已加载模块。

BOOL IMAGEAPI EnumerateLoadedModules(

[in]           HANDLE                       hProcess,
[in]           PENUMLOADED_MODULES_CALLBACK EnumLoadedModulesCallback,
[in, optional] PVOID                        UserContext
);

返回值 如果函数成功,则返回值为 TRUE。 如果函数失败,则返回值为 FALSE。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/dbghelp/nf-dbghelp-enumerateloadedmodules

func EtwEventWrite

func EtwEventWrite(regHandle windows.Handle, eventDescriptor uintptr, userDataCount uint32, userData uintptr) (value uintptr, err error)

EtwEventWrite 函数及其返回的结构在操作系统内部,并且可能会从一个版本的 Windows 更改为另一个版本。 将基本事件写入会话

ULONG EVNTAPI EtwEventWrite(

__in REGHANDLE RegHandle,
__in PCEVENT_DESCRIPTOR EventDescriptor,
__in ULONG UserDataCount,
__in_ecount_opt(UserDataCount) PEVENT_DATA_DESCRIPTOR UserData
);

返回值 Win32 错误代码。

Link: https://learn.microsoft.com/zh-cn/windows/win32/devnotes/etweventwrite

func EtwEventWriteEx

func EtwEventWriteEx(regHandle windows.Handle, eventDescriptor uintptr, filter uint64, flags uint32, activityId uintptr, relatedActivityId uintptr, userDataCount uintptr, userData uintptr) (value uintptr, err error)

EtwEventWriteEx

ULONG EtwEventWriteEx (

REGHANDLE RegHandle,
EVENT_DESCRIPTOR const *EventDescriptor,
ULONG64 Filter,
ULONG Flags,
GUID const *ActivityId,
GUID const *RelatedActivityId,
ULONG UserDataCount,
EVENT_DATA_DESCRIPTOR *UserData);

The function returns zero for success, else a Win32 error code.

Link: https://www.geoffchappell.com/studies/windows/win32/ntdll/api/etw/evntapi/writeex.htm

func EtwEventWriteFull

func EtwEventWriteFull(regHandle windows.Handle, eventDescriptor uintptr, eventProperty uintptr, activityId uintptr, relatedActivityId uintptr, userDataCount uint32, userData uintptr) (value uintptr, err error)

EtwEventWriteFull 函数及其返回的结构在操作系统内部,可能会从一个版本的 Windows 更改为另一个版本。 将完整事件写入会话

ULONG EVNTAPI EtwEventWriteFull(

__in REGHANDLE RegHandle,
__in PCEVENT_DESCRIPTOR EventDescriptor,
__in USHORT EventProperty,
__in_opt LPCGUID ActivityId,
__in_opt LPCGUID RelatedActivityId,
__in ULONG UserDataCount,
__in_ecount_opt(UserDataCount) PEVENT_DATA_DESCRIPTOR UserData
);

返回值 Win32 错误代码。

Link: https://learn.microsoft.com/zh-cn/windows/win32/devnotes/etweventwritefull

func EtwEventWriteString

func EtwEventWriteString(regHandle windows.Handle, level byte, keyword uint64, str *uint16) (value uintptr, err error)

EtwEventWriteString forwarded from EventWriteString TODO: Need documentation, not sure function is correct

NTSYSAPI ULONG NTAPI EtwEventWriteString(

_In_ REGHANDLE RegHandle,
_In_ UCHAR Level,
_In_ ULONGLONG Keyword,
_In_ PCWSTR String
);

func EtwEventWriteTransfer

func EtwEventWriteTransfer(regHandle windows.Handle, eventDescriptor *EVENT_DESCRIPTOR, activityId, relatedActivityId *GUID, userDataCount uint32, userData []*EVENT_DATA_DESCRIPTOR) (value uintptr, err error)

EtwEventWriteTransfer TODO: Need documentation, not sure function is correct

ULONG

EtwEventWriteTransfer (
REGHANDLE RegHandle,
EVENT_DESCRIPTOR const *EventDescriptor,
GUID const *ActivityId,
GUID const *RelatedActivityId,
ULONG UserDataCount,
EVENT_DATA_DESCRIPTOR *UserData
);

The function returns zero for success, else a Win32 error code.

func EtwpCreateEtwThread

func EtwpCreateEtwThread(lpStartAddress uintptr, lpParameter uintptr) (value uintptr, err error)

EtwpCreateEtwThread

static extern IntPtr EtwpCreateEtwThread(

IntPtr lpStartAddress,
IntPtr lpParameter
);

Link: https://gist.github.com/TheWover/b2b2e427d3a81659942f4e8b9a978dc3

func FreeADsMem

func FreeADsMem(pMem uintptr) (value uintptr, err error)

FreeADsMem 函数释放由 AllocADsMem 或 ReallocADsMem 分配的内存。

BOOL FreeADsMem(

[in] LPVOID pMem
);

返回值 类型: BOOL 如果成功,函数将返回 TRUE ,否则返回 FALSE。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/adshlp/nf-adshlp-freeadsmem

func GetConsoleWindow

func GetConsoleWindow() (proc uintptr, err error)

GetConsoleWindow 检索与调用进程相关联的控制台使用的窗口句柄

HWND WINAPI GetConsoleWindow(void);

返回值 返回值是与调用进程相关联的控制台所使用的窗口句柄,如果没有此类关联控制台,则返回值为 NULL。

Link: https://learn.microsoft.com/zh-cn/windows/console/getconsolewindow

func GetCurrentProcess

func GetCurrentProcess() (handle windows.Handle, err error)

GetCurrentProcess 检索当前进程的伪句柄

HANDLE GetCurrentProcess();

返回值是当前进程的伪句柄

Link: https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess

func GetCurrentThread

func GetCurrentThread() (handle windows.Handle, err error)

GetCurrentThread Retrieves a pseudo handle for the calling thread.

HANDLE GetCurrentThread();

The return value is a pseudo handle for the current thread.

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentthread

func GetLoadLibraryAAddr

func GetLoadLibraryAAddr() (uintptr, error)

func GetPhysicallyInstalledSystemMemory

func GetPhysicallyInstalledSystemMemory(totalMemoryInKilobytes uintptr) (value uintptr, err error)

GetPhysicallyInstalledSystemMemory 检索实际安装在计算机上的 RAM 量

BOOL GetPhysicallyInstalledSystemMemory(

[out] PULONGLONG TotalMemoryInKilobytes
);

如果函数成功,则返回 TRUE 并将 TotalMemoryInKilobytes 参数设置为非零值。 如果函数失败,它将返回 FALSE ,并且不会修改 TotalMemoryInKilobytes 参数。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/sysinfoapi/nf-sysinfoapi-getphysicallyinstalledsystemmemory

func GetProcAddress

func GetProcAddress(module windows.Handle, procName string) (proc uintptr, err error)

GetProcAddress

FARPROC GetProcAddress(

[in] HMODULE hModule,
[in] LPCSTR  lpProcName
);

[in] hModule 包含函数或变量的 DLL 模块的句柄。 LoadLibrary、LoadLibraryEx、LoadPackagedLibrary 或 GetModuleHandle 函数返回此句柄。 GetProcAddress 函数不会从使用 LOAD_LIBRARY_AS_DATAFILE 标志加载的模块中检索地址。 有关详细信息,请参阅 LoadLibraryEx。

[in] lpProcName 函数或变量名称,或函数的序号值。 如果此参数是序号值,则它必须在低序位字中;高序位字必须为零。

Return 如果函数成功,则返回值是导出的函数或变量的地址。 如果函数失败,则返回值为 NULL。 要获得更多的错误信息,请调用 GetLastError。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/libloaderapi/nf-libloaderapi-getprocaddress

func GetThreadContext

func GetThreadContext(hThread windows.Handle, lpContext *CONTEXT) (value uintptr, err error)

GetThreadContext 检索指定线程的上下文。 64 位应用程序可以使用 Wow64GetThreadContext 检索 WOW64 线程的上下文。

BOOL GetThreadContext(

[in]      HANDLE    hThread,  // 要检索其上下文的线程的句柄
[in, out] LPCONTEXT lpContext // 指向 CONTEXT 结构的指针 (,例如接收指定线程的适当上下文 的 ARM64_NT_CONTEXT)
);

如果该函数成功,则返回值为非零值。 如果函数失败,则返回值为零。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/processthreadsapi/nf-processthreadsapi-getthreadcontext

func GetTickCount

func GetTickCount() (value uintptr, err error)

GetTickCount 检索自系统启动以来经过的毫秒数,最长为 49.7 天

DWORD GetTickCount();

返回值是自系统启动以来经过的毫秒数

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/sysinfoapi/nf-sysinfoapi-gettickcount

func HeapAlloc

func HeapAlloc(hHeap windows.Handle, dwFlags uint32, dwBytes uintptr) (value uintptr, err error)

HeapAlloc 从堆中分配内存块。 分配的内存不可移动

DECLSPEC_ALLOCATOR LPVOID HeapAlloc(

[in] HANDLE hHeap,
[in] DWORD  dwFlags,
[in] SIZE_T dwBytes
);

如果函数成功,则返回值是指向已分配内存块的指针 如果函数失败并且您尚未指定 HEAP_GENERATE_EXCEPTIONS,则返回值为 NULL 如果函数失败并且已指定 HEAP_GENERATE_EXCEPTIONS,则函数可能会生成列出的任一异常: STATUS_NO_MEMORY, STATUS_ACCESS_VIOLATION

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/heapapi/nf-heapapi-heapalloc

func HeapCreate

func HeapCreate(flOptions uint32, dwInitialSize uintptr, dwMaximumSize uintptr) (value uintptr, err error)

HeapCreate 创建可由调用进程使用的专用堆对象。 函数在进程的虚拟地址空间中保留空间,并为此块的指定初始部分分配物理存储

HANDLE HeapCreate(

[in] DWORD  flOptions,
[in] SIZE_T dwInitialSize,
[in] SIZE_T dwMaximumSize
);

如果函数成功,则返回值是新创建的堆的句柄 如果函数失败,则返回值为 NULL

Link: https://learn.microsoft.com/en-us/windows/win32/api/heapapi/nf-heapapi-heapcreate

func I_QueryTagInformation

func I_QueryTagInformation(pszMachineName uintptr, eInfoLevel uintptr, pTagInfo uintptr) (value uintptr, err error)

I_QueryTagInformation

_Must_inspect_result_ DWORD WINAPI I_QueryTagInformation(_In_opt_ LPCWSTR pszMachineName,

_In_ TAG_INFO_LEVEL 	eInfoLevel,
_Inout_ PVOID 			pTagInfo
);

func LoadLibraryA

func LoadLibraryA(lpLibFileName string) (handle windows.Handle, err error)

LoadLibraryA 将指定的模块加载到调用进程的地址空间中。 指定的模块可能会导致加载其他模块。 有关其他加载选项,请使用 LoadLibraryEx 函数。

HMODULE LoadLibraryA(

  [in] LPCSTR lpLibFileName // 模块的名称。 可以是库模块 (.dll 文件) ,也可以是可执行模块 (.exe 文件)
);

返回值 如果函数成功,则返回值是模块的句柄。 如果函数失败,则返回值为 NULL。 要获得更多的错误信息,请调用 GetLastError。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibrarya

func LoadLibraryW

func LoadLibraryW(libName string) (handle windows.Handle, err error)

LoadLibraryW 将指定的模块加载到调用进程的地址空间中。 指定的模块可能会导致加载其他模块。

HMODULE LoadLibraryW(

[in] LPCWSTR lpLibFileName
);

如果函数成功,则返回值是模块的句柄。 如果函数失败,则返回值为 NULL。

Links: https://learn.microsoft.com/zh-cn/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryw

func NtAllocateVirtualMemory

func NtAllocateVirtualMemory(processHandle windows.Handle, baseAddress *byte, zeroBits uintptr, regionSize uintptr, allocationType uintptr, protect uintptr) (value uintptr, err error)

NtAllocateVirtualMemory 在指定进程的用户模式虚拟地址空间中保留和/或提交页面区域。

__kernel_entry NTSYSCALLAPI NTSTATUS NtAllocateVirtualMemory(

[in]      HANDLE    ProcessHandle,
[in, out] PVOID     *BaseAddress,
[in]      ULONG_PTR ZeroBits,
[in, out] PSIZE_T   RegionSize,
[in]      ULONG     AllocationType,
[in]      ULONG     Protect
);

NtAllocateVirtualMemory returns either STATUS_SUCCESS or an error status code

Link: https://learn.microsoft.com/zh-cn/windows-hardware/drivers/ddi/ntifs/nf-ntifs-ntallocatevirtualmemory

func NtCreateSection

func NtCreateSection(sectionHandle *windows.Handle, desiredAccess uint32, objectAttributes *OBJECT_ATTRIBUTES, maximumSize *int64, sectionPageProtection uint32, allocationAttributes uint32, fileHandle windows.Handle) (err error)

NtCreateSection 例程创建一个节对象**

__kernel_entry NTSYSCALLAPI NTSTATUS NtCreateSection(

  [out]          PHANDLE            SectionHandle,
  [in]           ACCESS_MASK        DesiredAccess,
  [in, optional] POBJECT_ATTRIBUTES ObjectAttributes,
  [in, optional] PLARGE_INTEGER     MaximumSize,
  [in]           ULONG              SectionPageProtection,
  [in]           ULONG              AllocationAttributes,
  [in, optional] HANDLE             FileHandle
);

NtCreateSection 在成功时返回STATUS_SUCCESS,或在失败时返回相应的 NTSTATUS 错误代码

link: https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-ntcreatesection Github: https://github.com/hillu/go-ntdll/blob/f8894bfa00af/section_generated.go#L24

func NtDelayExecution

func NtDelayExecution(DelayInterval int64) (err error)

NtDelayExecution

NTSYSAPI NTSTATUS NTAPI NtDelayExecution(

IN BOOLEAN              Alertable,
IN PLARGE_INTEGER       DelayInterval
);

func NtQueryInformationProcess

func NtQueryInformationProcess(
	processHandle windows.Handle,
	processInformationClass uint32,
	processInformation unsafe.Pointer,
	processInformationLength uintptr,
	returnLength *uintptr,
) (NTSTATUS uintptr, err error)

NtQueryInformationProcess

  • 检索有关指定进程的信息

__kernel_entry NTSTATUS NtQueryInformationProcess(

[in]            HANDLE           ProcessHandle,
[in]            PROCESSINFOCLASS ProcessInformationClass,
[out]           PVOID            ProcessInformation,
[in]            ULONG            ProcessInformationLength,
[out, optional] PULONG           ReturnLength

);

  • 返回值

函数返回 NTSTATUS 成功或错误代码。 NTSTATUS 错误代码的形式和意义列在 DDK 中提供的 Ntstatus.h 头文件中

func NtQueryInformationProcessZ

func NtQueryInformationProcessZ(
	processHandle windows.Handle,
	processInformationClass uintptr,
	processInformation uintptr,
	processInformationLength uintptr,
	returnLength uintptr,
) (value uintptr, err error)

NtQueryInformationProcessZ 暂代 NtQueryInformationProcess(调用参数错误) 的使用

func NtQueryInformationThread

func NtQueryInformationThread(threadHandle windows.Handle, threadInformationClass uintptr, threadInformation uintptr, threadInformationLength uintptr, returnLength uintptr) (value uintptr, err error)

NtQueryInformationThread 在 Windows 的未来版本中可能已更改或不可用。 应用程序应使用本主题中列出的备用函数。 检索有关指定线程的信息。

__kernel_entry NTSTATUS NtQueryInformationThread(

[in]            HANDLE          ThreadHandle,
[in]            THREADINFOCLASS ThreadInformationClass,
[in, out]       PVOID           ThreadInformation,
[in]            ULONG           ThreadInformationLength,
[out, optional] PULONG          ReturnLength
);

返回 NTSTATUS 成功或错误代码。 NTSTATUS 错误代码的形式和意义列在 DDK 中提供的 Ntstatus.h 头文件中,并在 DDK 文档中 Kernel-Mode 驱动程序体系结构/设计指南/驱动程序编程技术/日志记录错误下进行了介绍。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/winternl/nf-winternl-ntqueryinformationthread?redirectedfrom=MSDN

func NtQueueApcThreadEx

func NtQueueApcThreadEx(threadHandle windows.Handle, userApcOption uintptr, apcRoutine uintptr, args ...uintptr) (err error)

NtQueueApcThreadEx Each time NtQueueApcThread is called, a new KAPC object is allocated in kernel mode (from the kernel pool) to store the data about the APC object. Let’s say there’s a component that queues a lot of APCs, one after another. This can have performance implications because a lot of non-paged memory is used and also allocating memory takes some time.

NTSTATUS NtQueueApcThreadEx(

IN HANDLE ThreadHandle,
IN USER_APC_OPTION UserApcOption,
IN PPS_APC_ROUTINE ApcRoutine,
IN PVOID SystemArgument1 OPTIONAL,
IN PVOID SystemArgument2 OPTIONAL,
IN PVOID SystemArgument3 OPTIONAL
);

Link: https://repnz.github.io/posts/apc/user-apc/#ntqueueapcthreadex-reusing-kernel-memory Gitlab: https://gitlab.com/mjwhitta/runsc/-/blob/v1.3.4/api_windows.go#L157 Github: https://github.com/mjwhitta/win/blob/v0.15.2/api/ntdll_windows.go#L171

func NtWriteVirtualMemory

func NtWriteVirtualMemory(processHandle windows.Handle, baseAddress *byte, buffer *byte, BufferSize uintptr, numberOfBytesWritten *uintptr) (value uintptr, err error)

NtWriteVirtualMemory is similar to WINAPI WriteProcessMemory.

NTSYSCALLAPI NTSTATUS NTAPI NtWriteVirtualMemory(

_In_ HANDLE ProcessHandle,
_In_opt_ PVOID BaseAddress,
_In_reads_bytes_(NumberOfBytesToWrite) PVOID Buffer,
_In_ SIZE_T NumberOfBytesToWrite,
_Out_opt_ PSIZE_T NumberOfBytesWritten
);

Link: https://ntdoc.m417z.com/ntwritevirtualmemory Link: https://undocumented-ntinternals.github.io/index.html?page=UserMode%2FUndocumented%20Functions%2FMemory%20Management%2FVirtual%20Memory%2FNtWriteVirtualMemory.html

func OpenProcess

func OpenProcess(desiredAccess uint32, inheritHandle bool, processId uint32) (handle windows.Handle, err error)

OpenProcess 打开现有的本地进程对象

HANDLE OpenProcess(

[in] DWORD dwDesiredAccess,
[in] BOOL  bInheritHandle,
[in] DWORD dwProcessId
);

如果函数成功,则返回值是指定进程的打开句柄; 如果函数失败,则返回值为 NULL

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/processthreadsapi/nf-processthreadsapi-openprocess

func OpenThread

func OpenThread(desiredAccess uint32, inheritHandle bool, threadId uint32) (handle windows.Handle, err error)

OpenThread 打开现有线程对象

HANDLE OpenThread(

[in] DWORD dwDesiredAccess,
[in] BOOL  bInheritHandle,
[in] DWORD dwThreadId
);

如果函数成功,则返回值是指定线程的打开句柄。 如果函数失败,则返回值为 NULL。

Link: https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-openthread

func QueueUserAPC

func QueueUserAPC(pfnAPC uintptr, hThread uintptr, dwData uintptr) (value uintptr, err error)

QueueUserAPC 将用户模式 异步过程调用 (APC) 对象添加到指定线程的 APC 队列

DWORD QueueUserAPC(

[in] PAPCFUNC  pfnAPC,
[in] HANDLE    hThread,
[in] ULONG_PTR dwData
);

如果该函数成功,则返回值为非零值。 如果函数失败,则返回值为零。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/processthreadsapi/nf-processthreadsapi-queueuserapc

func ReadProcessMemory

func ReadProcessMemory(process windows.Handle, baseAddress uintptr, buffer *byte, size uintptr, numberOfBytesRead *uintptr) (err error)

ReadProcessMemory BOOL ReadProcessMemory(

[in]  HANDLE  hProcess,
[in]  LPCVOID lpBaseAddress,
[out] LPVOID  lpBuffer,
[in]  SIZE_T  nSize,
[out] SIZE_T  *lpNumberOfBytesRead
);

如果该函数成功,则返回值为非零值。 如果函数失败,则返回值为 0。 如果请求的读取操作交叉到无法访问的进程区域,函数将失败。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/memoryapi/nf-memoryapi-readprocessmemory

func ReallocADsMem

func ReallocADsMem(pOldMem uintptr, cbOld uint32, cbNew uint32) (value uintptr, err error)

ReallocADsMem 函数重新分配并复制现有内存块

LPVOID ReallocADsMem(

[in] LPVOID pOldMem, // 指向要复制的内存的指针
[in] DWORD  cbOld, // 要复制的内存的大小(以字节为单位)
[in] DWORD  cbNew  // 要分配的内存的大小(以字节为单位)

);

返回值 类型: LPVOID 成功后,函数返回指向新分配内存的指针。 否则返回 NULL。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/adshlp/nf-adshlp-reallocadsmem

func RegDeleteTreeA

func RegDeleteTreeA(key windows.Handle, subKey string) (value uintptr, err error)

RegDeleteTreeA 以递归方式删除指定键的子项和值

LSTATUS RegDeleteTreeA(

// 打开的注册表项的句柄, 必须已使用以下访问权限打开密钥: DELETE、KEY_ENUMERATE_SUB_KEYS 和 KEY_QUERY_VALUE
[in]           HKEY   hKey,
// 键的名称。 此键必须是 由 hKey 参数标识的密钥的子项。 如果此参数为 NULL,则删除 hKey 的子项和值。
[in, optional] LPCSTR lpSubKey
);

如果函数成功,则返回值为 ERROR_SUCCESS。 如果函数失败,则返回值为 Winerror.h 中定义的非零错误代码。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/winreg/nf-winreg-regdeletetreea

func ResumeThread

func ResumeThread(hThread windows.Handle) (value uintptr, err error)

ResumeThread 递减线程的挂起计数。 当暂停计数减为零时,将恢复线程的执行。

DWORD ResumeThread(

[in] HANDLE hThread // 要重启的线程的句柄
);

如果函数成功,则返回值是线程的上一个挂起计数。 如果函数失败,则返回值 (DWORD) -1。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/processthreadsapi/nf-processthreadsapi-resumethread

func RtlCopyBytes

func RtlCopyBytes(address uintptr, source *byte, length uintptr) (err error)

RtlCopyBytes The RtlCopyBytes routine copies the specified number of bytes from a source memory block to a destination memory block.

VOID RtlCopyBytes(

  _Out_       PVOID  Destination,
  _In_  const VOID   *Source,
  _In_        SIZE_T Length
);

Return value None

Link: https://learn.microsoft.com/en-us/previous-versions/windows/hardware/kernel/ff561806(v=vs.85)

func RtlCopyMemory

func RtlCopyMemory(address unsafe.Pointer, source unsafe.Pointer, length uintptr) (err error)

RtlCopyMemory 例程将源内存块的内容复制到目标内存块

void RtlCopyMemory(

void*       Destination,
const void* Source,
size_t      Length
);

无返回值

Link: https://learn.microsoft.com/zh-cn/windows-hardware/drivers/ddi/wdm/nf-wdm-rtlcopymemory

func RtlEthernetAddressToStringA

func RtlEthernetAddressToStringA(addr *byte, s uintptr) (value uintptr, err error)

RtlEthernetAddressToStringA 将二进制以太网地址转换为以太网 MAC 地址的字符串表示形式

NTSYSAPI PSTR RtlEthernetAddressToStringA(

  [in]  const DL_EUI48 *Addr,
  [out] PSTR           S
);

指向插入到以太网 MAC 地址字符串表示形式的末尾的 NULL 字符的指针。 调用方可以使用它轻松地将更多信息追加到字符串。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/ip2string/nf-ip2string-rtlethernetaddresstostringa

func RtlEthernetStringToAddressA

func RtlEthernetStringToAddressA(s uintptr, terminator *byte, addr *byte) (value uintptr, err error)

RtlEthernetStringToAddressA 将以太网 MAC 地址的字符串表示形式转换为以太网地址的二进制格式

NTSYSAPI NTSTATUS RtlEthernetStringToAddressA(

[in]  PCSTR    S,
[out] PCSTR    *Terminator,
[out] DL_EUI48 *Addr
);

如果函数成功,则返回值 STATUS_SUCCESS。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/ip2string/nf-ip2string-rtlethernetstringtoaddressa

func RtlIpv4AddressToStringA

func RtlIpv4AddressToStringA(addr uintptr, s uintptr) (value uintptr, err error)

RtlIpv4AddressToStringA 将 IPv4 地址转换为 Internet 标准点十进制格式的字符串

NTSYSAPI PSTR RtlIpv4AddressToStringA(

[in]  const in_addr *Addr,
[out] PSTR          S
);

指向在 IPv4 地址的字符串表示形式末尾插入的 NULL 字符的指针。 调用方可以使用它轻松将更多信息追加到字符串。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/ip2string/nf-ip2string-rtlipv4addresstostringa

func RtlIpv4StringToAddressA

func RtlIpv4StringToAddressA(s uintptr, strict uintptr, terminator uintptr, addr uintptr) (NTStatus windows.NTStatus, err error)

RtlIpv4StringToAddressA

RtlIpv4StringToAddressA 将 IPv4 地址的字符串表示形式转换为二进制 IPv4 地址

NTSYSAPI NTSTATUS RtlIpv4StringToAddressA(

[in]  PCSTR   S,           // 指向包含 IPv4 地址的 NULL终止字符串表示形式的缓冲区的指针
[in]  BOOLEAN Strict,      // 一个值,该值指示字符串是否必须是以严格四部分点十进制表示法表示的 IPv4 地址
[out] PCSTR   *Terminator, // 一个参数,该参数接收指向终止转换字符串的字符的指针
[out] in_addr *Addr        // 一个指针,其中存储 IPv4 地址的二进制表示形式
);

如果函数成功,则返回值 STATUS_SUCCESS。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/ip2string/nf-ip2string-rtlipv4stringtoaddressa

func RtlIpv4StringToAddressExA

func RtlIpv4StringToAddressExA(s uintptr, strict uintptr, addr uintptr, port uintptr) (NTStatus windows.NTStatus, err error)

RtlIpv4StringToAddressExA 将 IPv4 地址和端口号的字符串表示形式转换为二进制 IPv4 地址和端口

NTSYSAPI NTSTATUS RtlIpv4StringToAddressExA( [in] PCSTR AddressString, [in] BOOLEAN Strict, [out] in_addr *Address, [out] PUSHORT Port );

如果函数成功,则返回值 STATUS_SUCCESS 如果函数失败,则返回值为 STATUS_INVALID_PARAMETER

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/ip2string/nf-ip2string-rtlipv4stringtoaddressexa

func RtlMoveMemory

func RtlMoveMemory(destination unsafe.Pointer, source unsafe.Pointer, length uintptr) (err error)

RtlMoveMemory 将源内存块的内容复制到目标内存块,并支持重叠的源内存块和目标内存块

VOID RtlMoveMemory(

_Out_       VOID UNALIGNED *Destination,
_In_  const VOID UNALIGNED *Source,
_In_        SIZE_T         Length
);

无返回值

Link: https://learn.microsoft.com/en-us/windows/win32/devnotes/rtlmovememory

func RtlRestoreContext

func RtlRestoreContext(contextRecord *CONTEXT, exceptionRecord *EXCEPTION_RECORD) (err error)

RtlRestoreContext 将调用方上下文还原到指定的上下文记录

NTSYSAPI VOID __cdecl RtlRestoreContext(

PCONTEXT          ContextRecord,   // 指向 CONTEXT 结构的指针
_EXCEPTION_RECORD *ExceptionRecord // 指向 EXCEPTION_RECORD 结构的指针。 此参数是可选的,通常应为 NULL。

);

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/winnt/nf-winnt-rtlrestorecontext

func SetEvent

func SetEvent(event windows.Handle) (err error)

SetEvent 将指定的事件对象设置为信号状态

BOOL SetEvent(

[in] HANDLE hEvent // 事件对象的句柄。 CreateEvent 或 OpenEvent 函数返回此句柄。

);

返回值

  • 如果该函数成功,则返回值为非零值
  • 如果函数失败,则返回值为零。 要获得更多的错误信息,请调用 GetLastError

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/synchapi/nf-synchapi-setevent

func SetFileInformationByHandle

func SetFileInformationByHandle(handle windows.Handle, class uint32, inBuffer *byte, inBufferLen uint32) (err error)

SetFileInformationByHandle 设置指定文件的文件信息。 若要使用文件句柄检索文件信息,请参阅 GetFileInformationByHandle 或 GetFileInformationByHandleEx。

BOOL SetFileInformationByHandle(

[in] HANDLE                    hFile, // 要更改其信息的文件的句柄
[in] FILE_INFO_BY_HANDLE_CLASS FileInformationClass, // 一个FILE_INFO_BY_HANDLE_CLASS枚举值,该值指定要更改的信息的类型
[in] LPVOID                    lpFileInformation, // 指向缓冲区的指针,该缓冲区包含指定文件信息类要更改的信息
[in] DWORD                     dwBufferSize // lpFileInformation 的大小(以字节为单位)
);

如果成功,则返回非零值,否则返回零。 要获得更多的错误信息,请调用 GetLastError。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/fileapi/nf-fileapi-setfileinformationbyhandle

func SetThreadContext

func SetThreadContext(hThread windows.Handle, lpContext *CONTEXT) (value uintptr, err error)

SetThreadContext 设置指定的线程的上下文。 64 位应用程序可以使用 Wow64SetThreadContext 函数设置 WOW64 线程的上下文。

BOOL SetThreadContext(

[in] HANDLE        hThread, 	// 要设置其上下文的线程的句柄
[in] const CONTEXT *lpContext   // 指向 CONTEXT 结构的指针,该结构包含要设置在指定线程中的上下文
);

如果设置了上下文,则返回值为非零值。 如果函数失败,则返回值为零。

CONTEXT 结构: https://learn.microsoft.com/zh-cn/windows/win32/api/winnt/ns-winnt-arm64_nt_context Link: https://learn.microsoft.com/zh-cn/windows/win32/api/processthreadsapi/nf-processthreadsapi-setthreadcontext

func ShowWindow

func ShowWindow(handle windows.Handle, cmdShow int32) (err error)

ShowWindow 设置指定窗口的显示状态

BOOL ShowWindow(

[in] HWND hWnd,
[in] int  nCmdShow
);

返回值 类型: BOOL 如果窗口以前可见,则返回值为非零值。 如果以前隐藏窗口,则返回值为零。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/winuser/nf-winuser-showwindow

func SleepEx

func SleepEx(dwMilliseconds uint32, bAlertable bool) (value uintptr, err error)

SleepEx 挂起当前线程,直到满足指定的条件。 发生以下情况之一时,将继续执行:

调用 I/O 完成回调函数。
异步过程调用 (APC) 排队到线程。
超时间隔已过。

DWORD SleepEx(

[in] DWORD dwMilliseconds,   // 暂停执行的时间间隔(以毫秒为单位)
[in] BOOL  bAlertable        // 如果此参数为 FALSE,则函数在超时期限过后才会返回

);

返回值 如果指定的时间间隔过期,则返回值为零。

如果函数由于一个或多个 I/O 完成回调函数而返回,则返回值WAIT_IO_COMPLETION。 仅当 bAlertable 为 TRUE,并且调用 SleepEx 函数的线程与调用扩展 I/O 函数的线程相同时,才会发生这种情况。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/synchapi/nf-synchapi-sleepex

func SuspendThread

func SuspendThread(hThread windows.Handle) (value uintptr, err error)

SuspendThread 挂起指定的线程。 64 位应用程序可以使用 Wow64SuspendThread 函数挂起 WOW64 线程。

DWORD SuspendThread(

[in] HANDLE hThread // 要挂起的线程的句柄
);

如果函数成功,则返回值为线程的上一个挂起计数;否则为 (DWORD) -1。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/processthreadsapi/nf-processthreadsapi-suspendthread

func SwitchToFiber

func SwitchToFiber(lpFiber uintptr) (value uintptr, err error)

SwitchToFiber Schedules a fiber. The function must be called on a fiber.

Void SwitchToFiber(

[in] LPVOID lpFiber
);

None return value.

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/winbase/nf-winbase-switchtofiber

func TerminateThread

func TerminateThread(hThread uintptr, dwExitCode uint32) (value uintptr, err error)

TerminateThread 终止线程

BOOL TerminateThread(

[in, out] HANDLE hThread,
[in]      DWORD  dwExitCode
);

如果该函数成功,则返回值为非零值。 如果函数失败,则返回值为零。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/processthreadsapi/nf-processthreadsapi-terminatethread

func Thread32First

func Thread32First(snapshot windows.Handle, threadEntry *ThreadEntry32) (err error)

Thread32First 检索系统快照中遇到的任何进程的第一个线程的相关信息

BOOL Thread32First(

[in]      HANDLE          hSnapshot,
[in, out] LPTHREADENTRY32 lpte
);

如果线程列表的第一个条目已复制到缓冲区,则返回 TRUE ,否则返回 FALSE 。 如果不存在线程或快照不包含线程信息,则 GetLastError 函数返回ERROR_NO_MORE_FILES错误值。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/tlhelp32/nf-tlhelp32-thread32first

func TimeGetTime

func TimeGetTime() (value uintptr, err error)

TimeGetTime timeGetTime 函数检索系统时间(以毫秒为单位)。 系统时间是 Windows 启动以来经过的时间。

DWORD timeGetTime();

返回值 返回系统时间(以毫秒为单位)。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/timeapi/nf-timeapi-timegettime

func TimeGetTimeC

func TimeGetTimeC() uint32

func UuidFromStringA

func UuidFromStringA(stringUuid *byte, uuid uintptr) (RpcSOk uint32, err error)

UuidFromStringA UuidFromString 函数将字符串转换为 UUID。

RPC_STATUS UuidFromStringA(

RPC_CSTR StringUuid,
UUID     *Uuid
);

返回值 RPC_S_OK: 调用成功。 RPC_S_INVALID_STRING_UUID: 字符串 UUID 无效。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/rpcdce/nf-rpcdce-uuidfromstringa

func VirtualAlloc

func VirtualAlloc(address uintptr, size uintptr, alloctype uint32, protect uint32) (value uintptr, err error)

VirtualAlloc 保留、提交或更改调用进程的虚拟地址空间中页面区域的状态, 此函数分配的内存会自动初始化为零 若要在另一个进程的地址空间中分配内存,请使用 VirtualAllocEx 函数

LPVOID VirtualAlloc(

  [in, optional] LPVOID lpAddress,
  [in]           SIZE_T dwSize,
  [in]           DWORD  flAllocationType, (MEM_COMMIT | MEM_RESERVE)
  [in]           DWORD  flProtect         (PAGE_READWRITE or PAGE_EXECUTE_READWRITE)
);

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/memoryapi/nf-memoryapi-virtualalloc

func VirtualAllocEx

func VirtualAllocEx(hProcess windows.Handle, lpAddress uintptr, dwSize uintptr, allocType uint32, protect uint32) (value uintptr, err error)

VirtualAllocEx 在指定进程的虚拟地址空间中保留、提交或更改内存区域的状态。 函数将它分配的内存初始化为零 若要为物理内存指定 NUMA 节点,请参阅 VirtualAllocExNuma

LPVOID VirtualAllocEx(

  [in]           HANDLE hProcess,
  [in, optional] LPVOID lpAddress,
  [in]           SIZE_T dwSize,
  [in]           DWORD  flAllocationType,
  [in]           DWORD  flProtect
);

如果函数成功,则返回值是已分配页区域的基址 如果函数失败,则返回值为 NULL

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/memoryapi/nf-memoryapi-virtualallocex

func VirtualAllocExNuma

func VirtualAllocExNuma(
	hProcess windows.Handle,
	lpAddress uintptr,
	dwSize uintptr,
	flAllocationType uint32,
	flProtect uint32,
	nndPreferred uint32,
) (value uintptr, err error)

VirtualAllocExNuma 保留、提交或更改指定进程的虚拟地址空间中的内存区域的状态,并为物理内存指定 NUMA 节点

LPVOID VirtualAllocExNuma(

[in]           HANDLE hProcess,         // 进程的句柄
[in, optional] LPVOID lpAddress,        // 为要分配的页面区域指定所需起始地址的指针
[in]           SIZE_T dwSize,           // 要分配的内存区域的大小(以字节为单位)
[in]           DWORD  flAllocationType, // 内存分配的类型
[in]           DWORD  flProtect,        // 要分配的页区域的内存保护
[in]           DWORD  nndPreferred      // 物理内存应驻留的 NUMA 节点

);

返回值 如果函数成功,则返回值是已分配页区域的基址 如果函数失败,则返回值为 NULL。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/memoryapi/nf-memoryapi-virtualallocexnuma

func VirtualProtect

func VirtualProtect(address uintptr, size uintptr, newProtect uint32, oldProtect *uint32) (value uintptr, err error)

VirtualProtect 更改调用进程的虚拟地址空间中已提交页面区域的保护 若要更改任何进程的访问保护,请使用 VirtualProtectEx 函数

BOOL VirtualProtect(

  [in]  LPVOID lpAddress,
  [in]  SIZE_T dwSize,
  [in]  DWORD  flNewProtect,
  [out] DWORD  lpflOldProtect
);

如果该函数成功,则返回值为非零值

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/memoryapi/nf-memoryapi-virtualprotect

func VirtualProtectEx

func VirtualProtectEx(process windows.Handle, address uintptr, size uintptr, newProtect uint32, oldProtect *uint32) (err error)

VirtualProtectEx 更改指定进程的虚拟地址空间中已提交页面区域的保护

BOOL VirtualProtectEx(

[in]  HANDLE hProcess,
[in]  LPVOID lpAddress,
[in]  SIZE_T dwSize,
[in]  DWORD  flNewProtect,
[out] PDWORD lpflOldProtect
);

如果该函数成功,则返回值为非零值

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/memoryapi/nf-memoryapi-virtualprotectex

func WaitForSingleObject

func WaitForSingleObject(handle windows.Handle, waitMilliseconds uint32) (event uint32, err error)

WaitForSingleObject Waits until the specified object is in the signaled state or the time-out interval elapses. To enter an alertable wait state, use the WaitForSingleObjectEx function. To wait for multiple objects, use WaitForMultipleObjects.

DWORD WaitForSingleObject(

[in] HANDLE hHandle,
[in] DWORD  dwMilliseconds
);

If the function succeeds, the return value indicates the event that caused the function to return. It can be one of the following values.

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/synchapi/nf-synchapi-waitforsingleobject

func WriteProcessMemory

func WriteProcessMemory(process windows.Handle, baseAddress uintptr, buffer *byte, size uintptr, numberOfBytesWritten *uintptr) (err error)

WriteProcessMemory 将数据写入到指定进程中的内存区域。 要写入的整个区域必须可访问,否则操作将失败

BOOL WriteProcessMemory(

[in]  HANDLE  hProcess,
[in]  LPVOID  lpBaseAddress,
[in]  LPCVOID lpBuffer,
[in]  SIZE_T  nSize,
[out] SIZE_T  *lpNumberOfBytesWritten
);

如果该函数成功,则返回值为非零值。 如果函数失败,则返回值为 0(零)。 要获得更多的错误信息,请调用 GetLastError。 如果请求的写入操作交叉到无法访问的进程区域,函数将失败。

Link: https://learn.microsoft.com/zh-cn/windows/win32/api/memoryapi/nf-memoryapi-writeprocessmemory

Types

type BASE_RELOCATION_BLOCK

type BASE_RELOCATION_BLOCK struct {
	PageAddress uint32
	BlockSize   uint32
}

type BASE_RELOCATION_ENTRY

type BASE_RELOCATION_ENTRY struct {
	OffsetType uint16
}

func (BASE_RELOCATION_ENTRY) Offset

func (e BASE_RELOCATION_ENTRY) Offset() uint16

func (BASE_RELOCATION_ENTRY) Type

func (e BASE_RELOCATION_ENTRY) Type() uint8

type CONTEXT

type CONTEXT struct {
	P1Home               uint64
	P2Home               uint64
	P3Home               uint64
	P4Home               uint64
	P5Home               uint64
	P6Home               uint64
	ContextFlags         uint32
	MxCsr                uint32
	SegCs                uint16
	SegDs                uint16
	SegEs                uint16
	SegFs                uint16
	SegGs                uint16
	SegSs                uint16
	EFlags               uint32
	Dr0                  uint64
	Dr1                  uint64
	Dr2                  uint64
	Dr3                  uint64
	Dr6                  uint64
	Dr7                  uint64
	Rax                  uint64
	Rcx                  uint64
	Rdx                  uint64
	Rbx                  uint64
	Rsp                  uint64
	Rbp                  uint64
	Rsi                  uint64
	Rdi                  uint64
	R8                   uint64
	R9                   uint64
	R10                  uint64
	R11                  uint64
	R12                  uint64
	R13                  uint64
	R14                  uint64
	R15                  uint64
	Rip                  uint64
	FltSave              XMM_SAVE_AREA32
	VectorRegister       [26]M128A
	VectorControl        uint64
	DebugControl         uint64
	LastBranchToRip      uint64
	LastBranchFromRip    uint64
	LastExceptionToRip   uint64
	LastExceptionFromRip uint64
}

CONTEXT represents the full CPU context for x64 architecture

  • CONTEXT 结构体是 Windows 系统中用于保存线程上下文(Thread Context)的核心数据结构,主要用于操作系统内核和应用程序之间传递线程的执行状态
  • 核心作用是 捕获或修改线程在某一时刻的完整 CPU 状态 ,包括寄存器、浮点运算、调试寄存器、向量寄存器等信息

https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-context

type EXCEPTION_RECORD

type EXCEPTION_RECORD struct {
	ExceptionCode    uint32
	ExceptionFlags   uint32
	ExceptionRecord  *EXCEPTION_RECORD
	ExceptionAddress uintptr
	NumberParameters uint32

	ExceptionInformation [15]uintptr
	// contains filtered or unexported fields
}

EXCEPTION_RECORD struct matches WinSDK definition

type IMAGE_DATA_DIRECTORY

type IMAGE_DATA_DIRECTORY struct {
	VirtualAddress uint32
	Size           uint32
}

type IMAGE_DOS_HEADER

type IMAGE_DOS_HEADER struct {
	E_magic    uint16
	E_cblp     uint16
	E_cp       uint16
	E_crlc     uint16
	E_cparhdr  uint16
	E_minalloc uint16
	E_maxalloc uint16
	E_ss       uint16
	E_sp       uint16
	E_csum     uint16
	E_ip       uint16
	E_cs       uint16
	E_lfarlc   uint16
	E_ovno     uint16
	E_res      [4]uint16
	E_oemid    uint16
	E_oeminfo  uint16
	E_res2     [10]uint16
	E_lfanew   int32
}

type IMAGE_EXPORT_DIRECTORY

type IMAGE_EXPORT_DIRECTORY struct {
	Characteristics       uint32
	TimeDateStamp         uint32
	MajorVersion          uint16
	MinorVersion          uint16
	Name                  uint32
	Base                  uint32
	NumberOfFunctions     uint32
	NumberOfNames         uint32
	AddressOfFunctions    uint32 // RVA
	AddressOfNames        uint32 // RVA
	AddressOfNameOrdinals uint32 // RVA
}

type IMAGE_FILE_HEADER

type IMAGE_FILE_HEADER struct {
	Machine              uint16
	NumberOfSections     uint16
	TimeDateStamp        uint32
	PointerToSymbolTable uint32
	NumberOfSymbols      uint32
	SizeOfOptionalHeader uint16
	Characteristics      uint16
}

type IMAGE_IMPORT_DESCRIPTOR

type IMAGE_IMPORT_DESCRIPTOR struct {
	Characteristics uint32
	TimeDateStamp   uint32
	ForwarderChain  uint32
	Name            uint32
	FirstThunk      uint32
}

type IMAGE_NT_HEADERS32

type IMAGE_NT_HEADERS32 struct {
	Signature      uint32
	FileHeader     IMAGE_FILE_HEADER
	OptionalHeader IMAGE_OPTIONAL_HEADER32
}

type IMAGE_NT_HEADERS64

type IMAGE_NT_HEADERS64 struct {
	Signature      uint32
	FileHeader     IMAGE_FILE_HEADER
	OptionalHeader IMAGE_OPTIONAL_HEADER64
}

type IMAGE_OPTIONAL_HEADER32

type IMAGE_OPTIONAL_HEADER32 struct {
	Magic                       uint16
	MajorLinkerVersion          uint8
	MinorLinkerVersion          uint8
	SizeOfCode                  uint32
	SizeOfInitializedData       uint32
	SizeOfUninitializedData     uint32
	AddressOfEntryPoint         uint32
	BaseOfCode                  uint32
	BaseOfData                  uint32
	ImageBase                   uint32
	SectionAlignment            uint32
	FileAlignment               uint32
	MajorOperatingSystemVersion uint16
	MinorOperatingSystemVersion uint16
	MajorImageVersion           uint16
	MinorImageVersion           uint16
	MajorSubsystemVersion       uint16
	MinorSubsystemVersion       uint16
	Win32VersionValue           uint32
	SizeOfImage                 uint32
	SizeOfHeaders               uint32
	CheckSum                    uint32
	Subsystem                   uint16
	DllCharacteristics          uint16
	SizeOfStackReserve          uint32
	SizeOfStackCommit           uint32
	SizeOfHeapReserve           uint32
	SizeOfHeapCommit            uint32
	LoaderFlags                 uint32
	NumberOfRvaAndSizes         uint32
	DataDirectory               [IMAGE_NUMBEROF_DIRECTORY_ENTRIES]IMAGE_DATA_DIRECTORY
}

type IMAGE_OPTIONAL_HEADER64

type IMAGE_OPTIONAL_HEADER64 struct {
	Magic                       uint16
	MajorLinkerVersion          uint8
	MinorLinkerVersion          uint8
	SizeOfCode                  uint32
	SizeOfInitializedData       uint32
	SizeOfUninitializedData     uint32
	AddressOfEntryPoint         uint32
	BaseOfCode                  uint32
	ImageBase                   uint64
	SectionAlignment            uint32
	FileAlignment               uint32
	MajorOperatingSystemVersion uint16
	MinorOperatingSystemVersion uint16
	MajorImageVersion           uint16
	MinorImageVersion           uint16
	MajorSubsystemVersion       uint16
	MinorSubsystemVersion       uint16
	Win32VersionValue           uint32
	SizeOfImage                 uint32
	SizeOfHeaders               uint32
	CheckSum                    uint32
	Subsystem                   uint16
	DllCharacteristics          uint16
	SizeOfStackReserve          uint64
	SizeOfStackCommit           uint64
	SizeOfHeapReserve           uint64
	SizeOfHeapCommit            uint64
	LoaderFlags                 uint32
	NumberOfRvaAndSizes         uint32
	DataDirectory               [IMAGE_NUMBEROF_DIRECTORY_ENTRIES]IMAGE_DATA_DIRECTORY
}

type IMAGE_SECTION_HEADER

type IMAGE_SECTION_HEADER struct {
	Name                 [IMAGE_SIZEOF_SHORT_NAME]byte
	Misc                 [4]byte
	VirtualAddress       uint32
	SizeOfRawData        uint32
	PointerToRawData     uint32
	PointerToRelocations uint32
	PointerToLinenumbers uint32
	NumberOfRelocations  uint16
	NumberOfLinenumbers  uint16
	Characteristics      uint32
}

type M128A

type M128A struct {
	Low  uint64
	High uint64
}

M128A represents a 128-bit value aligned to 16 bytes https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-context

type MMTIME

type MMTIME struct {
	WType uint32
	U     struct {
		MS     uint32
		Sample uint32
		Cb     uint32
		Ticks  uint32

		// SMPTE 子结构体(8字节)
		Smpte struct {
			Hour  byte
			Min   byte
			Sec   byte
			Frame byte
			FPS   byte
			Dummy byte
			Pad   [2]byte
		}

		// MIDI 子结构体(4字节)
		Midi struct {
			SongPtrPos uint32
		}
	}
}

MMTIME https://learn.microsoft.com/zh-cn/previous-versions/dd757347(v=vs.85)

type SYSTEMTIME

type SYSTEMTIME struct {
	Year         uint16
	Month        uint16
	DayOfWeek    uint16
	Day          uint16
	Hour         uint16
	Minute       uint16
	Second       uint16
	Milliseconds uint16
}

SYSTEMTIME https://learn.microsoft.com/zh-cn/windows/win32/api/minwinbase/ns-minwinbase-systemtime

type XMM_SAVE_AREA32

type XMM_SAVE_AREA32 struct {
	ControlWord    uint16
	StatusWord     uint16
	TagWord        byte
	Reserved1      byte
	ErrorOpcode    uint16
	ErrorOffset    uint32
	ErrorSelector  uint16
	Reserved2      uint16
	DataOffset     uint32
	DataSelector   uint16
	Reserved3      uint16
	MxCsr          uint32
	MxCsr_Mask     uint32
	FloatRegisters [8]M128A
	XmmRegisters   [16]M128A
	Reserved4      [96]byte
}

XMM_SAVE_AREA32 represents the XMM register save area https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-context

Directories

Path Synopsis
OPUS 4
OPUS 4

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL