Struct Backup

Source
pub struct Backup {
    pub backup_path: PathBuf,
    pub manifest: Manifest,
    pub manifest_db: ManifestDb,
}
Expand description

Main entry point for working with an iOS backup.

Provides methods to initialize, configure, and extract data from a backup, including metadata loading, manifest database access, and file decryption.

Fields§

§backup_path: PathBuf

Filesystem path to the specific device backup folder

§manifest: Manifest

Parsed manifest and decryption state

§manifest_db: ManifestDb

Decrypted manifest database details

Implementations§

Source§

impl Backup

Source

pub fn open<P: AsRef<Path>>( backup_path: P, auth: &Authentication, ) -> Result<Self>

Create a new Backup instance, loading manifest data.

§Arguments
  • backup_path - Filesystem path to a specific device backup folder (the UDID directory).
  • auth - Authentication specifying password or derived key.
§Errors

Returns BackupError if paths are invalid, manifest loading fails, or decryption fails.

§Examples
use crabapple::{Backup, Authentication};

let backup = Backup::open(
    "/path/to/backup",
    &Authentication::Password("pass".into()),
)?;

println!("UDID: {}", backup.udid()?);
Source

pub fn udid(&self) -> Result<&str>

Returns the current device UDID (the backup folder name).

§Errors

Returns BackupError::InvalidBackupRoot if the UDID cannot be retrieved as a string.

§Examples
use crabapple::{Backup, Authentication};

let backup = Backup::open(
    "/path/to/backup",
    &Authentication::Password("pass".into()),
)?;

let udid = backup.udid()?;
println!("UDID: {}", udid);
Source

pub fn lockdown(&self) -> &ManifestLockdownInfo

Returns device metadata from Manifest.plist.

§Returns

Manifest lockdown information parsed from Manifest.plist.

§Examples
use crabapple::{Backup, Authentication};

let backup = Backup::open(
    "/path/to/backup",
    &Authentication::Password("pass".into()),
)?;

let lockdown = backup.lockdown();
println!("Device name: {}", lockdown.device_name);
Source

pub fn is_encrypted(&self) -> bool

Indicates whether the backup is encrypted.

§Returns

true if the backup is encrypted, false otherwise.

§Examples
use crabapple::{Backup, Authentication};

let backup = Backup::open(
    "/path/to/backup",
    &Authentication::Password("pass".into()),
)?;

println!("Encrypted?: {}", backup.is_encrypted());
Source

pub fn num_apps(&self) -> usize

Get number of applications in the backup.

§Returns

The number of applications in the backup.

§Examples
use crabapple::{Backup, Authentication};

let backup = Backup::open(
    "/path/to/backup",
    &Authentication::Password("pass".into()),
)?;

println!("Backup contains {} apps!", backup.num_apps());
Source

pub fn apps(&self) -> &[Application]

Get a reference to the applications in the backup.

§Returns

A reference to a vector of Application objects parsed from the manifest.

§Examples
use crabapple::{Backup, Authentication};

let backup = Backup::open(
    "/path/to/backup",
    &Authentication::Password("pass".into()),
)?;

let apps = backup.apps();
for app in apps {
   println!("App: {}", app.bundle_id);
}
Source

pub fn decryption_key_hex(&self) -> Option<String>

Returns the main decryption key as a hex string, if the backup is encrypted.

§Returns

An Option<String> containing the decryption key in hexadecimal representation, or None if the backup is not encrypted.

§Examples
use crabapple::{Backup, Authentication};

let backup = Backup::open(
    "/path/to/backup",
    &Authentication::Password("pass".into()),
)?;

if let Some(key_hex) = backup.decryption_key_hex() {
    println!("Key: {}", key_hex);
}
Source

pub fn decryption_key(&self) -> Option<EncryptionKey>

Retrieve the raw 32-byte decryption key, if available.

§Returns

An Option<KeyEncryptionKey> containing the main decryption key, or None if not encrypted.

§Examples
use crabapple::{Backup, Authentication};

let backup = Backup::open(
    "/path/to/backup",
    &Authentication::Password("pass".into()),
)?;

if let Some(key) = backup.decryption_key() {
    println!("Key: {:?}", key);
}
Source

pub fn query_all_domains(&self) -> Result<HashSet<String>>

Get all domains present in the backup’s manifest database.

