From a24d3cf1dda31a8ba49ef5b0e6ca41eefa79ebac Mon Sep 17 00:00:00 2001 From: SerpentSpirale Date: Sat, 11 Dec 2021 22:29:45 +0100 Subject: [PATCH 1/3] Extended MCOptionUtils to support list values --- .../kdt/pojavlaunch/utils/MCOptionUtils.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/MCOptionUtils.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/MCOptionUtils.java index 579cbbf43e..353f5343f9 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/MCOptionUtils.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/MCOptionUtils.java @@ -16,7 +16,9 @@ import java.io.IOException; import java.lang.ref.WeakReference; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; public class MCOptionUtils { @@ -56,9 +58,28 @@ public static void set(String key, String value) { parameterMap.put(key,value); } + /** Set an array of String, instead of a simple value. Not supported on all options */ + public static void set(String key, List values){ + parameterMap.put(key, values.toString()); + } + public static String get(String key){ return parameterMap.get(key); } + + /** @return A list of values from an array stored as a string */ + public static List getAsList(String key){ + String value = get(key); + + // Fallback if the value doesn't exist + if (value == null) return new ArrayList<>(); + + // Remove the edges + value = value.replace("[", "").replace("]", ""); + if (value.isEmpty()) return new ArrayList<>(); + + return Arrays.asList(value.split(",")); + } public static void save() { StringBuilder result = new StringBuilder(); @@ -89,6 +110,8 @@ public static int getMcScale() { return guiScale; } + /** Add a file observer to reload options on file change + * Listeners get notified of the change */ private static void setupFileObserver(){ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){ fileObserver = new FileObserver(new File(Tools.DIR_GAME_NEW + "/options.txt"), FileObserver.MODIFY) { @@ -111,6 +134,7 @@ public void onEvent(int i, @Nullable String s) { fileObserver.startWatching(); } + /** Notify the option listeners */ public static void notifyListeners(){ for(WeakReference weakReference : optionListeners){ MCOptionListener optionListener = weakReference.get(); @@ -120,10 +144,12 @@ public static void notifyListeners(){ } } + /** Add an option listener, notice how we don't have a reference to it */ public static void addMCOptionListener(MCOptionListener listener){ optionListeners.add(new WeakReference<>(listener)); } + /** Remove a listener from existence, or at least, its reference here */ public static void removeMCOptionListener(MCOptionListener listener){ for(WeakReference weakReference : optionListeners){ MCOptionListener optionListener = weakReference.get(); From 123a185d51a1a140d38dcceeafe82da4c8484627 Mon Sep 17 00:00:00 2001 From: Duy Tran Khanh <40482367+khanhduytran0@users.noreply.github.com> Date: Sun, 12 Dec 2021 14:19:03 +0700 Subject: [PATCH 2/3] Mitigation for the Apache Log4j RCE in 1.8.x-1.18 Related issue: #2378 --- .../src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java index 471cfaff36..1d77972319 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java @@ -361,6 +361,8 @@ public static List getJavaArgs(Context ctx) { "-Dext.net.resolvPath=" +new File(Tools.DIR_DATA,"resolv.conf").getAbsolutePath(), + "-Dlog4j2.formatMsgNoLookup=true", //Log4j RCE mitigation + "-Dnet.minecraft.clientmodname=" + Tools.APP_NAME, "-Dfml.earlyprogresswindow=false" //Forge 1.14+ workaround }; From 755148746124e41989e2a90f548eec37fe163d77 Mon Sep 17 00:00:00 2001 From: Duy Tran Khanh <40482367+khanhduytran0@users.noreply.github.com> Date: Sun, 12 Dec 2021 14:21:46 +0700 Subject: [PATCH 3/3] Update JREUtils.java --- .../src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java index 1d77972319..94e17f22fa 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java @@ -361,7 +361,7 @@ public static List getJavaArgs(Context ctx) { "-Dext.net.resolvPath=" +new File(Tools.DIR_DATA,"resolv.conf").getAbsolutePath(), - "-Dlog4j2.formatMsgNoLookup=true", //Log4j RCE mitigation + "-Dlog4j2.formatMsgNoLookups=true", //Log4j RCE mitigation "-Dnet.minecraft.clientmodname=" + Tools.APP_NAME, "-Dfml.earlyprogresswindow=false" //Forge 1.14+ workaround @@ -540,7 +540,6 @@ private static int getDetectedVersion() { public static native void setupExitTrap(Context context); // Obtain AWT screen pixels to render on Android SurfaceView public static native int[] renderAWTScreenFrame(/* Object canvas, int width, int height */); - static { System.loadLibrary("pojavexec"); System.loadLibrary("pojavexec_awt");