3
0

Lib.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. f.close()
  24. return sha.hexdigest()
  25. def clean_up(controller):
  26. """
  27. Removes the output files from a given controller
  28. :param controller: controller which created output files
  29. """
  30. os.remove(controller.pcap_dest_path)
  31. os.remove(controller.label_manager.label_file_path)
  32. """
  33. function patches for unittests
  34. """
  35. def get_bytes(count, ignore):
  36. """
  37. unittest patch for get_rnd_bytes (ID2TLib.Utility.py)
  38. :param count: count of requested bytes
  39. :param ignore: <not used>
  40. :return: a count of As
  41. """
  42. return b'A' * count
  43. def get_x86_nop(count, side_effect_free, char_filter):
  44. """
  45. unittest patch for get_rnd_x86_nop (ID2TLib.Utility.py)
  46. :param count: count of requested nops
  47. :param side_effect_free: <not used>
  48. :param char_filter: <not used>
  49. :return: a count of \x90
  50. """
  51. return b'\x90' * count