pub struct DexFile {
pub class_defs: Vec<ClassDef>,
pub version: String,
/* private fields */
}Expand description
A parsed DEX image.
Id tables and class defs are parsed eagerly; code items, class data and
annotations are materialized on demand. All accessors degrade to
sentinels/None on out-of-range indices instead of panicking.
Fields§
§class_defs: Vec<ClassDef>§version: StringImplementations§
Source§impl DexFile
impl DexFile
pub fn parse(data: Vec<u8>) -> Result<DexFile, String>
Sourcepub fn raw(&self) -> &[u8] ⓘ
pub fn raw(&self) -> &[u8] ⓘ
The raw image, or empty once retired.
SAFETY of the lifetime: the bytes live in an Arc<Vec<u8>> whose
clone is moved into a self-owned stash (raw_keep) that outlives
every later call — each call swaps the stash, keeping the previous
slice alive only for the previous caller, which is unsound in
general. The callers here hold the slice only inside one method
(code_at / parse-time table walks) and never across calls, and
single-call scope is the documented contract; the alternative
(returning a guard) would infect every parser signature.
Sourcepub fn release_data(&mut self)
pub fn release_data(&mut self)
Drop the inflated image (tables stay usable; code accessors return empty). Call only when no further code decoding will happen.
Sourcepub fn mark_released(&self)
pub fn mark_released(&self)
Mark the image retired through a shared reference: code accessors go empty immediately; the bytes themselves drop when the last Arc snapshot drops (workers hold snapshots only mid-class, so the memory is reclaimed as chunks complete).
pub fn string(&self, idx: u32) -> &str
pub fn string_count(&self) -> usize
Sourcepub fn class_name(&self, idx: u32) -> String
pub fn class_name(&self, idx: u32) -> String
Type id → CLASS internal name (java/lang/String), descriptor
stripped; array descriptors pass through unchanged.
Sourcepub fn type_name(&self, idx: u32) -> &str
pub fn type_name(&self, idx: u32) -> &str
Type id → descriptor string (Ljava/lang/String;, [I, …).
pub fn type_count(&self) -> usize
pub fn proto(&self, idx: u32) -> &ProtoId
Sourcepub fn string_arc(&self, idx: u32) -> Arc<str> ⓘ
pub fn string_arc(&self, idx: u32) -> Arc<str> ⓘ
Parameter type ids of a proto (empty for (V)).
Shared clone of a table string (the pool’s method names).
Sourcepub fn proto_desc(&self, idx: u32) -> Arc<str> ⓘ
pub fn proto_desc(&self, idx: u32) -> Arc<str> ⓘ
Method descriptor of a proto as a shared clone.
Sourcepub fn proto_params(&self, idx: u32) -> &[u32]
pub fn proto_params(&self, idx: u32) -> &[u32]
Parameter type ids of a proto, resolved once at parse (shared
slice; the old per-call type_list re-read is gone).
pub fn field(&self, idx: u32) -> &FieldId
pub fn field_count(&self) -> usize
pub fn method(&self, idx: u32) -> &MethodId
pub fn method_count(&self) -> usize
Sourcepub fn class_def_of(&self, type_idx: u32) -> Option<usize>
pub fn class_def_of(&self, type_idx: u32) -> Option<usize>
Class def index for a type descriptor, when this DEX defines it.
Sourcepub fn interfaces_of(&self, cd: &ClassDef) -> Vec<u32>
pub fn interfaces_of(&self, cd: &ClassDef) -> Vec<u32>
Interfaces of a class def as type ids.
pub fn class_data(&self, cd: &ClassDef) -> ClassData
Sourcepub fn code_stats(&self, off: u32) -> Option<(u16, u32)>
pub fn code_stats(&self, off: u32) -> Option<(u16, u32)>
(registers_size, insns_size) read straight from the code_item header — no instruction decoding. Hot path for risk checks.
Sourcepub fn debug_info_off_at(&self, off: u32) -> Option<u32>
pub fn debug_info_off_at(&self, off: u32) -> Option<u32>
debug_info_off straight from the code_item header (pool building).
pub fn code_at(&self, off: u32) -> Option<CodeItem>
Sourcepub fn class_names_from_image(image: &[u8]) -> Vec<String>
pub fn class_names_from_image(image: &[u8]) -> Vec<String>
Class descriptors straight from an inflated image, WITHOUT a full
DexFile::parse (which decodes the whole string table — the class
names are a small slice of it). Class listing pays for exactly what
it prints.
Sourcepub fn code_insns_bytes_at(&self, off: u32) -> Option<&[u8]>
pub fn code_insns_bytes_at(&self, off: u32) -> Option<&[u8]>
The raw insns byte section of one code item (zero-copy) for the boundary-walking scan path — skips try tables and full decode.
Sourcepub fn static_values(&self, off: u32) -> Vec<EncodedValue>
pub fn static_values(&self, off: u32) -> Vec<EncodedValue>
Static field initial values (aligned with static_fields order).
Sourcepub fn method_handle(&self, idx: u32) -> Option<&MethodHandleItem>
pub fn method_handle(&self, idx: u32) -> Option<&MethodHandleItem>
method_handle_item by index.