From 62a83b53aac11aa85e124573472ea6d776a42847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Alvarez?= Date: Thu, 23 Mar 2023 04:57:33 -0300 Subject: [PATCH] patterns/pbz: Modernize code, renamed pattern to pbz (#98) * Update pbz pattern - Rename pbzx to pbz; turns out the 'x' is the compression type. - Use type::Magic for the "pbz" magic number. - Decode compression type as an enum. - Mention compression_tool in the header comment. * Rename pbzx.hexpat to pbz.hexpat --- patterns/pbz.hexpat | 40 ++++++++++++++++++++++++++++++++++++++++ patterns/pbzx.hexpat | 30 ------------------------------ 2 files changed, 40 insertions(+), 30 deletions(-) create mode 100644 patterns/pbz.hexpat delete mode 100644 patterns/pbzx.hexpat diff --git a/patterns/pbz.hexpat b/patterns/pbz.hexpat new file mode 100644 index 0000000..c2565b0 --- /dev/null +++ b/patterns/pbz.hexpat @@ -0,0 +1,40 @@ +// Apple pbz compressed file +// Used by Apple on .xip files and OTA updates, +// and can be created with macOS compression_tool. +// +// Copyright (c) 2023 Nicolás Alvarez +// +// SPDX-License-Identifier: GPL-2.0-or-later + +#include +#include + +#pragma endian big + +#define SHOW_DATA 0 + +enum CompressionType: char { + ZLIB = 'z', + LZMA = 'x', + LZ4 = '4', + LZFSE = 'e' +}; + +struct Chunk { + u64 uncompressed_size; + u64 compressed_size; + if (SHOW_DATA) { + u8 data[compressed_size] [[sealed]]; + } else { + padding[compressed_size]; + } +}; + +struct PBZ { + type::Magic<"pbz"> magic; + CompressionType compression; + u64 chunk_size; + Chunk chunks[while(!std::mem::eof())]; +}; + +PBZ pbz @ 0; diff --git a/patterns/pbzx.hexpat b/patterns/pbzx.hexpat deleted file mode 100644 index a61cbc7..0000000 --- a/patterns/pbzx.hexpat +++ /dev/null @@ -1,30 +0,0 @@ -// pbzx compression stream -// Used by Apple on .xip files and OTA updates. -// -// Copyright (c) 2022 Nicolás Alvarez -// -// SPDX-License-Identifier: GPL-2.0-or-later - -#include - -#pragma endian big - -#define SHOW_DATA 0 - -struct Chunk { - u64 uncompressed_size; - u64 compressed_size; - if (SHOW_DATA) { - u8 data[compressed_size] [[sealed]]; - } else { - padding[compressed_size]; - } -}; - -struct PBZX { - char magic[4]; - u64 chunk_size; - Chunk chunks[while(!std::mem::eof())]; -}; - -PBZX pbzx @ 0;