Skip to main content

DexFile

Struct DexFile 

Source
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: String

Implementations§

Source§

impl DexFile

Source

pub fn parse(data: Vec<u8>) -> Result<DexFile, String>

Source

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.

Source

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.

Source

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).

Source

pub fn string(&self, idx: u32) -> &str

Source

pub fn string_count(&self) -> usize

Source

pub fn class_name(&self, idx: u32) -> String

Type id → CLASS internal name (java/lang/String), descriptor stripped; array descriptors pass through unchanged.

Source

pub fn type_name(&self, idx: u32) -> &str

Type id → descriptor string (Ljava/lang/String;, [I, …).

Source

pub fn type_count(&self) -> usize

Source

pub fn proto_count(&self) -> usize

Source

pub fn proto(&self, idx: u32) -> &ProtoId

Source

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).

Source

pub fn proto_desc(&self, idx: u32) -> Arc<str> ⓘ

Method descriptor of a proto as a shared clone.

Source

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).

Source

pub fn field(&self, idx: u32) -> &FieldId

Source

pub fn field_count(&self) -> usize

Source

pub fn method(&self, idx: u32) -> &MethodId

Source

pub fn method_count(&self) -> usize

Source

pub fn class_def_of(&self, type_idx: u32) -> Option<usize>

Class def index for a type descriptor, when this DEX defines it.

Source

pub fn interfaces_of(&self, cd: &ClassDef) -> Vec<u32>

Interfaces of a class def as type ids.

Source

pub fn class_data(&self, cd: &ClassDef) -> ClassData

Source

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.

Source

pub fn debug_info_off_at(&self, off: u32) -> Option<u32>

debug_info_off straight from the code_item header (pool building).

Source

pub fn code_at(&self, off: u32) -> Option<CodeItem>

Source

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.

Source

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.

Source

pub fn static_values(&self, off: u32) -> Vec<EncodedValue>

Static field initial values (aligned with static_fields order).

Source

pub fn method_handle(&self, idx: u32) -> Option<&MethodHandleItem>

method_handle_item by index.

Source

pub fn method_handle_count(&self) -> usize

Source

pub fn call_site(&self, idx: u32) -> Option<&CallSiteInfo>

Resolved call site by index.

Source

pub fn call_site_count(&self) -> usize

Source

pub fn debug_locals(&self, debug_info_off: u32) -> Vec<DebugLocal>

Parameter names from debug info (NO_INDEX → absent). debug_info_off comes from a code item; the entry layout is line_start uleb, parameters_size uleb, then uleb128p1 names. Local-variable table of a debug_info_item (DBG_START_LOCAL / END / RESTART ranges). Release APKs strip it (empty result, zero cost); debug-enabled builds recover the ORIGINAL source names (bArr, i3, …) instead of synthetic vN registers.

Source

pub fn parameter_names(&self, debug_info_off: u32) -> Vec<Option<String>>

Trait Implementations§

Source§

impl Debug for DexFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for DexFile

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.