Skip to content

Commit

Permalink
fix static field inliner
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicPlayerA10 committed Oct 18, 2024
1 parent 07ada75 commit ff2d17a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import org.jetbrains.annotations.Nullable;
import uwu.narumi.deobfuscator.api.transformer.ComposedTransformer;
import uwu.narumi.deobfuscator.core.other.composed.general.ComposedGeneralRepairTransformer;
import uwu.narumi.deobfuscator.core.other.impl.clean.LocalVariableNamesCleanTransformer;
import uwu.narumi.deobfuscator.core.other.impl.hp888.HP888PackerTransformer;
import uwu.narumi.deobfuscator.core.other.impl.hp888.HP888StringTransformer;
import uwu.narumi.deobfuscator.core.other.impl.universal.AccessRepairTransformer;
import uwu.narumi.deobfuscator.core.other.impl.universal.RecoverSyntheticsTransformer;
import uwu.narumi.deobfuscator.core.other.impl.universal.UniversalNumberTransformer;

Expand All @@ -31,7 +32,8 @@ public ComposedHP888Transformer(@Nullable String encryptedClassFilesSuffix) {

// Cleanup
UniversalNumberTransformer::new,
ComposedGeneralRepairTransformer::new,
AccessRepairTransformer::new,
LocalVariableNamesCleanTransformer::new,
RecoverSyntheticsTransformer::new
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Inlines constant static fields
Expand All @@ -23,7 +25,7 @@ public class InlineStaticFieldTransformer extends Transformer {

@Override
protected void transform() throws Exception {
List<FieldRef> notConstantFields = new ArrayList<>();
Set<FieldRef> notConstantFields = new HashSet<>();
Map<FieldRef, AbstractInsnNode> staticConstantFields = new HashMap<>();

// Find all static constant fields
Expand Down Expand Up @@ -55,6 +57,8 @@ protected void transform() throws Exception {
if (valueInsn.isConstant()) {
// We have constant static field
staticConstantFields.put(FieldRef.of(insn), valueInsn);
} else {
notConstantFields.add(fieldRef);
}
});
}));
Expand Down
Binary file modified testData/results/custom-classes/hp888/pack/MyFunction2.dec
Binary file not shown.
10 changes: 10 additions & 0 deletions testData/results/java/TestInlineStaticFields.dec
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
public class TestInlineStaticFields {
public static int TEST1 = 123;
public static int TEST4;
public static String TEST5;

public static void test() {
System.out.println(TEST1);
System.out.println("placki");
System.out.println(true);
System.out.println(TEST4);
System.out.println(TEST5.toUpperCase());
}

public static void modifyStatic() {
TEST1 = 321;
}

static {
try {
TEST5 = Number.class.getSimpleName();
} catch (Exception var1) {
TEST5 = null;
}
}
}
11 changes: 11 additions & 0 deletions testData/src/java/src/main/java/TestInlineStaticFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@ public class TestInlineStaticFields {
public static String TEST2 = "placki";
public static boolean TEST3 = true;
public static int TEST4;
public static String TEST5;

static {
try {
TEST5 = Number.class.getSimpleName();
} catch (Exception e) {
TEST5 = null;
}
}

public static void test() {
System.out.println(TEST1);
System.out.println(TEST2);
System.out.println(TEST3);
System.out.println(TEST4);

System.out.println(TEST5.toUpperCase());
}

public static void modifyStatic() {
Expand Down

0 comments on commit ff2d17a

Please sign in to comment.