-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathencode.py
54 lines (42 loc) · 1.25 KB
/
encode.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
import base64
import sys
import os
def b64(inpath: str) -> None:
key = "=ADR=".encode("utf-8")
outpath = os.path.dirname(inpath) + "\\ADR.b64"
print(f"{inpath} => {outpath}")
with open(inpath,"rb") as file:
data = base64.encodebytes(file.read())
file.close()
with open(outpath, "wb") as file:
file.write(key)
file.write(data)
file.close()
def bin(inpath: str) -> None:
key = ord('A')
outpath = os.path.dirname(inpath) + "\\ADR.bin"
print(f"{inpath} => {outpath}")
with open(inpath,"rb") as file:
encoded = bytearray()
for c in file.read():
encoded.append(c ^ key)
with open(outpath, "wb") as file:
file.write(encoded)
file.close()
def xor_str(data: str, key: str):
encoded = ''.join([chr(ord(char) ^ ord(key)) for char in data])
for char in encoded:
hex_value = hex(ord(char))[2:].zfill(2)
print(f"0x{hex_value}", end=', ')
def main(args: list[str]) -> int:
if len(args) < 1:
return 1
inpath = sys.argv[1]
if not os.path.exists(inpath):
xor_str(inpath, 'A')
return 1
# b64(inpath)
bin(inpath)
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))