# Class: com.pnfsoftware.jeb.core.units.code.android.DexUtil

Dex utility routines.

## Static Method: bytearrayMUTF8ToString
- parameter: `data`, type: `byte[]`
- parameter: `pos`, type: `int`
- parameter: `readsize`, type: `int[]`
- return type: `java.lang.String`

Description: Decode a MUTF\-8 encoded string whose length is unknown. The encoded string must be terminated by a null \(0\) byte, per the JVM MUTF\-8 specifications. 

 If the length of the constructed string is known, it is recommended to use [bytearrayMUTF8ToStringFast](#bytearrayMUTF8ToStringFast(byte[], int, int[], int)) instead.
parameter: data: bytes of the encoded string
parameter: pos: start position in the bytes buffer
parameter: readsize: optional one\-element output array
return: the string

## Static Method: bytearrayMUTF8ToStringFast
- parameter: `data`, type: `byte[]`
- parameter: `pos`, type: `int`
- parameter: `readsize`, type: `int[]`
- parameter: `expectedLength`, type: `int`
- return type: `java.lang.String`

Description: Decode a MUTF\-8 encoded string whose length is known. The encoded string must be terminated by a null \(0\) byte, per the JVM MUTF\-8 specifications.
parameter: data: bytes of the encoded string
parameter: pos: start position in the bytes buffer
parameter: readsize: optional one\-element output array
parameter: expectedLength: expected length of the constructed string \(in chars\); the method will            throw if the constructed string's length exceeds the expected length
return: the string

## Static Method: bytearraySLEB128ToInt
- parameter: `data`, type: `byte[]`
- parameter: `pos`, type: `int`
- parameter: `readsize`, type: `int[]`
- return type: `int`

Description: Read a signed LEB128\-encoded int.
parameter: data: input bytes
parameter: pos: read position
parameter: readsize: optional one\-element output array receiving the number of bytes read
return: the decoded signed integer

## Static Method: bytearrayULEB128P1ToInt
- parameter: `data`, type: `byte[]`
- parameter: `pos`, type: `int`
- parameter: `readsize`, type: `int[]`
- return type: `int`

Description: Read an unsigned LEB128\-encoded int shifted by 1.
parameter: data: input bytes
parameter: pos: read position
parameter: readsize: optional one\-element output array receiving the number of bytes read
return: the decoded unsigned integer minus one

## Static Method: bytearrayULEB128ToInt
- parameter: `data`, type: `byte[]`
- parameter: `pos`, type: `int`
- parameter: `readsize`, type: `int[]`
- return type: `int`

Description: Read an unsigned LEB128\-encoded int.
parameter: data: input bytes
parameter: pos: read position
parameter: readsize: optional one\-element output array receiving the number of bytes read
return: the decoded unsigned integer

## Static Method: bytearrayULEInt16ToInt
- parameter: `data`, type: `byte[]`
- parameter: `pos`, type: `int`
- return type: `int`

Description: Read a little\-endian uint16 short.
parameter: data: input bytes
parameter: pos: read position
return: the decoded unsigned 16\-bit integer

## Static Method: bytearrayULEInt32ToInt
- parameter: `data`, type: `byte[]`
- parameter: `pos`, type: `int`
- return type: `int`

Description: Read a little\-endian uint32 int.
parameter: data: input bytes
parameter: pos: read position
return: the decoded 32\-bit integer

## Static Method: convertDexFlagsToCodeFlags
- parameter: `nativeFlags`, type: `int`
- return type: `int`

Description: Convert native Dalvik flags to generic [ICodeItem](ICodeItem) flags.
parameter: nativeFlags: Dalvik access flags
return: generic code item flags

## Static Method: determineBestBase
- parameter: `value`, type: `long`
- return type: `int`

Description: Determine whether a numeric value is more readable in base 10 or base 16.
parameter: value: value to examine
return: 10 or 16

## Static Method: findAnnotation
- parameter: `dex`, type: `com.pnfsoftware.jeb.core.units.code.android.IDexUnit`
- parameter: `aicoll`, type: `java.util.Collection<com.pnfsoftware.jeb.core.units.code.android.dex.IDexAnnotationItem>`
- parameter: `requestedType`, type: `java.lang.String`
- parameter: `requestedVisibility`, type: `java.lang.Integer`
- return type: `com.pnfsoftware.jeb.core.units.code.android.dex.IDexAnnotation`

Description: Find an annotation by type and optional visibility.
parameter: dex: owner dex unit
parameter: aicoll: collection of annotation items
parameter: requestedType: mandatory annotation type \(internal signature\)
parameter: requestedVisibility: optional visibility \(see [IDexAnnotationItem](IDexAnnotationItem)\)
return: the annotation, or null

## Static Method: findAnnotationElement
- parameter: `dex`, type: `com.pnfsoftware.jeb.core.units.code.android.IDexUnit`
- parameter: `annotation`, type: `com.pnfsoftware.jeb.core.units.code.android.dex.IDexAnnotation`
- parameter: `name`, type: `java.lang.String`
- return type: `com.pnfsoftware.jeb.core.units.code.android.dex.IDexValue`

Description: Find an annotation element by name.
parameter: dex: owner dex unit
parameter: annotation: an annotation
parameter: name: the element name
return: the value associated with the element, or null

## Static Method: findInternalVirtualMethodTarget
- parameter: `dex`, type: `com.pnfsoftware.jeb.core.units.code.android.IDexUnit`
- parameter: `cl`, type: `com.pnfsoftware.jeb.core.units.code.android.dex.IDexClass`
- parameter: `mname`, type: `java.lang.String`
- parameter: `parameterTypes`, type: `java.lang.String[]`
- return type: `com.pnfsoftware.jeb.core.units.code.android.dex.IDexMethod`

Description: Check if a dex method is present in the provided class or if a super method is present in one of its super classes. For internal methods only.
parameter: dex: dex unit
parameter: cl: a class
parameter: mname: method name
parameter: parameterTypes: list of parameter signatures
return: the resolved internal dex method, or null

## Static Method: findPackageName
- parameter: `dex`, type: `com.pnfsoftware.jeb.core.units.code.android.IDexUnit`
- return type: `java.lang.String`

Description: Attempt to retrieve the package name of a Dex. The parent unit will be examined. If it is an APK unit, the [package name](IApkUnit#getPackageName()) will be returned.
parameter: dex: dex unit
return: the package name or null

## Static Method: findParentApk
- parameter: `dex`, type: `com.pnfsoftware.jeb.core.units.code.android.IDexUnit`
- return type: `com.pnfsoftware.jeb.core.units.code.android.IApkUnit`

Description: Attempt to retrieve the container APK unit of a Dex. The parent unit will be examined.
parameter: dex: dex unit
return: the apk unit or null

## Static Method: formatAccessFlags
- parameter: `f`, type: `int`
- parameter: `add_final_space`, type: `int`
- return type: `java.lang.String`

Description: Format Java access flags to an appropriate string.
parameter: f: Flags, as defined by the Dalvik specs
parameter: add_final_space: if 1, append a trailing space; if \-1, append a trailing space only if            the access flags string is not empty
return: the formatted access flags

## Static Method: formatFieldsigs
- parameter: `dex`, type: `com.pnfsoftware.jeb.core.units.code.android.IDexUnit`
- parameter: `indices`, type: `java.util.Collection<java.lang.Integer>`
- return type: `java.lang.String`

Description: Format a list of DEX fields.
parameter: dex: unit
parameter: indices: DEX method indices
return: a formatted list of field signatures

## Static Method: formatMethodsigs
- parameter: `dex`, type: `com.pnfsoftware.jeb.core.units.code.android.IDexUnit`
- parameter: `indices`, type: `java.util.Collection<java.lang.Integer>`
- return type: `java.lang.String`

Description: Format a list of DEX methods.
parameter: dex: unit
parameter: indices: DEX method indices
return: a formatted list of method signatures

## Static Method: formatTypenames
- parameter: `dex`, type: `com.pnfsoftware.jeb.core.units.code.android.IDexUnit`
- parameter: `indices`, type: `java.util.Collection<java.lang.Integer>`
- return type: `java.lang.String`

Description: Format a list of DEX types.
parameter: dex: unit
parameter: indices: DEX type indices
return: a formatted list of type names

## Static Method: generateDefaultJniNames
- parameter: `msig`, type: `java.lang.String`
- return type: `java.lang.String[]`

Description: Generate default JNI method names used for auto\-binding.
parameter: msig: java method signature \(e.g. `La/b/C;->foo(I)Ljava/lang/String;`\)
return: an array of two routine names \(with and without parameter signature\), or null on         error

## Static Method: getAnnotatedParameterNames
- parameter: `dex`, type: `com.pnfsoftware.jeb.core.units.code.android.IDexUnit`
- parameter: `md`, type: `com.pnfsoftware.jeb.core.units.code.android.dex.IDexMethodData`
- return type: `java.util.List<java.lang.String>`

Description: Retrieve the list of parameters names provided by a `MethodParameters` annotation.
parameter: dex: dex unit
parameter: md: method body
return: a list of names; null if no MethodParameters annotation 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

## Static Method: getDebugParameterNames
- parameter: `dex`, type: `com.pnfsoftware.jeb.core.units.code.android.IDexUnit`
- parameter: `md`, type: `com.pnfsoftware.jeb.core.units.code.android.dex.IDexMethodData`
- return type: `java.util.List<java.lang.String>`

Description: Retrieve the list of parameters names provided by the debug metadata of a dex method.
parameter: dex: dex unit
parameter: md: non\-abstract method body
return: 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

## Static Method: getMemberClasses
- parameter: `dex`, type: `com.pnfsoftware.jeb.core.units.code.android.IDexUnit`
- parameter: `c`, type: `com.pnfsoftware.jeb.core.units.code.android.dex.IDexClass`
- return type: `java.util.List<com.pnfsoftware.jeb.core.units.code.android.dex.IDexClass>`

Description: Get member classes for a class.
parameter: dex: dex unit
parameter: c: class
return: member classes

## Static Method: getMemberClasses
- parameter: `dex`, type: `com.pnfsoftware.jeb.core.units.code.android.IDexUnit`
- parameter: `m`, type: `com.pnfsoftware.jeb.core.units.code.android.dex.IDexMethod`
- return type: `java.util.List<com.pnfsoftware.jeb.core.units.code.android.dex.IDexClass>`

Description: Get member classes for a method.
parameter: dex: dex unit
parameter: m: method
return: member classes

## Static Method: getMethodParameterIndices
- parameter: `m`, type: `com.pnfsoftware.jeb.core.units.code.android.dex.IDexMethod`
- return type: `int[]`

Description: Retrieve an array of register indices holding the method parameters. Unlike `getMethodParametersInfo`, the list returned by this method includes \`this\` \(for non\-static methods\). Double\-slot variables are represented by their first register in the pair.
parameter: m: an internal, non\-abstract dex method
return: an array of register indices

## Static Method: getMethodParametersInfo
- parameter: `dex`, type: `com.pnfsoftware.jeb.core.units.code.android.IDexUnit`
- parameter: `md`, type: `com.pnfsoftware.jeb.core.units.code.android.dex.IDexMethodData`
- return type: `com.pnfsoftware.jeb.core.units.code.android.ParametersInfo`

Description: Generate method parameters' registers information.
parameter: dex: dex unit
parameter: md: method data
return: method parameter register information

## Static Method: getMethodParametersInfo
- parameter: `shorty`, type: `java.lang.String`
- parameter: `isStaticMethod`, type: `boolean`
- return type: `com.pnfsoftware.jeb.core.units.code.android.ParametersInfo`

Description: Generate method parameters' registers information.
parameter: shorty: shorty prototype string
parameter: isStaticMethod: true if the method is static
return: method parameter register information

## Static Method: getMethodSlotCount
- parameter: `shorty`, type: `java.lang.String`
- parameter: `isStaticMethod`, type: `boolean`
- return type: `int`

Description: Determine the number of slots required by a method to hold all of its parameters \(including \`this\` if the method is not static\).
parameter: shorty: method's shorty prototype, e.g. `BILJ` for            `byte foo(int, String, long)`, `V` for `void bar()`
parameter: isStaticMethod: true if the method is static
return: the number of parameter slots

## Static Method: getParentClass
- parameter: `dex`, type: `com.pnfsoftware.jeb.core.units.code.android.IDexUnit`
- parameter: `c`, type: `com.pnfsoftware.jeb.core.units.code.android.dex.IDexClass`
- return type: `com.pnfsoftware.jeb.core.units.code.android.dex.IDexClass`

Description: Get the parent class of a nested class.
parameter: dex: dex unit
parameter: c: class
return: the parent class, or null if none was found

## Static Method: getStaticFieldInitializer
- parameter: `c`, type: `com.pnfsoftware.jeb.core.units.code.android.dex.IDexClass`
- parameter: `fd`, type: `com.pnfsoftware.jeb.core.units.code.android.dex.IDexFieldData`
- return type: `com.pnfsoftware.jeb.core.units.code.android.dex.IDexValue`

Description: Retrieve the initial value of a static final class field.
parameter: c: a dex class object
parameter: fd: field definition of an internal field
return: the initial field value, null if none or on error

## Static Method: getStringSafe
- parameter: `dex`, type: `com.pnfsoftware.jeb.core.units.code.android.IDexUnit`
- parameter: `index`, type: `int`
- parameter: `defval`, type: `java.lang.String`
- return type: `java.lang.String`

Description: Retrieve a string value by index, returning a default value on error.
parameter: dex: dex unit
parameter: index: string pool index
parameter: defval: default value
return: the string value, or the default value

## Static Method: getSuperClass
- parameter: `dex`, type: `com.pnfsoftware.jeb.core.units.code.android.IDexUnit`
- parameter: `c`, type: `com.pnfsoftware.jeb.core.units.code.android.dex.IDexClass`
- return type: `com.pnfsoftware.jeb.core.units.code.android.dex.IDexClass`

Description: Get the superclass of a class.
parameter: dex: dex unit
parameter: c: class
return: the superclass, or null if none was found

## Static Method: getVersion
- parameter: `unit`, type: `com.pnfsoftware.jeb.core.units.IBinaryUnit`
- return type: `int`

Description: Extract the version number from an Android binary unit.
parameter: unit: an Android binary unit respecting the standard header \(xxxxNNN0\), such as dex,            vdex, cdex, art, etc.
return: the version number
throws: on parsing error

## Static Method: isClassname
- parameter: `s`, type: `java.lang.String`
- parameter: `validate`, type: `boolean`
- parameter: `elements`, type: `java.util.List<java.lang.String>`
- parameter: `dexVersion`, type: `int`
- return type: `boolean`

Description: Determine whether a string looks like a valid binary\-form \(dot\-separated\) class name. Arrays are not accepted.
parameter: s: the input string, e.g. `com.abc.Foo`
parameter: validate: if true, verify the legality of the simple names of the class name
parameter: elements: if non\-null, an output sink used to collect the simple names of the input            class name
parameter: dexVersion: optional dex version \(0 means latest\)
return: true if the string is a valid class name

## Static Method: isInternalClassname
- parameter: `s`, type: `java.lang.String`
- parameter: `validate`, type: `boolean`
- parameter: `elements`, type: `java.util.List<java.lang.String>`
- parameter: `dexVersion`, type: `int`
- return type: `boolean`

Description: Determine whether a string looks like a valid internal\-form \(jvm\) class name. Arrays are not accepted.
parameter: s: the input string, e.g. `Lcom/abc/Foo;`
parameter: validate: if true, verify the legality of the simple names of the class name
parameter: elements: if non\-null, an output sink used to collect the simple names of the input            class name
parameter: dexVersion: optional dex version \(0 means latest\)
return: true if the string is an internal class name

## Static Method: isInternalPackageName
- parameter: `s`, type: `java.lang.String`
- parameter: `validate`, type: `boolean`
- parameter: `elements`, type: `java.util.List<java.lang.String>`
- parameter: `dexVersion`, type: `int`
- return type: `boolean`

Description: Determine whether a string looks like a valid internal\-form \(jvm\) package name.
parameter: s: the input string, e.g. `Lcom/abc/`
parameter: validate: if true, verify the legality of the simple names of the package name
parameter: elements: if non\-null, an output sink used to collect the simple names of the input            package name
parameter: dexVersion: optional dex version \(0 means latest\)
return: true if the string is an internal package name

## Static Method: isSimpleName
- parameter: `s`, type: `java.lang.String`
- parameter: `dexVersion`, type: `int`
- return type: `boolean`

Description: Verify if the provided string is a valid dex `SimpleName`. 

 Ref: https://source.android.com/docs/core/runtime/dex\-format\#simplename
parameter: s: a Dalvik simple name, such as a non\-qualified class/method/field name
parameter: dexVersion: optional dex version; 0 means latest
return: true if the string is a valid simple name

## Static Method: isSubtypeOf
- parameter: `dex`, type: `com.pnfsoftware.jeb.core.units.code.android.IDexUnit`
- parameter: `typeIndex`, type: `int`
- parameter: `candidateParentTypeIndex`, type: `int`
- return type: `boolean`

Description: Determine whether a type is a subtype of another type.
parameter: dex: dex unit
parameter: typeIndex: type index
parameter: candidateParentTypeIndex: candidate parent type index
return: true if the type is a subtype of the candidate parent

## Static Method: parseSimpleName
- parameter: `s`, type: `java.lang.String`
- parameter: `start`, type: `int`
- parameter: `dexVersion`, type: `int`
- return type: `int`

Description: Determine if the token at the provided index is the start of a `SimpleName`. The end offset is provided. 

 Ref: https://source.android.com/docs/core/runtime/dex\-format\#simplename
parameter: s: a string
parameter: start: simple name start offset
parameter: dexVersion: optional dex version; 0 means latest
return: token end offset, \-1 on error

## Static Method: stringFromMUTF8
- parameter: `data`, type: `byte[]`
- return type: `java.lang.String`

Description: Decode a String encoded as MUTF\-8.
parameter: data: MUTF\-8 buffer \(always zero\-terminated\)
return: the string

## Static Method: stringToMUTF8
- parameter: `str`, type: `java.lang.String`
- return type: `byte[]`

Description: Encode a String to MUTF\-8.
parameter: str: a string
return: a MUTF\-8 byte buffer \(always zero\-terminated\)

## Static Method: stringToMUTF8
- parameter: `str`, type: `java.lang.String`
- parameter: `appendZero`, type: `boolean`
- return type: `byte[]`

Description: Encode a String to MUTF\-8.
parameter: str: a string
parameter: appendZero: if true, a zero\-byte is appended to the resulting buffer
return: a MUTF\-8 byte buffer

## Static Method: toUserFriendlyFieldSignature
- parameter: `fsig`, type: `java.lang.String`
- parameter: `fullyQualifiedTypeNames`, type: `boolean`
- return type: `java.lang.String`

Description: Generate a user\-friendly field signature from an internal field signature.
parameter: fsig: internal field signature, e.g. `La/b/C;->f:Ljava/lang/String;`
parameter: fullyQualifiedTypeNames: if true, type signatures will be fully qualified \(e.g. `java.lang.String`\)
return: the user\-friendly field signature

## Static Method: toUserFriendlyMethodSignature
- parameter: `msig`, type: `java.lang.String`
- parameter: `fullyQualifiedTypeNames`, type: `boolean`
- return type: `java.lang.String`

Description: Generate a user\-friendly method signature from an internal method signature.
parameter: msig: internal method signature, e.g. `La/b/C;->foo(I)Ljava/lang/String;`
parameter: fullyQualifiedTypeNames: if true, type signatures will be fully qualified \(e.g.            `java.lang.String`\)
return: the user\-friendly method signature

## Static Method: toUserFriendlyTypeSignature
- parameter: `tsig`, type: `java.lang.String`
- parameter: `fullyQualified`, type: `boolean`
- return type: `java.lang.String`

Description: Generate a user\-friendly type signature from an internal type signature.
parameter: tsig: internal type signature, e.g. `Ljava/lang/String;` or `[I` or `J`
parameter: fullyQualified: if true, type signatures will be fully qualified \(e.g. `java.lang.String`\)
return: the user\-friendly type signature

## Static Method: validateClassFlags
- parameter: `f`, type: `int`

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

## Static Method: validateFieldFlags
- parameter: `f`, type: `int`

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

## Static Method: validateFlags
- parameter: `f`, type: `int`

Description: Validate Dalvik flags: this method throws if some flags are undefined Dalvik flags.
parameter: f: Dalvik access flags

## Static Method: validateMethodFlags
- parameter: `f`, type: `int`

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

