mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-12-06 02:40:23 -08:00
Freedom for javascript mods (#5421)
* remove blacklist and class shutter * no context factory
This commit is contained in:
parent
a756dec379
commit
de9c82d1d2
4 changed files with 2 additions and 28 deletions
|
|
@ -62,13 +62,6 @@ public class AndroidRhinoContext{
|
||||||
initApplicationClassLoader(createClassLoader(AndroidContextFactory.class.getClassLoader()));
|
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
|
* Create a ClassLoader which is able to deal with bytecode
|
||||||
* @param parent the parent of the create classloader
|
* @param parent the parent of the create classloader
|
||||||
|
|
|
||||||
|
|
@ -79,15 +79,6 @@ public interface Platform{
|
||||||
}
|
}
|
||||||
|
|
||||||
default Context getScriptContext(){
|
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();
|
Context c = Context.enter();
|
||||||
c.setOptimizationLevel(9);
|
c.setOptimizationLevel(9);
|
||||||
return c;
|
return c;
|
||||||
|
|
|
||||||
|
|
@ -752,8 +752,8 @@ public class ContentParser{
|
||||||
var out = ClassMap.classes.get(!base.isEmpty() && Character.isLowerCase(base.charAt(0)) ? Strings.capitalize(base) : base);
|
var out = ClassMap.classes.get(!base.isEmpty() && Character.isLowerCase(base.charAt(0)) ? Strings.capitalize(base) : base);
|
||||||
if(out != null) return (Class<T>)out;
|
if(out != null) return (Class<T>)out;
|
||||||
|
|
||||||
//try to resolve it as a raw class name if it's allowed
|
//try to resolve it as a raw class name
|
||||||
if(base.indexOf('.') != -1 && Scripts.allowClass(base)){
|
if(base.indexOf('.') != -1){
|
||||||
try{
|
try{
|
||||||
return (Class<T>)Class.forName(base);
|
return (Class<T>)Class.forName(base);
|
||||||
}catch(Exception ignored){
|
}catch(Exception ignored){
|
||||||
|
|
|
||||||
|
|
@ -22,22 +22,12 @@ import java.util.*;
|
||||||
import java.util.regex.*;
|
import java.util.regex.*;
|
||||||
|
|
||||||
public class Scripts implements Disposable{
|
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 Context context;
|
||||||
private final Scriptable scope;
|
private final Scriptable scope;
|
||||||
private boolean errored;
|
private boolean errored;
|
||||||
|
|
||||||
LoadedMod currentMod = null;
|
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(){
|
public Scripts(){
|
||||||
Time.mark();
|
Time.mark();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue