/bin/pyhiew/3rd/IDA-Names-Client.py

http://pyhiew.googlecode.com/ · Python · 53 lines · 32 code · 10 blank · 11 comment · 8 complexity · b35ab17983bd5eb0f2bc57ee9b58ff17 MD5 · raw file

  1. """
  2. Transfer names from IDA to PyHiew - Server
  3. This script is part of the PyHiew project.
  4. http://code.google.com/p/pyhiew/
  5. History
  6. ---------
  7. v1.0 - Initial version
  8. """
  9. import socket
  10. import pickle
  11. import zlib
  12. import idaapi
  13. import idautils
  14. HOST = 'localhost'
  15. PORT = 8666
  16. def pickle_sendz(host, port, var):
  17. try:
  18. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  19. s.connect((host, port))
  20. d = zlib.compress(pickle.dumps(var))
  21. s.send(d)
  22. s.close()
  23. return None
  24. except Exception, e:
  25. return str(e)
  26. idaapi.info("Please run the Hiew-Names-Server script and press OK")
  27. idaapi.show_wait_box("Gathering and sending names to %s:%d" % (HOST, PORT))
  28. info = []
  29. for ea, name in idautils.Names():
  30. offs = idaapi.get_fileregion_offset(ea)
  31. if offs == idaapi.BADADDR:
  32. continue
  33. is_func = False if idaapi.get_func(ea) is None else True
  34. info.append((offs, name, is_func))
  35. ok = pickle_sendz(HOST, PORT, info)
  36. idaapi.hide_wait_box()
  37. if ok is not None:
  38. idaapi.warning("Failed to send names:\n" + ok)
  39. else:
  40. idaapi.info("Names successfully transfered!")