mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-03-28 01:02:19 +00:00
Reduce duplicate code for MagiskBoot
This commit is contained in:
parent
62fe92d922
commit
d3d5703f3f
@ -15,6 +15,7 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
|
#include <selinux/selinux.h>
|
||||||
|
|
||||||
#include "magisk.h"
|
#include "magisk.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
@ -114,7 +115,7 @@ void start_daemon() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
xsetsid();
|
xsetsid();
|
||||||
xsetcon("u:r:su:s0");
|
setcon("u:r:su:s0");
|
||||||
umask(022);
|
umask(022);
|
||||||
|
|
||||||
// Patch selinux with medium patch before we do anything
|
// Patch selinux with medium patch before we do anything
|
||||||
|
@ -20,6 +20,7 @@ LOCAL_SRC_FILES := \
|
|||||||
utils.c \
|
utils.c \
|
||||||
cpio.c \
|
cpio.c \
|
||||||
sha1.c \
|
sha1.c \
|
||||||
|
../utils/xwrap.c \
|
||||||
../utils/vector.c
|
../utils/vector.c
|
||||||
LOCAL_CFLAGS += -DZLIB_CONST
|
LOCAL_CFLAGS += -DZLIB_CONST
|
||||||
include $(BUILD_EXECUTABLE)
|
include $(BUILD_EXECUTABLE)
|
||||||
|
@ -16,8 +16,7 @@
|
|||||||
#define LZ4_LEGACY_BLOCKSIZE 0x800000
|
#define LZ4_LEGACY_BLOCKSIZE 0x800000
|
||||||
|
|
||||||
static void write_file(const int fd, const void *buf, const size_t size, const char *filename) {
|
static void write_file(const int fd, const void *buf, const size_t size, const char *filename) {
|
||||||
if (write(fd, buf, size) != size)
|
xwrite(fd, buf, size);
|
||||||
error(1, "Error in writing %s", filename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void report(const int mode, const char* filename) {
|
static void report(const int mode, const char* filename) {
|
||||||
@ -52,11 +51,11 @@ void gzip(int mode, const char* filename, const unsigned char* buf, size_t size)
|
|||||||
ret = deflateInit2(&strm, 9, Z_DEFLATED, windowBits | ZLIB_GZIP, memLevel, Z_DEFAULT_STRATEGY);
|
ret = deflateInit2(&strm, 9, Z_DEFLATED, windowBits | ZLIB_GZIP, memLevel, Z_DEFAULT_STRATEGY);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error(1, "Unsupported gzip mode!");
|
LOGE(1, "Unsupported gzip mode!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != Z_OK)
|
if (ret != Z_OK)
|
||||||
error(1, "Unable to init zlib stream");
|
LOGE(1, "Unable to init zlib stream\n");
|
||||||
|
|
||||||
do {
|
do {
|
||||||
strm.next_in = buf + pos;
|
strm.next_in = buf + pos;
|
||||||
@ -81,7 +80,7 @@ void gzip(int mode, const char* filename, const unsigned char* buf, size_t size)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (ret == Z_STREAM_ERROR)
|
if (ret == Z_STREAM_ERROR)
|
||||||
error(1, "Error when running gzip");
|
LOGE(1, "Error when running gzip\n");
|
||||||
|
|
||||||
have = CHUNK - strm.avail_out;
|
have = CHUNK - strm.avail_out;
|
||||||
write_file(fd, out, have, filename);
|
write_file(fd, out, have, filename);
|
||||||
@ -132,12 +131,12 @@ void lzma(int mode, const char* filename, const unsigned char* buf, size_t size)
|
|||||||
ret = lzma_alone_encoder(&strm, &opt);
|
ret = lzma_alone_encoder(&strm, &opt);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error(1, "Unsupported lzma mode!");
|
LOGE(1, "Unsupported lzma mode!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (ret != LZMA_OK)
|
if (ret != LZMA_OK)
|
||||||
error(1, "Unable to init lzma stream");
|
LOGE(1, "Unable to init lzma stream\n");
|
||||||
|
|
||||||
do {
|
do {
|
||||||
strm.next_in = buf + pos;
|
strm.next_in = buf + pos;
|
||||||
@ -159,7 +158,7 @@ void lzma(int mode, const char* filename, const unsigned char* buf, size_t size)
|
|||||||
} while (strm.avail_out == 0 && ret == LZMA_OK);
|
} while (strm.avail_out == 0 && ret == LZMA_OK);
|
||||||
|
|
||||||
if (ret != LZMA_OK && ret != LZMA_STREAM_END)
|
if (ret != LZMA_OK && ret != LZMA_STREAM_END)
|
||||||
error(1, "LZMA error %d!", ret);
|
LOGE(1, "LZMA error %d!\n", ret);
|
||||||
|
|
||||||
} while (pos < size);
|
} while (pos < size);
|
||||||
|
|
||||||
@ -189,11 +188,11 @@ void lz4(int mode, const char* filename, const unsigned char* buf, size_t size)
|
|||||||
ret = LZ4F_createCompressionContext(&cctx, LZ4F_VERSION);
|
ret = LZ4F_createCompressionContext(&cctx, LZ4F_VERSION);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error(1, "Unsupported lz4 mode!");
|
LOGE(1, "Unsupported lz4 mode!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LZ4F_isError(ret))
|
if (LZ4F_isError(ret))
|
||||||
error(1, "Context creation error: %s\n", LZ4F_getErrorName(ret));
|
LOGE(1, "Context creation error: %s\n", LZ4F_getErrorName(ret));
|
||||||
|
|
||||||
// Allocate out buffer
|
// Allocate out buffer
|
||||||
switch(mode) {
|
switch(mode) {
|
||||||
@ -202,7 +201,7 @@ void lz4(int mode, const char* filename, const unsigned char* buf, size_t size)
|
|||||||
read = CHUNK;
|
read = CHUNK;
|
||||||
ret = LZ4F_getFrameInfo(dctx, &info, buf, &read);
|
ret = LZ4F_getFrameInfo(dctx, &info, buf, &read);
|
||||||
if (LZ4F_isError(ret))
|
if (LZ4F_isError(ret))
|
||||||
error(1, "LZ4F_getFrameInfo error: %s\n", LZ4F_getErrorName(ret));
|
LOGE(1, "LZ4F_getFrameInfo error: %s\n", LZ4F_getErrorName(ret));
|
||||||
switch (info.blockSizeID) {
|
switch (info.blockSizeID) {
|
||||||
case LZ4F_default:
|
case LZ4F_default:
|
||||||
case LZ4F_max64KB: outCapacity = 1 << 16; break;
|
case LZ4F_max64KB: outCapacity = 1 << 16; break;
|
||||||
@ -210,7 +209,7 @@ void lz4(int mode, const char* filename, const unsigned char* buf, size_t size)
|
|||||||
case LZ4F_max1MB: outCapacity = 1 << 20; break;
|
case LZ4F_max1MB: outCapacity = 1 << 20; break;
|
||||||
case LZ4F_max4MB: outCapacity = 1 << 22; break;
|
case LZ4F_max4MB: outCapacity = 1 << 22; break;
|
||||||
default:
|
default:
|
||||||
error(1, "Impossible unless more block sizes are allowed\n");
|
LOGE(1, "Impossible unless more block sizes are allowed\n");
|
||||||
}
|
}
|
||||||
pos += read;
|
pos += read;
|
||||||
break;
|
break;
|
||||||
@ -219,15 +218,13 @@ void lz4(int mode, const char* filename, const unsigned char* buf, size_t size)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
out = malloc(outCapacity);
|
out = xmalloc(outCapacity);
|
||||||
if (!out)
|
|
||||||
error(1, "LZ4 malloc error!");
|
|
||||||
|
|
||||||
// Write header
|
// Write header
|
||||||
if (mode == 1) {
|
if (mode == 1) {
|
||||||
have = ret = LZ4F_compressBegin(cctx, out, size, NULL);
|
have = ret = LZ4F_compressBegin(cctx, out, size, NULL);
|
||||||
if (LZ4F_isError(ret))
|
if (LZ4F_isError(ret))
|
||||||
error(1, "Failed to start compression: error %s\n", LZ4F_getErrorName(ret));
|
LOGE(1, "Failed to start compression: error %s\n", LZ4F_getErrorName(ret));
|
||||||
write_file(fd, out, have, filename);
|
write_file(fd, out, have, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +247,7 @@ void lz4(int mode, const char* filename, const unsigned char* buf, size_t size)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (LZ4F_isError(ret))
|
if (LZ4F_isError(ret))
|
||||||
error(1, "LZ4 coding error: %s\n", LZ4F_getErrorName(ret));
|
LOGE(1, "LZ4 coding error: %s\n", LZ4F_getErrorName(ret));
|
||||||
|
|
||||||
write_file(fd, out, have, filename);
|
write_file(fd, out, have, filename);
|
||||||
// Update status
|
// Update status
|
||||||
@ -267,7 +264,7 @@ void lz4(int mode, const char* filename, const unsigned char* buf, size_t size)
|
|||||||
case 1:
|
case 1:
|
||||||
have = ret = LZ4F_compressEnd(cctx, out, outCapacity, NULL);
|
have = ret = LZ4F_compressEnd(cctx, out, outCapacity, NULL);
|
||||||
if (LZ4F_isError(ret))
|
if (LZ4F_isError(ret))
|
||||||
error(1, "Failed to end compression: error %s\n", LZ4F_getErrorName(ret));
|
LOGE(1, "Failed to end compression: error %s\n", LZ4F_getErrorName(ret));
|
||||||
|
|
||||||
write_file(fd, out, have, filename);
|
write_file(fd, out, have, filename);
|
||||||
|
|
||||||
@ -300,11 +297,11 @@ void bzip2(int mode, const char* filename, const unsigned char* buf, size_t size
|
|||||||
ret = BZ2_bzCompressInit(&strm, 9, 0, 0);
|
ret = BZ2_bzCompressInit(&strm, 9, 0, 0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error(1, "Unsupported bzip2 mode!");
|
LOGE(1, "Unsupported bzip2 mode!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != BZ_OK)
|
if (ret != BZ_OK)
|
||||||
error(1, "Unable to init bzlib stream");
|
LOGE(1, "Unable to init bzlib stream\n");
|
||||||
|
|
||||||
do {
|
do {
|
||||||
strm.next_in = (char *) buf + pos;
|
strm.next_in = (char *) buf + pos;
|
||||||
@ -361,22 +358,19 @@ void lz4_legacy(int mode, const char* filename, const unsigned char* buf, size_t
|
|||||||
|
|
||||||
switch(mode) {
|
switch(mode) {
|
||||||
case 0:
|
case 0:
|
||||||
out = malloc(LZ4_LEGACY_BLOCKSIZE);
|
out = xmalloc(LZ4_LEGACY_BLOCKSIZE);
|
||||||
// Skip magic
|
// Skip magic
|
||||||
pos += 4;
|
pos += 4;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
out = malloc(LZ4_COMPRESSBOUND(LZ4_LEGACY_BLOCKSIZE));
|
out = xmalloc(LZ4_COMPRESSBOUND(LZ4_LEGACY_BLOCKSIZE));
|
||||||
// Write magic
|
// Write magic
|
||||||
write_file(fd, "\x02\x21\x4c\x18", 4, filename);
|
write_file(fd, "\x02\x21\x4c\x18", 4, filename);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error(1, "Unsupported lz4_legacy mode!");
|
LOGE(1, "Unsupported lz4_legacy mode!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!out)
|
|
||||||
error(1, "lz4_legacy malloc error");
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
switch(mode) {
|
switch(mode) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -386,10 +380,10 @@ void lz4_legacy(int mode, const char* filename, const unsigned char* buf, size_t
|
|||||||
block_size += ((unsigned)buf[pos + 3])<<24;
|
block_size += ((unsigned)buf[pos + 3])<<24;
|
||||||
pos += 4;
|
pos += 4;
|
||||||
if (block_size > LZ4_COMPRESSBOUND(LZ4_LEGACY_BLOCKSIZE))
|
if (block_size > LZ4_COMPRESSBOUND(LZ4_LEGACY_BLOCKSIZE))
|
||||||
error(1, "lz4_legacy block size too large!");
|
LOGE(1, "lz4_legacy block size too large!\n");
|
||||||
have = LZ4_decompress_safe((const char*) (buf + pos), out, block_size, LZ4_LEGACY_BLOCKSIZE);
|
have = LZ4_decompress_safe((const char*) (buf + pos), out, block_size, LZ4_LEGACY_BLOCKSIZE);
|
||||||
if (have < 0)
|
if (have < 0)
|
||||||
error(1, "Cannot decode lz4_legacy block");
|
LOGE(1, "Cannot decode lz4_legacy block\n");
|
||||||
pos += block_size;
|
pos += block_size;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
@ -399,7 +393,7 @@ void lz4_legacy(int mode, const char* filename, const unsigned char* buf, size_t
|
|||||||
insize = LZ4_LEGACY_BLOCKSIZE;
|
insize = LZ4_LEGACY_BLOCKSIZE;
|
||||||
have = LZ4_compress_default((const char*) (buf + pos), out, insize, LZ4_COMPRESSBOUND(LZ4_LEGACY_BLOCKSIZE));
|
have = LZ4_compress_default((const char*) (buf + pos), out, insize, LZ4_COMPRESSBOUND(LZ4_LEGACY_BLOCKSIZE));
|
||||||
if (have == 0)
|
if (have == 0)
|
||||||
error(1, "lz4_legacy compression error");
|
LOGE(1, "lz4_legacy compression error\n");
|
||||||
pos += insize;
|
pos += insize;
|
||||||
block_size_le[0] = (unsigned char)have;
|
block_size_le[0] = (unsigned char)have;
|
||||||
block_size_le[1] = (unsigned char)(have >> 8);
|
block_size_le[1] = (unsigned char)(have >> 8);
|
||||||
@ -496,7 +490,7 @@ void decomp_file(char *from, const char *to) {
|
|||||||
char *ext;
|
char *ext;
|
||||||
ext = strrchr(from, '.');
|
ext = strrchr(from, '.');
|
||||||
if (ext == NULL)
|
if (ext == NULL)
|
||||||
error(1, "Bad filename extention");
|
LOGE(1, "Bad filename extention\n");
|
||||||
|
|
||||||
// File type and extension should match
|
// File type and extension should match
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@ -522,7 +516,7 @@ void decomp_file(char *from, const char *to) {
|
|||||||
ok = 0;
|
ok = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error(1, "Provided file \'%s\' is not a supported archive format", from);
|
LOGE(1, "Provided file \'%s\' is not a supported archive format\n", from);
|
||||||
}
|
}
|
||||||
if (ok) {
|
if (ok) {
|
||||||
// If all match, strip out the suffix
|
// If all match, strip out the suffix
|
||||||
@ -536,7 +530,7 @@ void decomp_file(char *from, const char *to) {
|
|||||||
unlink(from);
|
unlink(from);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error(1, "Bad filename extention \'%s\'", ext);
|
LOGE(1, "Bad filename extention \'%s\'\n", ext);
|
||||||
}
|
}
|
||||||
munmap(file, size);
|
munmap(file, size);
|
||||||
}
|
}
|
||||||
@ -556,7 +550,11 @@ void comp_file(const char *method, const char *from, const char *to) {
|
|||||||
} else if (strcmp(method, "bzip2") == 0) {
|
} else if (strcmp(method, "bzip2") == 0) {
|
||||||
type = BZIP2;
|
type = BZIP2;
|
||||||
} else {
|
} else {
|
||||||
error(1, "Only support following methods: ");
|
fprintf(stderr, "Only support following methods: ");
|
||||||
|
for (int i = 0; SUP_LIST[i]; ++i)
|
||||||
|
fprintf(stderr, "%s ", SUP_LIST[i]);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
unsigned char *file;
|
unsigned char *file;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
@ -13,7 +13,7 @@ static uint32_t x8u(char *hex) {
|
|||||||
// Because scanf gratuitously treats %*X differently than printf does.
|
// Because scanf gratuitously treats %*X differently than printf does.
|
||||||
sprintf(pattern, "%%%dx%%n", inpos);
|
sprintf(pattern, "%%%dx%%n", inpos);
|
||||||
sscanf(hex, pattern, &val, &outpos);
|
sscanf(hex, pattern, &val, &outpos);
|
||||||
if (inpos != outpos) error(1, "bad cpio header");
|
if (inpos != outpos) LOGE(1, "bad cpio header\n");
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
@ -62,13 +62,11 @@ static int cpio_compare(const void *a, const void *b) {
|
|||||||
// Parse cpio file to a vector of cpio_file
|
// Parse cpio file to a vector of cpio_file
|
||||||
static void parse_cpio(const char *filename, struct vector *v) {
|
static void parse_cpio(const char *filename, struct vector *v) {
|
||||||
printf("Loading cpio: [%s]\n\n", filename);
|
printf("Loading cpio: [%s]\n\n", filename);
|
||||||
int fd = open(filename, O_RDONLY);
|
int fd = xopen(filename, O_RDONLY);
|
||||||
if (fd < 0)
|
|
||||||
error(1, "Cannot open %s", filename);
|
|
||||||
cpio_newc_header header;
|
cpio_newc_header header;
|
||||||
cpio_file *f;
|
cpio_file *f;
|
||||||
while(read(fd, &header, 110) == 110) {
|
while(read(fd, &header, 110) == 110) {
|
||||||
f = calloc(sizeof(*f), 1);
|
f = xcalloc(sizeof(*f), 1);
|
||||||
// f->ino = x8u(header.ino);
|
// f->ino = x8u(header.ino);
|
||||||
f->mode = x8u(header.mode);
|
f->mode = x8u(header.mode);
|
||||||
f->uid = x8u(header.uid);
|
f->uid = x8u(header.uid);
|
||||||
@ -83,7 +81,7 @@ static void parse_cpio(const char *filename, struct vector *v) {
|
|||||||
f->namesize = x8u(header.namesize);
|
f->namesize = x8u(header.namesize);
|
||||||
// f->check = x8u(header.check);
|
// f->check = x8u(header.check);
|
||||||
f->filename = malloc(f->namesize);
|
f->filename = malloc(f->namesize);
|
||||||
read(fd, f->filename, f->namesize);
|
xxread(fd, f->filename, f->namesize);
|
||||||
file_align(fd, 4, 0);
|
file_align(fd, 4, 0);
|
||||||
if (strcmp(f->filename, ".") == 0 || strcmp(f->filename, "..") == 0) {
|
if (strcmp(f->filename, ".") == 0 || strcmp(f->filename, "..") == 0) {
|
||||||
cpio_free(f);
|
cpio_free(f);
|
||||||
@ -95,7 +93,7 @@ static void parse_cpio(const char *filename, struct vector *v) {
|
|||||||
}
|
}
|
||||||
if (f->filesize) {
|
if (f->filesize) {
|
||||||
f->data = malloc(f->filesize);
|
f->data = malloc(f->filesize);
|
||||||
read(fd, f->data, f->filesize);
|
xxread(fd, f->data, f->filesize);
|
||||||
file_align(fd, 4, 0);
|
file_align(fd, 4, 0);
|
||||||
}
|
}
|
||||||
vec_push_back(v, f);
|
vec_push_back(v, f);
|
||||||
@ -128,18 +126,18 @@ static void dump_cpio(const char *filename, struct vector *v) {
|
|||||||
f->namesize,
|
f->namesize,
|
||||||
0 // f->check
|
0 // f->check
|
||||||
);
|
);
|
||||||
write(fd, header, 110);
|
xwrite(fd, header, 110);
|
||||||
write(fd, f->filename, f->namesize);
|
xwrite(fd, f->filename, f->namesize);
|
||||||
file_align(fd, 4, 1);
|
file_align(fd, 4, 1);
|
||||||
if (f->filesize) {
|
if (f->filesize) {
|
||||||
write(fd, f->data, f->filesize);
|
xwrite(fd, f->data, f->filesize);
|
||||||
file_align(fd, 4, 1);
|
file_align(fd, 4, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Write trailer
|
// Write trailer
|
||||||
sprintf(header, "070701%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", inode++, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 11, 0);
|
sprintf(header, "070701%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", inode++, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 11, 0);
|
||||||
write(fd, header, 110);
|
xwrite(fd, header, 110);
|
||||||
write(fd, "TRAILER!!!\0", 11);
|
xwrite(fd, "TRAILER!!!\0", 11);
|
||||||
file_align(fd, 4, 1);
|
file_align(fd, 4, 1);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
@ -168,28 +166,26 @@ static void cpio_rm(int recursive, const char *entry, struct vector *v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void cpio_mkdir(mode_t mode, const char *entry, struct vector *v) {
|
static void cpio_mkdir(mode_t mode, const char *entry, struct vector *v) {
|
||||||
cpio_file *f = calloc(sizeof(*f), 1);
|
cpio_file *f = xcalloc(sizeof(*f), 1);
|
||||||
f->mode = S_IFDIR | mode;
|
f->mode = S_IFDIR | mode;
|
||||||
f->namesize = strlen(entry) + 1;
|
f->namesize = strlen(entry) + 1;
|
||||||
f->filename = malloc(f->namesize);
|
f->filename = xmalloc(f->namesize);
|
||||||
memcpy(f->filename, entry, f->namesize);
|
memcpy(f->filename, entry, f->namesize);
|
||||||
cpio_vec_insert(v, f);
|
cpio_vec_insert(v, f);
|
||||||
printf("Create directory [%s] (%04o)\n",entry, mode);
|
printf("Create directory [%s] (%04o)\n",entry, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cpio_add(mode_t mode, const char *entry, const char *filename, struct vector *v) {
|
static void cpio_add(mode_t mode, const char *entry, const char *filename, struct vector *v) {
|
||||||
int fd = open(filename, O_RDONLY);
|
int fd = xopen(filename, O_RDONLY);
|
||||||
if (fd < 0)
|
cpio_file *f = xcalloc(sizeof(*f), 1);
|
||||||
error(1, "Cannot open %s", filename);
|
|
||||||
cpio_file *f = calloc(sizeof(*f), 1);
|
|
||||||
f->mode = S_IFREG | mode;
|
f->mode = S_IFREG | mode;
|
||||||
f->namesize = strlen(entry) + 1;
|
f->namesize = strlen(entry) + 1;
|
||||||
f->filename = malloc(f->namesize);
|
f->filename = xmalloc(f->namesize);
|
||||||
memcpy(f->filename, entry, f->namesize);
|
memcpy(f->filename, entry, f->namesize);
|
||||||
f->filesize = lseek(fd, 0, SEEK_END);
|
f->filesize = lseek(fd, 0, SEEK_END);
|
||||||
lseek(fd, 0, SEEK_SET);
|
lseek(fd, 0, SEEK_SET);
|
||||||
f->data = malloc(f->filesize);
|
f->data = malloc(f->filesize);
|
||||||
read(fd, f->data, f->filesize);
|
xxread(fd, f->data, f->filesize);
|
||||||
close(fd);
|
close(fd);
|
||||||
cpio_vec_insert(v, f);
|
cpio_vec_insert(v, f);
|
||||||
printf("Add entry [%s] (%04o)\n", entry, mode);
|
printf("Add entry [%s] (%04o)\n", entry, mode);
|
||||||
@ -274,14 +270,14 @@ static void cpio_extract(const char *entry, const char *filename, struct vector
|
|||||||
if (strcmp(f->filename, entry) == 0 && S_ISREG(f->mode)) {
|
if (strcmp(f->filename, entry) == 0 && S_ISREG(f->mode)) {
|
||||||
printf("Extracting [%s] to [%s]\n\n", entry, filename);
|
printf("Extracting [%s] to [%s]\n\n", entry, filename);
|
||||||
int fd = open_new(filename);
|
int fd = open_new(filename);
|
||||||
write(fd, f->data, f->filesize);
|
xwrite(fd, f->data, f->filesize);
|
||||||
fchmod(fd, f->mode);
|
fchmod(fd, f->mode);
|
||||||
fchown(fd, f->uid, f->gid);
|
fchown(fd, f->uid, f->gid);
|
||||||
close(fd);
|
close(fd);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
error(1, "Cannot find the file entry [%s]", entry);
|
LOGE(1, "Cannot find the file entry [%s]\n", entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cpio_backup(const char *orig, struct vector *v) {
|
static void cpio_backup(const char *orig, struct vector *v) {
|
||||||
@ -290,8 +286,8 @@ static void cpio_backup(const char *orig, struct vector *v) {
|
|||||||
char chk1[21], chk2[21], buf[PATH_MAX];
|
char chk1[21], chk2[21], buf[PATH_MAX];
|
||||||
int res, doBak;
|
int res, doBak;
|
||||||
|
|
||||||
dir = calloc(sizeof(*dir), 1);
|
dir = xcalloc(sizeof(*dir), 1);
|
||||||
rem = calloc(sizeof(*rem), 1);
|
rem = xcalloc(sizeof(*rem), 1);
|
||||||
vec_init(o);
|
vec_init(o);
|
||||||
vec_init(&bak);
|
vec_init(&bak);
|
||||||
// First push back the directory and the rmlist
|
// First push back the directory and the rmlist
|
||||||
@ -342,7 +338,7 @@ static void cpio_backup(const char *orig, struct vector *v) {
|
|||||||
// Someting new in ramdisk, record in rem
|
// Someting new in ramdisk, record in rem
|
||||||
++j;
|
++j;
|
||||||
if (n->remove) continue;
|
if (n->remove) continue;
|
||||||
rem->data = realloc(rem->data, rem->filesize + n->namesize);
|
rem->data = xrealloc(rem->data, rem->filesize + n->namesize);
|
||||||
memcpy(rem->data + rem->filesize, n->filename, n->namesize);
|
memcpy(rem->data + rem->filesize, n->filename, n->namesize);
|
||||||
rem->filesize += n->namesize;
|
rem->filesize += n->namesize;
|
||||||
printf("Record new entry: [%s] -> [.backup/.rmlist]\n", n->filename);
|
printf("Record new entry: [%s] -> [.backup/.rmlist]\n", n->filename);
|
||||||
@ -391,12 +387,12 @@ static int cpio_restore(struct vector *v) {
|
|||||||
cpio_rm(0, f->data + pos, v);
|
cpio_rm(0, f->data + pos, v);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
n = calloc(sizeof(*n), 1);
|
n = xcalloc(sizeof(*n), 1);
|
||||||
memcpy(n, f, sizeof(*f));
|
memcpy(n, f, sizeof(*f));
|
||||||
n->namesize -= 8;
|
n->namesize -= 8;
|
||||||
n->filename = malloc(n->namesize);
|
n->filename = xmalloc(n->namesize);
|
||||||
memcpy(n->filename, f->filename + 8, n->namesize);
|
memcpy(n->filename, f->filename + 8, n->namesize);
|
||||||
n->data = malloc(n->filesize);
|
n->data = xmalloc(n->filesize);
|
||||||
memcpy(n->data, f->data, n->filesize);
|
memcpy(n->data, f->data, n->filesize);
|
||||||
n->remove = 0;
|
n->remove = 0;
|
||||||
printf("Restoring [%s] -> [%s]\n", f->filename, n->filename);
|
printf("Restoring [%s] -> [%s]\n", f->filename, n->filename);
|
||||||
|
@ -14,8 +14,8 @@ void hexpatch(const char *image, const char *from, const char *to) {
|
|||||||
size_t filesize;
|
size_t filesize;
|
||||||
unsigned char *file, *pattern, *patch;
|
unsigned char *file, *pattern, *patch;
|
||||||
mmap_rw(image, &file, &filesize);
|
mmap_rw(image, &file, &filesize);
|
||||||
pattern = malloc(patternsize);
|
pattern = xmalloc(patternsize);
|
||||||
patch = malloc(patchsize);
|
patch = xmalloc(patchsize);
|
||||||
hex2byte(from, pattern);
|
hex2byte(from, pattern);
|
||||||
hex2byte(to, patch);
|
hex2byte(to, patch);
|
||||||
for (size_t i = 0; i < filesize - patternsize; ++i) {
|
for (size_t i = 0; i < filesize - patternsize; ++i) {
|
||||||
|
10
jni/magiskboot/magisk.h
Normal file
10
jni/magiskboot/magisk.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/* magisk.h - Let MagiskBoot use the same error handling API as main magisk program
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _MAGISK_H_
|
||||||
|
#define _MAGISK_H_
|
||||||
|
|
||||||
|
#define LOGE(err, ...) { fprintf(stderr, __VA_ARGS__); exit(err); }
|
||||||
|
#define PLOGE(fmt, args...) { fprintf(stderr, fmt " failed with %d: %s\n\n", ##args, errno, strerror(errno)); exit(1); }
|
||||||
|
|
||||||
|
#endif
|
@ -8,23 +8,24 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/sendfile.h>
|
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "bootimg.h"
|
#include "bootimg.h"
|
||||||
#include "sha1.h"
|
#include "sha1.h"
|
||||||
|
#include "magisk.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#define CHROMEOS_MAGIC "CHROMEOS"
|
#define CHROMEOS_MAGIC "CHROMEOS"
|
||||||
#define ELF32_MAGIC "\x7f""ELF\x01"
|
#define ELF32_MAGIC "\x7f""ELF\x01"
|
||||||
#define ELF64_MAGIC "\x7f""ELF\x02"
|
#define ELF64_MAGIC "\x7f""ELF\x02"
|
||||||
|
|
||||||
#define KERNEL_FILE "kernel"
|
#define KERNEL_FILE "kernel"
|
||||||
#define RAMDISK_FILE "ramdisk.cpio"
|
#define RAMDISK_FILE "ramdisk.cpio"
|
||||||
#define SECOND_FILE "second"
|
#define SECOND_FILE "second"
|
||||||
#define DTB_FILE "dtb"
|
#define DTB_FILE "dtb"
|
||||||
#define NEW_BOOT "new-boot.img"
|
#define NEW_BOOT "new-boot.img"
|
||||||
|
|
||||||
#define str(a) #a
|
#define str(a) #a
|
||||||
#define xstr(a) str(a)
|
#define xstr(a) str(a)
|
||||||
@ -72,7 +73,6 @@ extern int mtk_kernel, mtk_ramdisk;
|
|||||||
void unpack(const char *image);
|
void unpack(const char *image);
|
||||||
void repack(const char* orig_image, const char* out_image);
|
void repack(const char* orig_image, const char* out_image);
|
||||||
void hexpatch(const char *image, const char *from, const char *to);
|
void hexpatch(const char *image, const char *from, const char *to);
|
||||||
void error(int rc, const char *msg, ...);
|
|
||||||
void parse_img(unsigned char *orig, size_t size);
|
void parse_img(unsigned char *orig, size_t size);
|
||||||
int cpio_commands(const char *command, int argc, char *argv[]);
|
int cpio_commands(const char *command, int argc, char *argv[]);
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
@ -58,15 +58,6 @@ static void usage(char *arg0) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void error(int rc, const char *msg, ...) {
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, msg);
|
|
||||||
vfprintf(stderr, msg, ap);
|
|
||||||
fprintf(stderr,"\n\n");
|
|
||||||
va_end(ap);
|
|
||||||
exit(rc);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
printf("MagiskBoot v" xstr(MAGISK_VERSION) " (by topjohnwu) - Boot Image Modification Tool\n\n");
|
printf("MagiskBoot v" xstr(MAGISK_VERSION) " (by topjohnwu) - Boot Image Modification Tool\n\n");
|
||||||
|
|
||||||
|
@ -87,5 +87,5 @@ void parse_img(unsigned char *orig, size_t size) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
error(1, "No boot image magic found!");
|
LOGE(1, "No boot image magic found!\n");
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,16 @@
|
|||||||
#include "magiskboot.h"
|
#include "magiskboot.h"
|
||||||
|
|
||||||
static size_t restore(const char *filename, int fd) {
|
static size_t restore(const char *filename, int fd) {
|
||||||
int ifd = open(filename, O_RDONLY);
|
int ifd = xopen(filename, O_RDONLY);
|
||||||
if (ifd < 0)
|
|
||||||
error(1, "Cannot open %s\n", filename);
|
|
||||||
|
|
||||||
size_t size = lseek(ifd, 0, SEEK_END);
|
size_t size = lseek(ifd, 0, SEEK_END);
|
||||||
lseek(ifd, 0, SEEK_SET);
|
lseek(ifd, 0, SEEK_SET);
|
||||||
if (sendfile(fd, ifd, NULL, size) != size) {
|
xsendfile(fd, ifd, NULL, size);
|
||||||
error(1, "Cannot write %s\n", filename);
|
|
||||||
}
|
|
||||||
close(ifd);
|
close(ifd);
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void restore_buf(int fd, const void *buf, size_t size) {
|
static void restore_buf(int fd, const void *buf, size_t size) {
|
||||||
if (write(fd, buf, size) != size) {
|
xwrite(fd, buf, size);
|
||||||
error(1, "Cannot dump from input file\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void repack(const char* orig_image, const char* out_image) {
|
void repack(const char* orig_image, const char* out_image) {
|
||||||
@ -79,7 +72,7 @@ void repack(const char* orig_image, const char* out_image) {
|
|||||||
mmap_ro(RAMDISK_FILE, &cpio, &cpio_size);
|
mmap_ro(RAMDISK_FILE, &cpio, &cpio_size);
|
||||||
|
|
||||||
if (comp(ramdisk_type, RAMDISK_FILE, cpio, cpio_size))
|
if (comp(ramdisk_type, RAMDISK_FILE, cpio, cpio_size))
|
||||||
error(1, "Unsupported ramdisk format!");
|
LOGE(1, "Unsupported ramdisk format!\n");
|
||||||
|
|
||||||
munmap(cpio, cpio_size);
|
munmap(cpio, cpio_size);
|
||||||
}
|
}
|
||||||
@ -94,7 +87,7 @@ void repack(const char* orig_image, const char* out_image) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found)
|
if (!found)
|
||||||
error(1, "No ramdisk exists!");
|
LOGE(1, "No ramdisk exists!\n");
|
||||||
hdr.ramdisk_size = restore(name, fd);
|
hdr.ramdisk_size = restore(name, fd);
|
||||||
file_align(fd, hdr.page_size, 1);
|
file_align(fd, hdr.page_size, 1);
|
||||||
|
|
||||||
@ -140,7 +133,7 @@ void repack(const char* orig_image, const char* out_image) {
|
|||||||
|
|
||||||
munmap(orig, size);
|
munmap(orig, size);
|
||||||
if (lseek(fd, 0, SEEK_END) > size) {
|
if (lseek(fd, 0, SEEK_END) > size) {
|
||||||
error(2, "Boot partition too small!");
|
LOGE(2, "Boot partition too small!\n");
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
static void dump(unsigned char *buf, size_t size, const char *filename) {
|
static void dump(unsigned char *buf, size_t size, const char *filename) {
|
||||||
int fd = open_new(filename);
|
int fd = open_new(filename);
|
||||||
if (write(fd, buf, size) != size)
|
xwrite(fd, buf, size);
|
||||||
error(1, "Cannot dump %s", filename);
|
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +32,7 @@ void unpack(const char* image) {
|
|||||||
if (decomp(ramdisk_type, RAMDISK_FILE, ramdisk, hdr.ramdisk_size)) {
|
if (decomp(ramdisk_type, RAMDISK_FILE, ramdisk, hdr.ramdisk_size)) {
|
||||||
// Dump the compressed ramdisk
|
// Dump the compressed ramdisk
|
||||||
dump(ramdisk, hdr.ramdisk_size, RAMDISK_FILE ".unsupport");
|
dump(ramdisk, hdr.ramdisk_size, RAMDISK_FILE ".unsupport");
|
||||||
error(1, "Unsupported ramdisk format! Dumped to %s", RAMDISK_FILE ".unsupport");
|
LOGE(1, "Unsupported ramdisk format! Dumped to %s\n", RAMDISK_FILE ".unsupport");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hdr.second_size) {
|
if (hdr.second_size) {
|
||||||
|
@ -5,22 +5,18 @@ char *SUP_EXT_LIST[] = { "gz", "xz", "lzma", "bz2", "lz4", "lz4", NULL };
|
|||||||
file_t SUP_TYPE_LIST[] = { GZIP, XZ, LZMA, BZIP2, LZ4, LZ4_LEGACY, 0 };
|
file_t SUP_TYPE_LIST[] = { GZIP, XZ, LZMA, BZIP2, LZ4, LZ4_LEGACY, 0 };
|
||||||
|
|
||||||
void mmap_ro(const char *filename, unsigned char **buf, size_t *size) {
|
void mmap_ro(const char *filename, unsigned char **buf, size_t *size) {
|
||||||
int fd = open(filename, O_RDONLY);
|
int fd = xopen(filename, O_RDONLY);
|
||||||
if (fd < 0)
|
|
||||||
error(1, "Cannot open %s", filename);
|
|
||||||
*size = lseek(fd, 0, SEEK_END);
|
*size = lseek(fd, 0, SEEK_END);
|
||||||
lseek(fd, 0, SEEK_SET);
|
lseek(fd, 0, SEEK_SET);
|
||||||
*buf = mmap(NULL, *size, PROT_READ, MAP_SHARED, fd, 0);
|
*buf = xmmap(NULL, *size, PROT_READ, MAP_SHARED, fd, 0);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mmap_rw(const char *filename, unsigned char **buf, size_t *size) {
|
void mmap_rw(const char *filename, unsigned char **buf, size_t *size) {
|
||||||
int fd = open(filename, O_RDWR);
|
int fd = xopen(filename, O_RDWR);
|
||||||
if (fd < 0)
|
|
||||||
error(1, "Cannot open %s", filename);
|
|
||||||
*size = lseek(fd, 0, SEEK_END);
|
*size = lseek(fd, 0, SEEK_END);
|
||||||
lseek(fd, 0, SEEK_SET);
|
lseek(fd, 0, SEEK_SET);
|
||||||
*buf = mmap(NULL, *size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
*buf = xmmap(NULL, *size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,10 +79,7 @@ void file_align(int fd, size_t align, int out) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int open_new(const char *filename) {
|
int open_new(const char *filename) {
|
||||||
int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
return xopen(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||||
if (fd < 0)
|
|
||||||
error(1, "Unable to create %s", filename);
|
|
||||||
return fd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_info() {
|
void print_info() {
|
||||||
|
@ -23,7 +23,10 @@ extern int quit_signals[];
|
|||||||
// xwrap.c
|
// xwrap.c
|
||||||
|
|
||||||
FILE *xfopen(const char *pathname, const char *mode);
|
FILE *xfopen(const char *pathname, const char *mode);
|
||||||
int xopen(const char *pathname, int flags);
|
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
|
||||||
|
#define xopen(...) GET_MACRO(__VA_ARGS__, xopen3, xopen2)(__VA_ARGS__)
|
||||||
|
int xopen2(const char *pathname, int flags);
|
||||||
|
int xopen3(const char *pathname, int flags, mode_t mode);
|
||||||
ssize_t xwrite(int fd, const void *buf, size_t count);
|
ssize_t xwrite(int fd, const void *buf, size_t count);
|
||||||
ssize_t xread(int fd, void *buf, size_t count);
|
ssize_t xread(int fd, void *buf, size_t count);
|
||||||
ssize_t xxread(int fd, void *buf, size_t count);
|
ssize_t xxread(int fd, void *buf, size_t count);
|
||||||
@ -32,7 +35,6 @@ int xsetns(int fd, int nstype);
|
|||||||
DIR *xopendir(const char *name);
|
DIR *xopendir(const char *name);
|
||||||
struct dirent *xreaddir(DIR *dirp);
|
struct dirent *xreaddir(DIR *dirp);
|
||||||
pid_t xsetsid();
|
pid_t xsetsid();
|
||||||
int xsetcon(char *context);
|
|
||||||
int xsocket(int domain, int type, int protocol);
|
int xsocket(int domain, int type, int protocol);
|
||||||
int xbind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
|
int xbind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
|
||||||
int xconnect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
|
int xconnect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
|
||||||
@ -56,6 +58,9 @@ int xmount(const char *source, const char *target,
|
|||||||
int xchmod(const char *pathname, mode_t mode);
|
int xchmod(const char *pathname, mode_t mode);
|
||||||
int xrename(const char *oldpath, const char *newpath);
|
int xrename(const char *oldpath, const char *newpath);
|
||||||
int xmkdir(const char *pathname, mode_t mode);
|
int xmkdir(const char *pathname, mode_t mode);
|
||||||
|
void *xmmap(void *addr, size_t length, int prot, int flags,
|
||||||
|
int fd, off_t offset);
|
||||||
|
ssize_t xsendfile(int out_fd, int in_fd, off_t *offset, size_t count);
|
||||||
|
|
||||||
// misc.c
|
// misc.c
|
||||||
|
|
||||||
|
@ -18,7 +18,8 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
#include <selinux/selinux.h>
|
#include <sys/mman.h>
|
||||||
|
#include <sys/sendfile.h>
|
||||||
|
|
||||||
#include "magisk.h"
|
#include "magisk.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
@ -31,7 +32,7 @@ FILE *xfopen(const char *pathname, const char *mode) {
|
|||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xopen(const char *pathname, int flags) {
|
int xopen2(const char *pathname, int flags) {
|
||||||
int fd = open(pathname, flags);
|
int fd = open(pathname, flags);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
PLOGE("open: %s", pathname);
|
PLOGE("open: %s", pathname);
|
||||||
@ -39,6 +40,14 @@ int xopen(const char *pathname, int flags) {
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int xopen3(const char *pathname, int flags, mode_t mode) {
|
||||||
|
int fd = open(pathname, flags, mode);
|
||||||
|
if (fd < 0) {
|
||||||
|
PLOGE("open: %s", pathname);
|
||||||
|
}
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
ssize_t xwrite(int fd, const void *buf, size_t count) {
|
ssize_t xwrite(int fd, const void *buf, size_t count) {
|
||||||
int ret = write(fd, buf, count);
|
int ret = write(fd, buf, count);
|
||||||
if (count != ret) {
|
if (count != ret) {
|
||||||
@ -106,14 +115,6 @@ pid_t xsetsid() {
|
|||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xsetcon(char *context) {
|
|
||||||
int ret = setcon(context);
|
|
||||||
if (ret == -1) {
|
|
||||||
PLOGE("setcon: %s", context);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int xsocket(int domain, int type, int protocol) {
|
int xsocket(int domain, int type, int protocol) {
|
||||||
int fd = socket(domain, type, protocol);
|
int fd = socket(domain, type, protocol);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
@ -280,4 +281,21 @@ int xmkdir(const char *pathname, mode_t mode) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *xmmap(void *addr, size_t length, int prot, int flags,
|
||||||
|
int fd, off_t offset) {
|
||||||
|
void *ret = mmap(addr, length, prot, flags, fd, offset);
|
||||||
|
if (ret == MAP_FAILED) {
|
||||||
|
PLOGE("mmap");
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t xsendfile(int out_fd, int in_fd, off_t *offset, size_t count) {
|
||||||
|
ssize_t ret = sendfile(out_fd, in_fd, offset, count);
|
||||||
|
if (count != ret) {
|
||||||
|
PLOGE("sendfile");
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -243,8 +243,7 @@ ui_print "- Device platform: $ARCH"
|
|||||||
BINDIR=$INSTALLER/$ARCH
|
BINDIR=$INSTALLER/$ARCH
|
||||||
chmod -R 755 $CHROMEDIR $BINDIR
|
chmod -R 755 $CHROMEDIR $BINDIR
|
||||||
|
|
||||||
SYSTEMLIB=/system/lib
|
$IS64BIT && SYSTEMLIB=/system/lib64 || SYSTEMLIB=/system/lib
|
||||||
$IS64BIT && SYSTEMLIB=/system/lib64
|
|
||||||
|
|
||||||
find_boot_image
|
find_boot_image
|
||||||
if [ -z $BOOTIMAGE ]; then
|
if [ -z $BOOTIMAGE ]; then
|
||||||
@ -315,10 +314,22 @@ cd $BOOTTMP
|
|||||||
|
|
||||||
ui_print "- Unpacking boot image"
|
ui_print "- Unpacking boot image"
|
||||||
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --unpack $BOOTIMAGE
|
LD_LIBRARY_PATH=$SYSTEMLIB $BINDIR/magiskboot --unpack $BOOTIMAGE
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
ui_print "! Unable to unpack boot image"
|
case $? in
|
||||||
exit 1
|
1 )
|
||||||
fi
|
ui_print "! Unable to unpack boot image"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
2 )
|
||||||
|
ui_print "! Sony ELF32 format detected"
|
||||||
|
ui_print "! Please use BootBridge from @AdrianDC to flash Magisk"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
3 )
|
||||||
|
ui_print "! Sony ELF64 format detected"
|
||||||
|
ui_print "! Stock kernel cannot be patched, please use a custom kernel"
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
# Ramdisk restores
|
# Ramdisk restores
|
||||||
@ -497,11 +508,11 @@ cd /
|
|||||||
if ! $BOOTMODE; then
|
if ! $BOOTMODE; then
|
||||||
ui_print "- Unmounting partitions"
|
ui_print "- Unmounting partitions"
|
||||||
umount /magisk
|
umount /magisk
|
||||||
losetup -d $MAGISKLOOP
|
losetup -d $MAGISKLOOP 2>/dev/null
|
||||||
rmdir /magisk
|
rmdir /magisk
|
||||||
if $SUPERSU; then
|
if $SUPERSU; then
|
||||||
umount /su
|
umount /su
|
||||||
losetup -d $SUPERSULOOP
|
losetup -d $SUPERSULOOP 2>/dev/null
|
||||||
rmdir /su
|
rmdir /su
|
||||||
fi
|
fi
|
||||||
umount /system
|
umount /system
|
||||||
|
Loading…
x
Reference in New Issue
Block a user