libmapi.so.1.0.0-gdb.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import datetime
  2. import math
  3. class CURRENCY_printer:
  4. def __init__(self, value):
  5. self.value = value
  6. def to_string(self):
  7. i = int(self.value["int64"])
  8. return "%d.%04d" % (i / 10000, i % 10000)
  9. class FILETIME_printer:
  10. def __init__(self, value):
  11. self.value = value
  12. def to_string(self):
  13. nsec = int(self.value["dwHighDateTime"]) << 32
  14. nsec += int(self.value["dwLowDateTime"])
  15. nsec -= 116444736000000000
  16. nsec /= 10000000
  17. return datetime.datetime.fromtimestamp(nsec).strftime("%Y-%m-%d %H:%M:%S")
  18. class GUID_printer:
  19. def __init__(self, value):
  20. self.value = value
  21. def to_string(self):
  22. return str(self.value.cast(gdb.lookup_type("_s_MAPIUID")))
  23. class GUID_p_printer:
  24. def __init__(self, value):
  25. self.value = value
  26. def to_string(self):
  27. return str(self.value.cast(gdb.lookup_type("_s_MAPIUID").pointer()))
  28. class LARGE_INTEGER_printer:
  29. def __init__(self, value):
  30. self.value = value
  31. def to_string(self):
  32. return self.value["QuadPart"];
  33. class MAPIUID_printer:
  34. def __init__(self, value):
  35. self.value = value
  36. def to_string(self):
  37. v = self.value["ab"]
  38. a = "{"
  39. a += "%02x" * 4 % (v[0], v[1], v[2], v[3])
  40. a += "-"
  41. a += "%02x%02x" % (v[4], v[5])
  42. a += "-"
  43. a += "%02x%02x" % (v[6], v[7])
  44. a += "-"
  45. a += "%02x" * 8 % (v[8], v[9], v[10], v[11], v[12], v[13], v[14], v[15])
  46. a += "}"
  47. return a
  48. class MAPIUID_p_printer:
  49. def __init__(self, value):
  50. self.value = value
  51. def to_string(self):
  52. return str(self.value.address) + " " + str(self.value.dereference())
  53. class SBinary_printer:
  54. def __init__(self, v):
  55. self.value = v
  56. self.voidp = gdb.lookup_type("void").pointer()
  57. def to_string(self):
  58. return str(self.value["cb"]) + "B:" + str(self.value["lpb"].cast(self.voidp))
  59. class SPropValue_printer:
  60. def __init__(self, value):
  61. self.value = value
  62. self.voidp = gdb.lookup_type("void").pointer()
  63. def mv_walk(self, arr, count):
  64. ret = "[" + str(count) + "]{"
  65. for i in xrange(0, count):
  66. if i != 0:
  67. ret += ", "
  68. ret += str(arr[i])
  69. return ret + "}"
  70. def mv_decode(self):
  71. type = self.value["ulPropTag"] & 0xFFFF
  72. v = self.value["Value"]
  73. if (type == 0x1002):
  74. return "PT_MV_SHORT" + self.mv_walk(v["MVi"]["lpi"], v["MVi"]["cValues"])
  75. elif (type == 0x1003):
  76. return "PT_MV_LONG" + self.mv_walk(v["MVl"]["lpl"], v["MVl"]["cValues"])
  77. elif (type == 0x1004):
  78. return "PT_MV_FLOAT" + self.mv_walk(v["MVflt"]["lpflt"], v["MVflt"]["cValues"])
  79. elif (type == 0x1005):
  80. return "PT_MV_DOUBLE" + self.mv_walk(v["MVdbl"]["lpdbl"], v["MVdbl"]["cValues"])
  81. elif (type == 0x1006):
  82. return "PT_MV_CURRENCY" + self.mv_walk(v["MVcur"]["lpcur"], v["MVcur"]["cValues"])
  83. elif (type == 0x1007):
  84. return "PT_MV_APPTIME" + self.mv_walk(v["MVat"]["lpat"], v["MVat"]["cValues"])
  85. elif (type == 0x1014):
  86. return "PT_MV_LONGLONG" + self.mv_walk(v["MVli"]["lpli"], v["MVli"]["cValues"])
  87. elif (type == 0x101E):
  88. return "PT_MV_STRING8" + self.mv_walk(v["MVszA"]["lppszA"], v["MVszA"]["cValues"])
  89. elif (type == 0x101F):
  90. return "PT_MV_UNICODE" + self.mv_walk(v["MVszW"]["lppszW"], v["MVszW"]["cValues"])
  91. elif (type == 0x1040):
  92. return "PT_MV_SYSTIME" + self.mv_walk(v["MVft"]["lpft"], v["MVft"]["cValues"])
  93. elif (type == 0x1048):
  94. return "PT_MV_CLSID" + self.mv_walk(v["MVguid"]["lpguid"], v["MVguid"]["cValues"])
  95. elif (type == 0x1102):
  96. return "PT_MV_BINARY" + self.mv_walk(v["MVbin"]["lpbin"], v["MVbin"]["cValues"])
  97. return "PT_MV_??"
  98. def to_string(self):
  99. type = self.value["ulPropTag"] & 0xFFFF
  100. v = self.value["Value"]
  101. if ((type & 0x1000) == 0x1000):
  102. return self.mv_decode()
  103. elif (type == 0):
  104. return "PT_UNSPEC"
  105. elif (type == 0x1):
  106. return "PT_NULL " + str(v["x"])
  107. elif (type == 0x2):
  108. return "PT_SHORT " + str(v["i"])
  109. elif (type == 0x3):
  110. return "PT_LONG " + str(v["l"])
  111. elif (type == 0x4):
  112. return "PT_FLOAT " + str(v["flt"])
  113. elif (type == 0x5):
  114. return "PT_DOUBLE " + str(v["dbl"])
  115. elif (type == 0x6):
  116. return "PT_CURRENCY " + str(v["cur"])
  117. elif (type == 0x7):
  118. return "PT_APPTIME " + str(v["at"])
  119. elif (type == 0xA):
  120. return "PT_ERROR " + str(v["err"])
  121. elif (type == 0xB):
  122. return "PT_BOOLEAN " + str(v["b"])
  123. elif (type == 0xD):
  124. return "PT_OBJECT " + str(v["x"])
  125. elif (type == 0x14):
  126. return "PT_LONGLONG " + str(v["li"])
  127. elif (type == 0x1E):
  128. return "PT_STRING8 " + str(v["lpszA"])
  129. elif (type == 0x1F):
  130. return "PT_UNICODE " + str(v["lpszW"])
  131. elif (type == 0x40):
  132. return "PT_SYSTIME " + str(v["ft"])
  133. elif (type == 0x48):
  134. return "PT_CLSID " + str(v["lpguid"])
  135. elif (type == 0x102):
  136. return "PT_BINARY " + str(v["bin"])
  137. else:
  138. return "PT_??"
  139. def lookup_type(val):
  140. dtype = val.type.strip_typedefs()
  141. dname = str(dtype)
  142. if dname == "LARGE_INTEGER" or dname == "ULARGE_INTEGER":
  143. return LARGE_INTEGER_printer(val)
  144. if dname == "SBinary":
  145. return SBinary_printer(val)
  146. if dname == "SPropValue":
  147. return SPropValue_printer(val)
  148. if dname == "FILETIME":
  149. return FILETIME_printer(val)
  150. if dname == "GUID":
  151. return GUID_printer(val)
  152. if dtype == gdb.lookup_type("GUID").pointer():
  153. return GUID_p_printer(val)
  154. if dname == "MAPIUID":
  155. return MAPIUID_printer(val)
  156. if dtype == gdb.lookup_type("MAPIUID").pointer():
  157. return MAPIUID_p_printer(val)
  158. iname = str(val.type)
  159. if iname == "CURRENCY":
  160. return CURRENCY_printer(val)
  161. return None
  162. gdb.pretty_printers.append(lookup_type)