proguard.classfile.editor
Class CodeAttributeEditor

java.lang.Object
  extended by proguard.classfile.util.SimplifiedVisitor
      extended by proguard.classfile.editor.CodeAttributeEditor
All Implemented Interfaces:
StackMapFrameVisitor, VerificationTypeVisitor, AttributeVisitor, ExceptionInfoVisitor, LineNumberInfoVisitor, LocalVariableInfoVisitor, LocalVariableTypeInfoVisitor, InstructionVisitor

public class CodeAttributeEditor
extends SimplifiedVisitor
implements AttributeVisitor, InstructionVisitor, ExceptionInfoVisitor, StackMapFrameVisitor, VerificationTypeVisitor, LineNumberInfoVisitor, LocalVariableInfoVisitor, LocalVariableTypeInfoVisitor

This AttributeVisitor accumulates specified changes to code, and then applies these accumulated changes to the code attributes that it visits.


Field Summary
 boolean[] deleted
           
 Instruction[] postInsertions
           
 Instruction[] preInsertions
           
 Instruction[] replacements
           
 
Constructor Summary
CodeAttributeEditor()
           
CodeAttributeEditor(boolean updateFrameSizes)
           
 
Method Summary
 void deleteInstruction(int instructionOffset)
          Remembers to delete the instruction at the given offset.
 void insertAfterInstruction(int instructionOffset, Instruction instruction)
          Remembers to place the given instruction right after the instruction at the given offset.
 void insertAfterInstruction(int instructionOffset, Instruction[] instructions)
          Remembers to place the given instructions right after the instruction at the given offset.
 void insertBeforeInstruction(int instructionOffset, Instruction instruction)
          Remembers to place the given instruction right before the instruction at the given offset.
 void insertBeforeInstruction(int instructionOffset, Instruction[] instructions)
          Remembers to place the given instructions right before the instruction at the given offset.
 boolean isModified(int instructionOffset)
          Returns whether the instruction at the given offset has been modified in any way.
 void replaceInstruction(int instructionOffset, Instruction instruction)
          Remembers to replace the instruction at the given offset by the given instruction.
 void replaceInstruction(int instructionOffset, Instruction[] instructions)
          Remembers to replace the instruction at the given offset by the given instructions.
 void reset(int codeLength)
          Resets the accumulated code changes.
 void undeleteInstruction(int instructionOffset)
          Remembers not to delete the instruction at the given offset.
 void visitAnyAttribute(Clazz clazz, Attribute attribute)
          Visit any type of attribute.
 void visitAnyStackMapFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, StackMapFrame stackMapFrame)
          Visits any type of VerificationType.
 void visitAnyVerificationType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VerificationType verificationType)
          Visits any type of VerificationType.
 void visitBranchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, BranchInstruction branchInstruction)
           
 void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
           
 void visitCodeAttribute0(Clazz clazz, Method method, CodeAttribute codeAttribute)
           
 void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
           
 void visitExceptionInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, ExceptionInfo exceptionInfo)
           
 void visitFullFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, FullFrame fullFrame)
           
 void visitLineNumberInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberInfo lineNumberInfo)
           
 void visitLineNumberTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberTableAttribute lineNumberTableAttribute)
           
 void visitLocalVariableInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableInfo localVariableInfo)
           
 void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute)
           
 void visitLocalVariableTypeInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeInfo localVariableTypeInfo)
           
 void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute)
           
 void visitLookUpSwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LookUpSwitchInstruction lookUpSwitchInstruction)
           
 void visitMoreZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, MoreZeroFrame moreZeroFrame)
           
 void visitSameOneFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SameOneFrame sameOneFrame)
           
 void visitSimpleInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SimpleInstruction simpleInstruction)
           
 void visitStackMapAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapAttribute stackMapAttribute)
           
 void visitStackMapTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapTableAttribute stackMapTableAttribute)
           
 void visitTableSwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, TableSwitchInstruction tableSwitchInstruction)
           
 void visitUninitializedType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, UninitializedType uninitializedType)
           
 void visitVariableInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VariableInstruction variableInstruction)
           
 
