2017-06-01 3 views
0

// Correction: Ce n'était pas une erreur à cause du code. C'était à cause de l'IDE.JAR d'agent introuvable ou aucun attribut de classe d'agent

J'ai juste essayé de faire une injection pour un jeu appelé Minecraft. Mais j'ai un problème. Ce n'est pas en mesure de charger l'agent.

Voici l'exception: Exception in thread "main" com.sun.tools.attach.AgentLoadException: Agent JAR not found or no Agent-Class attribute at sun.tools.attach.HotSpotVirtualMachine.loadAgent(HotSpotVirtualMachine.java:117) at com.sun.tools.attach.VirtualMachine.loadAgent(VirtualMachine.java:540) at pw.razex.injectionclient.Injectable.main(Injectable.java:55)

Et mon code:

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

}

Classe principale:

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

}

Et mon pom.xml:

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

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> 

+0

Bienvenue sur Stackoverflow! Il est un peu difficile de savoir quel est votre problème, s'il vous plaît modifier pour inclure les problèmes/erreurs que vous rencontrez, sinon nous ne pouvons pas aider. - Bonne chance avec votre mod, quand vous parlez couramment les mods de minecraft, il peut être amusant d'ajouter du nouveau contenu au jeu :) –

Répondre

0

Assurez-vous que votre pot d'agent a ce qui suit pour son MANIFESTE

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