Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
198 views
in Technique[技术] by (71.8m points)

java - From where does the Attaching Error come?

When I'm Executing my Attacher I will get an Error, and I don't know Why (The Classes are like they Should be)

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)

Line 42 in Util: VirtualMachine virtualMachine = VirtualMachine.attach(pid); Line 17 in Main (The Method attach gets Executed) Util.attach(pid, file);

The Attach Method:

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();
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

no providers installed simply means that the current VM does not support attachment. This typically occurs on a JRE (Java 8 and before) or if the instrumentation module is not present (Java 9 and later).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...