public class

DexUtil

extends Object
java.lang.Object
   ↳ com.pnfsoftware.jeb.core.units.code.android.DexUtil

Class Overview

DEX utility routines.

Summary

Public Methods
static String bytearrayMUTF8ToString(byte[] data, int pos, int[] readsize)
Decode a MUTF-8 encoded string.
static String bytearrayMUTF8ToStringFast(byte[] data, int pos, int[] readsize, int expectedLength)
Decode a MUTF-8 encoded string.
static int bytearraySLEB128ToInt(byte[] data, int pos, int[] readsize)
Read a signed LEB128-encoded int.
static int bytearrayULEB128P1ToInt(byte[] data, int pos, int[] readsize)
Read an unsigned LEB128-encoded int shifted by 1.
static int bytearrayULEB128ToInt(byte[] data, int pos, int[] readsize)
Read an unsigned LEB128-encoded int.
static int bytearrayULEInt16ToInt(byte[] data, int pos)
Read a little-endian uint16 short.
static int bytearrayULEInt32ToInt(byte[] data, int pos)
Read a little-endian uint32 int.
static int convertDexFlagsToCodeFlags(int nativeFlags)
Convert native Dalvik flags to generic ICodeItem flags.
static int determineBestBase(long value)
static String formatAccessFlags(int f, int add_final_space)
Format Java access flags to an appropriate string.
final static String formatFieldsigs(IDexUnit dex, Collection<Integer> indices)
Format a list of DEX fields.
final static String formatMethodsigs(IDexUnit dex, Collection<Integer> indices)
Format a list of DEX methods.
final static String formatTypenames(IDexUnit dex, Collection<Integer> indices)
Format a list of DEX types.
static List<String> getDebugParameterNames(IDexUnit dex, IDexMethodData md)
Convenience method to retrieve the list of arguments' debug names whose indices are provided by {@link IDexDebugInfo#getParameterNameIndexes().
static List<IDexClass> getMemberClasses(IDexUnit dex, IDexMethod m)
static List<IDexClass> getMemberClasses(IDexUnit dex, IDexClass c)
static int[] getMethodParameterIndices(IDexMethod m)
Retrieve an array of register indices holding the method parameters.
static ParametersInfo getMethodParametersInfo(IDexUnit dex, IDexMethodData md)
Generate method parameters' registers information.
static ParametersInfo getMethodParametersInfo(String shorty, boolean isStaticMethod)
Generate method parameters' registers information.
static int getMethodSlotCount(String shorty, boolean isStaticMethod)
Determine the number of slots required by a method to hold all of its parameters (including `this` if the method is not static).
static IDexValue getStaticFieldInitializer(IDexClass c, IDexFieldData fd)
Retrieve the initial value of a static final class field.
static String getStringSafe(IDexUnit dex, int index, String defval)
static IDexClass getSuperClass(IDexUnit dex, IDexClass c)
final static int getVersion(IBinaryUnit unit)
Extract the version number from an Android binary unit.
static boolean isClassname(String s, boolean validate, List<String> elements, int dexVersion)
Determine whether a string looks like a valid binary-form (dot-separated) class name.
static boolean isInternalClassname(String s, boolean validate, List<String> elements, int dexVersion)
Determine whether a string looks like a valid internal-form (jvm) class name.
static boolean isSimpleName(String s, int dexVersion)
Verify if the provided string is a valid dex SimpleName.
static boolean isSubtypeOf(IDexUnit dex, int typeIndex, int candidateParentTypeIndex)
static String[] toJniName(String signature)
Converts a java signature to the conventional jni method name.
static void validateClassFlags(int f)
Validate Dalvik class item flags: this method throws if some flags are undefined or illegal for class items.
static void validateFieldFlags(int f)
Validate Dalvik field item flags: this method throws if some flags are undefined or illegal for field items.
static void validateFlags(int f)
Validate Dalvik flags: this method throws if some flags are undefined Dalvik flags.
static void validateMethodFlags(int f)
Validate Dalvik method item flags: this method throws if some flags are undefined or illegal for method items.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static String bytearrayMUTF8ToString (byte[] data, int pos, int[] readsize)

Decode a MUTF-8 encoded string.

Parameters
readsize optional one-element output array

public static String bytearrayMUTF8ToStringFast (byte[] data, int pos, int[] readsize, int expectedLength)

Decode a MUTF-8 encoded string.

Parameters
readsize optional one-element output array

public static int bytearraySLEB128ToInt (byte[] data, int pos, int[] readsize)

Read a signed LEB128-encoded int.

public static int bytearrayULEB128P1ToInt (byte[] data, int pos, int[] readsize)

Read an unsigned LEB128-encoded int shifted by 1.

public static int bytearrayULEB128ToInt (byte[] data, int pos, int[] readsize)

Read an unsigned LEB128-encoded int.

public static int bytearrayULEInt16ToInt (byte[] data, int pos)

