/** Convenience constructor to set up some important values initially. * * @param class_name fully qualified class name * @param super_class_name fully qualified superclass name * @param file_name source file name * @param access_flags access qualifiers * @param interfaces implemented interfaces */ public ClassGen(final String class_name, final String super_class_name, final String file_name, final int access_flags, final String[] interfaces) { this(class_name, super_class_name, file_name, access_flags, interfaces, new ConstantPoolGen()); }
/** Convenience constructor to set up some important values initially. * * @param class_name fully qualified class name * @param super_class_name fully qualified superclass name * @param file_name source file name * @param access_flags access qualifiers * @param interfaces implemented interfaces */ public ClassGen(String class_name, String super_class_name, String file_name, int access_flags, String[] interfaces) { this(class_name, super_class_name, file_name, access_flags, interfaces, new ConstantPoolGen()); }
/** @param clazz Java class to "decompile" * @param out where to output Java program */ public BCELifier(final JavaClass clazz, final OutputStream out) { _clazz = clazz; _out = new PrintWriter(out); _cp = new ConstantPoolGen(_clazz.getConstantPool()); }
/** @param clazz Java class to "decompile" * @param out where to output Java program */ public BCELifier(JavaClass clazz, OutputStream out) { _clazz = clazz; _out = new PrintWriter(out); _cp = new ConstantPoolGen(_clazz.getConstantPool()); }
protected static String getField(Type target, String name, Type ret, Type[] args) throws ClassNotFoundException { final JavaClass clazz = Repository.lookupClass(target.toString()); for (Method method : clazz.getMethods()) { if (method.getName().equals(name) && method.getSignature().equals(Type.getMethodSignature(ret, args))) { final Code code = method.getCode(); final Instruction[] instructions = new InstructionList(code.getCode()).getInstructions(); if (instructions.length != 3) throw new Error("Method " + method + " does not have exactly three instruction!"); if (!(instructions[0] instanceof ALOAD) || (((ALOAD) instructions[0]).getIndex() != 0)) throw new Error(); if (!(instructions[instructions.length - 1] instanceof ReturnInstruction)) throw new Error(); final ConstantPoolGen constantPoolGen = new ConstantPoolGen(method.getConstantPool()); final GETFIELD get = ((GETFIELD) instructions[1]); return get.getFieldName(constantPoolGen); } } throw new Error(); }
final ConstantPoolGen constantPoolGen = new ConstantPoolGen(method.getConstantPool()); for (int i = 1; i < instructions.length - 1; i++) { final String field;
new LinkedHashMap<JavaClass, Set<Method>>(); ConstantPool cp = javaClass.getConstantPool(); ConstantPoolGen cpg = new ConstantPoolGen(cp); for (Method m : javaClass.getMethods())
superclassCode = new HashMap<>(); JavaClass superCls = cls.getSuperClass(); childPoolGen = new ConstantPoolGen(cls.getConstantPool()); parentPoolGen = new ConstantPoolGen(superCls.getConstantPool()); Method[] methods = superCls.getMethods(); for (Method m : methods) {
superclassCode = new HashMap<>(); JavaClass superCls = cls.getSuperClass(); childPoolGen = new ConstantPoolGen(cls.getConstantPool()); parentPoolGen = new ConstantPoolGen(superCls.getConstantPool()); Method[] methods = superCls.getMethods(); for (Method m : methods) {
private MethodGen getMethod(final Class<?> cls, final String name) throws ClassNotFoundException { final JavaClass jc = Repository.lookupClass(cls); final ConstantPoolGen cp = new ConstantPoolGen(jc.getConstantPool()); for (final Method method : jc.getMethods()) { if (method.getName().equals(name)) { return new MethodGen(method, jc.getClassName(), cp); } } fail("Method " + name + " not found in class " + cls); return null; }
@Test public void testConstantToString() throws ClassNotFoundException { final JavaClass clazz = getTestClass(PACKAGE_BASE_NAME + ".data.SimpleClassWithDefaultConstructor"); final ConstantPoolGen cp = new ConstantPoolGen(clazz.getConstantPool()); final Method[] methods = clazz.getMethods(); for (final Method method : methods) { if (method.getName().equals("<init>")) { for (final InstructionHandle instructionHandle : getInstructionHandles(clazz, cp, method)) { System.out.println(instructionHandle.getInstruction().toString(cp.getConstantPool())); } } } }
ConstantPoolGen cpg = new ConstantPoolGen(Repository.lookupClass(myOwner.getClassName()).getConstantPool()); InstOperandConstraintVisitor v = new InstOperandConstraintVisitor(cpg);
private byte[] getBytesFromClass(final String className) throws ClassNotFoundException, IOException { final JavaClass clazz = getTestClass(className); final ConstantPoolGen cp = new ConstantPoolGen(clazz.getConstantPool()); final Method[] methods = clazz.getMethods(); for (int i = 0; i < methods.length; i++) { final Method method = methods[i]; if (!method.isNative() && !method.isAbstract()) { methods[i] = injection(clazz, method, cp, findFirstStringLocalVariableOffset(method)); } } clazz.setConstantPool(cp.getFinalConstantPool()); return clazz.getBytes(); }
public JavaClass generate(SourceOfRandomness r, GenerationStatus s) { constants = new ConstantPoolGen(); // Generate a class with its meta-data String className = "example.A"; String superName = r.nextBoolean() ? "example.B" : "java.lang.Object"; String fileName = "A.class"; int flags = r.nextInt(0, Short.MAX_VALUE); int numInterfaces = r.nextBoolean() ? 0 : geom.sampleWithMean(MEAN_INTERFACE_COUNT, r); String[] interfaces = new String[numInterfaces]; for (int i = 0; i < numInterfaces; i++) { interfaces[i] = "example.I"+i; } ClassGen classGen = new ClassGen(className, superName, fileName, flags, interfaces, constants); // Validate flags Assume.assumeFalse(classGen.isFinal() && (classGen.isAbstract() | classGen.isInterface())); int numFields = geom.sampleWithMean(MEAN_FIELDS_COUNT, r); for (int i = 0; i < numFields; i++) { classGen.addField(generateField(r)); } int numMethods = geom.sampleWithMean(MEAN_METHODS_COUNT, r); for (int i = 0; i < numMethods; i++) { classGen.addMethod(generateMethod(className, r)); } return classGen.getJavaClass(); }
/** * Initialize with existing class. * @param clazz JavaClass object (e.g. read from file) */ public ClassGen(JavaClass clazz) { class_name_index = clazz.getClassNameIndex(); superclass_name_index = clazz.getSuperclassNameIndex(); class_name = clazz.getClassName(); super_class_name = clazz.getSuperclassName(); file_name = clazz.getSourceFileName(); access_flags = clazz.getAccessFlags(); cp = new ConstantPoolGen(clazz.getConstantPool()); major = clazz.getMajor(); minor = clazz.getMinor(); Attribute[] attributes = clazz.getAttributes(); Method[] methods = clazz.getMethods(); Field[] fields = clazz.getFields(); String[] interfaces = clazz.getInterfaceNames(); for(int i=0; i < interfaces.length; i++) addInterface(interfaces[i]); for(int i=0; i < attributes.length; i++) addAttribute(attributes[i]); for(int i=0; i < methods.length; i++) addMethod(methods[i]); for(int i=0; i < fields.length; i++) addField(fields[i]); }
final ConstantPoolGen cpg = new ConstantPoolGen(Repository.lookupClass(myOwner.getClassName()).getConstantPool()); final InstOperandConstraintVisitor v = new InstOperandConstraintVisitor(cpg);
ConstantPoolGen constantPoolGen = new ConstantPoolGen(jc.getConstantPool());
super_class_name = clazz.getSuperclassName(); file_name = clazz.getSourceFileName(); cp = new ConstantPoolGen(clazz.getConstantPool()); major = clazz.getMajor(); minor = clazz.getMinor();
final ConstantPoolGen constantPoolGen = new ConstantPoolGen(jc.getConstantPool());