Package javassist.bytecode

Examples of javassist.bytecode.CodeIterator


                        System.out.println("calleeMethod = " + calleeMethod.getName());
                        System.out.println("calleeClassName = " + calleeClassName);
                        System.out.println("methodCall = " + methodCall.indexOfBytecode());
                        methodCall.replace("{java.lang.System.out.println($args[0]); $_=null;}");
                        try {
                            CodeIterator it = where.getMethodInfo().getCodeAttribute().iterator();
                            it.move(methodCall.indexOfBytecode() - 5);
                            System.out.println("it.get() = " + it.get());
                            it.next();
                            System.out.println("it.get() = " + it.get());
                            it.next();
                            System.out.println("it.get() = " + it.get());
                            it.next();
                            System.out.println("it.get() = " + it.get());
                            it.next();
                        } catch (Throwable t) {
                            t.printStackTrace();
                        }
                        return;
View Full Code Here


                                System.out.println("calleeMethod = " + calleeMethod.getName());
                                System.out.println("calleeClassName = " + calleeClassName);
                                System.out.println("methodCall = " + methodCall.indexOfBytecode());
                                methodCall.replace("{java.lang.System.out.println($args[0]); $_=null;}");
                                try {
                                    CodeIterator it = where.getMethodInfo().getCodeAttribute().iterator();
                                    it.move(methodCall.indexOfBytecode() - 5);
                                    System.out.println("it.get() = " + it.get());
                                    it.next();
                                    System.out.println("it.get() = " + it.get());
                                    it.next();
                                    System.out.println("it.get() = " + it.get());
                                    it.next();
                                    System.out.println("it.get() = " + it.get());
                                    it.next();
                                } catch (Throwable t) {
                                    t.printStackTrace();
                                }
                                return;
View Full Code Here

      }
      CodeAttribute codeAttr = minfo.getCodeAttribute();
      if (codeAttr == null) {
        continue;
      }
      CodeIterator iter = codeAttr.iterator();
      while (iter.hasNext()) {
        int pos = iter.next();
        pos = transformInvokevirtualsIntoGetfields(classfile, iter, pos);
        pos = transformInvokevirtualsIntoPutfields(classfile, iter, pos);
      }
     
      StackMapTable smt = MapMaker.make(ClassPool.getDefault(), minfo);
View Full Code Here

      classFile.setSuperclass(null);
      for (CtConstructor ctBehavior : newClass.getDeclaredConstructors()) {
        javassist.bytecode.MethodInfo methodInfo = ctBehavior.getMethodInfo2();
        CodeAttribute codeAttribute = methodInfo.getCodeAttribute();
        if (codeAttribute != null) {
          CodeIterator iterator = codeAttribute.iterator();
          int pos = iterator.skipSuperConstructor();
          if (pos >= 0) {
            int mref = iterator.u16bitAt(pos + 1);
            ConstPool constPool = codeAttribute.getConstPool();
            iterator.write16bit(constPool.addMethodrefInfo(constPool.addClassInfo("java.lang.Object"), "<init>", "()V"), pos + 1);
            String desc = constPool.getMethodrefType(mref);
            int num = Descriptor.numOfParameters(desc) + 1;
            pos = iterator.insertGapAt(pos, num, false).position;
            Descriptor.Iterator i$ = new Descriptor.Iterator(desc);
            for (i$.next(); i$.isParameter(); i$.next()) {
              iterator.writeByte(i$.is2byte() ? Opcode.POP2 : Opcode.POP, pos++);
            }
          }
          methodInfo.rebuildStackMapIf6(newClass.getClassPool(), newClass.getClassFile2());
        }
      }
