// In ClassObfuscator publicvoidvisitProgramClass(ProgramClass programClass){ // Does this class still need a new name? newClassName = newClassName(programClass); ... String newPackagePrefix = newClassName != null ? ... : newPackagePrefix(ClassUtil.internalPackagePrefix(programClass.getName()));
// Come up with a new class name, numeric or ordinary. newClassName = newClassName != null && numericClassName ? ... : generateUniqueClassName(newPackagePrefix);
// In ClassRenamer publicvoidvisitClassConstant(Clazz clazz, ClassConstant classConstant){ // Update the Class entry if required. String newName = ClassObfuscator.newClassName(clazz); if (newName != null) { // Refer to a new Utf8 entry. classConstant.u2nameIndex = new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newName); } }
// In Obfuscator publicvoidexecute(ClassPool programClassPool, ClassPool libraryClassPool)throws IOException { ... // Update all references to these new names. programClassPool.classesAccept(new ClassReferenceFixer(false)); libraryClassPool.classesAccept(new ClassReferenceFixer(false)); ... }
直接看到ClassReferenceFixer的visitProgramClass():
// In ClassReferenceFixer publicvoidvisitProgramClass(ProgramClass programClass){ ... programClass.methodsAccept(this); ... }
methodAccept()會直接走到visitProgramMethod():
// In ClassReferenceFixer publicvoidvisitProgramMethod(ProgramClass programClass, ProgramMethod programMethod){ // Has the descriptor changed? String descriptor = programMethod.getDescriptor(programClass); String newDescriptor = newDescriptor(descriptor, programMethod.referencedClasses);
if (!descriptor.equals(newDescriptor)) { ConstantPoolEditor constantPoolEditor = new ConstantPoolEditor(programClass);
// In ClassReferenceFixer privatestatic String newDescriptor(String descriptor, Clazz[] referencedClasses){ ... // Unravel and reconstruct the class elements of the descriptor. DescriptorClassEnumeration descriptorClassEnumeration = new DescriptorClassEnumeration(descriptor);
StringBuffer newDescriptorBuffer = new StringBuffer(descriptor.length()); newDescriptorBuffer.append(descriptorClassEnumeration.nextFluff());
int index = 0; while (descriptorClassEnumeration.hasMoreClassNames()) { String className = descriptorClassEnumeration.nextClassName(); ... String fluff = descriptorClassEnumeration.nextFluff();