⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 constantpoolremapper.java

📁 j2me 混淆包,用于混淆j2me的原代码用的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* $Id: ConstantPoolRemapper.java,v 1.9 2004/11/20 15:41:24 eric Exp $ * * ProGuard -- shrinking, optimization, and obfuscation of Java class files. * * Copyright (c) 2002-2004 Eric Lafortune (eric@graphics.cornell.edu) * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package proguard.classfile.editor;import proguard.classfile.*;import proguard.classfile.attribute.*;import proguard.classfile.attribute.annotation.*;import proguard.classfile.instruction.*;import proguard.classfile.visitor.*;/** * This ClassFileVisitor remaps all possible references to constant pool entries * of the classes that it visits, based on a given index map. It is assumed that * the constant pool entries themselves have already been remapped. * * @author Eric Lafortune */public class ConstantPoolRemapper  implements ClassFileVisitor,             CpInfoVisitor,             MemberInfoVisitor,             AttrInfoVisitor,             InstructionVisitor,             InnerClassesInfoVisitor,             ExceptionInfoVisitor,             LocalVariableInfoVisitor,             LocalVariableTypeInfoVisitor,             AnnotationVisitor,             ElementValueVisitor{    private CodeAttrInfoEditor codeAttrInfoEditor;    private int[] cpIndexMap;    /**     * Creates a new ConstantPoolRemapper.     * @param codeLength an estimate of the maximum length of all the code that     *                   will be edited.     */    public ConstantPoolRemapper(int codeLength)    {        codeAttrInfoEditor = new CodeAttrInfoEditor(codeLength);    }    /**     * Sets the given mapping of old constant pool entry indexes to their new     * indexes.     */    public void setCpIndexMap(int[] cpIndexMap)    {        this.cpIndexMap = cpIndexMap;    }    // Implementations for ClassFileVisitor.    public void visitProgramClassFile(ProgramClassFile programClassFile)    {        // Remap the local constant pool references.        programClassFile.u2thisClass  = remapCpIndex(programClassFile.u2thisClass);        programClassFile.u2superClass = remapCpIndex(programClassFile.u2superClass);        remapCpIndexArray(programClassFile.u2interfaces,                          programClassFile.u2interfacesCount);        // Remap the references of the contant pool entries themselves.        programClassFile.constantPoolEntriesAccept(this);        // Remap the references in all fields, methods, and attributes.        programClassFile.fieldsAccept(this);        programClassFile.methodsAccept(this);        programClassFile.attributesAccept(this);    }    public void visitLibraryClassFile(LibraryClassFile libraryClassFile)    {    }    // Implementations for CpInfoVisitor.    public void visitClassCpInfo(ClassFile classFile, ClassCpInfo classCpInfo)    {        classCpInfo.u2nameIndex =            remapCpIndex(classCpInfo.u2nameIndex);    }    public void visitDoubleCpInfo(ClassFile classFile, DoubleCpInfo doubleCpInfo)    {        // Nothing to do.    }    public void visitFieldrefCpInfo(ClassFile classFile, FieldrefCpInfo fieldrefCpInfo)    {        fieldrefCpInfo.u2classIndex =            remapCpIndex(fieldrefCpInfo.u2classIndex);        fieldrefCpInfo.u2nameAndTypeIndex =            remapCpIndex(fieldrefCpInfo.u2nameAndTypeIndex);    }    public void visitFloatCpInfo(ClassFile classFile, FloatCpInfo floatCpInfo)    {        // Nothing to do.    }    public void visitIntegerCpInfo(ClassFile classFile, IntegerCpInfo integerCpInfo)    {        // Nothing to do.    }    public void visitInterfaceMethodrefCpInfo(ClassFile classFile, InterfaceMethodrefCpInfo interfaceMethodrefCpInfo)    {        interfaceMethodrefCpInfo.u2classIndex =            remapCpIndex(interfaceMethodrefCpInfo.u2classIndex);        interfaceMethodrefCpInfo.u2nameAndTypeIndex =            remapCpIndex(interfaceMethodrefCpInfo.u2nameAndTypeIndex);    }    public void visitLongCpInfo(ClassFile classFile, LongCpInfo longCpInfo)    {        // Nothing to do.    }    public void visitMethodrefCpInfo(ClassFile classFile, MethodrefCpInfo methodrefCpInfo)    {        methodrefCpInfo.u2classIndex =            remapCpIndex(methodrefCpInfo.u2classIndex);        methodrefCpInfo.u2nameAndTypeIndex =            remapCpIndex(methodrefCpInfo.u2nameAndTypeIndex);    }    public void visitNameAndTypeCpInfo(ClassFile classFile, NameAndTypeCpInfo nameAndTypeCpInfo)    {        nameAndTypeCpInfo.u2nameIndex =            remapCpIndex(nameAndTypeCpInfo.u2nameIndex);        nameAndTypeCpInfo.u2descriptorIndex =            remapCpIndex(nameAndTypeCpInfo.u2descriptorIndex);    }    public void visitStringCpInfo(ClassFile classFile, StringCpInfo stringCpInfo)    {        stringCpInfo.u2stringIndex =            remapCpIndex(stringCpInfo.u2stringIndex);    }    public void visitUtf8CpInfo(ClassFile classFile, Utf8CpInfo utf8CpInfo)    {        // Nothing to do.    }    // Implementations for MemberInfoVisitor.    public void visitProgramFieldInfo(ProgramClassFile programClassFile, ProgramFieldInfo programFieldInfo)    {        visitMemberInfo(programClassFile, programFieldInfo);    }    public void visitProgramMethodInfo(ProgramClassFile programClassFile, ProgramMethodInfo programMethodInfo)    {        visitMemberInfo(programClassFile, programMethodInfo);    }    private void visitMemberInfo(ProgramClassFile programClassFile, ProgramMemberInfo programMemberInfo)    {        // Remap the local constant pool references.        programMemberInfo.u2nameIndex =            remapCpIndex(programMemberInfo.u2nameIndex);        programMemberInfo.u2descriptorIndex =            remapCpIndex(programMemberInfo.u2descriptorIndex);        // Remap the constant pool references of the remaining attributes.        programMemberInfo.attributesAccept(programClassFile, this);    }    public void visitLibraryFieldInfo(LibraryClassFile libraryClassFile, LibraryFieldInfo libraryFieldInfo)    {        // Library class files are left unchanged.    }    public void visitLibraryMethodInfo(LibraryClassFile libraryClassFile, LibraryMethodInfo libraryMethodInfo)    {        // Library class files are left unchanged.    }    // Implementations for AttrInfoVisitor.    public void visitUnknownAttrInfo(ClassFile classFile, UnknownAttrInfo unknownAttrInfo)    {        unknownAttrInfo.u2attrNameIndex =            remapCpIndex(unknownAttrInfo.u2attrNameIndex);        // There's not much else we can do with unknown attributes.    }    public void visitInnerClassesAttrInfo(ClassFile classFile, InnerClassesAttrInfo innerClassesAttrInfo)    {        innerClassesAttrInfo.u2attrNameIndex =            remapCpIndex(innerClassesAttrInfo.u2attrNameIndex);        // Remap the constant pool references of the inner classes.        innerClassesAttrInfo.innerClassEntriesAccept(classFile, this);    }    public void visitEnclosingMethodAttrInfo(ClassFile classFile, EnclosingMethodAttrInfo enclosingMethodAttrInfo)    {        enclosingMethodAttrInfo.u2attrNameIndex =            remapCpIndex(enclosingMethodAttrInfo.u2attrNameIndex);        enclosingMethodAttrInfo.u2classIndex =            remapCpIndex(enclosingMethodAttrInfo.u2classIndex);        enclosingMethodAttrInfo.u2nameAndTypeIndex =            remapCpIndex(enclosingMethodAttrInfo.u2nameAndTypeIndex);    }    public void visitConstantValueAttrInfo(ClassFile classFile, FieldInfo fieldInfo, ConstantValueAttrInfo constantValueAttrInfo)    {        constantValueAttrInfo.u2attrNameIndex =            remapCpIndex(constantValueAttrInfo.u2attrNameIndex);        constantValueAttrInfo.u2constantValueIndex =            remapCpIndex(constantValueAttrInfo.u2constantValueIndex);    }    public void visitExceptionsAttrInfo(ClassFile classFile, MethodInfo methodInfo, ExceptionsAttrInfo exceptionsAttrInfo)    {        exceptionsAttrInfo.u2attrNameIndex =            remapCpIndex(exceptionsAttrInfo.u2attrNameIndex);        // Remap the constant pool references of the exceptions.        remapCpIndexArray(exceptionsAttrInfo.u2exceptionIndexTable,                          exceptionsAttrInfo.u2numberOfExceptions);    }    public void visitCodeAttrInfo(ClassFile classFile, MethodInfo methodInfo, CodeAttrInfo codeAttrInfo)    {        codeAttrInfo.u2attrNameIndex =            remapCpIndex(codeAttrInfo.u2attrNameIndex);        // Initially, the code attribute editor doesn't contain any changes.        codeAttrInfoEditor.reset(codeAttrInfo.u4codeLength);        // Remap the constant pool references of the instructions.        codeAttrInfo.instructionsAccept(classFile, methodInfo, this);        // Apply the code atribute editor. It will only contain any changes if        // the code length is changing at any point.        codeAttrInfoEditor.visitCodeAttrInfo(classFile, methodInfo, codeAttrInfo);        // Remap the constant pool references of the exceptions and attributes.        codeAttrInfo.exceptionsAccept(classFile, methodInfo, this);        codeAttrInfo.attributesAccept(classFile, methodInfo, this);    }    public void visitLineNumberTableAttrInfo(ClassFile classFile, MethodInfo methodInfo, CodeAttrInfo codeAttrInfo, LineNumberTableAttrInfo lineNumberTableAttrInfo)    {        lineNumberTableAttrInfo.u2attrNameIndex =

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -