Skip to content

rar.py

ofrak.core.rar

RarArchive (GenericBinary, FilesystemRoot) dataclass

Filesystem stored in a RAR archive.

RarUnpacker (Unpacker)

Extracts files and directories from RAR compressed archives using the free unar tool. RAR is a proprietary archive format that offers good compression and supports features like split archives and recovery records. Use when analyzing RAR-packaged software, data archives, or firmware bundles. The unpacker handles various RAR versions and compression methods. Note that there is currently no RAR packer, so after unpacking, the resource cannot be repacked.

unpack(self, resource, config=None) async

Unpack the given resource.

Users should not call this method directly; rather, they should run Resource.run or Resource.unpack.

Parameters:

Name Type Description Default
resource Resource

The resource that is being unpacked

required
config ComponentConfig

Optional config for unpacking. If an implementation provides a default, this default will always be used when config would otherwise be None. Note that a copy of the default config will be passed, so the default config values cannot be modified persistently by a component run.

None
Source code in ofrak/core/rar.py
async def unpack(self, resource: Resource, config: ComponentConfig = None):
    async with resource.temp_to_disk(suffix=".rar") as temp_archive:
        with tempfile.TemporaryDirectory() as temp_dir:
            cmd = [
                "unar",
                "-no-directory",
                "-no-recursion",
                temp_archive,
            ]
            proc = await asyncio.create_subprocess_exec(
                *cmd,
                cwd=temp_dir,
            )
            returncode = await proc.wait()
            if proc.returncode:
                raise CalledProcessError(returncode=returncode, cmd=cmd)

            rar_view = await resource.view_as(RarArchive)
            await rar_view.initialize_from_disk(temp_dir)