Skip to content

Commit e4f0598

Browse files
committed
Fix typo in ObjectValueBoxImpl preventing proper value merging
1 parent 8b4de77 commit e4f0598

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

recaf-core/src/main/java/software/coley/recaf/util/analysis/value/impl/ObjectValueBoxImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ else if (other instanceof ObjectValueBoxImpl<?> otherBoxed) {
8383
if (type().equals(otherBoxed.type()) && value().isPresent() && otherBoxed.value().isPresent()) {
8484
T v = value().get();
8585
T otherV = (T) otherBoxed.value().get();
86-
if (Objects.equals(v, otherBoxed))
86+
if (Objects.equals(v, otherV))
8787
return wrap(v);
8888
}
8989
return wrapUnknown(nullness().mergeWith(otherBoxed.nullness()));

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
@@ -1397,6 +1397,38 @@ void foldStringInstanceMethodCalls() {
13971397
assertEquals(0, StringUtil.count("ldc", dis), "Expected to fold original string");
13981398
assertEquals(0, StringUtil.count("invoke", dis), "Expected to fold method call");
13991399
});
1400+
1401+
// Found in a random sample, the control flow was resulting in the code under label 'C' being revisited.
1402+
// The merge code in our analysis for strings was wrong, which prevented this from being combined.
1403+
// This test ensures that bad frame merge is no longer an issue.
1404+
asm = """
1405+
.method public static example ([B)Ljava/lang/String; {
1406+
parameters: { data },
1407+
code: {
1408+
A:
1409+
iconst_0
1410+
istore counter
1411+
B:
1412+
iload counter
1413+
aload data
1414+
arraylength
1415+
if_icmpge C
1416+
iinc counter 1
1417+
goto B
1418+
C:
1419+
ldc "UTF-"
1420+
ldc "8"
1421+
invokevirtual java/lang/String.concat (Ljava/lang/String;)Ljava/lang/String;
1422+
D:
1423+
areturn
1424+
E:
1425+
}
1426+
}
1427+
""";
1428+
validateAfterAssembly(asm, List.of(OpaqueConstantFoldingTransformer.class), dis -> {
1429+
assertEquals(1, StringUtil.count("ldc \"UTF-8\"", dis), "Expected to fold to single string");
1430+
assertEquals(0, StringUtil.count("invoke", dis), "Expected to remove method calls");
1431+
});
14001432
}
14011433

14021434
@Test

0 commit comments

Comments
 (0)