【问题标题】:From where does the Attaching Error come?附加错误从哪里来?
【发布时间】:2021-01-11 08:49:53
【问题描述】:

当我执行我的 Attacher 时,我会得到一个错误,我不知道为什么 (课程应该是这样的)

java.util.ServiceConfigurationError: com.sun.tools.attach.spi.AttachProvider: Provider sun.tools.attach.WindowsAttachProvider could not be instantiated
com.sun.tools.attach.AttachNotSupportedException: no providers installed
        at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:203)
        at me.paul.TestInjector.Util.attach(Util.java:42)
        at me.paul.TestInjector.Main.main(Main.java:17)

Util 中的第 42 行: VirtualMachine virtualMachine = VirtualMachine.attach(pid); Main 中的第 17 行(方法附加被执行) Util.attach(pid, file);

附加方法:

public static void attach(String pid, File input) {
    System.setProperty("java.libary.path", System.getProperty("java.home").replace("jre", "jdk") + "\\jre\\bin");

    try {
        Field field = ClassLoader.class.getDeclaredField("sys_paths");
        field.setAccessible(true);
        field.set(null, null);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        e.printStackTrace();
        return;
    }

    File agentFile = new File(System.getProperty("user.home") + "/Desktop", "agent.jar");

    buildAgent(input, agentFile);

    try {
        VirtualMachine virtualMachine = VirtualMachine.attach(pid);

        virtualMachine.loadAgent(agentFile.getAbsolutePath());
        System.out.println("[Test-Injection] Agent loaded");

        virtualMachine.detach();
        System.out.println("[Test-Injection] detached!");
    } catch (IOException | AttachNotSupportedException | AgentLoadException | AgentInitializationException e) {
        e.printStackTrace();
    }
}

【问题讨论】:

    标签: java code-injection agent


    【解决方案1】:

    没有安装供应商仅仅意味着当前的虚拟机不支持附件。这通常发生在 JRE(Java 8 和更早版本)或检测模块不存在(Java 9 和更高版本)上。

    【讨论】:

    • Ty 但我使用了外部罐子:d
    猜你喜欢
    • 2018-06-05
    • 1970-01-01
    • 2021-02-07
    • 1970-01-01
    • 2016-07-19
    • 2019-12-06
    • 1970-01-01
    • 2010-12-14
    • 2021-10-03
    相关资源
    最近更新 更多