Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def objectGUIDAsString(bytes):
- """
- Returns an AD objectGUID as a human-readable string. Takes into consideration big-endian formatting as follows:
- <reversed first four bytes>-<reversed second two bytes>-<reversed third two bytes>-<normal fourth two bytes>-<normal last 6 bytes>
- """
- ## python-ldap reads AD objectGUIDs incorrectly. Unpack each byte from the objectGUID as an integer, then translate back to hex and order correctly
- result =""
- byteIntVals=struct.unpack('!BBBBBBBBBBBBBBBB',bytes)
- for byteInt in byteIntVals:
- result = result + hex(byteInt).replace("0x",",")
- resultByteList=result[1:].split(",")
- #Prepend zero to single-digit values in byte list.
- for strByte in resultByteList:
- if len(strByte) == 1:
- resultByteList[resultByteList.index(strByte)] = "0" + strByte
- return resultByteList[3] + resultByteList[2] + resultByteList[1] + resultByteList[0] + "-" \
- + resultByteList[5] + resultByteList[4] + "-" \
- + resultByteList[7] + resultByteList[6] + "-" \
- + resultByteList[8] + resultByteList[9] + "-" \
- + resultByteList[10] + resultByteList[11] + resultByteList[12] + resultByteList[13] + resultByteList[14] + resultByteList[15]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement