本文整理汇总了Java中proguard.classfile.editor.ConstantPoolEditor类的典型用法代码示例。如果您正苦于以下问题:Java ConstantPoolEditor类的具体用法?Java ConstantPoolEditor怎么用?Java ConstantPoolEditor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConstantPoolEditor类属于proguard.classfile.editor包,在下文中一共展示了ConstantPoolEditor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addNewClassConstant
import proguard.classfile.editor.ConstantPoolEditor; //导入依赖的package包/类
/**
* Explicitly adds a new class constant for the given class in the given
* program class.
*/
private int addNewClassConstant(ProgramClass programClass,
String className,
Clazz referencedClass)
{
ConstantPoolEditor constantPoolEditor =
new ConstantPoolEditor(programClass);
int nameIndex =
constantPoolEditor.addUtf8Constant(className);
int classConstantIndex =
constantPoolEditor.addConstant(new ClassConstant(nameIndex,
referencedClass));
return classConstantIndex;
}
示例2: visitSignatureAttribute
import proguard.classfile.editor.ConstantPoolEditor; //导入依赖的package包/类
public void visitSignatureAttribute(Clazz clazz, Method method, SignatureAttribute signatureAttribute)
{
// Compute the new signature.
String signature = clazz.getString(signatureAttribute.u2signatureIndex);
String newSignature = shrinkDescriptor(method, signature);
// Update the signature.
signatureAttribute.u2signatureIndex =
new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newSignature);
// Update the referenced classes.
signatureAttribute.referencedClasses =
shrinkReferencedClasses(method,
signature,
signatureAttribute.referencedClasses);
}
示例3: createClassConstant
import proguard.classfile.editor.ConstantPoolEditor; //导入依赖的package包/类
/**
* Finds or creates a class constant for the given reference value, and
* returns its index in the constant pool.
*/
private int createClassConstant(ProgramClass programClass,
ReferenceValue referenceValue)
{
return new ConstantPoolEditor(programClass).addClassConstant(referenceValue.getType(),
referenceValue.getReferencedClass());
}
示例4: visitSignatureAttribute
import proguard.classfile.editor.ConstantPoolEditor; //导入依赖的package包/类
public void visitSignatureAttribute(Clazz clazz, Method method, SignatureAttribute signatureAttribute)
{
String descriptor = method.getDescriptor(clazz);
int descriptorIndex = descriptor.indexOf(ClassConstants.INTERNAL_METHOD_ARGUMENTS_CLOSE);
String signature = clazz.getString(signatureAttribute.u2signatureIndex);
int signatureIndex = signature.indexOf(ClassConstants.INTERNAL_METHOD_ARGUMENTS_CLOSE);
String newSignature = signature.substring(0, signatureIndex) +
descriptor.charAt(descriptorIndex - 1) +
signature.substring(signatureIndex);
// Update the signature.
signatureAttribute.u2signatureIndex =
new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newSignature);
}
示例5: visitProgramMember
import proguard.classfile.editor.ConstantPoolEditor; //导入依赖的package包/类
public void visitProgramMember(ProgramClass programClass,
ProgramMember programMember)
{
// Has the class member name changed?
String name = programMember.getName(programClass);
String newName = MemberObfuscator.newMemberName(programMember);
if (newName != null &&
!newName.equals(name))
{
programMember.u2nameIndex =
new ConstantPoolEditor(programClass).addUtf8Constant(newName);
}
}
示例6: visitClassConstant
import proguard.classfile.editor.ConstantPoolEditor; //导入依赖的package包/类
public void visitClassConstant(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);
}
}
示例7: visitSignatureAttribute
import proguard.classfile.editor.ConstantPoolEditor; //导入依赖的package包/类
public void visitSignatureAttribute(Clazz clazz, Method method, SignatureAttribute signatureAttribute)
{
String descriptor = method.getDescriptor(clazz);
int descriptorIndex = descriptor.indexOf(ClassConstants.METHOD_ARGUMENTS_CLOSE);
String signature = signatureAttribute.getSignature(clazz);
int signatureIndex = signature.indexOf(ClassConstants.METHOD_ARGUMENTS_CLOSE);
String newSignature = signature.substring(0, signatureIndex) +
descriptor.charAt(descriptorIndex - 1) +
signature.substring(signatureIndex);
// Update the signature.
signatureAttribute.u2signatureIndex =
new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newSignature);
}
示例8: visitSignatureAttribute
import proguard.classfile.editor.ConstantPoolEditor; //导入依赖的package包/类
public void visitSignatureAttribute(Clazz clazz, Method method, SignatureAttribute signatureAttribute)
{
if (DEBUG)
{
System.out.println(" ["+signatureAttribute.getSignature(clazz)+"]");
}
// Compute the new signature.
String signature = signatureAttribute.getSignature(clazz);
String newSignature = shrinkDescriptor(method, signature);
if (!newSignature.equals(signature))
{
// Update the signature.
signatureAttribute.u2signatureIndex =
new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newSignature);
// Update the referenced classes.
signatureAttribute.referencedClasses =
shrinkReferencedClasses(method,
signature,
signatureAttribute.referencedClasses);
if (DEBUG)
{
System.out.println(" -> ["+newSignature+"]");
}
}
}
示例9: visitProgramMember
import proguard.classfile.editor.ConstantPoolEditor; //导入依赖的package包/类
public void visitProgramMember(ProgramClass programClass,
ProgramMember programMember)
{
// Has the class member name changed?
String name = programMember.getName(programClass);
String newName = MemberObfuscator.newMemberName(programMember);
if (newName != null &&
!newName.equals(name))
{
programMember.u2nameIndex =
new ConstantPoolEditor(programClass).addUtf8Constant(newName);
}
}
示例10: replaceIntegerPushInstruction
import proguard.classfile.editor.ConstantPoolEditor; //导入依赖的package包/类
/**
* Replaces the integer pushing instruction at the given offset by a simpler
* push instruction, if possible.
*/
private void replaceIntegerPushInstruction(Clazz clazz,
int offset,
Instruction instruction,
int maxVariableIndex)
{
Value pushedValue = partialEvaluator.getStackAfter(offset).getTop(0);
if (pushedValue.isParticular())
{
int value = pushedValue.integerValue().value();
if (value << 16 >> 16 == value)
{
replaceConstantPushInstruction(clazz,
offset,
instruction,
InstructionConstants.OP_SIPUSH,
value);
}
else
{
ConstantPoolEditor constantPoolEditor =
new ConstantPoolEditor((ProgramClass)clazz);
Instruction replacementInstruction =
new ConstantInstruction(InstructionConstants.OP_LDC,
constantPoolEditor.addIntegerConstant(value)).shrink();
replaceInstruction(clazz, offset, instruction, replacementInstruction);
}
}
else if (pushedValue.isSpecific())
{
TracedVariables variables = partialEvaluator.getVariablesBefore(offset);
for (int variableIndex = 0; variableIndex < maxVariableIndex; variableIndex++)
{
if (pushedValue.equals(variables.load(variableIndex)))
{
replaceVariablePushInstruction(clazz,
offset,
instruction,
InstructionConstants.OP_ILOAD,
variableIndex);
}
}
}
}
示例11: replaceLongPushInstruction
import proguard.classfile.editor.ConstantPoolEditor; //导入依赖的package包/类
/**
* Replaces the long pushing instruction at the given offset by a simpler
* push instruction, if possible.
*/
private void replaceLongPushInstruction(Clazz clazz,
int offset,
Instruction instruction,
int maxVariableIndex)
{
Value pushedValue = partialEvaluator.getStackAfter(offset).getTop(0);
if (pushedValue.isParticular())
{
long value = pushedValue.longValue().value();
if (value == 0L ||
value == 1L)
{
replaceConstantPushInstruction(clazz,
offset,
instruction,
InstructionConstants.OP_LCONST_0,
(int)value);
}
else
{
ConstantPoolEditor constantPoolEditor =
new ConstantPoolEditor((ProgramClass)clazz);
Instruction replacementInstruction =
new ConstantInstruction(InstructionConstants.OP_LDC2_W,
constantPoolEditor.addLongConstant(value)).shrink();
replaceInstruction(clazz, offset, instruction, replacementInstruction);
}
}
else if (pushedValue.isSpecific())
{
TracedVariables variables = partialEvaluator.getVariablesBefore(offset);
for (int variableIndex = 0; variableIndex < maxVariableIndex; variableIndex++)
{
if (pushedValue.equals(variables.load(variableIndex)))
{
replaceVariablePushInstruction(clazz,
offset,
instruction,
InstructionConstants.OP_LLOAD,
variableIndex);
}
}
}
}
示例12: replaceFloatPushInstruction
import proguard.classfile.editor.ConstantPoolEditor; //导入依赖的package包/类
/**
* Replaces the float pushing instruction at the given offset by a simpler
* push instruction, if possible.
*/
private void replaceFloatPushInstruction(Clazz clazz,
int offset,
Instruction instruction,
int maxVariableIndex)
{
Value pushedValue = partialEvaluator.getStackAfter(offset).getTop(0);
if (pushedValue.isParticular())
{
// Make sure to distinguish between +0.0 and -0.0.
float value = pushedValue.floatValue().value();
if (value == 0.0f && Float.floatToIntBits(value) == POS_ZERO_FLOAT_BITS ||
value == 1.0f ||
value == 2.0f)
{
replaceConstantPushInstruction(clazz,
offset,
instruction,
InstructionConstants.OP_FCONST_0,
(int)value);
}
else
{
ConstantPoolEditor constantPoolEditor =
new ConstantPoolEditor((ProgramClass)clazz);
Instruction replacementInstruction =
new ConstantInstruction(InstructionConstants.OP_LDC,
constantPoolEditor.addFloatConstant(value)).shrink();
replaceInstruction(clazz, offset, instruction, replacementInstruction);
}
}
else if (pushedValue.isSpecific())
{
TracedVariables variables = partialEvaluator.getVariablesBefore(offset);
for (int variableIndex = 0; variableIndex < maxVariableIndex; variableIndex++)
{
if (pushedValue.equals(variables.load(variableIndex)))
{
replaceVariablePushInstruction(clazz,
offset,
instruction,
InstructionConstants.OP_FLOAD,
variableIndex);
}
}
}
}
示例13: replaceDoublePushInstruction
import proguard.classfile.editor.ConstantPoolEditor; //导入依赖的package包/类
/**
* Replaces the double pushing instruction at the given offset by a simpler
* push instruction, if possible.
*/
private void replaceDoublePushInstruction(Clazz clazz,
int offset,
Instruction instruction,
int maxVariableIndex)
{
Value pushedValue = partialEvaluator.getStackAfter(offset).getTop(0);
if (pushedValue.isParticular())
{
// Make sure to distinguish between +0.0 and -0.0.
double value = pushedValue.doubleValue().value();
if (value == 0.0 && Double.doubleToLongBits(value) == POS_ZERO_DOUBLE_BITS ||
value == 1.0)
{
replaceConstantPushInstruction(clazz,
offset,
instruction,
InstructionConstants.OP_DCONST_0,
(int)value);
}
else
{
ConstantPoolEditor constantPoolEditor =
new ConstantPoolEditor((ProgramClass)clazz);
Instruction replacementInstruction =
new ConstantInstruction(InstructionConstants.OP_LDC2_W,
constantPoolEditor.addDoubleConstant(value)).shrink();
replaceInstruction(clazz, offset, instruction, replacementInstruction);
}
}
else if (pushedValue.isSpecific())
{
TracedVariables variables = partialEvaluator.getVariablesBefore(offset);
for (int variableIndex = 0; variableIndex < maxVariableIndex; variableIndex++)
{
if (pushedValue.equals(variables.load(variableIndex)))
{
replaceVariablePushInstruction(clazz,
offset,
instruction,
InstructionConstants.OP_DLOAD,
variableIndex);
}
}
}
}
示例14: visitProgramMethod
import proguard.classfile.editor.ConstantPoolEditor; //导入依赖的package包/类
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
// Is it a class instance initializer?
String name = programMethod.getName(programClass);
if (name.equals(ClassConstants.INTERNAL_METHOD_NAME_INIT))
{
// Is there already another initializer with the same descriptor?
String descriptor = programMethod.getDescriptor(programClass);
Method similarMethod = programClass.findMethod(name, descriptor);
if (!programMethod.equals(similarMethod))
{
// Should this initializer be preserved?
if (!KeepMarker.isKept(programMethod))
{
// Fix the other initializer.
programMethod = (ProgramMethod)similarMethod;
}
int index = descriptor.indexOf(ClassConstants.INTERNAL_METHOD_ARGUMENTS_CLOSE);
// Try to find a new, unique descriptor.
for (int typeIndex = 0; typeIndex < TYPES.length; typeIndex++)
{
String newDescriptor =
descriptor.substring(0, index) +
TYPES[typeIndex] +
descriptor.substring(index);
// Is the new initializer descriptor unique?
if (programClass.findMethod(name, newDescriptor) == null)
{
if (DEBUG)
{
System.out.println("DuplicateInitializerFixer:");
System.out.println(" ["+programClass.getName()+"."+name+descriptor+"] ("+ClassUtil.externalClassAccessFlags(programMethod.getAccessFlags())+") -> ["+newDescriptor+"]");
}
// Update the descriptor.
programMethod.u2descriptorIndex =
new ConstantPoolEditor(programClass).addUtf8Constant(newDescriptor);
// Fix the local variable frame size, the method
// signature, and the parameter annotations, if
// necessary.
programMethod.attributesAccept(programClass,
this);
// Visit the initializer, if required.
if (extraFixedInitializerVisitor != null)
{
extraFixedInitializerVisitor.visitProgramMethod(programClass, programMethod);
}
// We're done with this constructor.
return;
}
}
throw new IllegalStateException("Can't find unique constructor descriptor for ["+
programClass.getName()+"."+
programMethod.getName(programClass)+
programMethod.getDescriptor(programClass)+"]");
}
}
}
示例15: visitProgramMethod
import proguard.classfile.editor.ConstantPoolEditor; //导入依赖的package包/类
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
// Update the descriptor if it has any unused parameters.
String descriptor = programMethod.getDescriptor(programClass);
String newDescriptor = shrinkDescriptor(programMethod, descriptor);
if (!descriptor.equals(newDescriptor))
{
// Shrink the signature and parameter annotations.
programMethod.attributesAccept(programClass, this);
String name = programMethod.getName(programClass);
String newName = name;
// Append a code, if the method isn't a class instance initializer.
if (!name.equals(ClassConstants.INTERNAL_METHOD_NAME_INIT))
{
newName += ClassConstants.SPECIAL_MEMBER_SEPARATOR + Long.toHexString(Math.abs((descriptor).hashCode()));
}
if (DEBUG)
{
System.out.println("MethodDescriptorShrinker:");
System.out.println(" Class file = "+programClass.getName());
System.out.println(" Method name = "+name);
System.out.println(" -> "+newName);
System.out.println(" Method descriptor = "+descriptor);
System.out.println(" -> "+newDescriptor);
}
ConstantPoolEditor constantPoolEditor =
new ConstantPoolEditor(programClass);
// Update the name, if necessary.
if (!newName.equals(name))
{
programMethod.u2nameIndex =
constantPoolEditor.addUtf8Constant(newName);
}
// Update the referenced classes.
programMethod.referencedClasses =
shrinkReferencedClasses(programMethod,
descriptor,
programMethod.referencedClasses);
// Finally, update the descriptor itself.
programMethod.u2descriptorIndex =
constantPoolEditor.addUtf8Constant(newDescriptor);
// Visit the method, if required.
if (extraMemberVisitor != null)
{
extraMemberVisitor.visitProgramMethod(programClass, programMethod);
}
}
}