View Full Code Here

    int removed = 0;
    CtClass ctClass = ctBehavior.getDeclaringClass();
    MethodInfo methodInfo = ctBehavior.getMethodInfo();
    CodeAttribute codeAttribute = methodInfo.getCodeAttribute();
    if (codeAttribute != null) {
      CodeIterator iterator = codeAttribute.iterator();
      while (iterator.hasNext()) {
        int index = iterator.next();
        int op = iterator.byteAt(index);
        if (op == opcode && (removeIndex < 0 || removeIndex == ++currentIndex)) {
          for (int i = 0; i <= index; i++) {
            iterator.writeByte(Opcode.NOP, i);
          }
          removed++;
          PatchLog.fine("Removed until " + index);
          if (removeIndex == -2) {
            break;
View Full Code Here

    PatchLog.fine("Removed after opcode index " + index + " in " + ctBehavior.getLongName());
    CtClass ctClass = ctBehavior.getDeclaringClass();
    MethodInfo methodInfo = ctBehavior.getMethodInfo2();
    CodeAttribute codeAttribute = methodInfo.getCodeAttribute();
    if (codeAttribute != null) {
      CodeIterator iterator = codeAttribute.iterator();
      int i, length = iterator.getCodeLength() - 1;
      for (i = index; i < length; i++) {
        iterator.writeByte(Opcode.NOP, i);
      }
      iterator.writeByte(Opcode.RETURN, i);
      methodInfo.rebuildStackMapIf6(ctClass.getClassPool(), ctClass.getClassFile2());
    }
  }
View Full Code Here

  @Patch
  public void lockToSynchronized(CtBehavior ctBehavior, Map<String, String> attributes) throws BadBytecode {
    CtClass ctClass = ctBehavior.getDeclaringClass();
    MethodInfo methodInfo = ctBehavior.getMethodInfo();
    CodeAttribute codeAttribute = methodInfo.getCodeAttribute();
    CodeIterator iterator = codeAttribute.iterator();
    ConstPool constPool = codeAttribute.getConstPool();
    int done = 0;
    while (iterator.hasNext()) {
      int pos = iterator.next();
      int op = iterator.byteAt(pos);
      if (op == Opcode.INVOKEINTERFACE) {
        int mref = iterator.u16bitAt(pos + 1);
        if (constPool.getInterfaceMethodrefClassName(mref).endsWith("Lock")) {
          String name = constPool.getInterfaceMethodrefName(mref);
          boolean remove = false;
          if ("lock".equals(name)) {
            remove = true;
            iterator.writeByte(Opcode.MONITORENTER, pos);
          } else if ("unlock".equals(name)) {
            remove = true;
            iterator.writeByte(Opcode.MONITOREXIT, pos);
          }
          if (remove) {
            done++;
            iterator.writeByte(Opcode.NOP, pos + 1);
            iterator.writeByte(Opcode.NOP, pos + 2);
            iterator.writeByte(Opcode.NOP, pos + 3);
            iterator.writeByte(Opcode.NOP, pos + 4);
          }
        }
      } else if (op == Opcode.INVOKEVIRTUAL) {
        int mref = iterator.u16bitAt(pos + 1);
        if (constPool.getMethodrefClassName(mref).endsWith("NativeMutex")) {
          String name = constPool.getMethodrefName(mref);
          boolean remove = false;
          if ("lock".equals(name)) {
            remove = true;
            iterator.writeByte(Opcode.MONITORENTER, pos);
          } else if ("unlock".equals(name)) {
            remove = true;
            iterator.writeByte(Opcode.MONITOREXIT, pos);
          }
          if (remove) {
            done++;
            iterator.writeByte(Opcode.NOP, pos + 1);
            iterator.writeByte(Opcode.NOP, pos + 2);
          }
        }
      }
    }
    methodInfo.rebuildStackMapIf6(ctClass.getClassPool(), ctClass.getClassFile2());
View Full Code Here

      }
     
      // compute the hash from the opcodes
      ConstPool constants = behavior.getMethodInfo().getConstPool();
      final MessageDigest digest = MessageDigest.getInstance( "MD5" );
      CodeIterator iter = behavior.getMethodInfo().getCodeAttribute().iterator();
      while( iter.hasNext() )
      {
        int pos = iter.next();
       
        // update the hash with the opcode
        int opcode = iter.byteAt( pos );
        digest.update( (byte)opcode );
       
        switch( opcode )
        {
          case Opcode.LDC:
          {
            int constIndex = iter.byteAt( pos + 1 );
            updateHashWithConstant( digest, constants, constIndex );
          }
          break;
         
          case Opcode.LDC_W:
          case Opcode.LDC2_W:
          {
            int constIndex = ( iter.byteAt( pos + 1 ) << 8 ) | iter.byteAt( pos + 2 );
            updateHashWithConstant( digest, constants, constIndex );
          }
          break;
        }
      }
View Full Code Here

TOP

Related Classes of javassist.bytecode.CodeIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.