Methods inherited from class proguard.classfile.util.SimplifiedVisitor
visitAnnotation, visitAnnotation, visitAnnotation, visitAnnotation, visitAnnotation, visitAnnotationDefaultAttribute, visitAnnotationElementValue, visitAnyAnnotationsAttribute, visitAnyClass, visitAnyConstant, visitAnyElementValue, visitAnyInstruction, visitAnyMember, visitAnyMethodrefConstant, visitAnyParameterAnnotationsAttribute, visitAnyRefConstant, visitAnySwitchInstruction, visitArrayElementValue, visitClassConstant, visitClassElementValue, visitConstantElementValue, visitConstantValueAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitDoubleConstant, visitDoubleType, visitEnclosingMethodAttribute, visitEnumConstantElementValue, visitExceptionsAttribute, visitFieldrefConstant, visitFloatConstant, visitFloatType, visitInnerClassesAttribute, visitIntegerConstant, visitIntegerType, visitInterfaceMethodrefConstant, visitLessZeroFrame, visitLibraryClass, visitLibraryField, visitLibraryMember, visitLibraryMethod, visitLongConstant, visitLongType, visitMethodrefConstant, visitNameAndTypeConstant, visitNullType, visitObjectType, visitProgramClass, visitProgramField, visitProgramMember, visitProgramMethod, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleParameterAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleParameterAnnotationsAttribute, visitSameZeroFrame, visitSignatureAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSourceDirAttribute, visitSourceFileAttribute, visitStackDoubleType, visitStackFloatType, visitStackIntegerType, visitStackLongType, visitStackNullType, visitStackObjectType, visitStackTopType, visitStackUninitializedThisType, visitStackUninitializedType, visitStringConstant, visitSyntheticAttribute, visitSyntheticAttribute, visitSyntheticAttribute, visitSyntheticAttribute, visitTopType, visitUninitializedThisType, visitUnknownAttribute, visitUtf8Constant, visitVariablesDoubleType, visitVariablesFloatType, visitVariablesIntegerType, visitVariablesLongType, visitVariablesNullType, visitVariablesObjectType, visitVariablesTopType, visitVariablesUninitializedThisType, visitVariablesUninitializedType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface proguard.classfile.attribute.visitor.AttributeVisitor
visitAnnotationDefaultAttribute, visitConstantValueAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitEnclosingMethodAttribute, visitExceptionsAttribute, visitInnerClassesAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleParameterAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleParameterAnnotationsAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSourceDirAttribute, visitSourceFileAttribute, visitSyntheticAttribute, visitSyntheticAttribute, visitSyntheticAttribute, visitUnknownAttribute
 
Methods inherited from interface proguard.classfile.attribute.preverification.visitor.StackMapFrameVisitor
visitLessZeroFrame, visitSameZeroFrame
 
Methods inherited from interface proguard.classfile.attribute.preverification.visitor.VerificationTypeVisitor
visitDoubleType, visitFloatType, visitIntegerType, visitLongType, visitNullType, visitObjectType, visitStackDoubleType, visitStackFloatType, visitStackIntegerType, visitStackLongType, visitStackNullType, visitStackObjectType, visitStackTopType, visitStackUninitializedThisType, visitStackUninitializedType, visitTopType, visitUninitializedThisType, visitVariablesDoubleType, visitVariablesFloatType, visitVariablesIntegerType, visitVariablesLongType, visitVariablesNullType, visitVariablesObjectType, visitVariablesTopType, visitVariablesUninitializedThisType, visitVariablesUninitializedType
 

Field Detail

preInsertions

public Instruction[] preInsertions

replacements

public Instruction[] replacements

postInsertions

public Instruction[] postInsertions

deleted

public boolean[] deleted
Constructor Detail

CodeAttributeEditor

public CodeAttributeEditor()

CodeAttributeEditor

public CodeAttributeEditor(boolean updateFrameSizes)
Method Detail

reset

public void reset(int codeLength)
Resets the accumulated code changes.

Parameters:
codeLength - the length of the code that will be edited next.

insertBeforeInstruction

public void insertBeforeInstruction(int instructionOffset,
                                    Instruction instruction)
Remembers to place the given instruction right before the instruction at the given offset.

Parameters:
instructionOffset - the offset of the instruction.
instruction - the new instruction.

insertBeforeInstruction

public void insertBeforeInstruction(int instructionOffset,
                                    Instruction[] instructions)
Remembers to place the given instructions right before the instruction at the given offset.

Parameters:
instructionOffset - the offset of the instruction.
instructions - the new instructions.

replaceInstruction

public void replaceInstruction(int instructionOffset,
                               Instruction instruction)
Remembers to replace the instruction at the given offset by the given instruction.

Parameters:
instructionOffset - the offset of the instruction to be replaced.
instruction - the new instruction.

replaceInstruction

public void replaceInstruction(int instructionOffset,
                               Instruction[] instructions)
Remembers to replace the instruction at the given offset by the given instructions.

Parameters:
instructionOffset - the offset of the instruction to be replaced.
instructions - the new instructions.

