Question: Next, write another script named Q 1 B . py , that receives as a parameter ( on the command line ) the name of

Next, write another script named Q1B.py, that receives as a parameter (on the command line)
the name of a .py file in the current directory, e.g., x.py.
Q1B.py should check two things:
1) Is the given Python file a script (i.e., is it intended to be run directly)?
a. For our purposes, a Python file is considered a script if it contains an
if __name__==__main__: statement
2) Is it uninfected (i.e., does it not yet contain the virus code)?
If both checks are true, then the Q1B script should re-write the input script (e.g., x.py), so that
the new x.py will contain a Python script with the same functionality as of the original x.py,
except that the new script will also perform the following simple spyware payload functionality:
Whenever the new x.py script is run, it appends, to the end of a file called Q1B.out, a line
containing the entire command line used to invoke it, i.e., the file/script name (x.py) followed
by the arguments (parameters) with which the script (x.py) was run, if any. If Q1B.out does not
exist when the new x.py is run, then x.py should create Q1B.out.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!