Skip to content

Commit ceb9936

Browse files
committed
Allow setting value
1 parent 13baea4 commit ceb9936

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

src/java/com/javadeobfuscator/deobfuscator/ui/SwingWindow.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public static void main(String[] args)
7676
gbc_Text.fill = GridBagConstraints.HORIZONTAL;
7777
JTextField textField = new JTextField();
7878
i.component = textField;
79+
i.setValue();
7980
inputPnl.add(textField, gbc_Text);
8081
GridBagConstraints gbc_Select = new GridBagConstraints();
8182
gbc_Select.insets = new Insets(5, 7, 2, 2);
@@ -97,6 +98,7 @@ public static void main(String[] args)
9798
gbc_box.gridy = gridy;
9899
JCheckBox checkBox = new JCheckBox(i.getDisplayName());
99100
i.component = checkBox;
101+
i.setValue();
100102
inputPnl.add(checkBox, gbc_box);
101103
gridy++;
102104
}
@@ -209,6 +211,7 @@ public static void main(String[] args)
209211
JScrollPane libListScroll = new JScrollPane();
210212
DefaultListModel<String> librariesList = new DefaultListModel<>();
211213
i.component = librariesList;
214+
i.setValue();
212215
JList<String> libJList = new JList<>(librariesList);
213216
libJList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
214217
libJList.setModel(librariesList);
@@ -269,6 +272,7 @@ public static void main(String[] args)
269272
JScrollPane stringListScroll = new JScrollPane();
270273
DefaultListModel<String> stringList = new DefaultListModel<>();
271274
i.component = stringList;
275+
i.setValue();
272276
JList<String> stringJList = new JList<>(stringList);
273277
stringJList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
274278
stringJList.setModel(stringList);

src/java/com/javadeobfuscator/deobfuscator/ui/component/SwingConfiguration.java

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.lang.reflect.ParameterizedType;
66
import java.lang.reflect.Type;
77
import java.util.ArrayList;
8+
import java.util.Arrays;
89
import java.util.HashSet;
910
import java.util.List;
1011
import java.util.Set;
@@ -36,20 +37,22 @@ public SwingConfiguration(Object config)
3637
{
3738
if(IGNORED_VALUES.contains(field.getName()))
3839
continue;
39-
fieldsList.add(new ConfigItem(field));
40+
fieldsList.add(new ConfigItem(config, field));
4041
}
4142
}
4243

4344
public static class ConfigItem
4445
{
4546
private final Field field;
4647
public final ItemType type;
48+
private Object instance;
4749

4850
/** The swing component that we'll use to call the set value */
4951
public Object component;
5052

51-
public ConfigItem(Field field)
53+
public ConfigItem(Object instance, Field field)
5254
{
55+
this.instance = instance;
5356
this.field = field;
5457
if(field.getType().equals(File.class))
5558
type = ItemType.FILE;
@@ -81,16 +84,54 @@ public Object getValue()
8184
return ((JTextField)component).getText();
8285
if(type == ItemType.BOOLEAN)
8386
return ((JCheckBox)component).isSelected();
84-
//For LIST types, we return DefaultListModel
85-
return component;
87+
return Arrays.asList(((DefaultListModel<?>)component).toArray());
8688
}
8789

8890
/**
89-
* Sets the value. Used when run deobfuscator is clicked.
91+
* Sets the component value with the field value. Used on first load and load config.
92+
*/
93+
public void setValue()
94+
{
95+
if(getFieldValue() == null)
96+
return;
97+
if(type == ItemType.FILE)
98+
((JTextField)component).setText((String)getFieldValue());
99+
else if(type == ItemType.BOOLEAN)
100+
((JCheckBox)component).setSelected((Boolean)getFieldValue());
101+
else
102+
{
103+
DefaultListModel<Object> listModel = (DefaultListModel<Object>)component;
104+
listModel.clear();
105+
List<?> fieldValue = (List<?>)getFieldValue();
106+
for(Object o : fieldValue)
107+
listModel.addElement(o);
108+
}
109+
}
110+
111+
/**
112+
* Gets the field value (used on first load)
113+
*/
114+
public Object getFieldValue()
115+
{
116+
try
117+
{
118+
return Reflect.getFieldO(instance, field.getName());
119+
}catch(Exception e)
120+
{
121+
return null;
122+
}
123+
}
124+
125+
/**
126+
* Sets the field value with the component value. Used when run deobfuscator is clicked.
90127
*/
91128
public void setFieldValue()
92129
{
93-
//TODO
130+
try
131+
{
132+
Reflect.setFieldO(instance, field.getName(), getValue());
133+
}catch(Exception e)
134+
{}
94135
}
95136

96137
}

0 commit comments

Comments
 (0)