Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void btNhapActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- if (txtFile.getText().isEmpty()) {
- JOptionPane.showMessageDialog(null, "Error!");
- } else {
- try {
- // Lay ma Hash
- strMD5 = ToMD5(file.getAbsolutePath());
- strSHA1 = ToSHA1(file.getAbsolutePath());
- strSHA256 = ToSHA256(file.getAbsolutePath());
- strSHA384 = ToSHA384(file.getAbsolutePath());
- strSHA512 = ToSHA512(file.getAbsolutePath());
- // Doc file
- SAXBuilder builder = new SAXBuilder();
- File xmlFile = new File("MalwareData.xml");
- Document doc = (Document) builder.build(xmlFile);
- Element rootNode = doc.getRootElement();
- // update them file
- Element objects = rootNode.getChild("objects");
- List<Element> test = objects.getChildren();
- //System.out.println(test.size() + 1);
- String IDnext = String.valueOf(test.size() + 1);
- Element eFile = new Element("file").setAttribute("ID", IDnext);
- eFile.addContent(new Element("md5").setText(strMD5));
- eFile.addContent(new Element("sha1").setText(strSHA1));
- eFile.addContent(new Element("sha256").setText(strSHA256));
- eFile.addContent(new Element("sha384").setText(strSHA384));
- eFile.addContent(new Element("sha512").setText(strSHA512));
- eFile.addContent(new Element("filename").setText(file.getName()));
- eFile.addContent(new Element("size").setText(String.valueOf(file.length()) + " byte"));
- int dot = file.getName().lastIndexOf(".");
- String strType = "NULL";
- if (dot >= 0) {
- strType = file.getName().substring(dot + 1).toUpperCase();
- }
- eFile.addContent(new Element("MINEType").setText(strType));
- String strMalwareName = txtSign.getText();
- if (txtSign.getText().isEmpty()) {
- strMalwareName = "NULL";
- }
- eFile.addContent(new Element("MalwareName").setText(strMalwareName));
- String strSign = txtSign.getText();
- if (txtSign.getText().isEmpty()) {
- strSign = "NULL";
- }
- eFile.addContent(new Element("Sign").setText(strSign));
- objects.addContent(eFile);
- // cap nhat thoi gian
- DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy");
- String timeCurrent = dateFormat.format(new Date());
- Element timestamp = rootNode.getChild("timestamp");
- timestamp.setText(timeCurrent);
- // ghi file
- XMLOutputter xmlOutput = new XMLOutputter();
- xmlOutput.setFormat(Format.getPrettyFormat());
- xmlOutput.output(doc, new FileWriter("MalwareData.xml"));
- // Thong bao thanh cong
- System.out.println("File updated!");
- JOptionPane.showMessageDialog(null, "File updated!");
- } catch (Exception ex) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment