Jump to content

Binary Manipulation


NiVZ
 Share

Recommended Posts

Hello,

I'm trying to modify a BINARY registry value to turn on or off the "Automatically Detect Settings" in IE.

I've searched the web and found I need to modify a binary key at:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections", "DefaultConnectionSettings"

But I'm useless at Binary.

I found this VBScript that does what I need, but I want to do this in Autoit:

DIM sKey,sValue,binaryVal
Dim oReg
Set oReg=GetObject( "winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")    'For registry operations througout

Const HKCU=&H80000001

sKey = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"
sValue = "DefaultConnectionSettings"

oReg.GetBinaryValue HKCU, sKey, sValue, binaryVal

select case lcase(status)
  case "on"    binaryVal(8) = binaryVal(8) OR 8        'Force Autodetect on
  case "off"    binaryVal(8) = binaryVal(8) XOR 8        'Force Autodetect off
  case "show"    wscript.echo "Automatically detect is set to " & ((binaryVal(8) and 8) = 8)
  case else    wscript.echo "Invalid parameter - IEautomaticallydetect  on, off or show"
end select

So far I've got:

; Get The Registry Value
$Reg = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections", "DefaultConnectionSettings")

; Show the value we want to modify
MsgBox(0,"1",BinaryMid($Reg, 9, 1))

; Show the value we want to add or subtract to turn on or off
MsgBox(0,"2",Binary("0x08"))

But now I'm stuck as I don't know how to BitOR or BitXOR just the 8th (counting from zero) pair of bytes (in the way the VB code deos it with BinaryVal(8).

Any help appreciated.

Thanks,

NiVZ

Edited by NiVZ
Link to comment
Share on other sites

I tried this and it worked as expected:

; Get The Registry Value
$bReg = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections", "DefaultConnectionSettings")

$iSearch   = 9  ;the value we want to modify
$iReplace  = 8  ;The value we want to replace
$iExample1 = StringReplace($bReg, StringInStr($bReg, $iSearch), $iReplace, 1)
If Not @error Then RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections", "DefaultConnectionSettings", "REG_BINARY", $iExample1)

MsgBox(4096, "Example1", $iExample1)

$iSearch   = 8  ;the value we want to modify
$iReplace  = 9  ;The value we want to replace
$iExample2 = StringReplace($iExample1, StringInStr($iExample1, $iSearch), $iReplace, 1)
If Not @error Then RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections", "DefaultConnectionSettings", "REG_BINARY", $iExample2)

MsgBox(4096, "Example2", $iExample2)

Be careful when doing alterations in the Windows registry

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

  • 1 year later...

The problem with this solution is that if the Automatically detect proxy setting is already off, another section of the data will be modified. There is a section before that increments as well, and can be modified by accident if it reaches the number being searched.

The clean way would be to modify the 8th byte as in the code example posted at first. I am searching for a way to do this, but so far have not found what I'm looking for. I know it's got to be something obvious that I just don't see right now.

Link to comment
Share on other sites

What about:

$data = RegRead...
$chunk1 = BinaryMid($data, 1,7)
$chunk2 = BinaryMid($data, 9)
$result = $chunk1 & _Modify(BinaryMid($data, 8, 1)) & $chunk2

*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

Link to comment
Share on other sites

This is what I actually ended up doing:

$reg = RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections", "DefaultConnectionSettings")

$regupd = BinaryMid($reg, 1, 8) & Binary("0x01") & BinaryMid($reg, 10)

RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections","DefaultConnectionSettings","REG_BINARY",$regupd)
Edited by wporter
Link to comment
Share on other sites

  • 4 months later...

I just wanted to say thank you, i've been trying to do this for a very looooooong time.

I had found this thread in another forum for where the registry values needed are one of the posts in there revealed the following Binary values and what boxes would be checked.

3) Byte number 8 can take different values as per your settings.

The value is :

09 when only 'Automatically detect settings' is enabled

03 when only 'Use a proxy server for your LAN' is enabled

0B when both are enabled

05 when only 'Use automatic configuration script' is enabled

0D when 'Automatically detect settings' and 'Use automatic configuration script' are enabled

07 when 'Use a proxy server for your LAN' and 'Use automatic configuration script' are enabled

0F when all the three are enabled.

01 when none of them are enabled.

The next three bytes are zeros (Bytes 9 to B ).

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...