package com.nak.transform; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Iterator; import org.apache.bcel.classfile.Field; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.InstructionHandle; import org.apache.bcel.generic.InstructionList; import org.apache.bcel.generic.SIPUSH; import org.apache.bcel.util.InstructionFinder; public class EntityFinder extends JavaClassTransformer { public JavaClass transform(JavaClass javaClass) { if(javaClass.getInterfaceNames().length != 0) { return null; } ArrayList nonStaticFields = new ArrayList(); for(Field field : javaClass.getFields()) { if(!Modifier.isStatic(field.getModifiers())) { nonStaticFields.add(field); } } if(nonStaticFields.size() == 1) { if(nonStaticFields.get(0).getType().toString().equals("int")) { System.out.println(javaClass.getClassName()); for(Method method : javaClass.getMethods()) { if(method.getName().equals("")) { Iterator iterator = new InstructionFinder(new InstructionList(method.getCode().getCode())).search("sipush"); while(iterator.hasNext()) { if(((SIPUSH)((InstructionHandle[])iterator.next())[0].getInstruction()).getValue().intValue() == 1000) { System.out.println("Entity: " + javaClass.getClassName()); } } } } } } return null; } }