Skip to content

Instantly share code, notes, and snippets.

@remzmike
Last active September 24, 2018 16:05
Show Gist options
  • Save remzmike/a76d168c631159cf1035fd43fad6a28f to your computer and use it in GitHub Desktop.
Save remzmike/a76d168c631159cf1035fd43fad6a28f to your computer and use it in GitHub Desktop.
convert between microsoft and oracle guids, reversing first-half endian-ness (2010)
# 10/25/2010
import sys, struct
def change(l):
return ''.join( ['{0}{1}'.format(a,b) for a,b in zip(l,l[1:])[::2][::-1]] )
def convert(guidstring):
ms = guidstring.replace('-','').replace('{','').replace('}','').upper()
return change(ms[0:8]) + change(ms[8:12]) + change(ms[12:16]) + ms[16:]
def convert2(guidstring):
guidstring = guidstring.replace('-','').replace('{','').replace('}','')
assert(len(guidstring)==32)
a,b,c,d = guidstring[0:8], guidstring[8:12], guidstring[12:16], guidstring[16:]
a = int(a,16)
b = int(b,16)
c = int(c,16)
x = struct.pack('<LHH',a,b,c).encode('hex')
return (x+d).upper()
if __name__=='__main__':
ms = '81248ffb-0528-4bc9-8bc2-e559139110e7'
oracle = 'FB8F24812805C94B8BC2E559139110E7'
x = convert(ms)
assert x == oracle
x2 = convert2(ms)
assert x2 == oracle
if len(sys.argv)!=2:
print 'specify a guid as the one and only argument'
# todo: put it in the clipboard...
print convert(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment