-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
80 lines (70 loc) · 2.14 KB
/
test.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
# coding=utf-8
import os
import zipfile
import random
import time
import sys
import re
def change(path,name):
if not ('txt' in name or 'xml' in name):
return
curName = os.path.join(path,name)
tmpName = os.path.join(path,name+".backup2")
os.rename(curName,tmpName)
with open(tmpName,'r') as ifile:
with open(curName,'w') as ofile:
ss = ifile.read()
ss = re.sub("\r?\n","\r\n",ss)
ofile.write(ss)
os.remove(tmpName)
def insertSecret(path,name,secret,z):
curName = os.path.join(path,name)
tmpName = os.path.join(path,name+".backup")
os.rename(curName,tmpName)
with open(tmpName,'r') as ifile:
with open(curName,'w') as ofile:
ss = ifile.read()+"\r\n\r\n"+secret
ofile.write(ss)
change(path,name);
z.write(curName)
os.remove(curName)
os.rename(tmpName,curName)
def main():
locked = True
while locked:
try:
with open("lock",'r') as f:
print('locked')
locked = True
pass
except:
print("released")
locked = False
with open('lock', 'w') as f:
pass
basedir = os.getcwd();
rootdir = "Hacknet/HacknetLocalizationBase"
random.seed(time.time());
flag = False;
randomstr = sys.argv[1];
while flag == False:
with zipfile.ZipFile("downloads/"+sys.argv[2]+'.zip',"w") as z:
for path,dirs,files in os.walk(rootdir):
for file in files:
filepath = os.path.join(path,file);
#print(filepath);
change(path,file)
if flag == False and random.randint(0,100)==1 and ('xml' in file or 'txt' in file):
#print(filepath)
flag=True
insertSecret(path,file,randomstr,z)
else:
#change(path,file);
z.write(filepath);
os.remove('lock')
return ;
if __name__ == "__main__":
main();
else:
print("Hello Ruby");