Thus to summarize the complete design, the required user interface is created using the java swings and the key components used here are to choose the desired drive, folder or file of the system and the users can choose the desired location to start the C-worm scan operation. All the infected files are maintained in the few files and logs and these can be viewed by the users at any point of time and a detailed analysis of the worm and the corresponding scan operations can also done using this application. The actual implementation procedure is explained in detail in the next chapter.
Detailed explanation to the design procedure followed to implement the application is explained in the previous chapter and in this chapter the actual implementation procedure followed and explanation to the key coding blocks is given. As discussed in the design chapter, java swings framework is used to design the application and there are different java classed used in this process and this chapter provides an overview of all the important classes used in this application and important coding functionality used is provided in this chapter. Explanation to the classes is also given as per the flow of the application and is as given below
Important java classes
This section gives explanation to the important java classes used in this application and they are as given below
This is the main class of the complete application and the complete flow of the application is initiated from this application. When this java file is executed, the corresponding window is created where the users can choose different options in proceeding with the scanning process. As discussed java swings are used to create the required user interface of the application and the key components used in this application extends the key java swing frameworks.
The required window in this class extends the interface known as JFrame and thus it can inherit all the key components provided by the JFrame component. A default constructer is loaded at the beginning of the class implementation and the required logic is created in this constructer. Whenever the constructor is called at any point of the code, the complete coding logic can be inherited at the required place and re-writing the complete code can be avoided a lot.
Once the constructer is loaded across the class, all the variables are initiated and even the database created in this application is also invoked from this constructer. All the required log files are initiated in the try block of the code and this block is used to catch the default exceptions that may be raised while writing the information to the log file and the key code function written in this case is as given below
From the above code it is clear that all the components are designed and added to the windows with the corresponding parameters. Few labels, buttons and images are also created in this coding process and these files are maintained in the home location of the code where it is created. Complete layout is created in this process and required sizes to these layouts are also defined using the predefined methods of the java swings package as shown in the above piece of code. Once the required components are added to the main window, now the actions performed on these components should be tracked and analyzed further to implement the scan process.
There are few action and item listeners available with the java swings package and they can be inherited to track the actions performed by the end users with respect to the scan process in this application. Each and every button is provided with an action listener and whenever the action is performed on the corresponding button, the code written is invoked and the corresponding action is performed and the sample code used in this context is as shown below
From the above piece of code it is clear that the button b2 is added with an action listener and the corresponding method is written to capture the action to be done when the respective button is clicked. In this particular code few files are defined as the affected files and these files are written to the infected files section and then finally the process is on idle state for 1000 seconds and this is achieved using the multi-threading concept of java LANG package. When all the files are detected, the corresponding files are deleted from the database as shown in the above code.
Few run time executions are initiated in this process and these methods are to capture the runtime files and give the same as the input to the scanning process. Java IO package is used to write the files to the virus database and also the log files and the key method used in this process is File Write function is used to write the required content to the desired location across the application. Thus java class holds the key logic used in this application and the important coding functionalities used is discussed above.
This class can be used to view the details of the files infected by the C-worms and the corresponding text area used in the main window is created using the java swings concept. This class also extends the JFrame component in the java swings package and this class holds the key logic to create the text area and this text area is used to display the list of infected files till the time when the scan is under progress. The required input to this text area is given from the log file and buffered readers from the java IO package are used to read and write the content to the text area and the key coding functionality is used is as given below
From the above piece of code it is clear that a default constructer is used in this java class and the main logic of loading the required text area is given in this constructer. A default content pane is used to hold the text area and the required text area is added using the Text Area class of the java swings class. A super constructer is used in this context and this constructer is used to set the required title to the text area and the corresponding content pane and once the default values are set, now the actual components are added to the text area.
Background to the text area is added using few parameters with respect to the color attributes and the corresponding attributes used are 100, 151 and 104 and then the required color is set to the background of the considered text area. Once the default settings are created to the required text area, the corresponding text area is added to the content pane and size of the pane is also set using the setSize method of the content pane interface as shown in the above code. Once all the required parameters for the text area and the content pane are added, the text area is set to visible and the parameters is set to true such that all the components added are visible to the users.
Now once the required components with respect to the user interface are added, the actual files infected are fetched from the log file and inserted to the text area and the corresponding coding logic developed in this context is as given below
From the above code block, it can be observed that initially a file reader object is created and then initiated to the Scan.log file and now the same file reader object is given as the input to the buffered reader. All the classes are available with the Java IO package and they can be inherited in this piece of code by importing the required packages. A new string variable is created and assigned with the values of the log file and the key logic used here is that, a loop is iterated from the buffered reader and this loop is repeated till the last line of the log file and these values are added to the string variable and separated by a new line as shown in the above piece of code. Read line is the key method used in this process to iterate the loop and this function always returns the last line and when the last line is encountered the loop is stopped and all the corresponding values are added to the string variable as discussed above.
This is another java class used in this application, and this class can be used to track the overall system performance against the virus scan operations. This class almost shows the functionality of the task manager of the operating system and the key performance metrics of the CPU can be tracked using this java class. As discussed in the previous classes, java swings are used to create this interface and the corresponding coding logic followed is explained in this section.
This class extends the JFrame class from the java swings package and this is extended to create the basic user interface features to the windows being created against tracking the CPU performance against the C-worm detection. Few buttons, labels and a text area are used as the required components across this class and all the components are added to the content pane and finally the pane is set to visible using the same procedure as discussed in the previous section and the key coding logic used in this class are as given below
From the above block of code it is clear that, a typical run time environment is captured in this logic and this run time environment includes the CPU tracking and the required commands entered by the users. All the commands entered by the user are tracked and executed using the exec command and these commands are provided as the inputs to the buffered reader class that is inherited from the java IO class as discussed in the previous sections. All the buttons used in these classes are provided with some action listeners and the corresponding actions are captured when the end users click on the desired buttons and the corresponding screens are shown in the appendix section of this project.
This class is used to display the status of the scan operations and the corresponding graph generated against the detection rate and the detection time of the C-worms and even this class is created using the Java swings. All the required components are added to the chart using the key components of the java swings components and the required bars for the graph are created using the methods like jfree.chart package and all the required packages are imported to the class and the charts are generated and the key coding logic used for this class is as given below
From the above piece of the code it is clear that, the required chart components are imported using the corresponding packages and few colors assigned to the bars for the user display. All the possible chart options are used to create the chart to track the detection rate and detection time as discussed in the previous section.