Created
May 20, 2017 18:13
-
-
Save LuxXx/47842fa75eeb44c7d817df8249752df0 to your computer and use it in GitHub Desktop.
Decompiler for AutoHotKey - Written in early 2015
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.BorderLayout; | |
import java.awt.Color; | |
import java.awt.Dimension; | |
import java.awt.GridLayout; | |
import java.awt.Toolkit; | |
import java.awt.datatransfer.Clipboard; | |
import java.awt.datatransfer.StringSelection; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import java.io.BufferedReader; | |
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import javax.swing.JButton; | |
import javax.swing.JFileChooser; | |
import javax.swing.JFrame; | |
import javax.swing.JLabel; | |
import javax.swing.JOptionPane; | |
import javax.swing.JScrollPane; | |
import javax.swing.JTextArea; | |
import javax.swing.UIManager; | |
public class Decompiler extends JFrame { | |
private static final long serialVersionUID = -1554777358761015720L; | |
public static void main(String[] args) { | |
try { | |
UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() ); | |
} catch( Exception e ) { | |
// Problem changing UI occured. Ignore and show in default mode instead. | |
} | |
new Decompiler(); | |
} | |
public Decompiler() { | |
setPreferredSize(new Dimension(600,200)); | |
pack(); | |
setDefaultCloseOperation(EXIT_ON_CLOSE); | |
setLocationRelativeTo(null); | |
setTitle("LuxXx' AHK Decompiler v0.1"); | |
setLayout(new GridLayout(1,2)); | |
JButton decompile = new JButton("Decompile File"); | |
decompile.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
JFileChooser ch = new JFileChooser(); | |
int result = ch.showOpenDialog(Decompiler.this); | |
if (result == JFileChooser.APPROVE_OPTION) { | |
try { | |
File file = ch.getSelectedFile(); | |
decompileFile(file); | |
} catch (FileNotFoundException e1) { | |
e1.printStackTrace(); | |
} | |
} | |
} | |
}); | |
add(decompile); | |
JButton decompilepackedExe = new JButton("Decompile packed executable"); | |
decompilepackedExe.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
//JOptionPane.showMessageDialog(Decompiler.this, "Coming soon!"); | |
String code = "notImplementedYet"; | |
printCode(code); | |
} | |
}); | |
add(decompilepackedExe); | |
setVisible(true); | |
} | |
private void decompileFile(File selectedFile) throws FileNotFoundException { | |
// TODO Auto-generated method stub | |
BufferedReader br = new BufferedReader(new FileReader(selectedFile)); | |
String line; | |
StringBuilder code = new StringBuilder(); | |
boolean showLines = false; | |
try { | |
while ((line = br.readLine()) != null) { | |
// | |
if (line.contains("<assembly ")) { | |
showLines = false; | |
} | |
if(showLines) { | |
code.append(line + "\n"); | |
} | |
// wenn start des codes gefunden setze, show lines auf true | |
if (line.contains("<COMPILER: v")) { | |
showLines = true; | |
} | |
} | |
br.close(); | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
printCode(code.toString()); | |
} | |
private void printCode(String code) { | |
if (code.length() < 1) { | |
JOptionPane.showMessageDialog(this, "Konnte Datei nicht decompilieren"); | |
return; | |
} | |
JFrame popup = new JFrame(); | |
popup.setPreferredSize(new Dimension((int)Toolkit.getDefaultToolkit().getScreenSize().getWidth()-200,(int)Toolkit.getDefaultToolkit().getScreenSize().getHeight()-200)); | |
popup.pack(); | |
popup.setDefaultCloseOperation(DISPOSE_ON_CLOSE); | |
popup.setLocationRelativeTo(this); | |
popup.setTitle("Decompiled Result"); | |
popup.setLayout(new BorderLayout()); | |
JTextArea text = new JTextArea(code.replaceAll("[^\\x00-\\x7F]", "")); | |
text.setEditable(true); | |
JScrollPane sp = new JScrollPane(text); | |
popup.add(sp,BorderLayout.CENTER); | |
JButton copy = new JButton("Copy to clipboard"); | |
copy.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
StringSelection selection = new StringSelection(code); | |
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); | |
clipboard.setContents(selection, selection); | |
JOptionPane.showMessageDialog(popup, "Code kopiert"); | |
} | |
}); | |
popup.add(copy,BorderLayout.SOUTH); | |
popup.setVisible(true); | |
JLabel info = new JLabel("Bitte die letzten Zeilen des Codes überprüfen."); | |
info.setHorizontalAlignment(JLabel.CENTER); | |
info.setForeground(Color.RED); | |
popup.add(info, BorderLayout.NORTH); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment