API Changes
This commit is contained in:
parent
152957c128
commit
c45b8c4b5a
4 changed files with 58 additions and 9 deletions
|
@ -26,7 +26,7 @@ function execute(classNodeList)
|
|||
var fields = cn.fields.toArray();
|
||||
|
||||
//load the class node into the classloader
|
||||
BytecodeViewer.getClassNodeLoader().addClass(cn);
|
||||
BytecodeViewer.loadClassIntoClassLoader(cn);
|
||||
|
||||
for (fieldIndex = 0; fieldIndex < fields.length; fieldIndex++)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package the.bytecode.club.bytecodeviewer.api;
|
||||
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
/**
|
||||
* @author Konloch
|
||||
* @since 6/27/2021
|
||||
*/
|
||||
public class ASMUtil
|
||||
{
|
||||
/**
|
||||
* Creates a new ClassNode instances from the provided byte[]
|
||||
*
|
||||
* @param b the class file's byte[]
|
||||
* @return the ClassNode instance
|
||||
*/
|
||||
public static ClassNode getClassNode(final byte[] b)
|
||||
{
|
||||
ClassReader cr = new ClassReader(b);
|
||||
ClassNode cn = new ClassNode();
|
||||
try {
|
||||
cr.accept(cn, ClassReader.EXPAND_FRAMES);
|
||||
} catch (Exception e) {
|
||||
cr.accept(cn, ClassReader.SKIP_FRAMES);
|
||||
}
|
||||
return cn;
|
||||
}
|
||||
|
||||
public static MethodNode getMethodByName(ClassNode cn, String name)
|
||||
{
|
||||
for(MethodNode m : cn.methods)
|
||||
{
|
||||
if(m.name.equals(name))
|
||||
return m;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -71,6 +71,19 @@ public class BytecodeViewer {
|
|||
* @return The loaded classes into the new URLClassLoader instance
|
||||
* @author Cafebabe
|
||||
*/
|
||||
public static Class<?> loadClassIntoClassLoader(ClassNode cn)
|
||||
{
|
||||
getClassNodeLoader().addClass(cn);
|
||||
|
||||
try {
|
||||
return cl.loadClass(cn.name);
|
||||
} catch (Exception classLoadException) {
|
||||
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(classLoadException);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<Class<?>> loadClassesIntoClassLoader()
|
||||
{
|
||||
try
|
||||
|
@ -102,6 +115,7 @@ public class BytecodeViewer {
|
|||
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(classLoadException);
|
||||
}
|
||||
}
|
||||
|
||||
jarFile.close();
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.objectweb.asm.ClassReader;
|
|||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
|
||||
import the.bytecode.club.bytecodeviewer.api.ASMUtil;
|
||||
|
||||
import static the.bytecode.club.bytecodeviewer.Constants.*;
|
||||
|
||||
|
@ -248,14 +249,7 @@ public class JarUtils {
|
|||
* @return the ClassNode instance
|
||||
*/
|
||||
public static ClassNode getNode(final byte[] bytez) {
|
||||
ClassReader cr = new ClassReader(bytez);
|
||||
ClassNode cn = new ClassNode();
|
||||
try {
|
||||
cr.accept(cn, ClassReader.EXPAND_FRAMES);
|
||||
} catch (Exception e) {
|
||||
cr.accept(cn, ClassReader.SKIP_FRAMES);
|
||||
}
|
||||
return cn;
|
||||
return ASMUtil.getClassNode(bytez);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue