ox icon indicating copy to clipboard operation
ox copied to clipboard

Add ImpersonateSelf syscall

Open Enrico204 opened this issue 4 years ago • 0 comments

This pull request add ImpersonateSelf syscall: https://docs.microsoft.com/en-us/windows/win32/api/securitybaseapi/nf-securitybaseapi-impersonateself

This syscall is used in conjunction with others to refer to the current running user. For example:

// This is the new function. Without this call, OpenThreadToken will return an error on current thread
ImpersonateSelf(syscallex.SecurityImpersonation)

defer func() {
	syscallex.RevertToSelf()
}()

var impersonationToken syscall.Token
currentThread := syscallex.GetCurrentThread()
err := syscallex.OpenThreadToken(
	currentThread,
	syscall.TOKEN_ALL_ACCESS,
	1,
	&impersonationToken,
)
if err != nil {
	// handle error
}

permissionGranted, err := winox.UserHasPermission(impersonationToken, winox.RightsRead|winox.RightsWrite, path)

Enrico204 avatar Aug 23 '21 09:08 Enrico204