-
-
Notifications
You must be signed in to change notification settings - Fork 835
Open
Labels
Description
Hello,
I'm trying to intercept an external library load in java. There is a public API in java: System.loadLibrary() and Runtime.loadLibrary(). However the next code works for java 8 and 11. But doesn't work for java 17, 21, 25:
new AgentBuilder.Default()
.disableClassFormatChanges()
.with(RETRANSFORMATION)
.ignore(none())
.type(any())
.transform((builder, type, classLoader, module, pd) -> builder.visit(
Advice.to(LoadLibraryAdvice.class)
.on(ElementMatchers.isMethod().and(named("loadLibrary")))))
LoadLibraryAdvice contains just debug output to confirm if it's working:
public class LoadLibraryAdvice {
@Advice.OnMethodEnter
static void onEnter(
@Advice.Origin Method method,
@Advice.AllArguments(typing = DYNAMIC) Object[] args) {
System.out.println("intercepted: " + method.getDeclaringClass().getName() + "@" + method.getName());
for (Object a : args)
System.out.println(" > " + a.toString());
}
}
On java versions 8 and 11 it works and I see debug output (including internal call to java.lang.ClassLoader.loadLibrary).
On java versions 17, 21, 25 I don't see any output and also I don't see transformation debug log for System/Runtime/ClassLoader classes.