Skip to content

Instantly share code, notes, and snippets.

@trask
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trask/d47133aef3b662b6548b to your computer and use it in GitHub Desktop.
Save trask/d47133aef3b662b6548b to your computer and use it in GitHub Desktop.
ClassFileTransformer.transform() can be passed null protectionDomain
import java.lang.instrument.Instrumentation;
public class Agent {
public static void premain(String agentArgs, Instrumentation instrumentation) {
instrumentation.addTransformer(new Transformer());
}
}
Premain-Class: Agent
java/lang/invoke/MethodHandleImpl passed in with null protection domain
java/lang/invoke/MemberName$Factory passed in with null protection domain
java/lang/invoke/LambdaForm$NamedFunction passed in with null protection domain
java/lang/invoke/MethodType$ConcurrentWeakInternSet passed in with null protection domain
java/lang/invoke/MethodHandleStatics passed in with null protection domain
java/lang/invoke/MethodHandleStatics$1 passed in with null protection domain
java/lang/invoke/MethodTypeForm passed in with null protection domain
java/lang/invoke/Invokers passed in with null protection domain
java/lang/invoke/MethodType$ConcurrentWeakInternSet$WeakEntry passed in with null protection domain
java/lang/Void passed in with null protection domain
java/lang/IllegalAccessException passed in with null protection domain
sun/misc/PostVMInitHook passed in with null protection domain
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
java/lang/Shutdown passed in with null protection domain
java/lang/Shutdown$Lock passed in with null protection domain
#!/bin/sh
javac Agent.java Transformer.java
jar cmf MANIFEST.MF agent.jar Agent.class Transformer.class
java -javaagent:agent.jar -version
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.security.ProtectionDomain;
public class Transformer implements ClassFileTransformer {
@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
ProtectionDomain protectionDomain, byte[] classfileBuffer)
throws IllegalClassFormatException {
if (protectionDomain == null) {
System.out.println(className + " passed in with null protection domain");
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment