Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ImpersonateSelf syscall #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Enrico204
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant