sercomm-payload.py 994 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env python3
  2. import argparse
  3. import hashlib
  4. import os
  5. def create_output(args):
  6. in_st = os.stat(args.input_file)
  7. in_size = in_st.st_size
  8. in_f = open(args.input_file, 'r+b')
  9. in_bytes = in_f.read(in_size)
  10. in_f.close()
  11. sha256 = hashlib.sha256()
  12. sha256.update(in_bytes)
  13. out_f = open(args.output_file, 'w+b')
  14. out_f.write(bytes.fromhex(args.pid))
  15. out_f.write(sha256.digest())
  16. out_f.write(in_bytes)
  17. out_f.close()
  18. def main():
  19. global args
  20. parser = argparse.ArgumentParser(description='')
  21. parser.add_argument('--input-file',
  22. dest='input_file',
  23. action='store',
  24. type=str,
  25. help='Input file')
  26. parser.add_argument('--output-file',
  27. dest='output_file',
  28. action='store',
  29. type=str,
  30. help='Output file')
  31. parser.add_argument('--pid',
  32. dest='pid',
  33. action='store',
  34. type=str,
  35. help='Sercomm PID')
  36. args = parser.parse_args()
  37. if ((not args.input_file) or
  38. (not args.output_file) or
  39. (not args.pid)):
  40. parser.print_help()
  41. create_output(args)
  42. main()