gpt4 book ai didi

java - 使用 Bytebuddy 远程连接代理

转载 作者:行者123 更新时间:2023-12-02 11:38:29 56 4
gpt4 key购买 nike

我正在尝试使用 bytebuddy 为进程附加代理。我发现我们可以使用 ByteBuddyAgent.attach(file,"18467");为了这。但是当我尝试执行此操作时,发生了以下错误。

这是我使用的代理

File file = (new File("Agent.jar"));

错误

java.lang.IllegalStateException: Error during attachment using: net.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound@e26db604
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:378)
at net.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:227)
at net.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:202)
at net.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:189)
at common.netty.echo.EchoHttpServer.main(EchoHttpServer.java:95)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.bytebuddy.agent.Attacher.install(Attacher.java:77)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:373)
... 4 more
Caused by: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
at sun.tools.attach.LinuxVirtualMachine.<init>(LinuxVirtualMachine.java:106)
at sun.tools.attach.LinuxAttachProvider.attachVirtualMachine(LinuxAttachProvider.java:63)
at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:208)
... 10 more

对此有什么想法吗?当我尝试使用另一个代理的此附件时,如下所示

public class Agent {

public static void premain(String args, Instrumentation instrumentation) {

System.out.println("Premain");
File file ;
try {

file = (new File("Agent.jar"));
ByteBuddyAgent.attach(file,"18467");
}
catch (Exception e)
{
e.printStackTrace();
}

}

我收到此错误

错误

java.lang.IllegalStateException: Error during attachment using: net.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound@423f0955
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:378)
at net.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:227)
at net.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:202)
at net.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:189)
at common.netty.echo.Agent.premain(Agent.java:111)
at common.netty.echo.EchoHttpServer.<clinit>(EchoHttpServer.java:56)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.bytebuddy.agent.Attacher.install(Attacher.java:77)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:373)
... 5 more
Caused by: java.lang.UnsatisfiedLinkError: Native Library /usr/lib/jvm/java-8-oracle/jre/lib/amd64/libattach.so already loaded in another classloader
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1907)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1845)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at sun.tools.attach.LinuxVirtualMachine.<clinit>(LinuxVirtualMachine.java:342)
at sun.tools.attach.LinuxAttachProvider.attachVirtualMachine(LinuxAttachProvider.java:63)
at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:208)
... 11 more

对此有什么建议吗?

最佳答案

对于第一条错误消息:目标虚拟机是否运行附件监听器?您可以尝试通过设置默认设置的 -XX:+StartAttachListener 来强制启动线程。您运行的 JVM 版本是什么?

另一个错误消息表明附件库已被另一个类加载器加载。有关更多详细信息,请参阅此答案:java.lang.UnsatisfiedLinkError: Native Library XXX.so already loaded in another classloader

关于java - 使用 Bytebuddy 远程连接代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48745652/

56 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com