Skip to content

Commit b914598

Browse files
committed
Add remap program
0 parents  commit b914598

20 files changed

Lines changed: 1595 additions & 0 deletions

‎MCDynamicExchanger/.classpath‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
4+
<attributes>
5+
<attribute name="maven.pomderived" value="true"/>
6+
</attributes>
7+
</classpathentry>
8+
<classpathentry kind="src" output="target/classes" path="src">
9+
<attributes>
10+
<attribute name="optional" value="true"/>
11+
<attribute name="maven.pomderived" value="true"/>
12+
</attributes>
13+
</classpathentry>
14+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
15+
<attributes>
16+
<attribute name="maven.pomderived" value="true"/>
17+
</attributes>
18+
</classpathentry>
19+
<classpathentry kind="output" path="target/classes"/>
20+
</classpath>

‎MCDynamicExchanger/.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/bin/
2+
/target/

‎MCDynamicExchanger/.project‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>MCDynamicExchanger</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
21+
<nature>org.eclipse.jdt.core.javanature</nature>
22+
</natures>
23+
</projectDescription>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.8
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
12+
org.eclipse.jdt.core.compiler.release=disabled
13+
org.eclipse.jdt.core.compiler.source=1.8
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1

‎MCDynamicExchanger/pom.xml‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>com.github.nickid2018</groupId>
4+
<artifactId>mcde</artifactId>
5+
<version>0.0.1</version>
6+
<name>MCDynamicExchanger</name>
7+
<build>
8+
<sourceDirectory>src</sourceDirectory>
9+
<plugins>
10+
<plugin>
11+
<artifactId>maven-compiler-plugin</artifactId>
12+
<version>3.7.0</version>
13+
<configuration>
14+
<source>1.8</source>
15+
<target>1.8</target>
16+
</configuration>
17+
</plugin>
18+
</plugins>
19+
</build>
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.ow2.asm</groupId>
23+
<artifactId>asm-all</artifactId>
24+
<version>6.0_BETA</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>commons-io</groupId>
28+
<artifactId>commons-io</artifactId>
29+
<version>2.6</version>
30+
</dependency>
31+
</dependencies>
32+
<description>A no-mod-launcher dynamic class replacer</description>
33+
</project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.github.nickid2018.asmexecutor;
2+
3+
import org.objectweb.asm.*;
4+
5+
public final class ASMClass implements Comparable<ASMClass> {
6+
7+
public final int classHash;
8+
public final Class<?> clazz;
9+
10+
public ASMClass(byte[] asmcodes, String name) {
11+
classHash = asmcodes.hashCode();
12+
clazz = ASMClassLoader.LOADER.makeClass(asmcodes, name);
13+
ASMClassHolder.addClass(this);
14+
}
15+
16+
public static final ASMClass newClass(byte[] asmcodes) {
17+
ClassReader reader = new ClassReader(asmcodes);
18+
return new ASMClass(asmcodes, reader.getClassName());
19+
}
20+
21+
@Override
22+
public int compareTo(ASMClass o) {
23+
return classHash - o.classHash;
24+
}
25+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.github.nickid2018.asmexecutor;
2+
3+
import java.util.*;
4+
5+
public final class ASMClassHolder {
6+
7+
private static final Set<ASMClass> classes = new TreeSet<>();
8+
9+
public static final void addClass(ASMClass clazz) {
10+
classes.add(clazz);
11+
}
12+
13+
public static final void deleteClass(ASMClass clazz) {
14+
classes.remove(clazz);
15+
}
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.github.nickid2018.asmexecutor;
2+
3+
public final class ASMClassLoader extends ClassLoader {
4+
5+
public static final ASMClassLoader LOADER = new ASMClassLoader();
6+
7+
public Class<?> makeClass(byte[] asms, String name) {
8+
return defineClass(name, asms, 0, asms.length);
9+
}
10+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.github.nickid2018.asmexecutor.gen;
2+
3+
import java.util.*;
4+
import org.objectweb.asm.*;
5+
import com.github.nickid2018.asmexecutor.*;
6+
7+
import static org.objectweb.asm.Opcodes.*;
8+
9+
public class ClassGenerator {
10+
11+
public String details;
12+
public String cname;
13+
public ASMClass clazz;
14+
15+
public ClassGenerator(String details) {
16+
this.details = details;
17+
}
18+
19+
public void make() {
20+
String[] splits = details.split("\n", 2);
21+
details = splits[1];
22+
String[] splitss = splits[0].split(" ", 3);
23+
ClassWriter writer = new ClassWriter(0);
24+
writer.visit(V1_8, Integer.parseInt(splitss[0]),
25+
cname = "_ASM_gen_" + (int) (Integer.MAX_VALUE * Math.random()), null, splitss[1],
26+
splitss[2].trim().isEmpty() ? null : splitss[2].trim().split(" "));
27+
details = details.replaceAll("[Tt][Hh][Ii][Ss]_[Cc][Ll][Aa][Ss][Ss]", cname);
28+
String[] arrdetail = details.split("\n");
29+
for (int index = 0; index < arrdetail.length;) {
30+
String detail = arrdetail[index];
31+
String type = detail.split(" ")[0];
32+
switch (type.toUpperCase()) {
33+
case "METHOD":
34+
index += genMethod(writer, arrdetail, index);
35+
break;
36+
case "FIELD":
37+
index += genField(writer, arrdetail, index);
38+
break;
39+
case "DEFAULT_INIT":
40+
index += genDefaultInit(writer);
41+
break;
42+
default:
43+
throw new IllegalArgumentException("Uncompile Tag");
44+
}
45+
}
46+
writer.visitEnd();
47+
clazz = ASMClass.newClass(writer.toByteArray());
48+
}
49+
50+
public Class<?> getGeneratedClass() {
51+
return clazz.clazz;
52+
}
53+
54+
public static int genMethod(ClassWriter writer, String[] details, int offset) {
55+
int counter = 1;
56+
String description = details[offset];
57+
String[] aftSplit = description.split(" ");
58+
MethodVisitor mwriter = writer.visitMethod(Integer.parseInt(aftSplit[1]), aftSplit[2], aftSplit[3].trim(), null,
59+
null);
60+
Map<Integer, Label> labels = new HashMap<>();
61+
for (int i = offset;;) {
62+
String now = details[++i];
63+
counter++;
64+
if (!MethodGenerator.genNextLine(mwriter, now, labels))
65+
break;
66+
}
67+
return counter;
68+
}
69+
70+
public static int genField(ClassWriter writer, String[] details, int offset) {
71+
String[] aftSplit = details[offset].split(" ", 5);
72+
FieldVisitor fwriter;
73+
if (aftSplit.length == 4) {
74+
fwriter = writer.visitField(Integer.parseInt(aftSplit[1]), aftSplit[2], aftSplit[3].trim(), null, null);
75+
} else {
76+
try {
77+
fwriter = writer.visitField(Integer.parseInt(aftSplit[1]), aftSplit[2], aftSplit[3].trim(), null,
78+
MethodGenerator.parseObjects("{" + aftSplit[4].replaceFirst(" ", ",") + "}"));
79+
} catch (Exception e) {
80+
throw new RuntimeException(e);
81+
}
82+
}
83+
fwriter.visitEnd();
84+
return 1;
85+
}
86+
87+
public static int genDefaultInit(ClassWriter writer) {
88+
MethodVisitor mv = writer.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
89+
mv.visitVarInsn(ALOAD, 0);
90+
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
91+
mv.visitInsn(RETURN);
92+
mv.visitMaxs(1, 1);
93+
mv.visitEnd();
94+
return 1;
95+
}
96+
}

0 commit comments

Comments
 (0)