Class ClassProto

java.lang.Object
org.jf.dexlib2.analysis.ClassProto
All Implemented Interfaces:
TypeProto

public class ClassProto extends Object implements TypeProto
A class "prototype". This contains things like the interfaces, the superclass, the vtable and the instance fields and their offsets.
  • Field Details

    • REFERENCE

      private static final byte REFERENCE
      See Also:
    • WIDE

      private static final byte WIDE
      See Also:
    • OTHER

      private static final byte OTHER
      See Also:
    • classPath

      @Nonnull protected final ClassPath classPath
    • type

      @Nonnull protected final String type
    • vtableFullyResolved

      protected boolean vtableFullyResolved
    • interfacesFullyResolved

      protected boolean interfacesFullyResolved
    • unresolvedInterfaces

      protected Set<String> unresolvedInterfaces
    • classDefSupplier

      @Nonnull private final com.google.common.base.Supplier<ClassDef> classDefSupplier
    • preDefaultMethodInterfaceSupplier

      @Nonnull private final com.google.common.base.Supplier<LinkedHashMap<String,ClassDef>> preDefaultMethodInterfaceSupplier
      This calculates the interfaces in the order required for vtable generation for dalvik and pre-default method ART
    • postDefaultMethodInterfaceSupplier

      @Nonnull private final com.google.common.base.Supplier<LinkedHashMap<String,ClassDef>> postDefaultMethodInterfaceSupplier
      This calculates the interfaces in the order required for vtable generation for post-default method ART
    • dalvikInstanceFieldsSupplier

      @Nonnull private final com.google.common.base.Supplier<SparseArray<FieldReference>> dalvikInstanceFieldsSupplier
    • artInstanceFieldsSupplier

      @Nonnull private final com.google.common.base.Supplier<SparseArray<FieldReference>> artInstanceFieldsSupplier
    • preDefaultMethodVtableSupplier

      @Nonnull private final com.google.common.base.Supplier<List<Method>> preDefaultMethodVtableSupplier
    • buggyPostDefaultMethodVtableSupplier

      @Nonnull private final com.google.common.base.Supplier<List<Method>> buggyPostDefaultMethodVtableSupplier
      This is the vtable supplier for a version of art that had buggy vtable calculation logic. In some cases it can produce multiple vtable entries for a given virtual method. This supplier duplicates this buggy logic in order to generate an identical vtable
    • postDefaultMethodVtableSupplier

      @Nonnull private final com.google.common.base.Supplier<List<Method>> postDefaultMethodVtableSupplier
  • Constructor Details

    • ClassProto

      public ClassProto(@Nonnull ClassPath classPath, @Nonnull String type)
  • Method Details

    • toString

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

      @Nonnull public ClassPath getClassPath()
      Specified by:
      getClassPath in interface TypeProto
    • getType

      @Nonnull public String getType()
      Specified by:
      getType in interface TypeProto
    • getClassDef

      @Nonnull public ClassDef getClassDef()
    • isInterface

      public boolean isInterface()
      Returns true if this class is an interface. If this class is not defined, then this will throw an UnresolvedClassException
      Specified by:
      isInterface in interface TypeProto
      Returns:
      True if this class is an interface
    • getInterfaces

      @Nonnull protected LinkedHashMap<String,ClassDef> getInterfaces()
      Returns the set of interfaces that this class implements as a Mapinvalid input: '<'String, ClassDef>. The ClassDef value will be present only for the interfaces that this class directly implements (including any interfaces transitively implemented), but not for any interfaces that are only implemented by a superclass of this class For any interfaces that are only implemented by a superclass (or the class itself, if the class is an interface), the value will be null. If any interface couldn't be resolved, then the interfacesFullyResolved field will be set to false upon return.
      Returns:
      the set of interfaces that this class implements as a Mapinvalid input: '<'String, ClassDef>.
    • getUnresolvedInterfaces

      @Nonnull protected Set<String> getUnresolvedInterfaces()
    • getDirectInterfaces

      @Nonnull protected Iterable<ClassDef> getDirectInterfaces()
      Gets the interfaces directly implemented by this class, or the interfaces they transitively implement. This does not include any interfaces that are only implemented by a superclass
      Returns:
      An iterables of ClassDefs representing the directly or transitively implemented interfaces
      Throws:
      UnresolvedClassException - if interfaces could not be fully resolved
    • implementsInterface

      public boolean implementsInterface(@Nonnull String iface)
      Checks if this class implements the given interface. If the interfaces of this class cannot be fully resolved then this method will either return true or throw an UnresolvedClassException
      Specified by:
      implementsInterface in interface TypeProto
      Parameters:
      iface - The interface to check for
      Returns:
      true if this class implements the given interface, otherwise false
      Throws:
      UnresolvedClassException - if the interfaces for this class could not be fully resolved, and the interface is not one of the interfaces that were successfully resolved
    • getSuperclass

      @Nullable public String getSuperclass()
      Specified by:
      getSuperclass in interface TypeProto
    • checkInterface

      private boolean checkInterface(@Nonnull ClassProto other)
      This is a helper method for getCommonSuperclass It checks if this class is an interface, and if so, if other implements it. If this class is undefined, we go ahead and check if it is listed in other's interfaces. If not, we throw an UndefinedClassException If the interfaces of other cannot be fully resolved, we check the interfaces that can be resolved. If not found, we throw an UndefinedClassException
      Parameters:
      other - The class to check the interfaces of
      Returns:
      true if this class is an interface (or is undefined) other implements this class
    • getCommonSuperclass

      @Nonnull public TypeProto getCommonSuperclass(@Nonnull TypeProto other)
      Specified by:
      getCommonSuperclass in interface TypeProto
    • getFieldByOffset

      @Nullable public FieldReference getFieldByOffset(int fieldOffset)
      Specified by:
      getFieldByOffset in interface TypeProto
    • getMethodByVtableIndex

      @Nullable public Method getMethodByVtableIndex(int vtableIndex)
      Specified by:
      getMethodByVtableIndex in interface TypeProto
    • findMethodIndexInVtable

      public int findMethodIndexInVtable(@Nonnull MethodReference method)
      Specified by:
      findMethodIndexInVtable in interface TypeProto
    • findMethodIndexInVtable

      private int findMethodIndexInVtable(@Nonnull List<Method> vtable, MethodReference method)
    • findMethodIndexInVtableReverse

      private int findMethodIndexInVtableReverse(@Nonnull List<Method> vtable, MethodReference method)
    • getInstanceFields

      @Nonnull public SparseArray<FieldReference> getInstanceFields()
    • getNextFieldOffset

      private int getNextFieldOffset()
    • getTypeSize

      private static int getTypeSize(char type)
    • getVtable

      @Nonnull public List<Method> getVtable()
    • addToVtable

      private void addToVtable(@Nonnull Iterable<? extends Method> localMethods, @Nonnull List<Method> vtable, boolean replaceExisting, boolean sort)
    • getFieldType

      private static byte getFieldType(@Nonnull FieldReference field)
    • isOverridableByDefaultMethod

      private boolean isOverridableByDefaultMethod(@Nonnull Method method)
    • interfaceMethodOverrides

      private boolean interfaceMethodOverrides(@Nonnull Method method, @Nonnull Method method2)
      Checks if the interface method overrides the virtual or interface method2
      Parameters:
      method - A Method from an interface
      method2 - A Method from an interface or a class
      Returns:
      true if the interface method overrides the virtual or interface method2