在boom的边缘悬崖勒马,太刺激了

某个类现在跑的更溜了
画了个假的饼
This commit is contained in:
Izzel_Aliz
2018-06-23 15:39:51 +08:00
parent 1a73bc0bd7
commit 8af253c6ec
9 changed files with 78 additions and 13 deletions

View File

@@ -101,11 +101,11 @@ public class Ref {
public static JavaPlugin getCallerPlugin(Class<?> callerClass) {
try {
Field pluginField = callerClass.getClassLoader().getClass().getDeclaredField("plugin");
pluginField.setAccessible(true);
return (JavaPlugin) pluginField.get(callerClass.getClassLoader());
} catch (Exception ignored) {
return JavaPlugin.getProvidingPlugin(callerClass);
} catch (IllegalArgumentException ignored) {
TLocale.Logger.error("LOCALE.CALLER-PLUGIN-NOT-FOUND", callerClass.getName());
} catch (IllegalStateException e) {
TLocale.Logger.error("LOCALE.STATIC-CLASS-LOADER", callerClass.getName());
}
return (JavaPlugin) Main.getInst();
}

View File

@@ -2,12 +2,20 @@ package com.ilummc.tlib.util.asm;
public class AsmClassLoader extends ClassLoader {
public AsmClassLoader() {
private static final class AsmClassLoaderHolder {
private static AsmClassLoader instance = new AsmClassLoader();
}
public static AsmClassLoader getInstance() {
return AsmClassLoaderHolder.instance;
}
private AsmClassLoader() {
super(AsmClassLoader.class.getClassLoader());
}
public Class<?> createNewClass(String name, byte[] arr) {
return defineClass(name, arr, 0, arr.length, AsmClassLoader.class.getProtectionDomain());
public static Class<?> createNewClass(String name, byte[] arr) {
return getInstance().defineClass(name, arr, 0, arr.length, AsmClassLoader.class.getProtectionDomain());
}
}

View File

@@ -34,7 +34,7 @@ public class AsmClassTransformer extends ClassVisitor implements Opcodes {
newClassName = from.getName() + "_TabooLibRemap_" + this.hashCode() + "_" + toVer;
prevName = from.getName().replace('.', '/');
classReader.accept(this, ClassReader.SKIP_DEBUG);
Class<?> clazz = new AsmClassLoader().createNewClass(newClassName, writer.toByteArray());
Class<?> clazz = AsmClassLoader.createNewClass(newClassName, writer.toByteArray());
Field field = from.getClassLoader().getClass().getDeclaredField("classes");
field.setAccessible(true);
((Map<String, Class<?>>) field.get(from.getClassLoader())).put(newClassName, clazz);