By Ansty)
In Windows, all files have a property called LastModified, which is often used to compare suspicious files. Therefore, it is necessary for us to perform operations on this attribute, and we can also be accurate to seconds. As shown in Software Interface 1, I will not introduce the GUI creation. For details, refer to the code.
Figure 1
Select File
The target File is the beginning of all work. We use the JFileChooser control to create a File selection dialog box. The File is selected to obtain the absolute path of the File and provide it to the File class, therefore, we need to use the getAbsolutePath method to obtain the absolute path.
Public String chooseFile (){
Int choice;
String fileName = null;
JFileChooser jfc = new JFileChooser ();
// Create a JFileChooser Control
Jfc. setSize (400,400); // set the size of the file selection dialog box
Choice = jfc. showOpenDialog (this );
If (choice = JFileChooser. APPROVE_OPTION ){
FileName = jfc. getSelectedFile (). getAbsolutePath ();
// Obtain the absolute path of the selected file
}
Return fileName; // return the file path
}
Last modification time of the printed File
After obtaining the selected File from chooseFile (), create a File instance and use the lastModified method provided by the File class to get the last modification time. The prototype of this method is as follows.
LastModified
Public long lastModified ()
// Return the last modification time of the file indicated by this abstract path name
Why is the long type returned? After reading the Java doc, you can see that this long represents the time difference between the time and the calendar element (January 1, January 1, 1970, 00: 00: 00GMT) to calculate this value (in milliseconds ). We can use "new Date (objFile. lastModified (). toLocaleString ()" to obtain the familiar Date Format "yyyy-mm-dd hh: mm: ss ". However, we cannot use Date to obtain the getYear () method of the specific year, month, and day. Because it has expired, the returned value is also incorrect. Therefore, we need to use the Calendar method instead.
Calendar is an abstract method and cannot be instantiated. You need to use Calendar. getInstance () to obtain an instance. Because the Date field has expired, we use the Calendar. get () method to obtain the Year, month, and day field c. get (Calendar. Year ). Because the Month obtained by Calendar. Month will be less than one Month, we need "+ 1 ". I have not studied the specific cause. It may be a problem with the system time zone.
Public void print (){
Date date = new Date (objFile. lastModified ());
Calendar c = Calendar. getInstance ();
C. setTimeInMillis (objFile. lastModified ());
JtfTime. setText (date. toLocaleString ());
JtfYear. setText (c. get (Calendar. YEAR) + ""); // print the YEAR
JtfMonth. setText (c. get (Calendar. MONTH) + 1 + ""); // print the MONTH jtfDay. setText (c. get (Calendar. DAY_OF_MONTH) + ""); // print the date
JtfHour. setText (c. get (Calendar. HOUR_OF_DAY) + ""); // print the hour
JtfMin. setText (c. get (Calendar. MINUTE) + ""); // print the score
JtfSec. setText (c. get (Calendar. SECOND) + ""); // print seconds
}
Last modification time of the file
Because the Calendar class is an abstract class, we cannot use the constructor method to initialize it like a general class. Instead, we need to use the Calendar. set () method to set its attributes. Its prototype is as follows.
Set (int year, int month, int date, int hourOfDay, int minute, int second)
The set () method is used to obtain the Calendar type, while the setLastModified () parameter type of the File class is Long. Therefore, we must convert the Calendar to long, in this case, call the getTimeInMillis () method of the Calendar class, as shown in the following c. getTimeInMillis (). Because we added a 1 value when printing the month, we need to keep the original millisecond count correct in jtfMonth. if the number obtained by getText () is reduced by another 1, "Integer. parseInt (jtfMonth. getText ()-1 ".
Public void modifyTime (){
Int year = Integer. parseInt (jtfYear. getText ());
// Because the String type is obtained from the text box, we need to convert it to the int type.
Int month = Integer. parseInt (jtfMonth. getText ()-1;
...... Omitted code
C. set (year, month, day, hour, min, sec );
File. setLastModified (c. getTimeInMillis ());
Print ();
JbReset. setEnabled (true );
}
Restore time
The implementation of the entire function only saves the File time to an independent variable reset when loading the File at the beginning. During restoration, the reset value is directly transferred to the File. setLastModified () is complete.
Due to my own level, the algorithm implemented by the program has not been optimized, and some program exceptions have not been captured. However, this article only provides you with an idea, java can also be used to write black softwares. Although this is only a small software, it is enough to show that Java can also be used to write black soft, and because Java is cross-platform, that is to say, what we write in Windows can still be used in * nix, Mac, and other operating systems with JRE installed. Kill software is currently not very popular with Java programs. If we use Java to write backdoors, we believe it will run well in front of a lot of kill software. Next time, I will bring you some Java-written soft articles. Maybe our friends may have a cross-platform Trojan.