gdb-iterate-dll.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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) or (field_val.type.code == gdb.TYPE_CODE_ARRAY):
  23. val = str(field_val)
  24. res = (match == val)
  25. elif (field_val.type.code == gdb.TYPE_CODE_TYPEDEF):
  26. val = str(field_val)
  27. res = match in val
  28. else:
  29. continue
  30. if res:
  31. if pfield is None:
  32. print(symbol_val_def)
  33. else:
  34. print(symbol_val_def[pfield])
  35. symbol_val = symbol_val_def["next"]