# 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: 
parameter: pos: 
parameter: readsize: 
return: 

## 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: 
parameter: pos: 
parameter: readsize: 
return: 

## 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: 
parameter: pos: 
parameter: readsize: 
return: 

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

Description: Read a little\-endian uint16 short.
parameter: data: 
parameter: pos: 
return: 

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

Description: Read a little\-endian uint32 int.
parameter: data: 
parameter: pos: 
return: 

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

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

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


## 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: 

## 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: 

## 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: 

## 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: 

## 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: 
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: 
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: 
parameter: dex: 
parameter: c: 
return: 

## 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: 
parameter: dex: 
parameter: m: 
return: 

## 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: 
parameter: md: 
return: 

## 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: 
parameter: isStaticMethod: 
return: 

## 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: 
return: 

## 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: 
parameter: dex: 
parameter: c: 
return: 

## 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`


## 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`


## 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: 

## 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: 

## 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: 

## 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: 

## 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: 
parameter: dex: 
parameter: typeIndex: 
parameter: candidateParentTypeIndex: 
return: 

## 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: 

## 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: 

## 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: 

## 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: 

## 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: 

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

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

## 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: 

