Python reference¶
Every class and function of the dexpp module. The pages are generated from
the type stubs that ship with the package, so they match what your editor and
type checker see.
| Page | Main names |
|---|---|
| APK, manifest, resources, signing | Apk, Manifest, Component, IntentFilter, ComponentKind, ResourceTable and more |
| Context, classes, methods, fields | AnalysisContext, Class, ClassRef, Method, Field, MethodId and more |
| Annotations and values | Annotation, AnnotationVisibility, AnnotationValue, TypeValue, EnumValue, FieldValue and more |
| Instructions | opcode_name, to_string, Instruction, InstructionBase, OperandWidth, NopInstruction and more |
| Control-flow graph | Cfg, BasicBlock, CfgEdge, CfgEdgeKind, BasicBlockView |
| Call graph | CallGraph, CallNode, CallEdge, InvokeKind, EdgeOrigin, CallNodeView and more |
| Class hierarchy and cross-references | ClassHierarchy, Xrefs, MethodXref, FieldXref, StringXref, TypeXref and more |
| Editable DEX model | Model, ClassInfo, PoolStats, Problem |
| Errors | Error, InvalidApkError, InvalidDexError, UnsupportedDexError, ModelError, InvalidModelError and more |
Conventions¶
- Descriptors. Classes and types are named by DEX descriptors, such as
Lcom/example/Foo;, andClass.descriptorgives a class's own one. See Concepts. - Not found is
None. A lookup that finds nothing returnsNone. It does not raise. - Errors. A path that does not exist raises the built-in
FileNotFoundError, and one that exists but cannot be read raisesOSError. A file or a model that dexpp cannot use raises one of dexpp's own exceptions, which all derive fromdexpp.Error. See Errors. - Enums.
InvokeKind,CfgEdgeKindand the other enums areenum.Enumclasses. Compare members withisor==, readkind.nameandkind.value, and iterate the class to list its members. A member is not a number:int(kind)raisesTypeError, andkind.valuegives the number.AccessFlagsis different: it is anenum.IntFlag, so its members are also ints. - Properties and methods. A property is cheap or cached: reading it does
little work, or returns something that was built once and kept, such as
cls.methodsorctx.call_graph. A method computes: it does its work again on every call, such asctx.classes(), which makes a new object for every class,ctx.strings(), which copies the whole string table, ormodel.pool_stats(), which walks the whole model. Keep the result of a method when you need it more than once. - Views.
CallGraph.nodes,CallGraph.edges,Xrefs.referrersandCfg.blocksandMethod.instructionsare read-only sequences that do not copy the data. They supportlen(), indexing, slicing and iteration. - Equality.
Class,Method,FieldandClassRefobjects are equal when they point at the same class, method or field of the same analysis, so they work as dictionary keys and in sets. One analysis is oneAnalysisContext, or every result ofApk.analysis()on oneApk. The same file loaded twice gives two analyses, and their objects are not equal. Identities (MethodId,FieldId) and the small value classes (TypeValue,ResourceNameand the like) are equal when their content is equal. - Lifetime. You never have to keep the
AnalysisContextorApkaround yourself. Handles, views, the call graph, the class hierarchy, the cross-reference index, aCfg, and an APK'sManifest,ResourceTableandSigningInfokeep the analysis or APK they came from alive. Small value objects, such asStringLoad,CfgEdge,BasicBlockorMethodId, hold their own copy of their data instead.
The version of the installed package is dexpp.__version__.