Lib.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. """
  9. helper functions for generic_test
  10. """
  11. def get_sha256(file):
  12. """
  13. Generates a sha256 checksum from file
  14. :param file: absolute path to file
  15. :return: sha256 checksum
  16. """
  17. sha = hashlib.sha256()
  18. with open(file, 'rb') as f:
  19. while True:
  20. data = f.read(0x100000)
  21. if not data:
  22. break
  23. sha.update(data)
  24. f.close()
  25. return sha.hexdigest()
  26. def clean_up(controller):
  27. """
  28. Removes the output files from a given controller
  29. :param controller: controller which created output files
  30. """
  31. os.remove(controller.pcap_dest_path)
  32. os.remove(controller.label_manager.label_file_path)
  33. """
  34. function patches for unittests
  35. """
  36. def get_bytes(count, ignore):
  37. """
  38. unittest patch for get_rnd_bytes (ID2TLib.Utility.py)
  39. :param count: count of requested bytes
  40. :param ignore: <not used>
  41. :return: a count of As
  42. """
  43. return b'A' * count
  44. def get_x86_nop(count, side_effect_free, char_filter):
  45. """
  46. unittest patch for get_rnd_x86_nop (ID2TLib.Utility.py)
  47. :param count: count of requested nops
  48. :param side_effect_free: <not used>
  49. :param char_filter: <not used>
  50. :return: a count of \x90
  51. """
  52. return b'\x90' * count
  53. def get_win_size(pkts_num):
  54. result = []
  55. for i in range(0, pkts_num):
  56. result.append(10)
  57. return result
  58. def get_rnd_short():
  59. return 10