|
| 1 | +package com.javadeobfuscator.deobfuscator.ui; |
| 2 | + |
| 3 | +import java.io.File; |
| 4 | +import java.io.IOException; |
| 5 | +import java.util.List; |
| 6 | + |
| 7 | +import javax.swing.*; |
| 8 | +import javax.swing.border.TitledBorder; |
| 9 | + |
| 10 | +import com.javadeobfuscator.deobfuscator.ui.util.FallbackException; |
| 11 | +import com.javadeobfuscator.deobfuscator.ui.util.InvalidJarException; |
| 12 | +import com.javadeobfuscator.deobfuscator.ui.wrap.Config; |
| 13 | +import com.javadeobfuscator.deobfuscator.ui.wrap.Deobfuscator; |
| 14 | +import com.javadeobfuscator.deobfuscator.ui.wrap.Transformers; |
| 15 | +import com.javadeobfuscator.deobfuscator.ui.wrap.WrapperFactory; |
| 16 | +import java.awt.GridBagLayout; |
| 17 | +import java.awt.GridBagConstraints; |
| 18 | +import java.awt.Insets; |
| 19 | + |
| 20 | +public class SwingWindow |
| 21 | +{ |
| 22 | + private static Deobfuscator deob; |
| 23 | + private static Transformers trans; |
| 24 | + private static Config config; |
| 25 | + private static List<Class<?>> transformers; |
| 26 | + |
| 27 | + public static void main(String[] args) |
| 28 | + { |
| 29 | + try |
| 30 | + { |
| 31 | + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
| 32 | + }catch(ClassNotFoundException | InstantiationException |
| 33 | + | IllegalAccessException | UnsupportedLookAndFeelException e) |
| 34 | + { |
| 35 | + e.printStackTrace(); |
| 36 | + } |
| 37 | + loadWrappers(); |
| 38 | + //Initial frame |
| 39 | + JFrame frame = new JFrame(); |
| 40 | + frame.setTitle("Deobfuscator GUI"); |
| 41 | + frame.setBounds(100, 100, 580, 560); |
| 42 | + frame.getContentPane().setLayout(new GridBagLayout()); |
| 43 | + frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); |
| 44 | + |
| 45 | + //Deobfuscator Input |
| 46 | + GridBagConstraints gbc_IPanel = new GridBagConstraints(); |
| 47 | + gbc_IPanel.fill = GridBagConstraints.HORIZONTAL; |
| 48 | + gbc_IPanel.anchor = GridBagConstraints.FIRST_LINE_START; |
| 49 | + gbc_IPanel.insets = new Insets(15, 10, 0, 10); |
| 50 | + gbc_IPanel.weightx = 1; |
| 51 | + JPanel inputPnl = new JPanel(); |
| 52 | + inputPnl.setBorder(new TitledBorder("Deobfuscator Input")); |
| 53 | + frame.getContentPane().add(inputPnl, gbc_IPanel); |
| 54 | + inputPnl.setLayout(new GridBagLayout()); |
| 55 | + //TODO Options are loaded below |
| 56 | + int gridy = 0; |
| 57 | + for(gridy = 0; gridy < 2; gridy++) |
| 58 | + { |
| 59 | + GridBagConstraints gbc_Label = new GridBagConstraints(); |
| 60 | + gbc_Label.anchor = GridBagConstraints.PAGE_START; |
| 61 | + gbc_Label.insets = new Insets(5, 2, 2, 2); |
| 62 | + gbc_Label.gridx = 0; |
| 63 | + gbc_Label.gridy = gridy; |
| 64 | + inputPnl.add(new JLabel(gridy == 0 ? "Input:" : "Output:"), gbc_Label); |
| 65 | + GridBagConstraints gbc_Text = new GridBagConstraints(); |
| 66 | + gbc_Text.insets = new Insets(5, 2, 2, 2); |
| 67 | + gbc_Text.gridx = 1; |
| 68 | + gbc_Text.gridy = gridy; |
| 69 | + gbc_Text.weightx = 1; |
| 70 | + gbc_Text.fill = GridBagConstraints.HORIZONTAL; |
| 71 | + inputPnl.add(new JTextField(), gbc_Text); |
| 72 | + GridBagConstraints gbc_Select = new GridBagConstraints(); |
| 73 | + gbc_Select.insets = new Insets(5, 7, 2, 2); |
| 74 | + gbc_Select.gridx = 2; |
| 75 | + gbc_Select.gridy = gridy; |
| 76 | + gbc_Select.ipadx = 15; |
| 77 | + JButton button = new JButton("Select"); |
| 78 | + inputPnl.add(button, gbc_Select); |
| 79 | + } |
| 80 | + for(gridy = 2; gridy < 4; gridy++) |
| 81 | + { |
| 82 | + GridBagConstraints gbc_box = new GridBagConstraints(); |
| 83 | + gbc_box.anchor = GridBagConstraints.FIRST_LINE_START; |
| 84 | + gbc_box.insets = new Insets(5, 2, 2, 2); |
| 85 | + gbc_box.gridx = 0; |
| 86 | + gbc_box.gridy = gridy; |
| 87 | + inputPnl.add(new JCheckBox(gridy == 2 ? "Verify" : "Detect"), gbc_box); |
| 88 | + } |
| 89 | + |
| 90 | + //Other Options |
| 91 | + GridBagConstraints gbc_OPanel = new GridBagConstraints(); |
| 92 | + gbc_OPanel.fill = GridBagConstraints.BOTH; |
| 93 | + gbc_OPanel.anchor = GridBagConstraints.NORTHWEST; |
| 94 | + gbc_OPanel.insets = new Insets(15, 10, 20, 10); |
| 95 | + gbc_OPanel.gridy = 1; |
| 96 | + gbc_OPanel.weightx = 1; |
| 97 | + gbc_OPanel.weighty = 1; |
| 98 | + JPanel optionsPnl = new JPanel(); |
| 99 | + optionsPnl.setBorder(new TitledBorder("Other Options")); |
| 100 | + optionsPnl.setLayout(new GridBagLayout()); |
| 101 | + frame.getContentPane().add(optionsPnl, gbc_OPanel); |
| 102 | + |
| 103 | + //The tabbed pane |
| 104 | + JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.TOP); |
| 105 | + GridBagConstraints gbc_TabbedPane = new GridBagConstraints(); |
| 106 | + gbc_TabbedPane.fill = GridBagConstraints.BOTH; |
| 107 | + gbc_TabbedPane.weightx = 1; |
| 108 | + gbc_TabbedPane.weighty = 1; |
| 109 | + optionsPnl.add(tabbedPane, gbc_TabbedPane); |
| 110 | + |
| 111 | + //Transformers |
| 112 | + JPanel transformersPanel = new JPanel(); |
| 113 | + transformersPanel.setLayout(new GridBagLayout()); |
| 114 | + //First list (available) |
| 115 | + JScrollPane transformerListScroll = new JScrollPane(); |
| 116 | + DefaultListModel<String> transformerList = new DefaultListModel<>(); |
| 117 | + for(Class<?> clazz : transformers) |
| 118 | + transformerList.addElement(clazz.getName().replace("com.javadeobfuscator.deobfuscator.transformers.", "")); |
| 119 | + JList<String> transformerJList = new JList<>(transformerList); |
| 120 | + transformerJList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); |
| 121 | + transformerJList.setModel(transformerList); |
| 122 | + transformerListScroll.setViewportView(transformerJList); |
| 123 | + |
| 124 | + GridBagConstraints gbc_TransformerList = new GridBagConstraints(); |
| 125 | + gbc_TransformerList.anchor = GridBagConstraints.FIRST_LINE_START; |
| 126 | + gbc_TransformerList.fill = GridBagConstraints.BOTH; |
| 127 | + gbc_TransformerList.insets = new Insets(20, 20, 20, 10); |
| 128 | + gbc_TransformerList.weightx = 0.5; |
| 129 | + gbc_TransformerList.weighty = 1; |
| 130 | + transformersPanel.add(transformerListScroll, gbc_TransformerList); |
| 131 | + //Buttons |
| 132 | + JButton add = new JButton(">"); |
| 133 | + GridBagConstraints gbc_add = new GridBagConstraints(); |
| 134 | + gbc_add.gridx = 1; |
| 135 | + gbc_add.ipadx = 10; |
| 136 | + transformersPanel.add(add, gbc_add); |
| 137 | + JButton remove = new JButton("<"); |
| 138 | + GridBagConstraints gbc_remove = new GridBagConstraints(); |
| 139 | + gbc_remove.gridx = 1; |
| 140 | + gbc_remove.ipadx = 10; |
| 141 | + transformersPanel.add(remove, gbc_remove); |
| 142 | + //Second list (selected) |
| 143 | + JScrollPane transformerSelectedScroll = new JScrollPane(); |
| 144 | + DefaultListModel<String> transformerSelected = new DefaultListModel<>(); |
| 145 | + JList<String> selectedJList = new JList<>(transformerSelected); |
| 146 | + selectedJList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); |
| 147 | + selectedJList.setModel(transformerSelected); |
| 148 | + transformerSelectedScroll.setViewportView(selectedJList); |
| 149 | + GridBagConstraints gbc_TransformerSelected = new GridBagConstraints(); |
| 150 | + gbc_TransformerSelected.anchor = GridBagConstraints.LAST_LINE_START; |
| 151 | + gbc_TransformerSelected.fill = GridBagConstraints.BOTH; |
| 152 | + gbc_TransformerSelected.insets = new Insets(20, 10, 20, 20); |
| 153 | + gbc_TransformerSelected.gridx = 2; |
| 154 | + gbc_TransformerSelected.weightx = 0.5; |
| 155 | + gbc_TransformerSelected.weighty = 1; |
| 156 | + transformersPanel.add(transformerSelectedScroll, gbc_TransformerSelected); |
| 157 | + tabbedPane.addTab("Transformers", transformersPanel); |
| 158 | + |
| 159 | + frame.setVisible(true); |
| 160 | + } |
| 161 | + |
| 162 | + private static void loadWrappers() |
| 163 | + { |
| 164 | + WrapperFactory.setupJarLoader(false); |
| 165 | + deob = WrapperFactory.getDeobfuscator(); |
| 166 | + trans = WrapperFactory.getTransformers(); |
| 167 | + try |
| 168 | + { |
| 169 | + config = deob.getConfig(); |
| 170 | + transformers = trans.getTransformers(); |
| 171 | + }catch(FallbackException e) |
| 172 | + { |
| 173 | + config = null; |
| 174 | + transformers = null; |
| 175 | + fallbackLoad(e.path); |
| 176 | + } |
| 177 | + } |
| 178 | + |
| 179 | + private static void fallbackLoad(String path) |
| 180 | + { |
| 181 | + try |
| 182 | + { |
| 183 | + File file = new File(path); |
| 184 | + if(!file.exists()) |
| 185 | + throw new FallbackException("Loading error", "Path specified does not exist."); |
| 186 | + try |
| 187 | + { |
| 188 | + WrapperFactory.setupJarLoader(file); |
| 189 | + }catch(IOException e) |
| 190 | + { |
| 191 | + throw new FallbackException("Loading error", "IOException while reading file."); |
| 192 | + }catch(InvalidJarException e) |
| 193 | + { |
| 194 | + throw new FallbackException("Loading error", "Invaild JAR selected. Note that old versions of deobfuscator are not supported!"); |
| 195 | + } |
| 196 | + deob = WrapperFactory.getDeobfuscator(); |
| 197 | + trans = WrapperFactory.getTransformers(); |
| 198 | + config = deob.getConfig(); |
| 199 | + transformers = trans.getTransformers(); |
| 200 | + }catch(FallbackException e) |
| 201 | + { |
| 202 | + config = null; |
| 203 | + transformers = null; |
| 204 | + fallbackLoad(e.path); |
| 205 | + } |
| 206 | + } |
| 207 | +} |
0 commit comments