Skip to content

Unpacking existing ASAR archive

Rodion Morozov edited this page Dec 1, 2022 · 3 revisions

To unpack an existing ASAR archive, you need to use AsarArchiveUnpacker class. It provides methods for extracting all files, or just files you need.

Creating an unpacker

First, you need to open an ASAR archive in order to start extracting files from archive. After you opened an ASAR archive, you can create an unpacker and extract files from this archive.

Here is an example of creating unpacker:

AsarArchive archive = new AsarArchive("path/to/archive.asar");
AsarArchiveUnpacker unpacker = new AsarArchiveUnpacker(archive);

Unpacker class has two events that can be occurred when unpacking whole archive.

Occurs when archive unpacking status changed (current unpacking file changed, etc.)

Occurs when archive unpacking completed successfully

Extract one file

To unpack file, AsarArchiveUnpacked.UnpackFileAsync() method is used. It has a bunch of overloads that allows you to unpack file into file on disk or into data stream.

Here is an example of unpacking one file from archive:

await unpacker.UnpackFileAsync("path/within/archive/to/file.bin", "path/to/file/on/disk/file.bin");
MemoryStream outputStream = new MemoryStream(); // or any other type of stream
await unpacker.UnpackFileAsync("path/within/archive/to/file.bin", outputStream);

Unpacking whole archive

To unpack whole archive, you need to use AsarArchiveUnpacker.UnpackAsync(string) method. It accepts a string with a path to directory, in which to put unpacked files from archive.

Here is an example of how to unpack whole archive into a folder:

await unpacker.UnpackAsync("path/to/unpacked/destination/");