insertAfterInstruction

public void insertAfterInstruction(int instructionOffset,
                                   Instruction instruction)
Remembers to place the given instruction right after the instruction at the given offset.

Parameters:
instructionOffset - the offset of the instruction.
instruction - the new instruction.

insertAfterInstruction

public void insertAfterInstruction(int instructionOffset,
                                   Instruction[] instructions)
Remembers to place the given instructions right after the instruction at the given offset.

Parameters:
instructionOffset - the offset of the instruction.
instructions - the new instructions.

deleteInstruction

public void deleteInstruction(int instructionOffset)
Remembers to delete the instruction at the given offset.

Parameters:
instructionOffset - the offset of the instruction to be deleted.

undeleteInstruction

public void undeleteInstruction(int instructionOffset)
Remembers not to delete the instruction at the given offset.

Parameters:
instructionOffset - the offset of the instruction not to be deleted.

isModified

public boolean isModified(int instructionOffset)
Returns whether the instruction at the given offset has been modified in any way.


visitAnyAttribute

public void visitAnyAttribute(Clazz clazz,
                              Attribute attribute)
Description copied from class: SimplifiedVisitor
Visit any type of attribute.

Overrides:
visitAnyAttribute in class SimplifiedVisitor

visitCodeAttribute

public void visitCodeAttribute(Clazz clazz,
                               Method method,
                               CodeAttribute codeAttribute)
Specified by:
visitCodeAttribute in interface AttributeVisitor
Overrides:
visitCodeAttribute in class SimplifiedVisitor

visitCodeAttribute0

public void visitCodeAttribute0(Clazz clazz,
                                Method method,
                                CodeAttribute codeAttribute)

visitStackMapAttribute

public void visitStackMapAttribute(Clazz clazz,
                                   Method method,
                                   CodeAttribute codeAttribute,
                                   StackMapAttribute stackMapAttribute)
Specified by:
visitStackMapAttribute in interface AttributeVisitor
Overrides:
visitStackMapAttribute in class SimplifiedVisitor

visitStackMapTableAttribute

public void visitStackMapTableAttribute(Clazz clazz,
                                        Method method,
                                        CodeAttribute codeAttribute,
                                        StackMapTableAttribute stackMapTableAttribute)
Specified by:
visitStackMapTableAttribute in interface AttributeVisitor
Overrides:
visitStackMapTableAttribute in class SimplifiedVisitor

visitLineNumberTableAttribute

public void visitLineNumberTableAttribute(Clazz clazz,
                                          Method method,
                                          CodeAttribute codeAttribute,
                                          LineNumberTableAttribute lineNumberTableAttribute)
Specified by:
visitLineNumberTableAttribute in interface AttributeVisitor
Overrides:
visitLineNumberTableAttribute in class SimplifiedVisitor

visitLocalVariableTableAttribute

public void visitLocalVariableTableAttribute(Clazz clazz,
                                             Method method,
                                             CodeAttribute codeAttribute,
                                             LocalVariableTableAttribute localVariableTableAttribute)
Specified by:
visitLocalVariableTableAttribute in interface AttributeVisitor
Overrides:
visitLocalVariableTableAttribute in class SimplifiedVisitor

visitLocalVariableTypeTableAttribute

public void visitLocalVariableTypeTableAttribute(Clazz clazz,
                                                 Method method,
                                                 CodeAttribute codeAttribute,
                                                 LocalVariableTypeTableAttribute localVariableTypeTableAttribute)
Specified by:
visitLocalVariableTypeTableAttribute in interface AttributeVisitor
Overrides:
visitLocalVariableTypeTableAttribute in class SimplifiedVisitor

visitSimpleInstruction

public void visitSimpleInstruction(Clazz clazz,
                                   Method method,
                                   CodeAttribute codeAttribute,
                                   int offset,
                                   SimpleInstruction simpleInstruction)
Specified by:
visitSimpleInstruction in interface InstructionVisitor
Overrides:
visitSimpleInstruction in class SimplifiedVisitor

visitConstantInstruction

public void visitConstantInstruction(Clazz clazz,
                                     Method method,
                                     CodeAttribute codeAttribute,
                                     int offset,
                                     ConstantInstruction constantInstruction)
Specified by:
visitConstantInstruction in interface InstructionVisitor
Overrides:
visitConstantInstruction in class SimplifiedVisitor

visitVariableInstruction

public void visitVariableInstruction(Clazz clazz,
                                     Method method,
                                     CodeAttribute codeAttribute,
                                     int offset,
                                     VariableInstruction variableInstruction)
