Sign in to follow this  
Followers 0
dexto

RegWrite() REG_QWORD issue?

4 posts in this topic

So, we are on the same page:

I was working on a small function that what writing some reg and ran into some issues. Even thou i found a way around i thought you might find this interesting since its a AutoIt beta:

AutoIt 3.3.1.0 beta:

RegWrite($key, $val, "REG_QWORD", 0)
Runs ok.

.reg equivalent:

"$val"=hex(b):00,00,00,00,00,00,00,00

RegWrite($key, $val, "REG_QWORD", 0x00000000)
Runs ok.

.reg equivalent:

"$val"=hex(b):00,00,00,00,00,00,00,00

RegWrite($key, $val, "REG_QWORD", 12345)
Runs ok. (hex = 3930)

.reg equivalent:

"$val"=hex(b):39,30,00,00,00,00,00,00

RegWrite($key, $val, "REG_QWORD", 0x3930 )
Runs ok. (hex = 3930)

.reg equivalent:

"$val"=hex(b):30,39,00,00,00,00,00,00
how come is 30,39 and not 39,30?

RegWrite($key, $val, "REG_QWORD", hex(12345,8) )
Runs ok. (hex = 3930)

.reg equivalent:

"$val"=hex(b):DF,0B,00,00,00,00,00,00
Where did this come from?

RegWrite($key, $val, "REG_QWORD", 0x00000000000000000000000000000000)
Error?

==> Unable to parse line.:
How come?

Note: AutoIt 3.3.0.0 is not recognizing REG_QWORD at all.

Share this post


Link to post
Share on other sites



I've been working on a registry editor once a while just for the fun so I've extracted the necessary parts:

#Region Registry Constants
Global Const $REG_QWORD = 11
Global Const $HKEY_CLASSES_ROOT = 0x80000000
Global Const $HKEY_CURRENT_USER = 0x80000001
Global Const $HKEY_LOCAL_MACHINE = 0x80000002
Global Const $HKEY_USERS = 0x80000003
Global Const $HKEY_CURRENT_CONFIG = 0x80000005

Global Const $STANDARD_RIGHTS_ALL = 0x001F0000
Global Const $SYNCHRONIZE = 0x00100000
Global Const $KEY_QUERY_VALUE = 0x0001
Global Const $KEY_SET_VALUE = 0x0002
Global Const $KEY_CREATE_SUB_KEY = 0x0004
Global Const $KEY_ENUMERATE_SUB_KEYS = 0x0008
Global Const $KEY_NOTIFY = 0x0010
Global Const $KEY_CREATE_LINK = 0x0020
Global Const $KEY_WOW64_32KEY = 0x0200
Global Const $KEY_WOW64_64KEY = 0x0100
Global Const $KEY_WOW64_RES = 0x0300
Global Const $KEY_ALL_ACCESS = BitAND(BitOR($STANDARD_RIGHTS_ALL, $KEY_QUERY_VALUE, $KEY_SET_VALUE, _
                $KEY_CREATE_SUB_KEY, $KEY_ENUMERATE_SUB_KEYS, $KEY_NOTIFY, $KEY_CREATE_LINK), _
                    BitNOT($SYNCHRONIZE))
#EndRegion



; Example key, probably exist on other Window OS types.
Global Const $sKey = 'HKCU\Control Panel\Appearance\New Schemes\0\Sizes\0'
Global Const $sVal = 'Size #7'

ConsoleWrite(_RegRead($sKey, $sVal) & @LF)
Exit



