Sign in to follow this  
Followers 0
engine

$tagTOKEN_PRIVILEGES is wrong

3 posts in this topic

I suspect the structure defined in AutoIt as:

Global Const $tagTOKEN_PRIVILEGES = "int Count;int64 LUID;int Attributes"oÝ÷ Ú+0®àßr'²×v+l¥u·yø§yاëh"Öòiû§rبȦV«¶aÊ'y«­¢+ÙÕ¹}ÑQ=-9}AI%Y%1L ÀÌØí¥AÉ¥Ù¥±
½Õ¹Ð¤(%%9½Ð %Í%¹Ð ÀÌØí¥AÉ¥Ù¥±
½Õ¹Ð¤¹ÀÌØí¥AÉ¥Ù¥±
½Õ¹ÐÐìÀ¤Q¡¸IÑÕɸMÑÉÉ½È ´Ä°À°ÅÕ½ÐìÅÕ½Ðì¤(%1½°ÀÌØíÑQ=-9}AI%Y%1LôÅÕ½ÐíݽÉAÉ¥Ù¥±
½Õ¹ÐìÅÕ½Ðì(%½ÈÀÌØí¤ôÀQ¼ÀÌØí¥AÉ¥Ù¥±
½Õ¹Ð´Ä($$ÀÌØíÑQ=-9}AI%Y%1LµÀìôÅÕ½ÐíݽÉ1½ÝAÉÐÅÕ½ÐìµÀìÀÌØí¤µÀìÅÕ½Ðìí±½¹!¥¡AÉÐÅÕ½ÐìµÀìÀÌØí¤µÀìÅÕ½ÐìíݽÉÑÑÉ¥ÕÑÌÅÕ½ÐìµÀìÀÌØí¤µÀìÅÕ½ÐììÅÕ½Ðì(%9áÐ(%IÑÕɸMÑÉ¥¹QÉ¥µI¥¡Ð ÀÌØíÑQ=-9}AI%Y%1L°Ä¤)¹Õ¹oÝ÷ Ù8b±û§rب·­º¹ìi3ÓÑ!Ra²ÚîrÛ«y©Ýµ©jȧ¦ëméî·«¡úkø¥z¬çºÇ²¢çÇ­jÉ*kø¥z¬Ê°j{Z¶Üy*-ärêâ·$´úâ¾)^é¨v'âyÛޮȨ
.ÖÞjëh×6; #FUNCTION# ====================================================================================================================
; Name...........: _Security__SetPrivilege
; Description ...: Enables or disables a local token privilege
; Syntax.........: _Security__SetPrivilege($hToken, $sPrivilege, $fEnable)
; Parameters ....: $hToken      - Handle to a token
;                  $sPrivilege  - Privilege name
;                  $fEnable     - Privilege setting:
;                  | True - Enable privilege
;                  |False - Disable privilege
; Return values .: Success      - True
;                  Failure      - False
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......;
; ===============================================================================================================================
Func _Security__SetPrivilege($hToken, $sPrivilege, $fEnable)
    Local $pRequired, $tRequired, $iLUID, $iAttributes, $iCurrState, $pCurrState, $tCurrState, $iPrevState, $pPrevState, $tPrevState

    $iLUID = _Security__LookupPrivilegeValue("", $sPrivilege)
    If $iLUID = 0 Then Return SetError(-1, 0, False)

    $tCurrState = DllStructCreate( _tagTOKEN_PRIVILEGES(1) )
    $pCurrState = DllStructGetPtr($tCurrState)
    $iCurrState = DllStructGetSize($tCurrState)
    $tPrevState = DllStructCreate( _tagTOKEN_PRIVILEGES(1) )
    $pPrevState = DllStructGetPtr($tPrevState)
    $iPrevState = DllStructGetSize($tPrevState)
    $tRequired = DllStructCreate("int Data")
    $pRequired = DllStructGetPtr($tRequired)
    ; Get current privilege setting
    DllStructSetData($tCurrState, "PrivilegeCount", 1)
    DllStructSetData($tCurrState, "LowPart0", $iLUID)
    If Not _Security__AdjustTokenPrivileges($hToken, False, $pCurrState, $iCurrState, $pPrevState, $pRequired) Then
        Return SetError(-2, @error, False)
    EndIf
    ; Set privilege based on prior setting
    DllStructSetData($tPrevState, "PrivilegeCount", 1)
    DllStructSetData($tPrevState, "LowPart0", $iLUID)
    $iAttributes = DllStructGetData($tPrevState, "Attributes0")
    If $fEnable Then
        $iAttributes = BitOR($iAttributes, $SE_PRIVILEGE_ENABLED)
    Else
        $iAttributes = BitAND($iAttributes, BitNOT($SE_PRIVILEGE_ENABLED))
    EndIf
    DllStructSetData($tPrevState, "Attributes0", $iAttributes)
    If Not _Security__AdjustTokenPrivileges($hToken, False, $pPrevState, $iPrevState, $pCurrState, $pRequired) Then
        Return SetError(-3, @error, False)
    EndIf
    Return SetError(0, 0, True)
EndFunc   ;==>_Security__SetPrivilegeoÝ÷ Øíz»azÞ¾*.²jøjبËayú%"îËb¢|"(®E¡W¢¶Þ¾*.²Ù÷öÖ®¶­sc²4åDU$äÅõU4UôôäÅ3ÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓУ²æÖRââââââââââã¢6WE&fÆVvP£²FW67&Föâââã¢Væ&ÆW2÷"F6&ÆW27V6Â&fÆVvW22&WV&VB'6öÖRFÆÄ6ÆÇ0£²7çFââââââââã¢6WE&fÆVvRb33c·e&fÆVvRÂb33c¶dVæ&ÆR£²&ÖWFW'2âââã¢b33c·e&fÆVvRÒ6â&Râ'&öb&fÆVvW0£²b33c¶dVæ&ÆRÒVæ&ÆR÷"F6&ÆRFR&fÆVvP£²G'VP£²fÇ6P£²FVfVÇB2fÇ6P£²&WV&VÖVçB2ã £²&WGW&âfÇVW2ã¢æöæP£²WF÷"âââââââã¢VævæP£²ÖöFfVBââââââã £²&&·2ââââââã¢f÷"çFW&æÂW6RöæÇ£²&VÆFVBââââââã £²Ææ²âââââââââã°£²W×ÆRââââââã°£²ÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÐ ¤gVæ26WE&fÆVvRb33c·e&fÆVvRÂb33c¶dVæ&ÆRÒG'VR b4'&b33c·e&fÆVvRFVà Æö6Âb33c¶e&bÒb33c·e&fÆVvP VÇ6P Æö6Âb33c¶e&e³ÒÒ²b33c·e&fÆVvUÐ VæD` Æö6Âb33c¶Fö¶VâÒõ6V7W&Gõô÷Vå&ö6W75Fö¶VâõväôvWD7W'&VçE&ö6W72Â&Dõ"b33cµDô´TåôD¥U5Eõ$dÄTtU2Âb33cµDô´TåõTU% f÷"b33c¶ÒFòT&÷VæBb33c¶e&bÒ õ6V7W&Gõõ6WE&fÆVvRb33c¶Fö¶VâÂb33c¶e&e²b33c¶ÒÂb33c¶dVæ&ÆR æW@¤VæDgVæ0

It should also be possible to modify the _Security__SetPrivilege() function to handle arrays of privileges.

PS: I didn't know where to post this topic. Before submitting any bug reports I think it's best to discuss this here.


My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You're right, It is wrong.

But I'm not quite sure how you would do: $tagTOKEN_PRIVILEGES = "dword PrivilegeCount;LUID_AND_ATTRIBUTES Privileges[2]" in autoit. You have a nice work around, but that's all it is unfortunately. I might play around with LUID and LUID_AND_ATTRIBUTES to see if I can come with a proper structure. I would submit it to as a bug report, Gary (or one of the others) may know of a slick way of fixing it.

Edit: I also notice that function doesn't close the Token handle.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

This was what I came up with to make it work. I am developing several other AutoIt functions that use Structures with arrays inside them, and I am doing it in a similar way. It works.

It would be nice to have it in AutoIt in a proper way. At least it would be easier to translate from other programming languages, I think!

Edit: I also notice that function doesn't close the Token handle.

Sorry.

; #INTERNAL_USE_ONLY#=================================================================================
===========================================
; Name...........: SetPrivilege
; Description ...: Enables or disables special privileges as required by some DllCalls
; Syntax.........: SetPrivilege($vPrivilege, $fEnable)
; Parameters ....: $vPrivilege - Can be an array of privileges
;                  $fEnable - Enable or disable the privilege
;                             True
;                             False
;                             Default is False
; Requirement(s).:
; Return values .: None
; Author ........: engine
; Modified.......:
; Remarks .......: For internal use only
; Related .......:
; Link ..........;
; Example .......;
; ====================================================================================================
===========================================

Func SetPrivilege($vPrivilege, $fEnable = True)
    If IsArray($vPrivilege) Then
        Local $avPriv = $vPrivilege
    Else
        Local $avPriv[1] = [$vPrivilege]
    EndIf
    Local $hToken = _Security__OpenProcessToken( _WinAPI_GetCurrentProcess(), BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY) )
    For $i = 0 To UBound($avPriv) - 1
        _Security__SetPrivilege($hToken, $avPriv[$i], $fEnable)
    Next
    _WinAPI_CloseHandle($hToken)
EndFunc

Kind regards.

Edited by engine

My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0