2019-03-07 07:24:06 -05:00
|
|
|
#pragma once
|
2017-09-12 15:27:28 +08:00
|
|
|
|
2019-02-20 20:49:26 -05:00
|
|
|
#include <string_view>
|
|
|
|
|
2017-09-12 15:27:28 +08:00
|
|
|
typedef enum {
|
2020-12-30 22:11:24 -08:00
|
|
|
UNKNOWN,
|
2019-02-20 20:49:26 -05:00
|
|
|
/* Boot formats */
|
2020-12-30 22:11:24 -08:00
|
|
|
CHROMEOS,
|
|
|
|
AOSP,
|
|
|
|
AOSP_VENDOR,
|
|
|
|
DHTB,
|
|
|
|
BLOB,
|
2019-02-20 20:49:26 -05:00
|
|
|
/* Compression formats */
|
2020-12-30 22:11:24 -08:00
|
|
|
GZIP,
|
2021-08-28 17:16:20 -07:00
|
|
|
ZOPFLI,
|
2020-12-30 22:11:24 -08:00
|
|
|
XZ,
|
|
|
|
LZMA,
|
|
|
|
BZIP2,
|
|
|
|
LZ4,
|
|
|
|
LZ4_LEGACY,
|
|
|
|
LZ4_LG,
|
2019-05-28 12:47:52 -03:00
|
|
|
/* Unsupported compression */
|
2020-12-30 22:11:24 -08:00
|
|
|
LZOP,
|
2019-05-28 12:47:52 -03:00
|
|
|
/* Misc */
|
2020-12-30 22:11:24 -08:00
|
|
|
MTK,
|
|
|
|
DTB,
|
2021-07-24 23:04:44 +02:00
|
|
|
ZIMAGE,
|
2018-01-29 03:12:35 +08:00
|
|
|
} format_t;
|
2017-09-12 15:27:28 +08:00
|
|
|
|
2020-10-25 05:10:19 -07:00
|
|
|
#define COMPRESSED(fmt) ((fmt) >= GZIP && (fmt) < LZOP)
|
2019-06-06 16:56:17 -03:00
|
|
|
#define COMPRESSED_ANY(fmt) ((fmt) >= GZIP && (fmt) <= LZOP)
|
2017-10-07 22:08:10 +08:00
|
|
|
|
2021-03-02 20:37:37 -08:00
|
|
|
#define BUFFER_MATCH(buf, s) (memcmp(buf, s, sizeof(s) - 1) == 0)
|
|
|
|
|
2018-01-29 03:12:35 +08:00
|
|
|
#define BOOT_MAGIC "ANDROID!"
|
2020-10-25 06:09:36 -07:00
|
|
|
#define VENDOR_BOOT_MAGIC "VNDRBOOT"
|
2017-09-12 15:27:28 +08:00
|
|
|
#define CHROMEOS_MAGIC "CHROMEOS"
|
2019-03-08 00:47:15 -05:00
|
|
|
#define GZIP1_MAGIC "\x1f\x8b"
|
|
|
|
#define GZIP2_MAGIC "\x1f\x9e"
|
|
|
|
#define LZOP_MAGIC "\x89""LZO"
|
|
|
|
#define XZ_MAGIC "\xfd""7zXZ"
|
2017-09-12 15:27:28 +08:00
|
|
|
#define BZIP_MAGIC "BZh"
|
|
|
|
#define LZ4_LEG_MAGIC "\x02\x21\x4c\x18"
|
2019-03-08 00:47:15 -05:00
|
|
|
#define LZ41_MAGIC "\x03\x21\x4c\x18"
|
|
|
|
#define LZ42_MAGIC "\x04\x22\x4d\x18"
|
2017-09-12 15:27:28 +08:00
|
|
|
#define MTK_MAGIC "\x88\x16\x88\x58"
|
2020-10-12 01:55:33 -07:00
|
|
|
#define DTB_MAGIC "\xd0\x0d\xfe\xed"
|
2017-09-12 15:27:28 +08:00
|
|
|
#define LG_BUMP_MAGIC "\x41\xa9\xe4\x67\x74\x4d\x1d\x1b\xa4\x29\xf2\xec\xea\x65\x52\x79"
|
2018-01-29 22:16:02 +08:00
|
|
|
#define DHTB_MAGIC "\x44\x48\x54\x42\x01\x00\x00\x00"
|
|
|
|
#define SEANDROID_MAGIC "SEANDROIDENFORCE"
|
2018-01-30 05:20:18 +08:00
|
|
|
#define TEGRABLOB_MAGIC "-SIGNED-BY-SIGNBLOB-"
|
2019-05-19 21:18:18 -03:00
|
|
|
#define NOOKHD_RL_MAGIC "Red Loader"
|
|
|
|
#define NOOKHD_GL_MAGIC "Green Loader"
|
|
|
|
#define NOOKHD_GR_MAGIC "Green Recovery"
|
|
|
|
#define NOOKHD_EB_MAGIC "eMMC boot.img+secondloader"
|
|
|
|
#define NOOKHD_ER_MAGIC "eMMC recovery.img+secondloader"
|
2018-02-22 05:29:38 -06:00
|
|
|
#define NOOKHD_PRE_HEADER_SZ 1048576
|
|
|
|
#define ACCLAIM_MAGIC "BauwksBoot"
|
|
|
|
#define ACCLAIM_PRE_HEADER_SZ 262144
|
2021-03-02 20:37:37 -08:00
|
|
|
#define AVB_FOOTER_MAGIC "AVBf"
|
|
|
|
#define AVB_MAGIC "AVB0"
|
2021-07-24 23:04:44 +02:00
|
|
|
#define ZIMAGE_MAGIC "\x18\x28\x6f\x01"
|
2017-09-12 15:27:28 +08:00
|
|
|
|
2019-02-20 20:49:26 -05:00
|
|
|
class Fmt2Name {
|
|
|
|
public:
|
2020-12-30 22:11:24 -08:00
|
|
|
const char *operator[](format_t fmt);
|
2019-02-20 20:49:26 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
class Fmt2Ext {
|
|
|
|
public:
|
2020-12-30 22:11:24 -08:00
|
|
|
const char *operator[](format_t fmt);
|
2019-02-20 20:49:26 -05:00
|
|
|
};
|
|
|
|
|
2021-03-02 23:16:10 -08:00
|
|
|
class Name2Fmt {
|
|
|
|
public:
|
|
|
|
format_t operator[](std::string_view name);
|
|
|
|
};
|
|
|
|
|
2018-02-10 03:34:13 +08:00
|
|
|
format_t check_fmt(const void *buf, size_t len);
|
2019-02-20 20:49:26 -05:00
|
|
|
|
2021-03-02 23:16:10 -08:00
|
|
|
extern Name2Fmt name2fmt;
|
2019-02-20 20:49:26 -05:00
|
|
|
extern Fmt2Name fmt2name;
|
|
|
|
extern Fmt2Ext fmt2ext;
|