Hi, I'm reasonabily new to the forum (although I do use it as a source of reference when I code in KiX).

I've tried searching, but I cannot find anyway a binsid to SDDL UDF - does anyone know of a UDF that is available?

Specifcially, I want to convert the following VBScript (I'm at a loss as to how I can convert the BYTE values to process them in Kix).

Thanks in advance.

code:
  
'*
'* Setup the issuing authorities array
'*
Sub Init_IssueAuthorities( )
IssueAuthorities(0) = "-0-0"
IssueAuthorities(1) = "-1-0"
IssueAuthorities(2) = "-2-0"
IssueAuthorities(3) = "-3-0"
IssueAuthorities(4) = "-4"
IssueAuthorities(5) = "-5"
IssueAuthorities(6) = "-?"
IssueAuthorities(7) = "-?"
IssueAuthorities(8) = "-?"
IssueAuthorities(9) = "-?"

end Sub

'*******************************************************************************
' Helper Function to Format the string to a readable String format
'*******************************************************************************
function SDDL_SID ( oSID )
Dim Revision, SubAuthorities, strSDDL, IssueIndex, index, k, i
Dim p2, j, subtotal, dblSubAuth
'
' First byte is the revision value
'
Revision = ascb(midB(osid,1,1))
'
' Second byte is the number of sub authorities in the
' SID
'
SubAuthorities = CInt(ascb(midb(oSID,2,1)))
strSDDL = "S-" & Revision
IssueIndex = CInt(ascb(midb(oSID,8,1)))
'
' BYtes 2 - 8 are the issueing authority structure
' Currently these values are in the form:
' { 0, 0, 0, 0, 0, X}
'
' We use this fact to retreive byte number 8 as the index
' then look up the authorities for an array of values
'
strSDDL = strSDDL & IssueAuthorities(IssueIndex)
'
' The sub authorities start at byte number 9. The are 4 bytes long and
' the number of them is stored in the SubAuthorities variable.
'
index = 9
i = index
for k = 1 to SubAuthorities
'
' Very simple formula, the sub authorites are stored in the
' following order:
' Byte Index Starting Bit
' Byte 0 - Index 0
' Byte 1 - Index + 1 7
' Byte 2 - Index + 2 15
' Byte 3 - Index + 3 23
' Bytes0 - 4 make a DWORD value in whole. We need to shift the bits
' bits in each byte and sum them all together by multipling by powers of 2
' So the sub authority would be built by the following formula:
'
' SUbAuthority = byte0*2^0 + Byte1*2^8 + byte2*2^16 + byte3*2^24
'
' this be done using a simple short loop, initializing the power of two
' variable ( p2 ) to 0 before the start an incrementing by 8 on each byte
' and summing them all together.
'
p2 = 0
subtotal = 0
for j = 1 to 4
dblSubAuth = CDbl(ascb(midb(osid,i,1))) * (2^p2)
subTotal = subTotal + dblSubAuth
p2 = p2 + 8
i = i + 1
next
'
' Convert the value to a string, add it to the SDDL Sid and continue
'
strSDDL = strSDDL & "-" & cstr(subTotal)
next
SDDL_SID = strSDDL
End Function 'End of Function SDDL_SID()