java dll注入和启动是hook

//具体示例查看jdk中的dome文件编写例如: heapTracker文件编写
//使用java字节码技术修改内存中的java代码,采用动态的方式加载外部类
//开启调试端口
public class Test {
    //public static void main(String[] args) throws AgentLoadException, AgentInitializationException, IOException, AttachNotSupportedException {
        //attach();
    //}
    //public static void attach() throws AgentLoadException, AgentInitializationException, IOException, AttachNotSupportedException{
        //String pid = "10748";//java进程号
        //String agentPath = "C:\\Users\\DanteJ\\source\\repos\\agent\\x64\\Debug\\agent.dll";//本地库路径
        //System.out.println("attaching....pid="+pid);
        //VirtualMachine virtualMachine = VirtualMachine.attach(pid);//attach JVM
        //virtualMachine.loadAgentPath(agentPath);//加载本地库
        //virtualMachine.detach();//断开
    //}


}


// Dll.cpp : 定义 DLL 应用程序的导出函数。
/*
 * java agent有2个启动函数分别为Agent_OnLoad和Agent_OnAttach
 * Agent_OnLoad在onload阶段被调用
 * Agent_OnAttach在live阶段被调用
 * 但是每个agent只有一个启动函数会被调用
 */

/*
 * 此阶段JVM还没有初始化,所以能做的操作比较受限制
 * JVM参数都无法获取
 * The return value from Agent_OnLoad is used to indicate an error.
 * Any value other than zero indicates an error and causes termination of the VM.
 * 任何非零的返回值都会导致JVM终止。
 */


//JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) {}
/*
 * Any value other than zero indicates an error.
 * An error does not cause the VM to terminate.
 * Instead the VM ignores the error, or takes some implementation specific action -- for example it might print an error to standard error, or record the error in a system log.
 *
 */
//JNIEXPORT jint JNICALL Agent_OnAttach(JavaVM* vm, char* options, void* reserved) {}
/*
 * This function can be used to clean-up resources allocated by the agent.
 */
//JNIEXPORT void JNICALL Agent_OnUnload(JavaVM *vm) {}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值