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
This commit is contained in:
Nicolás Alvarez
2023-03-23 04:57:33 -03:00
committed by GitHub
parent 53ea45ffa6
commit 62a83b53aa
2 changed files with 40 additions and 30 deletions

40
patterns/pbz.hexpat Normal file
View File

@@ -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 <nicolas.alvarez@gmail.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later
#include <std/mem.pat>
#include <type/magic.pat>
#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;

View File

@@ -1,30 +0,0 @@
// pbzx compression stream
// Used by Apple on .xip files and OTA updates.
//
// Copyright (c) 2022 Nicolás Alvarez <nicolas.alvarez@gmail.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later
#include <std/mem.pat>
#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;