Skip to content

Commit de804b5

Browse files
committed
fix(obf): fixed functional interfaces
1 parent 8571507 commit de804b5

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

dev.skidfuscator.obfuscator/src/main/java/dev/skidfuscator/obfuscator/hierarchy/SkidHierarchy.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,30 @@ private void setupInvoke() {
281281
assert (e.getBootstrapArgs().length == 3 && e.getBootstrapArgs()[1] instanceof Handle);
282282
final Handle boundFunc = (Handle) e.getBootstrapArgs()[1];
283283

284-
if (boundFunc.getName().equals("handle")) {
285-
/*System.out.println("Invoking dynamic " + invocation.getOwner() + "#"
286-
+ invocation.getName() + invocation.getDesc());*/
284+
if (boundFunc.getName().equals("apply") && false ) {
285+
System.out.println("Invoking dynamic " + invocation.getOwner() + "#"
286+
+ invocation.getName() + invocation.getDesc() + " bound to " + boundFunc.getOwner() + "#" + boundFunc.getName() + boundFunc.getDesc()
287+
);
287288
}
289+
290+
// Patch for implicit funtions
291+
// TODO: Fix this
292+
if (boundFunc.getName().startsWith("lambda$new$")) {
293+
final String returnType = e.getType().getClassName().replace(".", "/");
294+
//System.out.println("Attempting to locate " + returnType);
295+
final ClassNode targetClass = skidfuscator.getClassSource().findClassNode(returnType);
296+
297+
if (!(targetClass instanceof SkidClassNode))
298+
return;
299+
300+
assert targetClass.getMethods().size() == 1 : "Implicit Function must be single method!";
301+
final SkidMethodNode methodNode = (SkidMethodNode) targetClass.getMethods().get(0);
302+
303+
methodNode.getGroup().setImplicitFunction(true);
304+
//System.out.println("Found implicit function: " + methodNode.toString());
305+
return;
306+
}
307+
288308
target = new ClassMethodHash(boundFunc.getName(), boundFunc.getDesc(), boundFunc.getOwner());
289309

290310
} else if (invocation instanceof InvocationExpr) {
@@ -335,6 +355,18 @@ private void setupInvoke() {
335355
}
336356
});
337357
}
358+
359+
// Patch for functional interfaces
360+
if (c.node.visibleAnnotations != null) {
361+
final List<AnnotationNode> annotationNodes = c.node.visibleAnnotations;
362+
363+
if (annotationNodes.stream().anyMatch(e -> e.desc.equals("Ljava/lang/FunctionalInterface;"))) {
364+
for (MethodNode method : c.getMethods()) {
365+
((SkidMethodNode) method).getGroup().setImplicitFunction(true);
366+
}
367+
}
368+
}
369+
338370
invocationBar.tick();
339371
});
340372
}

dev.skidfuscator.obfuscator/src/main/java/dev/skidfuscator/obfuscator/skidasm/SkidGroup.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class SkidGroup {
3333

3434
private int stackHeight;
3535
private transient boolean application;
36+
private transient boolean implicitFunction;
3637

3738
// TODO: Add parameter and parameter compilation
3839

@@ -145,8 +146,13 @@ public MethodNode first() {
145146
return methodNodeList.iterator().next();
146147
}
147148

149+
public void setImplicitFunction(boolean implicitFunction) {
150+
this.implicitFunction = implicitFunction;
151+
}
152+
148153
public boolean isEntryPoint() {
149154
return !application
155+
|| this.isImplicitFunction()
150156
|| this.getInvokers().isEmpty()
151157
|| this.getInvokers().stream().anyMatch(SkidInvocation::isDynamic)
152158
|| this.isAnnotation()

0 commit comments

Comments
 (0)