Skip to content

Commit 95750ff

Browse files
committed
update fernFlower config
1 parent caebf84 commit 95750ff

File tree

3 files changed

+40
-19
lines changed

3 files changed

+40
-19
lines changed

src/main/java/cn/enaium/joe/service/decompiler/VineFlowerDecompiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class VineFlowerDecompiler implements IDecompiler{
4949
} else if (v.equals("false")) {
5050
v = "0";
5151
}
52-
hashMap.put(entry.getKey(), v);
52+
hashMap.put(entry.getKey().replace('_', '-'), v);
5353
}
5454
return Collections.unmodifiableMap(hashMap);});
5555

src/main/java/cn/enaium/joe/util/config/extend/VineFlowerConfig.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
*/
3434
@SuppressWarnings("unused")
3535
public class VineFlowerConfig extends Config {
36+
3637
public EnableValue rbr = new EnableValue("Remove Bridge Methods", true, "Removes any methods that are marked as bridge from the decompiled output.");
3738
public EnableValue rsy = new EnableValue("Remove Synthetic Methods And Fields", true, "Removes any methods and fields that are marked as synthetic from the decompiled output.");
3839
public EnableValue din = new EnableValue("Decompile Inner Classes", true, "Process inner classes and add them to the decompiled output.");
@@ -69,6 +70,7 @@ public class VineFlowerConfig extends Config {
6970
public EnableValue ovr = new EnableValue("Override Annotation", true, "Display override annotations for methods known to the decompiler.");
7071
public EnableValue ssp = new EnableValue("Second-Pass Stack Simplification", true, "Simplify variables across stack bounds to resugar complex statements.");
7172
public EnableValue vvm = new EnableValue("[Experimental] Verify Variable Merges", false, "Tries harder to verify the validity of variable merges. If there are strange variable recompilation issues, this is a good place to start.");
73+
public EnableValue old_try_dedup = new EnableValue("[Experimental] Use old try deduplication", false, "Use the old try deduplication algorithm for methods with obfuscated exceptions, which inserts dummy exception handlers instead of duplicating blocks");
7274
public EnableValue iec = new EnableValue("Include Entire Classpath", false, "Give the decompiler information about every jar on the classpath.");
7375
public StringValue jrt = new StringValue("Include Java Runtime", "", "Give the decompiler information about the Java runtime, either 1 or current for the current runtime, or a path to another runtime");
7476
public EnableValue ega = new EnableValue("Explicit Generic Arguments", false, "Put explicit diamond generic arguments on method calls.");
@@ -92,7 +94,9 @@ public class VineFlowerConfig extends Config {
9294
public EnableValue fji = new EnableValue("Force JSR inline", false, "Forces the processing of JSR instructions even if the class files shouldn't contain it (Java 7+)");
9395
public EnableValue dtt = new EnableValue("Dump Text Tokens", false, "Dump Text Tokens on each class file");
9496
public EnableValue rim = new EnableValue("Remove Imports", false, "Remove import statements from the decompiled code");
95-
public EnableValue mcs = new EnableValue("Mark Corresponding Synthetics", false, "Mark lambdas and anonymous and local classes with their respective synthetic constructs"); // not auto, might be fixed at https://github.com/Vineflower/vineflower/pull/443 or other operate, now we just human-bot
97+
public EnableValue mcs = new EnableValue("Mark Corresponding Synthetics", false, "Mark lambdas and anonymous and local classes with their respective synthetic constructs");
98+
public StringValue excluded_classes = new StringValue("Excluded Classes", "", "Exclude classes from decompilation if their fully qualified names match the specified regular expression.");
99+
public StringValue validate_inner_classes_names = new StringValue("Validate inner classes names", "1", "Validates that the inner class name is correct (if it is separated using '$' for example BaseClass$InnerClass). If not then inner class won't be processed.");
96100

97101
public VineFlowerConfig() {
98102
super("VineFlower", Set.of(VineFlowerDecompiler.customProperties));

src/test/java/cn/enaium/joe/asm/GenerateDecompilerConfigTest.java

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818

1919
import cn.enaium.joe.util.ImagineBreakerHelper;
2020
import com.strobel.decompiler.languages.java.JavaFormattingOptions;
21+
import org.jetbrains.java.decompiler.api.DecompilerOption;
2122
import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger;
2223
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences;
2324
import org.junit.jupiter.api.Test;
25+
import org.tinylog.Logger;
2426

2527
import java.lang.reflect.Field;
2628
import java.util.Map;
@@ -43,35 +45,46 @@ public void fernFlower() throws IllegalAccessException {
4345
if (field.isAnnotationPresent(IFernflowerPreferences.Name.class) && field.isAnnotationPresent(IFernflowerPreferences.Description.class)) {
4446
try{
4547
String name = field.getAnnotation(IFernflowerPreferences.Name.class).value();
46-
String fieldName = field.getAnnotation(IFernflowerPreferences.ShortName.class).value();
48+
String fieldName = field.isAnnotationPresent(IFernflowerPreferences.ShortName.class) ? field.getAnnotation(IFernflowerPreferences.ShortName.class).value() : ((String)field.get(null)).replace('-', '_');
4749
String description = field.getAnnotation(IFernflowerPreferences.Description.class).value();
48-
String type = field.getAnnotation(IFernflowerPreferences.Type.class).value();
49-
Object o = defaults.get((String)field.get(null));
50+
DecompilerOption.Type type = field.isAnnotationPresent(IFernflowerPreferences.Type.class) ? field.getAnnotation(IFernflowerPreferences.Type.class).value() : null;
51+
Object defaultValue = defaults.get((String)field.get(null));
52+
String extra = null;
5053

51-
if (o != null) {
52-
if ("bool".equals(type)){
53-
if ("1".equals(o)) {
54-
o = Boolean.TRUE;
55-
} else if ("0".equals(o)) {
56-
o = Boolean.FALSE;
54+
if (defaultValue != null) {
55+
if ("mcs".equals(fieldName)) {
56+
type = DecompilerOption.Type.BOOLEAN;
57+
extra = " not auto, might be fixed at https://github.com/Vineflower/vineflower/pull/443 or other operate, now we just human-bot";
58+
}
59+
if (type == DecompilerOption.Type.BOOLEAN) {
60+
if ("1".equals(defaultValue)) {
61+
defaultValue = Boolean.TRUE;
62+
} else if ("0".equals(defaultValue)) {
63+
defaultValue = Boolean.FALSE;
5764
}
58-
} else if ("string".equals(type)){
65+
}
66+
else if (DecompilerOption.Type.STRING == type){
5967
if ("log".equals(fieldName))
60-
o = IFernflowerLogger.Severity.INFO;
61-
else o = String.valueOf(o);
62-
} else if ("int".equals(type)){
63-
o = Integer.parseInt(String.valueOf(o));
68+
defaultValue = IFernflowerLogger.Severity.INFO;
69+
else defaultValue = String.valueOf(defaultValue);
70+
} else if (DecompilerOption.Type.INTEGER == type){
71+
defaultValue = Integer.parseInt(String.valueOf(defaultValue));
6472
}
65-
System.out.println(buildConfig(fieldName, name, description, o));
73+
System.out.println(buildConfig(fieldName, name, description, defaultValue));
6674
}
6775
}catch (Throwable e){
68-
e.printStackTrace();
76+
Logger.error(e);
6977
}
7078
}
7179
}
7280
}
73-
7481
public static String buildConfig(String fieldName, String name, String desc, Object defaultValue){
82+
return buildConfig(fieldName, name, desc, defaultValue, null);
83+
}
84+
85+
public static String buildConfig(String fieldName, String name, String desc, Object defaultValue, String extra){
86+
desc = desc.replace('\"', '\'');
87+
7588
String type = null;
7689
if (defaultValue instanceof Boolean) {
7790
type = "EnableValue";
@@ -107,6 +120,10 @@ public static String buildConfig(String fieldName, String name, String desc, Obj
107120
}
108121
stringBuilder.append(");");
109122

123+
if (extra != null) {
124+
stringBuilder.append(" //").append(extra);
125+
}
126+
110127
return stringBuilder.toString();
111128
}
112129

0 commit comments

Comments
 (0)