1 21 package proguard.obfuscate; 22 23 import proguard.classfile.*; 24 import proguard.classfile.attribute.*; 25 import proguard.classfile.constant.Constant; 26 import proguard.classfile.editor.ConstantPoolRemapper; 27 import proguard.classfile.instruction.*; 28 import proguard.classfile.visitor.*; 29 30 31 39 public class NameAndTypeShrinker implements ClassVisitor 40 { 41 private int[] constantIndexMap; 42 private ConstantPoolRemapper constantPoolRemapper = new ConstantPoolRemapper(); 43 44 45 47 public void visitProgramClass(ProgramClass programClass) 48 { 49 programClass.u2constantPoolCount = 52 shrinkConstantPool(programClass.constantPool, 53 programClass.u2constantPoolCount); 54 55 56 constantPoolRemapper.setConstantIndexMap(constantIndexMap); 58 constantPoolRemapper.visitProgramClass(programClass); 59 } 60 61 62 public void visitLibraryClass(LibraryClass libraryClass) 63 { 64 } 65 66 67 69 74 private int shrinkConstantPool(Constant[] constantPool, int length) 75 { 76 if (constantIndexMap == null || 78 constantIndexMap.length < length) 79 { 80 constantIndexMap = new int[length]; 81 } 82 83 int counter = 1; 84 boolean isUsed = false; 85 86 for (int index = 1; index < length; index++) 88 { 89 constantIndexMap[index] = counter; 90 91 Constant constant = constantPool[index]; 92 93 if (constant != null) 95 { 96 isUsed = constant.getTag() != ClassConstants.CONSTANT_NameAndType || 97 NameAndTypeUsageMarker.isUsed(constant); 98 } 99 100 if (isUsed) 101 { 102 constantPool[counter++] = constant; 103 } 104 } 105 106 for (int index = counter; index < length; index++) 108 { 109 constantPool[index] = null; 110 } 111 112 return counter; 113 } 114 } 115 | Popular Tags |