import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.Scanner;
import java.util.Vector;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import com.sun.tools.classfile.ClassFile;
import com.sun.tools.classfile.ConstantPool;
import com.sun.tools.classfile.ConstantPoolException;
import com.sun.tools.classfile.Method;
public class MyJavap {
// find the method
public static boolean Find(String input, Method[] methods,
ConstantPool const_Pool) throws ConstantPoolException {
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method.getName(const_Pool).equals(input)) {
return true;
}
}
return false;
}
//main
public static void main(String[] args) throws IOException,ConstantPoolException {
Vector<String> answer = new Vector<String>();
//the directory is where you can find the jar
JarFile jarFile = new JarFile(new File(
"C:\\Users\\wl90000\\Desktop\\prework\\java_firstweek\\Java\\apt\\example\\test.jar"));
Enumeration<JarEntry> entries = jarFile.entries();
Scanner scanner = new Scanner(System.in);
System.out.println("input the method name or exit");
String input = scanner.nextLine();
if (input.isEmpty()||input.equals("exit")) {
return;
}
while (entries.hasMoreElements()) {
JarEntry jarEntry = (JarEntry) entries.nextElement();
// find all class file
if (jarEntry.toString().endsWith(".class")) {
URL url = new URL(
"jar:file:C:/Users/wl90000/Desktop/prework/java_firstweek/Java/apt/example/test.jar!/"
+ jarEntry.toString());
InputStream is = url.openStream();
ClassFile classFile = ClassFile.read(is);
ConstantPool constanPool = classFile.constant_pool;
Method[] methods = classFile.methods;
if (Find(input, methods, constanPool)) {
answer.add(jarEntry.toString());
}
}
}
input = null;
System.out.println("the class where you can find the function:");
for(String str : answer)
{
System.out.println(str);
}
}
}
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.Scanner;
import java.util.Vector;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import com.sun.tools.classfile.ClassFile;
import com.sun.tools.classfile.ConstantPool;
import com.sun.tools.classfile.ConstantPoolException;
import com.sun.tools.classfile.Method;
public class MyJavap {
// find the method
public static boolean Find(String input, Method[] methods,
ConstantPool const_Pool) throws ConstantPoolException {
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method.getName(const_Pool).equals(input)) {
return true;
}
}
return false;
}
//main
public static void main(String[] args) throws IOException,ConstantPoolException {
Vector<String> answer = new Vector<String>();
//the directory is where you can find the jar
JarFile jarFile = new JarFile(new File(
"C:\\Users\\wl90000\\Desktop\\prework\\java_firstweek\\Java\\apt\\example\\test.jar"));
Enumeration<JarEntry> entries = jarFile.entries();
Scanner scanner = new Scanner(System.in);
System.out.println("input the method name or exit");
String input = scanner.nextLine();
if (input.isEmpty()||input.equals("exit")) {
return;
}
while (entries.hasMoreElements()) {
JarEntry jarEntry = (JarEntry) entries.nextElement();
// find all class file
if (jarEntry.toString().endsWith(".class")) {
URL url = new URL(
"jar:file:C:/Users/wl90000/Desktop/prework/java_firstweek/Java/apt/example/test.jar!/"
+ jarEntry.toString());
InputStream is = url.openStream();
ClassFile classFile = ClassFile.read(is);
ConstantPool constanPool = classFile.constant_pool;
Method[] methods = classFile.methods;
if (Find(input, methods, constanPool)) {
answer.add(jarEntry.toString());
}
}
}
input = null;
System.out.println("the class where you can find the function:");
for(String str : answer)
{
System.out.println(str);
}
}
}