private void disassemble(ClassFile cf, PrintWriter out, String indent) { mClassFile = cf; mCp = cf.getConstantPool(); mOut = out; if (indent.length() == 0 || mClassFile.getSourceFile() != null || mClassFile.isDeprecated() || mClassFile.isSynthetic()) { if (indent.length() == 0 && mClassFile.getTarget() != null) { if (addBreak) { println(indent, " * "); println(CodeAssemblerPrinter.escape(mClassFile.getTarget())); if (mClassFile.getSourceFile() != null) { if (addBreak) { println(indent, " * "); println(CodeAssemblerPrinter.escape(mClassFile.getSourceFile())); if (mClassFile.isInnerClass()) { if (addBreak) { println(indent, " * "); addBreak = false; if (mClassFile.getInnerClassName() == null) { println(indent, " * @anonymous"); } else { print(indent, " * @name "); println(CodeAssemblerPrinter.escape(mClassFile.getInnerClassName()));
boolean saveLocalVariableInfo) { String target = info.getClassFile().getTarget(); if ("1.0".equals(target)) { mTarget = 0x00010000; mCp = mClassFile.getConstantPool(); mInstructions = new InstructionList(saveLocalVariableInfo); mThisReference = null; } else { localVar = mInstructions.createLocalParameter("this", mClassFile.getType()); mThisReference = localVar;
/** * Reads a ClassFile from the given InputStream. With this method, inner * classes cannot be loaded, and custom attributes cannot be defined. * * @param in source of class file data * @throws IOException for I/O error or if classfile is invalid. * @throws ArrayIndexOutOfBoundsException if a constant pool index is out * of range. * @throws ClassCastException if a constant pool index references the * wrong type. */ public static ClassFile readFrom(InputStream in) throws IOException { return readFrom(in, null, null); }
public void invokeConstructor(TypeDesc[] params) { invokeConstructor(mClassFile.getClassName(), mClassFile.getType(), params); }
/** * Add an inner class to this method. * * @param innerClassName Optional short inner class name. * @param superClassName Full super class name. */ public ClassFile addInnerClass(String innerClassName, String superClassName) { ClassFile inner; if (innerClassName == null) { inner = mParent.addInnerClass(null, null, superClassName); } else { String fullInnerClassName = mParent.getClassName() + '$' + (++mAnonymousInnerClassCount) + innerClassName; inner = mParent.addInnerClass(fullInnerClassName, innerClassName, superClassName); } if (mParent.getMajorVersion() >= 49) { inner.addAttribute(new EnclosingMethodAttr (mCp, mCp.addConstantClass(mParent.getClassName()), mCp.addConstantNameAndType(mNameConstant, mDescriptorConstant))); } return inner; }
public String toString() { StringBuffer buf = new StringBuffer(); String modStr = mModifiers.toString(); if (modStr.length() > 0) { buf.append(modStr); buf.append(' '); } if (getModifiers().isInterface()) { buf.append("interface"); } else { buf.append("class"); } buf.append(' '); buf.append(getClassName()); return buf.toString(); } }
private Class<T> createWrapper() { ClassInjector ci = ClassInjector.create(); ClassFile cf = new ClassFile(ci.getClassName()); cf.addInterface(mType); cf.markSynthetic(); cf.setSourceFile(BelatedCreator.class.getName()); cf.setTarget("1.5"); cf.addField(Modifiers.PRIVATE.toFinal(true), REF_FIELD_NAME, atomicRefType); CodeBuilder b = new CodeBuilder(cf.addConstructor(Modifiers.PUBLIC, new TypeDesc[] {atomicRefType})); b.loadThis(); addWrappedCall(cf, new CodeBuilder(cf.addMethod(m)), m); if (!Modifier.isFinal(modifiers) && Modifier.isPublic(modifiers)) { b = new CodeBuilder (cf.addMethod(Modifiers.PUBLIC, m.getName(), MethodDesc.forMethod(m))); addWrappedCall(cf, b, m);
if (innerClassSuffix == null) { println("/**"); println(" * Builds ClassFile for " + cf.getClassName()); println(" *"); println(" * @author auto-generated"); } else { println("/**"); println(" * Builds ClassFile for " + cf.getClassName()); println(" */"); println("private static class InnerBuilder" + innerClassSuffix + " {"); println("public static ClassFile createClassFile() {"); mIndent += 4; println("ClassFile cf = new ClassFile(\"" + escape(cf.getClassName()) + "\", \"" + escape(cf.getSuperClassName()) + "\");"); } else { println("static ClassFile createClassFile(ClassFile cf) {"); if (cf.getTarget() != null) { println("cf.setTarget(\"" + escape(cf.getTarget()) + "\");"); println("cf.setSourceFile(\"" + escape(cf.getSourceFile()) + "\");"); if (cf.isSynthetic()) { println("cf.markSynthetic();"); if (cf.isDeprecated()) { println("cf.markDeprecated();");
cf = new ClassFile(ci.getClassName()); cf.addInterface(type); } else { cf = new ClassFile(ci.getClassName(), type); Modifiers modifiers = cf.getModifiers().toAbstract(true); cf.setModifiers(modifiers); cf.addInterface(Storable.class); cf.addInterface(Cloneable.class); cf.markSynthetic(); cf.setSourceFile(aSourcefileName); cf.setTarget("1.5"); return cf;
cf = ClassFile.readFrom(new ByteArrayInputStream(classfileBuffer)); } catch (Exception e) { IllegalClassFormatException e2 = new IllegalClassFormatException(); if (cf.getModifiers().isInterface()) { for (MethodInfo mi : cf.getMethods()) { tryTransform(modes, transformedMethods, mi); for (MethodInfo mi : cf.getConstructors()) { tryTransform(modes, transformedMethods, mi); cf.addField(Modifiers.PRIVATE.toStatic(true), mHandlerFieldName, TypeDesc.forClass(TraceHandler.class)); MethodInfo clinit = cf.getInitializer(); CodeDisassembler dis; if (clinit == null) { dis = null; clinit = cf.addInitializer(); } else { dis = new CodeDisassembler(clinit); b.loadConstant(cf.getType()); b.loadConstant(mi.getName().equals("<init>") ? null : mi.getName()); File file = new File(cf.getClassName().replace('.', '/') + ".class"); try { File tempDir = new File(System.getProperty("java.io.tmpdir"));
ClassFile cf = new ClassFile(cp, modifiers, thisClass, superClass, outerClass); cf.setVersion(major, minor); loadedClassFiles.put(cf.getClassName(), cf); index = din.readUnsignedShort(); ConstantClassInfo info = (ConstantClassInfo)cp.getConstant(index); cf.addInterface(info.getType().getRootName()); for (int i=0; i<size; i++) { Attribute attr = Attribute.readFrom(cp, din, attrFactory); cf.addAttribute(attr); if (attr instanceof InnerClassesAttr) { cf.mInnerClassesAttr = (InnerClassesAttr)attr; cf.mOuterClass = readOuterClass (outer, loader, attrFactory, loadedClassFiles); ClassFile innerClass = readInnerClass (inner, loader, attrFactory, loadedClassFiles, cf); if (innerClass.getInnerClassName() != null) { innerClass.mInnerClassName = info.getInnerClassName().getValue();
ClassFile inner = new ClassFile(fullInnerClassName, superClassName); Modifiers modifiers = inner.getModifiers().toPrivate(true).toStatic(true); inner.setModifiers(modifiers); inner.mInnerClassName = innerClassName; inner.mOuterClass = this; addAttribute(new InnerClassesAttr(mCp)); inner.addAttribute(new InnerClassesAttr(inner.getConstantPool())); inner.mInnerClassesAttr.addInnerClass(fullInnerClassName, mClassName, innerClassName, modifiers);
ClassFile cf = new ClassFile(ci.getClassName()); cf.addInterface(Decoder.class); cf.markSynthetic(); cf.setSourceFile(GenericStorableCodec.class.getName()); cf.setTarget("1.5"); cf.addDefaultConstructor(); MethodInfo mi = cf.addMethod (Modifiers.PUBLIC, "decode", null, new TypeDesc[] {storableType, byteArrayType}); CodeBuilder b = new CodeBuilder(mi);
private static ClassFile readInnerClass(ConstantClassInfo inner, ClassFileDataLoader loader, AttributeFactory attrFactory, Map<String, ClassFile> loadedClassFiles, ClassFile outerClass) throws IOException { String name = inner.getType().getRootName(); // Prevent cycles in inner class structure. for (ClassFile outer = outerClass; outer != null; outer = outer.getOuterClass()) { if (name.equals(outer.getClassName())) { // Cycle prevented. return null; } } // Prevent classes from being loaded multiple times. ClassFile innerClass = loadedClassFiles.get(name); if (innerClass != null) { return innerClass; } InputStream in = loader.getClassData(name); if (in == null) { return null; } if (!(in instanceof DataInput)) { in = new DataInputStream(in); } return readFrom((DataInput)in, loader, attrFactory, loadedClassFiles, outerClass); }
ClassFile cf = ClassFile.readFrom(in); for (MethodInfo mi : cf.getConstructors()) for (MethodInfo mi : cf.getMethods())
/** * Add a method to this class. * * @param ret Is null if method returns void. * @param params May be null if method accepts no parameters. */ public MethodInfo addMethod(Modifiers modifiers, String methodName, TypeDesc ret, TypeDesc[] params) { MethodDesc md = MethodDesc.forArguments(ret, params); return addMethod(modifiers, methodName, md); }
cf = ClassFile.readFrom(in); } catch (IOException e) { MissingResourceException e2 = new MissingResourceException MethodInfo[] methods = cf.getMethods(); for (int i=0; i<methods.length; i++) { MethodInfo method = methods[i];
void set(ConstantPool cp, MethodInfo info) { TypeDesc[] paramTypes = info.getMethodDescriptor().getParameterTypes(); VerificationTypeInfo[] infos; int offset; if (info.getModifiers().isStatic()) { infos = new VerificationTypeInfo[paramTypes.length]; offset = 0; } else { infos = new VerificationTypeInfo[1 + paramTypes.length]; if (info.getName().equals("<init>")) { infos[0] = UninitThisVariableInfo.THE; } else { infos[0] = VerificationTypeInfo.forType(cp, info.getClassFile().getType()); } offset = 1; } for (int i=0; i<paramTypes.length; i++) { infos[offset + i] = VerificationTypeInfo.forType(cp, paramTypes[i]); } mLocalInfos = infos; } }
private DelegateStorableGenerator(Class<S> type, EnumSet<MasterFeature> features) throws SupportException { mStorableType = type; final Class<? extends S> abstractClass = MasterStorableGenerator.getAbstractClass(mStorableType, features); mClassInjector = ClassInjector.create(mStorableType.getName(), abstractClass.getClassLoader()); mClassFile = new ClassFile(mClassInjector.getClassName(), abstractClass); mClassFile.markSynthetic(); mClassFile.setSourceFile(DelegateStorableGenerator.class.getName()); mClassFile.setTarget("1.5"); }