Jump to content

Convert REG_BINARY value to a readable string


Recommended Posts

Hi, how to convert REG_BINARY value to a readable string? I trying, but unsuccessful :P

#include <String.au3>

$key = RegRead("HKLM\SOFTWARE\Microsoft\Internet Explorer\Registration", "DigitalProductId")

MsgBox(0, "Binary", $key)

MsgBox(0, "String", _HexToString($key))
The string on my PC has lots of 00 bytes, so maybe if you replace 00 bytes with 20, but being careful that you only change 00 if the first 0 is at an odd position, then maybe you'll get something.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Hi, how to convert REG_BINARY value to a readable string? I trying, but unsuccessful :P

#include <String.au3>

$key = RegRead("HKLM\SOFTWARE\Microsoft\Internet Explorer\Registration", "DigitalProductId")

MsgBox(0, "Binary", $key)

MsgBox(0, "String", _HexToString($key))oÝ÷ Ûú®¢×°zYr¢çÚò¶¬nëmë-®)àÉè¶÷«Ê«¨¶·u¦åz«¨µ«­¢+Ø¥¹±Õ±ÐíMÑÉ¥¹¹ÔÌÐì((ÀÌØí­äôII ÅÕ½Ðí!-14ÀäÈíM=Q]IÀäÈí5¥É½Í½ÐÀäÈí%¹ÑɹÐáÁ±½ÉÈÀäÈíI¥ÍÑÉÑ¥½¸ÅÕ½Ðì°ÅÕ½Ðí¥¥Ñ±AɽÕÑ%ÅÕ½Ðì¤()5Í  ½à À°ÅÕ½Ðí ¥¹ÉäÅÕ½Ðì°ÀÌØí­ä¤()5Í ½à À°ÅÕ½ÐíMÑÉ¥¹ÅÕ½Ðì°    ¥¹ÉåIQ½MÑÉ¥¹ ÀÌØí­ä¤¤()Õ¹    ¥¹ÉåIQ½MÑÉ¥¹ ÀÌØíµåMÑÉ¥¹¤(%1½°ÀÌØíIÍÕ±ÐôÅÕ½ÐìÅÕ½Ðì(%½ÈÀÌØí¤ôÄQ¼MÑÉ¥¹1¸ ÀÌØíµåMÑÉ¥¹¤MÑÀÈ($$ÀÌØíàôMÑÉ¥¹5¥ ÀÌØíµåMÑÉ¥¹°ÀÌØí¤°È¤($%%MÑÉ¥¹5¥ ÀÌØíµåMÑÉ¥¹°ÀÌØí¤°È¤±ÐìÐìÅÕ½ÐìÀÀÅÕ½ÐìQ¡¸ÀÌØíIÍÕ±ÐôÀÌØíIÍձеÀì   ¥¹ÉåQ½MÑÉ¥¹ ÅÕ½ÐìÁàÅÕ½ÐìµÀìMÑÉ¥¹5¥ ÀÌØíµåMÑÉ¥¹°ÀÌØí¤°È¤¤(%9áÐ(%IÑÕɸÀÌØíIÍÕ±Ð)¹Õ¹ìôÐì ¥¹ÉåIQ½MÑÉ¥¹ ¤
Link to comment
Share on other sites

Does this help, too?

#include <GUIConstantsEx.au3>
; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.1 beta
; Author: Thorsten Meger
;
; Script Function:
; Windows XP Information displayed in a Gui
;
; ----------------------------------------------------------------------------

$GUI = GUICreate("", 380, 315, -1, -1)
GUISetFont(9, 700, -1, "MS Sans Serif")

$windowsInformation_L = GUICtrlCreateLabel(" Windows Information", 5, 3, 290, 25)
$status_L = GUICtrlCreateLabel("Information read ...", 20, 280, 200, 20)
$description_L = GUICtrlCreateLabel("Description", 20, 58, 100, 20)
$windowsType_L = GUICtrlCreateLabel("WindowsType", 20, 83, 100, 20)
$serialNumber_L = GUICtrlCreateLabel("SerialNumber", 20, 108, 100, 20)
$ProductKey_L = GUICtrlCreateLabel("ProductKey", 20, 133, 100, 20)
$InstallDate_L = GUICtrlCreateLabel("InstallDate", 20, 158, 100, 20)
$LastBootUpTime_L = GUICtrlCreateLabel("LastBootUpTime", 20, 183, 100, 20)
$RegisteredOwner_L = GUICtrlCreateLabel("RegisteredOwner", 20, 208, 100, 20)
$officeKey_L = GUICtrlCreateLabel("OfficeKey", 20, 233, 100, 20)

$description_I = GUICtrlCreateInput("", 125, 55, 235, 20)
$windowsType_I = GUICtrlCreateInput("", 125, 80, 235, 20)
$serialNumber_I = GUICtrlCreateInput("", 125, 105, 235, 20)
$ProductKey_I = GUICtrlCreateInput("", 125, 130, 235, 20)
$InstallDate_I = GUICtrlCreateInput("", 125, 155, 235, 20)
$LastBootUpTime_I = GUICtrlCreateInput("", 125, 180, 235, 20)
$RegisteredOwner_I = GUICtrlCreateInput("", 125, 205, 235, 20)
$officeKey_I = GUICtrlCreateInput("", 125, 230, 235, 20)

$informationPanel_G = GUICtrlCreateGroup("Information Panel", 10, 35, 360, 225)
$status_G = GUICtrlCreateGroup("Status", 10, 265, 360, 40)

$font = "Comic Sans MS"
GUICtrlSetColor($windowsInformation_L, 0xff0000)
GUICtrlSetFont($windowsInformation_L, 16, 700, 4, $font)

$progressbar = GUICtrlCreateProgress(140, 278, 220, 20)

Global $product = ""
Global $counter = 3
Global $wait = 150

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $counter = 3 Then
        Sleep(1000)
        GUICtrlSetData($status_L, "Initialize ... " & $counter)
        progress()
        $counter -= 1
    ElseIf $counter = 2 Then
        GUICtrlSetData($status_L, "Initialize ... " & $counter)
        progress()
        $counter -= 1
    ElseIf $counter = 1 Then
        GUICtrlSetData($status_L, "Initialize ... " & $counter)
        progress()
        $counter -= 1
    ElseIf $counter = 0 Then
        GUICtrlSetData($status_L, "Ready ...")
        progress()
        $counter -= 1
    ElseIf $counter = -1 Then
        Dim $Bin = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DigitalProductID")
        Dim $key4RegisteredOwner = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
        $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
        $colSettings = $objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")

        For $objOperatingSystem In $colSettings
        Next
        GUICtrlSetData($description_I, StringMid($objOperatingSystem.Description, 1))
        GUICtrlSetData($windowsType_I, '(' & @OSVersion & ') ' & StringMid($objOperatingSystem.Caption, 19))
        GUICtrlSetData($serialNumber_I, StringMid($objOperatingSystem.SerialNumber, 1))
        GUICtrlSetData($ProductKey_I, DecodeProductKey($Bin))
        GUICtrlSetData($InstallDate_I, WMIDateStringToDate($objOperatingSystem.InstallDate))
        GUICtrlSetData($LastBootUpTime_I, WMIDateStringToDate($objOperatingSystem.LastBootUpTime))
        GUICtrlSetData($RegisteredOwner_I, RegRead($key4RegisteredOwner, "RegisteredOwner"))
        GUICtrlSetData($officeKey_I, getOfficeKey())
        GUICtrlSetData($officeKey_L, "Office " & $product)
        $counter -= 1
    ElseIf $counter < -1 Then
        Select
            Case $msg = $GUI_EVENT_CLOSE
                GUICtrlSetState($progressbar, $GUI_HIDE)
                GUICtrlSetData($status_L, "CU Mega")
                Sleep(2000)
                ExitLoop
        EndSelect
    EndIf
WEnd
Exit

Func DecodeProductKey($BinaryDPID)
    Local $bKey[15]
    Local $sKey[29]
    Local $Digits[24]
    Local $Value = 0
    Local $hi = 0
    Local $n = 0
    Local $i = 0
    Local $dlen = 29
    Local $slen = 15
    Local $Result

    $Digits = StringSplit("BCDFGHJKMPQRTVWXY2346789", "")
    $BinaryDPID = StringMid($BinaryDPID, 105, 30)
    For $i = 1 To 29 Step 2
        $bKey[Int($i / 2) ] = Dec(StringMid($BinaryDPID, $i, 2))
    Next
    For $i = $dlen - 1 To 0 Step - 1
        If Mod(($i + 1), 6) = 0 Then
            $sKey[$i] = "-"
        Else
            $hi = 0
            For $n = $slen - 1 To 0 Step - 1
                $Value = BitOR(BitShift($hi, -8), $bKey[$n])
                $bKey[$n] = Int($Value / 24)
                $hi = Mod($Value, 24)
            Next
            $sKey[$i] = $Digits[$hi + 1]
        EndIf
    Next
    For $i = 0 To 28
        $Result = $Result & $sKey[$i]
    Next
    Return $Result
EndFunc   ;==>DecodeProductKey

Func WMIDateStringToDate($dtmDate)
    Return (StringMid($dtmDate, 7, 2) & "/" & _
            StringMid($dtmDate, 5, 2) & "/" & StringLeft($dtmDate, 4) _
             & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate, 13, 2))
EndFunc   ;==>WMIDateStringToDate

Func progress()
    If $counter = 3 Then
        For $i = 0 To 20 Step 1
            GUICtrlSetData($progressbar, $i)
            Sleep($wait / 20)
        Next
    ElseIf $counter = 2 Then
        For $i = 20 To 50 Step 1
            GUICtrlSetData($progressbar, $i)
            Sleep($wait / 30)
        Next
    ElseIf $counter = 1 Then
        For $i = 50 To 80 Step 1
            GUICtrlSetData($progressbar, $i)
            Sleep($wait / 30)
        Next
    ElseIf $counter = 0 Then
        For $i = 80 To 100 Step 1
            GUICtrlSetData($progressbar, $i)
            Sleep($wait / 20)
        Next
        GUICtrlSetState($progressbar, $GUI_SHOW)
    EndIf
EndFunc   ;==>progress

Func getOfficeKey()
    Local $List[1]
    Local $i = 1
    $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\11.0\Common\InstallRoot", "Path")
    If $var <> "" Then
        $product = "2003"
        Dim $officeKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\11.0\Registration"
    Else
        $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0\Common\InstallRoot", "Path")
        If @error <> 0 Then
            GUICtrlSetData($status_L, "Info: Unable to find installationPath, maybe no Office installed!")
            Return "No Office XP or 2003 found"
        EndIf
        If $var <> "" Then
            $product = "XP"
            Dim $officeKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0\Registration"
        EndIf
    EndIf
    Dim $var = RegEnumKey($officeKey, $i)
    If @error <> 0 Then
        GUICtrlSetData($status_L, "Info: Unable to find REG_BINARY 'DigitalProductID', maybe no Office installed!")
        Return "No Office XP or 2003 found"
    Else
        $List[$i - 1] = RegRead($officeKey & "\" & $var, "DigitalProductID")
        If $List[$i - 1] = "" Then
            GUICtrlSetData($status_L, "Info: Unable to find REG_BINARY 'DigitalProductID', maybe no Office installed!")
        Else
            $key = $List[$i - 1]
            Return DecodeProductKey($key)
        EndIf
    EndIf
EndFunc   ;==>getOfficeKey

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Xenobiologist

Great! Thank you! :P

$key = RegRead("HKLM\SOFTWARE\Microsoft\Internet Explorer\Registration", "DigitalProductId")

$string = DecodeProductKey($key)

MsgBox(0, "String", $string)

Func DecodeProductKey($BinaryDPID)
    Local $bKey[15]
    Local $sKey[29]
    Local $Digits[24]
    Local $Value = 0
    Local $hi = 0
    Local $n = 0
    Local $i = 0
    Local $dlen = 29
    Local $slen = 15
    Local $Result

    $Digits = StringSplit("BCDFGHJKMPQRTVWXY2346789", "")
    $BinaryDPID = StringMid($BinaryDPID, 105, 30)
    For $i = 1 To 29 Step 2
        $bKey[Int($i / 2) ] = Dec(StringMid($BinaryDPID, $i, 2))
    Next
    For $i = $dlen - 1 To 0 Step - 1
        If Mod(($i + 1), 6) = 0 Then
            $sKey[$i] = "-"
        Else
            $hi = 0
            For $n = $slen - 1 To 0 Step - 1
                $Value = BitOR(BitShift($hi, -8), $bKey[$n])
                $bKey[$n] = Int($Value / 24)
                $hi = Mod($Value, 24)
            Next
            $sKey[$i] = $Digits[$hi + 1]
        EndIf
    Next
    For $i = 0 To 28
        $Result = $Result & $sKey[$i]
    Next
    Return $Result
EndFunc   ;==>DecodeProductKey
Link to comment
Share on other sites

Glad that I could help you first time. :P

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • 2 months later...

Xenobiologist

Great! Thank you! :P

$key = RegRead("HKLM\SOFTWARE\Microsoft\Internet Explorer\Registration", "DigitalProductId")

$string = DecodeProductKey($key)

MsgBox(0, "String", $string)

Func DecodeProductKey($BinaryDPID)
    Local $bKey[15]
    Local $sKey[29]
    Local $Digits[24]
    Local $Value = 0
    Local $hi = 0
    Local $n = 0
    Local $i = 0
    Local $dlen = 29
    Local $slen = 15
    Local $Result

    $Digits = StringSplit("BCDFGHJKMPQRTVWXY2346789", "")
    $BinaryDPID = StringMid($BinaryDPID, 105, 30)
    For $i = 1 To 29 Step 2
        $bKey[Int($i / 2) ] = Dec(StringMid($BinaryDPID, $i, 2))
    Next
    For $i = $dlen - 1 To 0 Step - 1
        If Mod(($i + 1), 6) = 0 Then
            $sKey[$i] = "-"
        Else
            $hi = 0
            For $n = $slen - 1 To 0 Step - 1
                $Value = BitOR(BitShift($hi, -8), $bKey[$n])
                $bKey[$n] = Int($Value / 24)
                $hi = Mod($Value, 24)
            Next
            $sKey[$i] = $Digits[$hi + 1]
        EndIf
    Next
    For $i = 0 To 28
        $Result = $Result & $sKey[$i]
    Next
    Return $Result
EndFunc   ;==>DecodeProductKey
Yhe code is very useful ? Now, how to convert to primary binary string? And does it just input regstry directly?
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...