Guest User

Untitled

a guest
Jun 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. import struct
  2.  
  3. import json
  4. import sys
  5.  
  6. class RDQ(object):
  7. def __init__(self, f):
  8. self.f = f
  9. self.read = f.read
  10.  
  11. def read_str_short(self):
  12. l = struct.unpack('>H', self.f.read(2))[0]
  13. return self.read(l)
  14.  
  15. def read_str(self):
  16. l = struct.unpack('>I', self.f.read(4))[0]
  17. return self.read(l)
  18.  
  19.  
  20. def main(name):
  21. with open(name) as f:
  22. rdq = RDQ(f)
  23. # read some header junk
  24. rdq.read(36)
  25.  
  26. while True:
  27. pos = f.tell()
  28. 'basic_message'
  29. item_type = rdq.read_str_short()
  30. if len(item_type) == 0:
  31. break
  32.  
  33. 'resource'
  34. rdq.read(3)
  35. rdq.read_str_short()
  36.  
  37. 'exchange'
  38. rdq.read(7)
  39. rdq.read_str_short()
  40.  
  41. exchange = rdq.read(3)
  42. rdq.read_str_short()
  43.  
  44. rdq.read(3)
  45. queue = rdq.read_str_short()
  46.  
  47. 'content'
  48. rdq.read(3)
  49. rdq.read_str_short()
  50.  
  51. 'none'
  52. rdq.read(3)
  53. rdq.read_str_short()
  54.  
  55. rdq.read(6)
  56. content_type = rdq.read_str_short()
  57.  
  58. rdq.read(7)
  59. content = rdq.read_str()
  60.  
  61. rdq.read(66)
  62.  
  63. print json.dumps({'pos': pos, 'queue': queue, 'content_type': content_type, 'content': content})
  64.  
  65.  
  66. if __name__ == '__main__':
  67. main(sys.argv[1])
Add Comment
Please, Sign In to add comment