@Override
 public AttributeInfo copy(final ConstPool newCp, final Map classnames) {
   final byte[] src = this.get();
   final byte[] dest = new byte[src.length];
   final ConstPool cp = this.getConstPool();
   final InnerClassesAttribute attr = new InnerClassesAttribute(newCp, dest);
   final int n = ByteArray.readU16bit(src, 0);
   ByteArray.write16bit(n, dest, 0);
   int j = 2;
   for (int i = 0; i < n; ++i) {
     int innerClass = ByteArray.readU16bit(src, j);
     int outerClass = ByteArray.readU16bit(src, j + 2);
     int innerName = ByteArray.readU16bit(src, j + 4);
     final int innerAccess = ByteArray.readU16bit(src, j + 6);
     if (innerClass != 0) {
       innerClass = cp.copy(innerClass, newCp, classnames);
     }
     ByteArray.write16bit(innerClass, dest, j);
     if (outerClass != 0) {
       outerClass = cp.copy(outerClass, newCp, classnames);
     }
     ByteArray.write16bit(outerClass, dest, j + 2);
     if (innerName != 0) {
       innerName = cp.copy(innerName, newCp, classnames);
     }
     ByteArray.write16bit(innerName, dest, j + 4);
     ByteArray.write16bit(innerAccess, dest, j + 6);
     j += 8;
   }
   return attr;
 }
Beispiel #2
0
 private static void copyConstPoolInfo(
     int i, byte[] code, ConstPool srcCp, byte[] newcode, ConstPool destCp, Map classnameMap) {
   int index = ((code[i] & 0xff) << 8) | (code[i + 1] & 0xff);
   index = srcCp.copy(index, destCp, classnameMap);
   newcode[i] = (byte) (index >> 8);
   newcode[i + 1] = (byte) index;
 }
Beispiel #3
0
  void prune(ConstPool cp) {
    LinkedList newAttributes = new LinkedList();
    AttributeInfo invisibleAnnotations = getAttribute(AnnotationsAttribute.invisibleTag);
    if (invisibleAnnotations != null) {
      invisibleAnnotations = invisibleAnnotations.copy(cp, null);
      newAttributes.add(invisibleAnnotations);
    }

    AttributeInfo visibleAnnotations = getAttribute(AnnotationsAttribute.visibleTag);
    if (visibleAnnotations != null) {
      visibleAnnotations = visibleAnnotations.copy(cp, null);
      newAttributes.add(visibleAnnotations);
    }

    AttributeInfo signature = getAttribute(SignatureAttribute.tag);
    if (signature != null) {
      signature = signature.copy(cp, null);
      newAttributes.add(signature);
    }

    int index = getConstantValue();
    if (index != 0) {
      index = constPool.copy(index, cp, null);
      newAttributes.add(new ConstantAttribute(cp, index));
    }

    attribute = newAttributes;
    name = cp.addUtf8Info(getName());
    descriptor = cp.addUtf8Info(getDescriptor());
    constPool = cp;
  }
    protected int[] copyData(int[] tags, int[] data) {
      int[] newData = new int[data.length];
      for (int i = 0; i < data.length; i++)
        if (tags[i] == OBJECT) newData[i] = srcPool.copy(data[i], destPool, classnames);
        else newData[i] = data[i];

      return newData;
    }
  /**
   * Copies the contents from a source attribute. Specified class names are replaced during the
   * copy.
   *
   * @param srcAttr source Exceptions attribute
   * @param classnames pairs of replaced and substituted class names.
   */
  private void copyFrom(ExceptionsAttribute srcAttr, Map classnames) {
    ConstPool srcCp = srcAttr.constPool;
    ConstPool destCp = this.constPool;
    byte[] src = srcAttr.info;
    int num = src.length;
    byte[] dest = new byte[num];
    dest[0] = src[0];
    dest[1] = src[1]; // the number of elements.
    for (int i = 2; i < num; i += 2) {
      int index = ByteArray.readU16bit(src, i);
      ByteArray.write16bit(srcCp.copy(index, destCp, classnames), dest, i);
    }

    this.info = dest;
  }
Beispiel #6
0
 /**
  * Copies a constant pool entry into the destination constant pool and returns the index of the
  * copied entry.
  *
  * @param srcIndex the index of the copied entry into the source constant pool.
  * @return the index of the copied item into the destination constant pool.
  */
 int copy(int srcIndex) {
   return srcPool.copy(srcIndex, destPool, classnames);
 }
Beispiel #7
0
  private static LdcEntry copyCode(
      byte[] code,
      int beginPos,
      int endPos,
      ConstPool srcCp,
      byte[] newcode,
      ConstPool destCp,
      Map classnameMap)
      throws BadBytecode {
    int i2, index;
    LdcEntry ldcEntry = null;

    for (int i = beginPos; i < endPos; i = i2) {
      i2 = CodeIterator.nextOpcode(code, i);
      byte c = code[i];
      newcode[i] = c;
      switch (c & 0xff) {
        case LDC_W:
        case LDC2_W:
        case GETSTATIC:
        case PUTSTATIC:
        case GETFIELD:
        case PUTFIELD:
        case INVOKEVIRTUAL:
        case INVOKESPECIAL:
        case INVOKESTATIC:
        case NEW:
        case ANEWARRAY:
        case CHECKCAST:
        case INSTANCEOF:
          copyConstPoolInfo(i + 1, code, srcCp, newcode, destCp, classnameMap);
          break;
        case LDC:
          index = code[i + 1] & 0xff;
          index = srcCp.copy(index, destCp, classnameMap);
          if (index < 0x100) newcode[i + 1] = (byte) index;
          else {
            newcode[i] = NOP;
            newcode[i + 1] = NOP;
            LdcEntry ldc = new LdcEntry();
            ldc.where = i;
            ldc.index = index;
            ldc.next = ldcEntry;
            ldcEntry = ldc;
          }
          break;
        case INVOKEINTERFACE:
          copyConstPoolInfo(i + 1, code, srcCp, newcode, destCp, classnameMap);
          newcode[i + 3] = code[i + 3];
          newcode[i + 4] = code[i + 4];
          break;
        case INVOKEDYNAMIC:
          copyConstPoolInfo(i + 1, code, srcCp, newcode, destCp, classnameMap);
          newcode[i + 3] = 0;
          newcode[i + 4] = 0;
          break;
        case MULTIANEWARRAY:
          copyConstPoolInfo(i + 1, code, srcCp, newcode, destCp, classnameMap);
          newcode[i + 3] = code[i + 3];
          break;
        default:
          while (++i < i2) newcode[i] = code[i];

          break;
      }
    }

    return ldcEntry;
  }
 protected int copyData(int tag, int data) {
   if (tag == OBJECT) return srcPool.copy(data, destPool, classnames);
   else return data;
 }