All pastes #330189 Raw Edit

JavFun

public java v1 · immutable
#330189 ·published 2007-01-27 17:52 UTC
rendered paste body
import org.apache.bcel.classfile.*;import java.util.jar.JarInputStream;import java.util.zip.ZipEntry;import java.io.FileInputStream;import java.io.File;import java.io.IOException;public class AccessorMethodsGen{    String entityclass = null;    String npcclass = null;    public static void main(String[] args){        AccessorMethodsGen am = new AccessorMethodsGen();        am.new NPC();        am.new Player();        am.new StringWrapper();    }    public class Player{        String s = null;        public Player(){            try{                JarInputStream jis = new JarInputStream(new FileInputStream(new File("runescape.jar")));                ZipEntry ze;                while((ze = jis.getNextEntry()) != null){                    if(ze.getName().endsWith(".class")){                        runCheck1(new ClassParser(jis, ze.getName()).parse());                        if(s != null){                            System.out.println("Player class is "+s);                            return;                        }                    }                }            }            catch(NullPointerException e){}            catch(Exception e){ e.printStackTrace();}            System.out.println("Failed!");        }        public void runCheck1(JavaClass jc){            if(jc.getSuperclassName().equals(entityclass) && !jc.getClassName().equals(npcclass)) s = jc.getClassName();        }    }    public class StringWrapper{        String s = null;        public StringWrapper(){            try{                JarInputStream jis = new JarInputStream(new FileInputStream(new File("runescape.jar")));                ZipEntry ze;                while((ze = jis.getNextEntry()) != null){                    if(ze.getName().endsWith(".class")){                        runCheck1(new ClassParser(jis, ze.getName()).parse());                        if(s != null){                            System.out.println("String wrapper class is "+s);                            return;                        }                    }                }            }            catch(NullPointerException e){}            catch(Exception e){ e.printStackTrace();}            System.out.println("Failed!");        }        public void runCheck1(JavaClass jc){            if(jc.getSuperclassName().endsWith("Object") && !jc.isAbstract()){                for(Method m : jc.getMethods()){                    if(m.getName().equals("toString")){                        for(Field f : jc.getFields()){                            if(f.getType().toString().equals("byte[]")) s = jc.getClassName();                        }                    }                }            }        }    }    public class NPC{        public NPC(){            try{                JarInputStream jis = new JarInputStream(new FileInputStream(new File("runescape.jar")));                ZipEntry ze;                while((ze = jis.getNextEntry()) != null){                    if(ze.getName().endsWith(".class")){                        runCheck1(new ClassParser(jis, ze.getName()).parse());                        if(npcclass != null){                            System.out.println("NPC class is "+ npcclass);                            return;                        }                    }                }            }            catch(NullPointerException e){}            catch(Exception e){ e.printStackTrace();}            System.out.println("Failed!");        }        public boolean runCheck1(JavaClass input){            if(!input.getSuperclassName().endsWith("Object")){                int nonStaticCount = 0;                for(Field f : input.getFields()){                    if(!f.isStatic() && !f.isPrivate()){                        nonStaticCount++;                    }                }                if(nonStaticCount == 1){                    try{                        if(getSubclasses(input.getSuperClass()) == 2 && getSubclasses(input) == 0 && !input.getSuperClass().getSuperClass().getSuperclassName().endsWith("Object")){                            npcclass = input.getClassName();                            System.out.println("Entity class is "+(entityclass = input.getSuperclassName()));                            return true;                        }                    }                    catch(ClassNotFoundException e){ return false; }                }            }            return false;        }        public int getSubclasses(JavaClass jc){            int i = 0;            try{                JarInputStream jis = new JarInputStream(new FileInputStream(new File("runescape.jar")));                ZipEntry ze;                while((ze = jis.getNextEntry()) != null){                    if(ze.getName().endsWith(".class")){                        JavaClass jav = new ClassParser(jis, ze.getName()).parse();                        if(jav.getSuperclassName().equals(jc.getClassName())) i++;                    }                }            }            catch(IOException e){ return 0; }            return i;        }    }}