-
Notifications
You must be signed in to change notification settings - Fork 12
/
gen_native_message.py
executable file
·56 lines (46 loc) · 1.36 KB
/
gen_native_message.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import json
import struct
def usage():
"""Show usage and exit with non-zero status."""
sys.stderr.write(
"\n[+] Usage: %s cmd [command] | %s\n"
% (os.path.basename(__file__), "native_main.py")
)
sys.stderr.write("\n - Note: Use '..' as key-value separator")
sys.stderr.write(
"\n - Example: %s %s %s %s | %s\n"
% (
os.path.basename(__file__),
"cmd..win_restart_firefox",
"profiledir..auto",
"browser..firefox",
"native_main.py",
)
)
exit(-1)
if __name__ == "__main__":
"""Main functionalities are here for now."""
separator = ".."
msg = dict()
if len(sys.argv) > 1:
for i in range(1, len(sys.argv)):
key = sys.argv[i].strip().split(separator)[0]
val = sys.argv[i].strip().split(separator)[1]
if val.lower() == "true":
msg[key] = True
elif val.lower() == "false":
msg[key] = False
else:
msg[key] = val
if len(sys.argv) == 1:
usage()
msg = json.dumps(msg)
msg = "\r\n" + msg + "\r\n"
msg = msg.encode("utf-8")
packed_len = struct.pack("@I", len(msg))
sys.stdout.buffer.write(packed_len + msg)
sys.stdout.flush()