Read a little-endian uint16 short.

public static int bytearrayULEInt32ToInt (byte[] data, int pos)

Read a little-endian uint32 int.

public static int convertDexFlagsToCodeFlags (int nativeFlags)

Convert native Dalvik flags to generic ICodeItem flags.

public static int determineBestBase (long value)

public static String formatAccessFlags (int f, int add_final_space)

Format Java access flags to an appropriate string.

Parameters
f Flags, as defined by the Dalvik specs
add_final_space if 1, append a trailing space; if -1, append a trailing space only if the access flags string is not empty

public static final String formatFieldsigs (IDexUnit dex, Collection<Integer> indices)

Format a list of DEX fields.

Parameters
dex unit
indices DEX method indices

public static final String formatMethodsigs (IDexUnit dex, Collection<Integer> indices)

Format a list of DEX methods.

Parameters
dex unit
indices DEX method indices

public static final String formatTypenames (IDexUnit dex, Collection<Integer> indices)

Format a list of DEX types.

Parameters
dex unit
indices DEX type indices

public static List<String> getDebugParameterNames (IDexUnit dex, IDexMethodData md)

Convenience method to retrieve the list of arguments' debug names whose indices are provided by {@link IDexDebugInfo#getParameterNameIndexes().

Returns
  • a list of names; null if no debug info is present; else, the list contains all parameter names in order, except for 'this' if the method is non-static; entries referring to invalid strings will hold null references; the list may be less than the actual number of method parameters

public static List<IDexClass> getMemberClasses (IDexUnit dex, IDexMethod m)

public static List<IDexClass> getMemberClasses (IDexUnit dex, IDexClass c)

public static int[] getMethodParameterIndices (IDexMethod m)

Retrieve an array of register indices holding the method parameters. The list includes 'this' (for non-static methods); double-slot variables are represengting by their first register in the pair.

Parameters
m an internal dex method
Returns
  • an array of register indices

public static ParametersInfo getMethodParametersInfo (IDexUnit dex, IDexMethodData md)

Generate method parameters' registers information.

public static ParametersInfo getMethodParametersInfo (String shorty, boolean isStaticMethod)

Generate method parameters' registers information.

public static int getMethodSlotCount (String shorty, boolean isStaticMethod)

Determine the number of slots required by a method to hold all of its parameters (including `this` if the method is not static).

public static IDexValue getStaticFieldInitializer (IDexClass c, IDexFieldData fd)

Retrieve the initial value of a static final class field.

Parameters
c a dex class object
fd field definition of an internal field
Returns
  • the initial field value, null if none or on error

public static String getStringSafe (IDexUnit dex, int index, String defval)

public static IDexClass getSuperClass (IDexUnit dex, IDexClass c)

public static final int getVersion (IBinaryUnit unit)

Extract the version number from an Android binary unit.

Parameters
unit an Android binary unit respecting the standard header (xxxxNNN0), such as dex, vdex, cdex, art, etc.
Throws
ParseException on parsing error

public static boolean isClassname (String s, boolean validate, List<String> elements, int dexVersion)

Determine whether a string looks like a valid binary-form (dot-separated) class name. Arrays are not accepted.

Parameters
s the input string, e.g. com.abc.Foo
validate if true, verify the legality of the simple names of the class name
elements if non-null, an output sink used to collect the simple names of the input class name
dexVersion optional dex version (0 means latest)

public static boolean isInternalClassname (String s, boolean validate, List<String> elements, int dexVersion)

Determine whether a string looks like a valid internal-form (jvm) class name. Arrays are not accepted.

Parameters
s the input string, e.g. Lcom/abc/Foo;
validate if true, verify the legality of the simple names of the class name
elements if non-null, an output sink used to collect the simple names of the input class name
dexVersion optional dex version (0 means latest)

public static boolean isSimpleName (String s, int dexVersion)

Verify if the provided string is a valid dex SimpleName.

Ref: https://source.android.com/devices/tech/dalvik/dex-format#simplename

Parameters
s a Dalvik simple name, such as a non-qualified class/method/field name
dexVersion optional dex version; 0 means latest

public static boolean isSubtypeOf (IDexUnit dex, int typeIndex, int candidateParentTypeIndex)

public static String[] toJniName (String signature)

Converts a java signature to the conventional jni method name.

Parameters
signature java signature
Returns
  • the possible signatures (with or without parameter signature)

public static void validateClassFlags (int f)

Validate Dalvik class item flags: this method throws if some flags are undefined or illegal for class items.

public static void validateFieldFlags (int f)

Validate Dalvik field item flags: this method throws if some flags are undefined or illegal for field items.

public static void validateFlags (int f)

Validate Dalvik flags: this method throws if some flags are undefined Dalvik flags.

public static void validateMethodFlags (int f)

Validate Dalvik method item flags: this method throws if some flags are undefined or illegal for method items.