SHARE
TWEET

guid2oid.py

waterjuice Sep 24th, 2019 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2. # Convert a GUID into valid OIDs of different forms. This produces the ISO OID in the 2.25 tree, the Microsoft one, and
  3. # three in the WaterJuice OID tree space.
  4. #
  5. # This is free and unencumbered software released into the public domain. Read https://unlicense.dev for details
  6.  
  7. import sys
  8. import uuid
  9.  
  10. try:
  11.     myGuid = uuid.UUID( sys.argv[1] )
  12. except:
  13.     print( "Syntax: guid2oid.py <Guid>" )
  14.     sys.exit( 1 )
  15.  
  16. # Create a 2.25.* OID (makes one large decimal from the guid)
  17. bigInt = int( myGuid.hex, 16 )
  18. oidForm1 = '2.25.%u' % bigInt
  19.  
  20. # Create an MS 1.2.840.113556.1.8000.2554.* OID (breaks GUID into smaller parts)
  21. oidParts = [None] * 7
  22. oidParts[0] = str( int( myGuid.hex[0:4], 16 ) )
  23. oidParts[1] = str( int( myGuid.hex[4:8], 16 ) )
  24. oidParts[2] = str( int( myGuid.hex[8:12], 16 ) )
  25. oidParts[3] = str( int( myGuid.hex[12:16], 16 ) )
  26. oidParts[4] = str( int( myGuid.hex[16:20], 16 ) )
  27. oidParts[5] = str( int( myGuid.hex[20:26], 16 ) )
  28. oidParts[6] = str( int( myGuid.hex[26:32], 16 ) )
  29. oidForm2 = '1.2.840.113556.1.8000.2554.%s' % '.'.join(oidParts)
  30.  
  31. # Create a WJ 1.3.6.1.4.1.54392.1.* OID (breaks GUID into 2 64 bit decimals)
  32. oidParts = [None] * 2
  33. oidParts[0] = str( int( myGuid.hex[0:16], 16 ) )
  34. oidParts[1] = str( int( myGuid.hex[16:32], 16 ) )
  35. oidForm3 = '1.3.6.1.4.1.54392.1.%s' % '.'.join(oidParts)
  36.  
  37. # Create a WJ 1.3.6.1.4.1.54392.2.* OID (breaks GUID into 4 32 bit decimals)
  38. oidParts = [None] * 4
  39. oidParts[0] = str( int( myGuid.hex[0:8], 16 ) )
  40. oidParts[1] = str( int( myGuid.hex[8:16], 16 ) )
  41. oidParts[2] = str( int( myGuid.hex[16:24], 16 ) )
  42. oidParts[3] = str( int( myGuid.hex[24:32], 16 ) )
  43. oidForm4 = '1.3.6.1.4.1.54392.2.%s' % '.'.join(oidParts)
  44.  
  45. # Create a WJ 1.3.6.1.4.1.54392.3.* OID (breaks GUID into 8 16 bit decimals)
  46. oidParts = [None] * 8
  47. oidParts[0] = str( int( myGuid.hex[0:4], 16 ) )
  48. oidParts[1] = str( int( myGuid.hex[4:8], 16 ) )
  49. oidParts[2] = str( int( myGuid.hex[8:12], 16 ) )
  50. oidParts[3] = str( int( myGuid.hex[12:16], 16 ) )
  51. oidParts[4] = str( int( myGuid.hex[16:20], 16 ) )
  52. oidParts[5] = str( int( myGuid.hex[20:24], 16 ) )
  53. oidParts[6] = str( int( myGuid.hex[24:28], 16 ) )
  54. oidParts[7] = str( int( myGuid.hex[28:32], 16 ) )
  55. oidForm5 = '1.3.6.1.4.1.54392.3.%s' % '.'.join(oidParts)
  56.  
  57.  
  58. # Print it
  59. print( myGuid )
  60. print( oidForm1 )
  61. print( oidForm2 )
  62. print( oidForm3 )
  63. print( oidForm4 )
  64. print( oidForm5 )
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top