2
0

gdb-iterate-dll.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from gdb import *
  2. def search_dll(head, field, match, pfield):
  3. """
  4. Search in a DLL by iterates over it.
  5. head: name of the symbol denoting the head of the DLL
  6. field: the field that should be search for match
  7. match: the mathing value for field
  8. pfield: the field whose value is to be printed for matched elements; None to
  9. print all fields of the matched elemented
  10. """
  11. (symbol, _) = lookup_symbol(head)
  12. if symbol is None:
  13. print("Can't find symbol: " + head)
  14. return
  15. symbol_val = symbol.value()
  16. while symbol_val:
  17. symbol_val_def = symbol_val.dereference()
  18. field_val = symbol_val_def[field]
  19. if field_val.type.code == gdb.TYPE_CODE_INT:
  20. val = int(field_val)
  21. res = (match == val)
  22. elif (field_val.type.code == gdb.TYPE_CODE_STRING
  23. ) or (field_val.type.code == gdb.TYPE_CODE_ARRAY):
  24. val = str(field_val)
  25. res = (match == val)
  26. elif (field_val.type.code == gdb.TYPE_CODE_TYPEDEF):
  27. val = str(field_val)
  28. res = match in val
  29. else:
  30. continue
  31. if res:
  32. if pfield is None:
  33. print(symbol_val_def)
  34. else:
  35. print(symbol_val_def[pfield])
  36. symbol_val = symbol_val_def["next"]