Jump to content
Sign in to follow this  
jdrom

RegWrite DWORD and BINARY

Recommended Posts

jdrom

Not sure how to go about this, and well I can't seem to find anything about how to do it either.

I have a REG_BINARY key which is in hexadecimal. When exported from regedit, it looks like this:

"License"=hex:xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx

Now in AutoIt I've tried doing:

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Raxco\PerfectDisk\10.0", "License", "REG_BINARY", "xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx")

I've tried spaces (instead of commas) and removing the commas as well.

Also have some DWORD keys as well, and exported from regedit they look like so:

"Wizard"=dword:0000000f

And the AutoIt code I've tried:

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Raxco\PerfectDisk\10.0", "Wizard", "REG_DWORD", "00 00 00 0f")

Also tried without spaces too.

Hopefully somebody on here has successfully used these functions before and can help me :P

Share this post


Link to post
Share on other sites
jdrom

Well I figured out the DWORD one, converted the hex to decimal and that worked out fine.

Still no idea how to do the REG_BINARY that uses hex (or so I'm assuming).

Share this post


Link to post
Share on other sites
Authenticity

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Raxco\PerfectDisk\10.0", "License", StringToBinary('Hello World!'))

Share this post


Link to post
Share on other sites
Ascend4nt

#include <String.au3>
$sHexTextStr="0b1a2c"
$bBinary=StringToBinary(_HexToString($sHexTextStr))
consolewrite($bBinary&@CRLF)

Share this post


Link to post
Share on other sites
ProgAndy

You can do that with

$binary = Binary("0x0123456789ABCDEF")
RegWrite("HKCU\Software\__Bintest", "BinaryVal", "REG_BINARY", $binary)
$read = RegRead("HKCU\Software\__Bintest", "BinaryVal")
MsgBox(0, 'Binary Write / Read', "Written:  " & $binary & @CRLF & "Read:    " & $read)

RegDelete("HKCU\Software\__Bintest")
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
Ascend4nt

Dang, you know I hadn't even thought of Binary. So in this case, when jdrom is faced with a RegEdit style binary string, he'll just need to prefix '0x' to the string, like such..

$sHexTextStr="0b1a2c"
$bBinary=Binary('0x'&$sHexTextStr)
ConsoleWrite($bBinary&@CRLF)

Thx Progandy - I actually have a RegEdit parser of my own and was wondering if there was a better way!

Share this post


Link to post
Share on other sites
jdrom

Sadly I don't even know enough about AutoIt to understand that code you guys posted...

I'm guessing your converting hex into binary? And 0x needs to be added in front of the hex value? I'd like to understand it though since obviously converting hex into ASCII and using that is far from ideal.

Would this be how I'd implement it?

RegWrite("HKEY_LOCAL_MACHINESOFTWARERaxcoPerfectDisk10.0", "License", "REG_BINARY", Binary ('0x'&'123ABC'))
Edited by jdrom

Share this post


Link to post
Share on other sites
Ascend4nt

You were exporting from RegEdit, so I had assumed you had gathered a string of hexadecimal values (and hopefully removed the commas) This would result in a string like I posted, for example "a0b1c3d40eff1b2c'. That, in string form, would need 0x added to the front.

What you describe, "123ABC" depends on what it is you are doing. As a HEX string, that will give you 0x123ABC, but do you want the binary string to represent the actual characters '123abc'', or are those the hexadecimal values. If its the latter, you can put it in as '0x123ABC'. If the former, then you'll need to use StringToBinary I believe

Share this post


Link to post
Share on other sites
Authenticity

Yup, but it's useless to concatenate these strings because "0x123ABC" and what you've wrote is the same. Try to test this things using the ConsoleWrite to see what the final result is because this -> "0x123ABC" is not interpreted as hex: 01,02,03,0A,0B,0C...

Example:

Dim $Var = Binary('0x123ABC')
Dim $tBuff = DllStructCreate('byte[' & BinaryLen($Var) & ']')

DllStructSetData($tBuff, 1, $Var)
ConsoleWrite(DllStructGetData($tBuff, 1) & @LF & @LF)

For $i = 1 To BinaryLen($Var)
    ConsoleWrite(Hex(DllStructGetData($tBuff, 1, $i), 2) & @LF)
Next
$tBuff = 0

Share this post


Link to post
Share on other sites
Ascend4nt

Yup, but it's useless to concatenate these strings because "0x123ABC" and what you've wrote is the same. ..

Authenticity, I tested it with RegWrite(), and the way I had it works perfectly. I don't know where you're coming from.

By the way, you're example doesn't write anything to the console and ends up in an endless loop. (AutoIT v3.3) *edit* retried, and worked the second time (don't know why it failed the first time. In any case, the results are the same as what was expected - these are hex *pairs*, as would be retrieved in grabbing text from a RegEdit file)*

Here's code that shows writing to the registry:

$sHexTextStr="0b1a2c"
RegWrite("HKEY_CURRENT_USER\Software\1Key","testbin","REG_BINARY",Binary('0x'&$sHexTextStr))

I export that key using RegEdit, and what is the result?

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\1key]
"testbin"=hex:0b,1a,2c

Works just as it should.

-Ascend4nt

Edited by ascendant

Share this post


Link to post
Share on other sites
Authenticity

My mistake, this post was a reply to jdrom's. I think I should quote him, anyway...

Share this post


Link to post
Share on other sites
jdrom

$sHexTextStr="0b1a2c"
RegWrite("HKEY_CURRENT_USER\Software\1Key","testbin","REG_BINARY",Binary('0x'&$sHexTextStr))
Thanks guy (or girls) :P

I used Ascendants way though, easier for me to understand and works perfectly. Though I ditched the variable and just put my hex string in directly (without commas of course). It's the 2nd line in my script anyways so I don't see the need for a variable.

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  

×