예제 #1
0
  public void toAsm(JarOutputStream jos) {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
    //        ClassWriter cw = new ClassWriter(0);
    CheckClassAdapter cca = new CheckClassAdapter(cw);

    cca.visit(version, access, name, sig, superName, interfaces);
    Iterator it = fieldVisitors.entrySet().iterator();

    while (it.hasNext()) {
      Map.Entry pairs = (Map.Entry) it.next();
      ByteCodeFieldVisitor fv = (ByteCodeFieldVisitor) pairs.getValue();
      fv.toAsm(cca);
    }

    it = methodVisitors.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry pairs = (Map.Entry) it.next();
      ByteCodeMethodVisitor mv = (ByteCodeMethodVisitor) pairs.getValue();
      mv.toAsm(cca);
    }

    byte[] bytes = cw.toByteArray();
    if (ProjectProperties.getBoolean("fortress.bytecode.verify", false)) {
      PrintWriter pw = new PrintWriter(System.out);
      CheckClassAdapter.verify(new ClassReader(bytes), true, pw);
    }
    System.out.println("About to write " + name);
    ByteCodeWriter.writeJarredClass(jos, name, bytes);
  }
예제 #2
0
 public MethodVisitor visitMethod(
     int access, String _name, String desc, String sig, String[] exceptions) {
   ByteCodeMethodVisitor bcmv = new ByteCodeMethodVisitor(access, _name, desc, sig, exceptions);
   methodVisitors.put(_name + desc, bcmv);
   bcmv.print();
   return bcmv;
 }
예제 #3
0
  public void print() {
    Iterator it = fieldVisitors.entrySet().iterator();

    while (it.hasNext()) {
      Map.Entry pairs = (Map.Entry) it.next();
      System.out.println("Printing Field: " + pairs.getKey() + ":");
      ByteCodeFieldVisitor fv = (ByteCodeFieldVisitor) pairs.getValue();
      fv.print();
    }

    it = methodVisitors.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry pairs = (Map.Entry) it.next();
      ByteCodeMethodVisitor bcmv = (ByteCodeMethodVisitor) pairs.getValue();
      System.out.println("Printing Method: Key = " + pairs.getKey() + " bcmv says " + bcmv.name);

      bcmv.print();
    }
  }