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();
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…