Jason A. Donenfeld
94ec62e081
windows: add SetNamedPipeHandleState
...
I added GetNamedPipeHandleState before but forgot the setter function,
which winds up being useful for namedpipe's tests.
Change-Id: Iefeabb2ac9584ec15e18e2ae7e4a72fbb46cbe7c
Reviewed-on: https://go-review.googlesource.com/c/sys/+/299209
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
2021-03-09 04:02:21 +00:00
Jason A. Donenfeld
8fe3ee5dd7
windows: return ERROR_ALREADY_EXIST for non-nil handle in Create* functions
...
These functions sometimes return a non-nil value, while indicating
ERROR_ALREADY_EXISTS through GetLastError. In this case, return the
error along with the handle, to indicate the case.
Fixes golang/go#44539 .
Change-Id: Id18e64724e57f62a34d6562511d9eafa8e6f9a3e
Reviewed-on: https://go-review.googlesource.com/c/sys/+/297332
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Ian Lance Taylor <iant@golang.org >
Reviewed-by: Alex Brainman <alex.brainman@gmail.com >
2021-03-05 23:01:14 +00:00
Jason A. Donenfeld
5cdee2b1b5
windows: correct NT definitions and add more resolution
...
Alex pointed out that some of these original types were incomplete, so
this commit fills things out a bit more. We also add more to the test
case.
Change-Id: Iff7bd9ea6e0d021ba997c6d7351fe7c4a46187a9
Reviewed-on: https://go-review.googlesource.com/c/sys/+/299189
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
2021-03-05 21:54:15 +00:00
Jason A. Donenfeld
61f932b4c6
windows: add QueryFullProcessImageName
...
This will be useful for reworking the IsWindowsService function in
svc/.
Change-Id: Ie1f7a560d7e81ee4ac3055e04748b6f9c8234edb
Reviewed-on: https://go-review.googlesource.com/c/sys/+/298829
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
2021-03-05 03:01:59 +00:00
Jason A. Donenfeld
0d6cb8bd5a
windows: add ole32 instantiation functions
...
These are basic functions for getting function pointers to instantiated
OLE objects.
Change-Id: I5a3d179d6da2af006b6e11def18280959bb9bd98
Reviewed-on: https://go-review.googlesource.com/c/sys/+/298469
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
2021-03-05 02:34:07 +00:00
Jason A. Donenfeld
f9bc61c02a
windows: add resource extraction functions
...
These functions make it possible to read executable resource information
at runtime.
Change-Id: I00f260199ecda8daeb3417eaa9c02198663063b7
Reviewed-on: https://go-review.googlesource.com/c/sys/+/298173
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Trust: Brad Fitzpatrick <bradfitz@golang.org >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
TryBot-Result: Go Bot <gobot@golang.org >
2021-03-05 02:33:59 +00:00
Jason A. Donenfeld
7b4935edff
windows: add pipe creation win32 APIs
...
These remaining APIs will make it possible to implement a win32 pipe
library using x/sys/windows.
Change-Id: If0cacedb7857c013c03e15cb6330b474cc010581
Reviewed-on: https://go-review.googlesource.com/c/sys/+/298172
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
2021-03-04 20:38:40 +00:00
Jason A. Donenfeld
1243437a8e
windows: add various NT APIs
...
In anticipation of the next commit which adds win32 pipe APIs, add some
of the foundational NT APIs for that, which will be required for making
a robust Go pipe library. Also add a simple test case.
Change-Id: I898bd6c5265a8939a7f05a24c4d9b22941dc56b7
Reviewed-on: https://go-review.googlesource.com/c/sys/+/298171
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
2021-03-04 20:34:36 +00:00
Jason A. Donenfeld
444254391f
windows: treat proc thread attribute lists as unsafe.Pointers
...
It turns out that the proc thread update function doesn't actually
allocate new memory for its arguments and instead just copies the
pointer values into the preallocated memory. Since we were allocating
that memory as []byte, the garbage collector didn't scan it for pointers
to Go allocations and freed them. We _could_ fix this by requiring that
all users of this use runtime.KeepAlive for everything they pass to the
update function, but that seems harder than necessary. Instead, we can
just do the allocation as []unsafe.Pointer, which means the GC can
operate as intended and not free these from beneath our feet. In order
to ensure this remains true, we also add a test for this.
Updates golang/go#44662 .
Change-Id: Iaa8b694a6682cc1876879632c7ba068e47b8666d
Reviewed-on: https://go-review.googlesource.com/c/sys/+/297331
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Trust: Bryan C. Mills <bcmills@google.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Ian Lance Taylor <iant@golang.org >
2021-03-04 19:59:27 +00:00
Jason A. Donenfeld
afaa3650a9
windows: do not write LastStatus parameter of TEB when converting errors
...
The prior function updated the TEB's LastStatus member, which is not
what we want to be doing here. It's also not consistent with Microsoft's
own Go code for their pipe library, which properly uses the "NoTeb"
variant like this commit.
For good measure, we add a simple test case to make sure these paths are
being exercised.
Change-Id: I4080898f704bdc93a6048001b06ffce516fb412d
Reviewed-on: https://go-review.googlesource.com/c/sys/+/298169
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
2021-03-04 15:22:09 +00:00
Jason A. Donenfeld
134d130e1a
windows: add support for NTSTATUS values
...
The native NT API returns error values from a different namespace as the
usual Win32 one. This means it needs to be typed differently. This
commit adds broad support for using NTSTATUS values in a new type called
NTStatus.
First we add the type as a basic uint32. Then we add all of the
predefined constants from ntstatus.h, by augmenting mkerrors.bash to do
automatic extraction. There's a convenece way to convert an NT error to
a Win32 error, so we add the NTStatus.Errno() function. Since NTStatus
is an error type, we define an Error() function that returns a string by
asking ntdll.dll for its contents, in the exact same way that
syscall.Errno.Error() does, by calling FormatMessage. Since functions
need to actually use this, we add the rule that if a `//sys` declaration
returns an error value called "ntstatus", then the type underlying the
error interface is an NTStatus instead of an Errno. Finally we fix one
function that was returning an error interface of an Errno rather than
an NTStatus.
Change-Id: I06296b9563bbec526759d12a19f13ac6ad46dcc3
Reviewed-on: https://go-review.googlesource.com/c/sys/+/297330
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Trust: Alex Brainman <alex.brainman@gmail.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
2021-03-03 07:41:36 +00:00
Tobias Kohlbau
479acdf4ea
windows: add support for CommTimeouts
...
CommTimeouts allows the user to set the timeout on Comm devices:
docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setcommtimeouts
docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getcommtimeouts
Change-Id: I756dc93b1b01412a496c6eccab22c9ff7e5f4b83
Reviewed-on: https://go-review.googlesource.com/c/sys/+/290209
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com >
Reviewed-by: Alex Brainman <alex.brainman@gmail.com >
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Trust: Alex Brainman <alex.brainman@gmail.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
2021-02-28 01:22:17 +00:00
Jason A. Donenfeld
f36f78243c
windows: add definitions and functions for ProcThreadAttributeList
...
The bulk of the documentation for these is in:
https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-updateprocthreadattribute
This allows creating processes from scratch that use advanced options,
such as changing the process parent.
Fixes golang/go#44005 .
Change-Id: Id5cc5400541e57710b9e888cd37ef4f925d510fe
Reviewed-on: https://go-review.googlesource.com/c/sys/+/288412
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Trust: Alex Brainman <alex.brainman@gmail.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Alex Brainman <alex.brainman@gmail.com >
2021-02-26 18:17:00 +00:00
Jason A. Donenfeld
683adc9d29
windows: do not overflow key memory in GetQueuedCompletionStatus
...
The third argument to GetQueuedCompletionStatus is a pointer to a
uintptr, not a uint32. Users of this functions have therefore been
corrupting their memory every time they used it. Either that memory
corruption was silent (dangerous), or their programs didn't work so they
chose a different API to use.
Updates golang/go#44538 .
Change-Id: Ie1f66de11001cf9c8195afaa61f003a86f821a95
Reviewed-on: https://go-review.googlesource.com/c/sys/+/295174
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Bryan C. Mills <bcmills@google.com >
2021-02-25 01:42:09 +00:00
Jason A. Donenfeld
eede4237b3
windows: add WSASocket
...
Simple function to complement the other ws2 functions we have:
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketw
Change-Id: Idf6b17360d84a8529e48ab94561c4ac7bee1d847
Reviewed-on: https://go-review.googlesource.com/c/sys/+/295175
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Trust: Alex Brainman <alex.brainman@gmail.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Alex Brainman <alex.brainman@gmail.com >
2021-02-23 21:21:15 +00:00
Boshi LIAN
3351caf150
windows: add CertFindCertificateInStore, CertFindChainInStore and CryptAcquireCertificatePrivateKey
...
add cert loading related syscall
CertFindCertificateInStore [1]
CertFindChainInStore [2]
CryptAcquireCertificatePrivateKey [3]
[1] https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-certfindcertificateinstore
[2] https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-certfindchaininstore
[3] https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptacquirecertificateprivatekey
Change-Id: I179bffd06d714d729f3afd83687336edecae6b37
GitHub-Last-Rev: 58a8c666c8
GitHub-Pull-Request: golang/sys#94
Reviewed-on: https://go-review.googlesource.com/c/sys/+/281012
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com >
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Trust: Alex Brainman <alex.brainman@gmail.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
2021-02-19 17:27:56 +00:00
Jason A. Donenfeld
1d476976d1
windows: add support for DPAPI
...
DPAPI allows machine or user-based blob encryption, using APIs from
crypt32:
https://docs.microsoft.com/en-us/windows/win32/api/dpapi/nf-dpapi-cryptunprotectdata
https://docs.microsoft.com/en-us/windows/win32/api/dpapi/nf-dpapi-cryptprotectdata
Change-Id: I57fb4f1877a5fb7629809e79111cbfa02b11cca3
Reviewed-on: https://go-review.googlesource.com/c/sys/+/285716
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
2021-01-23 23:11:50 +00:00
Jason A. Donenfeld
07034700bc
windows: add WinVerifyTrustEx function
...
This commit adds the function and the required structs for it. This is
the same as the WinVerifyTrust function but has the more correct
signature.
https://docs.microsoft.com/en-us/windows/win32/api/wintrust/nf-wintrust-winverifytrustex
Change-Id: I43ae20302ba85a6ae1fc32ad4c34b59bee0a6a35
Reviewed-on: https://go-review.googlesource.com/c/sys/+/285715
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
2021-01-23 23:11:35 +00:00
Jason A. Donenfeld
4df39788e6
windows: add missing crypt/cert API functions for examining certificate objects
...
This adds these functions and the various enums and constants required
to use them:
https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptdecodeobject
https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptqueryobject
https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-certgetnamestringw
https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-certfindextension
We also use this opportunity to clean up formatting of the previous
crypt APIs added: a few lines slipped in that used "//sys ", with
spaces, instead of "//sys\t" with a tab. This fixes that up for
consistency.
Change-Id: I925d3d29b5255f70ee2368e8906c45b8b22115ce
Reviewed-on: https://go-review.googlesource.com/c/sys/+/285714
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
2021-01-23 23:10:56 +00:00
Jason A. Donenfeld
a8b976e07c
windows: add Find*ChangeNotification APIs for file and directory monitoring
...
https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findfirstchangenotificationw
https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findnextchangenotification
https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findclosechangenotification
Change-Id: If7abfd63cd7a60e7f95ffad9aca2b7b7b74c94f0
Reviewed-on: https://go-review.googlesource.com/c/sys/+/285713
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
2021-01-22 23:57:52 +00:00
Jason A. Donenfeld
04d7465088
windows: correct signature of recently added GetWindowThreadProcessId
...
This function returns 0 and sets last error on failure. While this isn't
said explicitly on MSDN, there's no PID 0, and trivial reverse
engineering shows that this is the case. For example:
.text:00000001800035ED loc_1800035ED: ; CODE XREF: GetWindowThreadProcessId+23↑j
.text:00000001800035ED ; GetWindowThreadProcessId+3D↑j ...
.text:00000001800035ED mov ecx, 578h ; LastError
.text:00000001800035F2 call cs:__imp_RtlSetLastWin32Error
.text:00000001800035F9 nop dword ptr [rax+rax+00h]
.text:00000001800035FE
.text:00000001800035FE loc_1800035FE: ; CODE XREF: GetWindowThreadProcessId+65↑j
.text:00000001800035FE xor eax, eax
.text:0000000180003600 jmp short loc_1800035AA
This function was also just added by a user who is likely its only
consumer, so this error is not too late to fix.
Change-Id: I5dd24e78c006686bb8f1288ad0fe63cd67df56a6
Reviewed-on: https://go-review.googlesource.com/c/sys/+/285272
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Trust: Alex Brainman <alex.brainman@gmail.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Alex Brainman <alex.brainman@gmail.com >
2021-01-22 09:31:01 +00:00
Alex Brainman
59c308dcf3
windows: use HWND type in MessageBox, GetShellWindow and GetWindowThreadProcessId
...
This matches usual win32api conventions. While we're at it, we
group together user32.dll functions together.
This CL was based on CL 282634 with all but MessageBox, GetShellWindow
and GetWindowThreadProcessId changes removed to prevent compatibility
break.
Change-Id: I7e17c581723c41580a49c5612cabc7a5c13c0f15
Reviewed-on: https://go-review.googlesource.com/c/sys/+/282972
Run-TryBot: Alex Brainman <alex.brainman@gmail.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
Trust: Alex Brainman <alex.brainman@gmail.com >
2021-01-12 09:13:31 +00:00
Alex Brainman
0df2131ae3
windows: add GetShellWindow and GetWindowThreadProcessId
...
I am trying to implement
https://devblogs.microsoft.com/oldnewthing/20190425-00/?p=102443
so I need these functions.
Change-Id: Id5082e4cc450569ffd021f4a300d56de325e4952
Reviewed-on: https://go-review.googlesource.com/c/sys/+/280717
Trust: Alex Brainman <alex.brainman@gmail.com >
Trust: Brad Fitzpatrick <bradfitz@golang.org >
Run-TryBot: Alex Brainman <alex.brainman@gmail.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
2021-01-08 17:29:13 +00:00
Boshi LIAN
2d18734c60
windows: add PFXImportCertStore and CertDuplicateCertificateContext
...
add 2 new cert related dll call
PFXImportCertStore [1]
CertDuplicateCertificateContext [2]
also, add missing flags for CertCloseStore [3]
[1] https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-pfximportcertstore
[2] https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-certduplicatecertificatecontext
[3] https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-certclosestore
Change-Id: Ia44100ddb2cac1c2a817932c859926e8183dcda0
GitHub-Last-Rev: f3cd41859d
GitHub-Pull-Request: golang/sys#93
Reviewed-on: https://go-review.googlesource.com/c/sys/+/273907
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com >
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Trust: Alex Brainman <alex.brainman@gmail.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
2020-12-31 18:44:35 +00:00
Josh Bleecher Snyder
7e3030f880
windows: add RegNotifyChangeKeyValue syscall
...
Change-Id: If1a1b6ad1935bfaacb9e6a99fb9ade056169ccb2
Reviewed-on: https://go-review.googlesource.com/c/sys/+/277152
Trust: Josh Bleecher Snyder <josharian@gmail.com >
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
2020-12-10 22:38:39 +00:00
Jason A. Donenfeld
c9906e3070
windows: add SubscribeServiceChangeNotifications for service tracking
...
Windows 8+ introduced SubscribeServiceChangeNotifications for simpler
and more reliable service event tracking. This commit adds the function
and related constants:
https://docs.microsoft.com/en-us/windows/win32/services/subscribeservicechangenotifications
Since these functions are only available on Windows 8+, and Go supports
Windows 7+, we mark them with "?" so that the caller can handle graceful
degradation.
Change-Id: Ibb9708bbe797408701c70b4b1c715381f33cb8ee
Reviewed-on: https://go-review.googlesource.com/c/sys/+/274576
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Alex Brainman <alex.brainman@gmail.com >
Trust: Alex Brainman <alex.brainman@gmail.com >
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
2020-12-04 22:54:10 +00:00
Boshi Lian
111129e158
windows: correct CertOpenStore to expect a 0 return value on failure
...
According to [1], this function returns NULL when it errors, rather than
INVALID_HANDLE_VALUE, which other Win32 functions return. Quick reversing
indicates that [1] is correct, as there's a `xor eax, eax` in the error
paths of the function just before jumping to the epilogue.
[1] https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-certopenstore#return-value
Change-Id: Iafe3b9c78e92c9c5adb8d14a434e11b58f59f19b
GitHub-Last-Rev: 5fcd21d889
GitHub-Pull-Request: golang/sys#92
Reviewed-on: https://go-review.googlesource.com/c/sys/+/273446
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com >
Reviewed-by: Alex Brainman <alex.brainman@gmail.com >
Trust: Alex Brainman <alex.brainman@gmail.com >
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
2020-11-30 07:27:48 +00:00
Jason A. Donenfeld
7719067198
windows: add DLL directory search path manipulation functions
...
A whole class of DLL hijacking attacks can be avoided with a dance like:
SetDllDirectory("")
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32)
For applications who want to opt into this better secure posture, this
commit adds the function definitions to do so.
Reference:
https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setdlldirectorya
https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-setdefaultdlldirectories
Change-Id: I9b6d4e414a80a689b31b9b43a2d5c72de4813c39
Reviewed-on: https://go-review.googlesource.com/c/sys/+/273606
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
2020-11-26 23:39:18 +00:00
Jason A. Donenfeld
f88b827b86
windows: add Token.IsRestricted helper
...
This adds an additional helper method to Token to determine whether or
not it's a restricted one, by using:
https://docs.microsoft.com/en-us/windows/win32/api/securitybaseapi/nf-securitybaseapi-istokenrestricted
Change-Id: I1f2d051450524c22665c4bb99f5948b375b5e199
Reviewed-on: https://go-review.googlesource.com/c/sys/+/272107
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Alex Brainman <alex.brainman@gmail.com >
Trust: Alex Brainman <alex.brainman@gmail.com >
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
2020-11-26 22:47:55 +00:00
Jason A. Donenfeld
d9b008d0a6
windows: add SetFileInformationByHandle
...
We already have GetFileInformationByHandle, so this adds the
corresponding SetFileInformationByHandle, which has a nearly identical
function signature to GetFileInformationByHandleEx, which is
convenient.
We also add the enum for the various classes of data.
Reference: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfileinformationbyhandle
Change-Id: I3d3e8b99e616b512df4d57c8c521e14294c93a6d
Reviewed-on: https://go-review.googlesource.com/c/sys/+/270757
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
Trust: Brad Fitzpatrick <bradfitz@golang.org >
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
2020-11-17 17:04:46 +00:00
Jason A. Donenfeld
cc9327a14d
windows: fix signature of GetFinalPathNameByHandle
...
The function name should be GetFinalPathNameByHandle, not
GetFinalPathNameByHandleW, and it should take types in windows, not in
syscall. This was merged so recently that I think we can just fix it up
here.
Updates golang/go#41686
Fixes CL 264577
Change-Id: Ib84df5b5a9c2df5ad4344884874afa152e9ca554
Reviewed-on: https://go-review.googlesource.com/c/sys/+/270459
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Trust: Alex Brainman <alex.brainman@gmail.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
Reviewed-by: Alex Brainman <alex.brainman@gmail.com >
2020-11-16 19:43:26 +00:00
Jason A. Donenfeld
3a5be02000
windows: add SetKernelObjectSecurity
...
Straight forward function for adjusting object DACLs if you already have
a handle to them.
https://docs.microsoft.com/en-us/windows/win32/api/securitybaseapi/nf-securitybaseapi-setkernelobjectsecurity
Change-Id: I744f7efa53ad00cf0ae134cda1257a61bd3f9c5e
Reviewed-on: https://go-review.googlesource.com/c/sys/+/270458
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
2020-11-16 19:22:46 +00:00
Jason A. Donenfeld
a8a4db9169
windows: add missing return value to SetSecurityInfo
...
This was dangerously left out before, so now we add it.
Change-Id: I71640afa901aab289658644cb533086c91908289
Reviewed-on: https://go-review.googlesource.com/c/sys/+/270457
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
2020-11-16 19:22:36 +00:00
Jason A. Donenfeld
12cec1faf1
windows: add IsWow64Process2 for detecting x86 on arm
...
The original IsWow64Process returns false on arm, always, and so
IsWow64Process2 was added to account for this scenario. This isn't
available on older versions of Windows, so we mark it as such using the
new '?' notation. Finally, we add a test to make sure this all works and
does the expected thing on different versions of Windows.
Change-Id: Ic0412578cfb3f4cf6c9dc92a0028abc579bf6c85
Reviewed-on: https://go-review.googlesource.com/c/sys/+/269077
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
2020-11-13 23:30:24 +00:00
Jason A. Donenfeld
35f3e6cf4a
windows: cleanup mkwinsyscall argument list
...
CL 258038 improperly added a weird custom type to mkwinsyscall, rather
than doing the norm with wrapper functions. So, we revert the change to
mkwinsyscall and add the proper wrapper function to do the type
conversion.
Change-Id: I98134e4ce6bf4b52e1384fe84bddeedb00e18c0b
Reviewed-on: https://go-review.googlesource.com/c/sys/+/268777
Trust: Jason A. Donenfeld <Jason@zx2c4.com >
Trust: Alex Brainman <alex.brainman@gmail.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Alex Brainman <alex.brainman@gmail.com >
2020-11-10 21:10:18 +00:00
Daniel Kessler
80594f20fa
windows: add CertDeleteCertificateFromStore
...
https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-certdeletecertificatefromstore
Change-Id: I59c6e9c75de91176b064c0e16eeb6ea2fda7ffcd
Reviewed-on: https://go-review.googlesource.com/c/sys/+/267601
Trust: Alex Brainman <alex.brainman@gmail.com >
Trust: Ian Lance Taylor <iant@golang.org >
Run-TryBot: Alex Brainman <alex.brainman@gmail.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Alex Brainman <alex.brainman@gmail.com >
2020-11-06 07:34:44 +00:00
Meng Zhuo
3518587229
windows: add GetFinalPathNameByHandleW
...
https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfinalpathnamebyhandlew
Fixes #41686
Change-Id: I207676364a3abc8658498bcd060c8f9694161867
Reviewed-on: https://go-review.googlesource.com/c/sys/+/264577
Trust: Meng Zhuo <mzh@golangcn.org >
Run-TryBot: Meng Zhuo <mzh@golangcn.org >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Ian Lance Taylor <iant@golang.org >
2020-10-29 02:06:03 +00:00
Alex Brainman
9f70ab9862
windows/mkwinsyscall: use global variable to avoid allocation in errnoErr
...
Change-Id: I6f089ea96bfbad6390c50a63e9d2fb290cc8654a
Reviewed-on: https://go-review.googlesource.com/c/sys/+/264578
Trust: Alex Brainman <alex.brainman@gmail.com >
Run-TryBot: Alex Brainman <alex.brainman@gmail.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Bryan C. Mills <bcmills@google.com >
2020-10-24 23:29:16 +00:00
Alex Brainman
0aaa271806
windows/mkwinsyscall: sort by dll names and dll function names
...
Otherwise generated file changes every time //sys lines are moved
around, or when mkwinsyscall command parameters are reordered.
Change-Id: Ie4bdbee2ba50f9cea36ec78ce9951c57bd5da8a7
Reviewed-on: https://go-review.googlesource.com/c/sys/+/260900
Trust: Alex Brainman <alex.brainman@gmail.com >
Run-TryBot: Alex Brainman <alex.brainman@gmail.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Ian Lance Taylor <iant@golang.org >
2020-10-13 08:18:32 +00:00
Sebastiaan van Stijn
dfb3f7c4e6
windows: errnoErr(): return ENOENT to reduce code duplication
...
Change-Id: I51c08a4add9c2b31c4bb7c4421dde227b4fff489
GitHub-Last-Rev: ef8ef8646c
GitHub-Pull-Request: golang/sys#89
Reviewed-on: https://go-review.googlesource.com/c/sys/+/259537
Run-TryBot: Ian Lance Taylor <iant@golang.org >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Ian Lance Taylor <iant@golang.org >
Trust: Alex Brainman <alex.brainman@gmail.com >
2020-10-09 02:54:20 +00:00
Sebastiaan van Stijn
c1f3e3309c
windows/mkwinsyscall: simplify generated code for booleans
...
Change-Id: I31ca4f93924a593e7952c483084616141998a03c
GitHub-Last-Rev: d4fd0c7eca
GitHub-Pull-Request: golang/sys#88
Reviewed-on: https://go-review.googlesource.com/c/sys/+/259302
Trust: Alex Brainman <alex.brainman@gmail.com >
Run-TryBot: Alex Brainman <alex.brainman@gmail.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org >
Reviewed-by: Alex Brainman <alex.brainman@gmail.com >
2020-10-08 06:45:18 +00:00
Alex Brainman
280f808b4a
windows/svc: add IsWindowsService function
...
CL 244958 includes isWindowsService function that determines if a
process is running as a service. The code of the function is based on
public .Net implementation.
IsAnInteractiveSession function implements similar functionality, but
is based on an old Stackoverflow post., which is not as authoritative
as code written by Microsoft for their official product.
This change copies CL 244958 isWindowsService function into svc package
and makes it public. The intention is that future users will prefer
IsWindowsService to IsAnInteractiveSession.
Also this change adds "Deprecated" comment to IsAnInteractiveSession to
point future users to IsWindowsService.
Call to IsAnInteractiveSession is also replaced with IsWindowsService
in golang.org/x/sys/windows/svc/example package.
Change-Id: I4a33b7f590ee8161d1134d8e83668e9da4e6b434
Reviewed-on: https://go-review.googlesource.com/c/sys/+/259397
Run-TryBot: Alex Brainman <alex.brainman@gmail.com >
TryBot-Result: Go Bot <gobot@golang.org >
Reviewed-by: Ian Lance Taylor <iant@golang.org >
Trust: Brad Fitzpatrick <bradfitz@golang.org >
Trust: Alex Brainman <alex.brainman@gmail.com >
2020-10-08 06:31:27 +00:00
Sebastiaan van Stijn
8445cc04cb
windows: add SetConsoleCursorPosition
...
Relates to https://github.com/gotestyourself/gotestsum/pull/115#issuecomment-629785089
For details see: https://docs.microsoft.com/en-us/windows/console/SetConsoleCursorPosition
Change-Id: I512428b64af253916c81187cb644e40a6ba418b5
GitHub-Last-Rev: c6c7ba0ad0
GitHub-Pull-Request: golang/sys#87
Reviewed-on: https://go-review.googlesource.com/c/sys/+/258038
Reviewed-by: Alex Brainman <alex.brainman@gmail.com >
Trust: Alex Brainman <alex.brainman@gmail.com >
Trust: Tobias Klauser <tobias.klauser@gmail.com >
Trust: Ian Lance Taylor <iant@golang.org >
Run-TryBot: Alex Brainman <alex.brainman@gmail.com >
TryBot-Result: Go Bot <gobot@golang.org >
2020-10-07 08:21:16 +00:00
Alex Brainman
be1d3432aa
windows: add TestJobObjectInfo
...
Add test for CL 251197.
Updates golang/go#41001
Change-Id: I6317678057eb8b18a1f7564842a92682c0c9930f
Reviewed-on: https://go-review.googlesource.com/c/sys/+/253097
Run-TryBot: Alex Brainman <alex.brainman@gmail.com >
TryBot-Result: Gobot Gobot <gobot@golang.org >
Reviewed-by: Ian Lance Taylor <iant@golang.org >
2020-09-05 00:46:54 +00:00
Awn Umar
226ff32320
windows: add process working size system calls
...
Fixes golang/go#39422
Related to https://github.com/awnumar/memcall/issues/3
Change-Id: Idf3eec42c3077b39fe033091eea6d62b6a9d8d32
GitHub-Last-Rev: 7f57085a5f
GitHub-Pull-Request: golang/sys#72
Reviewed-on: https://go-review.googlesource.com/c/sys/+/236680
Run-TryBot: Alex Brainman <alex.brainman@gmail.com >
TryBot-Result: Gobot Gobot <gobot@golang.org >
Reviewed-by: Alex Brainman <alex.brainman@gmail.com >
2020-06-10 11:11:08 +00:00
maltalex
af0d71d358
windows: fix recvfrom and sendto data types
...
Fixes wrong data type used in Windows recvfrom and sendto calls
In Windows, `int` refers to a 32-bit signed integer
(https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types#int ).
However, the current implementation (https://golang.org/cl/208321 )
uses the `int` type, which can have a different size. This is especially
important when recvfrom` returns a 32bit value of `-1`, indicating an error,
since it is interpreted as the 64bit value 4294967295.
Change-Id: Ib966ff317b0be7e29e48ee373a794cd0267fb007
GitHub-Last-Rev: 9aad4c377f
GitHub-Pull-Request: golang/sys#51
Reviewed-on: https://go-review.googlesource.com/c/sys/+/211998
Reviewed-by: Ian Lance Taylor <iant@golang.org >
2019-12-19 23:57:34 +00:00
maltalex
6d18c012ae
windows: add Recvfrom and Sendto implementations
...
Added the missing `Sendto` and `Recvfrom` syscalls for Windows.
Fixes golang/go#7170
Change-Id: I794b4f631fad424400fec85ccecc3a3b3abe5465
GitHub-Last-Rev: 39ebe929ca
GitHub-Pull-Request: golang/sys#46
Reviewed-on: https://go-review.googlesource.com/c/sys/+/208321
Run-TryBot: Ian Lance Taylor <iant@golang.org >
TryBot-Result: Gobot Gobot <gobot@golang.org >
Reviewed-by: Ian Lance Taylor <iant@golang.org >
2019-11-28 01:58:09 +00:00
Simon Rozman
6bfc516c86
windows: add Get*PreferredUILanguages
...
This commit adds the following MUI functions:
- GetUserPreferredUILanguages
- GetSystemPreferredUILanguages
- GetThreadPreferredUILanguages
- GetProcessPreferredUILanguages
Change-Id: I44f1c07245ab814935778c6b910b224d24cc753c
Reviewed-on: https://go-review.googlesource.com/c/sys/+/207860
Reviewed-by: Simon Rozman <simon@rozman.si >
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com >
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Gobot Gobot <gobot@golang.org >
2019-11-20 13:05:36 +00:00
Tobias Klauser
e8c54fb511
windows: add EnumProcesses function
...
See https://docs.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-enumprocesses
Change-Id: Ibccb0c3d8e4f32857547ee6d072d0b1cb2430366
Reviewed-on: https://go-review.googlesource.com/c/sys/+/205197
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com >
TryBot-Result: Gobot Gobot <gobot@golang.org >
Reviewed-by: Alex Brainman <alex.brainman@gmail.com >
2019-11-04 09:48:58 +00:00
Takuto Ikuta
b09406accb
windows: add GetDiskFreeSpaceEx function
...
ref:
https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getdiskfreespaceexw
Change-Id: If57b0777106a2253e4287818d2c5aee2d6be13d3
Reviewed-on: https://go-review.googlesource.com/c/sys/+/200257
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com >
TryBot-Result: Gobot Gobot <gobot@golang.org >
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com >
2019-10-10 19:43:22 +00:00