1 21 package proguard.obfuscate; 22 23 import proguard.classfile.*; 24 import proguard.classfile.constant.Constant; 25 import proguard.classfile.editor.ConstantPoolRemapper; 26 import proguard.classfile.visitor.ClassVisitor; 27 28 29 37 public class Utf8Shrinker implements ClassVisitor 38 { 39 private int[] constantIndexMap = new int[ClassConstants.TYPICAL_CONSTANT_POOL_SIZE]; 40 private ConstantPoolRemapper constantPoolRemapper = new ConstantPoolRemapper(); 41 42 43 45 public void visitProgramClass(ProgramClass programClass) 46 { 47 programClass.u2constantPoolCount = 50 shrinkConstantPool(programClass.constantPool, 51 programClass.u2constantPoolCount); 52 53 constantPoolRemapper.setConstantIndexMap(constantIndexMap); 55 constantPoolRemapper.visitProgramClass(programClass); 56 } 57 58 59 public void visitLibraryClass(LibraryClass libraryClass) 60 { 61 } 62 63 64 66 71 private int shrinkConstantPool(Constant[] constantPool, int length) 72 { 73 if (constantIndexMap.length < length) 75 { 76 constantIndexMap = new int[length]; 77 } 78 79 int counter = 1; 80 boolean isUsed = false; 81 82 for (int index = 1; index < length; index++) 84 { 85 constantIndexMap[index] = counter; 86 87 Constant constant = constantPool[index]; 88 89 if (constant != null) 91 { 92 isUsed = constant.getTag() != ClassConstants.CONSTANT_Utf8 || 93 Utf8UsageMarker.isUsed(constant); 94 } 95 96 if (isUsed) 97 { 98 constantPool[counter++] = constant; 99 } 100 } 101 102 for (int index = counter; index < length; index++) 104 { 105 constantPool[index] = null; 106 } 107 108 return counter; 109 } 110 } 111 | Popular Tags |