找不到代理JAR或没有代理类属性 [英] Agent JAR not found or no Agent-Class attribute

查看:140
本文介绍了找不到代理JAR或没有代理类属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//已修复:这不是由于代码而引起的错误.这是因为有IDE.

// Fixed: This was not an Error because of code. It was because of the IDE.

我刚刚尝试为一款名为《我的世界》的游戏打针.但是我有一个问题.它无法加载代理.

I just tried to make a injection for a game called Minecraft. But i have one Problem. It's not able to load Agent.

以下是异常:线程"main"中的异常com.sun.tools.attach.AgentLoadException:找不到代理JAR或没有代理类属性在sun.tools.attach.HotSpotVirtualMachine.loadAgent(HotSpotVirtualMachine.java:117)在com.sun.tools.attach.VirtualMachine.loadAgent(VirtualMachine.java:540)在pw.razex.injectionclient.Injectable.main(Injectable.java:55)

还有我的代码:

AgentLoader [AgentClass]

AgentLoader [AgentClass]

public class AgentLoader {

public static void agentmain(String agent, Instrumentation instrumentation) {
    try {
        Class[] loadedClasses = instrumentation.getAllLoadedClasses();

        File agentFile = new File(AgentLoader.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
        agentFile.deleteOnExit();

        for(int i = 0; i < loadedClasses.length; i++) {
            Class loadedClass = loadedClasses[i];
            if(loadedClass.getName().equals("net.minecraft.client.Minecraft")) {
                LaunchClassLoader launchClassLoader = (LaunchClassLoader) loadedClass.getClassLoader();
                launchClassLoader.addURL(AgentLoader.class.getProtectionDomain().getCodeSource().getLocation());
                launchClassLoader.loadClass(MainGui.class.getName()).newInstance();
            }
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
}

}

主类:

public class Injectable {

private static VirtualMachineDescriptor minecraftProcess;

public static void main(String[] args) throws Throwable{
    OSUtil.initOS();

    if(OSUtil.osType != OSUtil.OSType.WINDOWS) {
        System.out.println("[X] Invalid OS [" + OSUtil.osType.name() + "]");
        System.exit(-1);
    }

    File sourceFile = new File(Injectable.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
    File tempAttachFile = File.createTempFile("lgt", ".dat");
    Files.copy(sourceFile.toPath(), tempAttachFile.toPath(), StandardCopyOption.REPLACE_EXISTING);

    System.out.println(new File("attach.dll").exists());

    if (System.getProperty("java.library.path") != null) {
        System.setProperty("java.library.path", new File("attach.dll").getAbsolutePath() + System.getProperty("path.separator") + System.getProperty("java.library.path"));
    } else {
        System.setProperty("java.library.path",  new File("attach.dll").getAbsolutePath());
    }

    Field field = ClassLoader.class.getDeclaredField("sys_paths");
    field.setAccessible(true);
    field.set(null, null);

    System.loadLibrary("attach");

    if(VirtualMachine.list().size() == 0) {
        System.out.println("[X] No injectable process found");
        System.exit(-1);
    }

    List<VirtualMachineDescriptor> virtualMachineDescriptors = VirtualMachine.list();
    for(VirtualMachineDescriptor virtualMachineDescriptor : virtualMachineDescriptors) {
        if(virtualMachineDescriptor.displayName().startsWith("net.minecraft.client.main.Main")) {
            minecraftProcess = virtualMachineDescriptor;
            VirtualMachine virtualMachine = VirtualMachine.attach(minecraftProcess);
            virtualMachine.loadAgent(tempAttachFile.getAbsolutePath());
            System.out.println("[O] Attached to minecraft");
        }
    }

    if(minecraftProcess == null) {
        System.out.println("[X] Minecraft is not started yet.");
        System.exit(-1);
    }
}

}

还有我的pom.xml:

And my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd>4.0.0

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>InjectionClientMaven</groupId>
<artifactId>InjectionClientMaven</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifestEntries>
                        <Built-By>David</Built-By>
                        <Main-Class>de.david.injectionclient.Injectable</Main-Class>
                        <Agent-Class>de.david.injectionclient.AgentLoader</Agent-Class>
                        <Class-Path>tools.jar</Class-Path>
                        <Can-Retransform-Classes>true</Can-Retransform-Classes>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

推荐答案

确保您的代理jar的清单中包含以下内容

Make sure your agent jar has the following for its MANIFEST

 Manifest-Version: 1.0
 Agent-Class: com.package.AgentLoader.agentNameHere
 Permissions: all-permissions

这篇关于找不到代理JAR或没有代理类属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