diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index c8836539..d65390bf 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -75,9 +75,9 @@ pack project(':LauncherAPI') bundle group: 'me.tongfei', name: 'progressbar', version: '0.10.1' bundle group: 'org.fusesource.jansi', name: 'jansi', version: rootProject['verJansi'] - bundle group: 'org.jline', name: 'jline', version: rootProject['verJline'] + bundle group: 'org.jline', name: 'jline-native', version: rootProject['verJline'] bundle group: 'org.jline', name: 'jline-reader', version: rootProject['verJline'] - bundle group: 'org.jline', name: 'jline-terminal', version: rootProject['verJline'] + bundle group: 'org.jline', name: 'jline-terminal-ffm', version: rootProject['verJline'] bundle group: 'org.bouncycastle', name: 'bcprov-jdk18on', version: rootProject['verBcpkix'] bundle group: 'org.bouncycastle', name: 'bcpkix-jdk18on', version: rootProject['verBcpkix'] bundle group: 'org.ow2.asm', name: 'asm-commons', version: rootProject['verAsm'] diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/Main.java b/LaunchServer/src/main/java/pro/gravit/launchserver/Main.java index f12ae900..86477420 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/Main.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/Main.java @@ -18,7 +18,7 @@ import java.util.stream.Stream; public class Main { - private static final List classpathOnly = List.of("proguard", "jline", "progressbar", "kotlin"); + private static final List classpathOnly = List.of("proguard", "progressbar", "kotlin"); private static final String LOG4J_PROPERTY = "log4j2.configurationFile"; private static final String DEBUG_PROPERTY = "launchserver.main.debug"; private static final String LIBRARIES_PROPERTY = "launchserver.dir.libraries"; @@ -74,6 +74,8 @@ public static void main(String[] args) throws Throwable { classpath.add(IOHelper.getCodeSource(LaunchServerStarter.class)); options.moduleConf.modulePath.addAll(modulepath); options.moduleConf.modules.add("ALL-MODULE-PATH"); + options.moduleConf.enableNativeAccess.add("org.fusesource.jansi"); + options.moduleConf.enableNativeAccess.add("io.netty.common"); ClassLoaderControl control = launch.init(classpath, "natives", options); control.clearLauncherPackages(); control.addLauncherPackage("pro.gravit.utils.launch"); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/launch/LaunchOptions.java b/LauncherCore/src/main/java/pro/gravit/utils/launch/LaunchOptions.java index ddabd56c..f6913067 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/launch/LaunchOptions.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/launch/LaunchOptions.java @@ -14,5 +14,6 @@ public static final class ModuleConf { public Map exports = new HashMap<>(); public Map opens = new HashMap<>(); public Map reads = new HashMap<>(); + public List enableNativeAccess = new ArrayList<>(); } } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/launch/ModuleLaunch.java b/LauncherCore/src/main/java/pro/gravit/utils/launch/ModuleLaunch.java index ca1e8bb7..202383eb 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/launch/ModuleLaunch.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/launch/ModuleLaunch.java @@ -29,6 +29,18 @@ public class ModuleLaunch implements Launch { private ModuleLayer layer; private MethodHandles.Lookup hackLookup; private boolean disablePackageDelegateSupport; + private static final MethodHandle ENABLE_NATIVE_ACCESS; + + static { + MethodHandle mh; + try { + mh = MethodHandles.lookup().findVirtual(ModuleLayer.Controller.class, "enableNativeAccess", MethodType.methodType(ModuleLayer.Controller.class, Module.class)); + } catch (NoSuchMethodException | IllegalAccessException e) { + mh = null; + } + ENABLE_NATIVE_ACCESS = mh; + } + @Override public ClassLoaderControl init(List files, String nativePath, LaunchOptions options) { this.disablePackageDelegateSupport = options.disablePackageDelegateSupport; @@ -120,6 +132,20 @@ public ClassLoaderControl init(List files, String nativePath, LaunchOption controller.addReads(source, target); } } + for(var e : options.moduleConf.enableNativeAccess) { + LogHelper.dev("Enable Native Access %s", e); + Module source = layer.findModule(e).orElse(null); + if(source == null) { + throw new RuntimeException(String.format("Module %s not found", e)); + } + if(ENABLE_NATIVE_ACCESS != null) { + try { + ENABLE_NATIVE_ACCESS.invoke(controller, source); + } catch (Throwable ex) { + throw new RuntimeException(ex); + } + } + } moduleClassLoader.initializeWithLayer(layer); } }