2020-06-02 10:50:37 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import hashlib
|
|
|
|
import os
|
|
|
|
|
|
|
|
def create_output(args):
|
|
|
|
in_st = os.stat(args.input_file)
|
|
|
|
in_size = in_st.st_size
|
|
|
|
|
|
|
|
in_f = open(args.input_file, 'r+b')
|
|
|
|
in_bytes = in_f.read(in_size)
|
|
|
|
in_f.close()
|
|
|
|
|
2023-04-09 07:55:57 +00:00
|
|
|
if (args.pid_file):
|
|
|
|
pid_st = os.stat(args.pid_file)
|
|
|
|
pid_size = pid_st.st_size
|
|
|
|
|
|
|
|
pid_f = open(args.pid_file, 'r+b')
|
|
|
|
pid_bytes = pid_f.read(pid_size)
|
|
|
|
pid_f.close()
|
|
|
|
else:
|
|
|
|
pid_bytes = bytes.fromhex(args.pid)
|
|
|
|
|
2020-06-02 10:50:37 +00:00
|
|
|
sha256 = hashlib.sha256()
|
|
|
|
sha256.update(in_bytes)
|
|
|
|
|
|
|
|
out_f = open(args.output_file, 'w+b')
|
2023-04-09 07:55:57 +00:00
|
|
|
out_f.write(pid_bytes)
|
2020-06-02 10:50:37 +00:00
|
|
|
out_f.write(sha256.digest())
|
|
|
|
out_f.write(in_bytes)
|
|
|
|
out_f.close()
|
|
|
|
|
|
|
|
def main():
|
|
|
|
global args
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='')
|
|
|
|
|
|
|
|
parser.add_argument('--input-file',
|
|
|
|
dest='input_file',
|
|
|
|
action='store',
|
|
|
|
type=str,
|
|
|
|
help='Input file')
|
|
|
|
|
|
|
|
parser.add_argument('--output-file',
|
|
|
|
dest='output_file',
|
|
|
|
action='store',
|
|
|
|
type=str,
|
|
|
|
help='Output file')
|
|
|
|
|
2023-04-09 07:55:57 +00:00
|
|
|
parser.add_argument('--pid-file',
|
|
|
|
dest='pid_file',
|
|
|
|
action='store',
|
|
|
|
type=str,
|
|
|
|
help='Sercomm PID file')
|
|
|
|
|
2020-06-02 10:50:37 +00:00
|
|
|
parser.add_argument('--pid',
|
|
|
|
dest='pid',
|
|
|
|
action='store',
|
|
|
|
type=str,
|
|
|
|
help='Sercomm PID')
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if ((not args.input_file) or
|
|
|
|
(not args.output_file) or
|
2023-04-09 07:55:57 +00:00
|
|
|
(not args.pid_file and not args.pid)):
|
2020-06-02 10:50:37 +00:00
|
|
|
parser.print_help()
|
|
|
|
|
|
|
|
create_output(args)
|
|
|
|
|
|
|
|
main()
|