showOpenMultipleDialog()
132 | {
133 | return showDialog(chooser -> chooser.showOpenMultipleDialog(null));
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/src/java/com/javadeobfuscator/deobfuscator/ui/component/WrapLayout.java:
--------------------------------------------------------------------------------
1 | package com.javadeobfuscator.deobfuscator.ui.component;
2 |
3 | import java.awt.Component;
4 | import java.awt.Container;
5 | import java.awt.Dimension;
6 | import java.awt.FlowLayout;
7 | import java.awt.Insets;
8 |
9 | import javax.swing.JScrollPane;
10 | import javax.swing.SwingUtilities;
11 |
12 | /**
13 | * FlowLayout subclass that fully supports wrapping of components.
14 | */
15 | public class WrapLayout extends FlowLayout
16 | {
17 | private Dimension preferredLayoutSize;
18 |
19 | /**
20 | * Constructs a new WrapLayout
with a left alignment and a default 5-unit horizontal and vertical gap.
21 | */
22 | public WrapLayout()
23 | {
24 | super();
25 | }
26 |
27 | /**
28 | * Constructs a new FlowLayout
with the specified alignment and a default 5-unit horizontal and vertical gap. The value of the alignment argument
29 | * must be one of
30 | * WrapLayout
, WrapLayout
,
31 | * or WrapLayout
.
32 | *
33 | * @param align the alignment value
34 | */
35 | public WrapLayout(int align)
36 | {
37 | super(align);
38 | }
39 |
40 | /**
41 | * Creates a new flow layout manager with the indicated alignment and the indicated horizontal and vertical gaps.
42 | *
43 | * The value of the alignment argument must be one of
44 | * WrapLayout
, WrapLayout
,
45 | * or WrapLayout
.
46 | *
47 | * @param align the alignment value
48 | * @param hgap the horizontal gap between components
49 | * @param vgap the vertical gap between components
50 | */
51 | public WrapLayout(int align, int hgap, int vgap)
52 | {
53 | super(align, hgap, vgap);
54 | }
55 |
56 | /**
57 | * Returns the preferred dimensions for this layout given the
58 | * visible components in the specified target container.
59 | *
60 | * @param target the component which needs to be laid out
61 | * @return the preferred dimensions to lay out the subcomponents of the specified container
62 | */
63 | @Override
64 | public Dimension preferredLayoutSize(Container target)
65 | {
66 | return layoutSize(target, true);
67 | }
68 |
69 | /**
70 | * Returns the minimum dimensions needed to layout the visible components contained in the specified target container.
71 | *
72 | * @param target the component which needs to be laid out
73 | * @return the minimum dimensions to lay out the subcomponents of the specified container
74 | */
75 | @Override
76 | public Dimension minimumLayoutSize(Container target)
77 | {
78 | Dimension minimum = layoutSize(target, false);
79 | minimum.width += (getHgap() * 2);
80 | return minimum;
81 | }
82 |
83 | /**
84 | * Returns the minimum or preferred dimension needed to layout the target container.
85 | *
86 | * @param target target to get layout size for
87 | * @param preferred should preferred size be calculated
88 | * @return the dimension to layout the target container
89 | */
90 | private Dimension layoutSize(Container target, boolean preferred)
91 | {
92 | synchronized (target.getTreeLock())
93 | {
94 | // Each row must fit with the width allocated to the containter.
95 | // When the container width = 0, the preferred width of the container
96 | // has not yet been calculated so lets ask for the maximum.
97 |
98 | Container container = target;
99 |
100 | while ((container == target || container.getSize().width == 0) && container.getParent() != null)
101 | {
102 | container = container.getParent();
103 | }
104 |
105 | int targetWidth = container.getSize().width;
106 |
107 | if (targetWidth == 0)
108 | targetWidth = Integer.MAX_VALUE;
109 |
110 | int hgap = getHgap();
111 | int vgap = getVgap();
112 | Insets insets = target.getInsets();
113 | int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2);
114 | int maxWidth = targetWidth - horizontalInsetsAndGap;
115 |
116 | // Fit components into the allowed width
117 |
118 | Dimension dim = new Dimension(0, 0);
119 | int rowWidth = 0;
120 | int rowHeight = 0;
121 |
122 | int nmembers = target.getComponentCount();
123 |
124 | for (int i = 0; i < nmembers; i++)
125 | {
126 | Component m = target.getComponent(i);
127 |
128 | if (m.isVisible())
129 | {
130 | Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();
131 |
132 | // Can't add the component to current row. Start a new row.
133 |
134 | int compWidth = rowWidth + d.width + hgap * 2 + 2;
135 | if (compWidth > maxWidth)
136 | {
137 | addRow(dim, rowWidth, rowHeight);
138 | rowWidth = 0;
139 | rowHeight = 0;
140 | }
141 |
142 | // Add a horizontal gap
143 | rowWidth += hgap;
144 |
145 | rowWidth += d.width;
146 | rowHeight = Math.max(rowHeight, d.height);
147 | }
148 | }
149 |
150 | addRow(dim, rowWidth, rowHeight);
151 |
152 | dim.width += Math.max(horizontalInsetsAndGap, maxWidth);
153 | dim.height += insets.top + insets.bottom + vgap * 2;
154 |
155 | // When using a scroll pane or the DecoratedLookAndFeel we need to
156 | // make sure the preferred size is less than the size of the
157 | // target containter so shrinking the container size works
158 | // correctly. Removing the horizontal gap is an easy way to do this.
159 |
160 | Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);
161 |
162 | if (scrollPane != null && target.isValid())
163 | {
164 | dim.width -= (hgap + 1);
165 | }
166 |
167 | return dim;
168 | }
169 | }
170 |
171 | /*
172 | * A new row has been completed. Use the dimensions of this row
173 | * to update the preferred size for the container.
174 | *
175 | * @param dim update the width and height when appropriate
176 | * @param rowWidth the width of the row to add
177 | * @param rowHeight the height of the row to add
178 | */
179 | private void addRow(Dimension dim, int rowWidth, int rowHeight)
180 | {
181 | dim.width = Math.max(dim.width, rowWidth);
182 |
183 | if (dim.height > 0)
184 | {
185 | dim.height += getVgap();
186 | }
187 |
188 | dim.height += rowHeight;
189 | }
190 | }
191 |
--------------------------------------------------------------------------------
/src/java/com/javadeobfuscator/deobfuscator/ui/util/ByteLoader.java:
--------------------------------------------------------------------------------
1 | package com.javadeobfuscator.deobfuscator.ui.util;
2 |
3 | import java.util.Map;
4 | import java.util.Set;
5 |
6 | import com.javadeobfuscator.deobfuscator.ui.SwingWindow;
7 |
8 | /**
9 | * ClassLoader that can find classes via their bytecode. Allows loading of external jar files to be instrumented before loading.
10 | */
11 | public final class ByteLoader extends ClassLoader
12 | {
13 | /**
14 | * Map of class names to their bytecode.
15 | */
16 | private final Map classes;
17 |
18 | /**
19 | * Create the loader with the map of classes to load from.
20 | *
21 | * @param classes {@link #classes}.
22 | */
23 | public ByteLoader(Map classes)
24 | {
25 | super(getSystemClassLoader());
26 | SwingWindow.mainThread.setContextClassLoader(this);
27 | this.classes = classes;
28 | }
29 |
30 | @Override
31 | protected final Class> findClass(String name) throws ClassNotFoundException
32 | {
33 | Class> loadedClass = findLoadedClass(name);
34 | if (loadedClass != null)
35 | {
36 | return loadedClass;
37 | }
38 |
39 | byte[] bytes = classes.get(name);
40 | if (bytes == null)
41 | {
42 | throw new ClassNotFoundException(name);
43 | }
44 | return defineClass(name, bytes, 0, bytes.length);
45 | }
46 |
47 | public final Set getClassNames()
48 | {
49 | return classes.keySet();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/java/com/javadeobfuscator/deobfuscator/ui/util/ExceptionUtil.java:
--------------------------------------------------------------------------------
1 | package com.javadeobfuscator.deobfuscator.ui.util;
2 |
3 | import java.io.PrintWriter;
4 | import java.io.StringWriter;
5 |
6 | import javax.swing.JOptionPane;
7 |
8 | import com.javadeobfuscator.deobfuscator.ui.SwingWindow;
9 |
10 | public class ExceptionUtil
11 | {
12 | public static void showFatalError(String message) {
13 | showFatalError(message, null);
14 | }
15 |
16 | public static void showFatalError(String message, Throwable t)
17 | {
18 | try
19 | {
20 | if (t != null)
21 | {
22 | t.printStackTrace();
23 | message = message + "\n" + getStackTrace(t);
24 | }
25 | SwingWindow.ensureSwingLafLoaded();
26 | JOptionPane.showMessageDialog(null, message, "Deobfuscator GUI - Error", JOptionPane.ERROR_MESSAGE);
27 | } catch (Throwable t2)
28 | {
29 | t2.printStackTrace();
30 | }
31 | System.exit(1);
32 | throw new Error("exit", t);
33 | }
34 |
35 | public static String getStackTrace(Throwable t)
36 | {
37 | StringWriter sw = new StringWriter();
38 | t.printStackTrace(new PrintWriter(sw));
39 | return sw.toString();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/java/com/javadeobfuscator/deobfuscator/ui/util/FallbackException.java:
--------------------------------------------------------------------------------
1 | package com.javadeobfuscator.deobfuscator.ui.util;
2 |
3 | import java.awt.GridBagConstraints;
4 | import java.awt.GridBagLayout;
5 | import java.awt.Insets;
6 | import java.io.File;
7 |
8 | import javax.swing.JButton;
9 | import javax.swing.JFileChooser;
10 | import javax.swing.JLabel;
11 | import javax.swing.JOptionPane;
12 | import javax.swing.JPanel;
13 | import javax.swing.JTextArea;
14 | import javax.swing.JTextField;
15 |
16 | import com.javadeobfuscator.deobfuscator.ui.SwingWindow;
17 | import com.javadeobfuscator.deobfuscator.ui.component.SynchronousJFXFileChooser;
18 | import javafx.stage.FileChooser;
19 |
20 | public class FallbackException extends Exception
21 | {
22 | public String path;
23 |
24 | public FallbackException(String title, String msg, Throwable cause)
25 | {
26 | super(msg, cause);
27 | this.printStackTrace();
28 | SwingWindow.ensureSwingLafLoaded();
29 | SwingWindow.initJFX();
30 | JPanel fallback = new JPanel();
31 | fallback.setLayout(new GridBagLayout());
32 | GridBagConstraints gbc = new GridBagConstraints();
33 | gbc.gridx = 0;
34 | gbc.gridy = 0;
35 | gbc.gridwidth = GridBagConstraints.REMAINDER;
36 | gbc.insets = new Insets(0, 0, 4, 0);
37 | fallback.add(new JLabel(msg), gbc);
38 | if (cause != null) {
39 | gbc.gridy++;
40 | JTextArea area = new JTextArea(ExceptionUtil.getStackTrace(cause));
41 | area.setEditable(false);
42 | fallback.add(area, gbc);
43 | }
44 | gbc.gridy++;
45 | fallback.add(new JLabel("Select deobfuscator.jar to try again:"), gbc);
46 | gbc.gridy++;
47 | JTextField textField = new JTextField(35);
48 | fallback.add(textField);
49 | gbc.gridx++;
50 | JButton button = new JButton("Select");
51 | button.addActionListener(e ->
52 | {
53 | SynchronousJFXFileChooser chooser = new SynchronousJFXFileChooser(() -> {
54 | FileChooser ch = new FileChooser();
55 | ch.setTitle("Select deobfuscator jar");
56 | ch.setInitialDirectory(new File("abc").getAbsoluteFile().getParentFile());
57 | ch.getExtensionFilters().addAll(
58 | new FileChooser.ExtensionFilter("Jar files", "*.jar"),
59 | new FileChooser.ExtensionFilter("Jar and Zip files", "*.jar", "*.zip"),
60 | new FileChooser.ExtensionFilter("Zip files", "*.zip"),
61 | new FileChooser.ExtensionFilter("All Files", "*.*"));
62 | return ch;
63 | });
64 | File file = chooser.showOpenDialog();
65 | if (file != null)
66 | {
67 | textField.setText(file.getAbsolutePath());
68 | }
69 | });
70 | GridBagConstraints gbc_Button = new GridBagConstraints();
71 | gbc_Button.insets = new Insets(0, 2, 0, 0);
72 | fallback.add(button, gbc_Button);
73 | Object[] options = {"Ok", "Cancel"};
74 | int result = JOptionPane.showOptionDialog(null, fallback, title,
75 | JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE,
76 | null, options, null);
77 | if (result == JOptionPane.CLOSED_OPTION || result == JOptionPane.NO_OPTION)
78 | System.exit(0);
79 | path = textField.getText();
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/java/com/javadeobfuscator/deobfuscator/ui/util/InvalidJarException.java:
--------------------------------------------------------------------------------
1 | package com.javadeobfuscator.deobfuscator.ui.util;
2 |
3 | /**
4 | * Exception to be thrown when a jar has been loaded for the deobfuscator
5 | * wrapper, but jar was not an instance of JavaDeobfuscator.
6 | */
7 | public class InvalidJarException extends Exception {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/src/java/com/javadeobfuscator/deobfuscator/ui/util/MiniClassReader.java:
--------------------------------------------------------------------------------
1 | // ASM: a very small and fast Java bytecode manipulation framework
2 | // Copyright (c) 2000-2011 INRIA, France Telecom
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions
7 | // are met:
8 | // 1. Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // 2. Redistributions in binary form must reproduce the above copyright
11 | // notice, this list of conditions and the following disclaimer in the
12 | // documentation and/or other materials provided with the distribution.
13 | // 3. Neither the name of the copyright holders nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 | // THE POSSIBILITY OF SUCH DAMAGE.
28 | package com.javadeobfuscator.deobfuscator.ui.util;
29 |
30 | /**
31 | * Minified version of ClassReader from ASM, only allows for fetching of class name.
Minification / stripping used because the rest of the class is unused.
32 | */
33 | public class MiniClassReader
34 | {
35 | private static final int CONSTANT_CLASS_TAG = 7;
36 | private static final int CONSTANT_FIELDREF_TAG = 9;
37 | private static final int CONSTANT_METHODREF_TAG = 10;
38 | private static final int CONSTANT_INTERFACE_METHODREF_TAG = 11;
39 | private static final int CONSTANT_STRING_TAG = 8;
40 | private static final int CONSTANT_INTEGER_TAG = 3;
41 | private static final int CONSTANT_FLOAT_TAG = 4;
42 | private static final int CONSTANT_LONG_TAG = 5;
43 | private static final int CONSTANT_DOUBLE_TAG = 6;
44 | private static final int CONSTANT_NAME_AND_TYPE_TAG = 12;
45 | private static final int CONSTANT_UTF8_TAG = 1;
46 | private static final int CONSTANT_METHOD_HANDLE_TAG = 15;
47 | private static final int CONSTANT_METHOD_TYPE_TAG = 16;
48 | private static final int CONSTANT_DYNAMIC_TAG = 17;
49 | private static final int CONSTANT_INVOKE_DYNAMIC_TAG = 18;
50 | private static final int CONSTANT_MODULE_TAG = 19;
51 | private static final int CONSTANT_PACKAGE_TAG = 20;
52 | /// ==========================================================
53 | private final byte[] b;
54 | private final int header;
55 | private int maxLen = 0;
56 | private final int[] offsets;
57 |
58 | public MiniClassReader(final byte[] buff)
59 | {
60 | this.b = buff;
61 | if (readShort(6) > 53)
62 | {
63 | throw new IllegalArgumentException("Unsupported class file major version " + readShort(6));
64 | }
65 | int poolSize = readUnsignedShort(8);
66 | int currIndex = 1;
67 | int curOffset = 10;
68 | offsets = new int[poolSize];
69 | while (currIndex < poolSize)
70 | {
71 | offsets[currIndex++] = curOffset + 1;
72 | int cpInfoSize;
73 | switch (buff[curOffset])
74 | {
75 | case CONSTANT_FIELDREF_TAG:
76 | case CONSTANT_METHODREF_TAG:
77 | case CONSTANT_INTERFACE_METHODREF_TAG:
78 | case CONSTANT_INTEGER_TAG:
79 | case CONSTANT_FLOAT_TAG:
80 | case CONSTANT_NAME_AND_TYPE_TAG:
81 | case CONSTANT_INVOKE_DYNAMIC_TAG:
82 | case CONSTANT_DYNAMIC_TAG:
83 | cpInfoSize = 5;
84 | break;
85 | case CONSTANT_LONG_TAG:
86 | case CONSTANT_DOUBLE_TAG:
87 | cpInfoSize = 9;
88 | currIndex++;
89 | break;
90 | case CONSTANT_UTF8_TAG:
91 | cpInfoSize = 3 + readUnsignedShort(curOffset + 1);
92 | if (cpInfoSize > maxLen)
93 | {
94 | maxLen = cpInfoSize;
95 | }
96 | break;
97 | case CONSTANT_METHOD_HANDLE_TAG:
98 | cpInfoSize = 4;
99 | break;
100 | case CONSTANT_CLASS_TAG:
101 | case CONSTANT_STRING_TAG:
102 | case CONSTANT_METHOD_TYPE_TAG:
103 | case CONSTANT_PACKAGE_TAG:
104 | case CONSTANT_MODULE_TAG:
105 | cpInfoSize = 3;
106 | break;
107 | default:
108 | throw new IllegalArgumentException();
109 | }
110 | curOffset += cpInfoSize;
111 | }
112 | this.header = curOffset;
113 | }
114 |
115 | public final String getClassName()
116 | {
117 | return readUTF8(offsets[readUnsignedShort(header + 2)], new char[maxLen]);
118 | }
119 |
120 | private final String readUTF8(final int offset, final char[] buf)
121 | {
122 | int poolIndex = readUnsignedShort(offset);
123 | if (offset == 0 || poolIndex == 0)
124 | {
125 | return null;
126 | }
127 | int utfOff = offsets[poolIndex];
128 | return readUTF(utfOff + 2, readUnsignedShort(utfOff), buf);
129 | }
130 |
131 | private final String readUTF(final int off, final int len, final char[] buf)
132 | {
133 | int currOff = off;
134 | int endOff = currOff + len;
135 | int curLen = 0;
136 | while (currOff < endOff)
137 | {
138 | int cB = b[currOff++];
139 | if ((cB & 0x80) == 0)
140 | {
141 | buf[curLen++] = (char) (cB & 0x7F);
142 | } else if ((cB & 0xE0) == 0xC0)
143 | {
144 | buf[curLen++] = (char) (((cB & 0x1F) << 6) + (b[currOff++] & 0x3F));
145 | } else
146 | {
147 | buf[curLen++] = (char) (((cB & 0xF) << 12) + ((b[currOff++] & 0x3F) << 6) + (b[currOff++] & 0x3F));
148 | }
149 | }
150 | return new String(buf, 0, curLen);
151 | }
152 |
153 | private final int readUnsignedShort(final int offset)
154 | {
155 | return ((b[offset] & 0xFF) << 8) | (b[offset + 1] & 0xFF);
156 | }
157 |
158 | private final short readShort(final int offset)
159 | {
160 | return (short) (((b[offset] & 0xFF) << 8) | (b[offset + 1] & 0xFF));
161 | }
162 | }
163 |
--------------------------------------------------------------------------------
/src/java/com/javadeobfuscator/deobfuscator/ui/util/Reflect.java:
--------------------------------------------------------------------------------
1 | package com.javadeobfuscator.deobfuscator.ui.util;
2 |
3 | import java.lang.reflect.Field;
4 |
5 | /**
6 | * Reflection wrapper
7 | */
8 | @SuppressWarnings("unchecked")
9 | public class Reflect
10 | {
11 |
12 | /**
13 | * Get all fields belonging to the given class.
14 | *
15 | * @param clazz Class containing fields.
16 | * @return Array of class's fields.
17 | */
18 | public static Field[] fields(Class> clazz)
19 | {
20 | return clazz.getDeclaredFields();
21 | }
22 |
23 | /**
24 | * Get the value of the field by its name in the given object instance.
25 | *
26 | * @param instance Object instance.
27 | * @param fieldName Field name.
28 | * @return Field value. {@code null} if could not be reached.
29 | */
30 | public static T get(Object instance, String fieldName)
31 | {
32 | try
33 | {
34 | Field field = instance.getClass().getDeclaredField(fieldName);
35 | field.setAccessible(true);
36 | return get(instance, field);
37 | } catch (NoSuchFieldException | SecurityException e)
38 | {
39 | return null;
40 | }
41 | }
42 |
43 | /**
44 | * Get the value of the field in the given object instance.
45 | *
46 | * @param instance Object instance.
47 | * @param field Field, assumed to be accessible.
48 | * @return Field value. {@code null} if could not be reached.
49 | */
50 | public static T get(Object instance, Field field)
51 | {
52 | try
53 | {
54 | return (T) field.get(instance);
55 | } catch (Exception e)
56 | {
57 | return null;
58 | }
59 | }
60 |
61 | /**
62 | * Sets the value of the field in the given object instance.
63 | *
64 | * @param instance Object instance.
65 | * @param field Field, assumed to be accessible.
66 | * @param value Value to set.
67 | */
68 | public static void set(Object instance, Field field, Object value)
69 | {
70 | try
71 | {
72 | field.set(instance, value);
73 | } catch (Exception e)
74 | {
75 | }
76 | }
77 |
78 | /**
79 | * Get instance field.
80 | *
81 | * @param instance
82 | * @param name
83 | * @return
84 | * @throws Exception
85 | */
86 | public static T getFieldO(Object instance, String name) throws Exception
87 | {
88 | Field f = instance.getClass().getDeclaredField(name);
89 | f.setAccessible(true);
90 | // get
91 | return (T) f.get(instance);
92 | }
93 |
94 | /**
95 | * Get static field.
96 | *
97 | * @param clazz
98 | * @param name
99 | * @return
100 | * @throws Exception
101 | */
102 | public static T getFieldS(Class> clazz, String name) throws Exception
103 | {
104 | Field f = clazz.getDeclaredField(name);
105 | f.setAccessible(true);
106 | // get
107 | return (T) f.get(null);
108 | }
109 |
110 | /**
111 | * Set instance field.
112 | *
113 | * @param instance
114 | * @param name
115 | * @param value
116 | * @throws Exception
117 | */
118 | public static void setFieldO(Object instance, String name, Object value) throws Exception
119 | {
120 | Field f = instance.getClass().getDeclaredField(name);
121 | f.setAccessible(true);
122 | // set
123 | f.set(instance, value);
124 | }
125 |
126 | /**
127 | * Set static field.
128 | *
129 | * @param clazz
130 | * @param name
131 | * @param value
132 | * @throws Exception
133 | */
134 | public static void setFieldS(Class> clazz, String name, Object value) throws Exception
135 | {
136 | Field f = clazz.getDeclaredField(name);
137 | f.setAccessible(true);
138 | // set
139 | f.set(null, value);
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/src/java/com/javadeobfuscator/deobfuscator/ui/util/SwingUtil.java:
--------------------------------------------------------------------------------
1 | package com.javadeobfuscator.deobfuscator.ui.util;
2 |
3 | import java.awt.Component;
4 | import java.awt.Container;
5 | import java.awt.GridBagConstraints;
6 | import java.awt.Insets;
7 | import java.util.function.Consumer;
8 |
9 | public class SwingUtil
10 | {
11 | private SwingUtil()
12 | {
13 | throw new UnsupportedOperationException();
14 | }
15 |
16 | public static void registerGBC(Container parent, Component component, int x, int y)
17 | {
18 | registerGBC(parent, component, x, y, null);
19 | }
20 |
21 | public static void registerGBC(Container parent, Component component, int x, int y, Consumer consumer)
22 | {
23 | registerGBC(parent, component, x, y, 1, 1, consumer);
24 | }
25 |
26 | public static void registerGBC(Container parent, Component component, int x, int y, int w, int h)
27 | {
28 | registerGBC(parent, component, x, y, w, h, null);
29 | }
30 |
31 | public static void registerGBC(Container parent, Component component, int x, int y, int w, int h, Consumer consumer)
32 | {
33 | GridBagConstraints gbc = new GridBagConstraints();
34 | gbc.anchor = GridBagConstraints.WEST;
35 | gbc.insets = new Insets(10, 10, 10, 10);
36 | gbc.gridx = x;
37 | gbc.gridy = y;
38 | gbc.gridwidth = w;
39 | gbc.gridheight = h;
40 | if (consumer != null)
41 | {
42 | consumer.accept(gbc);
43 | }
44 | parent.add(component, gbc);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/java/com/javadeobfuscator/deobfuscator/ui/util/TransformerConfigUtil.java:
--------------------------------------------------------------------------------
1 | package com.javadeobfuscator.deobfuscator.ui.util;
2 |
3 | import java.io.File;
4 | import java.lang.reflect.Field;
5 | import java.util.Collections;
6 | import java.util.LinkedHashSet;
7 | import java.util.Locale;
8 | import java.util.Set;
9 |
10 | import com.javadeobfuscator.deobfuscator.ui.SwingWindow;
11 |
12 | public class TransformerConfigUtil
13 | {
14 | private TransformerConfigUtil()
15 | {
16 | throw new UnsupportedOperationException();
17 | }
18 |
19 | public static Field getTransformerConfigFieldWithSuperclass(Class> cfgClazz, String fieldName)
20 | {
21 | if (cfgClazz == null || fieldName == null || cfgClazz.getName().equals("com.javadeobfuscator.deobfuscator.config.TransformerConfig"))
22 | {
23 | return null;
24 | }
25 | Field field = null;
26 | try
27 | {
28 | field = cfgClazz.getDeclaredField(fieldName);
29 | } catch (NoSuchFieldException ex)
30 | {
31 | Class> superclass = cfgClazz.getSuperclass();
32 | return getTransformerConfigFieldWithSuperclass(superclass, fieldName);
33 | }
34 | return field;
35 | }
36 |
37 | public static Set getTransformerConfigFieldsWithSuperclass(Class> cfgClazz)
38 | {
39 | return getTransformerConfigFielddWithSuperclass0(cfgClazz, new LinkedHashSet<>());
40 | }
41 |
42 | private static Set getTransformerConfigFielddWithSuperclass0(Class> cfgClazz, Set result)
43 | {
44 | if (cfgClazz == null || cfgClazz.getName().equals("com.javadeobfuscator.deobfuscator.config.TransformerConfig"))
45 | {
46 | return result;
47 | }
48 | Collections.addAll(result, cfgClazz.getDeclaredFields());
49 | return getTransformerConfigFielddWithSuperclass0(cfgClazz.getSuperclass(), result);
50 | }
51 |
52 | public static Object convertToObj(Class> fType, String strVal)
53 | {
54 | Object oval = null;
55 | if (fType == String.class || fType == CharSequence.class)
56 | {
57 | oval = strVal;
58 | } else if (fType == File.class)
59 | {
60 | oval = new File(strVal);
61 | } else if (fType == boolean.class || fType == Boolean.class)
62 | {
63 | oval = Boolean.parseBoolean(strVal);
64 | } else if (fType == byte.class || fType == Byte.class)
65 | {
66 | oval = Byte.parseByte(strVal);
67 | } else if (fType == short.class || fType == Short.class)
68 | {
69 | oval = Short.parseShort(strVal);
70 | } else if (fType == int.class || fType == Integer.class)
71 | {
72 | oval = Integer.parseInt(strVal);
73 | } else if (fType == long.class || fType == Long.class)
74 | {
75 | oval = Long.parseLong(strVal);
76 | } else if (fType == float.class || fType == Float.class)
77 | {
78 | oval = Float.parseFloat(strVal);
79 | } else if (fType == double.class || fType == Double.class)
80 | {
81 | oval = Double.parseDouble(strVal);
82 | } else if (fType.isEnum())
83 | {
84 | for (Object eObj : fType.getEnumConstants())
85 | {
86 | Enum> e = (Enum>) eObj;
87 | if (e.name().toLowerCase(Locale.ROOT).equals(strVal.toLowerCase(Locale.ROOT)))
88 | {
89 | return e;
90 | }
91 | }
92 | }
93 | return oval;
94 | }
95 |
96 | public static Object getConfig(Class> transformerClass)
97 | {
98 | try
99 | {
100 | Object cfg = SwingWindow.trans.getConfigFor(transformerClass);
101 | if (cfg != null && cfg.getClass().getName().equals("com.javadeobfuscator.deobfuscator.config.TransformerConfig"))
102 | {
103 | return null;
104 | }
105 | return cfg;
106 | } catch (Exception ex)
107 | {
108 | ex.printStackTrace();
109 | }
110 | return null;
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/src/java/com/javadeobfuscator/deobfuscator/ui/wrap/Config.java:
--------------------------------------------------------------------------------
1 | package com.javadeobfuscator.deobfuscator.ui.wrap;
2 |
3 | import java.util.List;
4 |
5 | import com.javadeobfuscator.deobfuscator.ui.util.Reflect;
6 |
7 | /**
8 | * Config wrapper that allows for easy reflection manipulation of fields.
9 | */
10 | public class Config
11 | {
12 |
13 | private final Object instance;
14 |
15 | public Config(Object instance)
16 | {
17 | this.instance = instance;
18 | }
19 |
20 | public Object get()
21 | {
22 | return instance;
23 | }
24 |
25 | /**
26 | * Set transformers list.
27 | *
28 | * @param trans
29 | * @param transformerConfigs
30 | */
31 | public void setTransformers(Transformers trans, List