3
0

Lib.py 1.4 KB

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