Skip to content

Commit 547d00b

Browse files
committed
Temporarily disable new var-folding behavior until regression is case "doNotFoldVarUsedInComparisonIfOriginalPossiblyUpdates" is fixed
1 parent 04ef84f commit 547d00b

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

recaf-core/src/main/java/software/coley/recaf/services/deobfuscation/transform/generic/VariableFoldingTransformer.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.objectweb.asm.Type;
1111
import org.objectweb.asm.tree.AbstractInsnNode;
1212
import org.objectweb.asm.tree.ClassNode;
13-
import org.objectweb.asm.tree.FieldInsnNode;
1413
import org.objectweb.asm.tree.IincInsnNode;
1514
import org.objectweb.asm.tree.InsnList;
1615
import org.objectweb.asm.tree.InsnNode;
@@ -46,7 +45,6 @@
4645
import software.coley.recaf.workspace.model.resource.WorkspaceResource;
4746

4847
import java.util.Collections;
49-
import java.util.Iterator;
5048
import java.util.NavigableSet;
5149
import java.util.Set;
5250
import java.util.TreeSet;
@@ -260,7 +258,8 @@ else if (!throwingObserved) {
260258

261259
// Remove variable writes + usages if:
262260
// - The variable is a redundant copy of an existing other variable
263-
for (int keyX : states.keySet()) {
261+
// TODO: Enable this after fixing the 'doNotFoldVarUsedInComparisonIfOriginalPossiblyUpdates' test
262+
if (false) for (int keyX : states.keySet()) {
264263
// Check if the current store is redundant with another variable.
265264
int slotX = slotFromKey(keyX);
266265
if (slotX != vin.var && isRedundantStore(states, instructions, i, slotX, vin.var, varSort)) {
@@ -339,13 +338,8 @@ private static boolean isRedundantStore(@Nonnull Int2ObjectMap<LocalAccessState>
339338
if (!isMatchingStore(typeSort, writeVin.getOpcode()))
340339
return false;
341340

342-
// Check if the prior instruction is a cast.
343-
// We want to keep patterns like 'Collection -> List' being stored into new variables.
341+
// Check if the prior instruction is the copy source of 'load x'.
344342
AbstractInsnNode previousInsn = writeInsnY.getPrevious();
345-
if (previousInsn == null || previousInsn.getOpcode() == CHECKCAST)
346-
return false;
347-
348-
// Contents of both locals must be equal.
349343
if (!(previousInsn instanceof VarInsnNode prevVin
350344
&& isVarLoad(prevVin.getOpcode())
351345
&& prevVin.var == slotX))
@@ -363,6 +357,10 @@ && isVarLoad(prevVin.getOpcode())
363357
int opcode = vin.getOpcode();
364358
if ((var == slotX || var == slotY) && isVarStore(opcode))
365359
return false;
360+
} else if (insn instanceof IincInsnNode iinc) {
361+
int var = iinc.var;
362+
if ((var == slotX || var == slotY))
363+
return false;
366364
}
367365
}
368366

recaf-core/src/test/java/software/coley/recaf/services/deobfuscation/BaseDeobfuscationTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ protected void validateNoTransformation(@Nonnull String assembly, @Nonnull List<
7373
// Transforming should not actually result in any changes
7474
JvmTransformResult result = assertDoesNotThrow(() -> newApplier().transformJvm(transformers));
7575
assertTrue(result.getTransformerFailures().isEmpty(), "There were transformation failures");
76-
assertTrue(result.getTransformedClasses().isEmpty(), "There were unexpected transformations applied");
77-
assertTrue(result.getModifiedClassesPerTransformer().isEmpty(), "There were unexpected transformations applied");
76+
if (!result.getTransformedClasses().isEmpty()) {
77+
String transformedDisassembly = disassembleTransformed(result, isFullBody);
78+
fail("There were unexpected transformations applied:\n\n" + transformedDisassembly);
79+
}
7880
}
7981

8082
protected void validateBeforeAfterDecompile(@Nonnull String assembly, @Nonnull List<Class<? extends JvmClassTransformer>> transformers,

recaf-core/src/test/java/software/coley/recaf/services/deobfuscation/FoldingDeobfuscationTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,6 +2263,8 @@ void foldVar() {
22632263
}
22642264

22652265
@Test
2266+
@Disabled
2267+
/** TODO: Enable after fixing {@link #doNotFoldVarUsedInComparisonIfOriginalPossiblyUpdates()} */
22662268
void foldVarWithRedundantCopyVariable() {
22672269
String asm = """
22682270
.method public example ()I {
@@ -2351,6 +2353,8 @@ void foldVarWithRedundantCopyVariable() {
23512353
}
23522354

23532355
@Test
2356+
@Disabled
2357+
/** TODO: Enable after fixing {@link #doNotFoldVarUsedInComparisonIfOriginalPossiblyUpdates()} */
23542358
void foldVarWithWideRedundantCopyVariable() {
23552359
String asm = """
23562360
.method public static example (J)I {
@@ -2375,6 +2379,34 @@ void foldVarWithWideRedundantCopyVariable() {
23752379
});
23762380
}
23772381

2382+
@Test
2383+
@Disabled
2384+
void doNotFoldVarUsedInComparisonIfOriginalPossiblyUpdates() {
2385+
String asm = """
2386+
.method public static example (I)I {
2387+
parameters: { a },
2388+
code: {
2389+
A:
2390+
iload a
2391+
istore b
2392+
iload a
2393+
invokestatic Example.lookup (I)I
2394+
istore a
2395+
iload a
2396+
iload b
2397+
if_icmpne B
2398+
iload a
2399+
ireturn
2400+
B:
2401+
iload b
2402+
ireturn
2403+
C:
2404+
}
2405+
}
2406+
""";
2407+
validateNoTransformation(asm, List.of(VariableFoldingTransformer.class, OpaqueConstantFoldingTransformer.class));
2408+
}
2409+
23782410
@Test
23792411
@Disabled
23802412
void foldVarWithSeriesOfRedundantBackToBackCycledWrites() {

0 commit comments

Comments
 (0)