This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am heipacker on github. | |
* I am heipacker (https://keybase.io/heipacker) on keybase. | |
* I have a public key ASBlfOIeXqcQ8Cmj0Q2yCH3j6JW2JGL4rZmrEfWRUFngfQo | |
To claim this, I am signing this object: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public Map<TypeDescription, Class<?>> inject(Map<? extends TypeDescription, byte[]> types) { | |
File jarFile = new File(folder, String.format("%s%s.jar", PREFIX, randomString.nextString())); | |
try { | |
if (!jarFile.createNewFile()) { | |
throw new IllegalStateException("Cannot create file " + jarFile); | |
} | |
JarOutputStream jarOutputStream = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(jarFile))); | |
try { | |
for (Map.Entry<? extends TypeDescription, byte[]> entry : types.entrySet()) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/home/fupan/q/java/jdk1.8.0_40/bin/java -javaagent:/home/fupan/IdeaProjects/agentTest/agent-tools/target/agent-tools-1.0-SNAPSHOT.jar -Didea.launcher.port=7541 -Didea.launcher.bin.path=/home/fupan/software/idea-IU-139.1117.1/bin -Dfile.encoding=UTF-8 -classpath /home/fupan/q/java/jdk1.8.0_40/jre/lib/resources.jar:/home/fupan/q/java/jdk1.8.0_40/jre/lib/javaws.jar:/home/fupan/q/java/jdk1.8.0_40/jre/lib/jfxswt.jar:/home/fupan/q/java/jdk1.8.0_40/jre/lib/deploy.jar:/home/fupan/q/java/jdk1.8.0_40/jre/lib/rt.jar:/home/fupan/q/java/jdk1.8.0_40/jre/lib/charsets.jar:/home/fupan/q/java/jdk1.8.0_40/jre/lib/jsse.jar:/home/fupan/q/java/jdk1.8.0_40/jre/lib/plugin.jar:/home/fupan/q/java/jdk1.8.0_40/jre/lib/management-agent.jar:/home/fupan/q/java/jdk1.8.0_40/jre/lib/jce.jar:/home/fupan/q/java/jdk1.8.0_40/jre/lib/jfr.jar:/home/fupan/q/java/jdk1.8.0_40/jre/lib/ext/localedata.jar:/home/fupan/q/java/jdk1.8.0_40/jre/lib/ext/nashorn.jar:/home/fupan/q/java/jdk1.8.0_40/jre/lib/ext/sunjce_provider.jar:/home/fupan/q/java/jdk1.8.0_40/jr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dlmu.agent.server; | |
import com.dlmu.agent.CosmosAgent; | |
import java.lang.instrument.Instrumentation; | |
/** | |
* Created by fupan on 16-4-2. | |
*/ | |
public class TestAgent { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dlmu.agent.server; | |
import net.bytebuddy.implementation.bind.annotation.Origin; | |
import java.lang.reflect.Method; | |
/** | |
* Created by fupan on 16-4-9. | |
*/ | |
public class DelagateLogging { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dlmu.agent.server; | |
import net.bytebuddy.agent.builder.AgentBuilder; | |
import net.bytebuddy.description.type.TypeDescription; | |
import net.bytebuddy.dynamic.DynamicType; | |
import net.bytebuddy.implementation.MethodDelegation; | |
import net.bytebuddy.implementation.SuperMethodCall; | |
import net.bytebuddy.matcher.ElementMatchers; | |
import java.lang.instrument.ClassFileTransformer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dlmu.agent.server; | |
import java.lang.instrument.ClassFileTransformer; | |
import java.lang.instrument.IllegalClassFormatException; | |
import java.security.ProtectionDomain; | |
/** | |
* Created by fupan on 16-4-9. | |
*/ | |
public class SimpleClassFileTransformer implements ClassFileTransformer { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Registers the supplied transformer. | |
* <P> | |
* Same as <code>addTransformer(transformer, false)</code>. | |
* | |
* @param transformer the transformer to register | |
* @throws java.lang.NullPointerException if passed a <code>null</code> transformer | |
* @see #addTransformer(ClassFileTransformer,boolean) | |
*/ | |
void |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String jarFilePath = "/home/fupan/IdeaProjects/agentTest/agent-jar/target/agent-jar-1.0-SNAPSHOT.jar"; | |
private static void attachAgent() { | |
TestAgent testAgent = new TestAgent(); | |
testAgent.loadAgent(); | |
} | |
void loadAgent() { | |
VirtualMachine vm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void addCode(Instrumentation instrumentation) { | |
Class[] allLoadedClasses = instrumentation.getAllLoadedClasses(); | |
System.out.println("all load classes length:" + allLoadedClasses.length); | |
System.out.println("object size:" + instrumentation.getObjectSize(new Object())); | |
instrumentation.addTransformer(new ClassFileTransformer() { | |
@Override | |
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { | |
if (classBeingRedefined != null) return null; | |
System.out.println("class transform " + className); | |
return classfileBuffer; |
NewerOlder