Page 1 of 1 1
Topic Options
#197202 - 2009-12-21 10:43 PM HEX numbers larger than 7FFFFFFF
Bonji Offline
Starting to like KiXtart

Registered: 2001-09-28
Posts: 169
Loc: Virginia
Is it possible to work with HEX numbers larger than 7FFFFFFF? I know you can work with decimal numbers larger than 2147483647 using CDbl() or 0.0, but I can't find any way to apply those to HEX numbers.

I'm working with how UltraVNC stores MSLogon account information in the registry. It stores the account's SID value as HEX numbers in reversed order. For example, I need to convert the number 4048423081 to HEX (F14E08A9), but I keep getting stymied by the 7FFFFFFF limit.

Any suggestions?

Top
#197204 - 2009-12-22 08:17 PM Re: HEX numbers larger than 7FFFFFFF [Re: Bonji]
Bonji Offline
Starting to like KiXtart

Registered: 2001-09-28
Posts: 169
Loc: Virginia
I tried using VBScript to get around the issue, but it looks like the limitation is related to the Variant type used by KiXtart which is also used by VBScript.

I'm so close to being able to write ACL entries for UltraVNC directly into the registry, but I can't find any way to deal with HEX values that are large enough.

Top
#197205 - 2009-12-23 04:40 AM Re: HEX numbers larger than 7FFFFFFF [Re: Bonji]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Try this:
 Code:
Function ToHex($_V)

  Dim $_Hc					; hex charset
  Dim $_aD[0], $_aV				; array segments
  Dim $_Dv					; intermediate value
  Dim $_sH					; hex string

  $_Hc = '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'

  If VarType($_V) <> 5 Exit 87 EndIf		; must get a double!


  $_I = -1					; index pointer
  $_Dv = 1.0					; initial value
  While $_V > $_Dv				; determine required multipliers
    $_I = $_I + 1
    ReDim Preserve $_aD[$_I]
    $_aD[$_I] = $_Dv
    $_Dv = 256.0 * $_Dv
  Loop

  ; evaluate each hex octet and convert to a hex string
  For $_I = UBound($_aD) To 0 Step -1
    If $_V > $_aD[$_I]
      $_aV = Int($_V / $_aD[$_I])
      $_V = $_V - 1.0 * ($_aD[$_I] * $_aV)
      $_sH = $_sH + $_Hc[$_aV / 16] + $_Hc[$_aV Mod 16]
    Else
      $_sH = $_sH + '00'
    EndIf
  Next

  $ToHex = $_sH
  Exit 0

EndFunction
The function requires a double - either
 Code:
$V = 4048423081.0
ToHex($V) ?
or
 Code:
$V = '4048423081'
$V = CDbl($V)
ToHex($V) ?
It returns hex strings, not hex values. Since you're converting decimal to hex string to write to the registry, this should be fine. It seems to work fine with arbitrarily large numbers - I tested with small values and large values up to 750,000,000,000,000 (didn't test anything larger). I verified by using Calc in scientific mode.

It's imperative that it get a double-precision value.

If this works for you, I'll wrap it in a header and put it in the UDF section.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#197206 - 2009-12-23 05:17 AM Re: HEX numbers larger than 7FFFFFFF [Re: Glenn Barnas]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4574
Loc: USA
Nice work Glenn... curious though... why couldn't the cdbl be done inside the function?

 Code:
if vartype($_V)=3
  $_V=cdbl($_V)
endif
_________________________
(... better days ahead)

Top
#197207 - 2009-12-23 11:56 AM Re: HEX numbers larger than 7FFFFFFF [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Tried that.. didn't work unless you sent the parameter as a string.
 Code:
$V = 456789123
ToHex($V)
immediately converts $v to an Int when it passes to the function. Doesn't matter if you stick the value in a variable or in the function call itself. Drove me nuts for a while..

Stick a "$_V ?" in the first line of the function to see what I mean. It gets an int, and converting it to a double gives you a double-precision wrong value. ;\)

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#197208 - 2009-12-23 03:12 PM Re: HEX numbers larger than 7FFFFFFF [Re: Glenn Barnas]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4574
Loc: USA
I'm cornfused I guess I will have to try it to understand.
_________________________
(... better days ahead)

Top
#197211 - 2009-12-23 05:45 PM Re: HEX numbers larger than 7FFFFFFF [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Maybe this will clear it up:
 Code:
$V = 4048423081
'V: ' $V ?

$V = 4048423081.0
'V: ' $V ?

$V = 4048423081
'V: ' CDbl($V) ?

$V = '4048423081'
'V: ' CDbl($V) ?

$V = CDbl(4048423081)
'V: ' $V ?
Large numbers without a decimal point default to INTs - casting them after the fact results in a double-precision INT, so to speak. Hence, I can't cast the value to a double in the function unless it's passed to me as a string.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#197214 - 2009-12-23 08:21 PM Re: HEX numbers larger than 7FFFFFFF [Re: Glenn Barnas]
Bonji Offline
Starting to like KiXtart

Registered: 2001-09-28
Posts: 169
Loc: Virginia
A most impressive function Glenn. It appears this will get me over the Hex hump. Many thanks and praises I bestow.

-Ben

Top
#197215 - 2009-12-23 08:31 PM Re: HEX numbers larger than 7FFFFFFF [Re: Bonji]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4574
Loc: USA
I see... I missed the part about sending it as a string. Dang limitations... I ran into the large number limit one time too.
_________________________
(... better days ahead)

Top
#197216 - 2009-12-23 08:40 PM Re: HEX numbers larger than 7FFFFFFF [Re: Bonji]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
\:\)

Is the "hex hump" in any way related to (or the precursor to) a "hex dump" ?

I'm not sure what the upper limit of a double is.. I probably should look it up and trap for size limits as well, otherwise the octet loop will fail at some point. Buyer beware. ;\)

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#197217 - 2009-12-23 08:56 PM Re: HEX numbers larger than 7FFFFFFF [Re: Glenn Barnas]
Bonji Offline
Starting to like KiXtart

Registered: 2001-09-28
Posts: 169
Loc: Virginia
Both sound equally painful which mirrors my experience on this.

For my purposes, I'm dealing with numbers that are no larger than a single portion of a SID (the numbers between the hyphens). Hence, this function is fantastically adequate for my needs.

-Ben

Top
#197220 - 2009-12-24 09:17 PM Re: HEX numbers larger than 7FFFFFFF [Re: Bonji]
Bonji Offline
Starting to like KiXtart

Registered: 2001-09-28
Posts: 169
Loc: Virginia
I will post what I ended up with to push UltraVNC ACLs (New MS Logon) directly to the registry without using the MSLogonACL.exe tool. This code isn't as pretty as it should be, but I just wanted to throw it out there as a resource in case it could help anyone. The 3rd and 5th binary values (which are passed as decimal) need to be changed depending on the number of entries you want to include. The values I include are for a single entry.

Since the local Administrator account is the only one I push that changes per machine, I programmatically determine the registry value for it and hard code the registry values for my domain accounts. I just configure VNC for the users I want, export the hex values out of the registry, and plug in the decimal equivalents into my code. After exporting various ACL configurations, you can figure out which hex values are static and must be included per user/group account.

 Code:
Break On

$Computer = "TestComp"
$SID = AddLocalAdmin2VNC($Computer)


