Update asm to 9.1, fix compile error
This commit is contained in:
parent
93fdb30227
commit
ce5b374da3
@ -57,7 +57,7 @@ public class ParamInfoColor extends ParamInfoEnum {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object fromString(String string) {
|
public Object fromString(String string) {
|
||||||
return parseToColor(string);
|
return parseToColor(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
package me.libraryaddict.disguise.utilities.reflection.asm;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.bukkit.craftbukkit.libs.org.objectweb.asm.*;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by libraryaddict on 17/02/2020.
|
|
||||||
*/
|
|
||||||
public class Asm14 implements IAsm {
|
|
||||||
@Getter
|
|
||||||
private Method defineMethod;
|
|
||||||
|
|
||||||
public Asm14() throws NoSuchMethodException {
|
|
||||||
defineMethod = getDefineClassMethod();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class<?> createClassWithoutMethods(String className,
|
|
||||||
ArrayList<Map.Entry<String, String>> illegalMethods) throws IOException, InvocationTargetException,
|
|
||||||
IllegalAccessException, NoSuchFieldException {
|
|
||||||
ClassReader cr = new ClassReader(
|
|
||||||
getClass().getClassLoader().getResourceAsStream(className.replace(".", "/") + ".class"));
|
|
||||||
ClassWriter writer = new ClassWriter(cr, 0);
|
|
||||||
|
|
||||||
cr.accept(new ClassVisitor(Opcodes.ASM5, writer) {
|
|
||||||
public MethodVisitor visitMethod(int access, String name, String desc, String signature,
|
|
||||||
String[] exceptions) {
|
|
||||||
|
|
||||||
Map.Entry<String, String> entry = illegalMethods.stream()
|
|
||||||
.filter(e -> e.getKey().equals(name) && e.getValue().equals(desc)).findFirst().orElse(null);
|
|
||||||
|
|
||||||
if (entry != null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.visitMethod(access, name, desc, signature, exceptions);
|
|
||||||
}
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
byte[] bytes = writer.toByteArray();
|
|
||||||
|
|
||||||
ClassLoader loader = getClass().getClassLoader();
|
|
||||||
Field field = loader.getClass().getDeclaredField("classes");
|
|
||||||
field.setAccessible(true);
|
|
||||||
Map<String, Class<?>> map = (Map<String, Class<?>>) field.get(loader);
|
|
||||||
Class newClass = (Class<?>) defineMethod.invoke(getClass().getClassLoader(), className, bytes, 0, bytes.length);
|
|
||||||
|
|
||||||
map.put(className, newClass);
|
|
||||||
return newClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Method getDefineClassMethod() throws NoSuchMethodException {
|
|
||||||
Method defineClass = ClassLoader.class
|
|
||||||
.getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class);
|
|
||||||
defineClass.setAccessible(true);
|
|
||||||
|
|
||||||
return defineClass;
|
|
||||||
}
|
|
||||||
}
|
|
@ -24,14 +24,10 @@ public class AsmDownloader {
|
|||||||
/**
|
/**
|
||||||
* Using maven
|
* Using maven
|
||||||
*/
|
*/
|
||||||
private String urlToGrab = "https://search.maven.org/remotecontent?filepath=org/ow2/asm/asm/7.3.1/asm-7.3.1.jar";
|
private String urlToGrab = "https://search.maven.org/remotecontent?filepath=org/ow2/asm/asm/9.1/asm-9.1.jar";
|
||||||
private File filePath = new File(LibsDisguises.getInstance().getDataFolder(), "libs/org-ow2-asm-7.3.1.jar");
|
private File filePath = new File(LibsDisguises.getInstance().getDataFolder(), "libs/org-ow2-asm-9.1.jar");
|
||||||
|
|
||||||
public AsmDownloader() {
|
public AsmDownloader() {
|
||||||
if (NmsVersion.v1_13.isSupported()) {
|
|
||||||
throw new IllegalStateException("Sorry, this shouldn't have been started!");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class.forName("org.objectweb.asm.ClassReader");
|
Class.forName("org.objectweb.asm.ClassReader");
|
||||||
return;
|
return;
|
||||||
@ -41,7 +37,7 @@ public class AsmDownloader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!hasASM()) {
|
if (!hasASM()) {
|
||||||
LibsDisguises.getInstance().getLogger().info("Downloading required library for 1.12 support!");
|
LibsDisguises.getInstance().getLogger().info("Downloading required library for asm!");
|
||||||
|
|
||||||
downloadASM();
|
downloadASM();
|
||||||
|
|
||||||
|
@ -35,10 +35,9 @@ public class WatcherSanitizer {
|
|||||||
PluginDescriptionFile desc = (PluginDescriptionFile) dF.get(loader);
|
PluginDescriptionFile desc = (PluginDescriptionFile) dF.get(loader);
|
||||||
|
|
||||||
if (hasWatcher(lClasses)) {
|
if (hasWatcher(lClasses)) {
|
||||||
LibsDisguises.getInstance().getLogger().severe(desc.getFullName() +
|
LibsDisguises.getInstance().getLogger()
|
||||||
" has been a naughty plugin, they're declaring access to the disguise watchers before Lib's " +
|
.severe(desc.getFullName() + " has been a naughty plugin, they're declaring access to the disguise watchers before Lib's " +
|
||||||
"Disguises can properly load them! They should add 'LibsDisguises' to the 'depend' section of" +
|
"Disguises can properly load them! They should add 'LibsDisguises' to the 'depend' section of" + " their plugin.yml!");
|
||||||
" their plugin.yml!");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,8 +48,7 @@ public class WatcherSanitizer {
|
|||||||
|
|
||||||
if (hasWatcher(classes)) {
|
if (hasWatcher(classes)) {
|
||||||
LibsDisguises.getInstance().getLogger()
|
LibsDisguises.getInstance().getLogger()
|
||||||
.severe("Somehow the main server has a Watcher instance! Hopefully there was a plugin mentioned " +
|
.severe("Somehow the main server has a Watcher instance! Hopefully there was a plugin mentioned " + "above! This is a bug!");
|
||||||
"above! This is a bug!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,17 +75,8 @@ public class WatcherSanitizer {
|
|||||||
ArrayList<String> mapped = new ArrayList<>();
|
ArrayList<String> mapped = new ArrayList<>();
|
||||||
|
|
||||||
try (InputStream stream = LibsDisguises.getInstance().getResource("ANTI_PIRACY_ENCRYPTION")) {
|
try (InputStream stream = LibsDisguises.getInstance().getResource("ANTI_PIRACY_ENCRYPTION")) {
|
||||||
IAsm asm;
|
new AsmDownloader();
|
||||||
|
IAsm asm = new Asm13();
|
||||||
if (NmsVersion.v1_14.isSupported()) {
|
|
||||||
asm = new Asm14();
|
|
||||||
} else {
|
|
||||||
if (!NmsVersion.v1_13.isSupported()) {
|
|
||||||
new AsmDownloader();
|
|
||||||
}
|
|
||||||
|
|
||||||
asm = new Asm13();
|
|
||||||
}
|
|
||||||
|
|
||||||
String[] lines = new String(ReflectionManager.readFully(stream), StandardCharsets.UTF_8).split("\n");
|
String[] lines = new String(ReflectionManager.readFully(stream), StandardCharsets.UTF_8).split("\n");
|
||||||
|
|
||||||
@ -100,8 +89,7 @@ public class WatcherSanitizer {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String path = "me.libraryaddict.disguise.disguisetypes." +
|
String path = "me.libraryaddict.disguise.disguisetypes." + (info.getWatcher().equals("FlagWatcher") ? "" : "watchers.") + info.getWatcher();
|
||||||
(info.getWatcher().equals("FlagWatcher") ? "" : "watchers.") + info.getWatcher();
|
|
||||||
|
|
||||||
toRemove.putIfAbsent(path, new ArrayList<>());
|
toRemove.putIfAbsent(path, new ArrayList<>());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user