Specified by:
visitVariableInstruction in interface InstructionVisitor
Overrides:
visitVariableInstruction in class SimplifiedVisitor

visitBranchInstruction

public void visitBranchInstruction(Clazz clazz,
                                   Method method,
                                   CodeAttribute codeAttribute,
                                   int offset,
                                   BranchInstruction branchInstruction)
Specified by:
visitBranchInstruction in interface InstructionVisitor
Overrides:
visitBranchInstruction in class SimplifiedVisitor

visitTableSwitchInstruction

public void visitTableSwitchInstruction(Clazz clazz,
                                        Method method,
                                        CodeAttribute codeAttribute,
                                        int offset,
                                        TableSwitchInstruction tableSwitchInstruction)
Specified by:
visitTableSwitchInstruction in interface InstructionVisitor
Overrides:
visitTableSwitchInstruction in class SimplifiedVisitor

visitLookUpSwitchInstruction

public void visitLookUpSwitchInstruction(Clazz clazz,
                                         Method method,
                                         CodeAttribute codeAttribute,
                                         int offset,
                                         LookUpSwitchInstruction lookUpSwitchInstruction)
Specified by:
visitLookUpSwitchInstruction in interface InstructionVisitor
Overrides:
visitLookUpSwitchInstruction in class SimplifiedVisitor

visitExceptionInfo

public void visitExceptionInfo(Clazz clazz,
                               Method method,
                               CodeAttribute codeAttribute,
                               ExceptionInfo exceptionInfo)
Specified by:
visitExceptionInfo in interface ExceptionInfoVisitor

visitAnyStackMapFrame

public void visitAnyStackMapFrame(Clazz clazz,
                                  Method method,
                                  CodeAttribute codeAttribute,
                                  int offset,
                                  StackMapFrame stackMapFrame)
Description copied from class: SimplifiedVisitor
Visits any type of VerificationType.

Overrides:
visitAnyStackMapFrame in class SimplifiedVisitor

visitSameOneFrame

public void visitSameOneFrame(Clazz clazz,
                              Method method,
                              CodeAttribute codeAttribute,
                              int offset,
                              SameOneFrame sameOneFrame)
Specified by:
visitSameOneFrame in interface StackMapFrameVisitor
Overrides:
visitSameOneFrame in class SimplifiedVisitor

visitMoreZeroFrame

public void visitMoreZeroFrame(Clazz clazz,
                               Method method,
                               CodeAttribute codeAttribute,
                               int offset,
                               MoreZeroFrame moreZeroFrame)
Specified by:
visitMoreZeroFrame in interface StackMapFrameVisitor
Overrides:
visitMoreZeroFrame in class SimplifiedVisitor

visitFullFrame

public void visitFullFrame(Clazz clazz,
                           Method method,
                           CodeAttribute codeAttribute,
                           int offset,
                           FullFrame fullFrame)
Specified by:
visitFullFrame in interface StackMapFrameVisitor
Overrides:
visitFullFrame in class SimplifiedVisitor

visitAnyVerificationType

public void visitAnyVerificationType(Clazz clazz,
                                     Method method,
                                     CodeAttribute codeAttribute,
                                     int offset,
                                     VerificationType verificationType)
Description copied from class: SimplifiedVisitor
Visits any type of VerificationType.

Overrides:
visitAnyVerificationType in class SimplifiedVisitor

visitUninitializedType

public void visitUninitializedType(Clazz clazz,
                                   Method method,
                                   CodeAttribute codeAttribute,
                                   int offset,
                                   UninitializedType uninitializedType)
Specified by:
visitUninitializedType in interface VerificationTypeVisitor
Overrides:
visitUninitializedType in class SimplifiedVisitor

visitLineNumberInfo

public void visitLineNumberInfo(Clazz clazz,
                                Method method,
                                CodeAttribute codeAttribute,
                                LineNumberInfo lineNumberInfo)
Specified by:
visitLineNumberInfo in interface LineNumberInfoVisitor

visitLocalVariableInfo

public void visitLocalVariableInfo(Clazz clazz,
                                   Method method,
                                   CodeAttribute codeAttribute,
                                   LocalVariableInfo localVariableInfo)
Specified by:
visitLocalVariableInfo in interface LocalVariableInfoVisitor

visitLocalVariableTypeInfo

public void visitLocalVariableTypeInfo(Clazz clazz,
                                       Method method,
                                       CodeAttribute codeAttribute,
                                       LocalVariableTypeInfo localVariableTypeInfo)
Specified by:
visitLocalVariableTypeInfo in interface LocalVariableTypeInfoVisitor