Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Col-E/Recaf
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Nov 18, 2024
2 parents b9304ba + 2a96cf1 commit 2b3017f
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public static void setWeldConsumer(@Nullable Consumer<Weld> consumer) {
private static SeContainer createContainer() {
logger.info("Creating Recaf CDI container...");
Weld weld = new Weld("recaf");
weld.setClassLoader(Bootstrap.class.getClassLoader());

// Setup custom interceptors & extensions
logger.info("CDI: Adding interceptors & extensions");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.module.ModuleReference;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -118,9 +124,33 @@ private static void handle(int code) {
System.out.println(" - Version (Raw): " + JavaVersion.get());
System.out.println(" - Vendor: " + System.getProperty("java.vm.vendor", "<unknown>"));
System.out.println(" - Home: " + System.getProperty("java.home", "<unknown>"));

System.out.println("JavaFX");
System.out.println(" - Version (Runtime): " + System.getProperty("javafx.runtime.version", "<uninitialized>"));
System.out.println(" - Version (Raw): " + System.getProperty("javafx.version", "<uninitialized>"));
{
ClassLoader loader = ExitDebugLoggingHook.class.getClassLoader();
String javafxClass = "javafx/beans/Observable.class";
try {
Iterator<URL> iterator = loader.getResources(javafxClass).asIterator();
if (!iterator.hasNext()) {
System.out.println(" - Location: not found");
} else {
URL url = iterator.next();
if (!iterator.hasNext()) {
System.out.println(" - Location: " + url);
} else {
System.out.println(" - Location (likely): " + url);
do {
System.out.println(" - Location (seen): " + url);
} while (iterator.hasNext());
}
}
} catch (Exception ex) {
System.out.println(" - Location: <error>");
}
}

System.out.println("Operating System");
System.out.println(" - Name: " + System.getProperty("os.name"));
System.out.println(" - Version: " + System.getProperty("os.version"));
Expand Down Expand Up @@ -154,6 +184,11 @@ private static void handle(int code) {
}
}

System.out.println("Boot class loader:");
dumpBootstrapClassLoader();
System.out.println("Platform class loader:");
dumpBuiltinClassLoader(ClassLoader.getPlatformClassLoader());

Path root = RecafDirectoriesConfig.createBaseDirectory().resolve("config");
if (printConfigs && Files.isDirectory(root)) {
System.out.println("Configs");
Expand Down Expand Up @@ -196,6 +231,35 @@ private static void handle(int code) {
});
}

private static void dumpBuiltinClassLoader(ClassLoader loader) {
try {
Class<?> c = Class.forName("jdk.internal.loader.BuiltinClassLoader");
Field nameToModuleField = c.getDeclaredField("nameToModule");
nameToModuleField.setAccessible(true);
//noinspection unchecked
Map<String, ModuleReference> mdouleMap = (Map<String, ModuleReference>) nameToModuleField.get(loader);
for (Map.Entry<String, ModuleReference> e : mdouleMap.entrySet()) {
ModuleReference moduleReference = e.getValue();
System.out.printf("%s located at %s%n", moduleReference.descriptor().toNameAndVersion(), moduleReference.location()
.map(URI::toString)
.orElse("Unknown"));
}
} catch (Exception ex) {
System.out.printf("dumpBuiltinClassLoader(%s) - <error>%n", loader);
}
}

private static void dumpBootstrapClassLoader() {
try {
Class<?> c = Class.forName("jdk.internal.loader.ClassLoaders");
Method bootLoaderMethod = c.getDeclaredMethod("bootLoader");
bootLoaderMethod.setAccessible(true);
dumpBuiltinClassLoader((ClassLoader) bootLoaderMethod.invoke(null));
} catch (Exception ex) {
System.out.println("dumpBootstrapClassLoader - <error>");
}
}

@Nonnull
@SuppressWarnings("all")
private static String createSha1(@Nonnull File file) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ClassDefiner(@Nonnull String name, @Nonnull byte[] bytecode) {
* Map of classes.
*/
public ClassDefiner(@Nonnull Map<String, byte[]> classes) {
super(ClassLoader.getSystemClassLoader());
super(ClassDefiner.class.getClassLoader());
this.classes = classes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public String getFileName() {
*/
public URL getURL() throws IOException {
if (internal) {
return ClassLoader.getSystemClassLoader().getResource(getPath());
return InternalPath.class.getClassLoader().getResource(getPath());
} else {
return new File(getPath()).toURI().toURL();
}
Expand Down

0 comments on commit 2b3017f

Please sign in to comment.