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 33 38 abstract public class ClassItemInfo implements ClassConstants 39 { 40 42 43 private int u2accessFlags; 45 private int u2nameIndex; 46 private int u2descriptorIndex; 47 protected int u2attributesCount; 48 protected AttrInfo attributes[]; 49 50 private ClassFile cf; 51 private boolean isSynthetic = false; 52 53 54 56 57 protected ClassItemInfo(ClassFile cf) {this.cf = cf;} 59 60 61 public boolean isSynthetic() {return isSynthetic;} 62 63 64 protected int getNameIndex() {return u2nameIndex;} 65 66 67 protected void setNameIndex(int index) {u2nameIndex = index;} 68 69 70 protected int getDescriptorIndex() {return u2descriptorIndex;} 71 72 73 protected void setDescriptorIndex(int index) {u2descriptorIndex = index;} 74 75 76 protected String getName() 77 { 78 return ((Utf8CpInfo)cf.getCpEntry(u2nameIndex)).getString(); 79 } 80 81 82 protected String getDescriptor() 83 { 84 return ((Utf8CpInfo)cf.getCpEntry(u2descriptorIndex)).getString(); 85 } 86 87 88 protected int getAccessFlags() 89 { 90 return u2accessFlags; 91 } 92 93 97 protected void trimAttrsExcept(String [] keepAttrs) 98 { 99 for (int i = 0; i < attributes.length; i++) 101 { 102 if (Tools.isInArray(attributes[i].getAttrName(), keepAttrs)) 103 { 104 attributes[i].trimAttrsExcept(keepAttrs); 105 } 106 else 107 { 108 attributes[i] = null; 109 } 110 } 111 112 AttrInfo[] left = new AttrInfo[attributes.length]; 114 int j = 0; 115 for (int i = 0; i < attributes.length; i++) 116 { 117 if (attributes[i] != null) 118 { 119 left[j++] = attributes[i]; 120 } 121 } 122 attributes = new AttrInfo[j]; 123 System.arraycopy(left, 0, attributes, 0, j); 124 u2attributesCount = j; 125 } 126 127 128 protected void markUtf8Refs(ConstantPool pool) 129 { 130 pool.incRefCount(u2nameIndex); 131 pool.incRefCount(u2descriptorIndex); 132 for (int i = 0; i < attributes.length; i++) 133 { 134 attributes[i].markUtf8Refs(pool); 135 } 136 } 137 138 139 protected void read(DataInput din) throws java.io.IOException 140 { 141 u2accessFlags = din.readUnsignedShort(); 142 u2nameIndex = din.readUnsignedShort(); 143 u2descriptorIndex = din.readUnsignedShort(); 144 u2attributesCount = din.readUnsignedShort(); 145 attributes = new AttrInfo[u2attributesCount]; 146 for (int i = 0; i < u2attributesCount; i++) 147 { 148 attributes[i] = AttrInfo.create(din, cf); 149 if (attributes[i].getAttrName().equals(ATTR_Synthetic)) 150 { 151 isSynthetic = true; 152 } 153 } 154 } 155 156 157 public void write(DataOutput dout) throws java.io.IOException 158 { 159 if (dout == null) throw new NullPointerException ("No output stream was provided."); 160 dout.writeShort(u2accessFlags); 161 dout.writeShort(u2nameIndex); 162 dout.writeShort(u2descriptorIndex); 163 dout.writeShort(u2attributesCount); 164 for (int i = 0; i < u2attributesCount; i++) 165 { 166 attributes[i].write(dout); 167 } 168 } 169 } 170 | Popular Tags |