1 26 package com.yworks.yguard.obf.classfile; 27 28 import java.io.*; 29 import java.util.*; 30 import com.yworks.yguard.obf.*; 31 32 37 public class CodeAttrInfo extends AttrInfo 38 { 39 public static final int CONSTANT_FIELD_SIZE = 12; 41 42 43 private int u2maxStack; 45 private int u2maxLocals; 46 private int u4codeLength; 47 private byte[] code; 48 private int u2exceptionTableLength; 49 private ExceptionInfo[] exceptionTable; 50 protected int u2attributesCount; 51 protected AttrInfo[] attributes; 52 53 54 56 57 protected CodeAttrInfo(ClassFile cf, int attrNameIndex, int attrLength) 59 { 60 super(cf, attrNameIndex, attrLength); 61 } 62 63 64 protected int getAttrInfoLength() 65 { 66 int length = CONSTANT_FIELD_SIZE + u4codeLength + 67 u2exceptionTableLength * ExceptionInfo.CONSTANT_FIELD_SIZE; 68 for (int i = 0; i < u2attributesCount; i++) 69 { 70 length += AttrInfo.CONSTANT_FIELD_SIZE + attributes[i].getAttrInfoLength(); 71 } 72 return length; 73 } 74 75 76 protected String getAttrName() 77 { 78 return ATTR_Code; 79 } 80 81 85 protected void trimAttrsExcept(String [] keepAttrs) 86 { 87 for (int i = 0; i < attributes.length; i++) 89 { 90 if (Tools.isInArray(attributes[i].getAttrName(), keepAttrs)) 91 { 92 attributes[i].trimAttrsExcept(keepAttrs); 93 } 94 else 95 { 96 attributes[i] = null; 97 } 98 } 99 100 AttrInfo[] left = new AttrInfo[attributes.length]; 102 int j = 0; 103 for (int i = 0; i < attributes.length; i++) 104 { 105 if (attributes[i] != null) 106 { 107 left[j++] = attributes[i]; 108 } 109 } 110 attributes = new AttrInfo[j]; 111 System.arraycopy(left, 0, attributes, 0, j); 112 u2attributesCount = j; 113 } 114 115 116 protected void markUtf8RefsInInfo(ConstantPool pool) 117 { 118 for (int i = 0; i < attributes.length; i++) 119 { 120 attributes[i].markUtf8Refs(pool); 121 } 122 } 123 124 125 protected void readInfo(DataInput din) throws java.io.IOException 126 { 127 u2maxStack = din.readUnsignedShort(); 128 u2maxLocals = din.readUnsignedShort(); 129 u4codeLength = din.readInt(); 130 code = new byte[u4codeLength]; 131 din.readFully(code); 132 u2exceptionTableLength = din.readUnsignedShort(); 133 exceptionTable = new ExceptionInfo[u2exceptionTableLength]; 134 for (int i = 0; i < u2exceptionTableLength; i++) 135 { 136 exceptionTable[i] = ExceptionInfo.create(din); 137 } 138 u2attributesCount = din.readUnsignedShort(); 139 attributes = new AttrInfo[u2attributesCount]; 140 for (int i = 0; i < u2attributesCount; i++) 141 { 142 attributes[i] = AttrInfo.create(din, owner); 143 } 144 } 145 146 147 public void writeInfo(DataOutput dout) throws java.io.IOException 148 { 149 dout.writeShort(u2maxStack); 150 dout.writeShort(u2maxLocals); 151 dout.writeInt(u4codeLength); 152 dout.write(code); 153 dout.writeShort(u2exceptionTableLength); 154 for (int i = 0; i < u2exceptionTableLength; i++) 155 { 156 exceptionTable[i].write(dout); 157 } 158 dout.writeShort(u2attributesCount); 159 for (int i = 0; i < u2attributesCount; i++) 160 { 161 attributes[i].write(dout); 162 } 163 } 164 } 165 166 | Popular Tags |