Class DexIMethod

java.lang.Object
com.ibm.wala.dalvik.classLoader.DexIMethod
All Implemented Interfaces:
IBytecodeMethod<Instruction>, IMember, IMethod, ContextItem, IClassHierarchyDweller

public class DexIMethod extends Object implements IBytecodeMethod<Instruction>
A wrapper around a EncodedMethod object (from dexlib) that represents a method.
  • Field Details

    • myClass

      protected final DexIClass myClass
      The declaring class for this method.
    • instructions

      protected InstructionArray instructions
  • Constructor Details

    • DexIMethod

      public DexIMethod(org.jf.dexlib2.iface.Method encodedMethod, DexIClass klass)
  • Method Details

    • getTotalInsts

      public static int getTotalInsts()
    • toEncodedMethod

      public org.jf.dexlib2.iface.Method toEncodedMethod()
      Returns:
      the EncodedMethod object for which this DexIMethod is a wrapper.
    • getDeclaredExceptions

      public TypeReference[] getDeclaredExceptions() throws UnsupportedOperationException
      Specified by:
      getDeclaredExceptions in interface IMethod
      Returns:
      an array of the exception types declared by the throws clause for this method, or null if there are none
      Throws:
      UnsupportedOperationException
    • getLocalVariableName

      public String getLocalVariableName(int bcIndex, int localNumber)
      Specified by:
      getLocalVariableName in interface IMethod
      Returns:
      the (source code) name of the local variable of a given number at the specified program counter, or null if the information is not available.
    • getMaxLocals

      public int getMaxLocals()
      XXX not fully about the + 2.
      Returns:
      the RegisterCount + 2 to make some room for the return and exception register
      See Also:
    • getReturnReg

      public int getReturnReg()
    • getExceptionReg

      public int getExceptionReg()
    • getMaxStackHeight

      public int getMaxStackHeight()
    • getDescriptor

      public Descriptor getDescriptor()
      Description copied from interface: IMethod
      something like: (IILjava.lang.String;SLjava.sql.Date;)Ljava.lang.Integer;
      Specified by:
      getDescriptor in interface IMethod
    • getNumberOfParameters

      public int getNumberOfParameters()
      Description copied from interface: IMethod
      Method getNumberOfParameters. This result includes the "this" pointer if applicable
      Specified by:
      getNumberOfParameters in interface IMethod
    • getNumberOfParameterRegisters

      public int getNumberOfParameterRegisters()
    • getParameterType

      public TypeReference getParameterType(int index)
      Description copied from interface: IMethod
      By convention, for a non-static method, getParameterType(0) is the this pointer
      Specified by:
      getParameterType in interface IMethod
    • getReference

      public MethodReference getReference()
      Specified by:
      getReference in interface IMethod
      Returns:
      canonical MethodReference corresponding to this method
    • getReturnType

      public TypeReference getReturnType()
      Specified by:
      getReturnType in interface IMethod
      Returns:
      the name of the return type for this method
    • getSelector

      public Selector getSelector()
      Description copied from interface: IMethod
      something like: foo(Ljava/langString;)Ljava/lang/Class;
      Specified by:
      getSelector in interface IMethod
    • getSignature

      public String getSignature()
      Description copied from interface: IMethod
      something like: com.foo.bar.createLargeOrder(IILjava.lang.String;SLjava.sql.Date;)Ljava.lang.Integer;
      Specified by:
      getSignature in interface IMethod
    • hasExceptionHandler

      public boolean hasExceptionHandler()
      Specified by:
      hasExceptionHandler in interface IMethod
      Returns:
      true iff this method has at least one exception handler
    • hasLocalVariableTable

      public boolean hasLocalVariableTable()
      Specified by:
      hasLocalVariableTable in interface IMethod
      Returns:
      true iff the local variable table information for this method is available
    • isAbstract

      public boolean isAbstract()
      Description copied from interface: IMethod
      Is this method abstract?
      Specified by:
      isAbstract in interface IMethod
    • isClinit

      public boolean isClinit()
      Description copied from interface: IMethod
      Is this method a class initializer?
      Specified by:
      isClinit in interface IMethod
    • isFinal

      public boolean isFinal()
      Description copied from interface: IMethod
      Is this method final?
      Specified by:
      isFinal in interface IMethod
    • isInit

      public boolean isInit()
      Description copied from interface: IMethod
      Is this method an object initializer?
      Specified by:
      isInit in interface IMethod
    • isNative

      public boolean isNative()
      Description copied from interface: IMethod
      Is this method native?
      Specified by:
      isNative in interface IMethod
    • isBridge

      public boolean isBridge()
      Description copied from interface: IMethod
      Is this method a bridge method? See JLS 3rd Edition 15.12.4.5
      Specified by:
      isBridge in interface IMethod
    • isPrivate

      public boolean isPrivate()
      Description copied from interface: IMethod
      Is this method private?
      Specified by:
      isPrivate in interface IMethod
    • isProtected

      public boolean isProtected()
      Description copied from interface: IMethod
      Is this method protected?
      Specified by:
      isProtected in interface IMethod
    • isPublic

      public boolean isPublic()
      Description copied from interface: IMethod
      Is this method public?
      Specified by:
      isPublic in interface IMethod
    • isSynchronized

      public boolean isSynchronized()
      Description copied from interface: IMethod
      Is this method synchronized?
      Specified by:
      isSynchronized in interface IMethod
    • isWalaSynthetic

      public boolean isWalaSynthetic()
      Description copied from interface: IMethod
      Is the implementation of this method a model generated by WALA? For compiler-generated synthetic methods, refer to IMethod.isSynthetic()
      Specified by:
      isWalaSynthetic in interface IMethod
    • isSynthetic

      public boolean isSynthetic()
      Description copied from interface: IMethod
      Is this method synthetic, i.e., compiler-generated (this refers to the synthetic flag in java/dex bytecode)
      Specified by:
      isSynthetic in interface IMethod
    • isStatic

      public boolean isStatic()
      Description copied from interface: IMember
      Is this member static?
      Specified by:
      isStatic in interface IMember
    • isVolatile

      public boolean isVolatile()
    • isAnnotation

      public boolean isAnnotation()
      Specified by:
      isAnnotation in interface IMethod
    • isEnum

      public boolean isEnum()
      Specified by:
      isEnum in interface IMethod
    • isModule

      public boolean isModule()
      Specified by:
      isModule in interface IMethod
    • getDeclaringClass

      public IClass getDeclaringClass()
      Description copied from interface: IMember
      Return the object that represents the declaring class for this member.
      Specified by:
      getDeclaringClass in interface IMember
      Returns:
      the object that represents the declaring class for this member.
    • getClassHierarchy

      public IClassHierarchy getClassHierarchy()
      Specified by:
      getClassHierarchy in interface IClassHierarchyDweller
    • getName

      public Atom getName()
      Specified by:
      getName in interface IMember
      Returns:
      the name of this member
    • getLineNumber

      public int getLineNumber(int bcIndex)
      Specified by:
      getLineNumber in interface IMethod
      Returns:
      the source line number corresponding to a particular bytecode index, or -1 if the information is not available.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getBytecodeIndex

      public int getBytecodeIndex(int i)
      Specified by:
      getBytecodeIndex in interface IBytecodeMethod<Instruction>
      Returns:
      the bytecode index corresponding to instruction i in the getInstructions() array
    • getHandlers

      public ExceptionHandler[][] getHandlers()
      Specified by:
      getHandlers in interface IBytecodeMethod<Instruction>
      Returns:
      the Shrike representation of the exception handlers
    • getInstructions

      public Instruction[] getInstructions()
      Specified by:
      getInstructions in interface IBytecodeMethod<Instruction>
      Returns:
      the Shrike instructions decoded from the bytecode
    • parseBytecode

      protected void parseBytecode()
    • handleINVOKE_VIRTUAL

      protected void handleINVOKE_VIRTUAL(int instLoc, String cname, String mname, String pname, int[] args, org.jf.dexlib2.Opcode opcode)
    • getDexInstructions

      public Instruction[] getDexInstructions()
    • instructions

      protected InstructionArray instructions()
    • getAddressFromIndex

      public int getAddressFromIndex(int index)
    • getInstructionIndex

      public int getInstructionIndex(int bytecodeindex)
      Specified by:
      getInstructionIndex in interface IBytecodeMethod<Instruction>
      Returns:
      the instuction index i in the getInstructions() array corresponding to the bytecode index bcIndex
    • getInstructionFromIndex

      public Instruction getInstructionFromIndex(int instructionIndex)
    • getIndirectionData

      public IndirectionData getIndirectionData()
      Specified by:
      getIndirectionData in interface IBytecodeMethod<Instruction>
      Returns:
      information about any indirect uses of local variables
    • getCallSites

      public Collection<CallSiteReference> getCallSites()
      Description copied from interface: IBytecodeMethod
      there
      Specified by:
      getCallSites in interface IBytecodeMethod<Instruction>
      Returns:
      the call sites declared in the bytecode for this method
      Throws:
      UnsupportedOperationException -

      TODO: Review this implementation - it may be horribly wrong!

    • getFieldsRead

      public Iterator<FieldReference> getFieldsRead()
      Specified by:
      getFieldsRead in interface IBytecodeMethod<Instruction>
    • getFieldsWritten

      public Iterator<FieldReference> getFieldsWritten()
      Specified by:
      getFieldsWritten in interface IBytecodeMethod<Instruction>
    • getArraysWritten

      public Iterator<TypeReference> getArraysWritten()
      Specified by:
      getArraysWritten in interface IBytecodeMethod<Instruction>
    • getNewSites

      public Collection<NewSiteReference> getNewSites()
      Specified by:
      getNewSites in interface IBytecodeMethod<Instruction>
      Returns:
      the new sites declared in the bytecode for this method
    • getSourcePosition

      public IMethod.SourcePosition getSourcePosition(int instructionIndex)
      Specified by:
      getSourcePosition in interface IMethod
    • getParameterSourcePosition

      public IMethod.SourcePosition getParameterSourcePosition(int paramNum)
      Specified by:
      getParameterSourcePosition in interface IMethod
    • getAnnotations

      public Collection<Annotation> getAnnotations()
      Description copied from interface: IMember
      Get the annotations on this member, if any
      Specified by:
      getAnnotations in interface IMember
    • getAnnotations

      public Collection<Annotation> getAnnotations(boolean runtimeInvisible)
      Specified by:
      getAnnotations in interface IBytecodeMethod<Instruction>
    • getParameterAnnotations

      public Collection<Annotation>[] getParameterAnnotations()
      Specified by:
      getParameterAnnotations in interface IBytecodeMethod<Instruction>