mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FIX] Forge 1.14 + [FEATURE] String split для asm.
This commit is contained in:
parent
05d5b72d05
commit
d33fe0e6d0
2 changed files with 63 additions and 10 deletions
|
@ -2,19 +2,13 @@
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.objectweb.asm.ClassReader;
|
import org.objectweb.asm.*;
|
||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.tree.*;
|
||||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
|
||||||
import org.objectweb.asm.tree.AnnotationNode;
|
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
|
||||||
import org.objectweb.asm.tree.InvokeDynamicInsnNode;
|
|
||||||
import org.objectweb.asm.tree.LdcInsnNode;
|
|
||||||
import org.objectweb.asm.tree.MethodInsnNode;
|
|
||||||
import org.objectweb.asm.tree.MethodNode;
|
|
||||||
|
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
|
||||||
|
@ -166,4 +160,63 @@ public static int opcodeEmulation(AbstractInsnNode e) {
|
||||||
}
|
}
|
||||||
return stackSize;
|
return stackSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static InsnList getSafeStringInsnList(String string) {
|
||||||
|
InsnList insnList = new InsnList();
|
||||||
|
if (string.length() * 2 < MAX_SAFE_BYTE_COUNT) {
|
||||||
|
insnList.add(new LdcInsnNode(string));
|
||||||
|
return insnList;
|
||||||
|
}
|
||||||
|
|
||||||
|
insnList.add(new TypeInsnNode(NEW, "java/lang/StringBuilder"));
|
||||||
|
insnList.add(new InsnNode(DUP));
|
||||||
|
insnList.add(new MethodInsnNode(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V", false));
|
||||||
|
|
||||||
|
String[] chunks = splitUtf8ToChunks(string, MAX_SAFE_BYTE_COUNT);
|
||||||
|
for (String chunk : chunks) {
|
||||||
|
insnList.add(new LdcInsnNode(chunk));
|
||||||
|
insnList.add(new MethodInsnNode(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false));
|
||||||
|
}
|
||||||
|
insnList.add(new MethodInsnNode(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false));
|
||||||
|
|
||||||
|
return insnList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final int MAX_SAFE_BYTE_COUNT = 65535-Byte.MAX_VALUE;
|
||||||
|
|
||||||
|
public static String[] splitUtf8ToChunks(String text, int maxBytes) {
|
||||||
|
List<String> parts = new ArrayList<>();
|
||||||
|
|
||||||
|
char[] chars = text.toCharArray();
|
||||||
|
|
||||||
|
int lastCharIndex = 0;
|
||||||
|
int currentChunkSize = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < chars.length; i++) {
|
||||||
|
char c = chars[i];
|
||||||
|
int charSize = getUtf8CharSize(c);
|
||||||
|
if (currentChunkSize + charSize < maxBytes) {
|
||||||
|
currentChunkSize += charSize;
|
||||||
|
} else {
|
||||||
|
parts.add(text.substring(lastCharIndex, i));
|
||||||
|
currentChunkSize = 0;
|
||||||
|
lastCharIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentChunkSize != 0) {
|
||||||
|
parts.add(text.substring(lastCharIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
return parts.toArray(new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getUtf8CharSize(char c) {
|
||||||
|
if (c >= 0x0001 && c <= 0x007F) {
|
||||||
|
return 1;
|
||||||
|
} else if (c <= 0x07FF) {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class FMLPatcher extends ClassLoader implements Opcodes {
|
||||||
public static final Vector<MethodHandle> MHS = new Vector<>();
|
public static final Vector<MethodHandle> MHS = new Vector<>();
|
||||||
|
|
||||||
public static void apply() {
|
public static void apply() {
|
||||||
INSTANCE = new FMLPatcher(ClassLoader.getSystemClassLoader());
|
INSTANCE = new FMLPatcher(null); // Never cause ClassFormatError (fuck forge 1.14!!!)
|
||||||
for (String s : PACKAGES) {
|
for (String s : PACKAGES) {
|
||||||
String rMethod = randomStr(16);
|
String rMethod = randomStr(16);
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue