Code Cleanup

This commit is contained in:
Konloch 2021-06-27 17:03:43 -07:00
parent 10950a71da
commit 06ff4d4f7d
2 changed files with 18 additions and 7 deletions

File diff suppressed because one or more lines are too long

View file

@ -71,26 +71,35 @@ public class BytecodeViewer {
* @return The loaded classes into the new URLClassLoader instance * @return The loaded classes into the new URLClassLoader instance
* @author Cafebabe * @author Cafebabe
*/ */
public static List<Class<?>> loadClassesIntoClassLoader() { public static List<Class<?>> loadClassesIntoClassLoader()
try { {
try
{
File f = new File(tempDirectory + fs + MiscUtils.randomString(12) + "loaded_temp.jar"); File f = new File(tempDirectory + fs + MiscUtils.randomString(12) + "loaded_temp.jar");
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), f.getAbsolutePath()); JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), f.getAbsolutePath());
JarFile jarFile = new JarFile("" + f.getAbsolutePath()); JarFile jarFile = new JarFile("" + f.getAbsolutePath());
Enumeration<JarEntry> e = jarFile.entries(); Enumeration<JarEntry> e = jarFile.entries();
URL[] urls = {new URL("jar:file:" + "" + f.getAbsolutePath() + "!/")}; URL[] urls = {new URL("jar:file:" + "" + f.getAbsolutePath() + "!/")};
cl = URLClassLoader.newInstance(urls); cl = URLClassLoader.newInstance(urls);
List<Class<?>> ret = new ArrayList<>(); List<Class<?>> ret = new ArrayList<>();
while (e.hasMoreElements()) { while (e.hasMoreElements())
{
JarEntry je = e.nextElement(); JarEntry je = e.nextElement();
if (je.isDirectory() || !je.getName().endsWith(".class")) if (je.isDirectory() || !je.getName().endsWith(".class"))
continue; continue;
String className = je.getName().replace("/", ".").replace(".class", ""); String className = je.getName().replace("/", ".").replace(".class", "");
className = className.replace('/', '.'); className = className.replace('/', '.');
try { try {
ret.add(cl.loadClass(className)); ret.add(cl.loadClass(className));
} catch (Exception e2) { } catch (Exception classLoadException) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e2); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(classLoadException);
} }
} }
jarFile.close(); jarFile.close();