2017-03-01 20:12:47 +00:00
|
|
|
#ifndef _MAGISKBOOT_H_
|
|
|
|
#define _MAGISKBOOT_H_
|
2017-02-27 21:37:47 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/sendfile.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "bootimg.h"
|
|
|
|
|
|
|
|
#define windowBits 15
|
|
|
|
#define ZLIB_GZIP 16
|
|
|
|
#define memLevel 8
|
|
|
|
#define CHUNK 0x40000
|
|
|
|
|
2017-03-01 20:12:47 +00:00
|
|
|
#define LZ4_HEADER_SIZE 19
|
|
|
|
#define LZ4_FOOTER_SIZE 4
|
|
|
|
|
2017-02-27 21:37:47 +00:00
|
|
|
#define CHROMEOS_MAGIC "CHROMEOS"
|
|
|
|
#define CHROMEOS_MAGIC_SIZE 8
|
|
|
|
|
|
|
|
#define KERNEL_FILE "kernel"
|
|
|
|
#define RAMDISK_FILE "ramdisk.cpio"
|
|
|
|
#define SECOND_FILE "second"
|
|
|
|
#define DTB_FILE "dtb"
|
|
|
|
|
|
|
|
typedef enum {
|
2017-03-02 13:59:37 +00:00
|
|
|
UNKNOWN,
|
2017-02-27 21:37:47 +00:00
|
|
|
CHROMEOS,
|
|
|
|
AOSP,
|
|
|
|
ELF,
|
|
|
|
GZIP,
|
|
|
|
LZOP,
|
|
|
|
XZ,
|
|
|
|
LZMA,
|
|
|
|
BZIP2,
|
|
|
|
LZ4,
|
2017-03-02 13:59:37 +00:00
|
|
|
MTK,
|
2017-02-27 21:37:47 +00:00
|
|
|
QCDT,
|
|
|
|
} file_t;
|
|
|
|
|
|
|
|
// Global variables
|
2017-03-04 13:16:59 +00:00
|
|
|
extern unsigned char *kernel, *ramdisk, *second, *dtb;
|
2017-02-27 21:37:47 +00:00
|
|
|
extern boot_img_hdr hdr;
|
|
|
|
extern file_t boot_type, ramdisk_type, dtb_type;
|
|
|
|
extern int mtk_kernel, mtk_ramdisk;
|
|
|
|
|
|
|
|
// Main entries
|
|
|
|
void unpack(const char *image);
|
|
|
|
void repack(const char *image);
|
2017-03-04 13:16:59 +00:00
|
|
|
void hexpatch(const char *image, const char *from, const char *to);
|
|
|
|
void cpio(const char *filename);
|
2017-02-27 21:37:47 +00:00
|
|
|
void error(int rc, const char *msg, ...);
|
|
|
|
void parse_img(unsigned char *orig, size_t size);
|
|
|
|
|
|
|
|
// Compressions
|
2017-03-04 13:16:59 +00: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);
|
|
|
|
int comp(file_t type, const char *to, const unsigned char *from, size_t size);
|
|
|
|
int decomp(file_t type, const char *to, const unsigned char *from, size_t size);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
void mem_align(size_t *pos, size_t align);
|
|
|
|
void file_align(int fd, size_t align);
|
|
|
|
int open_new(const char *filename);
|
2017-02-27 21:37:47 +00:00
|
|
|
|
|
|
|
#endif
|