package com.sk.service;
import javassist.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.instrument.ClassDefinition;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.lang.instrument.Instrumentation;
import java.security.ProtectionDomain;
public class FirstAgent02 {
public static void premain(String agentArgs, Instrumentation inst){
System.out.println("1-----FirstAgent is Start.");
inst.addTransformer(new FirstTransformer());
}
public static void agentmain(String args, Instrumentation ins) {
System.out.println("2-----FirstAgent is Start.");
ins.addTransformer(new ClassFileTransformer() {
/**
* @param loader
* @param className 动态加载的类名
* @param classBeingRedefined 这个类重新加载之前的类
* @param protectionDomain 类的基本信息
* @param classfileBuffer 这个类的字节码,如果返回null就按照原有的进行加载覆盖
* @return 返回指令码
* @throws IllegalClassFormatException
*/
@Override
public byte[] transform(ClassLoader loader, String className,
Class<?> classBeingRedefined,
ProtectionDomain protectionDomain,
byte[] classfileBuffer) throws IllegalClassFormatException {
System.out.println("-=======+++++++++++++++++++++++++++"+className);
/*if (!"javaagent/HelloWorld".equals(className)) {
return null;
}
// 配合javassist修改指令码
ClassPool pool = new ClassPool();
pool.appendSystemPath();
try {
CtClass ctClass = pool.get("javaagent.HelloWorld");
CtMethod method = ctClass.getDeclaredMethod("hello");
method.insertBefore("System.out.println(\"插入前置逻辑2\");");
return ctClass.toBytecode();
} catch (NotFoundException | CannotCompileException | IOException e) {
e.printStackTrace();
}*/
return null;
}
});
}
public static void agentmain(String args) {
System.out.println("-----attach-----00----"+args);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
javaAgent实现补丁不重出功能,通过attach实现程序运行时加载,同时通过shell脚本部署到容器内
共21个文件
java:9个
properties:4个
xml:3个
需积分: 6 0 下载量 73 浏览量
2022-11-13
22:23:21
上传
评论
收藏 16.9MB ZIP 举报
温馨提示
javaAgent字节码增强技术(也叫java探针技术)实现补丁不重出功能,通过attach实现程序运行时加载,同时通过shell脚本部署到容器内,涉及宿主机操作docker容器内的shell脚本
资源推荐
资源详情
资源评论
收起资源包目录
javaAgent.zip (21个子文件)
javaAgent
patchAgent
pom.xml 4KB
src
main
resources
application.properties 1B
templates
static
java
com
sk
agent
service
FirstAgent02.java 3KB
CustomAttachTransformer.java 696B
FirstTransformer.java 2KB
FirstAgent.java 2KB
shell
patchPublic
patchAgent
testDemo.jar 18.69MB
application.properties 17B
patch.sh 518B
start.sh 77B
patch.sh 515B
TaskService.class 1KB
testDemo
pom.xml 2KB
src
main
resources
application.properties 17B
templates
static
java
com
sk
service
InitAction.java 801B
TaskService.java 684B
demo
TestDemoApplication.java 315B
patchAttach
pom.xml 4KB
src
main
resources
application.properties 1B
templates
static
java
com
example
PatchAttchApplication.java 316B
sk
patchattch
service
Init.java 1KB
共 21 条
- 1
资源评论
Dylan~~~
- 粉丝: 8744
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功