Interface IDexUnit
- All Superinterfaces:
- IAddressableUnit,- ICodeUnit,- IEventSource,- IInteractiveUnit,- IUnit,- IUnitCreator,- IUserDataSupport
 Dex units use Java-style internal addresses to identify items:
 - package: Lcom/abc/
 - type: Lcom/abc/Foo;
 - method: Lcom/abc/Foo;->bar(I[JLjava/Lang/String;)V
 - field: Lcom/abc/Foo;->flag1:Z
 More information here.
 
 Note that in the case of multi-Dex APKs, the Dex unit represents a virtual, unified view of the
 separate Dex files contained in the APK. If required, the individual information about those Dex
 files can be retrieved via IDexFile.
 
 Like many units, Dex unit objects emit J.UnitChange when the unit contents is being
 changed. IDexUnit set up event objects such that JebEvent.getData() will return a
 UnitChangeEventData with fields reasonably populated.
 
 How use the JEB API to interact with those objects?
 - Writing JEB client scripts in Python is a great way to ease into the JEB API.
 - Visit this public
 GitHub repository for sample code
 - In the JEB client, use F2 to bring up the script manager, and try out some sample scripts
 
 Below is a sample client script that shows how to retrieve a project, find the main dex unit,
 enumerate dex methods, check the bytecode and search for specific instructions.
 File: ListDexMethodsWithXor.py
 
 
#?description=List dex methods making use of xor instructions
#?shortcut=
from com.pnfsoftware.jeb.client.api import IScript
from com.pnfsoftware.jeb.core.units.code.android import IDexUnit
class ListDexMethodsWithXor(IScript):
  def run(self, ctx):
    prj = ctx.getMainProject()
    assert prj, 'Need a project'
    dex = prj.findUnit(IDexUnit)
    assert dex, 'Need a dex unit'
    cnt = 0
    for m in dex.getMethods():
      if m.isInternal():
        ci = m.getData().getCodeItem()
        if ci and self.checkMethod(ci):
          print(m.getSignature(True, False))
          cnt += 1
    print('Found %d methods' % cnt)
  def checkMethod(self, ci):
    for insn in ci.getInstructions():
      if insn.toString().find('xor-') >= 0:
        return True
    return False
 - 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intInlining mode: allowed.static final intInlining mode: auto-determined.static final intInlining mode: blocked.static final intInlining mode: forced.static final intstatic final intstatic final intDo not use directly - reserved by dex decompilersstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final String
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdd (merge) an additional Dex file into this Dex unit.Create a new field and add it to the field pool index.Create a new field and add it to the field pool index.Create a new method reference and add it to the method pool index.addPackage(String signature) addPrototype(String prototypeString) Create a new Dex prototype and add it to the prototype pool index.Create a new string and add it to the string pool index.Create a new type and add it to the type pool index.intRetrieve the pool index of a string, by value.intgetCallSite(int index) List<? extends IDexCallSite>getClass(int index) Convenience method to retrieve a class by its Dex class pool index.Convenience method used to retrieve a class by name.Get the Dex class poolGet the comment manager.Retrieve the constant library object.Retrieve the context information provider.intRetrieve the count of dex entries managed by this unit.default intDeprecated.getCrossReferences(DexPoolType poolType, int index) Retrieve a list of addresses referencing the provided pool item.getCrossReferences(DexPoolType poolType, int index, int cap) Retrieve a list of addresses referencing the provided pool item.Retrieve or create a decompiler for this unit.Retrieve the collection of dex entries managed by this dex unit.getDexEntry(int index) Retrieve a dex entry by index.default IDexFilegetDexFile(int index) Deprecated.Deprecated.usegetDexEntries()This convenience method provides the entire disassembly of the bytecode making up the Dex file.Convenience method to retrieve the text document representing the disassembly of this code unit.getField(int index) Convenience method to retrieve a field by its Dex field pool index.Convenience method used to retrieve a field by name.Get the Dex field poollongRetrieve the total amount of instructions in this Dex unit.getMethod(int index) Convenience method to retrieve a method by its Dex method pool index.Convenience method used to retrieve a method by name.getMethodHandle(int index) List<? extends IDexMethodHandle>List<? extends IDexMethod>Get the Dex method poolgetObjectById(long id) Feature preview.getPackage(String signature) List<? extends IDexPackage>Get the list of code packages.getPrototype(int index) Convenience method to retrieve a prototype by its Dex prototype pool index.List<? extends IDexPrototype>Get the list of Dex prototypes defined in the Dex file (prototype pool).Retrieve the cross-references manager.Retrieve a map of renamed identifiers.getStaticFieldInitializer(int index) Retrieve the initializer for the static field of a class.getString(int index) Convenience method to retrieve a string by its Dex string pool index.intGet the number of strings present in the aggregated string pools represented by this Dex unit.List<? extends IDexString>Get the Dex string pool, including extra strings added viaaddString.getType(int index) Retrieve a type by its Dex type pool index.Retrieve a type by its fully-qualified name.getTypeHierarchy(String typesig, int maxNodeCount, boolean includeSuperTypes) getTypes()Get the Dex prototype pooldefault booleanMove a class or a package to another package, class, or method.booleanMove a class or a package to another package, class, or method.Methods inherited from interface com.pnfsoftware.jeb.core.units.IAddressableUnitgetAddressLabel, getAddressLabels, getAddressOfItem, getCanonicalAddress, getItemAtAddress, getItemObject, getRelatedItems, getWellKnownAddresses, isValidAddressMethods inherited from interface com.pnfsoftware.jeb.core.units.code.ICodeUnitgetAddressFromCodeCoordinates, getCodeCoordinatesFromAddress, getCodeItemByAddress, getHierarchyMethods inherited from interface com.pnfsoftware.jeb.util.events.IEventSourceaddListener, countListeners, getListeners, getParentSource, insertListener, notifyListeners, removeListener, setParentSourceMethods inherited from interface com.pnfsoftware.jeb.core.units.IInteractiveUnitaddressToLocation, canExecuteAction, executeAction, executeAction, getAddressActions, getFullComment, getFullComments, getGlobalActions, getInlineComment, getInlineComments, getItemActions, getMetadataManager, locationToAddress, prepareExecution, setInlineCommentMethods inherited from interface com.pnfsoftware.jeb.core.units.IUnitaddChild, addChild, canBePersisted, dispose, execprvfunc, generateQuickState, getChildren, getContributions, getCreationTimestamp, getDescription, getExtraInputs, getFormatter, getFormatType, getIconData, getInput, getInterpreters, getLock, getName, getNotes, getNotificationManager, getParent, getParentArtifact, getParentProject, getPropertyDefinitionManager, getPropertyManager, getRealName, getStatus, getUid, getUnitProcessor, initializePropertyObjects, isDisposed, isProcessed, isStale, isTransientChild, notifyGenericChange, postDeserialization, process, removeChild, setName, setNotes, setParent, setRealName, setUnitProcessorMethods inherited from interface com.pnfsoftware.jeb.core.IUserDataSupportclearAllData, getAllData, getData, setData
- 
Field Details- 
ACC_PUBLICstatic final int ACC_PUBLIC- See Also:
 
- 
ACC_PRIVATEstatic final int ACC_PRIVATE- See Also:
 
- 
ACC_PROTECTEDstatic final int ACC_PROTECTED- See Also:
 
- 
ACC_STATICstatic final int ACC_STATIC- See Also:
 
- 
ACC_FINALstatic final int ACC_FINAL- See Also:
 
- 
ACC_SYNCHRONIZEDstatic final int ACC_SYNCHRONIZED- See Also:
 
- 
ACC_VOLATILEstatic final int ACC_VOLATILE- See Also:
 
- 
ACC_BRIDGEstatic final int ACC_BRIDGE- See Also:
 
- 
ACC_TRANSIENTstatic final int ACC_TRANSIENT- See Also:
 
- 
ACC_VARARGSstatic final int ACC_VARARGS- See Also:
 
- 
ACC_NATIVEstatic final int ACC_NATIVE- See Also:
 
- 
ACC_INTERFACEstatic final int ACC_INTERFACE- See Also:
 
- 
ACC_ABSTRACTstatic final int ACC_ABSTRACT- See Also:
 
- 
ACC_STRICTstatic final int ACC_STRICT- See Also:
 
- 
ACC_SYNTHETICstatic final int ACC_SYNTHETIC- See Also:
 
- 
ACC_ANNOTATIONstatic final int ACC_ANNOTATION- See Also:
 
- 
ACC_ENUMstatic final int ACC_ENUM- See Also:
 
- 
ACC_CONSTRUCTORstatic final int ACC_CONSTRUCTOR- See Also:
 
- 
ACC_DECLARED_SYNCHRONIZEDstatic final int ACC_DECLARED_SYNCHRONIZED- See Also:
 
- 
INLINE_AUTOstatic final int INLINE_AUTOInlining mode: auto-determined. This mode is to be understood as 'limited', that is, inlining is blocked except for trivial cases- See Also:
 
- 
INLINE_BLOCKEDstatic final int INLINE_BLOCKEDInlining mode: blocked. The method must not be inlined by code processors.- See Also:
 
- 
INLINE_ALLOWEDstatic final int INLINE_ALLOWEDInlining mode: allowed. The method may be inlined by code processors.- See Also:
 
- 
INLINE_FORCEDstatic final int INLINE_FORCEDInlining mode: forced. The method should be inlined by code processors if possible.- See Also:
 
- 
itagItemIdShiftstatic final int itagItemIdShift- See Also:
 
- 
itagBitsizestatic final int itagBitsize- See Also:
 
- 
ITAG_STRINGstatic final int ITAG_STRING- See Also:
 
- 
ITAG_PACKAGEstatic final int ITAG_PACKAGE- See Also:
 
- 
ITAG_TYPEstatic final int ITAG_TYPE- See Also:
 
- 
ITAG_CLASSstatic final int ITAG_CLASS- See Also:
 
- 
ITAG_FIELDstatic final int ITAG_FIELD- See Also:
 
- 
ITAG_METHODstatic final int ITAG_METHOD- See Also:
 
- 
ITAG_BYTECODEstatic final int ITAG_BYTECODE- See Also:
 
- 
ITAG_PARAMETERstatic final int ITAG_PARAMETER- See Also:
 
- 
ITAG_VARIABLEstatic final int ITAG_VARIABLE- See Also:
 
- 
ITAG_IMMEDIATEstatic final int ITAG_IMMEDIATE- See Also:
 
- 
ITAG_VIRTUAL_VARstatic final int ITAG_VIRTUAL_VAR- See Also:
 
- 
ITAG_CUSTOMstatic final int ITAG_CUSTOMDo not use directly - reserved by dex decompilers- See Also:
 
- 
propnameContextInfoDb- See Also:
 
 
- 
- 
Method Details- 
getCountOfDexEntriesint getCountOfDexEntries()Retrieve the count of dex entries managed by this unit.- Returns:
 
- 
getCountOfDexFilesdefault int getCountOfDexFiles()Deprecated.
- 
getDexEntriesRetrieve the collection of dex entries managed by this dex unit.When the unit is the result of processing a multi-dex APK, dex files containing multiple dex entries (container dex, version 41+), or if the unit received additional dex files, this method will return a list with multiple items.- Returns:
- a non-empty collection of dex entries
 
- 
getDexFilesDeprecated.usegetDexEntries()
- 
getDexEntryRetrieve a dex entry by index.- Parameters:
- index- an index
- Returns:
- the dex entry
 
- 
getDexFileDeprecated.
- 
findStringIndexRetrieve the pool index of a string, by value.- Parameters:
- s- a string
- Returns:
- an string pool index, -1 if the string was not found
 
- 
getStringsList<? extends IDexString> getStrings()Get the Dex string pool, including extra strings added viaaddString.- Specified by:
- getStringsin interface- ICodeUnit
- Returns:
 
- 
getStringConvenience method to retrieve a string by its Dex string pool index.- Parameters:
- index-
- Returns:
 
- 
getStringCountint getStringCount()Get the number of strings present in the aggregated string pools represented by this Dex unit.- Returns:
 
- 
addStringCreate a new string and add it to the string pool index.- Parameters:
- value-
- Returns:
 
- 
getPrototypesList<? extends IDexPrototype> getPrototypes()Get the list of Dex prototypes defined in the Dex file (prototype pool).- Returns:
- a list of prototypes
 
- 
getPrototypeConvenience method to retrieve a prototype by its Dex prototype pool index.- Parameters:
- index- prototype index
- Returns:
 
- 
addPrototypeCreate a new Dex prototype and add it to the prototype pool index.- Parameters:
- prototypeString- a full prototype string, such as:- (typeParam1,typeParam2,...)typeReturn
- Returns:
 
- 
getTypesGet the Dex prototype pool
- 
getTypeRetrieve a type by its Dex type pool index.- Parameters:
- index-
- Returns:
 
- 
getTypeRetrieve a type by its fully-qualified name.- Parameters:
- fqname- eg,- Lcom/foo/Bar;
- Returns:
 
- 
addTypeCreate a new type and add it to the type pool index.- Parameters:
- typeString- a fully-qualified type name, using the standard Java internal signature notation (- L...;)
- Returns:
 
- 
getBadTypeCountint getBadTypeCount()- Returns:
 
- 
getClassDescription copied from interface:ICodeUnitConvenience method used to retrieve a class by name.
- 
getClassesGet the Dex class pool- Specified by:
- getClassesin interface- ICodeUnit
- Returns:
 
- 
getClassConvenience method to retrieve a class by its Dex class pool index.- Parameters:
- index-
- Returns:
 
- 
getFieldsGet the Dex field pool
- 
getFieldDescription copied from interface:ICodeUnitConvenience method used to retrieve a field by name.
- 
getFieldConvenience method to retrieve a field by its Dex field pool index.- Parameters:
- index-
- Returns:
 
- 
getStaticFieldInitializerRetrieve the initializer for the static field of a class.- Parameters:
- index- the field index
- Returns:
- the static initializer, or null if there's none
 
- 
addFieldCreate a new field and add it to the field pool index.- Parameters:
- signature- full, eg- Lcom/foo/Bar;->val:I
- Returns:
 
- 
addFieldCreate a new field and add it to the field pool index.- Parameters:
- type- full, eg- Lcom/foo/Bar;->val:I
- fieldname- simple name
- fieldtype- full, eg- Lcom/foo/Bar;->val:I
- Returns:
 
- 
getMethodsList<? extends IDexMethod> getMethods()Get the Dex method pool- Specified by:
- getMethodsin interface- ICodeUnit
- Returns:
 
- 
getMethodDescription copied from interface:ICodeUnitConvenience method used to retrieve a method by name.
- 
getMethodConvenience method to retrieve a method by its Dex method pool index.- Parameters:
- index-
- Returns:
 
- 
addMethodCreate a new method reference and add it to the method pool index.- Parameters:
- signature- full signature, including type name, eg:- La/b/Foo;->bar(ILjava/lang/String;)Z
- Returns:
 
- 
addMethod- Parameters:
- type-
- methodname-
- protostring-
- Returns:
 
- 
getCallSite- Parameters:
- index-
- Returns:
 
- 
getCallSitesList<? extends IDexCallSite> getCallSites()- Returns:
 
- 
getMethodHandle- Parameters:
- index-
- Returns:
 
- 
getMethodHandlesList<? extends IDexMethodHandle> getMethodHandles()- Returns:
 
- 
getPackagesList<? extends IDexPackage> getPackages()Description copied from interface:ICodeUnitGet the list of code packages.- Specified by:
- getPackagesin interface- ICodeUnit
- Returns:
 
- 
getPackage- Parameters:
- signature- fully-qualified package name, e.g.- com.foo.bar
- Returns:
 
- 
addPackage- Parameters:
- signature- fully-qualified package name, e.g.- com.foo.bar
- Returns:
 
- 
moveToMove a class or a package to another package, class, or method.- Parameters:
- src- an- IDexPackageor- IDexClass
- dst- an- IDexPackage,- IDexClassor- IDexMethod
- skipChecks- skip extra sanity checks (if applicable)
- neverAnonymous- legal only when moving a class to another method (else N/A); if true, the moved class will never be made an anonymous class of the destination method; if false, an anonymous class will be favored, if it is possible to do so
- Returns:
- success indicator
 
- 
moveToMove a class or a package to another package, class, or method. Checks are not skipped; whne moving a class to a method, the class will be made anonymous.- Parameters:
- src- an- IDexPackageor- IDexClass
- dst- an- IDexPackage,- IDexClassor- IDexMethod
- Returns:
- success indicator
 
- 
getInstructionCountlong getInstructionCount()Retrieve the total amount of instructions in this Dex unit. Note that if this unit represents the virtual Dex file resulting from the merge of several classesX.dex files, the number of instructions returned is the sum of instructions of each individual Dex file.- Returns:
 
- 
getDisassemblyDocumentIDexDisassemblyDocument getDisassemblyDocument()Description copied from interface:ICodeUnitConvenience method to retrieve the text document representing the disassembly of this code unit.The caller is responsible for disposing the returned document after usage. - Specified by:
- getDisassemblyDocumentin interface- ICodeUnit
- Returns:
 
- 
getDisassemblyString getDisassembly()This convenience method provides the entire disassembly of the bytecode making up the Dex file. This method is a convenience method: the disassembly text document object can always be retrieved viaIUnit.getFormatter().- Specified by:
- getDisassemblyin interface- ICodeUnit
- Returns:
 
- 
getCrossReferencesRetrieve a list of addresses referencing the provided pool item. This method is left for convenience and legacy only. Newer scripts should usegetReferenceManager().- Parameters:
- poolType- pool item type; currently supported for xrefs: STRING, TYPE, FIELD, METHOD
- index- pool item index
- cap- max number of references to return (leave to 0 to mean return everything possible)
- Returns:
 
- 
getCrossReferencesRetrieve a list of addresses referencing the provided pool item. This method is left for convenience and legacy only. Newer scripts should usegetReferenceManager().- Parameters:
- poolType- pool item type; currently supported for xrefs: STRING, TYPE, FIELD, METHOD
- index- pool item index
- Returns:
 
- 
getReferenceManagerIDexReferenceManager getReferenceManager()Retrieve the cross-references manager.- Returns:
 
- 
getCommentManagerDexCommentManager getCommentManager()Description copied from interface:IInteractiveUnitGet the comment manager. This method is optional. When the unit is disposed, this method must return null. The default implementation returns null.- Specified by:
- getCommentManagerin interface- ICodeUnit
- Specified by:
- getCommentManagerin interface- IInteractiveUnit
- Returns:
- a comment manager, or null if the unit does not have one
 
- 
getRenamedIdentifiersMap<IdentifierCoordinates,String> getRenamedIdentifiers()Retrieve a map of renamed identifiers. Only renamed identifiers are stored in the returned object.- Returns:
 
- 
getObjectByIdFeature preview.- Parameters:
- id-
- Returns:
 
- 
addDexAdd (merge) an additional Dex file into this Dex unit.- Parameters:
- dexInput- a Dex- input(file input, bytes input, etc.) or a ZIP input containing a single- classes.dexentry
- Throws:
- IOException
 
- 
getConstantsLibraryDexConstantLibrary getConstantsLibrary()Retrieve the constant library object. The constants library holds the constant fields of this dex unit (that is, allstatic finalfields ,regardless of their visibility attributes) as well as values attached to pure field references (external fields)- Returns:
 
- 
getContextInfoProviderIDexContextInfoProvider getContextInfoProvider()Retrieve the context information provider. This provider can be used to retrieve methods' context access information (context-sensitivity, side-effect) and fields' effective finality information.- Returns:
 
- 
getDecompilerIDexDecompilerUnit getDecompiler()Retrieve or create a decompiler for this unit. Ifdexdec(the Dex Decompiler module) is not available with your JEB license, null is returned.- Returns:
 
- 
getTypeHierarchy- Parameters:
- typesig-
- maxNodeCount-
- includeSuperTypes-
- Returns:
 
 
- 
getCountOfDexEntries()