Func _RegRead($sKey, $sVal)
    Local $sValue
    Local $iType
    
    Switch StringLeft($sKey, StringInStr($sKey, '\')-1)
        Case 'HKEY_LOCAL_MACHINE', 'HKLM'
            $hKey = _RegOpenKeyEx($HKEY_LOCAL_MACHINE, StringTrimLeft($sKey, StringInStr($sKey, '\')), $KEY_ALL_ACCESS)
        Case 'HKEY_CLASSES_ROOT', 'HKCR'
            $hKey = _RegOpenKeyEx($HKEY_CLASSES_ROOT, StringTrimLeft($sKey, StringInStr($sKey, '\')), $KEY_ALL_ACCESS)
        Case 'HKEY_CURRENT_CONFIG', 'HKCC'
            $hKey = _RegOpenKeyEx($HKEY_CURRENT_CONFIG, StringTrimLeft($sKey, StringInStr($sKey, '\')), $KEY_ALL_ACCESS)
        Case 'HKEY_CURRENT_USER', 'HKCU'
            $hKey = _RegOpenKeyEx($HKEY_CURRENT_USER, StringTrimLeft($sKey, StringInStr($sKey, '\')), $KEY_ALL_ACCESS)
        Case 'HKEY_USERS', 'HKU'
            $hKey = _RegOpenKeyEx($HKEY_USERS, StringTrimLeft($sKey, StringInStr($sKey, '\')), $KEY_ALL_ACCESS)
        Case Else
            Return SetError(1, 0, 0)
    EndSwitch
    
    If $hKey = 0 Then Return SetError(2, 0, 0)
    
    $sValue = _RegQueryValueEx($hKey, $sVal)
    $iType = @extended


    _RegCloseKey($hKey)
    
    Return SetError(0, $iType, $sValue)
EndFunc
    

Func _RegCreateKeyEx($hKey, $sKey, $iAccess)
    Local $aRet
    
    $aRet = DllCall('advapi32.dll', 'long', 'RegCreateKeyExW', 'ulong_ptr', $hKey, 'wstr', $sKey, _
                'dword', 0, 'ptr', 0, 'dword', 0, 'dword', $iAccess, 'ptr', 0, 'ulong_ptr*', 0, 'ptr', 0)
    
    If $aRet[0] <> 0 Then
        ConsoleWrite($aRet[0] & @LF)
        Return SetError(1, 0, $aRet[0])
    EndIf
    Return $aRet[8]
EndFunc

Func _RegOpenKeyEx($hKey, $sKey, $iAccess)
    Local $aRet
    
    $aRet = DllCall('advapi32.dll', 'long', 'RegOpenKeyExW', 'ulong_ptr', $hKey, 'wstr', $sKey, _
                'dword', 0, 'dword', $iAccess, 'ulong_ptr*', 0)
    
    If $aRet[0] <> 0 Then Return SetError(1, 0, $aRet[0])
    Return $aRet[5]
EndFunc

Func _RegQueryValueEx($hKey, $sValue)
    Local $aRet
    Local $tBuff, $pBuff
    
    $aRet = DllCall('advapi32.dll', 'long', 'RegQueryValueExW', 'ulong_ptr', $hKey, 'wstr', $sValue, _
                'ptr', 0, 'dword*', 0, 'ptr', 0, 'dword*', 0)
    
    $tBuff = DllStructCreate('byte[' & $aRet[6] & ']')
    $pBuff = DllStructGetPtr($tBuff)
    
    $aRet = DllCall('advapi32.dll', 'long', 'RegQueryValueExW', 'ulong_ptr', $hKey, 'wstr', $sValue, _
                'ptr', 0, 'dword*', 0, 'ptr', $pBuff, 'dword*', $aRet[6])
    
    If $aRet[0] <> 0 Then Return SetError(1, 0, $aRet[0])
    $aRet[0] = DllStructGetData($tBuff, 1)
    $tBuff = 0
    Return SetError(0, $aRet[4], $aRet[0])
EndFunc


Func _RegCloseKey($hKey)
    Local $aRet
    
    $aRet = DllCall('advapi32.dll', 'long', 'RegCloseKey', 'ulong_ptr', $hKey)
    
    If $aRet[0] <> 0 Then
        ConsoleWrite($aRet[0] & @LF)
        Return SetError(1, 0, $aRet[0])
    EndIf
    Return $aRet[0]
EndFunc

Regarding the Hex(12345, 8). It gets converted to 00003039 but it's just a hexadecimal representation, if you'll re-represent it again as hexadecimal number you'll see that it turns into Binary(3039). The last error is because the biggest literal number AutoIt expects is a 32-bit number, at least under the regular AutoIt version, don't know about x64 version.

Share this post


Link to post
Share on other sites

Its going to be very useful. >_< Thanks again Authenticity!

I've been working on a registry editor once a while just for the fun so I've extracted the necessary parts:

#Region Registry Constants
Global Const $REG_QWORD = 11
Global Const $HKEY_CLASSES_ROOT = 0x80000000
Global Const $HKEY_CURRENT_USER = 0x80000001
Global Const $HKEY_LOCAL_MACHINE = 0x80000002
Global Const $HKEY_USERS = 0x80000003
Global Const $HKEY_CURRENT_CONFIG = 0x80000005

Global Const $STANDARD_RIGHTS_ALL = 0x001F0000
Global Const $SYNCHRONIZE = 0x00100000
Global Const $KEY_QUERY_VALUE = 0x0001
Global Const $KEY_SET_VALUE = 0x0002
Global Const $KEY_CREATE_SUB_KEY = 0x0004
Global Const $KEY_ENUMERATE_SUB_KEYS = 0x0008
Global Const $KEY_NOTIFY = 0x0010
Global Const $KEY_CREATE_LINK = 0x0020
Global Const $KEY_WOW64_32KEY = 0x0200
Global Const $KEY_WOW64_64KEY = 0x0100
Global Const $KEY_WOW64_RES = 0x0300
Global Const $KEY_ALL_ACCESS = BitAND(BitOR($STANDARD_RIGHTS_ALL, $KEY_QUERY_VALUE, $KEY_SET_VALUE, _
                $KEY_CREATE_SUB_KEY, $KEY_ENUMERATE_SUB_KEYS, $KEY_NOTIFY, $KEY_CREATE_LINK), _
                    BitNOT($SYNCHRONIZE))
#EndRegion



; Example key, probably exist on other Window OS types.
Global Const $sKey = 'HKCU\Control Panel\Appearance\New Schemes\0\Sizes\0'
Global Const $sVal = 'Size #7'

ConsoleWrite(_RegRead($sKey, $sVal) & @LF)
Exit



Func _RegRead($sKey, $sVal)
    Local $sValue
    Local $iType
    
    Switch StringLeft($sKey, StringInStr($sKey, '\')-1)
        Case 'HKEY_LOCAL_MACHINE', 'HKLM'
            $hKey = _RegOpenKeyEx($HKEY_LOCAL_MACHINE, StringTrimLeft($sKey, StringInStr($sKey, '\')), $KEY_ALL_ACCESS)
        Case 'HKEY_CLASSES_ROOT', 'HKCR'
            $hKey = _RegOpenKeyEx($HKEY_CLASSES_ROOT, StringTrimLeft($sKey, StringInStr($sKey, '\')), $KEY_ALL_ACCESS)
        Case 'HKEY_CURRENT_CONFIG', 'HKCC'
            $hKey = _RegOpenKeyEx($HKEY_CURRENT_CONFIG, StringTrimLeft($sKey, StringInStr($sKey, '\')), $KEY_ALL_ACCESS)
        Case 'HKEY_CURRENT_USER', 'HKCU'
            $hKey = _RegOpenKeyEx($HKEY_CURRENT_USER, StringTrimLeft($sKey, StringInStr($sKey, '\')), $KEY_ALL_ACCESS)
        Case 'HKEY_USERS', 'HKU'
            $hKey = _RegOpenKeyEx($HKEY_USERS, StringTrimLeft($sKey, StringInStr($sKey, '\')), $KEY_ALL_ACCESS)
        Case Else
            Return SetError(1, 0, 0)
    EndSwitch
    
    If $hKey = 0 Then Return SetError(2, 0, 0)
    
    $sValue = _RegQueryValueEx($hKey, $sVal)
    $iType = @extended


    _RegCloseKey($hKey)
    
    Return SetError(0, $iType, $sValue)
EndFunc
    

Func _RegCreateKeyEx($hKey, $sKey, $iAccess)
    Local $aRet
    
    $aRet = DllCall('advapi32.dll', 'long', 'RegCreateKeyExW', 'ulong_ptr', $hKey, 'wstr', $sKey, _
                'dword', 0, 'ptr', 0, 'dword', 0, 'dword', $iAccess, 'ptr', 0, 'ulong_ptr*', 0, 'ptr', 0)
    
    If $aRet[0] <> 0 Then
        ConsoleWrite($aRet[0] & @LF)
        Return SetError(1, 0, $aRet[0])
    EndIf
    Return $aRet[8]
EndFunc

Func _RegOpenKeyEx($hKey, $sKey, $iAccess)
    Local $aRet
    
    $aRet = DllCall('advapi32.dll', 'long', 'RegOpenKeyExW', 'ulong_ptr', $hKey, 'wstr', $sKey, _
                'dword', 0, 'dword', $iAccess, 'ulong_ptr*', 0)
    
    If $aRet[0] <> 0 Then Return SetError(1, 0, $aRet[0])
    Return $aRet[5]
EndFunc

Func _RegQueryValueEx($hKey, $sValue)
    Local $aRet
    Local $tBuff, $pBuff
    
    $aRet = DllCall('advapi32.dll', 'long', 'RegQueryValueExW', 'ulong_ptr', $hKey, 'wstr', $sValue, _
                'ptr', 0, 'dword*', 0, 'ptr', 0, 'dword*', 0)
    
    $tBuff = DllStructCreate('byte[' & $aRet[6] & ']')
    $pBuff = DllStructGetPtr($tBuff)
    
    $aRet = DllCall('advapi32.dll', 'long', 'RegQueryValueExW', 'ulong_ptr', $hKey, 'wstr', $sValue, _
                'ptr', 0, 'dword*', 0, 'ptr', $pBuff, 'dword*', $aRet[6])
    
    If $aRet[0] <> 0 Then Return SetError(1, 0, $aRet[0])
    $aRet[0] = DllStructGetData($tBuff, 1)
    $tBuff = 0
    Return SetError(0, $aRet[4], $aRet[0])
EndFunc


Func _RegCloseKey($hKey)
    Local $aRet
    
    $aRet = DllCall('advapi32.dll', 'long', 'RegCloseKey', 'ulong_ptr', $hKey)
    
    If $aRet[0] <> 0 Then
        ConsoleWrite($aRet[0] & @LF)
        Return SetError(1, 0, $aRet[0])
    EndIf
    Return $aRet[0]
EndFunc

Regarding the Hex(12345, 8). It gets converted to 00003039 but it's just a hexadecimal representation, if you'll re-represent it again as hexadecimal number you'll see that it turns into Binary(3039). The last error is because the biggest literal number AutoIt expects is a 32-bit number, at least under the regular AutoIt version, don't know about x64 version.

Share this post


Link to post
Share on other sites

I've been working on a registry editor once a while just for the fun so I've extracted the necessary parts:

#Region Registry Constants
Global Const $REG_QWORD = 11
Global Const $HKEY_CLASSES_ROOT = 0x80000000
Global Const $HKEY_CURRENT_USER = 0x80000001
Global Const $HKEY_LOCAL_MACHINE = 0x80000002
Global Const $HKEY_USERS = 0x80000003
Global Const $HKEY_CURRENT_CONFIG = 0x80000005

Global Const $STANDARD_RIGHTS_ALL = 0x001F0000
Global Const $SYNCHRONIZE = 0x00100000
Global Const $KEY_QUERY_VALUE = 0x0001
Global Const $KEY_SET_VALUE = 0x0002
Global Const $KEY_CREATE_SUB_KEY = 0x0004
Global Const $KEY_ENUMERATE_SUB_KEYS = 0x0008
Global Const $KEY_NOTIFY = 0x0010
Global Const $KEY_CREATE_LINK = 0x0020
Global Const $KEY_WOW64_32KEY = 0x0200
Global Const $KEY_WOW64_64KEY = 0x0100
Global Const $KEY_WOW64_RES = 0x0300
Global Const $KEY_ALL_ACCESS = BitAND(BitOR($STANDARD_RIGHTS_ALL, $KEY_QUERY_VALUE, $KEY_SET_VALUE, _
                $KEY_CREATE_SUB_KEY, $KEY_ENUMERATE_SUB_KEYS, $KEY_NOTIFY, $KEY_CREATE_LINK), _
                    BitNOT($SYNCHRONIZE))
#EndRegion



; Example key, probably exist on other Window OS types.
Global Const $sKey = 'HKCU\Control Panel\Appearance\New Schemes\0\Sizes\0'
Global Const $sVal = 'Size #7'

ConsoleWrite(_RegRead($sKey, $sVal) & @LF)
Exit



Func _RegRead($sKey, $sVal)
    Local $sValue
    Local $iType
    
    Switch StringLeft($sKey, StringInStr($sKey, '\')-1)
        Case 'HKEY_LOCAL_MACHINE', 'HKLM'
            $hKey = _RegOpenKeyEx($HKEY_LOCAL_MACHINE, StringTrimLeft($sKey, StringInStr($sKey, '\')), $KEY_ALL_ACCESS)
        Case 'HKEY_CLASSES_ROOT', 'HKCR'
            $hKey = _RegOpenKeyEx($HKEY_CLASSES_ROOT, StringTrimLeft($sKey, StringInStr($sKey, '\')), $KEY_ALL_ACCESS)
        Case 'HKEY_CURRENT_CONFIG', 'HKCC'
            $hKey = _RegOpenKeyEx($HKEY_CURRENT_CONFIG, StringTrimLeft($sKey, StringInStr($sKey, '\')), $KEY_ALL_ACCESS)
        Case 'HKEY_CURRENT_USER', 'HKCU'
            $hKey = _RegOpenKeyEx($HKEY_CURRENT_USER, StringTrimLeft($sKey, StringInStr($sKey, '\')), $KEY_ALL_ACCESS)
        Case 'HKEY_USERS', 'HKU'
            $hKey = _RegOpenKeyEx($HKEY_USERS, StringTrimLeft($sKey, StringInStr($sKey, '\')), $KEY_ALL_ACCESS)
        Case Else
            Return SetError(1, 0, 0)
    EndSwitch
    
    If $hKey = 0 Then Return SetError(2, 0, 0)
    
    $sValue = _RegQueryValueEx($hKey, $sVal)
    $iType = @extended


    _RegCloseKey($hKey)
    
    Return SetError(0, $iType, $sValue)
EndFunc
    

Func _RegCreateKeyEx($hKey, $sKey, $iAccess)
    Local $aRet
    
    $aRet = DllCall('advapi32.dll', 'long', 'RegCreateKeyExW', 'ulong_ptr', $hKey, 'wstr', $sKey, _
                'dword', 0, 'ptr', 0, 'dword', 0, 'dword', $iAccess, 'ptr', 0, 'ulong_ptr*', 0, 'ptr', 0)
    
    If $aRet[0] <> 0 Then
        ConsoleWrite($aRet[0] & @LF)
        Return SetError(1, 0, $aRet[0])
    EndIf
    Return $aRet[8]
EndFunc

Func _RegOpenKeyEx($hKey, $sKey, $iAccess)
    Local $aRet
    
    $aRet = DllCall('advapi32.dll', 'long', 'RegOpenKeyExW', 'ulong_ptr', $hKey, 'wstr', $sKey, _
                'dword', 0, 'dword', $iAccess, 'ulong_ptr*', 0)
    
    If $aRet[0] <> 0 Then Return SetError(1, 0, $aRet[0])
    Return $aRet[5]
EndFunc

Func _RegQueryValueEx($hKey, $sValue)
    Local $aRet
    Local $tBuff, $pBuff
    
    $aRet = DllCall('advapi32.dll', 'long', 'RegQueryValueExW', 'ulong_ptr', $hKey, 'wstr', $sValue, _
                'ptr', 0, 'dword*', 0, 'ptr', 0, 'dword*', 0)
    
    $tBuff = DllStructCreate('byte[' & $aRet[6] & ']')
    $pBuff = DllStructGetPtr($tBuff)
    
    $aRet = DllCall('advapi32.dll', 'long', 'RegQueryValueExW', 'ulong_ptr', $hKey, 'wstr', $sValue, _
                'ptr', 0, 'dword*', 0, 'ptr', $pBuff, 'dword*', $aRet[6])
    
    If $aRet[0] <> 0 Then Return SetError(1, 0, $aRet[0])
    $aRet[0] = DllStructGetData($tBuff, 1)
    $tBuff = 0
    Return SetError(0, $aRet[4], $aRet[0])
EndFunc


Func _RegCloseKey($hKey)
    Local $aRet
    
    $aRet = DllCall('advapi32.dll', 'long', 'RegCloseKey', 'ulong_ptr', $hKey)
    
    If $aRet[0] <> 0 Then
        ConsoleWrite($aRet[0] & @LF)
        Return SetError(1, 0, $aRet[0])
    EndIf
    Return $aRet[0]
EndFunc

Regarding the Hex(12345, 8). It gets converted to 00003039 but it's just a hexadecimal representation, if you'll re-represent it again as hexadecimal number you'll see that it turns into Binary(3039). The last error is because the biggest literal number AutoIt expects is a 32-bit number, at least under the regular AutoIt version, don't know about x64 version.

definitely gonna try this one.

thanks

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