Merge remote-tracking branch 'origin/master'

This commit is contained in:
Anuken 2021-06-13 19:27:34 -04:00
commit 7fe9e7f9c2
4 changed files with 2 additions and 28 deletions

View File

@ -62,13 +62,6 @@ public class AndroidRhinoContext{
initApplicationClassLoader(createClassLoader(AndroidContextFactory.class.getClassLoader()));
}
@Override
protected Context makeContext(){
Context ctx = super.makeContext();
ctx.setClassShutter(Scripts::allowClass);
return ctx;
}
/**
* Create a ClassLoader which is able to deal with bytecode
* @param parent the parent of the create classloader

View File

@ -79,15 +79,6 @@ public interface Platform{
}
default Context getScriptContext(){
ContextFactory.getGlobalSetter().setContextFactoryGlobal(new ContextFactory(){
@Override
protected Context makeContext(){
Context ctx = super.makeContext();
ctx.setClassShutter(Scripts::allowClass);
return ctx;
}
});
Context c = Context.enter();
c.setOptimizationLevel(9);
return c;

View File

@ -752,8 +752,8 @@ public class ContentParser{
var out = ClassMap.classes.get(!base.isEmpty() && Character.isLowerCase(base.charAt(0)) ? Strings.capitalize(base) : base);
if(out != null) return (Class<T>)out;
//try to resolve it as a raw class name if it's allowed
if(base.indexOf('.') != -1 && Scripts.allowClass(base)){
//try to resolve it as a raw class name
if(base.indexOf('.') != -1){
try{
return (Class<T>)Class.forName(base);
}catch(Exception ignored){

View File

@ -22,22 +22,12 @@ import java.util.*;
import java.util.regex.*;
public class Scripts implements Disposable{
private static final Seq<String> blacklist = Seq.with(".net.", "java.net", "files", "reflect", "javax", "rhino", "file", "channels", "jdk",
"runtime", "util.os", "rmi", "security", "org.", "sun.", "beans", "sql", "http", "exec", "compiler", "process", "system",
".awt", "socket", "classloader", "oracle", "invoke", "java.util.function", "java.util.stream", "org.", "mod.classmap");
private static final Seq<String> whitelist = Seq.with("mindustry.net", "netserver", "netclient", "com.sun.proxy.$proxy", "jdk.proxy", "mindustry.gen.",
"mindustry.logic.", "mindustry.async.", "saveio", "systemcursor", "filetreeinitevent", "asyncexecutor");
private final Context context;
private final Scriptable scope;
private boolean errored;
LoadedMod currentMod = null;
public static boolean allowClass(String type){
return !blacklist.contains(t -> type.toLowerCase(Locale.ROOT).contains(t)) || whitelist.contains(t -> type.toLowerCase(Locale.ROOT).contains(t));
}
public Scripts(){
Time.mark();