ox
ox copied to clipboard
Add ImpersonateSelf syscall
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)