All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.imqa.asm.SuperFind Maven / Gradle / Ivy

There is a newer version: 2.25.11
Show newest version
package io.imqa.asm;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import io.imqa.injector.util.Logger;

public class SuperFind {

    public static String find(File classFile) {
        String superName = "";
        try {
            InputStream visitorInputStream = new FileInputStream(classFile);
            ClassReader cr = new ClassReader(visitorInputStream);
            superName = cr.getSuperName();
            visitorInputStream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return superName;
    }

    public static String find(String baseDir, String classFullName, String findMethod, String findDesc) {
        String superName = classFullName;
        boolean endFind = false;

        while (!endFind) {
            Logger.d("FINDING");
            try {
                InputStream visitorInputStream = new FileInputStream(baseDir + "/" + superName + ".class");
                ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
                ClassReader cr = new ClassReader(visitorInputStream);
                FindClassVisitor cv = new FindClassVisitor(cw, findMethod, findDesc);
                cr.accept(cv, ClassReader.EXPAND_FRAMES);

                visitorInputStream.close();

                superName = cv.getSuperClass();

                endFind = cv.isFind() || cv.isRoot();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                endFind = true;
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                endFind = true;
            }
        }

        return superName;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy