Skip to main content

Pkg

Struct Pkg 

Source
pub struct Pkg<R: AsRef<[u8]>> { /* private fields */ }
Expand description

A parsed PS4 PKG file.

This struct provides read-only access to the PKG contents including entries, headers, and the encrypted PFS image.

Reference: https://www.psdevwiki.com/ps4/PKG_files

Implementations§

Source§

impl<R: AsRef<[u8]>> Pkg<R>

Source

pub fn new(raw: R) -> Result<Self, OpenError>

Creates a new Pkg from raw bytes.

Parses the header, entry keys, and EKPFS from the provided data.

§Example
use orbis_pkg::Pkg;

let bytes = std::fs::read("game.pkg")?;
let pkg = Pkg::new(bytes)?;
println!("Content ID: {}", pkg.header().content_id());
Source

pub fn header(&self) -> &PkgHeader

Returns a reference to the PKG header.

Source

pub fn entry_count(&self) -> usize

Returns the number of entries in the PKG.

Source

pub fn entries(&self) -> PkgEntries<'_>

Returns an iterator over all entries in the PKG.

Each item contains the entry index and the entry metadata.

§Example
use orbis_pkg::Pkg;

let bytes = std::fs::read("game.pkg")?;
let pkg = Pkg::new(bytes)?;

for result in pkg.entries() {
    let (index, entry) = result?;
    println!("Entry {}: id=0x{:08X}, size={}", index, entry.id(), entry.data_size());
}
Source

pub fn entry_data(&self, entry: &PkgEntry) -> Result<Vec<u8>, EntryDataError>

Gets the decrypted data for an entry.

Returns the decrypted data with any padding removed.

§Errors

Returns EntryDataError::NoDecryptionKey if the entry is encrypted and no decryption key is available for its key index.

§Example
use orbis_pkg::Pkg;
use orbis_pkg::entry::EntryId;

let bytes = std::fs::read("game.pkg")?;
let pkg = Pkg::new(bytes)?;

// Find and extract param.sfo
if let Ok((entry, _)) = pkg.find_entry(EntryId::ParamSfo) {
    let data = pkg.entry_data(&entry)?;
    std::fs::write("param.sfo", &data)?;
}
Source

pub fn get_pfs_image(&self) -> Option<PfsImage<'_>>

Returns the embedded PFS image and its encryption key.

Returns None if the PFS offset/size is invalid.

Source

pub fn find_entry( &self, id: EntryId, ) -> Result<(PkgEntry, usize), FindEntryError>

Finds an entry by its ID.

Returns the entry and its index if found.

Source

pub fn find_entry_raw( &self, id: u32, ) -> Result<(PkgEntry, usize), FindEntryError>

Finds an entry by its raw numeric ID.

This is useful when working with unknown/unsupported IDs.

Trait Implementations§

Source§

impl<R: AsRef<[u8]>> Debug for Pkg<R>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R> Freeze for Pkg<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for Pkg<R>
where R: RefUnwindSafe,

§

impl<R> Send for Pkg<R>
where R: Send,

§

impl<R> Sync for Pkg<R>
where R: Sync,

§

impl<R> Unpin for Pkg<R>
where R: Unpin,

§

impl<R> UnwindSafe for Pkg<R>
where R: UnwindSafe,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V