CS1110    Spring 2009   Assignment A1    
Submit on the CMS. Due date: 8 Feb, 11:59PM
Computer Viruses

Introduction

sickcomMarkus Hanhisalo of Helsinki University of Technology defines a computer virus as: “a program, a block of executable code, [that] attaches itself to overwrite or otherwise replace another program in order to reproduce itself without [the] knowledge of a PC user.” (reference: http://www.tml.tkk.fi/Opinnot/Tik-110.501/1997/viruses.html) Computer viruses are often designed to maliciously corrupt or steal data from individuals. Sometimes, they cause computers to stop working all together.

Computer viruses are different from computer worms. A virus attaches itself to other programs, while a worm is a self-contained program that spreads copies of itself to other computers without attaching itself to other programs.

Some viruses and worms that come as attachments in an email appear to be jpg files —for example, MerryChristmas.jpg! But if your computer properly displayed file extensions/suffixes, you would see that this is really a file named MerryChristmas.jpg.exe, and clicking on it would cause it to execute, firmly embedding itself on your computer. Fix your operating systems preferences so that extensions/suffixes always show!virus

The first computer worm of any consequence was set loose by a Cornell computer science grad student. In Nov. 1988, Robert Morris wrote a worm —not to cause damage but to get an estimate of the size of the internet. He made a big mistake. When the worm reached another computer, it did not check to see whether it was already on that computer but just invaded the computer and sent itself on to other computers. So it spread much much faster than he thought it would. Anywhere from 6,000 to 60,000 computers were infected, and the internet was brought to its knees. Damage was estimated at $10M to $100M. Morris was convicted of violating the 1986 computer fraud and abuse act. He ended up on probation and owed a hefty fine plus community service. You can read more on Wikipedia. David Gries and Juris Hartmanis, of the Cornell CS Department, were on a Cornell commission that investigated the Morris worm. You can read about it in this article.

Because viruses and worms are so dangerous, people often wish to monitor them in order to help curtail their growth and spreading. Your task in this assignment is to develop a Java class Virus to maintain information about a virus, plus a JUnit class VirusTester to maintain a suite of testcases for Virus. This assignment will help illustrate how Java’s classes and objects can be used to maintain data about a collection of things –like computer viruses.

Read the whole assignment before starting. Follow the instructions given below in order to complete the assignment as quickly and as efficiently as possible.

HELP

If you don't know where to start, if you don't understand testing, if you are lost, SEE SOMEONE IMMEDIATELY —the course instructors, a TA, a consultant. Do not wait. A little one-on-one help can do wonders.

Class Virus

An instance of class Virus represents a single computer virus. It has several fields that one might use to describe a computer virus, as well as methods that operate on these fields. Here is a description of the fields, all of which should be private (you can choose the names of these fields).

Here are some details about these fields.

The class invariant. Accompanying your declarations of these fields should be comments that describe what each field means and what constraints hold on the field. For example, on the declaration of the field target, state in a comment that the field represents what kinds of computers the virus infects, 'W' for Windows, etc. The collection of the comments on these fields is called the class invariant. The class invariant describes all legal values for all the fields.

Whenever you write a method (see below), look through the class invariant and convince yourself that its exection leaves the class invariant true.

wurmark virus imagewormThe Wurmark-D worm (Jan 05) travels as an email attachment. It pretends to be amusing, but it installs itself on your computer and forwards itself to others.

The MCaffee website us.mcafee.com/virusInfo/default.asp contains information about recent threats by worms and viruses and trojan horses. Have a look at it.

Some emails go around the internet warning you about other emails that contain "virtual cards for you" --click on them, it says, and you will destroy your hard disk. Some of these warnings are real, others are hoaxes.

Virus Methods

Class Virus has the following methods. Pay close attention to the parameters and return values of each method. The descriptions, while informal, are complete and precise.

Constructor Description
Virus(String name, int month, int year, char target) Constructor: a new Virus. Parameters are, in order, the name of the virus, the month and year of discovery, and what kind of processor it targets. The virus has no id number, its predecessor is not known, and it has no known variations. Precondition: the month is in the range 1..12 and the target kind of processor is 'W' (windows), 'M' (Mac), or 'L' (Linux).
Virus(String name, char target, Virus pred, int month, int year, int id number) Constructor: a new Virus. Parameters are, in order, the name of the virus, its target, its predecessor, the month and year of discovery, and the id number. Precondition: the month is in the range 1..12, the target kind of processor is 'W' (windows),'M' (Mac), or 'L' (Linux), the predecessor is not null, and the id number is ≥ 0.

When you write a constructor body, be sure to set all the fields to appropriate values. Note that each constructor does NOT contain a parameter for each field. Nevertheless, each constructor MUST set each field to an appropriate value.

Getter Method Description
getName() = the name of this virus (a String)
getTarget() = the kind of operating system this virus attacks ('W' for windows, 'M' for Mac, or 'L' for Linux) (a char)
getMOD() = the month this virus was discovered, in the range 1..12 (an int)
getYOD() = the year this virus was discovered (an int)
getPredecessor() = the name (of the folder containing) this virus’s predecessor (a Virus) --null if none.
getId() = this virus’s id number (-1 if it has not been assigned one) (an int)
getVariations() = the number of viruses that have this one as a predecessor (an int)
toString() = a String representation of this Virus.  Its precise specification is given below.

Setter Method Description
setName(String s) Set the name of this virus to s.
setTarget(char t) Set the target processor of this virus to t. Precondition: t is one of 'W', 'M', and 'L'.
setMOD(int m) Set the month this virus was discovered to m. Precondition: m is in the range 1..12.
setYOD(int y) Set the year this virus was discovered to y.
setPredecessor(Virus v) Set the predecessor of this Virus to v.
Precondition: This virus’s predecessor is null, and v is not null.
setId(int i) Set this Virus’s id number to i.
Precondition: i >= 0, and the id number is currently -1.

Comparison Method Description
isOlder(Virus v) = "v is not null, and this Virus is older than v —i.e. this virus was discovered before v". (a boolean)
isOlder(Virus v1, Virus v2) Static method. = "v1 and v2 are not null, and v1 is older than v2 —i.e. v1 was discovered before v2". (a boolean)

The names of your methods must match those listed above exactly, including capitalization. The number of parameters and their order must also match. The best way to ensure this is to copy and paste from this handout! Our testing will expect those method names, so any mismatch will fail during our testing. You are free to use any parameter names that you want. Read page 371 of the text for conventions on parameter names.

Each method MUST be preceded by an appropriate specification, or "spec", as a Javadoc comment. The best way to ensure this is to copy and paste. After you have pasted, be sure to do any necessary editing. For example, the spec of a function does not have to say that the function yields a boolean or int or anything else, because that is known from the header of the method.

A precondition should not be tested by the method; it is the responsibility of the caller to ensure that the precondition is met. For example, it is a mistake to call method setPredecessor with null for the predecessor argument. However, in function isOlder, the tests for v1 and v2 not null MUST be made; it is not a precondition but part of what must be tested.

It is possible for virus v1 to be v2's predecessor and visa versa, at the same time. We do not check for such strange occurrences.

In writing setPredecessor, be careful! If P is becoming the predecessor of this Virus, then P has one more variation, and the field of P that contains its number of variations has to be updated accordingly.

Do not use if-statements. Use conditional expressions (...? ... : ...) only in function toString.

Function toStringworm

We illustrate the required format of the output of toString with an example and then make some comments. Here is an example of output from function toString:

"W computer virus Superfun. Id 34. Discovered 6/2005. Has 2 variations."

Here are some points about this output.

  1. Exactly one blank separates each piece of information (including the word “computer” and the word “virus”), and the periods are necessary.
  2. The 'W' at the beginning means it is a windows virus. Use 'M' for Mac and 'L' for Linux.
  3. The name of the virus follows "computer virus".
  4. If the id number is unknown, omit it and the word "Id" entirely. (In the example above, omit " Id 34.")
  5. The predecessor is not described in the output of this function.
  6. If the virus has exactly 1 variation, the word "variation" should appear instead of "variations".
  7. In writing the body of function toString, do not use if-statements or switches. Instead, use the conditional expression (condition ? expression-1: expression-2). This is the only place that you may use the conditional expression.

Class VirusTester

You must build a suite of test cases, as you develop class Virus, in a JUnit class VirusTester. Make sure that your test suite adheres to the following principles:

How to do this assignment

First, remember that if-statements are not allowed. If your assignments has if-statements, you will be asked to revise the assignment and resubmit.

Second, you should develop and test the class in a methodologically sound way, which we outline below. If we detect that you did not develop it this way, we may ask you to start from scratch and write some other assignment.

At each step, make sure all methods are correct before proceeding to the next step. When adding a new method, cut and paste the comment and the header from the assignment handout and then edit the comment. It must have suitable javadoc specifications as well as suitable comments on the field declarations. The assignment will not be accepted for testing until it does.

Other hints and directions

Procedure for submission

You may submit the assignment whenever you wish. We will look at it in several steps.

1. If the field specifications and the javadoc specifications are not appropriate, we will ask you to fix them and resubmit.

2. If the field and javadoc specs are ok, we will look at your test cases. If they are inadequate, we will ask you to fix them and resubmit.

3. If the test cases are adequate, we will test your program. If there are errors, you will be asked to correct them and resubmit.

The assignment will be considered completed when it passes all three steps.

Submitting the assignment

First, at the top of file Virus.java, put a comment that says that you looked carefully at the specifications produced by clicking the javadoc button and checked that the specifications of methods and the class specification were OK (insert this comment after doing what the comments says).

Second, upload files Virus.java and VirusTester.java on the CMS.

Make sure you submit .java files. Do not submit a file with the extension/suffix .java~ or .class. It will help to set the preferences in your operating system so that extensions always appear.

hoax tsnumaiHoaxes

Email and websites are full of hoaxes, and sometimes it is hard to distinguish the hoax from the real. Some hoaxes show us pictures that are obviously made up and are thus easy to distinguish --the image to the right is supposed to be a tsunami, but tsunami waves are not hundreds of feet high. Others are not so easy. Whenever you get a frightening or astonishing email that may be dangerous or simply asks you to forward it to others, always look it up on snopes.com, a website that is devoted to maintaining up-to-date information on hoaxes. Almost always, this site will tell you whether something is real or is a hoax.