2017-03-01 21:12:47 +01:00
|
|
|
#ifndef _MAGISKBOOT_H_
|
|
|
|
#define _MAGISKBOOT_H_
|
2017-02-27 22:37:47 +01:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2017-03-07 17:54:23 +01:00
|
|
|
#include <stdarg.h>
|
2017-02-27 22:37:47 +01:00
|
|
|
#include <unistd.h>
|
2017-03-07 17:54:23 +01:00
|
|
|
#include <ctype.h>
|
2017-02-27 22:37:47 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "bootimg.h"
|
2017-03-09 21:08:17 +01:00
|
|
|
#include "sha1.h"
|
2017-04-28 15:48:38 +02:00
|
|
|
#include "magisk.h"
|
|
|
|
#include "utils.h"
|
2017-02-27 22:37:47 +01:00
|
|
|
|
2017-04-27 21:15:48 +02:00
|
|
|
#define CHROMEOS_MAGIC "CHROMEOS"
|
|
|
|
#define ELF32_MAGIC "\x7f""ELF\x01"
|
|
|
|
#define ELF64_MAGIC "\x7f""ELF\x02"
|
2017-02-27 22:37:47 +01:00
|
|
|
|
2017-04-28 15:48:38 +02:00
|
|
|
#define KERNEL_FILE "kernel"
|
|
|
|
#define RAMDISK_FILE "ramdisk.cpio"
|
|
|
|
#define SECOND_FILE "second"
|
|
|
|
#define DTB_FILE "dtb"
|
|
|
|
#define NEW_BOOT "new-boot.img"
|
2017-03-04 18:50:36 +01:00
|
|
|
|
2017-04-27 21:15:48 +02:00
|
|
|
#define str(a) #a
|
|
|
|
#define xstr(a) str(a)
|
|
|
|
|
2017-02-27 22:37:47 +01:00
|
|
|
typedef enum {
|
2017-03-02 14:59:37 +01:00
|
|
|
UNKNOWN,
|
2017-02-27 22:37:47 +01:00
|
|
|
CHROMEOS,
|
|
|
|
AOSP,
|
2017-04-27 21:15:48 +02:00
|
|
|
ELF32,
|
|
|
|
ELF64,
|
2017-02-27 22:37:47 +01:00
|
|
|
GZIP,
|
|
|
|
LZOP,
|
|
|
|
XZ,
|
|
|
|
LZMA,
|
|
|
|
BZIP2,
|
|
|
|
LZ4,
|
2017-03-28 22:09:59 +02:00
|
|
|
LZ4_LEGACY,
|
2017-04-27 21:15:48 +02:00
|
|
|
MTK
|
2017-02-27 22:37:47 +01:00
|
|
|
} file_t;
|
|
|
|
|
2017-03-07 17:54:23 +01:00
|
|
|
typedef enum {
|
|
|
|
NONE,
|
|
|
|
RM,
|
|
|
|
MKDIR,
|
2017-03-09 21:08:17 +01:00
|
|
|
ADD,
|
|
|
|
EXTRACT,
|
|
|
|
TEST,
|
|
|
|
DMVERITY,
|
2017-03-10 00:52:59 +01:00
|
|
|
FORCEENCRYPT,
|
|
|
|
BACKUP,
|
|
|
|
RESTORE
|
2017-03-07 17:54:23 +01:00
|
|
|
} command_t;
|
|
|
|
|
2017-04-27 21:15:48 +02:00
|
|
|
extern char *SUP_LIST[];
|
|
|
|
extern char *SUP_EXT_LIST[];
|
|
|
|
extern file_t SUP_TYPE_LIST[];
|
2017-03-07 17:54:23 +01:00
|
|
|
|
2017-02-27 22:37:47 +01:00
|
|
|
// Global variables
|
2017-03-12 11:12:16 +01:00
|
|
|
extern unsigned char *kernel, *ramdisk, *second, *dtb, *extra;
|
2017-02-27 22:37:47 +01:00
|
|
|
extern boot_img_hdr hdr;
|
2017-04-27 21:15:48 +02:00
|
|
|
extern file_t ramdisk_type;
|
2017-02-27 22:37:47 +01:00
|
|
|
extern int mtk_kernel, mtk_ramdisk;
|
|
|
|
|
|
|
|
// Main entries
|
|
|
|
void unpack(const char *image);
|
2017-03-07 17:54:23 +01:00
|
|
|
void repack(const char* orig_image, const char* out_image);
|
2017-03-04 14:16:59 +01:00
|
|
|
void hexpatch(const char *image, const char *from, const char *to);
|
2017-02-27 22:37:47 +01:00
|
|
|
void parse_img(unsigned char *orig, size_t size);
|
2017-03-09 21:08:17 +01:00
|
|
|
int cpio_commands(const char *command, int argc, char *argv[]);
|
2017-03-04 18:50:36 +01:00
|
|
|
void cleanup();
|
2017-02-27 22:37:47 +01:00
|
|
|
|
|
|
|
// Compressions
|
2017-03-04 14:16:59 +01:00
|
|
|
void gzip(int mode, const char* filename, const unsigned char* buf, size_t size);
|
|
|
|
void lzma(int mode, const char* filename, const unsigned char* buf, size_t size);
|
|
|
|
void lz4(int mode, const char* filename, const unsigned char* buf, size_t size);
|
|
|
|
void bzip2(int mode, const char* filename, const unsigned char* buf, size_t size);
|
2017-03-28 22:09:59 +02:00
|
|
|
void lz4_legacy(int mode, const char* filename, const unsigned char* buf, size_t size);
|
2017-03-04 14:16:59 +01:00
|
|
|
int comp(file_t type, const char *to, const unsigned char *from, size_t size);
|
2017-03-12 11:12:16 +01:00
|
|
|
void comp_file(const char *method, const char *from, const char *to);
|
2017-03-04 14:16:59 +01:00
|
|
|
int decomp(file_t type, const char *to, const unsigned char *from, size_t size);
|
2017-03-12 11:12:16 +01:00
|
|
|
void decomp_file(char *from, const char *to);
|
2017-03-04 14:16:59 +01:00
|
|
|
|
|
|
|
// Utils
|
|
|
|
void mmap_ro(const char *filename, unsigned char **buf, size_t *size);
|
|
|
|
void mmap_rw(const char *filename, unsigned char **buf, size_t *size);
|
|
|
|
file_t check_type(const unsigned char *buf);
|
2017-03-12 22:05:51 +01:00
|
|
|
void write_zero(int fd, size_t size);
|
2017-03-04 14:16:59 +01:00
|
|
|
void mem_align(size_t *pos, size_t align);
|
2017-03-07 17:54:23 +01:00
|
|
|
void file_align(int fd, size_t align, int out);
|
2017-03-04 14:16:59 +01:00
|
|
|
int open_new(const char *filename);
|
2017-03-04 18:50:36 +01:00
|
|
|
void print_info();
|
2017-02-27 22:37:47 +01:00
|
|
|
|
|
|
|
#endif
|