mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-08-21 04:07:50 +00:00
Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
bb70385a42 | ||
![]() |
9855877b03 | ||
![]() |
76c9188fae | ||
![]() |
e4e5269836 | ||
![]() |
9e737df534 | ||
![]() |
0b3192c4d5 | ||
![]() |
968e6237bd | ||
![]() |
d780b5a0e4 | ||
![]() |
3e48427eaf | ||
![]() |
31360c34ed | ||
![]() |
e9624e2304 | ||
![]() |
9c6e64f47d | ||
![]() |
0afa601551 | ||
![]() |
a94fa81195 |
2
app
2
app
Submodule app updated: c840a30c30...d5408d1f09
1
build.py
1
build.py
@@ -120,6 +120,7 @@ def build_binary(args):
|
|||||||
def build_apk(args):
|
def build_apk(args):
|
||||||
header('* Building Magisk Manager')
|
header('* Building Magisk Manager')
|
||||||
|
|
||||||
|
mkdir(os.path.join('app', 'src', 'main', 'assets'))
|
||||||
for script in ['magisk_uninstaller.sh', 'util_functions.sh']:
|
for script in ['magisk_uninstaller.sh', 'util_functions.sh']:
|
||||||
source = os.path.join('scripts', script)
|
source = os.path.join('scripts', script)
|
||||||
target = os.path.join('app', 'src', 'main', 'assets', script)
|
target = os.path.join('app', 'src', 'main', 'assets', script)
|
||||||
|
@@ -55,12 +55,11 @@
|
|||||||
|
|
||||||
extern policydb_t *policydb;
|
extern policydb_t *policydb;
|
||||||
int (*init_applet_main[]) (int, char *[]) = { magiskpolicy_main, magiskpolicy_main, NULL };
|
int (*init_applet_main[]) (int, char *[]) = { magiskpolicy_main, magiskpolicy_main, NULL };
|
||||||
static int keepverity = 0, keepencrypt = 0;
|
|
||||||
static char RAND_SOCKET_NAME[sizeof(SOCKET_NAME)];
|
static char RAND_SOCKET_NAME[sizeof(SOCKET_NAME)];
|
||||||
static int SOCKET_OFF = -1;
|
static int SOCKET_OFF = -1;
|
||||||
|
|
||||||
struct cmdline {
|
struct cmdline {
|
||||||
int skip_initramfs;
|
char skip_initramfs;
|
||||||
char slot[3];
|
char slot[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -74,8 +73,7 @@ struct device {
|
|||||||
|
|
||||||
static void parse_cmdline(struct cmdline *cmd) {
|
static void parse_cmdline(struct cmdline *cmd) {
|
||||||
// cleanup
|
// cleanup
|
||||||
cmd->skip_initramfs = 0;
|
memset(cmd, 0, sizeof(&cmd));
|
||||||
cmd->slot[0] = '\0';
|
|
||||||
|
|
||||||
char cmdline[4096];
|
char cmdline[4096];
|
||||||
mkdir("/proc", 0555);
|
mkdir("/proc", 0555);
|
||||||
@@ -89,11 +87,13 @@ static void parse_cmdline(struct cmdline *cmd) {
|
|||||||
sscanf(tok, "androidboot.slot_suffix=%s", cmd->slot);
|
sscanf(tok, "androidboot.slot_suffix=%s", cmd->slot);
|
||||||
} else if (strncmp(tok, "androidboot.slot", 16) == 0) {
|
} else if (strncmp(tok, "androidboot.slot", 16) == 0) {
|
||||||
cmd->slot[0] = '_';
|
cmd->slot[0] = '_';
|
||||||
sscanf(tok, "androidboot.slot=%s", cmd->slot + 1);
|
sscanf(tok, "androidboot.slot=%c", cmd->slot + 1);
|
||||||
} else if (strcmp(tok, "skip_initramfs") == 0) {
|
} else if (strcmp(tok, "skip_initramfs") == 0) {
|
||||||
cmd->skip_initramfs = 1;
|
cmd->skip_initramfs = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VLOG("cmdline: skip_initramfs[%d] slot[%s]\n", cmd->skip_initramfs, cmd->slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_device(struct device *dev, char *uevent) {
|
static void parse_device(struct device *dev, char *uevent) {
|
||||||
@@ -148,24 +148,7 @@ static int setup_block(struct device *dev, const char *partname) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fstab_patch_cb(int dirfd, struct dirent *entry) {
|
static void patch_ramdisk() {
|
||||||
if (entry->d_type == DT_REG && strstr(entry->d_name, "fstab")) {
|
|
||||||
void *buf;
|
|
||||||
size_t _size;
|
|
||||||
uint32_t size;
|
|
||||||
full_read_at(dirfd, entry->d_name, &buf, &_size);
|
|
||||||
size = (uint32_t) _size; /* Type conversion */
|
|
||||||
if (!keepverity)
|
|
||||||
patch_verity(&buf, &size, 1);
|
|
||||||
if (!keepencrypt)
|
|
||||||
patch_encryption(&buf, &size);
|
|
||||||
int fstab = xopenat(dirfd, entry->d_name, O_WRONLY | O_CLOEXEC);
|
|
||||||
write(fstab, buf, size);
|
|
||||||
close(fstab);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void patch_ramdisk(int root) {
|
|
||||||
void *addr;
|
void *addr;
|
||||||
size_t size;
|
size_t size;
|
||||||
mmap_rw("/init", &addr, &size);
|
mmap_rw("/init", &addr, &size);
|
||||||
@@ -183,25 +166,6 @@ static void patch_ramdisk(int root) {
|
|||||||
write(fd, addr, size);
|
write(fd, addr, size);
|
||||||
close(fd);
|
close(fd);
|
||||||
free(addr);
|
free(addr);
|
||||||
|
|
||||||
/* Disabled for now */
|
|
||||||
|
|
||||||
// char *key, *value;
|
|
||||||
// full_read("/.backup/.magisk", &addr, &size);
|
|
||||||
// for (char *tok = strtok(addr, "\n"); tok; tok = strtok(NULL, "\n")) {
|
|
||||||
// key = tok;
|
|
||||||
// value = strchr(tok, '=') + 1;
|
|
||||||
// value[-1] = '\0';
|
|
||||||
// if (strcmp(key, "KEEPVERITY") == 0)
|
|
||||||
// keepverity = strcmp(value, "true") == 0;
|
|
||||||
// else if (strcmp(key, "KEEPFORCEENCRYPT") == 0)
|
|
||||||
// keepencrypt = strcmp(value, "true") == 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// excl_list = (char *[]) { "system_root", "system", "vendor", NULL };
|
|
||||||
// in_order_walk(root, fstab_patch_cb);
|
|
||||||
// if (!keepverity)
|
|
||||||
// unlink("/verity_key");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int strend(const char *s1, const char *s2) {
|
static int strend(const char *s1, const char *s2) {
|
||||||
@@ -375,7 +339,7 @@ static void patch_socket_name(const char *path) {
|
|||||||
mmap_rw(path, &buf, &size);
|
mmap_rw(path, &buf, &size);
|
||||||
if (SOCKET_OFF < 0) {
|
if (SOCKET_OFF < 0) {
|
||||||
for (int i = 0; i < size; ++i) {
|
for (int i = 0; i < size; ++i) {
|
||||||
if (memcmp(buf + i, SOCKET_NAME, sizeof(SOCKET_NAME)) == 0) {
|
if (memcmp(buf + i, socket_name, sizeof(SOCKET_NAME)) == 0) {
|
||||||
SOCKET_OFF = i;
|
SOCKET_OFF = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -465,51 +429,24 @@ int main(int argc, char *argv[]) {
|
|||||||
dump_magiskrc("/overlay/init.magisk.rc", 0750);
|
dump_magiskrc("/overlay/init.magisk.rc", 0750);
|
||||||
mkdir("/overlay/sbin", 0755);
|
mkdir("/overlay/sbin", 0755);
|
||||||
dump_magisk("/overlay/sbin/magisk", 0755);
|
dump_magisk("/overlay/sbin/magisk", 0755);
|
||||||
|
patch_socket_name("/overlay/sbin/magisk");
|
||||||
mkdir("/overlay/root", 0755);
|
mkdir("/overlay/root", 0755);
|
||||||
link("/init", "/overlay/root/magiskinit");
|
link("/init", "/overlay/root/magiskinit");
|
||||||
patch_socket_name("/overlay/sbin/magisk");
|
|
||||||
|
|
||||||
struct cmdline cmd;
|
struct cmdline cmd;
|
||||||
parse_cmdline(&cmd);
|
parse_cmdline(&cmd);
|
||||||
|
|
||||||
VLOG("cmdline: skip_initramfs=[%d] slot_suffix=[%s]\n", cmd.skip_initramfs, cmd.slot);
|
/* ***********
|
||||||
|
* Initialize
|
||||||
|
* ***********/
|
||||||
|
|
||||||
int root = open("/", O_RDONLY | O_CLOEXEC);
|
int root = open("/", O_RDONLY | O_CLOEXEC);
|
||||||
|
|
||||||
if (cmd.skip_initramfs) {
|
if (cmd.skip_initramfs) {
|
||||||
// Exclude overlay folder
|
|
||||||
excl_list = (char *[]) { "overlay", ".backup", NULL };
|
|
||||||
// Clear rootfs
|
// Clear rootfs
|
||||||
|
excl_list = (char *[]) { "overlay", ".backup", NULL };
|
||||||
frm_rf(root);
|
frm_rf(root);
|
||||||
|
} else if (access("/ramdisk.cpio.xz", R_OK) == 0) {
|
||||||
mkdir("/sys", 0755);
|
|
||||||
xmount("sysfs", "/sys", "sysfs", 0, NULL);
|
|
||||||
|
|
||||||
char partname[32];
|
|
||||||
snprintf(partname, sizeof(partname), "system%s", cmd.slot);
|
|
||||||
|
|
||||||
struct device dev;
|
|
||||||
setup_block(&dev, partname);
|
|
||||||
|
|
||||||
mkdir("/system_root", 0755);
|
|
||||||
xmount(dev.path, "/system_root", "ext4", MS_RDONLY, NULL);
|
|
||||||
int system_root = open("/system_root", O_RDONLY | O_CLOEXEC);
|
|
||||||
|
|
||||||
// Exclude system folder
|
|
||||||
excl_list = (char *[]) { "system", NULL };
|
|
||||||
clone_dir(system_root, root);
|
|
||||||
mkdir("/system", 0755);
|
|
||||||
xmount("/system_root/system", "/system", NULL, MS_BIND, NULL);
|
|
||||||
|
|
||||||
snprintf(partname, sizeof(partname), "vendor%s", cmd.slot);
|
|
||||||
|
|
||||||
// We need to mount independent vendor partition
|
|
||||||
if (setup_block(&dev, partname) == 0)
|
|
||||||
xmount(dev.path, "/vendor", "ext4", MS_RDONLY, NULL);
|
|
||||||
|
|
||||||
close(system_root);
|
|
||||||
} else {
|
|
||||||
if (access("/ramdisk.cpio.xz", R_OK) == 0) {
|
|
||||||
// High compression mode
|
// High compression mode
|
||||||
void *addr;
|
void *addr;
|
||||||
size_t size;
|
size_t size;
|
||||||
@@ -531,32 +468,59 @@ int main(int argc, char *argv[]) {
|
|||||||
unlink("/init");
|
unlink("/init");
|
||||||
link("/.backup/init", "/init");
|
link("/.backup/init", "/init");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************
|
||||||
|
* Early Mount
|
||||||
|
* ************/
|
||||||
|
|
||||||
|
// If skip_initramfs or using split policies, we need early mount
|
||||||
|
if (cmd.skip_initramfs || access("/sepolicy", R_OK) != 0) {
|
||||||
|
char partname[32];
|
||||||
|
struct device dev;
|
||||||
|
|
||||||
|
// Mount sysfs
|
||||||
|
mkdir("/sys", 0755);
|
||||||
|
xmount("sysfs", "/sys", "sysfs", 0, NULL);
|
||||||
|
|
||||||
|
// Mount system
|
||||||
|
snprintf(partname, sizeof(partname), "system%s", cmd.slot);
|
||||||
|
setup_block(&dev, partname);
|
||||||
|
if (cmd.skip_initramfs) {
|
||||||
|
mkdir("/system_root", 0755);
|
||||||
|
xmount(dev.path, "/system_root", "ext4", MS_RDONLY, NULL);
|
||||||
|
int system_root = open("/system_root", O_RDONLY | O_CLOEXEC);
|
||||||
|
|
||||||
|
// Clone rootfs except /system
|
||||||
|
excl_list = (char *[]) { "system", NULL };
|
||||||
|
clone_dir(system_root, root);
|
||||||
|
close(system_root);
|
||||||
|
|
||||||
|
mkdir("/system", 0755);
|
||||||
|
xmount("/system_root/system", "/system", NULL, MS_BIND, NULL);
|
||||||
|
} else {
|
||||||
|
xmount(dev.path, "/system", "ext4", MS_RDONLY, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mount vendor
|
||||||
|
snprintf(partname, sizeof(partname), "vendor%s", cmd.slot);
|
||||||
|
if (setup_block(&dev, partname) == 0)
|
||||||
|
xmount(dev.path, "/vendor", "ext4", MS_RDONLY, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* *************
|
||||||
|
* Patch rootfs
|
||||||
|
* *************/
|
||||||
|
|
||||||
// Only patch rootfs if not intended to run in recovery
|
// Only patch rootfs if not intended to run in recovery
|
||||||
if (access("/etc/recovery.fstab", F_OK) != 0) {
|
if (access("/etc/recovery.fstab", F_OK) != 0) {
|
||||||
int overlay = open("/overlay", O_RDONLY | O_CLOEXEC);
|
int overlay = open("/overlay", O_RDONLY | O_CLOEXEC);
|
||||||
mv_dir(overlay, root);
|
mv_dir(overlay, root);
|
||||||
|
close(overlay);
|
||||||
|
rmdir("/overlay");
|
||||||
|
|
||||||
patch_ramdisk(root);
|
patch_ramdisk();
|
||||||
if (patch_sepolicy()) {
|
|
||||||
/* Non skip_initramfs devices using separate sepolicy
|
|
||||||
* Mount /system and try to load again */
|
|
||||||
xmount("sysfs", "/sys", "sysfs", 0, NULL);
|
|
||||||
struct device dev;
|
|
||||||
setup_block(&dev, "system");
|
|
||||||
xmount(dev.path, "/system", "ext4", MS_RDONLY, NULL);
|
|
||||||
// We need to mount independent vendor partition
|
|
||||||
if (setup_block(&dev, "vendor") == 0)
|
|
||||||
xmount(dev.path, "/vendor", "ext4", MS_RDONLY, NULL);
|
|
||||||
|
|
||||||
patch_sepolicy();
|
patch_sepolicy();
|
||||||
|
|
||||||
umount("/system");
|
|
||||||
}
|
|
||||||
|
|
||||||
close(overlay);
|
|
||||||
close(STDIN_FILENO);
|
close(STDIN_FILENO);
|
||||||
close(STDOUT_FILENO);
|
close(STDOUT_FILENO);
|
||||||
close(STDERR_FILENO);
|
close(STDERR_FILENO);
|
||||||
@@ -570,8 +534,9 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
close(root);
|
close(root);
|
||||||
|
if (!cmd.skip_initramfs)
|
||||||
|
umount("/system");
|
||||||
umount("/vendor");
|
umount("/vendor");
|
||||||
rmdir("/overlay");
|
|
||||||
|
|
||||||
// Finally, give control back!
|
// Finally, give control back!
|
||||||
execv("/init", argv);
|
execv("/init", argv);
|
||||||
|
@@ -8,13 +8,15 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "magisk.h"
|
#include "magisk.h"
|
||||||
|
|
||||||
|
char socket_name[] = SOCKET_NAME;
|
||||||
|
|
||||||
/* Setup the address and return socket fd */
|
/* Setup the address and return socket fd */
|
||||||
int setup_socket(struct sockaddr_un *sun) {
|
int setup_socket(struct sockaddr_un *sun) {
|
||||||
int fd = xsocket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
int fd = xsocket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
||||||
memset(sun, 0, sizeof(*sun));
|
memset(sun, 0, sizeof(*sun));
|
||||||
sun->sun_family = AF_LOCAL;
|
sun->sun_family = AF_LOCAL;
|
||||||
sun->sun_path[0] = '\0';
|
sun->sun_path[0] = '\0';
|
||||||
memcpy(sun->sun_path + 1, SOCKET_NAME, sizeof(SOCKET_NAME));
|
memcpy(sun->sun_path + 1, socket_name, sizeof(SOCKET_NAME));
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
native/jni/external/busybox
vendored
2
native/jni/external/busybox
vendored
Submodule native/jni/external/busybox updated: 272bfb363b...e1895e6c95
@@ -55,6 +55,7 @@ extern char *argv0; /* For changing process name */
|
|||||||
#define init_applet ((char *[]) { "magiskpolicy", "supolicy", NULL })
|
#define init_applet ((char *[]) { "magiskpolicy", "supolicy", NULL })
|
||||||
|
|
||||||
extern int (*applet_main[]) (int, char *[]), (*init_applet_main[]) (int, char *[]);
|
extern int (*applet_main[]) (int, char *[]), (*init_applet_main[]) (int, char *[]);
|
||||||
|
extern char socket_name[]; /* Workaround compiler bug pre NDK r13 */
|
||||||
|
|
||||||
int create_links(const char *bin, const char *path);
|
int create_links(const char *bin, const char *path);
|
||||||
|
|
||||||
|
@@ -124,10 +124,16 @@ int parse_img(const char *image, boot_img *boot) {
|
|||||||
fprintf(stderr, "PXA_BOOT_HDR\n");
|
fprintf(stderr, "PXA_BOOT_HDR\n");
|
||||||
boot->hdr = malloc(sizeof(pxa_boot_img_hdr));
|
boot->hdr = malloc(sizeof(pxa_boot_img_hdr));
|
||||||
memcpy(boot->hdr, head, sizeof(pxa_boot_img_hdr));
|
memcpy(boot->hdr, head, sizeof(pxa_boot_img_hdr));
|
||||||
} else if (memcmp(((boot_img_hdr*) head)->cmdline, NOOK_MAGIC, 12) == 0) {
|
} else if (memcmp(((boot_img_hdr*) head)->cmdline, NOOKHD_MAGIC, 12) == 0
|
||||||
boot->flags |= NOOK_FLAG;
|
|| memcmp(((boot_img_hdr*) head)->cmdline, NOOKHD_NEW_MAGIC, 26) == 0) {
|
||||||
fprintf(stderr, "NOOK_GREEN_LOADER\n");
|
boot->flags |= NOOKHD_FLAG;
|
||||||
head += NOOK_PRE_HEADER_SZ - 1;
|
fprintf(stderr, "NOOKHD_GREEN_LOADER\n");
|
||||||
|
head += NOOKHD_PRE_HEADER_SZ - 1;
|
||||||
|
continue;
|
||||||
|
} else if (memcmp(((boot_img_hdr*) head)->name, ACCLAIM_MAGIC, 10) == 0) {
|
||||||
|
boot->flags |= ACCLAIM_FLAG;
|
||||||
|
fprintf(stderr, "ACCLAIM_BAUWKSBOOT\n");
|
||||||
|
head += ACCLAIM_PRE_HEADER_SZ - 1;
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
boot->hdr = malloc(sizeof(boot_img_hdr));
|
boot->hdr = malloc(sizeof(boot_img_hdr));
|
||||||
@@ -202,12 +208,12 @@ int parse_img(const char *image, boot_img *boot) {
|
|||||||
fprintf(stderr, "MTK_RAMDISK_HDR\n");
|
fprintf(stderr, "MTK_RAMDISK_HDR\n");
|
||||||
boot->flags |= MTK_RAMDISK;
|
boot->flags |= MTK_RAMDISK;
|
||||||
boot->r_hdr = malloc(sizeof(mtk_hdr));
|
boot->r_hdr = malloc(sizeof(mtk_hdr));
|
||||||
memcpy(boot->r_hdr, boot->kernel, sizeof(mtk_hdr));
|
memcpy(boot->r_hdr, boot->ramdisk, sizeof(mtk_hdr));
|
||||||
fprintf(stderr, "RAMDISK [%u]\n", boot->r_hdr->size);
|
fprintf(stderr, "RAMDISK [%u]\n", boot->r_hdr->size);
|
||||||
fprintf(stderr, "NAME [%s]\n", boot->r_hdr->name);
|
fprintf(stderr, "NAME [%s]\n", boot->r_hdr->name);
|
||||||
boot->ramdisk += 512;
|
boot->ramdisk += 512;
|
||||||
lheader(boot, ramdisk_size, -= 512);
|
lheader(boot, ramdisk_size, -= 512);
|
||||||
boot->k_fmt = check_fmt(boot->ramdisk, header(boot, ramdisk_size));
|
boot->r_fmt = check_fmt(boot->ramdisk, header(boot, ramdisk_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
char fmt[16];
|
char fmt[16];
|
||||||
@@ -288,8 +294,10 @@ void repack(const char* orig_image, const char* out_image) {
|
|||||||
} else if (boot.flags & BLOB_FLAG) {
|
} else if (boot.flags & BLOB_FLAG) {
|
||||||
// Skip blob header
|
// Skip blob header
|
||||||
write_zero(fd, sizeof(blob_hdr));
|
write_zero(fd, sizeof(blob_hdr));
|
||||||
} else if (boot.flags & NOOK_FLAG) {
|
} else if (boot.flags & NOOKHD_FLAG) {
|
||||||
restore_buf(fd, boot.map_addr, NOOK_PRE_HEADER_SZ);
|
restore_buf(fd, boot.map_addr, NOOKHD_PRE_HEADER_SZ);
|
||||||
|
} else if (boot.flags & ACCLAIM_FLAG) {
|
||||||
|
restore_buf(fd, boot.map_addr, ACCLAIM_PRE_HEADER_SZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip a page for header
|
// Skip a page for header
|
||||||
@@ -312,12 +320,13 @@ void repack(const char* orig_image, const char* out_image) {
|
|||||||
} else {
|
} else {
|
||||||
lheader(&boot, kernel_size, = restore(KERNEL_FILE, fd));
|
lheader(&boot, kernel_size, = restore(KERNEL_FILE, fd));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// dtb
|
// dtb
|
||||||
if (access(DTB_FILE, R_OK) == 0) {
|
if (access(DTB_FILE, R_OK) == 0) {
|
||||||
lheader(&boot, kernel_size, += restore(DTB_FILE, fd));
|
lheader(&boot, kernel_size, += restore(DTB_FILE, fd));
|
||||||
}
|
}
|
||||||
file_align();
|
file_align();
|
||||||
}
|
|
||||||
|
|
||||||
// ramdisk
|
// ramdisk
|
||||||
ramdisk_off = lseek(fd, 0, SEEK_CUR);
|
ramdisk_off = lseek(fd, 0, SEEK_CUR);
|
||||||
@@ -333,7 +342,7 @@ void repack(const char* orig_image, const char* out_image) {
|
|||||||
lheader(&boot, ramdisk_size, = comp(boot.r_fmt, fd, cpio, cpio_size));
|
lheader(&boot, ramdisk_size, = comp(boot.r_fmt, fd, cpio, cpio_size));
|
||||||
munmap(cpio, cpio_size);
|
munmap(cpio, cpio_size);
|
||||||
} else {
|
} else {
|
||||||
lheader(&boot, kernel_size, = restore(KERNEL_FILE, fd));
|
lheader(&boot, ramdisk_size, = restore(RAMDISK_FILE, fd));
|
||||||
}
|
}
|
||||||
file_align();
|
file_align();
|
||||||
}
|
}
|
||||||
|
@@ -130,7 +130,8 @@ typedef struct blob_hdr {
|
|||||||
#define LG_BUMP_FLAG 0x0040
|
#define LG_BUMP_FLAG 0x0040
|
||||||
#define SHA256_FLAG 0x0080
|
#define SHA256_FLAG 0x0080
|
||||||
#define BLOB_FLAG 0x0100
|
#define BLOB_FLAG 0x0100
|
||||||
#define NOOK_FLAG 0x0200
|
#define NOOKHD_FLAG 0x0200
|
||||||
|
#define ACCLAIM_FLAG 0x0400
|
||||||
|
|
||||||
typedef struct boot_img {
|
typedef struct boot_img {
|
||||||
// Memory map of the whole image
|
// Memory map of the whole image
|
||||||
|
@@ -38,8 +38,11 @@ typedef enum {
|
|||||||
#define DHTB_MAGIC "\x44\x48\x54\x42\x01\x00\x00\x00"
|
#define DHTB_MAGIC "\x44\x48\x54\x42\x01\x00\x00\x00"
|
||||||
#define SEANDROID_MAGIC "SEANDROIDENFORCE"
|
#define SEANDROID_MAGIC "SEANDROIDENFORCE"
|
||||||
#define TEGRABLOB_MAGIC "-SIGNED-BY-SIGNBLOB-"
|
#define TEGRABLOB_MAGIC "-SIGNED-BY-SIGNBLOB-"
|
||||||
#define NOOK_MAGIC "Green Loader"
|
#define NOOKHD_MAGIC "Green Loader"
|
||||||
#define NOOK_PRE_HEADER_SZ 1048575
|
#define NOOKHD_NEW_MAGIC "eMMC boot.img+secondloader"
|
||||||
|
#define NOOKHD_PRE_HEADER_SZ 1048576
|
||||||
|
#define ACCLAIM_MAGIC "BauwksBoot"
|
||||||
|
#define ACCLAIM_PRE_HEADER_SZ 262144
|
||||||
|
|
||||||
#define SUP_LIST ((char *[]) { "gzip", "xz", "lzma", "bzip2", "lz4", "lz4_legacy", NULL })
|
#define SUP_LIST ((char *[]) { "gzip", "xz", "lzma", "bzip2", "lz4", "lz4_legacy", NULL })
|
||||||
#define SUP_EXT_LIST ((char *[]) { "gz", "xz", "lzma", "bz2", "lz4", "lz4", NULL })
|
#define SUP_EXT_LIST ((char *[]) { "gz", "xz", "lzma", "bz2", "lz4", "lz4", NULL })
|
||||||
|
@@ -34,18 +34,22 @@ static void cpio_patch(struct vector *v, int keepverity, int keepforceencrypt) {
|
|||||||
|
|
||||||
#define STOCK_BOOT 0x0
|
#define STOCK_BOOT 0x0
|
||||||
#define MAGISK_PATCH 0x1
|
#define MAGISK_PATCH 0x1
|
||||||
#define OTHER_PATCH 0x2
|
#define HIGH_COMPRESS 0x2
|
||||||
|
#define OTHER_PATCH 0x3
|
||||||
|
|
||||||
static int cpio_test(struct vector *v) {
|
static int cpio_test(struct vector *v) {
|
||||||
const char *OTHER_LIST[] = { "sbin/launch_daemonsu.sh", "sbin/su", "init.xposed.rc", "boot/sbin/launch_daemonsu.sh", NULL };
|
const char *OTHER_LIST[] = { "sbin/launch_daemonsu.sh", "sbin/su", "init.xposed.rc", "boot/sbin/launch_daemonsu.sh", NULL };
|
||||||
const char *MAGISK_LIST[] = { ".backup/.magisk", "init.magisk.rc", "overlay/init.magisk.rc", NULL };
|
const char *MAGISK_LIST[] = { ".backup/.magisk", "init.magisk.rc", "overlay/init.magisk.rc", NULL };
|
||||||
|
|
||||||
for (int i = 0; OTHER_LIST[i]; ++i)
|
for (int i = 0; OTHER_LIST[i]; ++i)
|
||||||
if (cpio_find(v, OTHER_LIST[i]) > 0)
|
if (cpio_find(v, OTHER_LIST[i]) >= 0)
|
||||||
return OTHER_PATCH;
|
return OTHER_PATCH;
|
||||||
|
|
||||||
|
if (cpio_find(v, "ramdisk.cpio.xz") >= 0)
|
||||||
|
return HIGH_COMPRESS;
|
||||||
|
|
||||||
for (int i = 0; MAGISK_LIST[i]; ++i)
|
for (int i = 0; MAGISK_LIST[i]; ++i)
|
||||||
if (cpio_find(v, MAGISK_LIST[i]) > 0)
|
if (cpio_find(v, MAGISK_LIST[i]) >= 0)
|
||||||
return MAGISK_PATCH;
|
return MAGISK_PATCH;
|
||||||
|
|
||||||
return STOCK_BOOT;
|
return STOCK_BOOT;
|
||||||
|
Submodule native/jni/magiskpolicy updated: 2f4062a923...21a557a184
@@ -1116,7 +1116,8 @@ static bool initialize_properties() {
|
|||||||
if (!initialize_properties_from_file("/system/etc/selinux/plat_property_contexts")) {
|
if (!initialize_properties_from_file("/system/etc/selinux/plat_property_contexts")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!initialize_properties_from_file("/vendor/etc/selinux/nonplat_property_contexts")) {
|
if (!initialize_properties_from_file("/vendor/etc/selinux/nonplat_property_contexts")
|
||||||
|
&& !initialize_properties_from_file("/vendor/etc/selinux/vendor_property_contexts")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@@ -58,11 +58,13 @@ int create_img(const char *img, int size) {
|
|||||||
LOGI("Create %s with size %dM\n", img, size);
|
LOGI("Create %s with size %dM\n", img, size);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
char buffer[16];
|
char size_str[16];
|
||||||
snprintf(buffer, sizeof(buffer), "%dM", size);
|
snprintf(size_str, sizeof(size_str), "%dM", size);
|
||||||
ret = exec_command_sync("make_ext4fs", "-l", buffer, img, NULL);
|
ret = exec_command_sync("make_ext4fs", "-b", "4096", "-l", size_str, img, NULL);
|
||||||
if (ret < 0)
|
if (ret < 0) {
|
||||||
return 1;
|
// On Android P there is no make_ext4fs, use mke2fs
|
||||||
|
ret = exec_command_sync("mke2fs", "-b", "4096", "-t", "ext4", img, size_str, NULL);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -280,7 +280,7 @@ static int v_exec_command(int err, int *fd, void (*setupenv)(struct vector*), co
|
|||||||
}
|
}
|
||||||
|
|
||||||
execvpe(argv0, (char **) vec_entry(&args), envp);
|
execvpe(argv0, (char **) vec_entry(&args), envp);
|
||||||
PLOGE("execvpe");
|
PLOGE("execvpe %s", argv0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -91,9 +91,7 @@ case $? in
|
|||||||
abort "! Unable to unpack boot image"
|
abort "! Unable to unpack boot image"
|
||||||
;;
|
;;
|
||||||
2 )
|
2 )
|
||||||
ui_print "! Insufficient boot partition size detected"
|
|
||||||
HIGHCOMP=true
|
HIGHCOMP=true
|
||||||
ui_print "- Enable high compression mode"
|
|
||||||
;;
|
;;
|
||||||
3 )
|
3 )
|
||||||
ui_print "- ChromeOS boot image detected"
|
ui_print "- ChromeOS boot image detected"
|
||||||
@@ -114,6 +112,7 @@ esac
|
|||||||
|
|
||||||
# Test patch status and do restore, after this section, ramdisk.cpio.orig is guaranteed to exist
|
# Test patch status and do restore, after this section, ramdisk.cpio.orig is guaranteed to exist
|
||||||
ui_print "- Checking ramdisk status"
|
ui_print "- Checking ramdisk status"
|
||||||
|
MAGISK_PATCHED=false
|
||||||
./magiskboot --cpio ramdisk.cpio test
|
./magiskboot --cpio ramdisk.cpio test
|
||||||
case $? in
|
case $? in
|
||||||
0 ) # Stock boot
|
0 ) # Stock boot
|
||||||
@@ -125,17 +124,31 @@ case $? in
|
|||||||
cp -af ramdisk.cpio ramdisk.cpio.orig
|
cp -af ramdisk.cpio ramdisk.cpio.orig
|
||||||
;;
|
;;
|
||||||
1 ) # Magisk patched
|
1 ) # Magisk patched
|
||||||
|
MAGISK_PATCHED=true
|
||||||
|
HIGHCOMP=false
|
||||||
|
;;
|
||||||
|
2 ) # High compression mode
|
||||||
|
MAGISK_PATCHED=true
|
||||||
|
HIGHCOMP=true
|
||||||
|
;;
|
||||||
|
3 ) # Other patched
|
||||||
|
ui_print "! Boot image patched by other programs"
|
||||||
|
abort "! Please restore stock boot image"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if $MAGISK_PATCHED; then
|
||||||
ui_print "- Magisk patched image detected"
|
ui_print "- Magisk patched image detected"
|
||||||
# Find SHA1 of stock boot image
|
# Find SHA1 of stock boot image
|
||||||
[ -z $SHA1 ] && SHA1=`./magiskboot --cpio ramdisk.cpio sha1 2>/dev/null`
|
[ -z $SHA1 ] && SHA1=`./magiskboot --cpio ramdisk.cpio sha1 2>/dev/null`
|
||||||
./magiskboot --cpio ramdisk.cpio restore
|
./magiskboot --cpio ramdisk.cpio restore
|
||||||
cp -af ramdisk.cpio ramdisk.cpio.orig
|
cp -af ramdisk.cpio ramdisk.cpio.orig
|
||||||
;;
|
fi
|
||||||
2 ) # Other patched
|
|
||||||
ui_print "! Boot image patched by other programs"
|
if $HIGHCOMP; then
|
||||||
abort "! Please restore stock boot image"
|
ui_print "! Insufficient boot partition size detected"
|
||||||
;;
|
ui_print "- Enable high compression mode"
|
||||||
esac
|
fi
|
||||||
|
|
||||||
##########################################################################################
|
##########################################################################################
|
||||||
# Ramdisk patches
|
# Ramdisk patches
|
||||||
|
@@ -73,7 +73,7 @@ case $? in
|
|||||||
ui_print "- Stock boot image detected"
|
ui_print "- Stock boot image detected"
|
||||||
abort "! Magisk is not installed!"
|
abort "! Magisk is not installed!"
|
||||||
;;
|
;;
|
||||||
1 ) # Magisk patched
|
1|2 ) # Magisk patched
|
||||||
ui_print "- Magisk patched image detected"
|
ui_print "- Magisk patched image detected"
|
||||||
# Find SHA1 of stock boot image
|
# Find SHA1 of stock boot image
|
||||||
[ -z $SHA1 ] && SHA1=`./magiskboot --cpio ramdisk.cpio sha1 2>/dev/null`
|
[ -z $SHA1 ] && SHA1=`./magiskboot --cpio ramdisk.cpio sha1 2>/dev/null`
|
||||||
@@ -89,7 +89,7 @@ case $? in
|
|||||||
flash_boot_image new-boot.img "$BOOTIMAGE"
|
flash_boot_image new-boot.img "$BOOTIMAGE"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
2 ) # Other patched
|
3 ) # Other patched
|
||||||
ui_print "! Boot image patched by other programs"
|
ui_print "! Boot image patched by other programs"
|
||||||
abort "! Cannot uninstall"
|
abort "! Cannot uninstall"
|
||||||
;;
|
;;
|
||||||
@@ -103,4 +103,4 @@ rm -rf /cache/*magisk* /cache/unblock /data/*magisk* /data/cache/*magisk* /data
|
|||||||
/data/user*/*/magisk.db /data/user*/*/com.topjohnwu.magisk /data/user*/*/.tmp.magisk.config \
|
/data/user*/*/magisk.db /data/user*/*/com.topjohnwu.magisk /data/user*/*/.tmp.magisk.config \
|
||||||
/data/adb/*magisk* 2>/dev/null
|
/data/adb/*magisk* 2>/dev/null
|
||||||
|
|
||||||
$BOOTMODE && reboot
|
$BOOTMODE && /system/bin/reboot
|
||||||
|
@@ -494,6 +494,7 @@ public class SignAPK {
|
|||||||
outputStream.write(total_size & 0xff);
|
outputStream.write(total_size & 0xff);
|
||||||
outputStream.write((total_size >> 8) & 0xff);
|
outputStream.write((total_size >> 8) & 0xff);
|
||||||
temp.writeTo(outputStream);
|
temp.writeTo(outputStream);
|
||||||
|
outputStream.close();
|
||||||
}
|
}
|
||||||
private static void signFile(Manifest manifest, JarMap inputJar,
|
private static void signFile(Manifest manifest, JarMap inputJar,
|
||||||
X509Certificate publicKey, PrivateKey privateKey,
|
X509Certificate publicKey, PrivateKey privateKey,
|
||||||
|
Reference in New Issue
Block a user