├── .vscode └── settings.json ├── go.mod ├── go.sum ├── .gitignore ├── examples ├── propertystore │ └── propertystore.go ├── window_helloworld │ └── windows_helloworld.go └── console_io │ └── console_io.go ├── win32 ├── 0_package.go ├── System.Mailslots.go ├── 2_utils.go ├── System.IO.go ├── UI.Shell.Common.go ├── System.Time.go ├── System.Diagnostics.ToolHelp.go ├── System.Kernel.go ├── UI.Input.go ├── UI.HiDpi.go ├── System.Pipes.go ├── 1_supplement.go ├── Security.AppLocker.go ├── System.Shutdown.go ├── System.StationsAndDesktops.go ├── System.Diagnostics.ProcessSnapshotting.go ├── System.Environment.go └── System.LibraryLoader.go ├── README.md └── LICENSE /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "gopls": { 3 | "analyses": { 4 | "unsafeptr": false 5 | } 6 | } 7 | } -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/zzl/go-win32api/v2 2 | 3 | go 1.19 4 | 5 | require golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f 6 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f h1:rlezHXNlxYWvBCzNses9Dlc7nGFaNMJeqLolcmQSSZY= 2 | golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # Dependency directories (remove the comment below to include it) 15 | # vendor/ 16 | .idea/ 17 | x/ 18 | test/ 19 | 20 | go.work 21 | -------------------------------------------------------------------------------- /examples/propertystore/propertystore.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/zzl/go-win32api/v2/examples/propertystore/win32x" 5 | "github.com/zzl/go-win32api/v2/win32" 6 | "runtime" 7 | "unsafe" 8 | ) 9 | 10 | func main() { 11 | 12 | runtime.LockOSThread() 13 | win32.CoInitialize(nil) 14 | defer win32.CoUninitialize() 15 | 16 | // 17 | var pps *win32.IPropertyStore 18 | hr := win32.SHGetPropertyStoreFromParsingName( 19 | win32.StrToPwstr(`D:\Test\arial.ttf`), 20 | nil, win32.GPS_DEFAULT, 21 | &win32.IID_IPropertyStore, 22 | unsafe.Pointer(&pps), 23 | ) 24 | win32.ASSERT_SUCCEEDED(hr) 25 | defer pps.Release() 26 | 27 | // 28 | var pv win32.PROPVARIANT 29 | hr = pps.GetValue(&win32x.PKEY_Trademarks, &pv) 30 | win32.ASSERT_SUCCEEDED(hr) 31 | defer win32.PropVariantClear(&pv) 32 | 33 | // 34 | var pwszTrademarks win32.PWSTR 35 | hr = win32x.PSFormatForDisplayAlloc(&win32x.PKEY_Trademarks, &pv, win32.PDFF_DEFAULT, &pwszTrademarks) 36 | win32.ASSERT_SUCCEEDED(hr) 37 | defer win32.CoTaskMemFree(unsafe.Pointer(pwszTrademarks)) 38 | 39 | // 40 | trademarks := win32.PwstrToStr(pwszTrademarks) 41 | println(trademarks) 42 | 43 | } 44 | -------------------------------------------------------------------------------- /win32/0_package.go: -------------------------------------------------------------------------------- 1 | package win32 2 | 3 | import ( 4 | "golang.org/x/sys/windows" 5 | "sync/atomic" 6 | ) 7 | 8 | var ( 9 | libAdvapi32 = windows.NewLazySystemDLL("advapi32.dll") 10 | libComctl32 = windows.NewLazySystemDLL("comctl32.dll") 11 | libComdlg32 = windows.NewLazySystemDLL("comdlg32.dll") 12 | libGdi32 = windows.NewLazySystemDLL("gdi32.dll") 13 | libGdiplus = windows.NewLazySystemDLL("gdiplus.dll") 14 | libKernel32 = windows.NewLazySystemDLL("kernel32.dll") 15 | libMsimg32 = windows.NewLazySystemDLL("msimg32.dll") 16 | libOle32 = windows.NewLazySystemDLL("ole32.dll") 17 | libOleaut32 = windows.NewLazySystemDLL("oleaut32.dll") 18 | libPdh = windows.NewLazySystemDLL("pdh.dll") 19 | libShell32 = windows.NewLazySystemDLL("shell32.dll") 20 | libShlwapi = windows.NewLazySystemDLL("shlwapi.dll") 21 | libUser32 = windows.NewLazySystemDLL("user32.dll") 22 | libUserenv = windows.NewLazySystemDLL("userenv.dll") 23 | libUxtheme = windows.NewLazySystemDLL("uxtheme.dll") 24 | libVersion = windows.NewLazySystemDLL("version.dll") 25 | libPropsys = windows.NewLazySystemDLL("propsys.dll") 26 | 27 | // 28 | libApi_ms_win_core_winrt_string_l1_1_0 = windows.NewLazySystemDLL( 29 | "api-ms-win-core-winrt-string-l1-1-0.dll") 30 | libApi_ms_win_core_winrt_l1_1_0 = windows.NewLazySystemDLL( 31 | "api-ms-win-core-winrt-l1-1-0.dll") 32 | ) 33 | 34 | func LazyAddr(pAddr *uintptr, lib *windows.LazyDLL, procName string) uintptr { 35 | addr := atomic.LoadUintptr(pAddr) 36 | if addr == 0 { 37 | addr = lib.NewProc(procName).Addr() 38 | atomic.StoreUintptr(pAddr, addr) 39 | } 40 | return addr 41 | } 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | :ukraine: 2 | 3 | # go-win32api 4 | 5 | Win32 API bindings for Go. 6 | 7 | **Bindings:** 8 | All bindings are implemented through syscall, without using cgo. 9 | 10 | **Code Generation:** 11 | Most of the code is generated from win32metadata, an official 12 | Microsoft publication that describes Win32 APIs. 13 | 14 | **API Coverage:** 15 | The library includes frequently used APIs. 16 | Less common ones are omitted. 17 | You can generate your own code for these using the code generator available 18 | [here](https://github.com/zzl/go-winapi-gen). 19 | 20 | ## Status 21 | Currently, only the 64-bit architecture is supported and tested. 22 | 23 | ## Installation 24 | ``` 25 | go get github.com/zzl/go-win32api/v2 26 | ``` 27 | ```go 28 | import "github.com/zzl/go-win32api/v2/win32" 29 | ``` 30 | 31 | ## Unions 32 | Union fields are mapped to accessor methods in Go. 33 | These methods share the same name as the fields and 34 | return pointers to allow assigning new values. 35 | Additionally, a value accessor method is generated for each field, 36 | following the naming pattern FieldName+Val. 37 | 38 | ## Example: 39 | Consider this C Union: 40 | ```c 41 | union QWord { 42 | UINT64 WholeValue; 43 | struct { 44 | UINT32 LowPart; 45 | UINT32 HighPart; 46 | } Parts; 47 | }; 48 | ``` 49 | 50 | Here's how you would access and set field values in Go: 51 | ```go 52 | var qw QWord 53 | var whole uint64 = qw.WholeValueVal() // or whole = *qw.WholeValue() 54 | var lowPart uint32 = qw.Parts().LowPart 55 | 56 | // Setting values: 57 | *qw.WholeValue() = 123 58 | qw.Parts().LowPart = 4 59 | ``` 60 | -------------------------------------------------------------------------------- /win32/System.Mailslots.go: -------------------------------------------------------------------------------- 1 | package win32 2 | 3 | import ( 4 | "syscall" 5 | "unsafe" 6 | ) 7 | 8 | var ( 9 | pCreateMailslotA uintptr 10 | pCreateMailslotW uintptr 11 | pGetMailslotInfo uintptr 12 | pSetMailslotInfo uintptr 13 | ) 14 | 15 | func CreateMailslotA(lpName PSTR, nMaxMessageSize uint32, lReadTimeout uint32, lpSecurityAttributes *SECURITY_ATTRIBUTES) (HANDLE, WIN32_ERROR) { 16 | addr := LazyAddr(&pCreateMailslotA, libKernel32, "CreateMailslotA") 17 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpName)), uintptr(nMaxMessageSize), uintptr(lReadTimeout), uintptr(unsafe.Pointer(lpSecurityAttributes))) 18 | return ret, WIN32_ERROR(err) 19 | } 20 | 21 | var CreateMailslot = CreateMailslotW 22 | 23 | func CreateMailslotW(lpName PWSTR, nMaxMessageSize uint32, lReadTimeout uint32, lpSecurityAttributes *SECURITY_ATTRIBUTES) (HANDLE, WIN32_ERROR) { 24 | addr := LazyAddr(&pCreateMailslotW, libKernel32, "CreateMailslotW") 25 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpName)), uintptr(nMaxMessageSize), uintptr(lReadTimeout), uintptr(unsafe.Pointer(lpSecurityAttributes))) 26 | return ret, WIN32_ERROR(err) 27 | } 28 | 29 | func GetMailslotInfo(hMailslot HANDLE, lpMaxMessageSize *uint32, lpNextSize *uint32, lpMessageCount *uint32, lpReadTimeout *uint32) (BOOL, WIN32_ERROR) { 30 | addr := LazyAddr(&pGetMailslotInfo, libKernel32, "GetMailslotInfo") 31 | ret, _, err := syscall.SyscallN(addr, hMailslot, uintptr(unsafe.Pointer(lpMaxMessageSize)), uintptr(unsafe.Pointer(lpNextSize)), uintptr(unsafe.Pointer(lpMessageCount)), uintptr(unsafe.Pointer(lpReadTimeout))) 32 | return BOOL(ret), WIN32_ERROR(err) 33 | } 34 | 35 | func SetMailslotInfo(hMailslot HANDLE, lReadTimeout uint32) (BOOL, WIN32_ERROR) { 36 | addr := LazyAddr(&pSetMailslotInfo, libKernel32, "SetMailslotInfo") 37 | ret, _, err := syscall.SyscallN(addr, hMailslot, uintptr(lReadTimeout)) 38 | return BOOL(ret), WIN32_ERROR(err) 39 | } 40 | -------------------------------------------------------------------------------- /examples/window_helloworld/windows_helloworld.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/zzl/go-win32api/v2/win32" 5 | "runtime" 6 | "syscall" 7 | ) 8 | 9 | /* 10 | https://github.com/microsoft/Windows-classic-samples 11 | /blob/main/Samples/Win7Samples/begin/LearnWin32/HelloWorld/cpp/main.cpp 12 | */ 13 | 14 | func main() { 15 | 16 | runtime.LockOSThread() 17 | hInstance, _ := win32.GetModuleHandle(nil) 18 | 19 | // Register the window class. 20 | CLASS_NAME := win32.StrToPwstr("Sample Window Class") 21 | 22 | var wc win32.WNDCLASS 23 | wc.LpfnWndProc = syscall.NewCallback(WindowProc) 24 | wc.HCursor, _ = win32.LoadCursor(win32.NULL, win32.IDC_ARROW) 25 | wc.LpszClassName = CLASS_NAME 26 | 27 | win32.RegisterClass(&wc) 28 | 29 | // Create the window. 30 | hwnd, _ := win32.CreateWindowEx( 31 | 0, // Optional window styles. 32 | CLASS_NAME, // Window class 33 | win32.StrToPwstr("Learn to Program Windows"), // Window text 34 | win32.WS_OVERLAPPEDWINDOW, // Window style 35 | 36 | // Size and position 37 | win32.CW_USEDEFAULT, win32.CW_USEDEFAULT, win32.CW_USEDEFAULT, win32.CW_USEDEFAULT, 38 | 39 | win32.NULL, // Parent window 40 | win32.NULL, // Menu 41 | hInstance, // Instance handle 42 | nil, // Additional application data 43 | ) 44 | 45 | if hwnd == win32.NULL { 46 | return 47 | } 48 | 49 | win32.ShowWindow(hwnd, win32.SW_SHOWDEFAULT) 50 | 51 | // Run the message loop. 52 | var msg win32.MSG 53 | for { 54 | ok, _ := win32.GetMessage(&msg, win32.NULL, 0, 0) 55 | if ok == win32.FALSE { 56 | break 57 | } 58 | win32.TranslateMessage(&msg) 59 | win32.DispatchMessage(&msg) 60 | } 61 | } 62 | 63 | func WindowProc(hwnd win32.HWND, uMsg win32.UINT, wParam win32.WPARAM, lParam win32.LPARAM) win32.LRESULT { 64 | switch uMsg { 65 | case win32.WM_DESTROY: 66 | win32.PostQuitMessage(0) 67 | return 0 68 | case win32.WM_PAINT: 69 | var ps win32.PAINTSTRUCT 70 | hdc := win32.BeginPaint(hwnd, &ps) 71 | 72 | // All painting occurs here, between BeginPaint and EndPaint. 73 | win32.FillRect(hdc, &ps.RcPaint, win32.HBRUSH(win32.COLOR_WINDOW+1)) 74 | 75 | wszText, _ := syscall.UTF16FromString("Hello world!") 76 | win32.TextOut(hdc, 10, 10, &wszText[0], int32(len(wszText)-1)) 77 | 78 | win32.EndPaint(hwnd, &ps) 79 | return 0 80 | } 81 | return win32.DefWindowProc(hwnd, uMsg, wParam, lParam) 82 | } 83 | -------------------------------------------------------------------------------- /win32/2_utils.go: -------------------------------------------------------------------------------- 1 | package win32 2 | 3 | import ( 4 | "errors" 5 | "log" 6 | "strconv" 7 | "strings" 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | func HRESULT_ToString(hr HRESULT) string { 13 | const bufSize = 255 14 | buf := make([]uint16, bufSize) 15 | flags := FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS 16 | FormatMessage(flags, nil, uint32(hr), 0, &buf[0], bufSize, nil) 17 | hrHex := strconv.FormatUint(uint64(uint32(hr)), 16) 18 | s := syscall.UTF16ToString(buf) 19 | s = strings.TrimSpace(s) 20 | s = "HRESULT " + hrHex + " - " + s 21 | return s 22 | } 23 | 24 | func ASSERT_SUCCEEDED(hr HRESULT) { 25 | if FAILED(hr) { 26 | log.Fatal(HRESULT_ToString(hr)) 27 | } 28 | } 29 | 30 | func StrToPwstr(str string) PWSTR { 31 | pwsz, _ := syscall.UTF16PtrFromString(str) 32 | return pwsz 33 | } 34 | 35 | func StrToPstr(str string) PSTR { 36 | bts := []byte(str) 37 | return (PSTR)(&bts[0]) 38 | } 39 | 40 | func StrToPointer(str string) unsafe.Pointer { 41 | pwsz, _ := syscall.UTF16PtrFromString(str) 42 | return unsafe.Pointer(pwsz) 43 | } 44 | 45 | func StrToPointerOrNil(str string) unsafe.Pointer { 46 | if str == "" { 47 | return nil 48 | } 49 | pwsz, _ := syscall.UTF16PtrFromString(str) 50 | return unsafe.Pointer(pwsz) 51 | } 52 | 53 | func StrToBstr(str string) BSTR { 54 | pwsz, _ := syscall.UTF16PtrFromString(str) 55 | return SysAllocString(pwsz) 56 | } 57 | 58 | func PwstrToStr(pwsz PWSTR) string { 59 | wsz := unsafe.Slice(pwsz, 1024*64) 60 | return WstrToStr(wsz) 61 | } 62 | 63 | func WstrToStr(wsz []uint16) string { 64 | str := syscall.UTF16ToString(wsz) 65 | return str 66 | } 67 | 68 | func BstrToStr(bs BSTR) string { 69 | len := SysStringLen(bs) 70 | if len == 0 { 71 | return "" 72 | } 73 | ws := unsafe.Slice(bs, len) 74 | s := syscall.UTF16ToString(ws) 75 | return s 76 | } 77 | 78 | func BstrToStrAndFree(bs BSTR) string { 79 | str := BstrToStr(bs) 80 | SysFreeString(bs) 81 | return str 82 | } 83 | 84 | func GuidToStr(guid *syscall.GUID) (string, error) { 85 | var wszGuid [40]uint16 86 | hr := StringFromGUID2(guid, &wszGuid[0], 40) 87 | var err error 88 | if FAILED(hr) { 89 | err = errors.New(HRESULT_ToString(hr)) 90 | } 91 | return WstrToStr(wszGuid[1:37]), err 92 | } 93 | 94 | func StrToGuid(str string) (syscall.GUID, error) { 95 | if str == "" { 96 | return syscall.GUID{}, errors.New("empty guid string") 97 | } 98 | if str[0] != '{' { 99 | str = "{" + str + "}" 100 | } 101 | var guid syscall.GUID 102 | hr := CLSIDFromString(StrToPwstr(str), &guid) 103 | var err error 104 | if FAILED(hr) { 105 | err = errors.New(HRESULT_ToString(hr)) 106 | } 107 | return guid, err 108 | } 109 | 110 | func (me WIN32_ERROR) Error() string { 111 | return syscall.Errno(me).Error() 112 | } 113 | 114 | func (me WIN32_ERROR) NilOrError() error { 115 | if me == NO_ERROR { 116 | return nil 117 | } 118 | return me 119 | } 120 | 121 | func BoolToBOOL(b bool) BOOL { 122 | if b { 123 | return TRUE 124 | } else { 125 | return FALSE 126 | } 127 | } 128 | 129 | func BoolFromBOOL(b BOOL) bool { 130 | return b != 0 131 | } 132 | 133 | func GetCh() CHAR { 134 | hStdIn, _ := GetStdHandle(STD_INPUT_HANDLE) 135 | if hStdIn == 0 { 136 | println("??") 137 | return 0 138 | } 139 | var cc DWORD 140 | var ir INPUT_RECORD 141 | for { 142 | ReadConsoleInput(hStdIn, &ir, 1, &cc) 143 | if ir.EventType == uint16(KEY_EVENT) && 144 | ir.Event.KeyEvent().BKeyDown == TRUE { 145 | b := ir.Event.KeyEvent().UChar.AsciiCharVal() 146 | return b 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /examples/console_io/console_io.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/zzl/go-win32api/v2/win32" 5 | "os" 6 | ) 7 | 8 | //https://learn.microsoft.com/en-us/windows/console/using-the-high-level-input-and-output-functions 9 | 10 | var hStdout, hStdin win32.HANDLE 11 | var csbiInfo win32.CONSOLE_SCREEN_BUFFER_INFO 12 | 13 | func main() { 14 | 15 | lpszPrompt1 := win32.StrToPstr("Type a line and press Enter, or q to quit: ") 16 | lpszPrompt2 := win32.StrToPstr("Type any key, or q to quit: ") 17 | var chBuffer [256]win32.CHAR 18 | var cRead, cWritten win32.DWORD 19 | var fdwMode, fdwOldMode win32.CONSOLE_MODE 20 | var wOldColorAttrs win32.CONSOLE_CHARACTER_ATTRIBUTES 21 | 22 | // Get handles to STDIN and STDOUT. 23 | 24 | hStdin, _ = win32.GetStdHandle(win32.STD_INPUT_HANDLE) 25 | hStdout, _ = win32.GetStdHandle(win32.STD_OUTPUT_HANDLE) 26 | 27 | if hStdin == win32.INVALID_HANDLE_VALUE || 28 | hStdout == win32.INVALID_HANDLE_VALUE { 29 | win32.MessageBox(win32.NULL, win32.StrToPwstr("GetStdHandle"), 30 | win32.StrToPwstr("Console Error"), win32.MB_OK) 31 | os.Exit(1) 32 | } 33 | 34 | // Save the current text colors. 35 | 36 | if ok, _ := win32.GetConsoleScreenBufferInfo(hStdout, &csbiInfo); ok == win32.FALSE { 37 | win32.MessageBox(win32.NULL, win32.StrToPwstr("GetConsoleScreenBufferInfo"), 38 | win32.StrToPwstr("Console Error"), win32.MB_OK) 39 | os.Exit(1) 40 | } 41 | 42 | wOldColorAttrs = csbiInfo.WAttributes 43 | 44 | // Set the text attributes to draw red text on black background. 45 | 46 | if ok, _ := win32.SetConsoleTextAttribute(hStdout, 47 | win32.FOREGROUND_RED|win32.FOREGROUND_INTENSITY); ok == win32.FALSE { 48 | win32.MessageBox(win32.NULL, win32.StrToPwstr("GetConsoleScreenBufferInfo"), 49 | win32.StrToPwstr("Console Error"), win32.MB_OK) 50 | os.Exit(1) 51 | } 52 | 53 | // Write to STDOUT and read from STDIN by using the default 54 | // modes. Input is echoed automatically, and ReadFile 55 | // does not return until a carriage return is typed. 56 | // 57 | // The default input modes are line, processed, and echo. 58 | // The default output modes are processed and wrap at EOL. 59 | 60 | for { 61 | if ok, _ := win32.WriteFile( 62 | hStdout, // output handle 63 | lpszPrompt1, // prompt string 64 | uint32(win32.LstrlenA(lpszPrompt1)), // string length 65 | &cWritten, // bytes written 66 | nil, // not overlapped 67 | ); ok == win32.FALSE { 68 | os.Exit(1) 69 | } 70 | 71 | if ok, _ := win32.ReadFile( 72 | hStdin, // input handle 73 | &chBuffer[0], // buffer to read into 74 | 255, // size of buffer 75 | &cRead, // actual bytes read 76 | nil, // not overlapped 77 | ); ok == win32.FALSE { 78 | break 79 | } 80 | 81 | if chBuffer[0] == 'q' { 82 | break 83 | } 84 | } 85 | 86 | // Turn off the line input and echo input modes 87 | if ok, _ := win32.GetConsoleMode(hStdin, &fdwOldMode); ok == win32.FALSE { 88 | win32.MessageBox(win32.NULL, win32.StrToPwstr("GetConsoleMode"), 89 | win32.StrToPwstr("Console Error"), win32.MB_OK) 90 | os.Exit(1) 91 | } 92 | 93 | fdwMode = fdwOldMode & ^(win32.ENABLE_LINE_INPUT | win32.ENABLE_ECHO_INPUT) 94 | if ok, _ := win32.SetConsoleMode(hStdin, fdwMode); ok == win32.FALSE { 95 | win32.MessageBox(win32.NULL, win32.StrToPwstr("SetConsoleMode"), 96 | win32.StrToPwstr("Console Error"), win32.MB_OK) 97 | os.Exit(1) 98 | } 99 | 100 | // ReadFile returns when any input is available. 101 | // WriteFile is used to echo input. 102 | 103 | NewLine() 104 | 105 | for { 106 | if ok, _ := win32.WriteFile( 107 | hStdout, // output handle 108 | lpszPrompt2, // prompt string 109 | uint32(win32.LstrlenA(lpszPrompt2)), // string length 110 | &cWritten, // bytes written 111 | nil, // not overlapped 112 | ); ok == win32.FALSE { 113 | win32.MessageBox(win32.NULL, win32.StrToPwstr("WriteFile"), 114 | win32.StrToPwstr("Console Error"), win32.MB_OK) 115 | os.Exit(1) 116 | } 117 | 118 | if ok, _ := win32.ReadFile(hStdin, 119 | &chBuffer[0], 1, &cRead, nil); ok == win32.FALSE { 120 | break 121 | } 122 | if chBuffer[0] == '\r' { 123 | NewLine() 124 | } else if ok, _ := win32.WriteFile(hStdout, 125 | &chBuffer[0], cRead, &cWritten, nil); ok == win32.FALSE { 126 | break 127 | } else { 128 | NewLine() 129 | } 130 | if chBuffer[0] == 'q' { 131 | break 132 | } 133 | } 134 | 135 | // Restore the original console mode. 136 | 137 | win32.SetConsoleMode(hStdin, fdwOldMode) 138 | 139 | // Restore the original text colors. 140 | 141 | win32.SetConsoleTextAttribute(hStdout, wOldColorAttrs) 142 | 143 | } 144 | 145 | // The NewLine function handles carriage returns when the processed 146 | // input mode is disabled. It gets the current cursor position 147 | // and resets it to the first cell of the next row. 148 | func NewLine() { 149 | if ok, _ := win32.GetConsoleScreenBufferInfo(hStdout, &csbiInfo); ok == win32.FALSE { 150 | win32.MessageBox(win32.NULL, win32.StrToPwstr("GetConsoleScreenBufferInfo"), 151 | win32.StrToPwstr("Console Error"), win32.MB_OK) 152 | return 153 | } 154 | csbiInfo.DwCursorPosition.X = 0 155 | 156 | // If it is the last line in the screen buffer, scroll 157 | // the buffer up. 158 | if csbiInfo.DwSize.Y-1 == csbiInfo.DwCursorPosition.Y { 159 | ScrollScreenBuffer(hStdout, 1) 160 | } else { // Otherwise, advance the cursor to the next line. 161 | csbiInfo.DwCursorPosition.Y += 1 162 | } 163 | 164 | if ok, _ := win32.SetConsoleCursorPosition(hStdout, 165 | csbiInfo.DwCursorPosition); ok == win32.FALSE { 166 | 167 | win32.MessageBox(win32.NULL, win32.StrToPwstr("SetConsoleCursorPosition"), 168 | win32.StrToPwstr("Console Error"), win32.MB_OK) 169 | return 170 | } 171 | } 172 | 173 | func ScrollScreenBuffer(h win32.HANDLE, x win32.INT) { 174 | var srctScrollRect, srctClipRect win32.SMALL_RECT 175 | var chiFill win32.CHAR_INFO 176 | var coordDest win32.COORD 177 | 178 | srctScrollRect.Left = 0 179 | srctScrollRect.Top = 1 180 | srctScrollRect.Right = csbiInfo.DwSize.X - win32.SHORT(x) 181 | srctScrollRect.Bottom = csbiInfo.DwSize.Y - win32.SHORT(x) 182 | 183 | // The destination for the scroll rectangle is one row up. 184 | 185 | coordDest.X = 0 186 | coordDest.Y = 0 187 | 188 | // The clipping rectangle is the same as the scrolling rectangle. 189 | // The destination row is left unchanged. 190 | 191 | srctClipRect = srctScrollRect 192 | 193 | // Set the fill character and attributes. 194 | 195 | chiFill.Attributes = uint16(win32.FOREGROUND_RED | win32.FOREGROUND_INTENSITY) 196 | *chiFill.Char.AsciiChar() = ' ' 197 | 198 | // Scroll up one line. 199 | 200 | win32.ScrollConsoleScreenBuffer( 201 | h, // screen buffer handle 202 | &srctScrollRect, // scrolling rectangle 203 | &srctClipRect, // clipping rectangle 204 | coordDest, // top left destination cell 205 | &chiFill) // fill character and color 206 | } 207 | -------------------------------------------------------------------------------- /win32/System.IO.go: -------------------------------------------------------------------------------- 1 | package win32 2 | 3 | import ( 4 | "syscall" 5 | "unsafe" 6 | ) 7 | 8 | // structs 9 | 10 | type OVERLAPPED_Anonymous_Anonymous struct { 11 | Offset uint32 12 | OffsetHigh uint32 13 | } 14 | 15 | type OVERLAPPED_Anonymous struct { 16 | OVERLAPPED_Anonymous_Anonymous 17 | } 18 | 19 | func (this *OVERLAPPED_Anonymous) Anonymous() *OVERLAPPED_Anonymous_Anonymous { 20 | return (*OVERLAPPED_Anonymous_Anonymous)(unsafe.Pointer(this)) 21 | } 22 | 23 | func (this *OVERLAPPED_Anonymous) AnonymousVal() OVERLAPPED_Anonymous_Anonymous { 24 | return *(*OVERLAPPED_Anonymous_Anonymous)(unsafe.Pointer(this)) 25 | } 26 | 27 | func (this *OVERLAPPED_Anonymous) Pointer() *unsafe.Pointer { 28 | return (*unsafe.Pointer)(unsafe.Pointer(this)) 29 | } 30 | 31 | func (this *OVERLAPPED_Anonymous) PointerVal() unsafe.Pointer { 32 | return *(*unsafe.Pointer)(unsafe.Pointer(this)) 33 | } 34 | 35 | type OVERLAPPED struct { 36 | Internal uintptr 37 | InternalHigh uintptr 38 | OVERLAPPED_Anonymous 39 | HEvent HANDLE 40 | } 41 | 42 | type OVERLAPPED_ENTRY struct { 43 | LpCompletionKey uintptr 44 | LpOverlapped *OVERLAPPED 45 | Internal uintptr 46 | DwNumberOfBytesTransferred uint32 47 | } 48 | 49 | type IO_STATUS_BLOCK_Anonymous struct { 50 | Data [1]uint64 51 | } 52 | 53 | func (this *IO_STATUS_BLOCK_Anonymous) Status() *NTSTATUS { 54 | return (*NTSTATUS)(unsafe.Pointer(this)) 55 | } 56 | 57 | func (this *IO_STATUS_BLOCK_Anonymous) StatusVal() NTSTATUS { 58 | return *(*NTSTATUS)(unsafe.Pointer(this)) 59 | } 60 | 61 | func (this *IO_STATUS_BLOCK_Anonymous) Pointer() *unsafe.Pointer { 62 | return (*unsafe.Pointer)(unsafe.Pointer(this)) 63 | } 64 | 65 | func (this *IO_STATUS_BLOCK_Anonymous) PointerVal() unsafe.Pointer { 66 | return *(*unsafe.Pointer)(unsafe.Pointer(this)) 67 | } 68 | 69 | type IO_STATUS_BLOCK struct { 70 | IO_STATUS_BLOCK_Anonymous 71 | Information uintptr 72 | } 73 | 74 | // func types 75 | 76 | type LPOVERLAPPED_COMPLETION_ROUTINE = uintptr 77 | type LPOVERLAPPED_COMPLETION_ROUTINE_func = func(dwErrorCode uint32, dwNumberOfBytesTransfered uint32, lpOverlapped *OVERLAPPED) 78 | 79 | type PIO_APC_ROUTINE = uintptr 80 | type PIO_APC_ROUTINE_func = func(ApcContext unsafe.Pointer, IoStatusBlock *IO_STATUS_BLOCK, Reserved uint32) 81 | 82 | var ( 83 | pCreateIoCompletionPort uintptr 84 | pGetQueuedCompletionStatus uintptr 85 | pGetQueuedCompletionStatusEx uintptr 86 | pPostQueuedCompletionStatus uintptr 87 | pDeviceIoControl uintptr 88 | pGetOverlappedResult uintptr 89 | pCancelIoEx uintptr 90 | pCancelIo uintptr 91 | pGetOverlappedResultEx uintptr 92 | pCancelSynchronousIo uintptr 93 | pBindIoCompletionCallback uintptr 94 | ) 95 | 96 | func CreateIoCompletionPort(FileHandle HANDLE, ExistingCompletionPort HANDLE, CompletionKey uintptr, NumberOfConcurrentThreads uint32) (HANDLE, WIN32_ERROR) { 97 | addr := LazyAddr(&pCreateIoCompletionPort, libKernel32, "CreateIoCompletionPort") 98 | ret, _, err := syscall.SyscallN(addr, FileHandle, ExistingCompletionPort, CompletionKey, uintptr(NumberOfConcurrentThreads)) 99 | return ret, WIN32_ERROR(err) 100 | } 101 | 102 | func GetQueuedCompletionStatus(CompletionPort HANDLE, lpNumberOfBytesTransferred *uint32, lpCompletionKey *uintptr, lpOverlapped **OVERLAPPED, dwMilliseconds uint32) (BOOL, WIN32_ERROR) { 103 | addr := LazyAddr(&pGetQueuedCompletionStatus, libKernel32, "GetQueuedCompletionStatus") 104 | ret, _, err := syscall.SyscallN(addr, CompletionPort, uintptr(unsafe.Pointer(lpNumberOfBytesTransferred)), uintptr(unsafe.Pointer(lpCompletionKey)), uintptr(unsafe.Pointer(lpOverlapped)), uintptr(dwMilliseconds)) 105 | return BOOL(ret), WIN32_ERROR(err) 106 | } 107 | 108 | func GetQueuedCompletionStatusEx(CompletionPort HANDLE, lpCompletionPortEntries *OVERLAPPED_ENTRY, ulCount uint32, ulNumEntriesRemoved *uint32, dwMilliseconds uint32, fAlertable BOOL) (BOOL, WIN32_ERROR) { 109 | addr := LazyAddr(&pGetQueuedCompletionStatusEx, libKernel32, "GetQueuedCompletionStatusEx") 110 | ret, _, err := syscall.SyscallN(addr, CompletionPort, uintptr(unsafe.Pointer(lpCompletionPortEntries)), uintptr(ulCount), uintptr(unsafe.Pointer(ulNumEntriesRemoved)), uintptr(dwMilliseconds), uintptr(fAlertable)) 111 | return BOOL(ret), WIN32_ERROR(err) 112 | } 113 | 114 | func PostQueuedCompletionStatus(CompletionPort HANDLE, dwNumberOfBytesTransferred uint32, dwCompletionKey uintptr, lpOverlapped *OVERLAPPED) (BOOL, WIN32_ERROR) { 115 | addr := LazyAddr(&pPostQueuedCompletionStatus, libKernel32, "PostQueuedCompletionStatus") 116 | ret, _, err := syscall.SyscallN(addr, CompletionPort, uintptr(dwNumberOfBytesTransferred), dwCompletionKey, uintptr(unsafe.Pointer(lpOverlapped))) 117 | return BOOL(ret), WIN32_ERROR(err) 118 | } 119 | 120 | func DeviceIoControl(hDevice HANDLE, dwIoControlCode uint32, lpInBuffer unsafe.Pointer, nInBufferSize uint32, lpOutBuffer unsafe.Pointer, nOutBufferSize uint32, lpBytesReturned *uint32, lpOverlapped *OVERLAPPED) (BOOL, WIN32_ERROR) { 121 | addr := LazyAddr(&pDeviceIoControl, libKernel32, "DeviceIoControl") 122 | ret, _, err := syscall.SyscallN(addr, hDevice, uintptr(dwIoControlCode), uintptr(lpInBuffer), uintptr(nInBufferSize), uintptr(lpOutBuffer), uintptr(nOutBufferSize), uintptr(unsafe.Pointer(lpBytesReturned)), uintptr(unsafe.Pointer(lpOverlapped))) 123 | return BOOL(ret), WIN32_ERROR(err) 124 | } 125 | 126 | func GetOverlappedResult(hFile HANDLE, lpOverlapped *OVERLAPPED, lpNumberOfBytesTransferred *uint32, bWait BOOL) (BOOL, WIN32_ERROR) { 127 | addr := LazyAddr(&pGetOverlappedResult, libKernel32, "GetOverlappedResult") 128 | ret, _, err := syscall.SyscallN(addr, hFile, uintptr(unsafe.Pointer(lpOverlapped)), uintptr(unsafe.Pointer(lpNumberOfBytesTransferred)), uintptr(bWait)) 129 | return BOOL(ret), WIN32_ERROR(err) 130 | } 131 | 132 | func CancelIoEx(hFile HANDLE, lpOverlapped *OVERLAPPED) (BOOL, WIN32_ERROR) { 133 | addr := LazyAddr(&pCancelIoEx, libKernel32, "CancelIoEx") 134 | ret, _, err := syscall.SyscallN(addr, hFile, uintptr(unsafe.Pointer(lpOverlapped))) 135 | return BOOL(ret), WIN32_ERROR(err) 136 | } 137 | 138 | func CancelIo(hFile HANDLE) (BOOL, WIN32_ERROR) { 139 | addr := LazyAddr(&pCancelIo, libKernel32, "CancelIo") 140 | ret, _, err := syscall.SyscallN(addr, hFile) 141 | return BOOL(ret), WIN32_ERROR(err) 142 | } 143 | 144 | func GetOverlappedResultEx(hFile HANDLE, lpOverlapped *OVERLAPPED, lpNumberOfBytesTransferred *uint32, dwMilliseconds uint32, bAlertable BOOL) (BOOL, WIN32_ERROR) { 145 | addr := LazyAddr(&pGetOverlappedResultEx, libKernel32, "GetOverlappedResultEx") 146 | ret, _, err := syscall.SyscallN(addr, hFile, uintptr(unsafe.Pointer(lpOverlapped)), uintptr(unsafe.Pointer(lpNumberOfBytesTransferred)), uintptr(dwMilliseconds), uintptr(bAlertable)) 147 | return BOOL(ret), WIN32_ERROR(err) 148 | } 149 | 150 | func CancelSynchronousIo(hThread HANDLE) (BOOL, WIN32_ERROR) { 151 | addr := LazyAddr(&pCancelSynchronousIo, libKernel32, "CancelSynchronousIo") 152 | ret, _, err := syscall.SyscallN(addr, hThread) 153 | return BOOL(ret), WIN32_ERROR(err) 154 | } 155 | 156 | func BindIoCompletionCallback(FileHandle HANDLE, Function LPOVERLAPPED_COMPLETION_ROUTINE, Flags uint32) (BOOL, WIN32_ERROR) { 157 | addr := LazyAddr(&pBindIoCompletionCallback, libKernel32, "BindIoCompletionCallback") 158 | ret, _, err := syscall.SyscallN(addr, FileHandle, Function, uintptr(Flags)) 159 | return BOOL(ret), WIN32_ERROR(err) 160 | } 161 | -------------------------------------------------------------------------------- /win32/UI.Shell.Common.go: -------------------------------------------------------------------------------- 1 | package win32 2 | 3 | import ( 4 | "syscall" 5 | "unsafe" 6 | ) 7 | 8 | const ( 9 | PERCEIVEDFLAG_UNDEFINED uint32 = 0x0 10 | PERCEIVEDFLAG_SOFTCODED uint32 = 0x1 11 | PERCEIVEDFLAG_HARDCODED uint32 = 0x2 12 | PERCEIVEDFLAG_NATIVESUPPORT uint32 = 0x4 13 | PERCEIVEDFLAG_GDIPLUS uint32 = 0x10 14 | PERCEIVEDFLAG_WMSDK uint32 = 0x20 15 | PERCEIVEDFLAG_ZIPFOLDER uint32 = 0x40 16 | ) 17 | 18 | // enums 19 | 20 | // enum 21 | type STRRET_TYPE int32 22 | 23 | const ( 24 | STRRET_WSTR STRRET_TYPE = 0 25 | STRRET_OFFSET STRRET_TYPE = 1 26 | STRRET_CSTR STRRET_TYPE = 2 27 | ) 28 | 29 | // enum 30 | type PERCEIVED int32 31 | 32 | const ( 33 | PERCEIVED_TYPE_FIRST PERCEIVED = -3 34 | PERCEIVED_TYPE_CUSTOM PERCEIVED = -3 35 | PERCEIVED_TYPE_UNSPECIFIED PERCEIVED = -2 36 | PERCEIVED_TYPE_FOLDER PERCEIVED = -1 37 | PERCEIVED_TYPE_UNKNOWN PERCEIVED = 0 38 | PERCEIVED_TYPE_TEXT PERCEIVED = 1 39 | PERCEIVED_TYPE_IMAGE PERCEIVED = 2 40 | PERCEIVED_TYPE_AUDIO PERCEIVED = 3 41 | PERCEIVED_TYPE_VIDEO PERCEIVED = 4 42 | PERCEIVED_TYPE_COMPRESSED PERCEIVED = 5 43 | PERCEIVED_TYPE_DOCUMENT PERCEIVED = 6 44 | PERCEIVED_TYPE_SYSTEM PERCEIVED = 7 45 | PERCEIVED_TYPE_APPLICATION PERCEIVED = 8 46 | PERCEIVED_TYPE_GAMEMEDIA PERCEIVED = 9 47 | PERCEIVED_TYPE_CONTACTS PERCEIVED = 10 48 | PERCEIVED_TYPE_LAST PERCEIVED = 10 49 | ) 50 | 51 | // enum 52 | type SHCOLSTATE int32 53 | 54 | const ( 55 | SHCOLSTATE_DEFAULT SHCOLSTATE = 0 56 | SHCOLSTATE_TYPE_STR SHCOLSTATE = 1 57 | SHCOLSTATE_TYPE_INT SHCOLSTATE = 2 58 | SHCOLSTATE_TYPE_DATE SHCOLSTATE = 3 59 | SHCOLSTATE_TYPEMASK SHCOLSTATE = 15 60 | SHCOLSTATE_ONBYDEFAULT SHCOLSTATE = 16 61 | SHCOLSTATE_SLOW SHCOLSTATE = 32 62 | SHCOLSTATE_EXTENDED SHCOLSTATE = 64 63 | SHCOLSTATE_SECONDARYUI SHCOLSTATE = 128 64 | SHCOLSTATE_HIDDEN SHCOLSTATE = 256 65 | SHCOLSTATE_PREFER_VARCMP SHCOLSTATE = 512 66 | SHCOLSTATE_PREFER_FMTCMP SHCOLSTATE = 1024 67 | SHCOLSTATE_NOSORTBYFOLDERNESS SHCOLSTATE = 2048 68 | SHCOLSTATE_VIEWONLY SHCOLSTATE = 65536 69 | SHCOLSTATE_BATCHREAD SHCOLSTATE = 131072 70 | SHCOLSTATE_NO_GROUPBY SHCOLSTATE = 262144 71 | SHCOLSTATE_FIXED_WIDTH SHCOLSTATE = 4096 72 | SHCOLSTATE_NODPISCALE SHCOLSTATE = 8192 73 | SHCOLSTATE_FIXED_RATIO SHCOLSTATE = 16384 74 | SHCOLSTATE_DISPLAYMASK SHCOLSTATE = 61440 75 | ) 76 | 77 | // enum 78 | type DEVICE_SCALE_FACTOR int32 79 | 80 | const ( 81 | DEVICE_SCALE_FACTOR_INVALID DEVICE_SCALE_FACTOR = 0 82 | SCALE_100_PERCENT DEVICE_SCALE_FACTOR = 100 83 | SCALE_120_PERCENT DEVICE_SCALE_FACTOR = 120 84 | SCALE_125_PERCENT DEVICE_SCALE_FACTOR = 125 85 | SCALE_140_PERCENT DEVICE_SCALE_FACTOR = 140 86 | SCALE_150_PERCENT DEVICE_SCALE_FACTOR = 150 87 | SCALE_160_PERCENT DEVICE_SCALE_FACTOR = 160 88 | SCALE_175_PERCENT DEVICE_SCALE_FACTOR = 175 89 | SCALE_180_PERCENT DEVICE_SCALE_FACTOR = 180 90 | SCALE_200_PERCENT DEVICE_SCALE_FACTOR = 200 91 | SCALE_225_PERCENT DEVICE_SCALE_FACTOR = 225 92 | SCALE_250_PERCENT DEVICE_SCALE_FACTOR = 250 93 | SCALE_300_PERCENT DEVICE_SCALE_FACTOR = 300 94 | SCALE_350_PERCENT DEVICE_SCALE_FACTOR = 350 95 | SCALE_400_PERCENT DEVICE_SCALE_FACTOR = 400 96 | SCALE_450_PERCENT DEVICE_SCALE_FACTOR = 450 97 | SCALE_500_PERCENT DEVICE_SCALE_FACTOR = 500 98 | ) 99 | 100 | // structs 101 | 102 | type SHITEMID struct { 103 | Cb uint16 104 | AbID [1]byte 105 | } 106 | 107 | type ITEMIDLIST struct { 108 | Mkid SHITEMID 109 | } 110 | 111 | type STRRET_Anonymous struct { 112 | Data [32]uint64 113 | } 114 | 115 | func (this *STRRET_Anonymous) POleStr() *PWSTR { 116 | return (*PWSTR)(unsafe.Pointer(this)) 117 | } 118 | 119 | func (this *STRRET_Anonymous) POleStrVal() PWSTR { 120 | return *(*PWSTR)(unsafe.Pointer(this)) 121 | } 122 | 123 | func (this *STRRET_Anonymous) UOffset() *uint32 { 124 | return (*uint32)(unsafe.Pointer(this)) 125 | } 126 | 127 | func (this *STRRET_Anonymous) UOffsetVal() uint32 { 128 | return *(*uint32)(unsafe.Pointer(this)) 129 | } 130 | 131 | func (this *STRRET_Anonymous) CStr() *[260]byte { 132 | return (*[260]byte)(unsafe.Pointer(this)) 133 | } 134 | 135 | func (this *STRRET_Anonymous) CStrVal() [260]byte { 136 | return *(*[260]byte)(unsafe.Pointer(this)) 137 | } 138 | 139 | type STRRET struct { 140 | UType uint32 141 | STRRET_Anonymous 142 | } 143 | 144 | type SHELLDETAILS struct { 145 | Fmt int32 146 | CxChar int32 147 | Str STRRET 148 | } 149 | 150 | type COMDLG_FILTERSPEC struct { 151 | PszName PWSTR 152 | PszSpec PWSTR 153 | } 154 | 155 | // interfaces 156 | 157 | // 92CA9DCD-5622-4BBA-A805-5E9F541BD8C9 158 | var IID_IObjectArray = syscall.GUID{0x92CA9DCD, 0x5622, 0x4BBA, 159 | [8]byte{0xA8, 0x05, 0x5E, 0x9F, 0x54, 0x1B, 0xD8, 0xC9}} 160 | 161 | type IObjectArrayInterface interface { 162 | IUnknownInterface 163 | GetCount(pcObjects *uint32) HRESULT 164 | GetAt(uiIndex uint32, riid *syscall.GUID, ppv unsafe.Pointer) HRESULT 165 | } 166 | 167 | type IObjectArrayVtbl struct { 168 | IUnknownVtbl 169 | GetCount uintptr 170 | GetAt uintptr 171 | } 172 | 173 | type IObjectArray struct { 174 | IUnknown 175 | } 176 | 177 | func (this *IObjectArray) Vtbl() *IObjectArrayVtbl { 178 | return (*IObjectArrayVtbl)(unsafe.Pointer(this.IUnknown.LpVtbl)) 179 | } 180 | 181 | func (this *IObjectArray) GetCount(pcObjects *uint32) HRESULT { 182 | ret, _, _ := syscall.SyscallN(this.Vtbl().GetCount, uintptr(unsafe.Pointer(this)), uintptr(unsafe.Pointer(pcObjects))) 183 | return HRESULT(ret) 184 | } 185 | 186 | func (this *IObjectArray) GetAt(uiIndex uint32, riid *syscall.GUID, ppv unsafe.Pointer) HRESULT { 187 | ret, _, _ := syscall.SyscallN(this.Vtbl().GetAt, uintptr(unsafe.Pointer(this)), uintptr(uiIndex), uintptr(unsafe.Pointer(riid)), uintptr(ppv)) 188 | return HRESULT(ret) 189 | } 190 | 191 | // 5632B1A4-E38A-400A-928A-D4CD63230295 192 | var IID_IObjectCollection = syscall.GUID{0x5632B1A4, 0xE38A, 0x400A, 193 | [8]byte{0x92, 0x8A, 0xD4, 0xCD, 0x63, 0x23, 0x02, 0x95}} 194 | 195 | type IObjectCollectionInterface interface { 196 | IObjectArrayInterface 197 | AddObject(punk *IUnknown) HRESULT 198 | AddFromArray(poaSource *IObjectArray) HRESULT 199 | RemoveObjectAt(uiIndex uint32) HRESULT 200 | Clear() HRESULT 201 | } 202 | 203 | type IObjectCollectionVtbl struct { 204 | IObjectArrayVtbl 205 | AddObject uintptr 206 | AddFromArray uintptr 207 | RemoveObjectAt uintptr 208 | Clear uintptr 209 | } 210 | 211 | type IObjectCollection struct { 212 | IObjectArray 213 | } 214 | 215 | func (this *IObjectCollection) Vtbl() *IObjectCollectionVtbl { 216 | return (*IObjectCollectionVtbl)(unsafe.Pointer(this.IUnknown.LpVtbl)) 217 | } 218 | 219 | func (this *IObjectCollection) AddObject(punk *IUnknown) HRESULT { 220 | ret, _, _ := syscall.SyscallN(this.Vtbl().AddObject, uintptr(unsafe.Pointer(this)), uintptr(unsafe.Pointer(punk))) 221 | return HRESULT(ret) 222 | } 223 | 224 | func (this *IObjectCollection) AddFromArray(poaSource *IObjectArray) HRESULT { 225 | ret, _, _ := syscall.SyscallN(this.Vtbl().AddFromArray, uintptr(unsafe.Pointer(this)), uintptr(unsafe.Pointer(poaSource))) 226 | return HRESULT(ret) 227 | } 228 | 229 | func (this *IObjectCollection) RemoveObjectAt(uiIndex uint32) HRESULT { 230 | ret, _, _ := syscall.SyscallN(this.Vtbl().RemoveObjectAt, uintptr(unsafe.Pointer(this)), uintptr(uiIndex)) 231 | return HRESULT(ret) 232 | } 233 | 234 | func (this *IObjectCollection) Clear() HRESULT { 235 | ret, _, _ := syscall.SyscallN(this.Vtbl().Clear, uintptr(unsafe.Pointer(this))) 236 | return HRESULT(ret) 237 | } 238 | -------------------------------------------------------------------------------- /win32/System.Time.go: -------------------------------------------------------------------------------- 1 | package win32 2 | 3 | import ( 4 | "syscall" 5 | "unsafe" 6 | ) 7 | 8 | const ( 9 | WszW32TimeRegKeyTimeProviders string = "System\\CurrentControlSet\\Services\\W32Time\\TimeProviders" 10 | WszW32TimeRegKeyPolicyTimeProviders string = "Software\\Policies\\Microsoft\\W32Time\\TimeProviders" 11 | WszW32TimeRegValueEnabled string = "Enabled" 12 | WszW32TimeRegValueDllName string = "DllName" 13 | WszW32TimeRegValueInputProvider string = "InputProvider" 14 | WszW32TimeRegValueMetaDataProvider string = "MetaDataProvider" 15 | TSF_Hardware uint32 = 0x1 16 | TSF_Authenticated uint32 = 0x2 17 | TSF_IPv6 uint32 = 0x4 18 | TSF_SignatureAuthenticated uint32 = 0x8 19 | TIME_ZONE_ID_INVALID uint32 = 0xffffffff 20 | ) 21 | 22 | // structs 23 | 24 | type TIME_ZONE_INFORMATION struct { 25 | Bias int32 26 | StandardName [32]uint16 27 | StandardDate SYSTEMTIME 28 | StandardBias int32 29 | DaylightName [32]uint16 30 | DaylightDate SYSTEMTIME 31 | DaylightBias int32 32 | } 33 | 34 | type DYNAMIC_TIME_ZONE_INFORMATION struct { 35 | Bias int32 36 | StandardName [32]uint16 37 | StandardDate SYSTEMTIME 38 | StandardBias int32 39 | DaylightName [32]uint16 40 | DaylightDate SYSTEMTIME 41 | DaylightBias int32 42 | TimeZoneKeyName [128]uint16 43 | DynamicDaylightTimeDisabled BOOLEAN 44 | } 45 | 46 | var ( 47 | pSystemTimeToTzSpecificLocalTime uintptr 48 | pTzSpecificLocalTimeToSystemTime uintptr 49 | pFileTimeToSystemTime uintptr 50 | pSystemTimeToFileTime uintptr 51 | pGetTimeZoneInformation uintptr 52 | pSetTimeZoneInformation uintptr 53 | pSetDynamicTimeZoneInformation uintptr 54 | pGetDynamicTimeZoneInformation uintptr 55 | pGetTimeZoneInformationForYear uintptr 56 | pEnumDynamicTimeZoneInformation uintptr 57 | pGetDynamicTimeZoneInformationEffectiveYears uintptr 58 | pSystemTimeToTzSpecificLocalTimeEx uintptr 59 | pTzSpecificLocalTimeToSystemTimeEx uintptr 60 | pLocalFileTimeToLocalSystemTime uintptr 61 | pLocalSystemTimeToLocalFileTime uintptr 62 | ) 63 | 64 | func SystemTimeToTzSpecificLocalTime(lpTimeZoneInformation *TIME_ZONE_INFORMATION, lpUniversalTime *SYSTEMTIME, lpLocalTime *SYSTEMTIME) (BOOL, WIN32_ERROR) { 65 | addr := LazyAddr(&pSystemTimeToTzSpecificLocalTime, libKernel32, "SystemTimeToTzSpecificLocalTime") 66 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpTimeZoneInformation)), uintptr(unsafe.Pointer(lpUniversalTime)), uintptr(unsafe.Pointer(lpLocalTime))) 67 | return BOOL(ret), WIN32_ERROR(err) 68 | } 69 | 70 | func TzSpecificLocalTimeToSystemTime(lpTimeZoneInformation *TIME_ZONE_INFORMATION, lpLocalTime *SYSTEMTIME, lpUniversalTime *SYSTEMTIME) (BOOL, WIN32_ERROR) { 71 | addr := LazyAddr(&pTzSpecificLocalTimeToSystemTime, libKernel32, "TzSpecificLocalTimeToSystemTime") 72 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpTimeZoneInformation)), uintptr(unsafe.Pointer(lpLocalTime)), uintptr(unsafe.Pointer(lpUniversalTime))) 73 | return BOOL(ret), WIN32_ERROR(err) 74 | } 75 | 76 | func FileTimeToSystemTime(lpFileTime *FILETIME, lpSystemTime *SYSTEMTIME) (BOOL, WIN32_ERROR) { 77 | addr := LazyAddr(&pFileTimeToSystemTime, libKernel32, "FileTimeToSystemTime") 78 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpFileTime)), uintptr(unsafe.Pointer(lpSystemTime))) 79 | return BOOL(ret), WIN32_ERROR(err) 80 | } 81 | 82 | func SystemTimeToFileTime(lpSystemTime *SYSTEMTIME, lpFileTime *FILETIME) (BOOL, WIN32_ERROR) { 83 | addr := LazyAddr(&pSystemTimeToFileTime, libKernel32, "SystemTimeToFileTime") 84 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpSystemTime)), uintptr(unsafe.Pointer(lpFileTime))) 85 | return BOOL(ret), WIN32_ERROR(err) 86 | } 87 | 88 | func GetTimeZoneInformation(lpTimeZoneInformation *TIME_ZONE_INFORMATION) (uint32, WIN32_ERROR) { 89 | addr := LazyAddr(&pGetTimeZoneInformation, libKernel32, "GetTimeZoneInformation") 90 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpTimeZoneInformation))) 91 | return uint32(ret), WIN32_ERROR(err) 92 | } 93 | 94 | func SetTimeZoneInformation(lpTimeZoneInformation *TIME_ZONE_INFORMATION) (BOOL, WIN32_ERROR) { 95 | addr := LazyAddr(&pSetTimeZoneInformation, libKernel32, "SetTimeZoneInformation") 96 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpTimeZoneInformation))) 97 | return BOOL(ret), WIN32_ERROR(err) 98 | } 99 | 100 | func SetDynamicTimeZoneInformation(lpTimeZoneInformation *DYNAMIC_TIME_ZONE_INFORMATION) (BOOL, WIN32_ERROR) { 101 | addr := LazyAddr(&pSetDynamicTimeZoneInformation, libKernel32, "SetDynamicTimeZoneInformation") 102 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpTimeZoneInformation))) 103 | return BOOL(ret), WIN32_ERROR(err) 104 | } 105 | 106 | func GetDynamicTimeZoneInformation(pTimeZoneInformation *DYNAMIC_TIME_ZONE_INFORMATION) (uint32, WIN32_ERROR) { 107 | addr := LazyAddr(&pGetDynamicTimeZoneInformation, libKernel32, "GetDynamicTimeZoneInformation") 108 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(pTimeZoneInformation))) 109 | return uint32(ret), WIN32_ERROR(err) 110 | } 111 | 112 | func GetTimeZoneInformationForYear(wYear uint16, pdtzi *DYNAMIC_TIME_ZONE_INFORMATION, ptzi *TIME_ZONE_INFORMATION) (BOOL, WIN32_ERROR) { 113 | addr := LazyAddr(&pGetTimeZoneInformationForYear, libKernel32, "GetTimeZoneInformationForYear") 114 | ret, _, err := syscall.SyscallN(addr, uintptr(wYear), uintptr(unsafe.Pointer(pdtzi)), uintptr(unsafe.Pointer(ptzi))) 115 | return BOOL(ret), WIN32_ERROR(err) 116 | } 117 | 118 | func EnumDynamicTimeZoneInformation(dwIndex uint32, lpTimeZoneInformation *DYNAMIC_TIME_ZONE_INFORMATION) uint32 { 119 | addr := LazyAddr(&pEnumDynamicTimeZoneInformation, libAdvapi32, "EnumDynamicTimeZoneInformation") 120 | ret, _, _ := syscall.SyscallN(addr, uintptr(dwIndex), uintptr(unsafe.Pointer(lpTimeZoneInformation))) 121 | return uint32(ret) 122 | } 123 | 124 | func GetDynamicTimeZoneInformationEffectiveYears(lpTimeZoneInformation *DYNAMIC_TIME_ZONE_INFORMATION, FirstYear *uint32, LastYear *uint32) uint32 { 125 | addr := LazyAddr(&pGetDynamicTimeZoneInformationEffectiveYears, libAdvapi32, "GetDynamicTimeZoneInformationEffectiveYears") 126 | ret, _, _ := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpTimeZoneInformation)), uintptr(unsafe.Pointer(FirstYear)), uintptr(unsafe.Pointer(LastYear))) 127 | return uint32(ret) 128 | } 129 | 130 | func SystemTimeToTzSpecificLocalTimeEx(lpTimeZoneInformation *DYNAMIC_TIME_ZONE_INFORMATION, lpUniversalTime *SYSTEMTIME, lpLocalTime *SYSTEMTIME) (BOOL, WIN32_ERROR) { 131 | addr := LazyAddr(&pSystemTimeToTzSpecificLocalTimeEx, libKernel32, "SystemTimeToTzSpecificLocalTimeEx") 132 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpTimeZoneInformation)), uintptr(unsafe.Pointer(lpUniversalTime)), uintptr(unsafe.Pointer(lpLocalTime))) 133 | return BOOL(ret), WIN32_ERROR(err) 134 | } 135 | 136 | func TzSpecificLocalTimeToSystemTimeEx(lpTimeZoneInformation *DYNAMIC_TIME_ZONE_INFORMATION, lpLocalTime *SYSTEMTIME, lpUniversalTime *SYSTEMTIME) (BOOL, WIN32_ERROR) { 137 | addr := LazyAddr(&pTzSpecificLocalTimeToSystemTimeEx, libKernel32, "TzSpecificLocalTimeToSystemTimeEx") 138 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpTimeZoneInformation)), uintptr(unsafe.Pointer(lpLocalTime)), uintptr(unsafe.Pointer(lpUniversalTime))) 139 | return BOOL(ret), WIN32_ERROR(err) 140 | } 141 | 142 | func LocalFileTimeToLocalSystemTime(timeZoneInformation *TIME_ZONE_INFORMATION, localFileTime *FILETIME, localSystemTime *SYSTEMTIME) BOOL { 143 | addr := LazyAddr(&pLocalFileTimeToLocalSystemTime, libKernel32, "LocalFileTimeToLocalSystemTime") 144 | ret, _, _ := syscall.SyscallN(addr, uintptr(unsafe.Pointer(timeZoneInformation)), uintptr(unsafe.Pointer(localFileTime)), uintptr(unsafe.Pointer(localSystemTime))) 145 | return BOOL(ret) 146 | } 147 | 148 | func LocalSystemTimeToLocalFileTime(timeZoneInformation *TIME_ZONE_INFORMATION, localSystemTime *SYSTEMTIME, localFileTime *FILETIME) BOOL { 149 | addr := LazyAddr(&pLocalSystemTimeToLocalFileTime, libKernel32, "LocalSystemTimeToLocalFileTime") 150 | ret, _, _ := syscall.SyscallN(addr, uintptr(unsafe.Pointer(timeZoneInformation)), uintptr(unsafe.Pointer(localSystemTime)), uintptr(unsafe.Pointer(localFileTime))) 151 | return BOOL(ret) 152 | } 153 | -------------------------------------------------------------------------------- /win32/System.Diagnostics.ToolHelp.go: -------------------------------------------------------------------------------- 1 | package win32 2 | 3 | import ( 4 | "syscall" 5 | "unsafe" 6 | ) 7 | 8 | const ( 9 | MAX_MODULE_NAME32 uint32 = 0xff 10 | HF32_DEFAULT uint32 = 0x1 11 | HF32_SHARED uint32 = 0x2 12 | ) 13 | 14 | // enums 15 | 16 | // enum 17 | // flags 18 | type CREATE_TOOLHELP_SNAPSHOT_FLAGS uint32 19 | 20 | const ( 21 | TH32CS_INHERIT CREATE_TOOLHELP_SNAPSHOT_FLAGS = 2147483648 22 | TH32CS_SNAPALL CREATE_TOOLHELP_SNAPSHOT_FLAGS = 15 23 | TH32CS_SNAPHEAPLIST CREATE_TOOLHELP_SNAPSHOT_FLAGS = 1 24 | TH32CS_SNAPMODULE CREATE_TOOLHELP_SNAPSHOT_FLAGS = 8 25 | TH32CS_SNAPMODULE32 CREATE_TOOLHELP_SNAPSHOT_FLAGS = 16 26 | TH32CS_SNAPPROCESS CREATE_TOOLHELP_SNAPSHOT_FLAGS = 2 27 | TH32CS_SNAPTHREAD CREATE_TOOLHELP_SNAPSHOT_FLAGS = 4 28 | ) 29 | 30 | // enum 31 | type HEAPENTRY32_FLAGS uint32 32 | 33 | const ( 34 | LF32_FIXED HEAPENTRY32_FLAGS = 1 35 | LF32_FREE HEAPENTRY32_FLAGS = 2 36 | LF32_MOVEABLE HEAPENTRY32_FLAGS = 4 37 | ) 38 | 39 | // structs 40 | 41 | type HEAPLIST32 struct { 42 | DwSize uintptr 43 | Th32ProcessID uint32 44 | Th32HeapID uintptr 45 | DwFlags uint32 46 | } 47 | 48 | type HEAPENTRY32 struct { 49 | DwSize uintptr 50 | HHandle HANDLE 51 | DwAddress uintptr 52 | DwBlockSize uintptr 53 | DwFlags HEAPENTRY32_FLAGS 54 | DwLockCount uint32 55 | DwResvd uint32 56 | Th32ProcessID uint32 57 | Th32HeapID uintptr 58 | } 59 | 60 | type PROCESSENTRY32W struct { 61 | DwSize uint32 62 | CntUsage uint32 63 | Th32ProcessID uint32 64 | Th32DefaultHeapID uintptr 65 | Th32ModuleID uint32 66 | CntThreads uint32 67 | Th32ParentProcessID uint32 68 | PcPriClassBase int32 69 | DwFlags uint32 70 | SzExeFile [260]uint16 71 | } 72 | 73 | type PROCESSENTRY32 struct { 74 | DwSize uint32 75 | CntUsage uint32 76 | Th32ProcessID uint32 77 | Th32DefaultHeapID uintptr 78 | Th32ModuleID uint32 79 | CntThreads uint32 80 | Th32ParentProcessID uint32 81 | PcPriClassBase int32 82 | DwFlags uint32 83 | SzExeFile [260]CHAR 84 | } 85 | 86 | type THREADENTRY32 struct { 87 | DwSize uint32 88 | CntUsage uint32 89 | Th32ThreadID uint32 90 | Th32OwnerProcessID uint32 91 | TpBasePri int32 92 | TpDeltaPri int32 93 | DwFlags uint32 94 | } 95 | 96 | type MODULEENTRY32W struct { 97 | DwSize uint32 98 | Th32ModuleID uint32 99 | Th32ProcessID uint32 100 | GlblcntUsage uint32 101 | ProccntUsage uint32 102 | ModBaseAddr *byte 103 | ModBaseSize uint32 104 | HModule HMODULE 105 | SzModule [256]uint16 106 | SzExePath [260]uint16 107 | } 108 | 109 | type MODULEENTRY32 struct { 110 | DwSize uint32 111 | Th32ModuleID uint32 112 | Th32ProcessID uint32 113 | GlblcntUsage uint32 114 | ProccntUsage uint32 115 | ModBaseAddr *byte 116 | ModBaseSize uint32 117 | HModule HMODULE 118 | SzModule [256]CHAR 119 | SzExePath [260]CHAR 120 | } 121 | 122 | var ( 123 | pCreateToolhelp32Snapshot uintptr 124 | pHeap32ListFirst uintptr 125 | pHeap32ListNext uintptr 126 | pHeap32First uintptr 127 | pHeap32Next uintptr 128 | pToolhelp32ReadProcessMemory uintptr 129 | pProcess32FirstW uintptr 130 | pProcess32NextW uintptr 131 | pProcess32First uintptr 132 | pProcess32Next uintptr 133 | pThread32First uintptr 134 | pThread32Next uintptr 135 | pModule32FirstW uintptr 136 | pModule32NextW uintptr 137 | pModule32First uintptr 138 | pModule32Next uintptr 139 | ) 140 | 141 | func CreateToolhelp32Snapshot(dwFlags CREATE_TOOLHELP_SNAPSHOT_FLAGS, th32ProcessID uint32) (HANDLE, WIN32_ERROR) { 142 | addr := LazyAddr(&pCreateToolhelp32Snapshot, libKernel32, "CreateToolhelp32Snapshot") 143 | ret, _, err := syscall.SyscallN(addr, uintptr(dwFlags), uintptr(th32ProcessID)) 144 | return ret, WIN32_ERROR(err) 145 | } 146 | 147 | func Heap32ListFirst(hSnapshot HANDLE, lphl *HEAPLIST32) (BOOL, WIN32_ERROR) { 148 | addr := LazyAddr(&pHeap32ListFirst, libKernel32, "Heap32ListFirst") 149 | ret, _, err := syscall.SyscallN(addr, hSnapshot, uintptr(unsafe.Pointer(lphl))) 150 | return BOOL(ret), WIN32_ERROR(err) 151 | } 152 | 153 | func Heap32ListNext(hSnapshot HANDLE, lphl *HEAPLIST32) (BOOL, WIN32_ERROR) { 154 | addr := LazyAddr(&pHeap32ListNext, libKernel32, "Heap32ListNext") 155 | ret, _, err := syscall.SyscallN(addr, hSnapshot, uintptr(unsafe.Pointer(lphl))) 156 | return BOOL(ret), WIN32_ERROR(err) 157 | } 158 | 159 | func Heap32First(lphe *HEAPENTRY32, th32ProcessID uint32, th32HeapID uintptr) (BOOL, WIN32_ERROR) { 160 | addr := LazyAddr(&pHeap32First, libKernel32, "Heap32First") 161 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lphe)), uintptr(th32ProcessID), th32HeapID) 162 | return BOOL(ret), WIN32_ERROR(err) 163 | } 164 | 165 | func Heap32Next(lphe *HEAPENTRY32) (BOOL, WIN32_ERROR) { 166 | addr := LazyAddr(&pHeap32Next, libKernel32, "Heap32Next") 167 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lphe))) 168 | return BOOL(ret), WIN32_ERROR(err) 169 | } 170 | 171 | func Toolhelp32ReadProcessMemory(th32ProcessID uint32, lpBaseAddress unsafe.Pointer, lpBuffer unsafe.Pointer, cbRead uintptr, lpNumberOfBytesRead *uintptr) BOOL { 172 | addr := LazyAddr(&pToolhelp32ReadProcessMemory, libKernel32, "Toolhelp32ReadProcessMemory") 173 | ret, _, _ := syscall.SyscallN(addr, uintptr(th32ProcessID), uintptr(lpBaseAddress), uintptr(lpBuffer), cbRead, uintptr(unsafe.Pointer(lpNumberOfBytesRead))) 174 | return BOOL(ret) 175 | } 176 | 177 | func Process32FirstW(hSnapshot HANDLE, lppe *PROCESSENTRY32W) (BOOL, WIN32_ERROR) { 178 | addr := LazyAddr(&pProcess32FirstW, libKernel32, "Process32FirstW") 179 | ret, _, err := syscall.SyscallN(addr, hSnapshot, uintptr(unsafe.Pointer(lppe))) 180 | return BOOL(ret), WIN32_ERROR(err) 181 | } 182 | 183 | func Process32NextW(hSnapshot HANDLE, lppe *PROCESSENTRY32W) (BOOL, WIN32_ERROR) { 184 | addr := LazyAddr(&pProcess32NextW, libKernel32, "Process32NextW") 185 | ret, _, err := syscall.SyscallN(addr, hSnapshot, uintptr(unsafe.Pointer(lppe))) 186 | return BOOL(ret), WIN32_ERROR(err) 187 | } 188 | 189 | func Process32First(hSnapshot HANDLE, lppe *PROCESSENTRY32) (BOOL, WIN32_ERROR) { 190 | addr := LazyAddr(&pProcess32First, libKernel32, "Process32First") 191 | ret, _, err := syscall.SyscallN(addr, hSnapshot, uintptr(unsafe.Pointer(lppe))) 192 | return BOOL(ret), WIN32_ERROR(err) 193 | } 194 | 195 | func Process32Next(hSnapshot HANDLE, lppe *PROCESSENTRY32) (BOOL, WIN32_ERROR) { 196 | addr := LazyAddr(&pProcess32Next, libKernel32, "Process32Next") 197 | ret, _, err := syscall.SyscallN(addr, hSnapshot, uintptr(unsafe.Pointer(lppe))) 198 | return BOOL(ret), WIN32_ERROR(err) 199 | } 200 | 201 | func Thread32First(hSnapshot HANDLE, lpte *THREADENTRY32) (BOOL, WIN32_ERROR) { 202 | addr := LazyAddr(&pThread32First, libKernel32, "Thread32First") 203 | ret, _, err := syscall.SyscallN(addr, hSnapshot, uintptr(unsafe.Pointer(lpte))) 204 | return BOOL(ret), WIN32_ERROR(err) 205 | } 206 | 207 | func Thread32Next(hSnapshot HANDLE, lpte *THREADENTRY32) (BOOL, WIN32_ERROR) { 208 | addr := LazyAddr(&pThread32Next, libKernel32, "Thread32Next") 209 | ret, _, err := syscall.SyscallN(addr, hSnapshot, uintptr(unsafe.Pointer(lpte))) 210 | return BOOL(ret), WIN32_ERROR(err) 211 | } 212 | 213 | func Module32FirstW(hSnapshot HANDLE, lpme *MODULEENTRY32W) (BOOL, WIN32_ERROR) { 214 | addr := LazyAddr(&pModule32FirstW, libKernel32, "Module32FirstW") 215 | ret, _, err := syscall.SyscallN(addr, hSnapshot, uintptr(unsafe.Pointer(lpme))) 216 | return BOOL(ret), WIN32_ERROR(err) 217 | } 218 | 219 | func Module32NextW(hSnapshot HANDLE, lpme *MODULEENTRY32W) (BOOL, WIN32_ERROR) { 220 | addr := LazyAddr(&pModule32NextW, libKernel32, "Module32NextW") 221 | ret, _, err := syscall.SyscallN(addr, hSnapshot, uintptr(unsafe.Pointer(lpme))) 222 | return BOOL(ret), WIN32_ERROR(err) 223 | } 224 | 225 | func Module32First(hSnapshot HANDLE, lpme *MODULEENTRY32) (BOOL, WIN32_ERROR) { 226 | addr := LazyAddr(&pModule32First, libKernel32, "Module32First") 227 | ret, _, err := syscall.SyscallN(addr, hSnapshot, uintptr(unsafe.Pointer(lpme))) 228 | return BOOL(ret), WIN32_ERROR(err) 229 | } 230 | 231 | func Module32Next(hSnapshot HANDLE, lpme *MODULEENTRY32) (BOOL, WIN32_ERROR) { 232 | addr := LazyAddr(&pModule32Next, libKernel32, "Module32Next") 233 | ret, _, err := syscall.SyscallN(addr, hSnapshot, uintptr(unsafe.Pointer(lpme))) 234 | return BOOL(ret), WIN32_ERROR(err) 235 | } 236 | -------------------------------------------------------------------------------- /win32/System.Kernel.go: -------------------------------------------------------------------------------- 1 | package win32 2 | 3 | import ( 4 | "syscall" 5 | "unsafe" 6 | ) 7 | 8 | const ( 9 | OBJ_HANDLE_TAGBITS int32 = 3 10 | RTL_BALANCED_NODE_RESERVED_PARENT_MASK uint32 = 0x3 11 | OBJ_INHERIT int32 = 2 12 | OBJ_PERMANENT int32 = 16 13 | OBJ_EXCLUSIVE int32 = 32 14 | OBJ_CASE_INSENSITIVE int32 = 64 15 | OBJ_OPENIF int32 = 128 16 | OBJ_OPENLINK int32 = 256 17 | OBJ_KERNEL_HANDLE int32 = 512 18 | OBJ_FORCE_ACCESS_CHECK int32 = 1024 19 | OBJ_IGNORE_IMPERSONATED_DEVICEMAP int32 = 2048 20 | OBJ_DONT_REPARSE int32 = 4096 21 | OBJ_VALID_ATTRIBUTES int32 = 8178 22 | NULL64 uint32 = 0x0 23 | MAXUCHAR uint32 = 0xff 24 | MAXUSHORT uint32 = 0xffff 25 | MAXULONG uint32 = 0xffffffff 26 | ) 27 | 28 | // enums 29 | 30 | // enum 31 | type EXCEPTION_DISPOSITION int32 32 | 33 | const ( 34 | ExceptionContinueExecution EXCEPTION_DISPOSITION = 0 35 | ExceptionContinueSearch EXCEPTION_DISPOSITION = 1 36 | ExceptionNestedException EXCEPTION_DISPOSITION = 2 37 | ExceptionCollidedUnwind EXCEPTION_DISPOSITION = 3 38 | ) 39 | 40 | // enum 41 | type EVENT_TYPE int32 42 | 43 | const ( 44 | NotificationEvent EVENT_TYPE = 0 45 | SynchronizationEvent EVENT_TYPE = 1 46 | ) 47 | 48 | // enum 49 | type TIMER_TYPE int32 50 | 51 | const ( 52 | NotificationTimer TIMER_TYPE = 0 53 | SynchronizationTimer TIMER_TYPE = 1 54 | ) 55 | 56 | // enum 57 | type WAIT_TYPE int32 58 | 59 | const ( 60 | WaitAll WAIT_TYPE = 0 61 | WaitAny WAIT_TYPE = 1 62 | WaitNotification WAIT_TYPE = 2 63 | WaitDequeue WAIT_TYPE = 3 64 | WaitDpc WAIT_TYPE = 4 65 | ) 66 | 67 | // enum 68 | type NT_PRODUCT_TYPE int32 69 | 70 | const ( 71 | NtProductWinNt NT_PRODUCT_TYPE = 1 72 | NtProductLanManNt NT_PRODUCT_TYPE = 2 73 | NtProductServer NT_PRODUCT_TYPE = 3 74 | ) 75 | 76 | // enum 77 | type SUITE_TYPE int32 78 | 79 | const ( 80 | SmallBusiness SUITE_TYPE = 0 81 | Enterprise SUITE_TYPE = 1 82 | BackOffice SUITE_TYPE = 2 83 | CommunicationServer SUITE_TYPE = 3 84 | TerminalServer SUITE_TYPE = 4 85 | SmallBusinessRestricted SUITE_TYPE = 5 86 | EmbeddedNT SUITE_TYPE = 6 87 | DataCenter SUITE_TYPE = 7 88 | SingleUserTS SUITE_TYPE = 8 89 | Personal SUITE_TYPE = 9 90 | Blade SUITE_TYPE = 10 91 | EmbeddedRestricted SUITE_TYPE = 11 92 | SecurityAppliance SUITE_TYPE = 12 93 | StorageServer SUITE_TYPE = 13 94 | ComputeServer SUITE_TYPE = 14 95 | WHServer SUITE_TYPE = 15 96 | PhoneNT SUITE_TYPE = 16 97 | MultiUserTS SUITE_TYPE = 17 98 | MaxSuiteType SUITE_TYPE = 18 99 | ) 100 | 101 | // enum 102 | type COMPARTMENT_ID int32 103 | 104 | const ( 105 | UNSPECIFIED_COMPARTMENT_ID COMPARTMENT_ID = 0 106 | DEFAULT_COMPARTMENT_ID COMPARTMENT_ID = 1 107 | ) 108 | 109 | // structs 110 | 111 | type SLIST_ENTRY struct { 112 | Next *SLIST_ENTRY 113 | } 114 | 115 | type QUAD_Anonymous struct { 116 | Data [1]uint64 117 | } 118 | 119 | func (this *QUAD_Anonymous) UseThisFieldToCopy() *int64 { 120 | return (*int64)(unsafe.Pointer(this)) 121 | } 122 | 123 | func (this *QUAD_Anonymous) UseThisFieldToCopyVal() int64 { 124 | return *(*int64)(unsafe.Pointer(this)) 125 | } 126 | 127 | func (this *QUAD_Anonymous) DoNotUseThisField() *float64 { 128 | return (*float64)(unsafe.Pointer(this)) 129 | } 130 | 131 | func (this *QUAD_Anonymous) DoNotUseThisFieldVal() float64 { 132 | return *(*float64)(unsafe.Pointer(this)) 133 | } 134 | 135 | type QUAD struct { 136 | QUAD_Anonymous 137 | } 138 | 139 | type PROCESSOR_NUMBER struct { 140 | Group uint16 141 | Number byte 142 | Reserved byte 143 | } 144 | 145 | type STRING struct { 146 | Length uint16 147 | MaximumLength uint16 148 | Buffer PSTR 149 | } 150 | 151 | type CSTRING struct { 152 | Length uint16 153 | MaximumLength uint16 154 | Buffer PSTR 155 | } 156 | 157 | type LIST_ENTRY struct { 158 | Flink *LIST_ENTRY 159 | Blink *LIST_ENTRY 160 | } 161 | 162 | type SINGLE_LIST_ENTRY struct { 163 | Next *SINGLE_LIST_ENTRY 164 | } 165 | 166 | type RTL_BALANCED_NODE_Anonymous1_Anonymous struct { 167 | Left *RTL_BALANCED_NODE 168 | Right *RTL_BALANCED_NODE 169 | } 170 | 171 | type RTL_BALANCED_NODE_Anonymous1 struct { 172 | RTL_BALANCED_NODE_Anonymous1_Anonymous 173 | } 174 | 175 | func (this *RTL_BALANCED_NODE_Anonymous1) Children() *[2]*RTL_BALANCED_NODE { 176 | return (*[2]*RTL_BALANCED_NODE)(unsafe.Pointer(this)) 177 | } 178 | 179 | func (this *RTL_BALANCED_NODE_Anonymous1) ChildrenVal() [2]*RTL_BALANCED_NODE { 180 | return *(*[2]*RTL_BALANCED_NODE)(unsafe.Pointer(this)) 181 | } 182 | 183 | func (this *RTL_BALANCED_NODE_Anonymous1) Anonymous() *RTL_BALANCED_NODE_Anonymous1_Anonymous { 184 | return (*RTL_BALANCED_NODE_Anonymous1_Anonymous)(unsafe.Pointer(this)) 185 | } 186 | 187 | func (this *RTL_BALANCED_NODE_Anonymous1) AnonymousVal() RTL_BALANCED_NODE_Anonymous1_Anonymous { 188 | return *(*RTL_BALANCED_NODE_Anonymous1_Anonymous)(unsafe.Pointer(this)) 189 | } 190 | 191 | type RTL_BALANCED_NODE_Anonymous2 struct { 192 | Data [1]uint64 193 | } 194 | 195 | func (this *RTL_BALANCED_NODE_Anonymous2) Bitfield_() *byte { 196 | return (*byte)(unsafe.Pointer(this)) 197 | } 198 | 199 | func (this *RTL_BALANCED_NODE_Anonymous2) Bitfield_Val() byte { 200 | return *(*byte)(unsafe.Pointer(this)) 201 | } 202 | 203 | func (this *RTL_BALANCED_NODE_Anonymous2) ParentValue() *uintptr { 204 | return (*uintptr)(unsafe.Pointer(this)) 205 | } 206 | 207 | func (this *RTL_BALANCED_NODE_Anonymous2) ParentValueVal() uintptr { 208 | return *(*uintptr)(unsafe.Pointer(this)) 209 | } 210 | 211 | type RTL_BALANCED_NODE struct { 212 | RTL_BALANCED_NODE_Anonymous1 213 | RTL_BALANCED_NODE_Anonymous2 214 | } 215 | 216 | type LIST_ENTRY32 struct { 217 | Flink uint32 218 | Blink uint32 219 | } 220 | 221 | type LIST_ENTRY64 struct { 222 | Flink uint64 223 | Blink uint64 224 | } 225 | 226 | type SINGLE_LIST_ENTRY32 struct { 227 | Next uint32 228 | } 229 | 230 | type WNF_STATE_NAME struct { 231 | Data [2]uint32 232 | } 233 | 234 | type STRING32 struct { 235 | Length uint16 236 | MaximumLength uint16 237 | Buffer uint32 238 | } 239 | 240 | type STRING64 struct { 241 | Length uint16 242 | MaximumLength uint16 243 | Buffer uint64 244 | } 245 | 246 | type OBJECTID struct { 247 | Lineage syscall.GUID 248 | Uniquifier uint32 249 | } 250 | 251 | type SLIST_HEADER_Anonymous struct { 252 | Alignment uint64 253 | Region uint64 254 | } 255 | 256 | type SLIST_HEADER_HeaderX64 struct { 257 | Bitfield1_ uint64 258 | Bitfield2_ uint64 259 | } 260 | 261 | type SLIST_HEADER struct { 262 | SLIST_HEADER_Anonymous 263 | } 264 | 265 | func (this *SLIST_HEADER) Anonymous() *SLIST_HEADER_Anonymous { 266 | return (*SLIST_HEADER_Anonymous)(unsafe.Pointer(this)) 267 | } 268 | 269 | func (this *SLIST_HEADER) AnonymousVal() SLIST_HEADER_Anonymous { 270 | return *(*SLIST_HEADER_Anonymous)(unsafe.Pointer(this)) 271 | } 272 | 273 | func (this *SLIST_HEADER) HeaderX64() *SLIST_HEADER_HeaderX64 { 274 | return (*SLIST_HEADER_HeaderX64)(unsafe.Pointer(this)) 275 | } 276 | 277 | func (this *SLIST_HEADER) HeaderX64Val() SLIST_HEADER_HeaderX64 { 278 | return *(*SLIST_HEADER_HeaderX64)(unsafe.Pointer(this)) 279 | } 280 | 281 | type FLOATING_SAVE_AREA struct { 282 | ControlWord uint32 283 | StatusWord uint32 284 | TagWord uint32 285 | ErrorOffset uint32 286 | ErrorSelector uint32 287 | DataOffset uint32 288 | DataSelector uint32 289 | RegisterArea [80]byte 290 | Cr0NpxState uint32 291 | } 292 | 293 | type EXCEPTION_REGISTRATION_RECORD struct { 294 | Next *EXCEPTION_REGISTRATION_RECORD 295 | Handler EXCEPTION_ROUTINE 296 | } 297 | 298 | type NT_TIB_Anonymous struct { 299 | Data [1]uint64 300 | } 301 | 302 | func (this *NT_TIB_Anonymous) FiberData() *unsafe.Pointer { 303 | return (*unsafe.Pointer)(unsafe.Pointer(this)) 304 | } 305 | 306 | func (this *NT_TIB_Anonymous) FiberDataVal() unsafe.Pointer { 307 | return *(*unsafe.Pointer)(unsafe.Pointer(this)) 308 | } 309 | 310 | func (this *NT_TIB_Anonymous) Version() *uint32 { 311 | return (*uint32)(unsafe.Pointer(this)) 312 | } 313 | 314 | func (this *NT_TIB_Anonymous) VersionVal() uint32 { 315 | return *(*uint32)(unsafe.Pointer(this)) 316 | } 317 | 318 | type NT_TIB struct { 319 | ExceptionList *EXCEPTION_REGISTRATION_RECORD 320 | StackBase unsafe.Pointer 321 | StackLimit unsafe.Pointer 322 | SubSystemTib unsafe.Pointer 323 | NT_TIB_Anonymous 324 | ArbitraryUserPointer unsafe.Pointer 325 | Self *NT_TIB 326 | } 327 | 328 | // func types 329 | 330 | type EXCEPTION_ROUTINE = uintptr 331 | type EXCEPTION_ROUTINE_func = func(ExceptionRecord *EXCEPTION_RECORD, EstablisherFrame unsafe.Pointer, ContextRecord *CONTEXT, DispatcherContext unsafe.Pointer) EXCEPTION_DISPOSITION 332 | -------------------------------------------------------------------------------- /win32/UI.Input.go: -------------------------------------------------------------------------------- 1 | package win32 2 | 3 | import ( 4 | "syscall" 5 | "unsafe" 6 | ) 7 | 8 | type ( 9 | HRAWINPUT = uintptr 10 | ) 11 | 12 | // enums 13 | 14 | // enum 15 | type RAW_INPUT_DATA_COMMAND_FLAGS uint32 16 | 17 | const ( 18 | RID_HEADER RAW_INPUT_DATA_COMMAND_FLAGS = 268435461 19 | RID_INPUT RAW_INPUT_DATA_COMMAND_FLAGS = 268435459 20 | ) 21 | 22 | // enum 23 | type RAW_INPUT_DEVICE_INFO_COMMAND uint32 24 | 25 | const ( 26 | RIDI_PREPARSEDDATA RAW_INPUT_DEVICE_INFO_COMMAND = 536870917 27 | RIDI_DEVICENAME RAW_INPUT_DEVICE_INFO_COMMAND = 536870919 28 | RIDI_DEVICEINFO RAW_INPUT_DEVICE_INFO_COMMAND = 536870923 29 | ) 30 | 31 | // enum 32 | type RID_DEVICE_INFO_TYPE uint32 33 | 34 | const ( 35 | RIM_TYPEMOUSE RID_DEVICE_INFO_TYPE = 0 36 | RIM_TYPEKEYBOARD RID_DEVICE_INFO_TYPE = 1 37 | RIM_TYPEHID RID_DEVICE_INFO_TYPE = 2 38 | ) 39 | 40 | // enum 41 | // flags 42 | type RAWINPUTDEVICE_FLAGS uint32 43 | 44 | const ( 45 | RIDEV_REMOVE RAWINPUTDEVICE_FLAGS = 1 46 | RIDEV_EXCLUDE RAWINPUTDEVICE_FLAGS = 16 47 | RIDEV_PAGEONLY RAWINPUTDEVICE_FLAGS = 32 48 | RIDEV_NOLEGACY RAWINPUTDEVICE_FLAGS = 48 49 | RIDEV_INPUTSINK RAWINPUTDEVICE_FLAGS = 256 50 | RIDEV_CAPTUREMOUSE RAWINPUTDEVICE_FLAGS = 512 51 | RIDEV_NOHOTKEYS RAWINPUTDEVICE_FLAGS = 512 52 | RIDEV_APPKEYS RAWINPUTDEVICE_FLAGS = 1024 53 | RIDEV_EXINPUTSINK RAWINPUTDEVICE_FLAGS = 4096 54 | RIDEV_DEVNOTIFY RAWINPUTDEVICE_FLAGS = 8192 55 | ) 56 | 57 | // enum 58 | type MOUSE_STATE uint16 59 | 60 | const ( 61 | MOUSE_MOVE_RELATIVE MOUSE_STATE = 0 62 | MOUSE_MOVE_ABSOLUTE MOUSE_STATE = 1 63 | MOUSE_VIRTUAL_DESKTOP MOUSE_STATE = 2 64 | MOUSE_ATTRIBUTES_CHANGED MOUSE_STATE = 4 65 | MOUSE_MOVE_NOCOALESCE MOUSE_STATE = 8 66 | ) 67 | 68 | // enum 69 | type INPUT_MESSAGE_DEVICE_TYPE int32 70 | 71 | const ( 72 | IMDT_UNAVAILABLE INPUT_MESSAGE_DEVICE_TYPE = 0 73 | IMDT_KEYBOARD INPUT_MESSAGE_DEVICE_TYPE = 1 74 | IMDT_MOUSE INPUT_MESSAGE_DEVICE_TYPE = 2 75 | IMDT_TOUCH INPUT_MESSAGE_DEVICE_TYPE = 4 76 | IMDT_PEN INPUT_MESSAGE_DEVICE_TYPE = 8 77 | IMDT_TOUCHPAD INPUT_MESSAGE_DEVICE_TYPE = 16 78 | ) 79 | 80 | // enum 81 | type INPUT_MESSAGE_ORIGIN_ID int32 82 | 83 | const ( 84 | IMO_UNAVAILABLE INPUT_MESSAGE_ORIGIN_ID = 0 85 | IMO_HARDWARE INPUT_MESSAGE_ORIGIN_ID = 1 86 | IMO_INJECTED INPUT_MESSAGE_ORIGIN_ID = 2 87 | IMO_SYSTEM INPUT_MESSAGE_ORIGIN_ID = 4 88 | ) 89 | 90 | // structs 91 | 92 | type RAWINPUTHEADER struct { 93 | DwType uint32 94 | DwSize uint32 95 | HDevice HANDLE 96 | WParam WPARAM 97 | } 98 | 99 | type RAWMOUSE_Anonymous_Anonymous struct { 100 | UsButtonFlags uint16 101 | UsButtonData uint16 102 | } 103 | 104 | type RAWMOUSE_Anonymous struct { 105 | RAWMOUSE_Anonymous_Anonymous 106 | } 107 | 108 | func (this *RAWMOUSE_Anonymous) UlButtons() *uint32 { 109 | return (*uint32)(unsafe.Pointer(this)) 110 | } 111 | 112 | func (this *RAWMOUSE_Anonymous) UlButtonsVal() uint32 { 113 | return *(*uint32)(unsafe.Pointer(this)) 114 | } 115 | 116 | func (this *RAWMOUSE_Anonymous) Anonymous() *RAWMOUSE_Anonymous_Anonymous { 117 | return (*RAWMOUSE_Anonymous_Anonymous)(unsafe.Pointer(this)) 118 | } 119 | 120 | func (this *RAWMOUSE_Anonymous) AnonymousVal() RAWMOUSE_Anonymous_Anonymous { 121 | return *(*RAWMOUSE_Anonymous_Anonymous)(unsafe.Pointer(this)) 122 | } 123 | 124 | type RAWMOUSE struct { 125 | UsFlags MOUSE_STATE 126 | RAWMOUSE_Anonymous 127 | UlRawButtons uint32 128 | LLastX int32 129 | LLastY int32 130 | UlExtraInformation uint32 131 | } 132 | 133 | type RAWKEYBOARD struct { 134 | MakeCode uint16 135 | Flags uint16 136 | Reserved uint16 137 | VKey uint16 138 | Message uint32 139 | ExtraInformation uint32 140 | } 141 | 142 | type RAWHID struct { 143 | DwSizeHid uint32 144 | DwCount uint32 145 | BRawData [1]byte 146 | } 147 | 148 | type RAWINPUT_Data struct { 149 | Data [6]uint32 150 | } 151 | 152 | func (this *RAWINPUT_Data) Mouse() *RAWMOUSE { 153 | return (*RAWMOUSE)(unsafe.Pointer(this)) 154 | } 155 | 156 | func (this *RAWINPUT_Data) MouseVal() RAWMOUSE { 157 | return *(*RAWMOUSE)(unsafe.Pointer(this)) 158 | } 159 | 160 | func (this *RAWINPUT_Data) Keyboard() *RAWKEYBOARD { 161 | return (*RAWKEYBOARD)(unsafe.Pointer(this)) 162 | } 163 | 164 | func (this *RAWINPUT_Data) KeyboardVal() RAWKEYBOARD { 165 | return *(*RAWKEYBOARD)(unsafe.Pointer(this)) 166 | } 167 | 168 | func (this *RAWINPUT_Data) Hid() *RAWHID { 169 | return (*RAWHID)(unsafe.Pointer(this)) 170 | } 171 | 172 | func (this *RAWINPUT_Data) HidVal() RAWHID { 173 | return *(*RAWHID)(unsafe.Pointer(this)) 174 | } 175 | 176 | type RAWINPUT struct { 177 | Header RAWINPUTHEADER 178 | Data RAWINPUT_Data 179 | } 180 | 181 | type RID_DEVICE_INFO_MOUSE struct { 182 | DwId uint32 183 | DwNumberOfButtons uint32 184 | DwSampleRate uint32 185 | FHasHorizontalWheel BOOL 186 | } 187 | 188 | type RID_DEVICE_INFO_KEYBOARD struct { 189 | DwType uint32 190 | DwSubType uint32 191 | DwKeyboardMode uint32 192 | DwNumberOfFunctionKeys uint32 193 | DwNumberOfIndicators uint32 194 | DwNumberOfKeysTotal uint32 195 | } 196 | 197 | type RID_DEVICE_INFO_HID struct { 198 | DwVendorId uint32 199 | DwProductId uint32 200 | DwVersionNumber uint32 201 | UsUsagePage uint16 202 | UsUsage uint16 203 | } 204 | 205 | type RID_DEVICE_INFO_Anonymous struct { 206 | Data [6]uint32 207 | } 208 | 209 | func (this *RID_DEVICE_INFO_Anonymous) Mouse() *RID_DEVICE_INFO_MOUSE { 210 | return (*RID_DEVICE_INFO_MOUSE)(unsafe.Pointer(this)) 211 | } 212 | 213 | func (this *RID_DEVICE_INFO_Anonymous) MouseVal() RID_DEVICE_INFO_MOUSE { 214 | return *(*RID_DEVICE_INFO_MOUSE)(unsafe.Pointer(this)) 215 | } 216 | 217 | func (this *RID_DEVICE_INFO_Anonymous) Keyboard() *RID_DEVICE_INFO_KEYBOARD { 218 | return (*RID_DEVICE_INFO_KEYBOARD)(unsafe.Pointer(this)) 219 | } 220 | 221 | func (this *RID_DEVICE_INFO_Anonymous) KeyboardVal() RID_DEVICE_INFO_KEYBOARD { 222 | return *(*RID_DEVICE_INFO_KEYBOARD)(unsafe.Pointer(this)) 223 | } 224 | 225 | func (this *RID_DEVICE_INFO_Anonymous) Hid() *RID_DEVICE_INFO_HID { 226 | return (*RID_DEVICE_INFO_HID)(unsafe.Pointer(this)) 227 | } 228 | 229 | func (this *RID_DEVICE_INFO_Anonymous) HidVal() RID_DEVICE_INFO_HID { 230 | return *(*RID_DEVICE_INFO_HID)(unsafe.Pointer(this)) 231 | } 232 | 233 | type RID_DEVICE_INFO struct { 234 | CbSize uint32 235 | DwType RID_DEVICE_INFO_TYPE 236 | RID_DEVICE_INFO_Anonymous 237 | } 238 | 239 | type RAWINPUTDEVICE struct { 240 | UsUsagePage uint16 241 | UsUsage uint16 242 | DwFlags RAWINPUTDEVICE_FLAGS 243 | HwndTarget HWND 244 | } 245 | 246 | type RAWINPUTDEVICELIST struct { 247 | HDevice HANDLE 248 | DwType RID_DEVICE_INFO_TYPE 249 | } 250 | 251 | type INPUT_MESSAGE_SOURCE struct { 252 | DeviceType INPUT_MESSAGE_DEVICE_TYPE 253 | OriginId INPUT_MESSAGE_ORIGIN_ID 254 | } 255 | 256 | var ( 257 | pGetRawInputData uintptr 258 | pGetRawInputDeviceInfoA uintptr 259 | pGetRawInputDeviceInfoW uintptr 260 | pGetRawInputBuffer uintptr 261 | pRegisterRawInputDevices uintptr 262 | pGetRegisteredRawInputDevices uintptr 263 | pGetRawInputDeviceList uintptr 264 | pDefRawInputProc uintptr 265 | pGetCurrentInputMessageSource uintptr 266 | pGetCIMSSM uintptr 267 | ) 268 | 269 | func GetRawInputData(hRawInput HRAWINPUT, uiCommand RAW_INPUT_DATA_COMMAND_FLAGS, pData unsafe.Pointer, pcbSize *uint32, cbSizeHeader uint32) uint32 { 270 | addr := LazyAddr(&pGetRawInputData, libUser32, "GetRawInputData") 271 | ret, _, _ := syscall.SyscallN(addr, hRawInput, uintptr(uiCommand), uintptr(pData), uintptr(unsafe.Pointer(pcbSize)), uintptr(cbSizeHeader)) 272 | return uint32(ret) 273 | } 274 | 275 | func GetRawInputDeviceInfoA(hDevice HANDLE, uiCommand RAW_INPUT_DEVICE_INFO_COMMAND, pData unsafe.Pointer, pcbSize *uint32) (uint32, WIN32_ERROR) { 276 | addr := LazyAddr(&pGetRawInputDeviceInfoA, libUser32, "GetRawInputDeviceInfoA") 277 | ret, _, err := syscall.SyscallN(addr, hDevice, uintptr(uiCommand), uintptr(pData), uintptr(unsafe.Pointer(pcbSize))) 278 | return uint32(ret), WIN32_ERROR(err) 279 | } 280 | 281 | var GetRawInputDeviceInfo = GetRawInputDeviceInfoW 282 | 283 | func GetRawInputDeviceInfoW(hDevice HANDLE, uiCommand RAW_INPUT_DEVICE_INFO_COMMAND, pData unsafe.Pointer, pcbSize *uint32) (uint32, WIN32_ERROR) { 284 | addr := LazyAddr(&pGetRawInputDeviceInfoW, libUser32, "GetRawInputDeviceInfoW") 285 | ret, _, err := syscall.SyscallN(addr, hDevice, uintptr(uiCommand), uintptr(pData), uintptr(unsafe.Pointer(pcbSize))) 286 | return uint32(ret), WIN32_ERROR(err) 287 | } 288 | 289 | func GetRawInputBuffer(pData *RAWINPUT, pcbSize *uint32, cbSizeHeader uint32) (uint32, WIN32_ERROR) { 290 | addr := LazyAddr(&pGetRawInputBuffer, libUser32, "GetRawInputBuffer") 291 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(pData)), uintptr(unsafe.Pointer(pcbSize)), uintptr(cbSizeHeader)) 292 | return uint32(ret), WIN32_ERROR(err) 293 | } 294 | 295 | func RegisterRawInputDevices(pRawInputDevices *RAWINPUTDEVICE, uiNumDevices uint32, cbSize uint32) (BOOL, WIN32_ERROR) { 296 | addr := LazyAddr(&pRegisterRawInputDevices, libUser32, "RegisterRawInputDevices") 297 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(pRawInputDevices)), uintptr(uiNumDevices), uintptr(cbSize)) 298 | return BOOL(ret), WIN32_ERROR(err) 299 | } 300 | 301 | func GetRegisteredRawInputDevices(pRawInputDevices *RAWINPUTDEVICE, puiNumDevices *uint32, cbSize uint32) (uint32, WIN32_ERROR) { 302 | addr := LazyAddr(&pGetRegisteredRawInputDevices, libUser32, "GetRegisteredRawInputDevices") 303 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(pRawInputDevices)), uintptr(unsafe.Pointer(puiNumDevices)), uintptr(cbSize)) 304 | return uint32(ret), WIN32_ERROR(err) 305 | } 306 | 307 | func GetRawInputDeviceList(pRawInputDeviceList *RAWINPUTDEVICELIST, puiNumDevices *uint32, cbSize uint32) (uint32, WIN32_ERROR) { 308 | addr := LazyAddr(&pGetRawInputDeviceList, libUser32, "GetRawInputDeviceList") 309 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(pRawInputDeviceList)), uintptr(unsafe.Pointer(puiNumDevices)), uintptr(cbSize)) 310 | return uint32(ret), WIN32_ERROR(err) 311 | } 312 | 313 | func DefRawInputProc(paRawInput **RAWINPUT, nInput int32, cbSizeHeader uint32) LRESULT { 314 | addr := LazyAddr(&pDefRawInputProc, libUser32, "DefRawInputProc") 315 | ret, _, _ := syscall.SyscallN(addr, uintptr(unsafe.Pointer(paRawInput)), uintptr(nInput), uintptr(cbSizeHeader)) 316 | return ret 317 | } 318 | 319 | func GetCurrentInputMessageSource(inputMessageSource *INPUT_MESSAGE_SOURCE) (BOOL, WIN32_ERROR) { 320 | addr := LazyAddr(&pGetCurrentInputMessageSource, libUser32, "GetCurrentInputMessageSource") 321 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(inputMessageSource))) 322 | return BOOL(ret), WIN32_ERROR(err) 323 | } 324 | 325 | func GetCIMSSM(inputMessageSource *INPUT_MESSAGE_SOURCE) BOOL { 326 | addr := LazyAddr(&pGetCIMSSM, libUser32, "GetCIMSSM") 327 | ret, _, _ := syscall.SyscallN(addr, uintptr(unsafe.Pointer(inputMessageSource))) 328 | return BOOL(ret) 329 | } 330 | -------------------------------------------------------------------------------- /win32/UI.HiDpi.go: -------------------------------------------------------------------------------- 1 | package win32 2 | 3 | import ( 4 | "syscall" 5 | "unsafe" 6 | ) 7 | 8 | type ( 9 | DPI_AWARENESS_CONTEXT = uintptr 10 | ) 11 | 12 | const ( 13 | DPI_AWARENESS_CONTEXT_UNAWARE DPI_AWARENESS_CONTEXT = ^DPI_AWARENESS_CONTEXT(0x0) 14 | DPI_AWARENESS_CONTEXT_SYSTEM_AWARE DPI_AWARENESS_CONTEXT = ^DPI_AWARENESS_CONTEXT(0x1) 15 | DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE DPI_AWARENESS_CONTEXT = ^DPI_AWARENESS_CONTEXT(0x2) 16 | DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 DPI_AWARENESS_CONTEXT = ^DPI_AWARENESS_CONTEXT(0x3) 17 | DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED DPI_AWARENESS_CONTEXT = ^DPI_AWARENESS_CONTEXT(0x4) 18 | ) 19 | 20 | // enums 21 | 22 | // enum 23 | type DPI_AWARENESS int32 24 | 25 | const ( 26 | DPI_AWARENESS_INVALID DPI_AWARENESS = -1 27 | DPI_AWARENESS_UNAWARE DPI_AWARENESS = 0 28 | DPI_AWARENESS_SYSTEM_AWARE DPI_AWARENESS = 1 29 | DPI_AWARENESS_PER_MONITOR_AWARE DPI_AWARENESS = 2 30 | ) 31 | 32 | // enum 33 | type DPI_HOSTING_BEHAVIOR int32 34 | 35 | const ( 36 | DPI_HOSTING_BEHAVIOR_INVALID DPI_HOSTING_BEHAVIOR = -1 37 | DPI_HOSTING_BEHAVIOR_DEFAULT DPI_HOSTING_BEHAVIOR = 0 38 | DPI_HOSTING_BEHAVIOR_MIXED DPI_HOSTING_BEHAVIOR = 1 39 | ) 40 | 41 | // enum 42 | // flags 43 | type DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS int32 44 | 45 | const ( 46 | DCDC_DEFAULT DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS = 0 47 | DCDC_DISABLE_FONT_UPDATE DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS = 1 48 | DCDC_DISABLE_RELAYOUT DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS = 2 49 | ) 50 | 51 | // enum 52 | // flags 53 | type DIALOG_DPI_CHANGE_BEHAVIORS int32 54 | 55 | const ( 56 | DDC_DEFAULT DIALOG_DPI_CHANGE_BEHAVIORS = 0 57 | DDC_DISABLE_ALL DIALOG_DPI_CHANGE_BEHAVIORS = 1 58 | DDC_DISABLE_RESIZE DIALOG_DPI_CHANGE_BEHAVIORS = 2 59 | DDC_DISABLE_CONTROL_RELAYOUT DIALOG_DPI_CHANGE_BEHAVIORS = 4 60 | ) 61 | 62 | // enum 63 | type PROCESS_DPI_AWARENESS int32 64 | 65 | const ( 66 | PROCESS_DPI_UNAWARE PROCESS_DPI_AWARENESS = 0 67 | PROCESS_SYSTEM_DPI_AWARE PROCESS_DPI_AWARENESS = 1 68 | PROCESS_PER_MONITOR_DPI_AWARE PROCESS_DPI_AWARENESS = 2 69 | ) 70 | 71 | // enum 72 | type MONITOR_DPI_TYPE int32 73 | 74 | const ( 75 | MDT_EFFECTIVE_DPI MONITOR_DPI_TYPE = 0 76 | MDT_ANGULAR_DPI MONITOR_DPI_TYPE = 1 77 | MDT_RAW_DPI MONITOR_DPI_TYPE = 2 78 | MDT_DEFAULT MONITOR_DPI_TYPE = 0 79 | ) 80 | 81 | var ( 82 | pOpenThemeDataForDpi uintptr 83 | pSetDialogControlDpiChangeBehavior uintptr 84 | pGetDialogControlDpiChangeBehavior uintptr 85 | pSetDialogDpiChangeBehavior uintptr 86 | pGetDialogDpiChangeBehavior uintptr 87 | pGetSystemMetricsForDpi uintptr 88 | pAdjustWindowRectExForDpi uintptr 89 | pLogicalToPhysicalPointForPerMonitorDPI uintptr 90 | pPhysicalToLogicalPointForPerMonitorDPI uintptr 91 | pSystemParametersInfoForDpi uintptr 92 | pSetThreadDpiAwarenessContext uintptr 93 | pGetThreadDpiAwarenessContext uintptr 94 | pGetWindowDpiAwarenessContext uintptr 95 | pGetAwarenessFromDpiAwarenessContext uintptr 96 | pGetDpiFromDpiAwarenessContext uintptr 97 | pAreDpiAwarenessContextsEqual uintptr 98 | pIsValidDpiAwarenessContext uintptr 99 | pGetDpiForWindow uintptr 100 | pGetDpiForSystem uintptr 101 | pGetSystemDpiForProcess uintptr 102 | pEnableNonClientDpiScaling uintptr 103 | pSetProcessDpiAwarenessContext uintptr 104 | pGetDpiAwarenessContextForProcess uintptr 105 | pSetThreadDpiHostingBehavior uintptr 106 | pGetThreadDpiHostingBehavior uintptr 107 | pGetWindowDpiHostingBehavior uintptr 108 | ) 109 | 110 | func OpenThemeDataForDpi(hwnd HWND, pszClassList PWSTR, dpi uint32) HTHEME { 111 | addr := LazyAddr(&pOpenThemeDataForDpi, libUxtheme, "OpenThemeDataForDpi") 112 | ret, _, _ := syscall.SyscallN(addr, hwnd, uintptr(unsafe.Pointer(pszClassList)), uintptr(dpi)) 113 | return ret 114 | } 115 | 116 | func SetDialogControlDpiChangeBehavior(hWnd HWND, mask DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS, values DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS) (BOOL, WIN32_ERROR) { 117 | addr := LazyAddr(&pSetDialogControlDpiChangeBehavior, libUser32, "SetDialogControlDpiChangeBehavior") 118 | ret, _, err := syscall.SyscallN(addr, hWnd, uintptr(mask), uintptr(values)) 119 | return BOOL(ret), WIN32_ERROR(err) 120 | } 121 | 122 | func GetDialogControlDpiChangeBehavior(hWnd HWND) (DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS, WIN32_ERROR) { 123 | addr := LazyAddr(&pGetDialogControlDpiChangeBehavior, libUser32, "GetDialogControlDpiChangeBehavior") 124 | ret, _, err := syscall.SyscallN(addr, hWnd) 125 | return DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS(ret), WIN32_ERROR(err) 126 | } 127 | 128 | func SetDialogDpiChangeBehavior(hDlg HWND, mask DIALOG_DPI_CHANGE_BEHAVIORS, values DIALOG_DPI_CHANGE_BEHAVIORS) (BOOL, WIN32_ERROR) { 129 | addr := LazyAddr(&pSetDialogDpiChangeBehavior, libUser32, "SetDialogDpiChangeBehavior") 130 | ret, _, err := syscall.SyscallN(addr, hDlg, uintptr(mask), uintptr(values)) 131 | return BOOL(ret), WIN32_ERROR(err) 132 | } 133 | 134 | func GetDialogDpiChangeBehavior(hDlg HWND) (DIALOG_DPI_CHANGE_BEHAVIORS, WIN32_ERROR) { 135 | addr := LazyAddr(&pGetDialogDpiChangeBehavior, libUser32, "GetDialogDpiChangeBehavior") 136 | ret, _, err := syscall.SyscallN(addr, hDlg) 137 | return DIALOG_DPI_CHANGE_BEHAVIORS(ret), WIN32_ERROR(err) 138 | } 139 | 140 | func GetSystemMetricsForDpi(nIndex SYSTEM_METRICS_INDEX, dpi uint32) (int32, WIN32_ERROR) { 141 | addr := LazyAddr(&pGetSystemMetricsForDpi, libUser32, "GetSystemMetricsForDpi") 142 | ret, _, err := syscall.SyscallN(addr, uintptr(nIndex), uintptr(dpi)) 143 | return int32(ret), WIN32_ERROR(err) 144 | } 145 | 146 | func AdjustWindowRectExForDpi(lpRect *RECT, dwStyle WINDOW_STYLE, bMenu BOOL, dwExStyle WINDOW_EX_STYLE, dpi uint32) (BOOL, WIN32_ERROR) { 147 | addr := LazyAddr(&pAdjustWindowRectExForDpi, libUser32, "AdjustWindowRectExForDpi") 148 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpRect)), uintptr(dwStyle), uintptr(bMenu), uintptr(dwExStyle), uintptr(dpi)) 149 | return BOOL(ret), WIN32_ERROR(err) 150 | } 151 | 152 | func LogicalToPhysicalPointForPerMonitorDPI(hWnd HWND, lpPoint *POINT) BOOL { 153 | addr := LazyAddr(&pLogicalToPhysicalPointForPerMonitorDPI, libUser32, "LogicalToPhysicalPointForPerMonitorDPI") 154 | ret, _, _ := syscall.SyscallN(addr, hWnd, uintptr(unsafe.Pointer(lpPoint))) 155 | return BOOL(ret) 156 | } 157 | 158 | func PhysicalToLogicalPointForPerMonitorDPI(hWnd HWND, lpPoint *POINT) BOOL { 159 | addr := LazyAddr(&pPhysicalToLogicalPointForPerMonitorDPI, libUser32, "PhysicalToLogicalPointForPerMonitorDPI") 160 | ret, _, _ := syscall.SyscallN(addr, hWnd, uintptr(unsafe.Pointer(lpPoint))) 161 | return BOOL(ret) 162 | } 163 | 164 | func SystemParametersInfoForDpi(uiAction uint32, uiParam uint32, pvParam unsafe.Pointer, fWinIni uint32, dpi uint32) (BOOL, WIN32_ERROR) { 165 | addr := LazyAddr(&pSystemParametersInfoForDpi, libUser32, "SystemParametersInfoForDpi") 166 | ret, _, err := syscall.SyscallN(addr, uintptr(uiAction), uintptr(uiParam), uintptr(pvParam), uintptr(fWinIni), uintptr(dpi)) 167 | return BOOL(ret), WIN32_ERROR(err) 168 | } 169 | 170 | func SetThreadDpiAwarenessContext(dpiContext DPI_AWARENESS_CONTEXT) DPI_AWARENESS_CONTEXT { 171 | addr := LazyAddr(&pSetThreadDpiAwarenessContext, libUser32, "SetThreadDpiAwarenessContext") 172 | ret, _, _ := syscall.SyscallN(addr, dpiContext) 173 | return ret 174 | } 175 | 176 | func GetThreadDpiAwarenessContext() DPI_AWARENESS_CONTEXT { 177 | addr := LazyAddr(&pGetThreadDpiAwarenessContext, libUser32, "GetThreadDpiAwarenessContext") 178 | ret, _, _ := syscall.SyscallN(addr) 179 | return ret 180 | } 181 | 182 | func GetWindowDpiAwarenessContext(hwnd HWND) DPI_AWARENESS_CONTEXT { 183 | addr := LazyAddr(&pGetWindowDpiAwarenessContext, libUser32, "GetWindowDpiAwarenessContext") 184 | ret, _, _ := syscall.SyscallN(addr, hwnd) 185 | return ret 186 | } 187 | 188 | func GetAwarenessFromDpiAwarenessContext(value DPI_AWARENESS_CONTEXT) DPI_AWARENESS { 189 | addr := LazyAddr(&pGetAwarenessFromDpiAwarenessContext, libUser32, "GetAwarenessFromDpiAwarenessContext") 190 | ret, _, _ := syscall.SyscallN(addr, value) 191 | return DPI_AWARENESS(ret) 192 | } 193 | 194 | func GetDpiFromDpiAwarenessContext(value DPI_AWARENESS_CONTEXT) uint32 { 195 | addr := LazyAddr(&pGetDpiFromDpiAwarenessContext, libUser32, "GetDpiFromDpiAwarenessContext") 196 | ret, _, _ := syscall.SyscallN(addr, value) 197 | return uint32(ret) 198 | } 199 | 200 | func AreDpiAwarenessContextsEqual(dpiContextA DPI_AWARENESS_CONTEXT, dpiContextB DPI_AWARENESS_CONTEXT) BOOL { 201 | addr := LazyAddr(&pAreDpiAwarenessContextsEqual, libUser32, "AreDpiAwarenessContextsEqual") 202 | ret, _, _ := syscall.SyscallN(addr, dpiContextA, dpiContextB) 203 | return BOOL(ret) 204 | } 205 | 206 | func IsValidDpiAwarenessContext(value DPI_AWARENESS_CONTEXT) BOOL { 207 | addr := LazyAddr(&pIsValidDpiAwarenessContext, libUser32, "IsValidDpiAwarenessContext") 208 | ret, _, _ := syscall.SyscallN(addr, value) 209 | return BOOL(ret) 210 | } 211 | 212 | func GetDpiForWindow(hwnd HWND) uint32 { 213 | addr := LazyAddr(&pGetDpiForWindow, libUser32, "GetDpiForWindow") 214 | ret, _, _ := syscall.SyscallN(addr, hwnd) 215 | return uint32(ret) 216 | } 217 | 218 | func GetDpiForSystem() uint32 { 219 | addr := LazyAddr(&pGetDpiForSystem, libUser32, "GetDpiForSystem") 220 | ret, _, _ := syscall.SyscallN(addr) 221 | return uint32(ret) 222 | } 223 | 224 | func GetSystemDpiForProcess(hProcess HANDLE) uint32 { 225 | addr := LazyAddr(&pGetSystemDpiForProcess, libUser32, "GetSystemDpiForProcess") 226 | ret, _, _ := syscall.SyscallN(addr, hProcess) 227 | return uint32(ret) 228 | } 229 | 230 | func EnableNonClientDpiScaling(hwnd HWND) (BOOL, WIN32_ERROR) { 231 | addr := LazyAddr(&pEnableNonClientDpiScaling, libUser32, "EnableNonClientDpiScaling") 232 | ret, _, err := syscall.SyscallN(addr, hwnd) 233 | return BOOL(ret), WIN32_ERROR(err) 234 | } 235 | 236 | func SetProcessDpiAwarenessContext(value DPI_AWARENESS_CONTEXT) (BOOL, WIN32_ERROR) { 237 | addr := LazyAddr(&pSetProcessDpiAwarenessContext, libUser32, "SetProcessDpiAwarenessContext") 238 | ret, _, err := syscall.SyscallN(addr, value) 239 | return BOOL(ret), WIN32_ERROR(err) 240 | } 241 | 242 | func GetDpiAwarenessContextForProcess(hProcess HANDLE) DPI_AWARENESS_CONTEXT { 243 | addr := LazyAddr(&pGetDpiAwarenessContextForProcess, libUser32, "GetDpiAwarenessContextForProcess") 244 | ret, _, _ := syscall.SyscallN(addr, hProcess) 245 | return ret 246 | } 247 | 248 | func SetThreadDpiHostingBehavior(value DPI_HOSTING_BEHAVIOR) DPI_HOSTING_BEHAVIOR { 249 | addr := LazyAddr(&pSetThreadDpiHostingBehavior, libUser32, "SetThreadDpiHostingBehavior") 250 | ret, _, _ := syscall.SyscallN(addr, uintptr(value)) 251 | return DPI_HOSTING_BEHAVIOR(ret) 252 | } 253 | 254 | func GetThreadDpiHostingBehavior() DPI_HOSTING_BEHAVIOR { 255 | addr := LazyAddr(&pGetThreadDpiHostingBehavior, libUser32, "GetThreadDpiHostingBehavior") 256 | ret, _, _ := syscall.SyscallN(addr) 257 | return DPI_HOSTING_BEHAVIOR(ret) 258 | } 259 | 260 | func GetWindowDpiHostingBehavior(hwnd HWND) DPI_HOSTING_BEHAVIOR { 261 | addr := LazyAddr(&pGetWindowDpiHostingBehavior, libUser32, "GetWindowDpiHostingBehavior") 262 | ret, _, _ := syscall.SyscallN(addr, hwnd) 263 | return DPI_HOSTING_BEHAVIOR(ret) 264 | } 265 | -------------------------------------------------------------------------------- /win32/System.Pipes.go: -------------------------------------------------------------------------------- 1 | package win32 2 | 3 | import ( 4 | "syscall" 5 | "unsafe" 6 | ) 7 | 8 | const ( 9 | PIPE_UNLIMITED_INSTANCES uint32 = 0xff 10 | NMPWAIT_WAIT_FOREVER uint32 = 0xffffffff 11 | NMPWAIT_NOWAIT uint32 = 0x1 12 | NMPWAIT_USE_DEFAULT_WAIT uint32 = 0x0 13 | ) 14 | 15 | // enums 16 | 17 | // enum 18 | // flags 19 | type NAMED_PIPE_MODE uint32 20 | 21 | const ( 22 | PIPE_WAIT NAMED_PIPE_MODE = 0 23 | PIPE_NOWAIT NAMED_PIPE_MODE = 1 24 | PIPE_READMODE_BYTE NAMED_PIPE_MODE = 0 25 | PIPE_READMODE_MESSAGE NAMED_PIPE_MODE = 2 26 | PIPE_CLIENT_END NAMED_PIPE_MODE = 0 27 | PIPE_SERVER_END NAMED_PIPE_MODE = 1 28 | PIPE_TYPE_BYTE NAMED_PIPE_MODE = 0 29 | PIPE_TYPE_MESSAGE NAMED_PIPE_MODE = 4 30 | PIPE_ACCEPT_REMOTE_CLIENTS NAMED_PIPE_MODE = 0 31 | PIPE_REJECT_REMOTE_CLIENTS NAMED_PIPE_MODE = 8 32 | ) 33 | 34 | var ( 35 | pCreatePipe uintptr 36 | pConnectNamedPipe uintptr 37 | pDisconnectNamedPipe uintptr 38 | pSetNamedPipeHandleState uintptr 39 | pPeekNamedPipe uintptr 40 | pTransactNamedPipe uintptr 41 | pCreateNamedPipeW uintptr 42 | pWaitNamedPipeW uintptr 43 | pGetNamedPipeClientComputerNameW uintptr 44 | pImpersonateNamedPipeClient uintptr 45 | pGetNamedPipeInfo uintptr 46 | pGetNamedPipeHandleStateW uintptr 47 | pCallNamedPipeW uintptr 48 | pCreateNamedPipeA uintptr 49 | pGetNamedPipeHandleStateA uintptr 50 | pCallNamedPipeA uintptr 51 | pWaitNamedPipeA uintptr 52 | pGetNamedPipeClientComputerNameA uintptr 53 | pGetNamedPipeClientProcessId uintptr 54 | pGetNamedPipeClientSessionId uintptr 55 | pGetNamedPipeServerProcessId uintptr 56 | pGetNamedPipeServerSessionId uintptr 57 | ) 58 | 59 | func CreatePipe(hReadPipe *HANDLE, hWritePipe *HANDLE, lpPipeAttributes *SECURITY_ATTRIBUTES, nSize uint32) (BOOL, WIN32_ERROR) { 60 | addr := LazyAddr(&pCreatePipe, libKernel32, "CreatePipe") 61 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(hReadPipe)), uintptr(unsafe.Pointer(hWritePipe)), uintptr(unsafe.Pointer(lpPipeAttributes)), uintptr(nSize)) 62 | return BOOL(ret), WIN32_ERROR(err) 63 | } 64 | 65 | func ConnectNamedPipe(hNamedPipe HANDLE, lpOverlapped *OVERLAPPED) (BOOL, WIN32_ERROR) { 66 | addr := LazyAddr(&pConnectNamedPipe, libKernel32, "ConnectNamedPipe") 67 | ret, _, err := syscall.SyscallN(addr, hNamedPipe, uintptr(unsafe.Pointer(lpOverlapped))) 68 | return BOOL(ret), WIN32_ERROR(err) 69 | } 70 | 71 | func DisconnectNamedPipe(hNamedPipe HANDLE) (BOOL, WIN32_ERROR) { 72 | addr := LazyAddr(&pDisconnectNamedPipe, libKernel32, "DisconnectNamedPipe") 73 | ret, _, err := syscall.SyscallN(addr, hNamedPipe) 74 | return BOOL(ret), WIN32_ERROR(err) 75 | } 76 | 77 | func SetNamedPipeHandleState(hNamedPipe HANDLE, lpMode *NAMED_PIPE_MODE, lpMaxCollectionCount *uint32, lpCollectDataTimeout *uint32) (BOOL, WIN32_ERROR) { 78 | addr := LazyAddr(&pSetNamedPipeHandleState, libKernel32, "SetNamedPipeHandleState") 79 | ret, _, err := syscall.SyscallN(addr, hNamedPipe, uintptr(unsafe.Pointer(lpMode)), uintptr(unsafe.Pointer(lpMaxCollectionCount)), uintptr(unsafe.Pointer(lpCollectDataTimeout))) 80 | return BOOL(ret), WIN32_ERROR(err) 81 | } 82 | 83 | func PeekNamedPipe(hNamedPipe HANDLE, lpBuffer unsafe.Pointer, nBufferSize uint32, lpBytesRead *uint32, lpTotalBytesAvail *uint32, lpBytesLeftThisMessage *uint32) (BOOL, WIN32_ERROR) { 84 | addr := LazyAddr(&pPeekNamedPipe, libKernel32, "PeekNamedPipe") 85 | ret, _, err := syscall.SyscallN(addr, hNamedPipe, uintptr(lpBuffer), uintptr(nBufferSize), uintptr(unsafe.Pointer(lpBytesRead)), uintptr(unsafe.Pointer(lpTotalBytesAvail)), uintptr(unsafe.Pointer(lpBytesLeftThisMessage))) 86 | return BOOL(ret), WIN32_ERROR(err) 87 | } 88 | 89 | func TransactNamedPipe(hNamedPipe HANDLE, lpInBuffer unsafe.Pointer, nInBufferSize uint32, lpOutBuffer unsafe.Pointer, nOutBufferSize uint32, lpBytesRead *uint32, lpOverlapped *OVERLAPPED) (BOOL, WIN32_ERROR) { 90 | addr := LazyAddr(&pTransactNamedPipe, libKernel32, "TransactNamedPipe") 91 | ret, _, err := syscall.SyscallN(addr, hNamedPipe, uintptr(lpInBuffer), uintptr(nInBufferSize), uintptr(lpOutBuffer), uintptr(nOutBufferSize), uintptr(unsafe.Pointer(lpBytesRead)), uintptr(unsafe.Pointer(lpOverlapped))) 92 | return BOOL(ret), WIN32_ERROR(err) 93 | } 94 | 95 | var CreateNamedPipe = CreateNamedPipeW 96 | 97 | func CreateNamedPipeW(lpName PWSTR, dwOpenMode FILE_FLAGS_AND_ATTRIBUTES, dwPipeMode NAMED_PIPE_MODE, nMaxInstances uint32, nOutBufferSize uint32, nInBufferSize uint32, nDefaultTimeOut uint32, lpSecurityAttributes *SECURITY_ATTRIBUTES) HANDLE { 98 | addr := LazyAddr(&pCreateNamedPipeW, libKernel32, "CreateNamedPipeW") 99 | ret, _, _ := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpName)), uintptr(dwOpenMode), uintptr(dwPipeMode), uintptr(nMaxInstances), uintptr(nOutBufferSize), uintptr(nInBufferSize), uintptr(nDefaultTimeOut), uintptr(unsafe.Pointer(lpSecurityAttributes))) 100 | return ret 101 | } 102 | 103 | var WaitNamedPipe = WaitNamedPipeW 104 | 105 | func WaitNamedPipeW(lpNamedPipeName PWSTR, nTimeOut uint32) BOOL { 106 | addr := LazyAddr(&pWaitNamedPipeW, libKernel32, "WaitNamedPipeW") 107 | ret, _, _ := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpNamedPipeName)), uintptr(nTimeOut)) 108 | return BOOL(ret) 109 | } 110 | 111 | var GetNamedPipeClientComputerName = GetNamedPipeClientComputerNameW 112 | 113 | func GetNamedPipeClientComputerNameW(Pipe HANDLE, ClientComputerName PWSTR, ClientComputerNameLength uint32) BOOL { 114 | addr := LazyAddr(&pGetNamedPipeClientComputerNameW, libKernel32, "GetNamedPipeClientComputerNameW") 115 | ret, _, _ := syscall.SyscallN(addr, Pipe, uintptr(unsafe.Pointer(ClientComputerName)), uintptr(ClientComputerNameLength)) 116 | return BOOL(ret) 117 | } 118 | 119 | func ImpersonateNamedPipeClient(hNamedPipe HANDLE) (BOOL, WIN32_ERROR) { 120 | addr := LazyAddr(&pImpersonateNamedPipeClient, libAdvapi32, "ImpersonateNamedPipeClient") 121 | ret, _, err := syscall.SyscallN(addr, hNamedPipe) 122 | return BOOL(ret), WIN32_ERROR(err) 123 | } 124 | 125 | func GetNamedPipeInfo(hNamedPipe HANDLE, lpFlags *NAMED_PIPE_MODE, lpOutBufferSize *uint32, lpInBufferSize *uint32, lpMaxInstances *uint32) (BOOL, WIN32_ERROR) { 126 | addr := LazyAddr(&pGetNamedPipeInfo, libKernel32, "GetNamedPipeInfo") 127 | ret, _, err := syscall.SyscallN(addr, hNamedPipe, uintptr(unsafe.Pointer(lpFlags)), uintptr(unsafe.Pointer(lpOutBufferSize)), uintptr(unsafe.Pointer(lpInBufferSize)), uintptr(unsafe.Pointer(lpMaxInstances))) 128 | return BOOL(ret), WIN32_ERROR(err) 129 | } 130 | 131 | var GetNamedPipeHandleState = GetNamedPipeHandleStateW 132 | 133 | func GetNamedPipeHandleStateW(hNamedPipe HANDLE, lpState *NAMED_PIPE_MODE, lpCurInstances *uint32, lpMaxCollectionCount *uint32, lpCollectDataTimeout *uint32, lpUserName PWSTR, nMaxUserNameSize uint32) BOOL { 134 | addr := LazyAddr(&pGetNamedPipeHandleStateW, libKernel32, "GetNamedPipeHandleStateW") 135 | ret, _, _ := syscall.SyscallN(addr, hNamedPipe, uintptr(unsafe.Pointer(lpState)), uintptr(unsafe.Pointer(lpCurInstances)), uintptr(unsafe.Pointer(lpMaxCollectionCount)), uintptr(unsafe.Pointer(lpCollectDataTimeout)), uintptr(unsafe.Pointer(lpUserName)), uintptr(nMaxUserNameSize)) 136 | return BOOL(ret) 137 | } 138 | 139 | var CallNamedPipe = CallNamedPipeW 140 | 141 | func CallNamedPipeW(lpNamedPipeName PWSTR, lpInBuffer unsafe.Pointer, nInBufferSize uint32, lpOutBuffer unsafe.Pointer, nOutBufferSize uint32, lpBytesRead *uint32, nTimeOut uint32) BOOL { 142 | addr := LazyAddr(&pCallNamedPipeW, libKernel32, "CallNamedPipeW") 143 | ret, _, _ := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpNamedPipeName)), uintptr(lpInBuffer), uintptr(nInBufferSize), uintptr(lpOutBuffer), uintptr(nOutBufferSize), uintptr(unsafe.Pointer(lpBytesRead)), uintptr(nTimeOut)) 144 | return BOOL(ret) 145 | } 146 | 147 | func CreateNamedPipeA(lpName PSTR, dwOpenMode FILE_FLAGS_AND_ATTRIBUTES, dwPipeMode NAMED_PIPE_MODE, nMaxInstances uint32, nOutBufferSize uint32, nInBufferSize uint32, nDefaultTimeOut uint32, lpSecurityAttributes *SECURITY_ATTRIBUTES) (HANDLE, WIN32_ERROR) { 148 | addr := LazyAddr(&pCreateNamedPipeA, libKernel32, "CreateNamedPipeA") 149 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpName)), uintptr(dwOpenMode), uintptr(dwPipeMode), uintptr(nMaxInstances), uintptr(nOutBufferSize), uintptr(nInBufferSize), uintptr(nDefaultTimeOut), uintptr(unsafe.Pointer(lpSecurityAttributes))) 150 | return ret, WIN32_ERROR(err) 151 | } 152 | 153 | func GetNamedPipeHandleStateA(hNamedPipe HANDLE, lpState *NAMED_PIPE_MODE, lpCurInstances *uint32, lpMaxCollectionCount *uint32, lpCollectDataTimeout *uint32, lpUserName PSTR, nMaxUserNameSize uint32) (BOOL, WIN32_ERROR) { 154 | addr := LazyAddr(&pGetNamedPipeHandleStateA, libKernel32, "GetNamedPipeHandleStateA") 155 | ret, _, err := syscall.SyscallN(addr, hNamedPipe, uintptr(unsafe.Pointer(lpState)), uintptr(unsafe.Pointer(lpCurInstances)), uintptr(unsafe.Pointer(lpMaxCollectionCount)), uintptr(unsafe.Pointer(lpCollectDataTimeout)), uintptr(unsafe.Pointer(lpUserName)), uintptr(nMaxUserNameSize)) 156 | return BOOL(ret), WIN32_ERROR(err) 157 | } 158 | 159 | func CallNamedPipeA(lpNamedPipeName PSTR, lpInBuffer unsafe.Pointer, nInBufferSize uint32, lpOutBuffer unsafe.Pointer, nOutBufferSize uint32, lpBytesRead *uint32, nTimeOut uint32) (BOOL, WIN32_ERROR) { 160 | addr := LazyAddr(&pCallNamedPipeA, libKernel32, "CallNamedPipeA") 161 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpNamedPipeName)), uintptr(lpInBuffer), uintptr(nInBufferSize), uintptr(lpOutBuffer), uintptr(nOutBufferSize), uintptr(unsafe.Pointer(lpBytesRead)), uintptr(nTimeOut)) 162 | return BOOL(ret), WIN32_ERROR(err) 163 | } 164 | 165 | func WaitNamedPipeA(lpNamedPipeName PSTR, nTimeOut uint32) (BOOL, WIN32_ERROR) { 166 | addr := LazyAddr(&pWaitNamedPipeA, libKernel32, "WaitNamedPipeA") 167 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpNamedPipeName)), uintptr(nTimeOut)) 168 | return BOOL(ret), WIN32_ERROR(err) 169 | } 170 | 171 | func GetNamedPipeClientComputerNameA(Pipe HANDLE, ClientComputerName PSTR, ClientComputerNameLength uint32) (BOOL, WIN32_ERROR) { 172 | addr := LazyAddr(&pGetNamedPipeClientComputerNameA, libKernel32, "GetNamedPipeClientComputerNameA") 173 | ret, _, err := syscall.SyscallN(addr, Pipe, uintptr(unsafe.Pointer(ClientComputerName)), uintptr(ClientComputerNameLength)) 174 | return BOOL(ret), WIN32_ERROR(err) 175 | } 176 | 177 | func GetNamedPipeClientProcessId(Pipe HANDLE, ClientProcessId *uint32) (BOOL, WIN32_ERROR) { 178 | addr := LazyAddr(&pGetNamedPipeClientProcessId, libKernel32, "GetNamedPipeClientProcessId") 179 | ret, _, err := syscall.SyscallN(addr, Pipe, uintptr(unsafe.Pointer(ClientProcessId))) 180 | return BOOL(ret), WIN32_ERROR(err) 181 | } 182 | 183 | func GetNamedPipeClientSessionId(Pipe HANDLE, ClientSessionId *uint32) (BOOL, WIN32_ERROR) { 184 | addr := LazyAddr(&pGetNamedPipeClientSessionId, libKernel32, "GetNamedPipeClientSessionId") 185 | ret, _, err := syscall.SyscallN(addr, Pipe, uintptr(unsafe.Pointer(ClientSessionId))) 186 | return BOOL(ret), WIN32_ERROR(err) 187 | } 188 | 189 | func GetNamedPipeServerProcessId(Pipe HANDLE, ServerProcessId *uint32) (BOOL, WIN32_ERROR) { 190 | addr := LazyAddr(&pGetNamedPipeServerProcessId, libKernel32, "GetNamedPipeServerProcessId") 191 | ret, _, err := syscall.SyscallN(addr, Pipe, uintptr(unsafe.Pointer(ServerProcessId))) 192 | return BOOL(ret), WIN32_ERROR(err) 193 | } 194 | 195 | func GetNamedPipeServerSessionId(Pipe HANDLE, ServerSessionId *uint32) (BOOL, WIN32_ERROR) { 196 | addr := LazyAddr(&pGetNamedPipeServerSessionId, libKernel32, "GetNamedPipeServerSessionId") 197 | ret, _, err := syscall.SyscallN(addr, Pipe, uintptr(unsafe.Pointer(ServerSessionId))) 198 | return BOOL(ret), WIN32_ERROR(err) 199 | } 200 | -------------------------------------------------------------------------------- /win32/1_supplement.go: -------------------------------------------------------------------------------- 1 | package win32 2 | 3 | import ( 4 | "syscall" 5 | "unsafe" 6 | 7 | "golang.org/x/sys/windows" 8 | ) 9 | 10 | // type HKL = uintptr 11 | type HTASK = uintptr 12 | 13 | type ALG_ID = uint32 14 | 15 | type CONDITION_OPERATION = int32 16 | 17 | type IID = syscall.GUID 18 | 19 | type POINTER_TOUCH_INFO struct { 20 | Data [18]uint64 21 | } 22 | 23 | type POINTER_PEN_INFO struct { 24 | Data [15]uint64 25 | } 26 | 27 | type NETRESOURCEA struct { 28 | } 29 | 30 | type BYTE = byte 31 | type SHORT = int16 32 | type INT = int32 33 | type UINT = uint32 34 | type CLSID = syscall.GUID 35 | type LANGID = uint16 36 | type UINT16 = uint16 37 | type ULONG_PTR = uintptr 38 | 39 | //type COLORREF = uint32 40 | 41 | type ATOM = uint16 42 | 43 | //type HGLOBAL = uintptr 44 | 45 | type WORD = uint16 46 | type DWORD = uint32 47 | 48 | type HREFTYPE = DWORD 49 | 50 | type DISPID = int32 51 | type MEMBERID = DISPID 52 | 53 | //type VARIANT_BOOL = int16 54 | 55 | type TOOLINFO struct { 56 | CbSize uint32 57 | UFlags uint32 58 | Hwnd HWND 59 | UId uintptr 60 | Rect RECT 61 | Hinst HINSTANCE 62 | LpszText *uint16 63 | LParam uintptr 64 | LpReserved unsafe.Pointer 65 | } 66 | 67 | const NULL = 0 68 | 69 | const ( 70 | DATA_E_FORMATETC = DV_E_FORMATETC 71 | ) 72 | 73 | //const DTN_FIRST = ^uint32(739) // -740 74 | //const DTN_FIRST2 = ^uint32(752) // -753 75 | 76 | // Notifications 77 | const ( 78 | // DTN_DATETIMECHANGE = DTN_FIRST2 - 6 79 | // DTN_USERSTRING = DTN_FIRST - 5 80 | // DTN_WMKEYDOWN = DTN_FIRST - 4 81 | // DTN_FORMAT = DTN_FIRST - 3 82 | // DTN_FORMATQUERY = DTN_FIRST - 2 83 | // DTN_DROPDOWN = DTN_FIRST2 - 1 84 | // DTN_CLOSEUP = DTN_FIRST2 85 | ) 86 | 87 | // WM_NOTITY messages 88 | const ( 89 | // NM_FIRST = 0 90 | // NM_OUTOFMEMORY = ^uint32(0) // NM_FIRST - 1 91 | // NM_CLICK = ^uint32(1) // NM_FIRST - 2 92 | // NM_DBLCLK = ^uint32(2) // NM_FIRST - 3 93 | // NM_RETURN = ^uint32(3) // NM_FIRST - 4 94 | // NM_RCLICK = ^uint32(4) // NM_FIRST - 5 95 | // NM_RDBLCLK = ^uint32(5) // NM_FIRST - 6 96 | // NM_SETFOCUS = ^uint32(6) // NM_FIRST - 7 97 | // NM_KILLFOCUS = ^uint32(7) // NM_FIRST - 8 98 | // NM_CUSTOMDRAW = ^uint32(11) // NM_FIRST - 12 99 | // NM_HOVER = ^uint32(12) // NM_FIRST - 13 100 | // NM_NCHITTEST = ^uint32(13) // NM_FIRST - 14 101 | // NM_KEYDOWN = ^uint32(14) // NM_FIRST - 15 102 | // NM_RELEASEDCAPTURE = ^uint32(15) // NM_FIRST - 16 103 | // NM_SETCURSOR = ^uint32(16) // NM_FIRST - 17 104 | // NM_CHAR = ^uint32(17) // NM_FIRST - 18 105 | // NM_TOOLTIPSCREATED = ^uint32(18) // NM_FIRST - 19 106 | // NM_LAST = ^uint32(98) // NM_FIRST - 99 107 | // TRBN_THUMBPOSCHANGING = 0xfffffa22 // TRBN_FIRST - 1 108 | ) 109 | 110 | // ListView notifications 111 | const ( 112 | // LVN_FIRST = ^uint32(99) // -100 113 | // 114 | // LVN_ITEMCHANGING = LVN_FIRST - 0 115 | // LVN_ITEMCHANGED = LVN_FIRST - 1 116 | // LVN_INSERTITEM = LVN_FIRST - 2 117 | // LVN_DELETEITEM = LVN_FIRST - 3 118 | // LVN_DELETEALLITEMS = LVN_FIRST - 4 119 | // LVN_BEGINLABELEDIT = LVN_FIRST - 75 120 | // LVN_ENDLABELEDIT = LVN_FIRST - 76 121 | // LVN_COLUMNCLICK = LVN_FIRST - 8 122 | // LVN_BEGINDRAG = LVN_FIRST - 9 123 | // LVN_BEGINRDRAG = LVN_FIRST - 11 124 | // LVN_ODCACHEHINT = LVN_FIRST - 13 125 | // LVN_ODFINDITEM = LVN_FIRST - 79 126 | // LVN_ITEMACTIVATE = LVN_FIRST - 14 127 | // LVN_ODSTATECHANGED = LVN_FIRST - 15 128 | // LVN_HOTTRACK = LVN_FIRST - 21 129 | // LVN_GETDISPINFO = LVN_FIRST - 77 130 | // LVN_SETDISPINFO = LVN_FIRST - 78 131 | // LVN_KEYDOWN = LVN_FIRST - 55 132 | // LVN_MARQUEEBEGIN = LVN_FIRST - 56 133 | // LVN_GETINFOTIP = LVN_FIRST - 58 134 | // LVN_INCREMENTALSEARCH = LVN_FIRST - 63 135 | // LVN_BEGINSCROLL = LVN_FIRST - 80 136 | // LVN_ENDSCROLL = LVN_FIRST - 81 137 | ) 138 | 139 | const ( 140 | // RBN_FIRST = 0xFFFFFCC1 141 | // RBN_HEIGHTCHANGE = RBN_FIRST - 0 142 | // RBN_GETOBJECT = RBN_FIRST - 1 143 | // RBN_LAYOUTCHANGED = RBN_FIRST - 2 144 | // RBN_AUTOSIZE = RBN_FIRST - 3 145 | // RBN_BEGINDRAG = RBN_FIRST - 4 146 | // RBN_ENDDRAG = RBN_FIRST - 5 147 | // RBN_DELETINGBAND = RBN_FIRST - 6 148 | // RBN_DELETEDBAND = RBN_FIRST - 7 149 | // RBN_CHILDSIZE = RBN_FIRST - 8 150 | // RBN_CHEVRONPUSHED = RBN_FIRST - 10 151 | // RBN_SPLITTERDRAG = RBN_FIRST - 11 152 | // RBN_MINMAX = RBN_FIRST - 21 153 | // RBN_AUTOBREAK = RBN_FIRST - 22 154 | ) 155 | 156 | const ( 157 | // WVR_REDRAW = WVR_HREDRAW | WVR_VREDRAW 158 | ) 159 | 160 | const ( 161 | // EP_EDITTEXT = 1 162 | // EP_CARET = 2 163 | // EP_BACKGROUND = 3 164 | // EP_PASSWORD = 4 165 | // EP_BACKGROUNDWITHBORDER = 5 166 | // EP_EDITBORDER_NOSCROLL = 6 167 | // EP_EDITBORDER_HSCROLL = 7 168 | // EP_EDITBORDER_VSCROLL = 8 169 | // EP_EDITBORDER_HVSCROLL = 9 170 | ) 171 | 172 | const ( 173 | // ETS_NORMAL = 1 174 | // ETS_HOT = 2 175 | // ETS_SELECTED = 3 176 | // ETS_DISABLED = 4 177 | // ETS_FOCUSED = 5 178 | // ETS_READONLY = 6 179 | // ETS_ASSIST = 7 180 | // ETS_CUEBANNER = 8 181 | ) 182 | 183 | // TrackBar (Slider) messages 184 | const ( 185 | TBM_GETPOS = WM_USER 186 | ) 187 | 188 | //const TCN_FIRST uint32 = 0xFFFFFDDA 189 | 190 | const ( 191 | // TCN_KEYDOWN = TCN_FIRST - 0 192 | // TCN_SELCHANGE = TCN_FIRST - 1 193 | // TCN_SELCHANGING = TCN_FIRST - 2 194 | // TCN_GETOBJECT = TCN_FIRST - 3 195 | // TCN_FOCUSCHANGE = TCN_FIRST - 4 196 | ) 197 | 198 | //const MENU_BARITEM = 8 199 | //const MBI_NORMAL = 1 200 | //const MBI_HOT = 2 201 | //const MBI_PUSHED = 3 202 | 203 | //const TRUE BOOL = 1 204 | //const FALSE BOOL = 0 205 | 206 | const ( 207 | CLR_NONE_U = ^uint32(-CLR_NONE - 1) 208 | CLR_DEFAULT_U = ^uint32(-CLR_DEFAULT - 1) 209 | ) 210 | 211 | // ToolBar notifications 212 | const ( 213 | // TBN_FIRST = 0xFFFFFD44 //-700 214 | // TBN_DROPDOWN = TBN_FIRST - 10 215 | // TBN_GETINFOTIP = TBN_FIRST - 19 216 | // TBN_BEGINADJUST = TBN_FIRST - 3 217 | // TBN_QUERYINSERT = TBN_FIRST - 6 218 | ) 219 | 220 | const ( 221 | // TTN_FIRST = ^uint32(519) 222 | // TTN_GETDISPINFO = TTN_FIRST - 10 223 | // TTN_SHOW = TTN_FIRST - 1 224 | // TTN_POP = TTN_FIRST - 2 225 | // TTN_LINKCLICK = TTN_FIRST - 3 226 | ) 227 | 228 | // TreeView notifications 229 | const ( 230 | // TVN_FIRST = ^uint32(399) 231 | // 232 | // TVN_SELCHANGING = TVN_FIRST - 50 233 | // TVN_SELCHANGED = TVN_FIRST - 51 234 | // TVN_GETDISPINFO = TVN_FIRST - 52 235 | // TVN_ITEMEXPANDING = TVN_FIRST - 54 236 | // TVN_ITEMEXPANDED = TVN_FIRST - 55 237 | // TVN_BEGINDRAG = TVN_FIRST - 56 238 | // TVN_BEGINRDRAG = TVN_FIRST - 57 239 | // TVN_DELETEITEM = TVN_FIRST - 58 240 | // TVN_BEGINLABELEDIT = TVN_FIRST - 59 241 | // TVN_ENDLABELEDIT = TVN_FIRST - 60 242 | // TVN_KEYDOWN = TVN_FIRST - 12 243 | // TVN_GETINFOTIP = TVN_FIRST - 14 244 | // TVN_SINGLEEXPAND = TVN_FIRST - 15 245 | // TVN_ITEMCHANGING = TVN_FIRST - 17 246 | // TVN_ITEMCHANGED = TVN_FIRST - 19 247 | // TVN_ASYNCDRAW = TVN_FIRST - 20 248 | // 249 | // NM_TVSTATEIMAGECHANGING = ^uint32(23) //NM_FIRST-24 250 | ) 251 | 252 | // SHGetStockIconInfo flags 253 | const ( 254 | // SHGSI_ICONLOCATION = 0 255 | // SHGSI_ICON = 0x000000100 256 | // SHGSI_SYSICONINDEX = 0x000004000 257 | // SHGSI_LINKOVERLAY = 0x000008000 258 | // SHGSI_SELECTED = 0x000010000 259 | // SHGSI_LARGEICON = 0x000000000 260 | // SHGSI_SMALLICON = 0x000000001 261 | // SHGSI_SHELLICONSIZE = 0x000000004 262 | ) 263 | 264 | // Button parts 265 | const ( 266 | // BP_PUSHBUTTON = 1 267 | // BP_RADIOBUTTON = 2 268 | // BP_CHECKBOX = 3 269 | // BP_GROUPBOX = 4 270 | // BP_USERBUTTON = 5 271 | // BP_COMMANDLINK = 6 272 | // BP_COMMANDLINKGLYPH = 7 273 | ) 274 | 275 | // CheckBox states 276 | const ( 277 | // CBS_UNCHECKEDNORMAL = 1 278 | // CBS_UNCHECKEDHOT = 2 279 | // CBS_UNCHECKEDPRESSED = 3 280 | // CBS_UNCHECKEDDISABLED = 4 281 | // CBS_CHECKEDNORMAL = 5 282 | // CBS_CHECKEDHOT = 6 283 | // CBS_CHECKEDPRESSED = 7 284 | // CBS_CHECKEDDISABLED = 8 285 | // CBS_MIXEDNORMAL = 9 286 | // CBS_MIXEDHOT = 10 287 | // CBS_MIXEDPRESSED = 11 288 | // CBS_MIXEDDISABLED = 12 289 | // CBS_IMPLICITNORMAL = 13 290 | // CBS_IMPLICITHOT = 14 291 | // CBS_IMPLICITPRESSED = 15 292 | // CBS_IMPLICITDISABLED = 16 293 | // CBS_EXCLUDEDNORMAL = 17 294 | // CBS_EXCLUDEDHOT = 18 295 | // CBS_EXCLUDEDPRESSED = 19 296 | // CBS_EXCLUDEDDISABLED = 20 297 | ) 298 | 299 | // Month Calendar consts 300 | const ( 301 | // MCN_FIRST = ^uint32(745) // -746 302 | // MCN_SELECT = MCN_FIRST 303 | ) 304 | 305 | const ( 306 | //SP_GRIPPER = 3 307 | LOCALE_INVARIANT = 127 308 | LOCALE_USER_DEFAULT = 1024 309 | LOCALE_SYSTEM_DEFAULT = 2048 310 | ) 311 | 312 | const ( 313 | // VARIANT_TRUE VARIANT_BOOL = -1 314 | // VARIANT_FALSE VARIANT_BOOL = 0 315 | ) 316 | 317 | const VK_WHEEL_DOWN VIRTUAL_KEY = 0x9E 318 | const VK_WHEEL_UP VIRTUAL_KEY = 0x9F 319 | const VK_WHEEL_LEFT VIRTUAL_KEY = 0x9C 320 | const VK_WHEEL_RIGHT VIRTUAL_KEY = 0x9D 321 | 322 | var ( 323 | IID_NULL syscall.GUID 324 | ) 325 | 326 | func RGB(r, g, b byte) COLORREF { 327 | return COLORREF(r) | (COLORREF(g) << 8) | (COLORREF(b) << 16) 328 | } 329 | 330 | func MAKEINTRESOURCE(id uint16) *uint16 { 331 | return (*uint16)(unsafe.Pointer(uintptr(id))) 332 | } 333 | 334 | func MAKEINTRESOURCEA(id uint16) *byte { 335 | return (*byte)(unsafe.Pointer(uintptr(id))) 336 | } 337 | 338 | func MAKELONG(lo, hi uint16) uint32 { 339 | return uint32(uint32(lo) | ((uint32(hi)) << 16)) 340 | } 341 | 342 | func GET_X_LPARAM(dw DWORD) int32 { 343 | return int32(int16(LOWORD(dw))) 344 | } 345 | 346 | func GET_Y_LPARAM(dw DWORD) int32 { 347 | return int32(int16(HIWORD(dw))) 348 | } 349 | 350 | func LOBYTE(w uint16) byte { 351 | return byte(w) 352 | } 353 | 354 | func HIBYTE(w uint16) byte { 355 | return byte(w >> 8 & 0xff) 356 | } 357 | 358 | func MAKEWORD(lo, hi byte) uint16 { 359 | return uint16(uint16(lo) | ((uint16(hi)) << 8)) 360 | } 361 | 362 | func LOWORD(dw uint32) uint16 { 363 | return uint16(dw) 364 | } 365 | 366 | func HIWORD(dw uint32) uint16 { 367 | return uint16(dw >> 16 & 0xffff) 368 | } 369 | 370 | func SUCCEEDED(hr HRESULT) bool { 371 | return hr >= 0 372 | } 373 | 374 | func FAILED(hr HRESULT) bool { 375 | return hr < 0 376 | } 377 | 378 | var ( 379 | copyMemory *windows.LazyProc 380 | imageList_AddIcon *windows.LazyProc 381 | ) 382 | 383 | func init() { 384 | copyMemory = libKernel32.NewProc("RtlMoveMemory") 385 | imageList_AddIcon = libComctl32.NewProc("ImageList_AddIcon") 386 | 387 | // 388 | LazyAddr(&pTlsGetValue, libKernel32, "TlsGetValue") 389 | } 390 | 391 | func CopyMemory(Destination unsafe.Pointer, Source unsafe.Pointer, Length uint32) WIN32_ERROR { 392 | _, _, err := syscall.SyscallN(copyMemory.Addr(), 393 | uintptr(Destination), 394 | uintptr(Source), 395 | uintptr(Length)) 396 | return WIN32_ERROR(err) 397 | } 398 | 399 | func ImageList_AddIcon(himl HIMAGELIST, hicon HICON) (int32, WIN32_ERROR) { 400 | ret, _, err := syscall.SyscallN(imageList_AddIcon.Addr(), himl, hicon) 401 | return int32(ret), WIN32_ERROR(err) 402 | } 403 | 404 | type IUnknownObject interface { 405 | GetIUnknown() *IUnknown 406 | } 407 | 408 | func (this *IUnknown) GetIUnknown() *IUnknown { 409 | return this 410 | } 411 | 412 | type IDispatchObject interface { 413 | GetIDispatch_() *IDispatch 414 | } 415 | 416 | func (this *IDispatch) GetIDispatch_() *IDispatch { 417 | return this 418 | } 419 | 420 | func TlsGetValueAlt(dwTlsIndex uint32) uintptr { 421 | ret, _, _ := syscall.SyscallN(pTlsGetValue, uintptr(dwTlsIndex)) 422 | return ret 423 | } 424 | -------------------------------------------------------------------------------- /win32/Security.AppLocker.go: -------------------------------------------------------------------------------- 1 | package win32 2 | 3 | import ( 4 | "syscall" 5 | "unsafe" 6 | ) 7 | 8 | const ( 9 | SAFER_SCOPEID_MACHINE uint32 = 0x1 10 | SAFER_SCOPEID_USER uint32 = 0x2 11 | SAFER_LEVELID_FULLYTRUSTED uint32 = 0x40000 12 | SAFER_LEVELID_NORMALUSER uint32 = 0x20000 13 | SAFER_LEVELID_CONSTRAINED uint32 = 0x10000 14 | SAFER_LEVELID_UNTRUSTED uint32 = 0x1000 15 | SAFER_LEVELID_DISALLOWED uint32 = 0x0 16 | SAFER_LEVEL_OPEN uint32 = 0x1 17 | SAFER_MAX_FRIENDLYNAME_SIZE uint32 = 0x100 18 | SAFER_MAX_DESCRIPTION_SIZE uint32 = 0x100 19 | SAFER_MAX_HASH_SIZE uint32 = 0x40 20 | SAFER_CRITERIA_IMAGEPATH uint32 = 0x1 21 | SAFER_CRITERIA_NOSIGNEDHASH uint32 = 0x2 22 | SAFER_CRITERIA_IMAGEHASH uint32 = 0x4 23 | SAFER_CRITERIA_AUTHENTICODE uint32 = 0x8 24 | SAFER_CRITERIA_URLZONE uint32 = 0x10 25 | SAFER_CRITERIA_APPX_PACKAGE uint32 = 0x20 26 | SAFER_CRITERIA_IMAGEPATH_NT uint32 = 0x1000 27 | SAFER_POLICY_JOBID_MASK uint32 = 0xff000000 28 | SAFER_POLICY_JOBID_CONSTRAINED uint32 = 0x4000000 29 | SAFER_POLICY_JOBID_UNTRUSTED uint32 = 0x3000000 30 | SAFER_POLICY_ONLY_EXES uint32 = 0x10000 31 | SAFER_POLICY_SANDBOX_INERT uint32 = 0x20000 32 | SAFER_POLICY_HASH_DUPLICATE uint32 = 0x40000 33 | SAFER_POLICY_ONLY_AUDIT uint32 = 0x1000 34 | SAFER_POLICY_BLOCK_CLIENT_UI uint32 = 0x2000 35 | SAFER_POLICY_UIFLAGS_MASK uint32 = 0xff 36 | SAFER_POLICY_UIFLAGS_INFORMATION_PROMPT uint32 = 0x1 37 | SAFER_POLICY_UIFLAGS_OPTION_PROMPT uint32 = 0x2 38 | SAFER_POLICY_UIFLAGS_HIDDEN uint32 = 0x4 39 | SRP_POLICY_EXE string = "EXE" 40 | SRP_POLICY_DLL string = "DLL" 41 | SRP_POLICY_MSI string = "MSI" 42 | SRP_POLICY_SCRIPT string = "SCRIPT" 43 | SRP_POLICY_SHELL string = "SHELL" 44 | SRP_POLICY_NOV2 string = "IGNORESRPV2" 45 | SRP_POLICY_APPX string = "APPX" 46 | SRP_POLICY_WLDPMSI string = "WLDPMSI" 47 | SRP_POLICY_WLDPSCRIPT string = "WLDPSCRIPT" 48 | SRP_POLICY_WLDPCONFIGCI string = "WLDPCONFIGCI" 49 | SRP_POLICY_MANAGEDINSTALLER string = "MANAGEDINSTALLER" 50 | ) 51 | 52 | // enums 53 | 54 | // enum 55 | // flags 56 | type SAFER_COMPUTE_TOKEN_FROM_LEVEL_FLAGS uint32 57 | 58 | const ( 59 | SAFER_TOKEN_NULL_IF_EQUAL SAFER_COMPUTE_TOKEN_FROM_LEVEL_FLAGS = 1 60 | SAFER_TOKEN_COMPARE_ONLY SAFER_COMPUTE_TOKEN_FROM_LEVEL_FLAGS = 2 61 | SAFER_TOKEN_MAKE_INERT SAFER_COMPUTE_TOKEN_FROM_LEVEL_FLAGS = 4 62 | SAFER_TOKEN_WANT_FLAGS SAFER_COMPUTE_TOKEN_FROM_LEVEL_FLAGS = 8 63 | ) 64 | 65 | // enum 66 | type SAFER_POLICY_INFO_CLASS int32 67 | 68 | const ( 69 | SaferPolicyLevelList SAFER_POLICY_INFO_CLASS = 1 70 | SaferPolicyEnableTransparentEnforcement SAFER_POLICY_INFO_CLASS = 2 71 | SaferPolicyDefaultLevel SAFER_POLICY_INFO_CLASS = 3 72 | SaferPolicyEvaluateUserScope SAFER_POLICY_INFO_CLASS = 4 73 | SaferPolicyScopeFlags SAFER_POLICY_INFO_CLASS = 5 74 | SaferPolicyDefaultLevelFlags SAFER_POLICY_INFO_CLASS = 6 75 | SaferPolicyAuthenticodeEnabled SAFER_POLICY_INFO_CLASS = 7 76 | ) 77 | 78 | // enum 79 | type SAFER_OBJECT_INFO_CLASS int32 80 | 81 | const ( 82 | SaferObjectLevelId SAFER_OBJECT_INFO_CLASS = 1 83 | SaferObjectScopeId SAFER_OBJECT_INFO_CLASS = 2 84 | SaferObjectFriendlyName SAFER_OBJECT_INFO_CLASS = 3 85 | SaferObjectDescription SAFER_OBJECT_INFO_CLASS = 4 86 | SaferObjectBuiltin SAFER_OBJECT_INFO_CLASS = 5 87 | SaferObjectDisallowed SAFER_OBJECT_INFO_CLASS = 6 88 | SaferObjectDisableMaxPrivilege SAFER_OBJECT_INFO_CLASS = 7 89 | SaferObjectInvertDeletedPrivileges SAFER_OBJECT_INFO_CLASS = 8 90 | SaferObjectDeletedPrivileges SAFER_OBJECT_INFO_CLASS = 9 91 | SaferObjectDefaultOwner SAFER_OBJECT_INFO_CLASS = 10 92 | SaferObjectSidsToDisable SAFER_OBJECT_INFO_CLASS = 11 93 | SaferObjectRestrictedSidsInverted SAFER_OBJECT_INFO_CLASS = 12 94 | SaferObjectRestrictedSidsAdded SAFER_OBJECT_INFO_CLASS = 13 95 | SaferObjectAllIdentificationGuids SAFER_OBJECT_INFO_CLASS = 14 96 | SaferObjectSingleIdentification SAFER_OBJECT_INFO_CLASS = 15 97 | SaferObjectExtendedError SAFER_OBJECT_INFO_CLASS = 16 98 | ) 99 | 100 | // enum 101 | type SAFER_IDENTIFICATION_TYPES int32 102 | 103 | const ( 104 | SaferIdentityDefault SAFER_IDENTIFICATION_TYPES = 0 105 | SaferIdentityTypeImageName SAFER_IDENTIFICATION_TYPES = 1 106 | SaferIdentityTypeImageHash SAFER_IDENTIFICATION_TYPES = 2 107 | SaferIdentityTypeUrlZone SAFER_IDENTIFICATION_TYPES = 3 108 | SaferIdentityTypeCertificate SAFER_IDENTIFICATION_TYPES = 4 109 | ) 110 | 111 | // structs 112 | 113 | type SAFER_CODE_PROPERTIES_V1 struct { 114 | CbSize uint32 115 | DwCheckFlags uint32 116 | ImagePath PWSTR 117 | HImageFileHandle HANDLE 118 | UrlZoneId uint32 119 | ImageHash [64]byte 120 | DwImageHashSize uint32 121 | ImageSize int64 122 | HashAlgorithm ALG_ID 123 | PByteBlock *byte 124 | HWndParent HWND 125 | DwWVTUIChoice uint32 126 | } 127 | 128 | type SAFER_CODE_PROPERTIES_V2 struct { 129 | CbSize uint32 130 | DwCheckFlags uint32 131 | ImagePath PWSTR 132 | HImageFileHandle HANDLE 133 | UrlZoneId uint32 134 | ImageHash [64]byte 135 | DwImageHashSize uint32 136 | ImageSize int64 137 | HashAlgorithm ALG_ID 138 | PByteBlock *byte 139 | HWndParent HWND 140 | DwWVTUIChoice uint32 141 | PackageMoniker PWSTR 142 | PackagePublisher PWSTR 143 | PackageName PWSTR 144 | PackageVersion uint64 145 | PackageIsFramework BOOL 146 | } 147 | 148 | type SAFER_IDENTIFICATION_HEADER struct { 149 | DwIdentificationType SAFER_IDENTIFICATION_TYPES 150 | CbStructSize uint32 151 | IdentificationGuid syscall.GUID 152 | LastModified FILETIME 153 | } 154 | 155 | type SAFER_PATHNAME_IDENTIFICATION struct { 156 | Header SAFER_IDENTIFICATION_HEADER 157 | Description [256]uint16 158 | ImageName PWSTR 159 | DwSaferFlags uint32 160 | } 161 | 162 | type SAFER_HASH_IDENTIFICATION struct { 163 | Header SAFER_IDENTIFICATION_HEADER 164 | Description [256]uint16 165 | FriendlyName [256]uint16 166 | HashSize uint32 167 | ImageHash [64]byte 168 | HashAlgorithm ALG_ID 169 | ImageSize int64 170 | DwSaferFlags uint32 171 | } 172 | 173 | type SAFER_HASH_IDENTIFICATION2 struct { 174 | HashIdentification SAFER_HASH_IDENTIFICATION 175 | HashSize uint32 176 | ImageHash [64]byte 177 | HashAlgorithm ALG_ID 178 | } 179 | 180 | type SAFER_URLZONE_IDENTIFICATION struct { 181 | Header SAFER_IDENTIFICATION_HEADER 182 | UrlZoneId uint32 183 | DwSaferFlags uint32 184 | } 185 | 186 | var ( 187 | pSaferGetPolicyInformation uintptr 188 | pSaferSetPolicyInformation uintptr 189 | pSaferCreateLevel uintptr 190 | pSaferCloseLevel uintptr 191 | pSaferIdentifyLevel uintptr 192 | pSaferComputeTokenFromLevel uintptr 193 | pSaferGetLevelInformation uintptr 194 | pSaferSetLevelInformation uintptr 195 | pSaferRecordEventLogEntry uintptr 196 | pSaferiIsExecutableFileType uintptr 197 | ) 198 | 199 | func SaferGetPolicyInformation(dwScopeId uint32, SaferPolicyInfoClass SAFER_POLICY_INFO_CLASS, InfoBufferSize uint32, InfoBuffer unsafe.Pointer, InfoBufferRetSize *uint32, lpReserved unsafe.Pointer) (BOOL, WIN32_ERROR) { 200 | addr := LazyAddr(&pSaferGetPolicyInformation, libAdvapi32, "SaferGetPolicyInformation") 201 | ret, _, err := syscall.SyscallN(addr, uintptr(dwScopeId), uintptr(SaferPolicyInfoClass), uintptr(InfoBufferSize), uintptr(InfoBuffer), uintptr(unsafe.Pointer(InfoBufferRetSize)), uintptr(lpReserved)) 202 | return BOOL(ret), WIN32_ERROR(err) 203 | } 204 | 205 | func SaferSetPolicyInformation(dwScopeId uint32, SaferPolicyInfoClass SAFER_POLICY_INFO_CLASS, InfoBufferSize uint32, InfoBuffer unsafe.Pointer, lpReserved unsafe.Pointer) (BOOL, WIN32_ERROR) { 206 | addr := LazyAddr(&pSaferSetPolicyInformation, libAdvapi32, "SaferSetPolicyInformation") 207 | ret, _, err := syscall.SyscallN(addr, uintptr(dwScopeId), uintptr(SaferPolicyInfoClass), uintptr(InfoBufferSize), uintptr(InfoBuffer), uintptr(lpReserved)) 208 | return BOOL(ret), WIN32_ERROR(err) 209 | } 210 | 211 | func SaferCreateLevel(dwScopeId uint32, dwLevelId uint32, OpenFlags uint32, pLevelHandle *SAFER_LEVEL_HANDLE, lpReserved unsafe.Pointer) (BOOL, WIN32_ERROR) { 212 | addr := LazyAddr(&pSaferCreateLevel, libAdvapi32, "SaferCreateLevel") 213 | ret, _, err := syscall.SyscallN(addr, uintptr(dwScopeId), uintptr(dwLevelId), uintptr(OpenFlags), uintptr(unsafe.Pointer(pLevelHandle)), uintptr(lpReserved)) 214 | return BOOL(ret), WIN32_ERROR(err) 215 | } 216 | 217 | func SaferCloseLevel(hLevelHandle SAFER_LEVEL_HANDLE) (BOOL, WIN32_ERROR) { 218 | addr := LazyAddr(&pSaferCloseLevel, libAdvapi32, "SaferCloseLevel") 219 | ret, _, err := syscall.SyscallN(addr, hLevelHandle) 220 | return BOOL(ret), WIN32_ERROR(err) 221 | } 222 | 223 | func SaferIdentifyLevel(dwNumProperties uint32, pCodeProperties *SAFER_CODE_PROPERTIES_V2, pLevelHandle *SAFER_LEVEL_HANDLE, lpReserved unsafe.Pointer) (BOOL, WIN32_ERROR) { 224 | addr := LazyAddr(&pSaferIdentifyLevel, libAdvapi32, "SaferIdentifyLevel") 225 | ret, _, err := syscall.SyscallN(addr, uintptr(dwNumProperties), uintptr(unsafe.Pointer(pCodeProperties)), uintptr(unsafe.Pointer(pLevelHandle)), uintptr(lpReserved)) 226 | return BOOL(ret), WIN32_ERROR(err) 227 | } 228 | 229 | func SaferComputeTokenFromLevel(LevelHandle SAFER_LEVEL_HANDLE, InAccessToken HANDLE, OutAccessToken *HANDLE, dwFlags SAFER_COMPUTE_TOKEN_FROM_LEVEL_FLAGS, lpReserved unsafe.Pointer) (BOOL, WIN32_ERROR) { 230 | addr := LazyAddr(&pSaferComputeTokenFromLevel, libAdvapi32, "SaferComputeTokenFromLevel") 231 | ret, _, err := syscall.SyscallN(addr, LevelHandle, InAccessToken, uintptr(unsafe.Pointer(OutAccessToken)), uintptr(dwFlags), uintptr(lpReserved)) 232 | return BOOL(ret), WIN32_ERROR(err) 233 | } 234 | 235 | func SaferGetLevelInformation(LevelHandle SAFER_LEVEL_HANDLE, dwInfoType SAFER_OBJECT_INFO_CLASS, lpQueryBuffer unsafe.Pointer, dwInBufferSize uint32, lpdwOutBufferSize *uint32) (BOOL, WIN32_ERROR) { 236 | addr := LazyAddr(&pSaferGetLevelInformation, libAdvapi32, "SaferGetLevelInformation") 237 | ret, _, err := syscall.SyscallN(addr, LevelHandle, uintptr(dwInfoType), uintptr(lpQueryBuffer), uintptr(dwInBufferSize), uintptr(unsafe.Pointer(lpdwOutBufferSize))) 238 | return BOOL(ret), WIN32_ERROR(err) 239 | } 240 | 241 | func SaferSetLevelInformation(LevelHandle SAFER_LEVEL_HANDLE, dwInfoType SAFER_OBJECT_INFO_CLASS, lpQueryBuffer unsafe.Pointer, dwInBufferSize uint32) (BOOL, WIN32_ERROR) { 242 | addr := LazyAddr(&pSaferSetLevelInformation, libAdvapi32, "SaferSetLevelInformation") 243 | ret, _, err := syscall.SyscallN(addr, LevelHandle, uintptr(dwInfoType), uintptr(lpQueryBuffer), uintptr(dwInBufferSize)) 244 | return BOOL(ret), WIN32_ERROR(err) 245 | } 246 | 247 | func SaferRecordEventLogEntry(hLevel SAFER_LEVEL_HANDLE, szTargetPath PWSTR, lpReserved unsafe.Pointer) (BOOL, WIN32_ERROR) { 248 | addr := LazyAddr(&pSaferRecordEventLogEntry, libAdvapi32, "SaferRecordEventLogEntry") 249 | ret, _, err := syscall.SyscallN(addr, hLevel, uintptr(unsafe.Pointer(szTargetPath)), uintptr(lpReserved)) 250 | return BOOL(ret), WIN32_ERROR(err) 251 | } 252 | 253 | func SaferiIsExecutableFileType(szFullPathname PWSTR, bFromShellExecute BOOLEAN) BOOL { 254 | addr := LazyAddr(&pSaferiIsExecutableFileType, libAdvapi32, "SaferiIsExecutableFileType") 255 | ret, _, _ := syscall.SyscallN(addr, uintptr(unsafe.Pointer(szFullPathname)), uintptr(bFromShellExecute)) 256 | return BOOL(ret) 257 | } 258 | -------------------------------------------------------------------------------- /win32/System.Shutdown.go: -------------------------------------------------------------------------------- 1 | package win32 2 | 3 | import ( 4 | "syscall" 5 | "unsafe" 6 | ) 7 | 8 | const ( 9 | MAX_REASON_NAME_LEN uint32 = 0x40 10 | MAX_REASON_DESC_LEN uint32 = 0x100 11 | MAX_REASON_BUGID_LEN uint32 = 0x20 12 | MAX_REASON_COMMENT_LEN uint32 = 0x200 13 | SHUTDOWN_TYPE_LEN uint32 = 0x20 14 | POLICY_SHOWREASONUI_NEVER uint32 = 0x0 15 | POLICY_SHOWREASONUI_ALWAYS uint32 = 0x1 16 | POLICY_SHOWREASONUI_WORKSTATIONONLY uint32 = 0x2 17 | POLICY_SHOWREASONUI_SERVERONLY uint32 = 0x3 18 | SNAPSHOT_POLICY_NEVER uint32 = 0x0 19 | SNAPSHOT_POLICY_ALWAYS uint32 = 0x1 20 | SNAPSHOT_POLICY_UNPLANNED uint32 = 0x2 21 | MAX_NUM_REASONS uint32 = 0x100 22 | ) 23 | 24 | // enums 25 | 26 | // enum 27 | // flags 28 | type SHUTDOWN_REASON uint32 29 | 30 | const ( 31 | SHTDN_REASON_NONE SHUTDOWN_REASON = 0 32 | SHTDN_REASON_FLAG_COMMENT_REQUIRED SHUTDOWN_REASON = 16777216 33 | SHTDN_REASON_FLAG_DIRTY_PROBLEM_ID_REQUIRED SHUTDOWN_REASON = 33554432 34 | SHTDN_REASON_FLAG_CLEAN_UI SHUTDOWN_REASON = 67108864 35 | SHTDN_REASON_FLAG_DIRTY_UI SHUTDOWN_REASON = 134217728 36 | SHTDN_REASON_FLAG_MOBILE_UI_RESERVED SHUTDOWN_REASON = 268435456 37 | SHTDN_REASON_FLAG_USER_DEFINED SHUTDOWN_REASON = 1073741824 38 | SHTDN_REASON_FLAG_PLANNED SHUTDOWN_REASON = 2147483648 39 | SHTDN_REASON_MAJOR_OTHER SHUTDOWN_REASON = 0 40 | SHTDN_REASON_MAJOR_NONE SHUTDOWN_REASON = 0 41 | SHTDN_REASON_MAJOR_HARDWARE SHUTDOWN_REASON = 65536 42 | SHTDN_REASON_MAJOR_OPERATINGSYSTEM SHUTDOWN_REASON = 131072 43 | SHTDN_REASON_MAJOR_SOFTWARE SHUTDOWN_REASON = 196608 44 | SHTDN_REASON_MAJOR_APPLICATION SHUTDOWN_REASON = 262144 45 | SHTDN_REASON_MAJOR_SYSTEM SHUTDOWN_REASON = 327680 46 | SHTDN_REASON_MAJOR_POWER SHUTDOWN_REASON = 393216 47 | SHTDN_REASON_MAJOR_LEGACY_API SHUTDOWN_REASON = 458752 48 | SHTDN_REASON_MINOR_OTHER SHUTDOWN_REASON = 0 49 | SHTDN_REASON_MINOR_NONE SHUTDOWN_REASON = 255 50 | SHTDN_REASON_MINOR_MAINTENANCE SHUTDOWN_REASON = 1 51 | SHTDN_REASON_MINOR_INSTALLATION SHUTDOWN_REASON = 2 52 | SHTDN_REASON_MINOR_UPGRADE SHUTDOWN_REASON = 3 53 | SHTDN_REASON_MINOR_RECONFIG SHUTDOWN_REASON = 4 54 | SHTDN_REASON_MINOR_HUNG SHUTDOWN_REASON = 5 55 | SHTDN_REASON_MINOR_UNSTABLE SHUTDOWN_REASON = 6 56 | SHTDN_REASON_MINOR_DISK SHUTDOWN_REASON = 7 57 | SHTDN_REASON_MINOR_PROCESSOR SHUTDOWN_REASON = 8 58 | SHTDN_REASON_MINOR_NETWORKCARD SHUTDOWN_REASON = 9 59 | SHTDN_REASON_MINOR_POWER_SUPPLY SHUTDOWN_REASON = 10 60 | SHTDN_REASON_MINOR_CORDUNPLUGGED SHUTDOWN_REASON = 11 61 | SHTDN_REASON_MINOR_ENVIRONMENT SHUTDOWN_REASON = 12 62 | SHTDN_REASON_MINOR_HARDWARE_DRIVER SHUTDOWN_REASON = 13 63 | SHTDN_REASON_MINOR_OTHERDRIVER SHUTDOWN_REASON = 14 64 | SHTDN_REASON_MINOR_BLUESCREEN SHUTDOWN_REASON = 15 65 | SHTDN_REASON_MINOR_SERVICEPACK SHUTDOWN_REASON = 16 66 | SHTDN_REASON_MINOR_HOTFIX SHUTDOWN_REASON = 17 67 | SHTDN_REASON_MINOR_SECURITYFIX SHUTDOWN_REASON = 18 68 | SHTDN_REASON_MINOR_SECURITY SHUTDOWN_REASON = 19 69 | SHTDN_REASON_MINOR_NETWORK_CONNECTIVITY SHUTDOWN_REASON = 20 70 | SHTDN_REASON_MINOR_WMI SHUTDOWN_REASON = 21 71 | SHTDN_REASON_MINOR_SERVICEPACK_UNINSTALL SHUTDOWN_REASON = 22 72 | SHTDN_REASON_MINOR_HOTFIX_UNINSTALL SHUTDOWN_REASON = 23 73 | SHTDN_REASON_MINOR_SECURITYFIX_UNINSTALL SHUTDOWN_REASON = 24 74 | SHTDN_REASON_MINOR_MMC SHUTDOWN_REASON = 25 75 | SHTDN_REASON_MINOR_SYSTEMRESTORE SHUTDOWN_REASON = 26 76 | SHTDN_REASON_MINOR_TERMSRV SHUTDOWN_REASON = 32 77 | SHTDN_REASON_MINOR_DC_PROMOTION SHUTDOWN_REASON = 33 78 | SHTDN_REASON_MINOR_DC_DEMOTION SHUTDOWN_REASON = 34 79 | SHTDN_REASON_UNKNOWN SHUTDOWN_REASON = 255 80 | SHTDN_REASON_LEGACY_API SHUTDOWN_REASON = 2147942400 81 | SHTDN_REASON_VALID_BIT_MASK SHUTDOWN_REASON = 3238002687 82 | ) 83 | 84 | // enum 85 | // flags 86 | type SHUTDOWN_FLAGS uint32 87 | 88 | const ( 89 | SHUTDOWN_FORCE_OTHERS SHUTDOWN_FLAGS = 1 90 | SHUTDOWN_FORCE_SELF SHUTDOWN_FLAGS = 2 91 | SHUTDOWN_RESTART SHUTDOWN_FLAGS = 4 92 | SHUTDOWN_POWEROFF SHUTDOWN_FLAGS = 8 93 | SHUTDOWN_NOREBOOT SHUTDOWN_FLAGS = 16 94 | SHUTDOWN_GRACE_OVERRIDE SHUTDOWN_FLAGS = 32 95 | SHUTDOWN_INSTALL_UPDATES SHUTDOWN_FLAGS = 64 96 | SHUTDOWN_RESTARTAPPS SHUTDOWN_FLAGS = 128 97 | SHUTDOWN_SKIP_SVC_PRESHUTDOWN SHUTDOWN_FLAGS = 256 98 | SHUTDOWN_HYBRID SHUTDOWN_FLAGS = 512 99 | SHUTDOWN_RESTART_BOOTOPTIONS SHUTDOWN_FLAGS = 1024 100 | SHUTDOWN_SOFT_REBOOT SHUTDOWN_FLAGS = 2048 101 | SHUTDOWN_MOBILE_UI SHUTDOWN_FLAGS = 4096 102 | SHUTDOWN_ARSO SHUTDOWN_FLAGS = 8192 103 | SHUTDOWN_CHECK_SAFE_FOR_SERVER SHUTDOWN_FLAGS = 16384 104 | SHUTDOWN_VAIL_CONTAINER SHUTDOWN_FLAGS = 32768 105 | SHUTDOWN_SYSTEM_INITIATED SHUTDOWN_FLAGS = 65536 106 | ) 107 | 108 | // enum 109 | // flags 110 | type EXIT_WINDOWS_FLAGS uint32 111 | 112 | const ( 113 | EWX_LOGOFF EXIT_WINDOWS_FLAGS = 0 114 | EWX_SHUTDOWN EXIT_WINDOWS_FLAGS = 1 115 | EWX_REBOOT EXIT_WINDOWS_FLAGS = 2 116 | EWX_FORCE EXIT_WINDOWS_FLAGS = 4 117 | EWX_POWEROFF EXIT_WINDOWS_FLAGS = 8 118 | EWX_FORCEIFHUNG EXIT_WINDOWS_FLAGS = 16 119 | EWX_QUICKRESOLVE EXIT_WINDOWS_FLAGS = 32 120 | EWX_RESTARTAPPS EXIT_WINDOWS_FLAGS = 64 121 | EWX_HYBRID_SHUTDOWN EXIT_WINDOWS_FLAGS = 4194304 122 | EWX_BOOTOPTIONS EXIT_WINDOWS_FLAGS = 16777216 123 | EWX_ARSO EXIT_WINDOWS_FLAGS = 67108864 124 | EWX_CHECK_SAFE_FOR_SERVER EXIT_WINDOWS_FLAGS = 134217728 125 | EWX_SYSTEM_INITIATED EXIT_WINDOWS_FLAGS = 268435456 126 | ) 127 | 128 | var ( 129 | pInitiateSystemShutdownA uintptr 130 | pInitiateSystemShutdownW uintptr 131 | pAbortSystemShutdownA uintptr 132 | pAbortSystemShutdownW uintptr 133 | pInitiateSystemShutdownExA uintptr 134 | pInitiateSystemShutdownExW uintptr 135 | pInitiateShutdownA uintptr 136 | pInitiateShutdownW uintptr 137 | pCheckForHiberboot uintptr 138 | pExitWindowsEx uintptr 139 | pLockWorkStation uintptr 140 | pShutdownBlockReasonCreate uintptr 141 | pShutdownBlockReasonQuery uintptr 142 | pShutdownBlockReasonDestroy uintptr 143 | ) 144 | 145 | func InitiateSystemShutdownA(lpMachineName PSTR, lpMessage PSTR, dwTimeout uint32, bForceAppsClosed BOOL, bRebootAfterShutdown BOOL) (BOOL, WIN32_ERROR) { 146 | addr := LazyAddr(&pInitiateSystemShutdownA, libAdvapi32, "InitiateSystemShutdownA") 147 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpMachineName)), uintptr(unsafe.Pointer(lpMessage)), uintptr(dwTimeout), uintptr(bForceAppsClosed), uintptr(bRebootAfterShutdown)) 148 | return BOOL(ret), WIN32_ERROR(err) 149 | } 150 | 151 | var InitiateSystemShutdown = InitiateSystemShutdownW 152 | 153 | func InitiateSystemShutdownW(lpMachineName PWSTR, lpMessage PWSTR, dwTimeout uint32, bForceAppsClosed BOOL, bRebootAfterShutdown BOOL) (BOOL, WIN32_ERROR) { 154 | addr := LazyAddr(&pInitiateSystemShutdownW, libAdvapi32, "InitiateSystemShutdownW") 155 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpMachineName)), uintptr(unsafe.Pointer(lpMessage)), uintptr(dwTimeout), uintptr(bForceAppsClosed), uintptr(bRebootAfterShutdown)) 156 | return BOOL(ret), WIN32_ERROR(err) 157 | } 158 | 159 | func AbortSystemShutdownA(lpMachineName PSTR) (BOOL, WIN32_ERROR) { 160 | addr := LazyAddr(&pAbortSystemShutdownA, libAdvapi32, "AbortSystemShutdownA") 161 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpMachineName))) 162 | return BOOL(ret), WIN32_ERROR(err) 163 | } 164 | 165 | var AbortSystemShutdown = AbortSystemShutdownW 166 | 167 | func AbortSystemShutdownW(lpMachineName PWSTR) (BOOL, WIN32_ERROR) { 168 | addr := LazyAddr(&pAbortSystemShutdownW, libAdvapi32, "AbortSystemShutdownW") 169 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpMachineName))) 170 | return BOOL(ret), WIN32_ERROR(err) 171 | } 172 | 173 | func InitiateSystemShutdownExA(lpMachineName PSTR, lpMessage PSTR, dwTimeout uint32, bForceAppsClosed BOOL, bRebootAfterShutdown BOOL, dwReason SHUTDOWN_REASON) (BOOL, WIN32_ERROR) { 174 | addr := LazyAddr(&pInitiateSystemShutdownExA, libAdvapi32, "InitiateSystemShutdownExA") 175 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpMachineName)), uintptr(unsafe.Pointer(lpMessage)), uintptr(dwTimeout), uintptr(bForceAppsClosed), uintptr(bRebootAfterShutdown), uintptr(dwReason)) 176 | return BOOL(ret), WIN32_ERROR(err) 177 | } 178 | 179 | var InitiateSystemShutdownEx = InitiateSystemShutdownExW 180 | 181 | func InitiateSystemShutdownExW(lpMachineName PWSTR, lpMessage PWSTR, dwTimeout uint32, bForceAppsClosed BOOL, bRebootAfterShutdown BOOL, dwReason SHUTDOWN_REASON) (BOOL, WIN32_ERROR) { 182 | addr := LazyAddr(&pInitiateSystemShutdownExW, libAdvapi32, "InitiateSystemShutdownExW") 183 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpMachineName)), uintptr(unsafe.Pointer(lpMessage)), uintptr(dwTimeout), uintptr(bForceAppsClosed), uintptr(bRebootAfterShutdown), uintptr(dwReason)) 184 | return BOOL(ret), WIN32_ERROR(err) 185 | } 186 | 187 | func InitiateShutdownA(lpMachineName PSTR, lpMessage PSTR, dwGracePeriod uint32, dwShutdownFlags SHUTDOWN_FLAGS, dwReason SHUTDOWN_REASON) uint32 { 188 | addr := LazyAddr(&pInitiateShutdownA, libAdvapi32, "InitiateShutdownA") 189 | ret, _, _ := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpMachineName)), uintptr(unsafe.Pointer(lpMessage)), uintptr(dwGracePeriod), uintptr(dwShutdownFlags), uintptr(dwReason)) 190 | return uint32(ret) 191 | } 192 | 193 | var InitiateShutdown = InitiateShutdownW 194 | 195 | func InitiateShutdownW(lpMachineName PWSTR, lpMessage PWSTR, dwGracePeriod uint32, dwShutdownFlags SHUTDOWN_FLAGS, dwReason SHUTDOWN_REASON) uint32 { 196 | addr := LazyAddr(&pInitiateShutdownW, libAdvapi32, "InitiateShutdownW") 197 | ret, _, _ := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpMachineName)), uintptr(unsafe.Pointer(lpMessage)), uintptr(dwGracePeriod), uintptr(dwShutdownFlags), uintptr(dwReason)) 198 | return uint32(ret) 199 | } 200 | 201 | func CheckForHiberboot(pHiberboot *BOOLEAN, bClearFlag BOOLEAN) uint32 { 202 | addr := LazyAddr(&pCheckForHiberboot, libAdvapi32, "CheckForHiberboot") 203 | ret, _, _ := syscall.SyscallN(addr, uintptr(unsafe.Pointer(pHiberboot)), uintptr(bClearFlag)) 204 | return uint32(ret) 205 | } 206 | 207 | func ExitWindowsEx(uFlags EXIT_WINDOWS_FLAGS, dwReason SHUTDOWN_REASON) (BOOL, WIN32_ERROR) { 208 | addr := LazyAddr(&pExitWindowsEx, libUser32, "ExitWindowsEx") 209 | ret, _, err := syscall.SyscallN(addr, uintptr(uFlags), uintptr(dwReason)) 210 | return BOOL(ret), WIN32_ERROR(err) 211 | } 212 | 213 | func LockWorkStation() (BOOL, WIN32_ERROR) { 214 | addr := LazyAddr(&pLockWorkStation, libUser32, "LockWorkStation") 215 | ret, _, err := syscall.SyscallN(addr) 216 | return BOOL(ret), WIN32_ERROR(err) 217 | } 218 | 219 | func ShutdownBlockReasonCreate(hWnd HWND, pwszReason PWSTR) (BOOL, WIN32_ERROR) { 220 | addr := LazyAddr(&pShutdownBlockReasonCreate, libUser32, "ShutdownBlockReasonCreate") 221 | ret, _, err := syscall.SyscallN(addr, hWnd, uintptr(unsafe.Pointer(pwszReason))) 222 | return BOOL(ret), WIN32_ERROR(err) 223 | } 224 | 225 | func ShutdownBlockReasonQuery(hWnd HWND, pwszBuff PWSTR, pcchBuff *uint32) (BOOL, WIN32_ERROR) { 226 | addr := LazyAddr(&pShutdownBlockReasonQuery, libUser32, "ShutdownBlockReasonQuery") 227 | ret, _, err := syscall.SyscallN(addr, hWnd, uintptr(unsafe.Pointer(pwszBuff)), uintptr(unsafe.Pointer(pcchBuff))) 228 | return BOOL(ret), WIN32_ERROR(err) 229 | } 230 | 231 | func ShutdownBlockReasonDestroy(hWnd HWND) (BOOL, WIN32_ERROR) { 232 | addr := LazyAddr(&pShutdownBlockReasonDestroy, libUser32, "ShutdownBlockReasonDestroy") 233 | ret, _, err := syscall.SyscallN(addr, hWnd) 234 | return BOOL(ret), WIN32_ERROR(err) 235 | } 236 | -------------------------------------------------------------------------------- /win32/System.StationsAndDesktops.go: -------------------------------------------------------------------------------- 1 | package win32 2 | 3 | import ( 4 | "syscall" 5 | "unsafe" 6 | ) 7 | 8 | type ( 9 | HWINSTA = uintptr 10 | HDESK = uintptr 11 | ) 12 | 13 | // enums 14 | 15 | // enum 16 | // flags 17 | type BROADCAST_SYSTEM_MESSAGE_FLAGS uint32 18 | 19 | const ( 20 | BSF_ALLOWSFW BROADCAST_SYSTEM_MESSAGE_FLAGS = 128 21 | BSF_FLUSHDISK BROADCAST_SYSTEM_MESSAGE_FLAGS = 4 22 | BSF_FORCEIFHUNG BROADCAST_SYSTEM_MESSAGE_FLAGS = 32 23 | BSF_IGNORECURRENTTASK BROADCAST_SYSTEM_MESSAGE_FLAGS = 2 24 | BSF_NOHANG BROADCAST_SYSTEM_MESSAGE_FLAGS = 8 25 | BSF_NOTIMEOUTIFNOTHUNG BROADCAST_SYSTEM_MESSAGE_FLAGS = 64 26 | BSF_POSTMESSAGE BROADCAST_SYSTEM_MESSAGE_FLAGS = 16 27 | BSF_QUERY BROADCAST_SYSTEM_MESSAGE_FLAGS = 1 28 | BSF_SENDNOTIFYMESSAGE BROADCAST_SYSTEM_MESSAGE_FLAGS = 256 29 | BSF_LUID BROADCAST_SYSTEM_MESSAGE_FLAGS = 1024 30 | BSF_RETURNHDESK BROADCAST_SYSTEM_MESSAGE_FLAGS = 512 31 | ) 32 | 33 | // enum 34 | // flags 35 | type BROADCAST_SYSTEM_MESSAGE_INFO uint32 36 | 37 | const ( 38 | BSM_ALLCOMPONENTS BROADCAST_SYSTEM_MESSAGE_INFO = 0 39 | BSM_ALLDESKTOPS BROADCAST_SYSTEM_MESSAGE_INFO = 16 40 | BSM_APPLICATIONS BROADCAST_SYSTEM_MESSAGE_INFO = 8 41 | ) 42 | 43 | // enum 44 | type USER_OBJECT_INFORMATION_INDEX int32 45 | 46 | const ( 47 | UOI_FLAGS USER_OBJECT_INFORMATION_INDEX = 1 48 | UOI_HEAPSIZE USER_OBJECT_INFORMATION_INDEX = 5 49 | UOI_IO USER_OBJECT_INFORMATION_INDEX = 6 50 | UOI_NAME USER_OBJECT_INFORMATION_INDEX = 2 51 | UOI_TYPE USER_OBJECT_INFORMATION_INDEX = 3 52 | UOI_USER_SID USER_OBJECT_INFORMATION_INDEX = 4 53 | ) 54 | 55 | // enum 56 | type DESKTOP_CONTROL_FLAGS uint32 57 | 58 | const ( 59 | DF_ALLOWOTHERACCOUNTHOOK DESKTOP_CONTROL_FLAGS = 1 60 | ) 61 | 62 | // enum 63 | type DESKTOP_ACCESS_FLAGS uint32 64 | 65 | const ( 66 | DESKTOP_DELETE DESKTOP_ACCESS_FLAGS = 65536 67 | DESKTOP_READ_CONTROL DESKTOP_ACCESS_FLAGS = 131072 68 | DESKTOP_WRITE_DAC DESKTOP_ACCESS_FLAGS = 262144 69 | DESKTOP_WRITE_OWNER DESKTOP_ACCESS_FLAGS = 524288 70 | DESKTOP_SYNCHRONIZE DESKTOP_ACCESS_FLAGS = 1048576 71 | DESKTOP_READOBJECTS DESKTOP_ACCESS_FLAGS = 1 72 | DESKTOP_CREATEWINDOW DESKTOP_ACCESS_FLAGS = 2 73 | DESKTOP_CREATEMENU DESKTOP_ACCESS_FLAGS = 4 74 | DESKTOP_HOOKCONTROL DESKTOP_ACCESS_FLAGS = 8 75 | DESKTOP_JOURNALRECORD DESKTOP_ACCESS_FLAGS = 16 76 | DESKTOP_JOURNALPLAYBACK DESKTOP_ACCESS_FLAGS = 32 77 | DESKTOP_ENUMERATE DESKTOP_ACCESS_FLAGS = 64 78 | DESKTOP_WRITEOBJECTS DESKTOP_ACCESS_FLAGS = 128 79 | DESKTOP_SWITCHDESKTOP DESKTOP_ACCESS_FLAGS = 256 80 | ) 81 | 82 | // structs 83 | 84 | type USEROBJECTFLAGS struct { 85 | FInherit BOOL 86 | FReserved BOOL 87 | DwFlags uint32 88 | } 89 | 90 | type BSMINFO struct { 91 | CbSize uint32 92 | Hdesk HDESK 93 | Hwnd HWND 94 | Luid LUID 95 | } 96 | 97 | // func types 98 | 99 | type WINSTAENUMPROCA = uintptr 100 | type WINSTAENUMPROCA_func = func(param0 PSTR, param1 LPARAM) BOOL 101 | 102 | type WINSTAENUMPROCW = uintptr 103 | type WINSTAENUMPROCW_func = func(param0 PWSTR, param1 LPARAM) BOOL 104 | 105 | type DESKTOPENUMPROCA = uintptr 106 | type DESKTOPENUMPROCA_func = func(param0 PSTR, param1 LPARAM) BOOL 107 | 108 | type DESKTOPENUMPROCW = uintptr 109 | type DESKTOPENUMPROCW_func = func(param0 PWSTR, param1 LPARAM) BOOL 110 | 111 | var ( 112 | pCreateDesktopA uintptr 113 | pCreateDesktopW uintptr 114 | pCreateDesktopExA uintptr 115 | pCreateDesktopExW uintptr 116 | pOpenDesktopA uintptr 117 | pOpenDesktopW uintptr 118 | pOpenInputDesktop uintptr 119 | pEnumDesktopsA uintptr 120 | pEnumDesktopsW uintptr 121 | pEnumDesktopWindows uintptr 122 | pSwitchDesktop uintptr 123 | pSetThreadDesktop uintptr 124 | pCloseDesktop uintptr 125 | pGetThreadDesktop uintptr 126 | pCreateWindowStationA uintptr 127 | pCreateWindowStationW uintptr 128 | pOpenWindowStationA uintptr 129 | pOpenWindowStationW uintptr 130 | pEnumWindowStationsA uintptr 131 | pEnumWindowStationsW uintptr 132 | pCloseWindowStation uintptr 133 | pSetProcessWindowStation uintptr 134 | pGetProcessWindowStation uintptr 135 | pGetUserObjectInformationA uintptr 136 | pGetUserObjectInformationW uintptr 137 | pSetUserObjectInformationA uintptr 138 | pSetUserObjectInformationW uintptr 139 | pBroadcastSystemMessageExA uintptr 140 | pBroadcastSystemMessageExW uintptr 141 | pBroadcastSystemMessageA uintptr 142 | pBroadcastSystemMessageW uintptr 143 | ) 144 | 145 | func CreateDesktopA(lpszDesktop PSTR, lpszDevice PSTR, pDevmode *DEVMODEA, dwFlags DESKTOP_CONTROL_FLAGS, dwDesiredAccess uint32, lpsa *SECURITY_ATTRIBUTES) (HDESK, WIN32_ERROR) { 146 | addr := LazyAddr(&pCreateDesktopA, libUser32, "CreateDesktopA") 147 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpszDesktop)), uintptr(unsafe.Pointer(lpszDevice)), uintptr(unsafe.Pointer(pDevmode)), uintptr(dwFlags), uintptr(dwDesiredAccess), uintptr(unsafe.Pointer(lpsa))) 148 | return ret, WIN32_ERROR(err) 149 | } 150 | 151 | var CreateDesktop = CreateDesktopW 152 | 153 | func CreateDesktopW(lpszDesktop PWSTR, lpszDevice PWSTR, pDevmode *DEVMODEW, dwFlags DESKTOP_CONTROL_FLAGS, dwDesiredAccess uint32, lpsa *SECURITY_ATTRIBUTES) (HDESK, WIN32_ERROR) { 154 | addr := LazyAddr(&pCreateDesktopW, libUser32, "CreateDesktopW") 155 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpszDesktop)), uintptr(unsafe.Pointer(lpszDevice)), uintptr(unsafe.Pointer(pDevmode)), uintptr(dwFlags), uintptr(dwDesiredAccess), uintptr(unsafe.Pointer(lpsa))) 156 | return ret, WIN32_ERROR(err) 157 | } 158 | 159 | func CreateDesktopExA(lpszDesktop PSTR, lpszDevice PSTR, pDevmode *DEVMODEA, dwFlags DESKTOP_CONTROL_FLAGS, dwDesiredAccess uint32, lpsa *SECURITY_ATTRIBUTES, ulHeapSize uint32, pvoid unsafe.Pointer) (HDESK, WIN32_ERROR) { 160 | addr := LazyAddr(&pCreateDesktopExA, libUser32, "CreateDesktopExA") 161 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpszDesktop)), uintptr(unsafe.Pointer(lpszDevice)), uintptr(unsafe.Pointer(pDevmode)), uintptr(dwFlags), uintptr(dwDesiredAccess), uintptr(unsafe.Pointer(lpsa)), uintptr(ulHeapSize), uintptr(pvoid)) 162 | return ret, WIN32_ERROR(err) 163 | } 164 | 165 | var CreateDesktopEx = CreateDesktopExW 166 | 167 | func CreateDesktopExW(lpszDesktop PWSTR, lpszDevice PWSTR, pDevmode *DEVMODEW, dwFlags DESKTOP_CONTROL_FLAGS, dwDesiredAccess uint32, lpsa *SECURITY_ATTRIBUTES, ulHeapSize uint32, pvoid unsafe.Pointer) (HDESK, WIN32_ERROR) { 168 | addr := LazyAddr(&pCreateDesktopExW, libUser32, "CreateDesktopExW") 169 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpszDesktop)), uintptr(unsafe.Pointer(lpszDevice)), uintptr(unsafe.Pointer(pDevmode)), uintptr(dwFlags), uintptr(dwDesiredAccess), uintptr(unsafe.Pointer(lpsa)), uintptr(ulHeapSize), uintptr(pvoid)) 170 | return ret, WIN32_ERROR(err) 171 | } 172 | 173 | func OpenDesktopA(lpszDesktop PSTR, dwFlags DESKTOP_CONTROL_FLAGS, fInherit BOOL, dwDesiredAccess uint32) (HDESK, WIN32_ERROR) { 174 | addr := LazyAddr(&pOpenDesktopA, libUser32, "OpenDesktopA") 175 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpszDesktop)), uintptr(dwFlags), uintptr(fInherit), uintptr(dwDesiredAccess)) 176 | return ret, WIN32_ERROR(err) 177 | } 178 | 179 | var OpenDesktop = OpenDesktopW 180 | 181 | func OpenDesktopW(lpszDesktop PWSTR, dwFlags DESKTOP_CONTROL_FLAGS, fInherit BOOL, dwDesiredAccess uint32) (HDESK, WIN32_ERROR) { 182 | addr := LazyAddr(&pOpenDesktopW, libUser32, "OpenDesktopW") 183 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpszDesktop)), uintptr(dwFlags), uintptr(fInherit), uintptr(dwDesiredAccess)) 184 | return ret, WIN32_ERROR(err) 185 | } 186 | 187 | func OpenInputDesktop(dwFlags DESKTOP_CONTROL_FLAGS, fInherit BOOL, dwDesiredAccess DESKTOP_ACCESS_FLAGS) (HDESK, WIN32_ERROR) { 188 | addr := LazyAddr(&pOpenInputDesktop, libUser32, "OpenInputDesktop") 189 | ret, _, err := syscall.SyscallN(addr, uintptr(dwFlags), uintptr(fInherit), uintptr(dwDesiredAccess)) 190 | return ret, WIN32_ERROR(err) 191 | } 192 | 193 | func EnumDesktopsA(hwinsta HWINSTA, lpEnumFunc DESKTOPENUMPROCA, lParam LPARAM) (BOOL, WIN32_ERROR) { 194 | addr := LazyAddr(&pEnumDesktopsA, libUser32, "EnumDesktopsA") 195 | ret, _, err := syscall.SyscallN(addr, hwinsta, lpEnumFunc, lParam) 196 | return BOOL(ret), WIN32_ERROR(err) 197 | } 198 | 199 | var EnumDesktops = EnumDesktopsW 200 | 201 | func EnumDesktopsW(hwinsta HWINSTA, lpEnumFunc DESKTOPENUMPROCW, lParam LPARAM) (BOOL, WIN32_ERROR) { 202 | addr := LazyAddr(&pEnumDesktopsW, libUser32, "EnumDesktopsW") 203 | ret, _, err := syscall.SyscallN(addr, hwinsta, lpEnumFunc, lParam) 204 | return BOOL(ret), WIN32_ERROR(err) 205 | } 206 | 207 | func EnumDesktopWindows(hDesktop HDESK, lpfn WNDENUMPROC, lParam LPARAM) (BOOL, WIN32_ERROR) { 208 | addr := LazyAddr(&pEnumDesktopWindows, libUser32, "EnumDesktopWindows") 209 | ret, _, err := syscall.SyscallN(addr, hDesktop, lpfn, lParam) 210 | return BOOL(ret), WIN32_ERROR(err) 211 | } 212 | 213 | func SwitchDesktop(hDesktop HDESK) (BOOL, WIN32_ERROR) { 214 | addr := LazyAddr(&pSwitchDesktop, libUser32, "SwitchDesktop") 215 | ret, _, err := syscall.SyscallN(addr, hDesktop) 216 | return BOOL(ret), WIN32_ERROR(err) 217 | } 218 | 219 | func SetThreadDesktop(hDesktop HDESK) (BOOL, WIN32_ERROR) { 220 | addr := LazyAddr(&pSetThreadDesktop, libUser32, "SetThreadDesktop") 221 | ret, _, err := syscall.SyscallN(addr, hDesktop) 222 | return BOOL(ret), WIN32_ERROR(err) 223 | } 224 | 225 | func CloseDesktop(hDesktop HDESK) (BOOL, WIN32_ERROR) { 226 | addr := LazyAddr(&pCloseDesktop, libUser32, "CloseDesktop") 227 | ret, _, err := syscall.SyscallN(addr, hDesktop) 228 | return BOOL(ret), WIN32_ERROR(err) 229 | } 230 | 231 | func GetThreadDesktop(dwThreadId uint32) (HDESK, WIN32_ERROR) { 232 | addr := LazyAddr(&pGetThreadDesktop, libUser32, "GetThreadDesktop") 233 | ret, _, err := syscall.SyscallN(addr, uintptr(dwThreadId)) 234 | return ret, WIN32_ERROR(err) 235 | } 236 | 237 | func CreateWindowStationA(lpwinsta PSTR, dwFlags uint32, dwDesiredAccess uint32, lpsa *SECURITY_ATTRIBUTES) (HWINSTA, WIN32_ERROR) { 238 | addr := LazyAddr(&pCreateWindowStationA, libUser32, "CreateWindowStationA") 239 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpwinsta)), uintptr(dwFlags), uintptr(dwDesiredAccess), uintptr(unsafe.Pointer(lpsa))) 240 | return ret, WIN32_ERROR(err) 241 | } 242 | 243 | var CreateWindowStation = CreateWindowStationW 244 | 245 | func CreateWindowStationW(lpwinsta PWSTR, dwFlags uint32, dwDesiredAccess uint32, lpsa *SECURITY_ATTRIBUTES) (HWINSTA, WIN32_ERROR) { 246 | addr := LazyAddr(&pCreateWindowStationW, libUser32, "CreateWindowStationW") 247 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpwinsta)), uintptr(dwFlags), uintptr(dwDesiredAccess), uintptr(unsafe.Pointer(lpsa))) 248 | return ret, WIN32_ERROR(err) 249 | } 250 | 251 | func OpenWindowStationA(lpszWinSta PSTR, fInherit BOOL, dwDesiredAccess uint32) (HWINSTA, WIN32_ERROR) { 252 | addr := LazyAddr(&pOpenWindowStationA, libUser32, "OpenWindowStationA") 253 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpszWinSta)), uintptr(fInherit), uintptr(dwDesiredAccess)) 254 | return ret, WIN32_ERROR(err) 255 | } 256 | 257 | var OpenWindowStation = OpenWindowStationW 258 | 259 | func OpenWindowStationW(lpszWinSta PWSTR, fInherit BOOL, dwDesiredAccess uint32) (HWINSTA, WIN32_ERROR) { 260 | addr := LazyAddr(&pOpenWindowStationW, libUser32, "OpenWindowStationW") 261 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpszWinSta)), uintptr(fInherit), uintptr(dwDesiredAccess)) 262 | return ret, WIN32_ERROR(err) 263 | } 264 | 265 | func EnumWindowStationsA(lpEnumFunc WINSTAENUMPROCA, lParam LPARAM) (BOOL, WIN32_ERROR) { 266 | addr := LazyAddr(&pEnumWindowStationsA, libUser32, "EnumWindowStationsA") 267 | ret, _, err := syscall.SyscallN(addr, lpEnumFunc, lParam) 268 | return BOOL(ret), WIN32_ERROR(err) 269 | } 270 | 271 | var EnumWindowStations = EnumWindowStationsW 272 | 273 | func EnumWindowStationsW(lpEnumFunc WINSTAENUMPROCW, lParam LPARAM) (BOOL, WIN32_ERROR) { 274 | addr := LazyAddr(&pEnumWindowStationsW, libUser32, "EnumWindowStationsW") 275 | ret, _, err := syscall.SyscallN(addr, lpEnumFunc, lParam) 276 | return BOOL(ret), WIN32_ERROR(err) 277 | } 278 | 279 | func CloseWindowStation(hWinSta HWINSTA) (BOOL, WIN32_ERROR) { 280 | addr := LazyAddr(&pCloseWindowStation, libUser32, "CloseWindowStation") 281 | ret, _, err := syscall.SyscallN(addr, hWinSta) 282 | return BOOL(ret), WIN32_ERROR(err) 283 | } 284 | 285 | func SetProcessWindowStation(hWinSta HWINSTA) (BOOL, WIN32_ERROR) { 286 | addr := LazyAddr(&pSetProcessWindowStation, libUser32, "SetProcessWindowStation") 287 | ret, _, err := syscall.SyscallN(addr, hWinSta) 288 | return BOOL(ret), WIN32_ERROR(err) 289 | } 290 | 291 | func GetProcessWindowStation() (HWINSTA, WIN32_ERROR) { 292 | addr := LazyAddr(&pGetProcessWindowStation, libUser32, "GetProcessWindowStation") 293 | ret, _, err := syscall.SyscallN(addr) 294 | return ret, WIN32_ERROR(err) 295 | } 296 | 297 | func GetUserObjectInformationA(hObj HANDLE, nIndex USER_OBJECT_INFORMATION_INDEX, pvInfo unsafe.Pointer, nLength uint32, lpnLengthNeeded *uint32) (BOOL, WIN32_ERROR) { 298 | addr := LazyAddr(&pGetUserObjectInformationA, libUser32, "GetUserObjectInformationA") 299 | ret, _, err := syscall.SyscallN(addr, hObj, uintptr(nIndex), uintptr(pvInfo), uintptr(nLength), uintptr(unsafe.Pointer(lpnLengthNeeded))) 300 | return BOOL(ret), WIN32_ERROR(err) 301 | } 302 | 303 | var GetUserObjectInformation = GetUserObjectInformationW 304 | 305 | func GetUserObjectInformationW(hObj HANDLE, nIndex USER_OBJECT_INFORMATION_INDEX, pvInfo unsafe.Pointer, nLength uint32, lpnLengthNeeded *uint32) (BOOL, WIN32_ERROR) { 306 | addr := LazyAddr(&pGetUserObjectInformationW, libUser32, "GetUserObjectInformationW") 307 | ret, _, err := syscall.SyscallN(addr, hObj, uintptr(nIndex), uintptr(pvInfo), uintptr(nLength), uintptr(unsafe.Pointer(lpnLengthNeeded))) 308 | return BOOL(ret), WIN32_ERROR(err) 309 | } 310 | 311 | func SetUserObjectInformationA(hObj HANDLE, nIndex int32, pvInfo unsafe.Pointer, nLength uint32) (BOOL, WIN32_ERROR) { 312 | addr := LazyAddr(&pSetUserObjectInformationA, libUser32, "SetUserObjectInformationA") 313 | ret, _, err := syscall.SyscallN(addr, hObj, uintptr(nIndex), uintptr(pvInfo), uintptr(nLength)) 314 | return BOOL(ret), WIN32_ERROR(err) 315 | } 316 | 317 | var SetUserObjectInformation = SetUserObjectInformationW 318 | 319 | func SetUserObjectInformationW(hObj HANDLE, nIndex int32, pvInfo unsafe.Pointer, nLength uint32) (BOOL, WIN32_ERROR) { 320 | addr := LazyAddr(&pSetUserObjectInformationW, libUser32, "SetUserObjectInformationW") 321 | ret, _, err := syscall.SyscallN(addr, hObj, uintptr(nIndex), uintptr(pvInfo), uintptr(nLength)) 322 | return BOOL(ret), WIN32_ERROR(err) 323 | } 324 | 325 | func BroadcastSystemMessageExA(flags BROADCAST_SYSTEM_MESSAGE_FLAGS, lpInfo *BROADCAST_SYSTEM_MESSAGE_INFO, Msg uint32, wParam WPARAM, lParam LPARAM, pbsmInfo *BSMINFO) (int32, WIN32_ERROR) { 326 | addr := LazyAddr(&pBroadcastSystemMessageExA, libUser32, "BroadcastSystemMessageExA") 327 | ret, _, err := syscall.SyscallN(addr, uintptr(flags), uintptr(unsafe.Pointer(lpInfo)), uintptr(Msg), wParam, lParam, uintptr(unsafe.Pointer(pbsmInfo))) 328 | return int32(ret), WIN32_ERROR(err) 329 | } 330 | 331 | var BroadcastSystemMessageEx = BroadcastSystemMessageExW 332 | 333 | func BroadcastSystemMessageExW(flags BROADCAST_SYSTEM_MESSAGE_FLAGS, lpInfo *BROADCAST_SYSTEM_MESSAGE_INFO, Msg uint32, wParam WPARAM, lParam LPARAM, pbsmInfo *BSMINFO) (int32, WIN32_ERROR) { 334 | addr := LazyAddr(&pBroadcastSystemMessageExW, libUser32, "BroadcastSystemMessageExW") 335 | ret, _, err := syscall.SyscallN(addr, uintptr(flags), uintptr(unsafe.Pointer(lpInfo)), uintptr(Msg), wParam, lParam, uintptr(unsafe.Pointer(pbsmInfo))) 336 | return int32(ret), WIN32_ERROR(err) 337 | } 338 | 339 | func BroadcastSystemMessageA(flags uint32, lpInfo *uint32, Msg uint32, wParam WPARAM, lParam LPARAM) int32 { 340 | addr := LazyAddr(&pBroadcastSystemMessageA, libUser32, "BroadcastSystemMessageA") 341 | ret, _, _ := syscall.SyscallN(addr, uintptr(flags), uintptr(unsafe.Pointer(lpInfo)), uintptr(Msg), wParam, lParam) 342 | return int32(ret) 343 | } 344 | 345 | var BroadcastSystemMessage = BroadcastSystemMessageW 346 | 347 | func BroadcastSystemMessageW(flags BROADCAST_SYSTEM_MESSAGE_FLAGS, lpInfo *BROADCAST_SYSTEM_MESSAGE_INFO, Msg uint32, wParam WPARAM, lParam LPARAM) (int32, WIN32_ERROR) { 348 | addr := LazyAddr(&pBroadcastSystemMessageW, libUser32, "BroadcastSystemMessageW") 349 | ret, _, err := syscall.SyscallN(addr, uintptr(flags), uintptr(unsafe.Pointer(lpInfo)), uintptr(Msg), wParam, lParam) 350 | return int32(ret), WIN32_ERROR(err) 351 | } 352 | -------------------------------------------------------------------------------- /win32/System.Diagnostics.ProcessSnapshotting.go: -------------------------------------------------------------------------------- 1 | package win32 2 | 3 | import ( 4 | "syscall" 5 | "unsafe" 6 | ) 7 | 8 | type ( 9 | HPSS = uintptr 10 | HPSSWALK = uintptr 11 | ) 12 | 13 | const ( 14 | PSS_PERF_RESOLUTION uint32 = 0xf4240 15 | ) 16 | 17 | // enums 18 | 19 | // enum 20 | // flags 21 | type PSS_HANDLE_FLAGS int32 22 | 23 | const ( 24 | PSS_HANDLE_NONE PSS_HANDLE_FLAGS = 0 25 | PSS_HANDLE_HAVE_TYPE PSS_HANDLE_FLAGS = 1 26 | PSS_HANDLE_HAVE_NAME PSS_HANDLE_FLAGS = 2 27 | PSS_HANDLE_HAVE_BASIC_INFORMATION PSS_HANDLE_FLAGS = 4 28 | PSS_HANDLE_HAVE_TYPE_SPECIFIC_INFORMATION PSS_HANDLE_FLAGS = 8 29 | ) 30 | 31 | // enum 32 | type PSS_OBJECT_TYPE int32 33 | 34 | const ( 35 | PSS_OBJECT_TYPE_UNKNOWN PSS_OBJECT_TYPE = 0 36 | PSS_OBJECT_TYPE_PROCESS PSS_OBJECT_TYPE = 1 37 | PSS_OBJECT_TYPE_THREAD PSS_OBJECT_TYPE = 2 38 | PSS_OBJECT_TYPE_MUTANT PSS_OBJECT_TYPE = 3 39 | PSS_OBJECT_TYPE_EVENT PSS_OBJECT_TYPE = 4 40 | PSS_OBJECT_TYPE_SECTION PSS_OBJECT_TYPE = 5 41 | PSS_OBJECT_TYPE_SEMAPHORE PSS_OBJECT_TYPE = 6 42 | ) 43 | 44 | // enum 45 | // flags 46 | type PSS_CAPTURE_FLAGS uint32 47 | 48 | const ( 49 | PSS_CAPTURE_NONE PSS_CAPTURE_FLAGS = 0 50 | PSS_CAPTURE_VA_CLONE PSS_CAPTURE_FLAGS = 1 51 | PSS_CAPTURE_RESERVED_00000002 PSS_CAPTURE_FLAGS = 2 52 | PSS_CAPTURE_HANDLES PSS_CAPTURE_FLAGS = 4 53 | PSS_CAPTURE_HANDLE_NAME_INFORMATION PSS_CAPTURE_FLAGS = 8 54 | PSS_CAPTURE_HANDLE_BASIC_INFORMATION PSS_CAPTURE_FLAGS = 16 55 | PSS_CAPTURE_HANDLE_TYPE_SPECIFIC_INFORMATION PSS_CAPTURE_FLAGS = 32 56 | PSS_CAPTURE_HANDLE_TRACE PSS_CAPTURE_FLAGS = 64 57 | PSS_CAPTURE_THREADS PSS_CAPTURE_FLAGS = 128 58 | PSS_CAPTURE_THREAD_CONTEXT PSS_CAPTURE_FLAGS = 256 59 | PSS_CAPTURE_THREAD_CONTEXT_EXTENDED PSS_CAPTURE_FLAGS = 512 60 | PSS_CAPTURE_RESERVED_00000400 PSS_CAPTURE_FLAGS = 1024 61 | PSS_CAPTURE_VA_SPACE PSS_CAPTURE_FLAGS = 2048 62 | PSS_CAPTURE_VA_SPACE_SECTION_INFORMATION PSS_CAPTURE_FLAGS = 4096 63 | PSS_CAPTURE_IPT_TRACE PSS_CAPTURE_FLAGS = 8192 64 | PSS_CAPTURE_RESERVED_00004000 PSS_CAPTURE_FLAGS = 16384 65 | PSS_CREATE_BREAKAWAY_OPTIONAL PSS_CAPTURE_FLAGS = 67108864 66 | PSS_CREATE_BREAKAWAY PSS_CAPTURE_FLAGS = 134217728 67 | PSS_CREATE_FORCE_BREAKAWAY PSS_CAPTURE_FLAGS = 268435456 68 | PSS_CREATE_USE_VM_ALLOCATIONS PSS_CAPTURE_FLAGS = 536870912 69 | PSS_CREATE_MEASURE_PERFORMANCE PSS_CAPTURE_FLAGS = 1073741824 70 | PSS_CREATE_RELEASE_SECTION PSS_CAPTURE_FLAGS = 2147483648 71 | ) 72 | 73 | // enum 74 | type PSS_QUERY_INFORMATION_CLASS int32 75 | 76 | const ( 77 | PSS_QUERY_PROCESS_INFORMATION PSS_QUERY_INFORMATION_CLASS = 0 78 | PSS_QUERY_VA_CLONE_INFORMATION PSS_QUERY_INFORMATION_CLASS = 1 79 | PSS_QUERY_AUXILIARY_PAGES_INFORMATION PSS_QUERY_INFORMATION_CLASS = 2 80 | PSS_QUERY_VA_SPACE_INFORMATION PSS_QUERY_INFORMATION_CLASS = 3 81 | PSS_QUERY_HANDLE_INFORMATION PSS_QUERY_INFORMATION_CLASS = 4 82 | PSS_QUERY_THREAD_INFORMATION PSS_QUERY_INFORMATION_CLASS = 5 83 | PSS_QUERY_HANDLE_TRACE_INFORMATION PSS_QUERY_INFORMATION_CLASS = 6 84 | PSS_QUERY_PERFORMANCE_COUNTERS PSS_QUERY_INFORMATION_CLASS = 7 85 | ) 86 | 87 | // enum 88 | type PSS_WALK_INFORMATION_CLASS int32 89 | 90 | const ( 91 | PSS_WALK_AUXILIARY_PAGES PSS_WALK_INFORMATION_CLASS = 0 92 | PSS_WALK_VA_SPACE PSS_WALK_INFORMATION_CLASS = 1 93 | PSS_WALK_HANDLES PSS_WALK_INFORMATION_CLASS = 2 94 | PSS_WALK_THREADS PSS_WALK_INFORMATION_CLASS = 3 95 | ) 96 | 97 | // enum 98 | // flags 99 | type PSS_DUPLICATE_FLAGS int32 100 | 101 | const ( 102 | PSS_DUPLICATE_NONE PSS_DUPLICATE_FLAGS = 0 103 | PSS_DUPLICATE_CLOSE_SOURCE PSS_DUPLICATE_FLAGS = 1 104 | ) 105 | 106 | // enum 107 | // flags 108 | type PSS_PROCESS_FLAGS int32 109 | 110 | const ( 111 | PSS_PROCESS_FLAGS_NONE PSS_PROCESS_FLAGS = 0 112 | PSS_PROCESS_FLAGS_PROTECTED PSS_PROCESS_FLAGS = 1 113 | PSS_PROCESS_FLAGS_WOW64 PSS_PROCESS_FLAGS = 2 114 | PSS_PROCESS_FLAGS_RESERVED_03 PSS_PROCESS_FLAGS = 4 115 | PSS_PROCESS_FLAGS_RESERVED_04 PSS_PROCESS_FLAGS = 8 116 | PSS_PROCESS_FLAGS_FROZEN PSS_PROCESS_FLAGS = 16 117 | ) 118 | 119 | // enum 120 | // flags 121 | type PSS_THREAD_FLAGS int32 122 | 123 | const ( 124 | PSS_THREAD_FLAGS_NONE PSS_THREAD_FLAGS = 0 125 | PSS_THREAD_FLAGS_TERMINATED PSS_THREAD_FLAGS = 1 126 | ) 127 | 128 | // structs 129 | 130 | type PSS_PROCESS_INFORMATION struct { 131 | ExitStatus uint32 132 | PebBaseAddress unsafe.Pointer 133 | AffinityMask uintptr 134 | BasePriority int32 135 | ProcessId uint32 136 | ParentProcessId uint32 137 | Flags PSS_PROCESS_FLAGS 138 | CreateTime FILETIME 139 | ExitTime FILETIME 140 | KernelTime FILETIME 141 | UserTime FILETIME 142 | PriorityClass uint32 143 | PeakVirtualSize uintptr 144 | VirtualSize uintptr 145 | PageFaultCount uint32 146 | PeakWorkingSetSize uintptr 147 | WorkingSetSize uintptr 148 | QuotaPeakPagedPoolUsage uintptr 149 | QuotaPagedPoolUsage uintptr 150 | QuotaPeakNonPagedPoolUsage uintptr 151 | QuotaNonPagedPoolUsage uintptr 152 | PagefileUsage uintptr 153 | PeakPagefileUsage uintptr 154 | PrivateUsage uintptr 155 | ExecuteFlags uint32 156 | ImageFileName [260]uint16 157 | } 158 | 159 | type PSS_VA_CLONE_INFORMATION struct { 160 | VaCloneHandle HANDLE 161 | } 162 | 163 | type PSS_AUXILIARY_PAGES_INFORMATION struct { 164 | AuxPagesCaptured uint32 165 | } 166 | 167 | type PSS_VA_SPACE_INFORMATION struct { 168 | RegionCount uint32 169 | } 170 | 171 | type PSS_HANDLE_INFORMATION struct { 172 | HandlesCaptured uint32 173 | } 174 | 175 | type PSS_THREAD_INFORMATION struct { 176 | ThreadsCaptured uint32 177 | ContextLength uint32 178 | } 179 | 180 | type PSS_HANDLE_TRACE_INFORMATION struct { 181 | SectionHandle HANDLE 182 | Size uint32 183 | } 184 | 185 | type PSS_PERFORMANCE_COUNTERS struct { 186 | TotalCycleCount uint64 187 | TotalWallClockPeriod uint64 188 | VaCloneCycleCount uint64 189 | VaCloneWallClockPeriod uint64 190 | VaSpaceCycleCount uint64 191 | VaSpaceWallClockPeriod uint64 192 | AuxPagesCycleCount uint64 193 | AuxPagesWallClockPeriod uint64 194 | HandlesCycleCount uint64 195 | HandlesWallClockPeriod uint64 196 | ThreadsCycleCount uint64 197 | ThreadsWallClockPeriod uint64 198 | } 199 | 200 | type PSS_AUXILIARY_PAGE_ENTRY struct { 201 | Address unsafe.Pointer 202 | BasicInformation MEMORY_BASIC_INFORMATION 203 | CaptureTime FILETIME 204 | PageContents unsafe.Pointer 205 | PageSize uint32 206 | } 207 | 208 | type PSS_VA_SPACE_ENTRY struct { 209 | BaseAddress unsafe.Pointer 210 | AllocationBase unsafe.Pointer 211 | AllocationProtect uint32 212 | RegionSize uintptr 213 | State uint32 214 | Protect uint32 215 | Type uint32 216 | TimeDateStamp uint32 217 | SizeOfImage uint32 218 | ImageBase unsafe.Pointer 219 | CheckSum uint32 220 | MappedFileNameLength uint16 221 | MappedFileName PWSTR 222 | } 223 | 224 | type PSS_HANDLE_ENTRY_TypeSpecificInformation_Process struct { 225 | ExitStatus uint32 226 | PebBaseAddress unsafe.Pointer 227 | AffinityMask uintptr 228 | BasePriority int32 229 | ProcessId uint32 230 | ParentProcessId uint32 231 | Flags uint32 232 | } 233 | 234 | type PSS_HANDLE_ENTRY_TypeSpecificInformation_Thread struct { 235 | ExitStatus uint32 236 | TebBaseAddress unsafe.Pointer 237 | ProcessId uint32 238 | ThreadId uint32 239 | AffinityMask uintptr 240 | Priority int32 241 | BasePriority int32 242 | Win32StartAddress unsafe.Pointer 243 | } 244 | 245 | type PSS_HANDLE_ENTRY_TypeSpecificInformation_Mutant struct { 246 | CurrentCount int32 247 | Abandoned BOOL 248 | OwnerProcessId uint32 249 | OwnerThreadId uint32 250 | } 251 | 252 | type PSS_HANDLE_ENTRY_TypeSpecificInformation_Event struct { 253 | ManualReset BOOL 254 | Signaled BOOL 255 | } 256 | 257 | type PSS_HANDLE_ENTRY_TypeSpecificInformation_Section struct { 258 | BaseAddress unsafe.Pointer 259 | AllocationAttributes uint32 260 | MaximumSize int64 261 | } 262 | 263 | type PSS_HANDLE_ENTRY_TypeSpecificInformation_Semaphore struct { 264 | CurrentCount int32 265 | MaximumCount int32 266 | } 267 | 268 | type PSS_HANDLE_ENTRY_TypeSpecificInformation struct { 269 | Data [6]uint64 270 | } 271 | 272 | func (this *PSS_HANDLE_ENTRY_TypeSpecificInformation) Process() *PSS_HANDLE_ENTRY_TypeSpecificInformation_Process { 273 | return (*PSS_HANDLE_ENTRY_TypeSpecificInformation_Process)(unsafe.Pointer(this)) 274 | } 275 | 276 | func (this *PSS_HANDLE_ENTRY_TypeSpecificInformation) ProcessVal() PSS_HANDLE_ENTRY_TypeSpecificInformation_Process { 277 | return *(*PSS_HANDLE_ENTRY_TypeSpecificInformation_Process)(unsafe.Pointer(this)) 278 | } 279 | 280 | func (this *PSS_HANDLE_ENTRY_TypeSpecificInformation) Thread() *PSS_HANDLE_ENTRY_TypeSpecificInformation_Thread { 281 | return (*PSS_HANDLE_ENTRY_TypeSpecificInformation_Thread)(unsafe.Pointer(this)) 282 | } 283 | 284 | func (this *PSS_HANDLE_ENTRY_TypeSpecificInformation) ThreadVal() PSS_HANDLE_ENTRY_TypeSpecificInformation_Thread { 285 | return *(*PSS_HANDLE_ENTRY_TypeSpecificInformation_Thread)(unsafe.Pointer(this)) 286 | } 287 | 288 | func (this *PSS_HANDLE_ENTRY_TypeSpecificInformation) Mutant() *PSS_HANDLE_ENTRY_TypeSpecificInformation_Mutant { 289 | return (*PSS_HANDLE_ENTRY_TypeSpecificInformation_Mutant)(unsafe.Pointer(this)) 290 | } 291 | 292 | func (this *PSS_HANDLE_ENTRY_TypeSpecificInformation) MutantVal() PSS_HANDLE_ENTRY_TypeSpecificInformation_Mutant { 293 | return *(*PSS_HANDLE_ENTRY_TypeSpecificInformation_Mutant)(unsafe.Pointer(this)) 294 | } 295 | 296 | func (this *PSS_HANDLE_ENTRY_TypeSpecificInformation) Event() *PSS_HANDLE_ENTRY_TypeSpecificInformation_Event { 297 | return (*PSS_HANDLE_ENTRY_TypeSpecificInformation_Event)(unsafe.Pointer(this)) 298 | } 299 | 300 | func (this *PSS_HANDLE_ENTRY_TypeSpecificInformation) EventVal() PSS_HANDLE_ENTRY_TypeSpecificInformation_Event { 301 | return *(*PSS_HANDLE_ENTRY_TypeSpecificInformation_Event)(unsafe.Pointer(this)) 302 | } 303 | 304 | func (this *PSS_HANDLE_ENTRY_TypeSpecificInformation) Section() *PSS_HANDLE_ENTRY_TypeSpecificInformation_Section { 305 | return (*PSS_HANDLE_ENTRY_TypeSpecificInformation_Section)(unsafe.Pointer(this)) 306 | } 307 | 308 | func (this *PSS_HANDLE_ENTRY_TypeSpecificInformation) SectionVal() PSS_HANDLE_ENTRY_TypeSpecificInformation_Section { 309 | return *(*PSS_HANDLE_ENTRY_TypeSpecificInformation_Section)(unsafe.Pointer(this)) 310 | } 311 | 312 | func (this *PSS_HANDLE_ENTRY_TypeSpecificInformation) Semaphore() *PSS_HANDLE_ENTRY_TypeSpecificInformation_Semaphore { 313 | return (*PSS_HANDLE_ENTRY_TypeSpecificInformation_Semaphore)(unsafe.Pointer(this)) 314 | } 315 | 316 | func (this *PSS_HANDLE_ENTRY_TypeSpecificInformation) SemaphoreVal() PSS_HANDLE_ENTRY_TypeSpecificInformation_Semaphore { 317 | return *(*PSS_HANDLE_ENTRY_TypeSpecificInformation_Semaphore)(unsafe.Pointer(this)) 318 | } 319 | 320 | type PSS_HANDLE_ENTRY struct { 321 | Handle HANDLE 322 | Flags PSS_HANDLE_FLAGS 323 | ObjectType PSS_OBJECT_TYPE 324 | CaptureTime FILETIME 325 | Attributes uint32 326 | GrantedAccess uint32 327 | HandleCount uint32 328 | PointerCount uint32 329 | PagedPoolCharge uint32 330 | NonPagedPoolCharge uint32 331 | CreationTime FILETIME 332 | TypeNameLength uint16 333 | TypeName PWSTR 334 | ObjectNameLength uint16 335 | ObjectName PWSTR 336 | TypeSpecificInformation PSS_HANDLE_ENTRY_TypeSpecificInformation 337 | } 338 | 339 | type PSS_THREAD_ENTRY struct { 340 | ExitStatus uint32 341 | TebBaseAddress unsafe.Pointer 342 | ProcessId uint32 343 | ThreadId uint32 344 | AffinityMask uintptr 345 | Priority int32 346 | BasePriority int32 347 | LastSyscallFirstArgument unsafe.Pointer 348 | LastSyscallNumber uint16 349 | CreateTime FILETIME 350 | ExitTime FILETIME 351 | KernelTime FILETIME 352 | UserTime FILETIME 353 | Win32StartAddress unsafe.Pointer 354 | CaptureTime FILETIME 355 | Flags PSS_THREAD_FLAGS 356 | SuspendCount uint16 357 | SizeOfContextRecord uint16 358 | ContextRecord *CONTEXT 359 | } 360 | 361 | type PSS_ALLOCATOR struct { 362 | Context unsafe.Pointer 363 | AllocRoutine uintptr 364 | FreeRoutine uintptr 365 | } 366 | 367 | var ( 368 | pPssCaptureSnapshot uintptr 369 | pPssFreeSnapshot uintptr 370 | pPssQuerySnapshot uintptr 371 | pPssWalkSnapshot uintptr 372 | pPssDuplicateSnapshot uintptr 373 | pPssWalkMarkerCreate uintptr 374 | pPssWalkMarkerFree uintptr 375 | pPssWalkMarkerGetPosition uintptr 376 | pPssWalkMarkerSetPosition uintptr 377 | pPssWalkMarkerSeekToBeginning uintptr 378 | ) 379 | 380 | func PssCaptureSnapshot(ProcessHandle HANDLE, CaptureFlags PSS_CAPTURE_FLAGS, ThreadContextFlags uint32, SnapshotHandle *HPSS) uint32 { 381 | addr := LazyAddr(&pPssCaptureSnapshot, libKernel32, "PssCaptureSnapshot") 382 | ret, _, _ := syscall.SyscallN(addr, ProcessHandle, uintptr(CaptureFlags), uintptr(ThreadContextFlags), uintptr(unsafe.Pointer(SnapshotHandle))) 383 | return uint32(ret) 384 | } 385 | 386 | func PssFreeSnapshot(ProcessHandle HANDLE, SnapshotHandle HPSS) uint32 { 387 | addr := LazyAddr(&pPssFreeSnapshot, libKernel32, "PssFreeSnapshot") 388 | ret, _, _ := syscall.SyscallN(addr, ProcessHandle, SnapshotHandle) 389 | return uint32(ret) 390 | } 391 | 392 | func PssQuerySnapshot(SnapshotHandle HPSS, InformationClass PSS_QUERY_INFORMATION_CLASS, Buffer unsafe.Pointer, BufferLength uint32) uint32 { 393 | addr := LazyAddr(&pPssQuerySnapshot, libKernel32, "PssQuerySnapshot") 394 | ret, _, _ := syscall.SyscallN(addr, SnapshotHandle, uintptr(InformationClass), uintptr(Buffer), uintptr(BufferLength)) 395 | return uint32(ret) 396 | } 397 | 398 | func PssWalkSnapshot(SnapshotHandle HPSS, InformationClass PSS_WALK_INFORMATION_CLASS, WalkMarkerHandle HPSSWALK, Buffer unsafe.Pointer, BufferLength uint32) uint32 { 399 | addr := LazyAddr(&pPssWalkSnapshot, libKernel32, "PssWalkSnapshot") 400 | ret, _, _ := syscall.SyscallN(addr, SnapshotHandle, uintptr(InformationClass), WalkMarkerHandle, uintptr(Buffer), uintptr(BufferLength)) 401 | return uint32(ret) 402 | } 403 | 404 | func PssDuplicateSnapshot(SourceProcessHandle HANDLE, SnapshotHandle HPSS, TargetProcessHandle HANDLE, TargetSnapshotHandle *HPSS, Flags PSS_DUPLICATE_FLAGS) uint32 { 405 | addr := LazyAddr(&pPssDuplicateSnapshot, libKernel32, "PssDuplicateSnapshot") 406 | ret, _, _ := syscall.SyscallN(addr, SourceProcessHandle, SnapshotHandle, TargetProcessHandle, uintptr(unsafe.Pointer(TargetSnapshotHandle)), uintptr(Flags)) 407 | return uint32(ret) 408 | } 409 | 410 | func PssWalkMarkerCreate(Allocator *PSS_ALLOCATOR, WalkMarkerHandle *HPSSWALK) uint32 { 411 | addr := LazyAddr(&pPssWalkMarkerCreate, libKernel32, "PssWalkMarkerCreate") 412 | ret, _, _ := syscall.SyscallN(addr, uintptr(unsafe.Pointer(Allocator)), uintptr(unsafe.Pointer(WalkMarkerHandle))) 413 | return uint32(ret) 414 | } 415 | 416 | func PssWalkMarkerFree(WalkMarkerHandle HPSSWALK) uint32 { 417 | addr := LazyAddr(&pPssWalkMarkerFree, libKernel32, "PssWalkMarkerFree") 418 | ret, _, _ := syscall.SyscallN(addr, WalkMarkerHandle) 419 | return uint32(ret) 420 | } 421 | 422 | func PssWalkMarkerGetPosition(WalkMarkerHandle HPSSWALK, Position *uintptr) uint32 { 423 | addr := LazyAddr(&pPssWalkMarkerGetPosition, libKernel32, "PssWalkMarkerGetPosition") 424 | ret, _, _ := syscall.SyscallN(addr, WalkMarkerHandle, uintptr(unsafe.Pointer(Position))) 425 | return uint32(ret) 426 | } 427 | 428 | func PssWalkMarkerSetPosition(WalkMarkerHandle HPSSWALK, Position uintptr) uint32 { 429 | addr := LazyAddr(&pPssWalkMarkerSetPosition, libKernel32, "PssWalkMarkerSetPosition") 430 | ret, _, _ := syscall.SyscallN(addr, WalkMarkerHandle, Position) 431 | return uint32(ret) 432 | } 433 | 434 | func PssWalkMarkerSeekToBeginning(WalkMarkerHandle HPSSWALK) uint32 { 435 | addr := LazyAddr(&pPssWalkMarkerSeekToBeginning, libKernel32, "PssWalkMarkerSeekToBeginning") 436 | ret, _, _ := syscall.SyscallN(addr, WalkMarkerHandle) 437 | return uint32(ret) 438 | } 439 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | -------------------------------------------------------------------------------- /win32/System.Environment.go: -------------------------------------------------------------------------------- 1 | package win32 2 | 3 | import ( 4 | "syscall" 5 | "unsafe" 6 | ) 7 | 8 | const ( 9 | ENCLAVE_RUNTIME_POLICY_ALLOW_FULL_DEBUG uint32 = 0x1 10 | ENCLAVE_RUNTIME_POLICY_ALLOW_DYNAMIC_DEBUG uint32 = 0x2 11 | ENCLAVE_UNSEAL_FLAG_STALE_KEY uint32 = 0x1 12 | ENCLAVE_FLAG_FULL_DEBUG_ENABLED uint32 = 0x1 13 | ENCLAVE_FLAG_DYNAMIC_DEBUG_ENABLED uint32 = 0x2 14 | ENCLAVE_FLAG_DYNAMIC_DEBUG_ACTIVE uint32 = 0x4 15 | VBS_ENCLAVE_REPORT_PKG_HEADER_VERSION_CURRENT uint32 = 0x1 16 | VBS_ENCLAVE_REPORT_SIGNATURE_SCHEME_SHA256_RSA_PSS_SHA256 uint32 = 0x1 17 | VBS_ENCLAVE_REPORT_VERSION_CURRENT uint32 = 0x1 18 | ENCLAVE_REPORT_DATA_LENGTH uint32 = 0x40 19 | VBS_ENCLAVE_VARDATA_INVALID uint32 = 0x0 20 | VBS_ENCLAVE_VARDATA_MODULE uint32 = 0x1 21 | ENCLAVE_VBS_BASIC_KEY_FLAG_MEASUREMENT uint32 = 0x1 22 | ENCLAVE_VBS_BASIC_KEY_FLAG_FAMILY_ID uint32 = 0x2 23 | ENCLAVE_VBS_BASIC_KEY_FLAG_IMAGE_ID uint32 = 0x4 24 | ENCLAVE_VBS_BASIC_KEY_FLAG_DEBUG_KEY uint32 = 0x8 25 | ) 26 | 27 | // enums 28 | 29 | // enum 30 | type ENCLAVE_SEALING_IDENTITY_POLICY int32 31 | 32 | const ( 33 | ENCLAVE_IDENTITY_POLICY_SEAL_INVALID ENCLAVE_SEALING_IDENTITY_POLICY = 0 34 | ENCLAVE_IDENTITY_POLICY_SEAL_EXACT_CODE ENCLAVE_SEALING_IDENTITY_POLICY = 1 35 | ENCLAVE_IDENTITY_POLICY_SEAL_SAME_PRIMARY_CODE ENCLAVE_SEALING_IDENTITY_POLICY = 2 36 | ENCLAVE_IDENTITY_POLICY_SEAL_SAME_IMAGE ENCLAVE_SEALING_IDENTITY_POLICY = 3 37 | ENCLAVE_IDENTITY_POLICY_SEAL_SAME_FAMILY ENCLAVE_SEALING_IDENTITY_POLICY = 4 38 | ENCLAVE_IDENTITY_POLICY_SEAL_SAME_AUTHOR ENCLAVE_SEALING_IDENTITY_POLICY = 5 39 | ) 40 | 41 | // structs 42 | 43 | type ENCLAVE_IDENTITY struct { 44 | OwnerId [32]byte 45 | UniqueId [32]byte 46 | AuthorId [32]byte 47 | FamilyId [16]byte 48 | ImageId [16]byte 49 | EnclaveSvn uint32 50 | SecureKernelSvn uint32 51 | PlatformSvn uint32 52 | Flags uint32 53 | SigningLevel uint32 54 | EnclaveType uint32 55 | } 56 | 57 | type VBS_ENCLAVE_REPORT_PKG_HEADER struct { 58 | PackageSize uint32 59 | Version uint32 60 | SignatureScheme uint32 61 | SignedStatementSize uint32 62 | SignatureSize uint32 63 | Reserved uint32 64 | } 65 | 66 | type VBS_ENCLAVE_REPORT struct { 67 | ReportSize uint32 68 | ReportVersion uint32 69 | EnclaveData [64]byte 70 | EnclaveIdentity ENCLAVE_IDENTITY 71 | } 72 | 73 | type VBS_ENCLAVE_REPORT_VARDATA_HEADER struct { 74 | DataType uint32 75 | Size uint32 76 | } 77 | 78 | type VBS_ENCLAVE_REPORT_MODULE struct { 79 | Header VBS_ENCLAVE_REPORT_VARDATA_HEADER 80 | UniqueId [32]byte 81 | AuthorId [32]byte 82 | FamilyId [16]byte 83 | ImageId [16]byte 84 | Svn uint32 85 | ModuleName [1]uint16 86 | } 87 | 88 | type ENCLAVE_INFORMATION struct { 89 | EnclaveType uint32 90 | Reserved uint32 91 | BaseAddress unsafe.Pointer 92 | Size uintptr 93 | Identity ENCLAVE_IDENTITY 94 | } 95 | 96 | type VBS_BASIC_ENCLAVE_THREAD_DESCRIPTOR32 struct { 97 | ThreadContext [4]uint32 98 | EntryPoint uint32 99 | StackPointer uint32 100 | ExceptionEntryPoint uint32 101 | ExceptionStack uint32 102 | ExceptionActive uint32 103 | } 104 | 105 | type VBS_BASIC_ENCLAVE_THREAD_DESCRIPTOR64 struct { 106 | ThreadContext [4]uint64 107 | EntryPoint uint64 108 | StackPointer uint64 109 | ExceptionEntryPoint uint64 110 | ExceptionStack uint64 111 | ExceptionActive uint32 112 | } 113 | 114 | type VBS_BASIC_ENCLAVE_EXCEPTION_AMD64 struct { 115 | ExceptionCode uint32 116 | NumberParameters uint32 117 | ExceptionInformation [3]uintptr 118 | ExceptionRAX uintptr 119 | ExceptionRCX uintptr 120 | ExceptionRIP uintptr 121 | ExceptionRFLAGS uintptr 122 | ExceptionRSP uintptr 123 | } 124 | 125 | type ENCLAVE_VBS_BASIC_KEY_REQUEST struct { 126 | RequestSize uint32 127 | Flags uint32 128 | EnclaveSVN uint32 129 | SystemKeyID uint32 130 | CurrentSystemKeyID uint32 131 | } 132 | 133 | type VBS_BASIC_ENCLAVE_SYSCALL_PAGE struct { 134 | ReturnFromEnclave VBS_BASIC_ENCLAVE_BASIC_CALL_RETURN_FROM_ENCLAVE 135 | ReturnFromException VBS_BASIC_ENCLAVE_BASIC_CALL_RETURN_FROM_EXCEPTION 136 | TerminateThread VBS_BASIC_ENCLAVE_BASIC_CALL_TERMINATE_THREAD 137 | InterruptThread VBS_BASIC_ENCLAVE_BASIC_CALL_INTERRUPT_THREAD 138 | CommitPages VBS_BASIC_ENCLAVE_BASIC_CALL_COMMIT_PAGES 139 | DecommitPages VBS_BASIC_ENCLAVE_BASIC_CALL_DECOMMIT_PAGES 140 | ProtectPages VBS_BASIC_ENCLAVE_BASIC_CALL_PROTECT_PAGES 141 | CreateThread VBS_BASIC_ENCLAVE_BASIC_CALL_CREATE_THREAD 142 | GetEnclaveInformation VBS_BASIC_ENCLAVE_BASIC_CALL_GET_ENCLAVE_INFORMATION 143 | GenerateKey VBS_BASIC_ENCLAVE_BASIC_CALL_GENERATE_KEY 144 | GenerateReport VBS_BASIC_ENCLAVE_BASIC_CALL_GENERATE_REPORT 145 | VerifyReport VBS_BASIC_ENCLAVE_BASIC_CALL_VERIFY_REPORT 146 | GenerateRandomData VBS_BASIC_ENCLAVE_BASIC_CALL_GENERATE_RANDOM_DATA 147 | } 148 | 149 | // func types 150 | 151 | type VBS_BASIC_ENCLAVE_BASIC_CALL_RETURN_FROM_EXCEPTION = uintptr 152 | type VBS_BASIC_ENCLAVE_BASIC_CALL_RETURN_FROM_EXCEPTION_func = func(ExceptionRecord *VBS_BASIC_ENCLAVE_EXCEPTION_AMD64) int32 153 | 154 | type VBS_BASIC_ENCLAVE_BASIC_CALL_TERMINATE_THREAD = uintptr 155 | type VBS_BASIC_ENCLAVE_BASIC_CALL_TERMINATE_THREAD_func = func(ThreadDescriptor *VBS_BASIC_ENCLAVE_THREAD_DESCRIPTOR64) int32 156 | 157 | type VBS_BASIC_ENCLAVE_BASIC_CALL_INTERRUPT_THREAD = uintptr 158 | type VBS_BASIC_ENCLAVE_BASIC_CALL_INTERRUPT_THREAD_func = func(ThreadDescriptor *VBS_BASIC_ENCLAVE_THREAD_DESCRIPTOR64) int32 159 | 160 | type VBS_BASIC_ENCLAVE_BASIC_CALL_CREATE_THREAD = uintptr 161 | type VBS_BASIC_ENCLAVE_BASIC_CALL_CREATE_THREAD_func = func(ThreadDescriptor *VBS_BASIC_ENCLAVE_THREAD_DESCRIPTOR64) int32 162 | 163 | type VBS_BASIC_ENCLAVE_BASIC_CALL_RETURN_FROM_ENCLAVE = uintptr 164 | type VBS_BASIC_ENCLAVE_BASIC_CALL_RETURN_FROM_ENCLAVE_func = func(ReturnValue uintptr) 165 | 166 | type VBS_BASIC_ENCLAVE_BASIC_CALL_COMMIT_PAGES = uintptr 167 | type VBS_BASIC_ENCLAVE_BASIC_CALL_COMMIT_PAGES_func = func(EnclaveAddress unsafe.Pointer, NumberOfBytes uintptr, SourceAddress unsafe.Pointer, PageProtection uint32) int32 168 | 169 | type VBS_BASIC_ENCLAVE_BASIC_CALL_DECOMMIT_PAGES = uintptr 170 | type VBS_BASIC_ENCLAVE_BASIC_CALL_DECOMMIT_PAGES_func = func(EnclaveAddress unsafe.Pointer, NumberOfBytes uintptr) int32 171 | 172 | type VBS_BASIC_ENCLAVE_BASIC_CALL_PROTECT_PAGES = uintptr 173 | type VBS_BASIC_ENCLAVE_BASIC_CALL_PROTECT_PAGES_func = func(EnclaveAddress unsafe.Pointer, NumberOfytes uintptr, PageProtection uint32) int32 174 | 175 | type VBS_BASIC_ENCLAVE_BASIC_CALL_GET_ENCLAVE_INFORMATION = uintptr 176 | type VBS_BASIC_ENCLAVE_BASIC_CALL_GET_ENCLAVE_INFORMATION_func = func(EnclaveInfo *ENCLAVE_INFORMATION) int32 177 | 178 | type VBS_BASIC_ENCLAVE_BASIC_CALL_GENERATE_KEY = uintptr 179 | type VBS_BASIC_ENCLAVE_BASIC_CALL_GENERATE_KEY_func = func(KeyRequest *ENCLAVE_VBS_BASIC_KEY_REQUEST, RequestedKeySize uint32, ReturnedKey *byte) int32 180 | 181 | type VBS_BASIC_ENCLAVE_BASIC_CALL_GENERATE_REPORT = uintptr 182 | type VBS_BASIC_ENCLAVE_BASIC_CALL_GENERATE_REPORT_func = func(EnclaveData *byte, Report unsafe.Pointer, BufferSize uint32, OutputSize *uint32) int32 183 | 184 | type VBS_BASIC_ENCLAVE_BASIC_CALL_VERIFY_REPORT = uintptr 185 | type VBS_BASIC_ENCLAVE_BASIC_CALL_VERIFY_REPORT_func = func(Report unsafe.Pointer, ReportSize uint32) int32 186 | 187 | type VBS_BASIC_ENCLAVE_BASIC_CALL_GENERATE_RANDOM_DATA = uintptr 188 | type VBS_BASIC_ENCLAVE_BASIC_CALL_GENERATE_RANDOM_DATA_func = func(Buffer *byte, NumberOfBytes uint32, Generation *uint64) int32 189 | 190 | var ( 191 | pSetEnvironmentStringsW uintptr 192 | pGetCommandLineA uintptr 193 | pGetCommandLineW uintptr 194 | pGetEnvironmentStrings uintptr 195 | pGetEnvironmentStringsW uintptr 196 | pFreeEnvironmentStringsA uintptr 197 | pFreeEnvironmentStringsW uintptr 198 | pGetEnvironmentVariableA uintptr 199 | pGetEnvironmentVariableW uintptr 200 | pSetEnvironmentVariableA uintptr 201 | pSetEnvironmentVariableW uintptr 202 | pExpandEnvironmentStringsA uintptr 203 | pExpandEnvironmentStringsW uintptr 204 | pSetCurrentDirectoryA uintptr 205 | pSetCurrentDirectoryW uintptr 206 | pGetCurrentDirectoryA uintptr 207 | pGetCurrentDirectoryW uintptr 208 | pNeedCurrentDirectoryForExePathA uintptr 209 | pNeedCurrentDirectoryForExePathW uintptr 210 | pCreateEnvironmentBlock uintptr 211 | pDestroyEnvironmentBlock uintptr 212 | pExpandEnvironmentStringsForUserA uintptr 213 | pExpandEnvironmentStringsForUserW uintptr 214 | pIsEnclaveTypeSupported uintptr 215 | pCreateEnclave uintptr 216 | pLoadEnclaveData uintptr 217 | pInitializeEnclave uintptr 218 | ) 219 | 220 | func SetEnvironmentStringsW(NewEnvironment PWSTR) BOOL { 221 | addr := LazyAddr(&pSetEnvironmentStringsW, libKernel32, "SetEnvironmentStringsW") 222 | ret, _, _ := syscall.SyscallN(addr, uintptr(unsafe.Pointer(NewEnvironment))) 223 | return BOOL(ret) 224 | } 225 | 226 | func GetCommandLineA() PSTR { 227 | addr := LazyAddr(&pGetCommandLineA, libKernel32, "GetCommandLineA") 228 | ret, _, _ := syscall.SyscallN(addr) 229 | return (PSTR)(unsafe.Pointer(ret)) 230 | } 231 | 232 | var GetCommandLine = GetCommandLineW 233 | 234 | func GetCommandLineW() PWSTR { 235 | addr := LazyAddr(&pGetCommandLineW, libKernel32, "GetCommandLineW") 236 | ret, _, _ := syscall.SyscallN(addr) 237 | return (PWSTR)(unsafe.Pointer(ret)) 238 | } 239 | 240 | func GetEnvironmentStrings() PSTR { 241 | addr := LazyAddr(&pGetEnvironmentStrings, libKernel32, "GetEnvironmentStrings") 242 | ret, _, _ := syscall.SyscallN(addr) 243 | return (PSTR)(unsafe.Pointer(ret)) 244 | } 245 | 246 | func GetEnvironmentStringsW() PWSTR { 247 | addr := LazyAddr(&pGetEnvironmentStringsW, libKernel32, "GetEnvironmentStringsW") 248 | ret, _, _ := syscall.SyscallN(addr) 249 | return (PWSTR)(unsafe.Pointer(ret)) 250 | } 251 | 252 | func FreeEnvironmentStringsA(penv PSTR) (BOOL, WIN32_ERROR) { 253 | addr := LazyAddr(&pFreeEnvironmentStringsA, libKernel32, "FreeEnvironmentStringsA") 254 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(penv))) 255 | return BOOL(ret), WIN32_ERROR(err) 256 | } 257 | 258 | var FreeEnvironmentStrings = FreeEnvironmentStringsW 259 | 260 | func FreeEnvironmentStringsW(penv PWSTR) (BOOL, WIN32_ERROR) { 261 | addr := LazyAddr(&pFreeEnvironmentStringsW, libKernel32, "FreeEnvironmentStringsW") 262 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(penv))) 263 | return BOOL(ret), WIN32_ERROR(err) 264 | } 265 | 266 | func GetEnvironmentVariableA(lpName PSTR, lpBuffer PSTR, nSize uint32) (uint32, WIN32_ERROR) { 267 | addr := LazyAddr(&pGetEnvironmentVariableA, libKernel32, "GetEnvironmentVariableA") 268 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpName)), uintptr(unsafe.Pointer(lpBuffer)), uintptr(nSize)) 269 | return uint32(ret), WIN32_ERROR(err) 270 | } 271 | 272 | var GetEnvironmentVariable = GetEnvironmentVariableW 273 | 274 | func GetEnvironmentVariableW(lpName PWSTR, lpBuffer PWSTR, nSize uint32) (uint32, WIN32_ERROR) { 275 | addr := LazyAddr(&pGetEnvironmentVariableW, libKernel32, "GetEnvironmentVariableW") 276 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpName)), uintptr(unsafe.Pointer(lpBuffer)), uintptr(nSize)) 277 | return uint32(ret), WIN32_ERROR(err) 278 | } 279 | 280 | func SetEnvironmentVariableA(lpName PSTR, lpValue PSTR) (BOOL, WIN32_ERROR) { 281 | addr := LazyAddr(&pSetEnvironmentVariableA, libKernel32, "SetEnvironmentVariableA") 282 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpName)), uintptr(unsafe.Pointer(lpValue))) 283 | return BOOL(ret), WIN32_ERROR(err) 284 | } 285 | 286 | var SetEnvironmentVariable = SetEnvironmentVariableW 287 | 288 | func SetEnvironmentVariableW(lpName PWSTR, lpValue PWSTR) (BOOL, WIN32_ERROR) { 289 | addr := LazyAddr(&pSetEnvironmentVariableW, libKernel32, "SetEnvironmentVariableW") 290 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpName)), uintptr(unsafe.Pointer(lpValue))) 291 | return BOOL(ret), WIN32_ERROR(err) 292 | } 293 | 294 | func ExpandEnvironmentStringsA(lpSrc PSTR, lpDst PSTR, nSize uint32) (uint32, WIN32_ERROR) { 295 | addr := LazyAddr(&pExpandEnvironmentStringsA, libKernel32, "ExpandEnvironmentStringsA") 296 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpSrc)), uintptr(unsafe.Pointer(lpDst)), uintptr(nSize)) 297 | return uint32(ret), WIN32_ERROR(err) 298 | } 299 | 300 | var ExpandEnvironmentStrings = ExpandEnvironmentStringsW 301 | 302 | func ExpandEnvironmentStringsW(lpSrc PWSTR, lpDst PWSTR, nSize uint32) (uint32, WIN32_ERROR) { 303 | addr := LazyAddr(&pExpandEnvironmentStringsW, libKernel32, "ExpandEnvironmentStringsW") 304 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpSrc)), uintptr(unsafe.Pointer(lpDst)), uintptr(nSize)) 305 | return uint32(ret), WIN32_ERROR(err) 306 | } 307 | 308 | func SetCurrentDirectoryA(lpPathName PSTR) BOOL { 309 | addr := LazyAddr(&pSetCurrentDirectoryA, libKernel32, "SetCurrentDirectoryA") 310 | ret, _, _ := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpPathName))) 311 | return BOOL(ret) 312 | } 313 | 314 | var SetCurrentDirectory = SetCurrentDirectoryW 315 | 316 | func SetCurrentDirectoryW(lpPathName PWSTR) BOOL { 317 | addr := LazyAddr(&pSetCurrentDirectoryW, libKernel32, "SetCurrentDirectoryW") 318 | ret, _, _ := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpPathName))) 319 | return BOOL(ret) 320 | } 321 | 322 | func GetCurrentDirectoryA(nBufferLength uint32, lpBuffer PSTR) uint32 { 323 | addr := LazyAddr(&pGetCurrentDirectoryA, libKernel32, "GetCurrentDirectoryA") 324 | ret, _, _ := syscall.SyscallN(addr, uintptr(nBufferLength), uintptr(unsafe.Pointer(lpBuffer))) 325 | return uint32(ret) 326 | } 327 | 328 | var GetCurrentDirectory = GetCurrentDirectoryW 329 | 330 | func GetCurrentDirectoryW(nBufferLength uint32, lpBuffer PWSTR) uint32 { 331 | addr := LazyAddr(&pGetCurrentDirectoryW, libKernel32, "GetCurrentDirectoryW") 332 | ret, _, _ := syscall.SyscallN(addr, uintptr(nBufferLength), uintptr(unsafe.Pointer(lpBuffer))) 333 | return uint32(ret) 334 | } 335 | 336 | func NeedCurrentDirectoryForExePathA(ExeName PSTR) BOOL { 337 | addr := LazyAddr(&pNeedCurrentDirectoryForExePathA, libKernel32, "NeedCurrentDirectoryForExePathA") 338 | ret, _, _ := syscall.SyscallN(addr, uintptr(unsafe.Pointer(ExeName))) 339 | return BOOL(ret) 340 | } 341 | 342 | var NeedCurrentDirectoryForExePath = NeedCurrentDirectoryForExePathW 343 | 344 | func NeedCurrentDirectoryForExePathW(ExeName PWSTR) BOOL { 345 | addr := LazyAddr(&pNeedCurrentDirectoryForExePathW, libKernel32, "NeedCurrentDirectoryForExePathW") 346 | ret, _, _ := syscall.SyscallN(addr, uintptr(unsafe.Pointer(ExeName))) 347 | return BOOL(ret) 348 | } 349 | 350 | func CreateEnvironmentBlock(lpEnvironment unsafe.Pointer, hToken HANDLE, bInherit BOOL) (BOOL, WIN32_ERROR) { 351 | addr := LazyAddr(&pCreateEnvironmentBlock, libUserenv, "CreateEnvironmentBlock") 352 | ret, _, err := syscall.SyscallN(addr, uintptr(lpEnvironment), hToken, uintptr(bInherit)) 353 | return BOOL(ret), WIN32_ERROR(err) 354 | } 355 | 356 | func DestroyEnvironmentBlock(lpEnvironment unsafe.Pointer) (BOOL, WIN32_ERROR) { 357 | addr := LazyAddr(&pDestroyEnvironmentBlock, libUserenv, "DestroyEnvironmentBlock") 358 | ret, _, err := syscall.SyscallN(addr, uintptr(lpEnvironment)) 359 | return BOOL(ret), WIN32_ERROR(err) 360 | } 361 | 362 | func ExpandEnvironmentStringsForUserA(hToken HANDLE, lpSrc PSTR, lpDest PSTR, dwSize uint32) (BOOL, WIN32_ERROR) { 363 | addr := LazyAddr(&pExpandEnvironmentStringsForUserA, libUserenv, "ExpandEnvironmentStringsForUserA") 364 | ret, _, err := syscall.SyscallN(addr, hToken, uintptr(unsafe.Pointer(lpSrc)), uintptr(unsafe.Pointer(lpDest)), uintptr(dwSize)) 365 | return BOOL(ret), WIN32_ERROR(err) 366 | } 367 | 368 | var ExpandEnvironmentStringsForUser = ExpandEnvironmentStringsForUserW 369 | 370 | func ExpandEnvironmentStringsForUserW(hToken HANDLE, lpSrc PWSTR, lpDest PWSTR, dwSize uint32) (BOOL, WIN32_ERROR) { 371 | addr := LazyAddr(&pExpandEnvironmentStringsForUserW, libUserenv, "ExpandEnvironmentStringsForUserW") 372 | ret, _, err := syscall.SyscallN(addr, hToken, uintptr(unsafe.Pointer(lpSrc)), uintptr(unsafe.Pointer(lpDest)), uintptr(dwSize)) 373 | return BOOL(ret), WIN32_ERROR(err) 374 | } 375 | 376 | func IsEnclaveTypeSupported(flEnclaveType uint32) (BOOL, WIN32_ERROR) { 377 | addr := LazyAddr(&pIsEnclaveTypeSupported, libKernel32, "IsEnclaveTypeSupported") 378 | ret, _, err := syscall.SyscallN(addr, uintptr(flEnclaveType)) 379 | return BOOL(ret), WIN32_ERROR(err) 380 | } 381 | 382 | func CreateEnclave(hProcess HANDLE, lpAddress unsafe.Pointer, dwSize uintptr, dwInitialCommitment uintptr, flEnclaveType uint32, lpEnclaveInformation unsafe.Pointer, dwInfoLength uint32, lpEnclaveError *uint32) (unsafe.Pointer, WIN32_ERROR) { 383 | addr := LazyAddr(&pCreateEnclave, libKernel32, "CreateEnclave") 384 | ret, _, err := syscall.SyscallN(addr, hProcess, uintptr(lpAddress), dwSize, dwInitialCommitment, uintptr(flEnclaveType), uintptr(lpEnclaveInformation), uintptr(dwInfoLength), uintptr(unsafe.Pointer(lpEnclaveError))) 385 | return (unsafe.Pointer)(ret), WIN32_ERROR(err) 386 | } 387 | 388 | func LoadEnclaveData(hProcess HANDLE, lpAddress unsafe.Pointer, lpBuffer unsafe.Pointer, nSize uintptr, flProtect uint32, lpPageInformation unsafe.Pointer, dwInfoLength uint32, lpNumberOfBytesWritten *uintptr, lpEnclaveError *uint32) (BOOL, WIN32_ERROR) { 389 | addr := LazyAddr(&pLoadEnclaveData, libKernel32, "LoadEnclaveData") 390 | ret, _, err := syscall.SyscallN(addr, hProcess, uintptr(lpAddress), uintptr(lpBuffer), nSize, uintptr(flProtect), uintptr(lpPageInformation), uintptr(dwInfoLength), uintptr(unsafe.Pointer(lpNumberOfBytesWritten)), uintptr(unsafe.Pointer(lpEnclaveError))) 391 | return BOOL(ret), WIN32_ERROR(err) 392 | } 393 | 394 | func InitializeEnclave(hProcess HANDLE, lpAddress unsafe.Pointer, lpEnclaveInformation unsafe.Pointer, dwInfoLength uint32, lpEnclaveError *uint32) (BOOL, WIN32_ERROR) { 395 | addr := LazyAddr(&pInitializeEnclave, libKernel32, "InitializeEnclave") 396 | ret, _, err := syscall.SyscallN(addr, hProcess, uintptr(lpAddress), uintptr(lpEnclaveInformation), uintptr(dwInfoLength), uintptr(unsafe.Pointer(lpEnclaveError))) 397 | return BOOL(ret), WIN32_ERROR(err) 398 | } 399 | -------------------------------------------------------------------------------- /win32/System.LibraryLoader.go: -------------------------------------------------------------------------------- 1 | package win32 2 | 3 | import ( 4 | "syscall" 5 | "unsafe" 6 | ) 7 | 8 | const ( 9 | FIND_RESOURCE_DIRECTORY_TYPES uint32 = 0x100 10 | FIND_RESOURCE_DIRECTORY_NAMES uint32 = 0x200 11 | FIND_RESOURCE_DIRECTORY_LANGUAGES uint32 = 0x400 12 | RESOURCE_ENUM_LN uint32 = 0x1 13 | RESOURCE_ENUM_MUI uint32 = 0x2 14 | RESOURCE_ENUM_MUI_SYSTEM uint32 = 0x4 15 | RESOURCE_ENUM_VALIDATE uint32 = 0x8 16 | RESOURCE_ENUM_MODULE_EXACT uint32 = 0x10 17 | SUPPORT_LANG_NUMBER uint32 = 0x20 18 | GET_MODULE_HANDLE_EX_FLAG_PIN uint32 = 0x1 19 | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT uint32 = 0x2 20 | GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS uint32 = 0x4 21 | CURRENT_IMPORT_REDIRECTION_VERSION uint32 = 0x1 22 | LOAD_LIBRARY_OS_INTEGRITY_CONTINUITY uint32 = 0x8000 23 | ) 24 | 25 | // enums 26 | 27 | // enum 28 | // flags 29 | type LOAD_LIBRARY_FLAGS uint32 30 | 31 | const ( 32 | DONT_RESOLVE_DLL_REFERENCES LOAD_LIBRARY_FLAGS = 1 33 | LOAD_LIBRARY_AS_DATAFILE LOAD_LIBRARY_FLAGS = 2 34 | LOAD_WITH_ALTERED_SEARCH_PATH LOAD_LIBRARY_FLAGS = 8 35 | LOAD_IGNORE_CODE_AUTHZ_LEVEL LOAD_LIBRARY_FLAGS = 16 36 | LOAD_LIBRARY_AS_IMAGE_RESOURCE LOAD_LIBRARY_FLAGS = 32 37 | LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE LOAD_LIBRARY_FLAGS = 64 38 | LOAD_LIBRARY_REQUIRE_SIGNED_TARGET LOAD_LIBRARY_FLAGS = 128 39 | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR LOAD_LIBRARY_FLAGS = 256 40 | LOAD_LIBRARY_SEARCH_APPLICATION_DIR LOAD_LIBRARY_FLAGS = 512 41 | LOAD_LIBRARY_SEARCH_USER_DIRS LOAD_LIBRARY_FLAGS = 1024 42 | LOAD_LIBRARY_SEARCH_SYSTEM32 LOAD_LIBRARY_FLAGS = 2048 43 | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS LOAD_LIBRARY_FLAGS = 4096 44 | LOAD_LIBRARY_SAFE_CURRENT_DIRS LOAD_LIBRARY_FLAGS = 8192 45 | LOAD_LIBRARY_SEARCH_SYSTEM32_NO_FORWARDER LOAD_LIBRARY_FLAGS = 16384 46 | ) 47 | 48 | // structs 49 | 50 | type ENUMUILANG struct { 51 | NumOfEnumUILang uint32 52 | SizeOfEnumUIBuffer uint32 53 | PEnumUIBuffer *uint16 54 | } 55 | 56 | type REDIRECTION_FUNCTION_DESCRIPTOR struct { 57 | DllName PSTR 58 | FunctionName PSTR 59 | RedirectionTarget unsafe.Pointer 60 | } 61 | 62 | type REDIRECTION_DESCRIPTOR struct { 63 | Version uint32 64 | FunctionCount uint32 65 | Redirections *REDIRECTION_FUNCTION_DESCRIPTOR 66 | } 67 | 68 | // func types 69 | 70 | type ENUMRESLANGPROCA = uintptr 71 | type ENUMRESLANGPROCA_func = func(hModule HMODULE, lpType PSTR, lpName PSTR, wLanguage uint16, lParam uintptr) BOOL 72 | 73 | type ENUMRESLANGPROCW = uintptr 74 | type ENUMRESLANGPROCW_func = func(hModule HMODULE, lpType PWSTR, lpName PWSTR, wLanguage uint16, lParam uintptr) BOOL 75 | 76 | type ENUMRESNAMEPROCA = uintptr 77 | type ENUMRESNAMEPROCA_func = func(hModule HMODULE, lpType PSTR, lpName PSTR, lParam uintptr) BOOL 78 | 79 | type ENUMRESNAMEPROCW = uintptr 80 | type ENUMRESNAMEPROCW_func = func(hModule HMODULE, lpType PWSTR, lpName PWSTR, lParam uintptr) BOOL 81 | 82 | type ENUMRESTYPEPROCA = uintptr 83 | type ENUMRESTYPEPROCA_func = func(hModule HMODULE, lpType PSTR, lParam uintptr) BOOL 84 | 85 | type ENUMRESTYPEPROCW = uintptr 86 | type ENUMRESTYPEPROCW_func = func(hModule HMODULE, lpType PWSTR, lParam uintptr) BOOL 87 | 88 | type PGET_MODULE_HANDLE_EXA = uintptr 89 | type PGET_MODULE_HANDLE_EXA_func = func(dwFlags uint32, lpModuleName PSTR, phModule *HMODULE) BOOL 90 | 91 | type PGET_MODULE_HANDLE_EXW = uintptr 92 | type PGET_MODULE_HANDLE_EXW_func = func(dwFlags uint32, lpModuleName PWSTR, phModule *HMODULE) BOOL 93 | 94 | var ( 95 | pDisableThreadLibraryCalls uintptr 96 | pFindResourceExW uintptr 97 | pFreeLibraryAndExitThread uintptr 98 | pFreeResource uintptr 99 | pGetModuleFileNameA uintptr 100 | pGetModuleFileNameW uintptr 101 | pGetModuleHandleA uintptr 102 | pGetModuleHandleW uintptr 103 | pGetModuleHandleExA uintptr 104 | pGetModuleHandleExW uintptr 105 | pGetProcAddress uintptr 106 | pLoadLibraryExA uintptr 107 | pLoadLibraryExW uintptr 108 | pLoadResource uintptr 109 | pLockResource uintptr 110 | pSizeofResource uintptr 111 | pAddDllDirectory uintptr 112 | pRemoveDllDirectory uintptr 113 | pSetDefaultDllDirectories uintptr 114 | pEnumResourceLanguagesExA uintptr 115 | pEnumResourceLanguagesExW uintptr 116 | pEnumResourceNamesExA uintptr 117 | pEnumResourceNamesExW uintptr 118 | pEnumResourceTypesExA uintptr 119 | pEnumResourceTypesExW uintptr 120 | pFindResourceW uintptr 121 | pLoadLibraryA uintptr 122 | pLoadLibraryW uintptr 123 | pEnumResourceNamesW uintptr 124 | pEnumResourceNamesA uintptr 125 | pLoadModule uintptr 126 | pLoadPackagedLibrary uintptr 127 | pFindResourceA uintptr 128 | pFindResourceExA uintptr 129 | pEnumResourceTypesA uintptr 130 | pEnumResourceTypesW uintptr 131 | pEnumResourceLanguagesA uintptr 132 | pEnumResourceLanguagesW uintptr 133 | pBeginUpdateResourceA uintptr 134 | pBeginUpdateResourceW uintptr 135 | pUpdateResourceA uintptr 136 | pUpdateResourceW uintptr 137 | pEndUpdateResourceA uintptr 138 | pEndUpdateResourceW uintptr 139 | pSetDllDirectoryA uintptr 140 | pSetDllDirectoryW uintptr 141 | pGetDllDirectoryA uintptr 142 | pGetDllDirectoryW uintptr 143 | ) 144 | 145 | func DisableThreadLibraryCalls(hLibModule HMODULE) (BOOL, WIN32_ERROR) { 146 | addr := LazyAddr(&pDisableThreadLibraryCalls, libKernel32, "DisableThreadLibraryCalls") 147 | ret, _, err := syscall.SyscallN(addr, hLibModule) 148 | return BOOL(ret), WIN32_ERROR(err) 149 | } 150 | 151 | var FindResourceEx = FindResourceExW 152 | 153 | func FindResourceExW(hModule HMODULE, lpType PWSTR, lpName PWSTR, wLanguage uint16) HRSRC { 154 | addr := LazyAddr(&pFindResourceExW, libKernel32, "FindResourceExW") 155 | ret, _, _ := syscall.SyscallN(addr, hModule, uintptr(unsafe.Pointer(lpType)), uintptr(unsafe.Pointer(lpName)), uintptr(wLanguage)) 156 | return ret 157 | } 158 | 159 | func FreeLibraryAndExitThread(hLibModule HMODULE, dwExitCode uint32) { 160 | addr := LazyAddr(&pFreeLibraryAndExitThread, libKernel32, "FreeLibraryAndExitThread") 161 | syscall.SyscallN(addr, hLibModule, uintptr(dwExitCode)) 162 | } 163 | 164 | func FreeResource(hResData HGLOBAL) BOOL { 165 | addr := LazyAddr(&pFreeResource, libKernel32, "FreeResource") 166 | ret, _, _ := syscall.SyscallN(addr, uintptr(unsafe.Pointer(hResData))) 167 | return BOOL(ret) 168 | } 169 | 170 | func GetModuleFileNameA(hModule HMODULE, lpFilename PSTR, nSize uint32) (uint32, WIN32_ERROR) { 171 | addr := LazyAddr(&pGetModuleFileNameA, libKernel32, "GetModuleFileNameA") 172 | ret, _, err := syscall.SyscallN(addr, hModule, uintptr(unsafe.Pointer(lpFilename)), uintptr(nSize)) 173 | return uint32(ret), WIN32_ERROR(err) 174 | } 175 | 176 | var GetModuleFileName = GetModuleFileNameW 177 | 178 | func GetModuleFileNameW(hModule HMODULE, lpFilename PWSTR, nSize uint32) (uint32, WIN32_ERROR) { 179 | addr := LazyAddr(&pGetModuleFileNameW, libKernel32, "GetModuleFileNameW") 180 | ret, _, err := syscall.SyscallN(addr, hModule, uintptr(unsafe.Pointer(lpFilename)), uintptr(nSize)) 181 | return uint32(ret), WIN32_ERROR(err) 182 | } 183 | 184 | func GetModuleHandleA(lpModuleName PSTR) (HMODULE, WIN32_ERROR) { 185 | addr := LazyAddr(&pGetModuleHandleA, libKernel32, "GetModuleHandleA") 186 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpModuleName))) 187 | return ret, WIN32_ERROR(err) 188 | } 189 | 190 | var GetModuleHandle = GetModuleHandleW 191 | 192 | func GetModuleHandleW(lpModuleName PWSTR) (HMODULE, WIN32_ERROR) { 193 | addr := LazyAddr(&pGetModuleHandleW, libKernel32, "GetModuleHandleW") 194 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpModuleName))) 195 | return ret, WIN32_ERROR(err) 196 | } 197 | 198 | func GetModuleHandleExA(dwFlags uint32, lpModuleName PSTR, phModule *HMODULE) (BOOL, WIN32_ERROR) { 199 | addr := LazyAddr(&pGetModuleHandleExA, libKernel32, "GetModuleHandleExA") 200 | ret, _, err := syscall.SyscallN(addr, uintptr(dwFlags), uintptr(unsafe.Pointer(lpModuleName)), uintptr(unsafe.Pointer(phModule))) 201 | return BOOL(ret), WIN32_ERROR(err) 202 | } 203 | 204 | var GetModuleHandleEx = GetModuleHandleExW 205 | 206 | func GetModuleHandleExW(dwFlags uint32, lpModuleName PWSTR, phModule *HMODULE) (BOOL, WIN32_ERROR) { 207 | addr := LazyAddr(&pGetModuleHandleExW, libKernel32, "GetModuleHandleExW") 208 | ret, _, err := syscall.SyscallN(addr, uintptr(dwFlags), uintptr(unsafe.Pointer(lpModuleName)), uintptr(unsafe.Pointer(phModule))) 209 | return BOOL(ret), WIN32_ERROR(err) 210 | } 211 | 212 | func GetProcAddress(hModule HMODULE, lpProcName PSTR) (FARPROC, WIN32_ERROR) { 213 | addr := LazyAddr(&pGetProcAddress, libKernel32, "GetProcAddress") 214 | ret, _, err := syscall.SyscallN(addr, hModule, uintptr(unsafe.Pointer(lpProcName))) 215 | return FARPROC(ret), WIN32_ERROR(err) 216 | } 217 | 218 | func LoadLibraryExA(lpLibFileName PSTR, hFile HANDLE, dwFlags LOAD_LIBRARY_FLAGS) (HMODULE, WIN32_ERROR) { 219 | addr := LazyAddr(&pLoadLibraryExA, libKernel32, "LoadLibraryExA") 220 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpLibFileName)), hFile, uintptr(dwFlags)) 221 | return ret, WIN32_ERROR(err) 222 | } 223 | 224 | var LoadLibraryEx = LoadLibraryExW 225 | 226 | func LoadLibraryExW(lpLibFileName PWSTR, hFile HANDLE, dwFlags LOAD_LIBRARY_FLAGS) (HMODULE, WIN32_ERROR) { 227 | addr := LazyAddr(&pLoadLibraryExW, libKernel32, "LoadLibraryExW") 228 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpLibFileName)), hFile, uintptr(dwFlags)) 229 | return ret, WIN32_ERROR(err) 230 | } 231 | 232 | func LoadResource(hModule HMODULE, hResInfo HRSRC) (HGLOBAL, WIN32_ERROR) { 233 | addr := LazyAddr(&pLoadResource, libKernel32, "LoadResource") 234 | ret, _, err := syscall.SyscallN(addr, hModule, hResInfo) 235 | return (HGLOBAL)(unsafe.Pointer(ret)), WIN32_ERROR(err) 236 | } 237 | 238 | func LockResource(hResData HGLOBAL) unsafe.Pointer { 239 | addr := LazyAddr(&pLockResource, libKernel32, "LockResource") 240 | ret, _, _ := syscall.SyscallN(addr, uintptr(unsafe.Pointer(hResData))) 241 | return (unsafe.Pointer)(ret) 242 | } 243 | 244 | func SizeofResource(hModule HMODULE, hResInfo HRSRC) (uint32, WIN32_ERROR) { 245 | addr := LazyAddr(&pSizeofResource, libKernel32, "SizeofResource") 246 | ret, _, err := syscall.SyscallN(addr, hModule, hResInfo) 247 | return uint32(ret), WIN32_ERROR(err) 248 | } 249 | 250 | func AddDllDirectory(NewDirectory PWSTR) (unsafe.Pointer, WIN32_ERROR) { 251 | addr := LazyAddr(&pAddDllDirectory, libKernel32, "AddDllDirectory") 252 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(NewDirectory))) 253 | return (unsafe.Pointer)(ret), WIN32_ERROR(err) 254 | } 255 | 256 | func RemoveDllDirectory(Cookie unsafe.Pointer) (BOOL, WIN32_ERROR) { 257 | addr := LazyAddr(&pRemoveDllDirectory, libKernel32, "RemoveDllDirectory") 258 | ret, _, err := syscall.SyscallN(addr, uintptr(Cookie)) 259 | return BOOL(ret), WIN32_ERROR(err) 260 | } 261 | 262 | func SetDefaultDllDirectories(DirectoryFlags LOAD_LIBRARY_FLAGS) (BOOL, WIN32_ERROR) { 263 | addr := LazyAddr(&pSetDefaultDllDirectories, libKernel32, "SetDefaultDllDirectories") 264 | ret, _, err := syscall.SyscallN(addr, uintptr(DirectoryFlags)) 265 | return BOOL(ret), WIN32_ERROR(err) 266 | } 267 | 268 | func EnumResourceLanguagesExA(hModule HMODULE, lpType PSTR, lpName PSTR, lpEnumFunc ENUMRESLANGPROCA, lParam uintptr, dwFlags uint32, LangId uint16) (BOOL, WIN32_ERROR) { 269 | addr := LazyAddr(&pEnumResourceLanguagesExA, libKernel32, "EnumResourceLanguagesExA") 270 | ret, _, err := syscall.SyscallN(addr, hModule, uintptr(unsafe.Pointer(lpType)), uintptr(unsafe.Pointer(lpName)), lpEnumFunc, lParam, uintptr(dwFlags), uintptr(LangId)) 271 | return BOOL(ret), WIN32_ERROR(err) 272 | } 273 | 274 | var EnumResourceLanguagesEx = EnumResourceLanguagesExW 275 | 276 | func EnumResourceLanguagesExW(hModule HMODULE, lpType PWSTR, lpName PWSTR, lpEnumFunc ENUMRESLANGPROCW, lParam uintptr, dwFlags uint32, LangId uint16) (BOOL, WIN32_ERROR) { 277 | addr := LazyAddr(&pEnumResourceLanguagesExW, libKernel32, "EnumResourceLanguagesExW") 278 | ret, _, err := syscall.SyscallN(addr, hModule, uintptr(unsafe.Pointer(lpType)), uintptr(unsafe.Pointer(lpName)), lpEnumFunc, lParam, uintptr(dwFlags), uintptr(LangId)) 279 | return BOOL(ret), WIN32_ERROR(err) 280 | } 281 | 282 | func EnumResourceNamesExA(hModule HMODULE, lpType PSTR, lpEnumFunc ENUMRESNAMEPROCA, lParam uintptr, dwFlags uint32, LangId uint16) (BOOL, WIN32_ERROR) { 283 | addr := LazyAddr(&pEnumResourceNamesExA, libKernel32, "EnumResourceNamesExA") 284 | ret, _, err := syscall.SyscallN(addr, hModule, uintptr(unsafe.Pointer(lpType)), lpEnumFunc, lParam, uintptr(dwFlags), uintptr(LangId)) 285 | return BOOL(ret), WIN32_ERROR(err) 286 | } 287 | 288 | var EnumResourceNamesEx = EnumResourceNamesExW 289 | 290 | func EnumResourceNamesExW(hModule HMODULE, lpType PWSTR, lpEnumFunc ENUMRESNAMEPROCW, lParam uintptr, dwFlags uint32, LangId uint16) (BOOL, WIN32_ERROR) { 291 | addr := LazyAddr(&pEnumResourceNamesExW, libKernel32, "EnumResourceNamesExW") 292 | ret, _, err := syscall.SyscallN(addr, hModule, uintptr(unsafe.Pointer(lpType)), lpEnumFunc, lParam, uintptr(dwFlags), uintptr(LangId)) 293 | return BOOL(ret), WIN32_ERROR(err) 294 | } 295 | 296 | func EnumResourceTypesExA(hModule HMODULE, lpEnumFunc ENUMRESTYPEPROCA, lParam uintptr, dwFlags uint32, LangId uint16) (BOOL, WIN32_ERROR) { 297 | addr := LazyAddr(&pEnumResourceTypesExA, libKernel32, "EnumResourceTypesExA") 298 | ret, _, err := syscall.SyscallN(addr, hModule, lpEnumFunc, lParam, uintptr(dwFlags), uintptr(LangId)) 299 | return BOOL(ret), WIN32_ERROR(err) 300 | } 301 | 302 | var EnumResourceTypesEx = EnumResourceTypesExW 303 | 304 | func EnumResourceTypesExW(hModule HMODULE, lpEnumFunc ENUMRESTYPEPROCW, lParam uintptr, dwFlags uint32, LangId uint16) (BOOL, WIN32_ERROR) { 305 | addr := LazyAddr(&pEnumResourceTypesExW, libKernel32, "EnumResourceTypesExW") 306 | ret, _, err := syscall.SyscallN(addr, hModule, lpEnumFunc, lParam, uintptr(dwFlags), uintptr(LangId)) 307 | return BOOL(ret), WIN32_ERROR(err) 308 | } 309 | 310 | var FindResource = FindResourceW 311 | 312 | func FindResourceW(hModule HMODULE, lpName PWSTR, lpType PWSTR) HRSRC { 313 | addr := LazyAddr(&pFindResourceW, libKernel32, "FindResourceW") 314 | ret, _, _ := syscall.SyscallN(addr, hModule, uintptr(unsafe.Pointer(lpName)), uintptr(unsafe.Pointer(lpType))) 315 | return ret 316 | } 317 | 318 | func LoadLibraryA(lpLibFileName PSTR) (HMODULE, WIN32_ERROR) { 319 | addr := LazyAddr(&pLoadLibraryA, libKernel32, "LoadLibraryA") 320 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpLibFileName))) 321 | return ret, WIN32_ERROR(err) 322 | } 323 | 324 | var LoadLibrary = LoadLibraryW 325 | 326 | func LoadLibraryW(lpLibFileName PWSTR) (HMODULE, WIN32_ERROR) { 327 | addr := LazyAddr(&pLoadLibraryW, libKernel32, "LoadLibraryW") 328 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpLibFileName))) 329 | return ret, WIN32_ERROR(err) 330 | } 331 | 332 | var EnumResourceNames = EnumResourceNamesW 333 | 334 | func EnumResourceNamesW(hModule HMODULE, lpType PWSTR, lpEnumFunc ENUMRESNAMEPROCW, lParam uintptr) BOOL { 335 | addr := LazyAddr(&pEnumResourceNamesW, libKernel32, "EnumResourceNamesW") 336 | ret, _, _ := syscall.SyscallN(addr, hModule, uintptr(unsafe.Pointer(lpType)), lpEnumFunc, lParam) 337 | return BOOL(ret) 338 | } 339 | 340 | func EnumResourceNamesA(hModule HMODULE, lpType PSTR, lpEnumFunc ENUMRESNAMEPROCA, lParam uintptr) (BOOL, WIN32_ERROR) { 341 | addr := LazyAddr(&pEnumResourceNamesA, libKernel32, "EnumResourceNamesA") 342 | ret, _, err := syscall.SyscallN(addr, hModule, uintptr(unsafe.Pointer(lpType)), lpEnumFunc, lParam) 343 | return BOOL(ret), WIN32_ERROR(err) 344 | } 345 | 346 | func LoadModule(lpModuleName PSTR, lpParameterBlock unsafe.Pointer) uint32 { 347 | addr := LazyAddr(&pLoadModule, libKernel32, "LoadModule") 348 | ret, _, _ := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpModuleName)), uintptr(lpParameterBlock)) 349 | return uint32(ret) 350 | } 351 | 352 | func LoadPackagedLibrary(lpwLibFileName PWSTR, Reserved uint32) (HMODULE, WIN32_ERROR) { 353 | addr := LazyAddr(&pLoadPackagedLibrary, libKernel32, "LoadPackagedLibrary") 354 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpwLibFileName)), uintptr(Reserved)) 355 | return ret, WIN32_ERROR(err) 356 | } 357 | 358 | func FindResourceA(hModule HMODULE, lpName PSTR, lpType PSTR) (HRSRC, WIN32_ERROR) { 359 | addr := LazyAddr(&pFindResourceA, libKernel32, "FindResourceA") 360 | ret, _, err := syscall.SyscallN(addr, hModule, uintptr(unsafe.Pointer(lpName)), uintptr(unsafe.Pointer(lpType))) 361 | return ret, WIN32_ERROR(err) 362 | } 363 | 364 | func FindResourceExA(hModule HMODULE, lpType PSTR, lpName PSTR, wLanguage uint16) (HRSRC, WIN32_ERROR) { 365 | addr := LazyAddr(&pFindResourceExA, libKernel32, "FindResourceExA") 366 | ret, _, err := syscall.SyscallN(addr, hModule, uintptr(unsafe.Pointer(lpType)), uintptr(unsafe.Pointer(lpName)), uintptr(wLanguage)) 367 | return ret, WIN32_ERROR(err) 368 | } 369 | 370 | func EnumResourceTypesA(hModule HMODULE, lpEnumFunc ENUMRESTYPEPROCA, lParam uintptr) (BOOL, WIN32_ERROR) { 371 | addr := LazyAddr(&pEnumResourceTypesA, libKernel32, "EnumResourceTypesA") 372 | ret, _, err := syscall.SyscallN(addr, hModule, lpEnumFunc, lParam) 373 | return BOOL(ret), WIN32_ERROR(err) 374 | } 375 | 376 | var EnumResourceTypes = EnumResourceTypesW 377 | 378 | func EnumResourceTypesW(hModule HMODULE, lpEnumFunc ENUMRESTYPEPROCW, lParam uintptr) (BOOL, WIN32_ERROR) { 379 | addr := LazyAddr(&pEnumResourceTypesW, libKernel32, "EnumResourceTypesW") 380 | ret, _, err := syscall.SyscallN(addr, hModule, lpEnumFunc, lParam) 381 | return BOOL(ret), WIN32_ERROR(err) 382 | } 383 | 384 | func EnumResourceLanguagesA(hModule HMODULE, lpType PSTR, lpName PSTR, lpEnumFunc ENUMRESLANGPROCA, lParam uintptr) (BOOL, WIN32_ERROR) { 385 | addr := LazyAddr(&pEnumResourceLanguagesA, libKernel32, "EnumResourceLanguagesA") 386 | ret, _, err := syscall.SyscallN(addr, hModule, uintptr(unsafe.Pointer(lpType)), uintptr(unsafe.Pointer(lpName)), lpEnumFunc, lParam) 387 | return BOOL(ret), WIN32_ERROR(err) 388 | } 389 | 390 | var EnumResourceLanguages = EnumResourceLanguagesW 391 | 392 | func EnumResourceLanguagesW(hModule HMODULE, lpType PWSTR, lpName PWSTR, lpEnumFunc ENUMRESLANGPROCW, lParam uintptr) (BOOL, WIN32_ERROR) { 393 | addr := LazyAddr(&pEnumResourceLanguagesW, libKernel32, "EnumResourceLanguagesW") 394 | ret, _, err := syscall.SyscallN(addr, hModule, uintptr(unsafe.Pointer(lpType)), uintptr(unsafe.Pointer(lpName)), lpEnumFunc, lParam) 395 | return BOOL(ret), WIN32_ERROR(err) 396 | } 397 | 398 | func BeginUpdateResourceA(pFileName PSTR, bDeleteExistingResources BOOL) (HANDLE, WIN32_ERROR) { 399 | addr := LazyAddr(&pBeginUpdateResourceA, libKernel32, "BeginUpdateResourceA") 400 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(pFileName)), uintptr(bDeleteExistingResources)) 401 | return ret, WIN32_ERROR(err) 402 | } 403 | 404 | var BeginUpdateResource = BeginUpdateResourceW 405 | 406 | func BeginUpdateResourceW(pFileName PWSTR, bDeleteExistingResources BOOL) (HANDLE, WIN32_ERROR) { 407 | addr := LazyAddr(&pBeginUpdateResourceW, libKernel32, "BeginUpdateResourceW") 408 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(pFileName)), uintptr(bDeleteExistingResources)) 409 | return ret, WIN32_ERROR(err) 410 | } 411 | 412 | func UpdateResourceA(hUpdate HANDLE, lpType PSTR, lpName PSTR, wLanguage uint16, lpData unsafe.Pointer, cb uint32) (BOOL, WIN32_ERROR) { 413 | addr := LazyAddr(&pUpdateResourceA, libKernel32, "UpdateResourceA") 414 | ret, _, err := syscall.SyscallN(addr, hUpdate, uintptr(unsafe.Pointer(lpType)), uintptr(unsafe.Pointer(lpName)), uintptr(wLanguage), uintptr(lpData), uintptr(cb)) 415 | return BOOL(ret), WIN32_ERROR(err) 416 | } 417 | 418 | var UpdateResource = UpdateResourceW 419 | 420 | func UpdateResourceW(hUpdate HANDLE, lpType PWSTR, lpName PWSTR, wLanguage uint16, lpData unsafe.Pointer, cb uint32) (BOOL, WIN32_ERROR) { 421 | addr := LazyAddr(&pUpdateResourceW, libKernel32, "UpdateResourceW") 422 | ret, _, err := syscall.SyscallN(addr, hUpdate, uintptr(unsafe.Pointer(lpType)), uintptr(unsafe.Pointer(lpName)), uintptr(wLanguage), uintptr(lpData), uintptr(cb)) 423 | return BOOL(ret), WIN32_ERROR(err) 424 | } 425 | 426 | func EndUpdateResourceA(hUpdate HANDLE, fDiscard BOOL) (BOOL, WIN32_ERROR) { 427 | addr := LazyAddr(&pEndUpdateResourceA, libKernel32, "EndUpdateResourceA") 428 | ret, _, err := syscall.SyscallN(addr, hUpdate, uintptr(fDiscard)) 429 | return BOOL(ret), WIN32_ERROR(err) 430 | } 431 | 432 | var EndUpdateResource = EndUpdateResourceW 433 | 434 | func EndUpdateResourceW(hUpdate HANDLE, fDiscard BOOL) (BOOL, WIN32_ERROR) { 435 | addr := LazyAddr(&pEndUpdateResourceW, libKernel32, "EndUpdateResourceW") 436 | ret, _, err := syscall.SyscallN(addr, hUpdate, uintptr(fDiscard)) 437 | return BOOL(ret), WIN32_ERROR(err) 438 | } 439 | 440 | func SetDllDirectoryA(lpPathName PSTR) (BOOL, WIN32_ERROR) { 441 | addr := LazyAddr(&pSetDllDirectoryA, libKernel32, "SetDllDirectoryA") 442 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpPathName))) 443 | return BOOL(ret), WIN32_ERROR(err) 444 | } 445 | 446 | var SetDllDirectory = SetDllDirectoryW 447 | 448 | func SetDllDirectoryW(lpPathName PWSTR) (BOOL, WIN32_ERROR) { 449 | addr := LazyAddr(&pSetDllDirectoryW, libKernel32, "SetDllDirectoryW") 450 | ret, _, err := syscall.SyscallN(addr, uintptr(unsafe.Pointer(lpPathName))) 451 | return BOOL(ret), WIN32_ERROR(err) 452 | } 453 | 454 | func GetDllDirectoryA(nBufferLength uint32, lpBuffer PSTR) (uint32, WIN32_ERROR) { 455 | addr := LazyAddr(&pGetDllDirectoryA, libKernel32, "GetDllDirectoryA") 456 | ret, _, err := syscall.SyscallN(addr, uintptr(nBufferLength), uintptr(unsafe.Pointer(lpBuffer))) 457 | return uint32(ret), WIN32_ERROR(err) 458 | } 459 | 460 | var GetDllDirectory = GetDllDirectoryW 461 | 462 | func GetDllDirectoryW(nBufferLength uint32, lpBuffer PWSTR) (uint32, WIN32_ERROR) { 463 | addr := LazyAddr(&pGetDllDirectoryW, libKernel32, "GetDllDirectoryW") 464 | ret, _, err := syscall.SyscallN(addr, uintptr(nBufferLength), uintptr(unsafe.Pointer(lpBuffer))) 465 | return uint32(ret), WIN32_ERROR(err) 466 | } 467 | --------------------------------------------------------------------------------