Skip to content

Commit 91f42e9

Browse files
committed
modified loadClassesIntoClassLoader
loadClassesIntoClassLoader is now using specified list of ClassNode
1 parent 198d0f2 commit 91f42e9

File tree

2 files changed

+75
-60
lines changed

2 files changed

+75
-60
lines changed

src/the/bytecode/club/bytecodeviewer/api/BytecodeViewer.java

Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package the.bytecode.club.bytecodeviewer.api;
22

33
import java.io.File;
4+
import java.io.IOException;
45
import java.net.URL;
56
import java.net.URLClassLoader;
67
import java.util.ArrayList;
@@ -62,50 +63,60 @@ public static URLClassLoader getClassLoaderInstance() {
6263
return cl;
6364
}
6465

66+
67+
6568
/**
6669
* Re-instances the URLClassLoader and loads a jar to it.
67-
* @param path
70+
*
71+
* @param nodeList
72+
* The list of ClassNodes to be loaded
6873
* @return The loaded classes into the new URLClassLoader instance
6974
* @author Cafebabe
75+
* @throws IOException
76+
* @throws ClassNotFoundException
7077
*/
71-
public static List<Class<?>> loadClassesIntoClassLoader() {
72-
try {
73-
File f = new File(
74-
the.bytecode.club.bytecodeviewer.BytecodeViewer.tempDirectory +
75-
the.bytecode.club.bytecodeviewer.BytecodeViewer.fs +
76-
"loaded_temp.jar");
77-
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), f.getAbsolutePath());
78-
JarFile jarFile = new JarFile(""+f.getAbsolutePath());
79-
Enumeration<JarEntry> e = jarFile.entries();
80-
URL[] urls = { new URL("jar:file:" + ""+f.getAbsolutePath()+"!/") };
81-
cl = URLClassLoader.newInstance(urls);
82-
List<Class<?>> ret = new ArrayList<Class<?>>();
83-
84-
while (e.hasMoreElements())
85-
{
86-
JarEntry je = (JarEntry) e.nextElement();
87-
if(je.isDirectory() || !je.getName().endsWith(".class"))
88-
continue;
89-
String className = je.getName().replace("/", ".").replace(".class", "");
90-
className = className.replace('/', '.');
91-
try{
92-
ret.add(cl.loadClass(className));
93-
}
94-
catch(Exception e2)
95-
{
96-
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e2);
97-
}
98-
}
99-
jarFile.close();
100-
101-
return ret;
102-
}
103-
catch(Exception e)
104-
{
105-
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
106-
}
107-
return null;
108-
}
78+
@SuppressWarnings("deprecation")
79+
public static List<Class<?>> loadClassesIntoClassLoader(
80+
ArrayList<ClassNode> nodeList) throws IOException,
81+
ClassNotFoundException {
82+
83+
File f = new File(
84+
the.bytecode.club.bytecodeviewer.BytecodeViewer.tempDirectory
85+
+ the.bytecode.club.bytecodeviewer.BytecodeViewer.fs
86+
+ "loaded_temp.jar");
87+
JarUtils.saveAsJarClassesOnly(nodeList, f.getAbsolutePath());
88+
89+
JarFile jarFile = new JarFile("" + f.getAbsolutePath());
90+
Enumeration<JarEntry> e = jarFile.entries();
91+
cl = URLClassLoader.newInstance(new URL[]{ f.toURL() });
92+
List<Class<?>> ret = new ArrayList<Class<?>>();
93+
94+
while (e.hasMoreElements()) {
95+
JarEntry je = (JarEntry) e.nextElement();
96+
if (je.isDirectory() || !je.getName().endsWith(".class"))
97+
continue;
98+
String className = je.getName().replace("/", ".").replace(".class", "");
99+
className = className.replace('/', '.');
100+
ret.add(cl.loadClass(className));
101+
102+
}
103+
jarFile.close();
104+
105+
return ret;
106+
107+
}
108+
109+
110+
/**
111+
* Re-instances the URLClassLoader and loads a jar to it.
112+
* @return The loaded classes into the new URLClassLoader instance
113+
* @author Cafebabe
114+
* @throws IOException
115+
* @throws ClassNotFoundException
116+
*/
117+
public static List<Class<?>> loadAllClassesIntoClassLoader() throws ClassNotFoundException, IOException {
118+
return loadClassesIntoClassLoader(getLoadedClasses());
119+
}
109120

110121
/**
111122
* Creates a new instance of the ClassNode loader.

src/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ZStringArrayDecrypter.java

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.objectweb.asm.tree.ClassNode;
44

55
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
6+
import the.bytecode.club.bytecodeviewer.api.ExceptionUI;
67
import the.bytecode.club.bytecodeviewer.api.Plugin;
78
import the.bytecode.club.bytecodeviewer.api.PluginConsole;
89

@@ -63,28 +64,31 @@ public void execute(ArrayList<ClassNode> classNodeList) {
6364

6465
if (result == 0) {
6566
boolean needsWarning = false;
66-
for (Class<?> debug : the.bytecode.club.bytecodeviewer.api.BytecodeViewer.loadClassesIntoClassLoader()) {
67-
try {
68-
Field[] fields = debug.getDeclaredFields();
69-
for ( Field field : fields ) {
70-
if ( field.getName().equals("z") ) {
71-
out.append(debug.getName() + ":" + BytecodeViewer.nl);
72-
field.setAccessible(true);
73-
if(field.get(null) != null && field.get(null) instanceof String[] && Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) {
74-
String[] fieldVal = (String[]) field.get(null);
75-
for ( int i = 0; i < fieldVal.length; i++ ) {
76-
out.append(" z[" + i + "] = " + fieldVal[i] + BytecodeViewer.nl);
67+
try {
68+
for (Class<?> debug : the.bytecode.club.bytecodeviewer.api.BytecodeViewer.loadAllClassesIntoClassLoader()) {
69+
try {
70+
Field[] fields = debug.getDeclaredFields();
71+
for ( Field field : fields ) {
72+
if ( field.getName().equals("z") ) {
73+
out.append(debug.getName() + ":" + BytecodeViewer.nl);
74+
field.setAccessible(true);
75+
if(field.get(null) != null && field.get(null) instanceof String[] && Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) {
76+
String[] fieldVal = (String[]) field.get(null);
77+
for ( int i = 0; i < fieldVal.length; i++ ) {
78+
out.append(" z[" + i + "] = " + fieldVal[i] + BytecodeViewer.nl);
79+
}
7780
}
78-
}
79-
}
80-
}
81-
} catch(NoClassDefFoundError | Exception e) {
82-
System.err.println("Failed loading class " + debug.getName());
83-
e.printStackTrace();
84-
needsWarning = true;
85-
}
86-
}
87-
81+
}
82+
}
83+
} catch(NoClassDefFoundError | Exception e) {
84+
System.err.println("Failed loading class " + debug.getName());
85+
e.printStackTrace();
86+
needsWarning = true;
87+
}
88+
}
89+
} catch (Exception e){
90+
new ExceptionUI(e);
91+
}
8892
if(needsWarning) {
8993
BytecodeViewer.showMessage("Some classes failed to decrypt, if you'd like to decrypt all of them"+BytecodeViewer.nl+"makes sure you include ALL the libraries it requires.");
9094
}

0 commit comments

Comments
 (0)