Arsc

Struct Arsc 

Source
pub struct Arsc { /* private fields */ }
Expand description

Parsed ARSC (resources.arsc) file. Mirrors the Python ARSC class: proto holds the prost-generated protobuf message, stringblocks wraps the global string pool (proto + binary).

Implementations§

Source§

impl Arsc

Source

pub fn from_axml(data: &[u8]) -> Result<Self, AxmlError>

Parse a binary resources.arsc file.

Source

pub fn get_proto(&self) -> &Arsc

Return a reference to the cached prost-generated protobuf message. Call update_proto() first if the internal state has been modified.

Source

pub fn to_proto_text(&self) -> String

Serialize self.proto to native protobuf text format using prost-reflect.

Source

pub fn to_proto_text_pretty(&self) -> String

Serialize to indented proto text format (one field per line).

Source

pub fn export_proto_file(&self, path: &str) -> Result<(), AxmlError>

Write the binary proto representation of this ARSC file to path.

Source

pub fn from_proto_file(path: &str) -> Result<Self, AxmlError>

Load an ARSC from a binary proto file written by [export_proto_file].

Source

pub fn export_pkg_proto_file( &self, idx: usize, path: &str, ) -> Result<(), AxmlError>

Write the binary proto representation of package idx to path.

Source

pub fn import_pkg_proto_file( &mut self, idx: usize, path: &str, ) -> Result<(), AxmlError>

Replace package idx from a binary proto file written by [export_pkg_proto_file].

Source

pub fn list_packages(&self, language_filter: Option<&str>) -> String

Produce an XML listing of resource entries grouped by locale. Each group is wrapped in <resources lang="…">.

If language_filter is Some, only the matching locale section is emitted. Matching is case-insensitive ASCII. Use "default" to select entries with no locale qualifier, or a language tag such as "en" or "fr-FR".

Source

pub fn compute(&mut self, recursive: bool)

Force recalculation of string-pool chunk sizes on the next pack().

When recursive is true (the default), all string pools are marked dirty, the global pool plus every package’s type and key pools. When false, only the global string pool is recomputed; package-level pools keep their current raw bytes. Recalculate all chunk-size header fields and store them in the struct.

When recursive is true (the default), all string pools are marked dirty and all package chunk_size fields are updated. When false, only the global string pool and the top-level size fields are recomputed; package-level string pools keep their current raw bytes.

After compute(), pack() produces a fully correct binary.

Source

pub fn global_stringpool_size(&self) -> usize

Returns the global string pool pack size (for debugging).

Source

pub fn global_stringpool_is_dirty(&self) -> bool

Returns whether the global string pool is dirty.

Source

pub fn package_count(&self) -> usize

Returns the number of packages.

Source

pub fn package_pool_info( &self, idx: usize, ) -> Option<(usize, bool, usize, bool)>

Returns info about package string pools (for debugging).

Source

pub fn package_chunks_have_raw(&self, pkg_idx: usize) -> Vec<bool>

Returns the count of chunks in a package (spec and type counts).

Source

pub fn pack(&self) -> Vec<u8>

Serialize this ARSC to binary resources.arsc format.

This function auto-recalculates sizes when needed (when total_size is 0). Always produces a correct binary output.

Source

pub fn add_resource( &mut self, type_name: &str, name: &str, file_path: &str, ) -> u32

Add a new resource entry (type_name / name → file_path string value).

Finds or creates the type in the first package’s type string pool, adds the entry name to the key string pool, adds file_path to the global string pool, then appends a new TypeSpec+TypeType pair for the default locale. Returns the new resource ID (0x7fTTEEEE).

Source§

impl Arsc

Source

pub fn to_proto_bytes(&self) -> Vec<u8>

Serialize self.proto as binary protobuf bytes.

Source

pub fn from_proto_bytes(data: &[u8]) -> Result<Self, AxmlError>

Deserialize an Arsc from binary protobuf bytes produced by [to_proto_bytes].

Source

pub fn from_proto(p: Arsc) -> Result<Self, AxmlError>

Reconstruct an Arsc from a prost-generated [proto::Arsc] message.

Source

pub fn to_proto(&self) -> Arsc

Convert to the prost-generated [proto::Arsc] message for in-process manipulation.

Source

pub fn update_proto(&mut self)

Recompute self.proto and self.stringblocks.proto from the current in-memory state. Called automatically at the end of from_axml(). Call manually if you modify stringblocks.inner or packages directly.

Auto Trait Implementations§

§

impl Freeze for Arsc

§

impl RefUnwindSafe for Arsc

§

impl Send for Arsc

§

impl Sync for Arsc

§

impl Unpin for Arsc

§

impl UnwindSafe for Arsc

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.