Function AddLocalAdmin2VNC($Computer)
	Dim $oWMI, $oAccount, $LocalAdminSID, $arySID, $Hex4, $Hex5, $Hex6, $Hex7
	Dim $ProcessSID, $oReg, $HKEY_LOCAL_MACHINE, $RegKey, $RegValueName, $RegValue, $aryBinarySID
	$oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $Computer + "\root\cimv2")
	If @Error
		$ = MessageBox("Could not connect to " + $Computer + ".","Error")
		Return
	EndIf

	$oAccount = $oWMI.Get("Win32_UserAccount.Name='Administrator',Domain='" + $Computer + "'")
	$LocalAdminSID = $oAccount.SID
	$arySID = Split($LocalAdminSID,"-")
	$Hex4 = CDbl($arySID[4])
	$Hex4 = ToHex($Hex4)
	$Hex4 = ConvertSID($Hex4)
	$Hex5 = CDbl($arySID[5])
	$Hex5 = ToHex($Hex5)
	$Hex5 = ConvertSID($Hex5)
	$Hex6 = CDbl($arySID[6])
	$Hex6 = ToHex($Hex6)
	$Hex6 = ConvertSID($Hex6)
	$Hex7 = CDbl($arySID[7])
	$Hex7 = ToHex($Hex7)
	$Hex7 = ConvertSID($Hex7)
	$ProcessSID = $Hex4 + "," + $Hex5 + "," + $Hex6 + "," + $Hex7
	$oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $Computer + "\root\default:StdRegProv")
	If @Error
		$ = MessageBox("Could not connect WMI Registry to " + $Computer + ".","Error")
		Return
	EndIf
	$HKEY_LOCAL_MACHINE = CInt(2147483650.0)
	$RegKey = "SOFTWARE\ORL\WinVNC3"
	$RegValueName = "ACL"
	$RegValue = "2,0,44,0,1,0,0,0,0,0,36,0,3,0,0,0,1,5,0,0,0,0,0,5,21,0,0,0," + $ProcessSID + ",0,0"
	$aryBinarySID = Split($RegValue,",")
	$ = $oReg.CreateKey($HKEY_LOCAL_MACHINE, $RegKey)
	If @Error
		$ = MessageBox("Could not create VNC Security registry key on " + $Computer + ".","Error")
		Return
	EndIf
	$ = $oReg.SetBinaryValue($HKEY_LOCAL_MACHINE, $RegKey, $RegValueName, $aryBinarySID)
	If @Error
		$ = MessageBox("Could not modify VNC Security on " + $Computer + ".","Error")
		Return
	EndIF
EndFunction

Function ConvertSID($Hex)
	Dim $Start, $HexStr, $NewHex, $aryTmp, $Element, $tmpElement
	While Len($Hex) < 4
		$Hex = "" + "0" + $Hex
	Loop
	$Start = 1
	$HexStr = SubStr($Hex,$Start,2)
	While $HexStr <> ""
		$NewHex = $NewHex + $HexStr + ","
		$Start = $Start + 2
		$HexStr = SubStr($Hex,$Start,2)
	Loop
	$Hex = SubStr($NewHex,1,Len($NewHex) - 1)
	ReDim $NewHex
	$aryTmp = Split($Hex,",")
	For Each $Element In $aryTmp
		$tmpElement = Execute("Exit &" + $Element)
		$NewHex = "" + $tmpElement + "," + $NewHex
	Next
	$ConvertSID = SubStr($NewHex,1,Len($NewHex) - 1)
EndFunction

Function ToHex($_V)
	Dim $_Hc, $_aD[0], $_aV, $_Dv, $_sH
	$_Hc = '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
	If VarType($_V) <> 5			; must get a double!
		Exit 87
	EndIf
	$_I = -1				; index pointer
	$_Dv = 1.0				; initial value
	While $_V > $_Dv			; determine required multipliers
		$_I = $_I + 1
		ReDim Preserve $_aD[$_I]
		$_aD[$_I] = $_Dv
		$_Dv = 256.0 * $_Dv
	Loop
	;Evaluate each hex octet and convert to a hex string
	For $_I = UBound($_aD) To 0 Step -1
		If $_V > $_aD[$_I]
			$_aV = Int($_V / $_aD[$_I])
			$_V = $_V - 1.0 * ($_aD[$_I] * $_aV)
			$_sH = $_sH + $_Hc[$_aV / 16] + $_Hc[$_aV Mod 16]
		Else
			$_sH = $_sH + '00'
		EndIf
	Next
	$ToHex = $_sH
	Exit 0
EndFunction

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 581 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.127 seconds in which 0.016 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org