/** * */ package org.apache.bcel.classfile; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import org.apache.bcel.Constants; import org.apache.bcel.SignatureConstants; /** * @author dorina * */ public class ProofAttribute extends Attribute { /** * */ private static final long serialVersionUID = 4438673227269627128L; byte []proof; public ProofAttribute(int name_index, int length, byte[] proof, ConstantPool cp) { super(Constants.ATTR_PROOF_MAP, name_index,length, cp); this.proof = proof; } public ProofAttribute(int name_index, int length, DataInputStream str, ConstantPool cp) throws IOException { this(name_index, length, (byte [])null, cp); if( length > 0) { proof = new byte[length]; for(int i = 0; i < length; i++) { proof[i] = str.readByte(); } } } /* (non-Javadoc) * @see org.apache.bcel.classfile.Attribute#accept(org.apache.bcel.classfile.Visitor) */ public void accept(Visitor v) { // TODO Auto-generated method stub } /* (non-Javadoc) * @see org.apache.bcel.classfile.Attribute#copy(org.apache.bcel.classfile.ConstantPool) */ public Attribute copy(ConstantPool constant_pool) { ProofAttribute copy = (ProofAttribute)clone(); System.arraycopy(proof,0,copy.proof,0,proof.length); return copy; } public final void dump(DataOutputStream file) throws IOException { super.dump(file); // FIXME: sort the output ? for(int i = 0; i < proof.length; i++) { file.writeByte(proof[i]); } } private int index; public String toString() { for(int ll = 0 ; ll < this.proof.length; ll++) System.out.print(proof[ll]+" "); System.out.println(""); StringBuffer buf = new StringBuffer("ProofAttribute("); index = 0; //read codification byte codification = proof[index++]; buf.append("codification = "+codification+", "); //System.out.println("codification = "+codification); //read length of jvmTypes int jvmTypes_length = SignatureConstants.readInt(proof, index, SignatureConstants.LABEL_BYTECODE_SIZE); index += SignatureConstants.LABEL_BYTECODE_SIZE; buf.append("jvmTypes_length = "+jvmTypes_length +", "); //read proof_table_length int proof_length = SignatureConstants.readInt(proof, index, SignatureConstants.LABEL_BYTECODE_SIZE); index += SignatureConstants.LABEL_BYTECODE_SIZE; buf.append("no of proofs = "+proof_length+", "); //System.out.println("no of proofs = "+proof_length+", "); //read proof_table for(int i=0; i < proof_length; i++) { buf.append("\n[ "); //read label of bytecode int label = SignatureConstants.readInt(proof, index, SignatureConstants.LABEL_BYTECODE_SIZE); index += SignatureConstants.LABEL_BYTECODE_SIZE; int size = SignatureConstants.readInt(proof, index, SignatureConstants.TOTAL_LENGTH_SIZE); index += SignatureConstants.TOTAL_LENGTH_SIZE; buf.append("no of bytes to follow:"+size); buf.append(" label = "+label); //System.out.println("label = "+label); //read size of link table size = SignatureConstants.readInt(proof, index, SignatureConstants.TOTAL_LENGTH_SIZE); index += SignatureConstants.TOTAL_LENGTH_SIZE; //read link_table byte[] tmp = new byte[size]; System.arraycopy(proof, index, tmp, 0, size); buf.append(LinkAttribute.print(" LinkTable ", tmp)); index += size; //read stack //read size of stack size = SignatureConstants.readInt(proof, index, SignatureConstants.TOTAL_LENGTH_SIZE); index += SignatureConstants.TOTAL_LENGTH_SIZE; buf.append(" size of stack "+size); buf.append(" Stack "+readMultiObjectsTable(codification)); //read size of localvar size = SignatureConstants.readInt(proof, index, SignatureConstants.TOTAL_LENGTH_SIZE); index += SignatureConstants.TOTAL_LENGTH_SIZE; buf.append(" size of localvar "+size); //read local_variables buf.append(" LocalVariables "+readMultiObjectsTable(codification)); //LinkAttribute la = new LinkAttribute() buf.append(" ]"); } buf.append(')'); return buf.toString(); } private String readMultiObjectsTable(byte codification) { StringBuffer buf = new StringBuffer("["); //read number of multiObjects int size = SignatureConstants.readInt(proof, index, SignatureConstants.TOTAL_LENGTH_SIZE); index += SignatureConstants.TOTAL_LENGTH_SIZE; //System.out.println("multiobject size = "+size); for(int j = 0; j < size; j++) { //read size of multiobject int mo_size = SignatureConstants.readInt(proof, index, SignatureConstants.MULTIOBJECT_LENGTH_SIZE); index += SignatureConstants.MULTIOBJECT_LENGTH_SIZE; //System.out.println("--mo["+j+"] size = "+mo_size); buf.append("("); for(int k = 0; k < mo_size; k++) { //read jvmtype int jvmtype = SignatureConstants.readInt(proof, index, 1); index ++; int part; if(codification == SignatureConstants.CODIF_6B) { part = jvmtype & 0x03; jvmtype = jvmtype >> 2; } else { part = SignatureConstants.readInt(proof, index, 1); index ++; } buf.append(jvmtype+":"+part); if(k < mo_size-1) buf.append(", "); } buf.append(")"); if(j < size-1) buf.append(", "); } buf.append("]"); return buf.toString(); } }