Some common domains, in no particular order, include:

  • AppDomain
  • AppDomainGroup
  • AppDomainPlugin
  • CameraRollDomain
  • DatabaseDomain
  • HealthDomain
  • HomeDomain
  • HomeKitDomain
  • InstallDomain
  • KeyboardDomain
  • KeychainDomain
  • ManagedPreferencesDomain
  • MediaDomain
  • MobileDeviceDomain
  • NetworkDomain
  • ProtectedDomain
  • RootDomain
  • SysContainerDomain
  • SysSharedContainerDomain
  • SystemPreferencesDomain
  • TonesDomain
  • WirelessDomain
§Returns

A HashSet<String> containing each unique domain present in the backup.

§Errors

Returns BackupError::ManifestDbNotFound if the manifest database is unavailable, or BackupError::Database if the database query fails.

§Examples
use crabapple::{Backup, Authentication};

let backup = Backup::open(
    "/path/to/backup",
    &Authentication::Password("pass".into()),
)?;

let domains = backup.query_all_domains()?;
println!("Domains: {:?}", domains);
Source

pub fn manifest_db_path(&self) -> &Path

Get the filesystem path to the decrypted (or raw) Manifest.db file.

§Returns

A Path pointing to the location of the manifest database file.

§Examples
use crabapple::{Backup, Authentication};

let backup = Backup::open(
    "/path/to/backup",
    &Authentication::Password("pass".into()),
)?;

let db_path = backup.manifest_db_path();
println!("Manifest.db path: {:?}", db_path);
Source

pub fn entries(&self) -> Result<Vec<BackupFileEntry>>

List all files recorded in Manifest.db.

§Errors

Returns BackupError::Database if the database cannot be accessed.

§Examples
use crabapple::{Backup, Authentication};

let backup = Backup::open(
    "/path/to/backup",
    &Authentication::Password("pass".into()),
)?;

let entries = backup.entries()?;
for entry in entries {
    println!("{:?}", entry);
}
Source

pub fn get_file(&self, file_id: &str) -> Result<BackupFileEntry>

Get a single file entry by its file ID.

§Arguments
  • file_id - The file’s unique identifier (SHA1 hash).
§Errors

Returns BackupError::FileNotFoundInBackup if the specified file ID is not found, or BackupError::Database if the database query fails.

§Examples
use crabapple::{Backup, Authentication};

let backup = Backup::open(
    "/path/to/backup",
    &Authentication::Password("pass".into()),
)?;

let entry = backup.get_file("fileid")?;
println!("File encryption key: {:?}", entry.metadata.encryption_key);
Source

pub fn decrypt_entry(&self, entry: &BackupFileEntry) -> Result<Vec<u8>>

Decrypt the file represented by BackupFileEntry, returning plaintext bytes.

All operations are performed in memory, and the decrypted data is returned as a byte vector.

§Arguments
§Returns

Plaintext data as a byte vector.

§Errors

Returns BackupError::Crypto on decryption errors or missing keys.

§Examples
use crabapple::{Backup, Authentication};

let backup = Backup::open(
    "/path/to/backup",
    &Authentication::Password("pass".into()),
)?;

let entry = backup.get_file("fileid")?;
let data = backup.decrypt_entry(&entry)?;
println!("Data size: {} bytes", data.len());
Source

pub fn decrypt_entry_stream( &self, entry: &BackupFileEntry, ) -> Result<AesCbcDecryptReader<BufReader<File>>>

Decrypt the file represented by BackupFileEntry, returning a streaming reader.

All operations are streamed from the disk, and the decrypted data is returned as a reader.

§Arguments
§Returns

A streaming reader implementing std::io::Read that yields plaintext as it’s read.

§Errors

Returns BackupError::Crypto on decryption errors or missing keys.

§Examples
use std::{fs::File, io::copy};
use crabapple::{Backup, Authentication};

let backup = Backup::open(
    "/path/to/backup",
    &Authentication::Password("pass".into()),
)?;

let file = backup.get_file("41ee3469300471004e6d526ebd09c051c19f8a39")?;
let mut reader = backup.decrypt_entry_stream(&file)?;
let mut plain = Vec::new();
copy(&mut reader, &mut plain)?;

Trait Implementations§

Source§

impl Debug for Backup

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Backup

§

impl !RefUnwindSafe for Backup

§

impl Send for Backup

§

impl !Sync for Backup

§

impl Unpin for Backup

§

impl !UnwindSafe for Backup

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> Same for T

Source§

type Output = T

Should always be Self
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.