Lib.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import os
  2. import hashlib
  3. from definitions import ROOT_DIR
  4. # TODO: generate better test pcap (1000-2000 packets)
  5. test_resource_dir = ROOT_DIR + "/../resources/test"
  6. test_pcap = ROOT_DIR + "/../resources/test/test.pcap"
  7. test_pcap_ips = ["192.168.189.143", "192.168.189.1"]
  8. test_pcap_empty = []
  9. """
  10. helper functions for generic_test
  11. """
  12. def get_sha256(file):
  13. """
  14. Generates a sha256 checksum from file
  15. :param file: absolute path to file
  16. :return: sha256 checksum
  17. """
  18. sha = hashlib.sha256()
  19. with open(file, 'rb') as f:
  20. while True:
  21. data = f.read(0x100000)
  22. if not data:
  23. break
  24. sha.update(data)
  25. f.close()
  26. return sha.hexdigest()
  27. def clean_up(controller):
  28. """
  29. Removes the output files from a given controller
  30. :param controller: controller which created output files
  31. """
  32. os.remove(controller.pcap_dest_path)
  33. os.remove(controller.label_manager.label_file_path)
  34. """
  35. function patches for unittests
  36. """
  37. def get_bytes(count, ignore):
  38. """
  39. unittest patch for get_rnd_bytes (ID2TLib.Utility.py)
  40. :param count: count of requested bytes
  41. :param ignore: <not used>
  42. :return: a count of As
  43. """
  44. return b'A' * count
  45. def get_x86_nop(count, side_effect_free, char_filter):
  46. """
  47. unittest patch for get_rnd_x86_nop (ID2TLib.Utility.py)
  48. :param count: count of requested nops
  49. :param side_effect_free: <not used>
  50. :param char_filter: <not used>
  51. :return: a count of \x90
  52. """
  53. return b'\x90' * count