Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package FileToHash;
- import java.awt.FileDialog;
- import java.io.File;
- import java.io.FileInputStream;
- import java.security.MessageDigest;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JOptionPane;
- /**
- *
- * @author leo
- */
- public class Malware extends javax.swing.JFrame {
- private File file;
- /**
- * Creates new form Malware
- */
- public Malware() {
- initComponents();
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- jLabel4 = new javax.swing.JLabel();
- jLabel5 = new javax.swing.JLabel();
- jLabel6 = new javax.swing.JLabel();
- jLabel7 = new javax.swing.JLabel();
- jLabel8 = new javax.swing.JLabel();
- jLabel9 = new javax.swing.JLabel();
- tfPath = new javax.swing.JTextField();
- tfMD5 = new javax.swing.JTextField();
- tfSHA1 = new javax.swing.JTextField();
- tfSHA256 = new javax.swing.JTextField();
- tfSHA384 = new javax.swing.JTextField();
- tfSHA512 = new javax.swing.JTextField();
- tfName = new javax.swing.JTextField();
- tfSize = new javax.swing.JTextField();
- tfType = new javax.swing.JTextField();
- btPath = new javax.swing.JButton();
- btRun = new javax.swing.JButton();
- btClear = new javax.swing.JButton();
- btAbout = new javax.swing.JButton();
- btExit = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setTitle("Malware");
- jLabel1.setText("Path");
- jLabel2.setText("MD5");
- jLabel3.setText("SHA1");
- jLabel4.setText("SHA256");
- jLabel5.setText("SHA384");
- jLabel6.setText("SHA512");
- jLabel7.setText("Name");
- jLabel8.setText("Size");
- jLabel9.setText("Type");
- tfPath.setColumns(60);
- tfPath.setFont(new java.awt.Font("Times New Roman", 0, 11)); // NOI18N
- tfMD5.setColumns(60);
- tfMD5.setFont(new java.awt.Font("Times New Roman", 0, 11)); // NOI18N
- tfSHA1.setColumns(60);
- tfSHA1.setFont(new java.awt.Font("Times New Roman", 0, 11)); // NOI18N
- tfSHA256.setColumns(60);
- tfSHA256.setFont(new java.awt.Font("Times New Roman", 0, 11)); // NOI18N
- tfSHA384.setColumns(60);
- tfSHA384.setFont(new java.awt.Font("Times New Roman", 0, 11)); // NOI18N
- tfSHA512.setColumns(60);
- tfSHA512.setFont(new java.awt.Font("Times New Roman", 0, 11)); // NOI18N
- tfName.setColumns(60);
- tfName.setFont(new java.awt.Font("Times New Roman", 0, 11)); // NOI18N
- tfSize.setColumns(60);
- tfSize.setFont(new java.awt.Font("Times New Roman", 0, 11)); // NOI18N
- tfType.setColumns(60);
- tfType.setFont(new java.awt.Font("Times New Roman", 0, 11)); // NOI18N
- btPath.setText("...");
- btPath.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btPathActionPerformed(evt);
- }
- });
- btRun.setText("Run");
- btRun.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btRunActionPerformed(evt);
- }
- });
- btClear.setText("Clear");
- btClear.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btClearActionPerformed(evt);
- }
- });
- btAbout.setText("About");
- btAbout.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btAboutActionPerformed(evt);
- }
- });
- btExit.setText("Exit");
- btExit.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btExitActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel1)
- .addComponent(jLabel2)
- .addComponent(jLabel3)
- .addComponent(jLabel4)
- .addComponent(jLabel5)
- .addComponent(jLabel6)
- .addComponent(jLabel7)
- .addComponent(jLabel8)
- .addComponent(jLabel9))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(btRun)
- .addGap(18, 18, 18)
- .addComponent(btClear)
- .addGap(18, 18, 18)
- .addComponent(btAbout)
- .addGap(18, 18, 18)
- .addComponent(btExit))
- .addGroup(layout.createSequentialGroup()
- .addComponent(tfPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(btPath))
- .addComponent(tfMD5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(tfSHA1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(tfSHA256, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(tfSHA384, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(tfSHA512, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(tfName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(tfSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(tfType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(26, 26, 26)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(tfPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(btPath))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel2)
- .addComponent(tfMD5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel3)
- .addComponent(tfSHA1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel4)
- .addComponent(tfSHA256, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel5)
- .addComponent(tfSHA384, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel6)
- .addComponent(tfSHA512, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel7)
- .addComponent(tfName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel8)
- .addComponent(tfSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel9)
- .addComponent(tfType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(btRun)
- .addComponent(btClear)
- .addComponent(btAbout)
- .addComponent(btExit))
- .addContainerGap(16, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void btPathActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- tfMD5.setText("");
- tfSHA1.setText("");
- tfSHA256.setText("");
- tfSHA384.setText("");
- tfSHA512.setText("");
- tfName.setText("");
- tfSize.setText("");
- tfType.setText("");
- file = getFileDialogOpen("*.*");
- if (file == null) {
- return;
- }
- tfPath.setText(file.getAbsolutePath());
- }
- private void btRunActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- try {
- tfMD5.setText(ToMD5(file.getAbsolutePath()));
- tfSHA1.setText(ToSHA1(file.getAbsolutePath()));
- tfSHA256.setText(ToSHA256(file.getAbsolutePath()));
- tfSHA384.setText(ToSHA384(file.getAbsolutePath()));
- tfSHA512.setText(ToSHA512(file.getAbsolutePath()));
- } catch (Exception ex) {
- Logger.getLogger(FileToHash.class.getName()).log(Level.SEVERE, null, ex);
- }
- tfName.setText(file.getName());
- tfSize.setText(String.valueOf(file.length() + " byte"));
- int dot = file.getName().lastIndexOf(".");
- if (dot < 0) {
- tfType.setText("NULL");
- } else {
- tfType.setText(file.getName().substring(dot + 1).toUpperCase());
- }
- }
- private void btClearActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- tfPath.setText("");
- tfMD5.setText("");
- tfSHA1.setText("");
- tfSHA256.setText("");
- tfSHA384.setText("");
- tfSHA512.setText("");
- tfName.setText("");
- tfSize.setText("");
- tfType.setText("");
- }
- private void btAboutActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- JOptionPane.showMessageDialog(null, "Author: Thieu Mao - KSEC");
- }
- private void btExitActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- System.exit(0);
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(Malware.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(Malware.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(Malware.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(Malware.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new Malware().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton btAbout;
- private javax.swing.JButton btClear;
- private javax.swing.JButton btExit;
- private javax.swing.JButton btPath;
- private javax.swing.JButton btRun;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JLabel jLabel5;
- private javax.swing.JLabel jLabel6;
- private javax.swing.JLabel jLabel7;
- private javax.swing.JLabel jLabel8;
- private javax.swing.JLabel jLabel9;
- private javax.swing.JTextField tfMD5;
- private javax.swing.JTextField tfName;
- private javax.swing.JTextField tfPath;
- private javax.swing.JTextField tfSHA1;
- private javax.swing.JTextField tfSHA256;
- private javax.swing.JTextField tfSHA384;
- private javax.swing.JTextField tfSHA512;
- private javax.swing.JTextField tfSize;
- private javax.swing.JTextField tfType;
- // End of variables declaration
- private File getFileDialogOpen(String string) {
- FileDialog fd = new FileDialog(this, "Chọn file", FileDialog.LOAD);
- fd.setFile(string);
- fd.setVisible(true);
- if (fd.getFile() == null) {
- return null;
- }
- File file = new File(fd.getDirectory() + fd.getFile());
- if (!file.canRead()) {
- JOptionPane.showMessageDialog(null, "File bạn chọn không thể đọc.",
- "Error", JOptionPane.ERROR_MESSAGE);
- return null;
- }
- return file;
- }
- private static String ToMD5(String FilePath) throws Exception {
- MessageDigest md = MessageDigest.getInstance("MD5");
- FileInputStream fis = new FileInputStream(FilePath);
- byte[] dataBytes = new byte[1024];
- int nread = 0;
- while ((nread = fis.read(dataBytes)) != -1) {
- md.update(dataBytes, 0, nread);
- };
- byte[] mdbytes = md.digest();
- //convert the byte to hex
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < mdbytes.length; i++) {
- sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
- }
- return sb.toString();
- }
- private static String ToSHA1(String FilePath) throws Exception {
- MessageDigest md = MessageDigest.getInstance("SHA1");
- FileInputStream fis = new FileInputStream(FilePath);
- byte[] dataBytes = new byte[1024];
- int nread = 0;
- while ((nread = fis.read(dataBytes)) != -1) {
- md.update(dataBytes, 0, nread);
- };
- byte[] mdbytes = md.digest();
- //convert the byte to hex
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < mdbytes.length; i++) {
- sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
- }
- return sb.toString();
- }
- private static String ToSHA256(String FilePath) throws Exception {
- MessageDigest md = MessageDigest.getInstance("SHA-256");
- FileInputStream fis = new FileInputStream(FilePath);
- byte[] dataBytes = new byte[1024];
- int nread = 0;
- while ((nread = fis.read(dataBytes)) != -1) {
- md.update(dataBytes, 0, nread);
- };
- byte[] mdbytes = md.digest();
- //convert the byte to hex
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < mdbytes.length; i++) {
- sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
- }
- return sb.toString();
- }
- private static String ToSHA384(String FilePath) throws Exception {
- MessageDigest md = MessageDigest.getInstance("SHA-384");
- FileInputStream fis = new FileInputStream(FilePath);
- byte[] dataBytes = new byte[1024];
- int nread = 0;
- while ((nread = fis.read(dataBytes)) != -1) {
- md.update(dataBytes, 0, nread);
- };
- byte[] mdbytes = md.digest();
- //convert the byte to hex
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < mdbytes.length; i++) {
- sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
- }
- return sb.toString();
- }
- private static String ToSHA512(String FilePath) throws Exception {
- MessageDigest md = MessageDigest.getInstance("SHA-512");
- FileInputStream fis = new FileInputStream(FilePath);
- byte[] dataBytes = new byte[1024];
- int nread = 0;
- while ((nread = fis.read(dataBytes)) != -1) {
- md.update(dataBytes, 0, nread);
- };
- byte[] mdbytes = md.digest();
- //convert the byte to hex
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < mdbytes.length; i++) {
- sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
- }
- return sb.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment