Compare commits

...

21 Commits
v16.0 ... v16.3

Author SHA1 Message Date
topjohnwu
7d7686da33 Update Magisk Manager 2018-03-28 15:23:55 +08:00
topjohnwu
65e455ef0b Update Android gradle plugin 2018-03-28 02:43:03 +08:00
topjohnwu
ac05e2f2e2 Fix tail size calculation
Close #381
2018-03-27 00:45:18 +08:00
topjohnwu
787f7b3035 Remove backwards compatibility symlinks
These links cause magiskhide unable to work ideally and add complications. I think I gave enough time for migration
2018-03-27 00:35:59 +08:00
topjohnwu
31bd642b80 Update to busybox 1.28.2 2018-03-26 22:12:04 +08:00
topjohnwu
f0bac6b154 Resetprop small refactor 2018-03-26 21:21:48 +08:00
topjohnwu
cc7e74ca11 Cleanup build.gradle 2018-03-26 03:53:06 +08:00
topjohnwu
e8a44646b8 Update Magisk Manager 2018-03-18 12:34:07 +08:00
topjohnwu
ae97d011ae Change MagiskHide state if logd is disabled 2018-03-18 12:17:10 +08:00
imswebra
1b7657a374 tips.md Grammar Fix 2018-03-18 12:16:57 +08:00
topjohnwu
5665e04014 Force using system binaries 2018-03-17 21:42:42 +08:00
topjohnwu
bb70385a42 Update Magisk Manager 2018-03-11 08:37:13 +08:00
topjohnwu
9855877b03 Update rules for Android P 2018-03-11 08:36:20 +08:00
topjohnwu
76c9188fae Android P renamed nonplat_properties 2018-03-11 02:53:57 +08:00
topjohnwu
e4e5269836 Android P have no make_ext4fs, use mke2fs as fallback 2018-03-11 02:52:24 +08:00
topjohnwu
9e737df534 Update high compression mode detection logic 2018-03-10 15:55:55 +08:00
Shaka Huang
0b3192c4d5 Check dtb even if kernel is not available
By the flow of unpacking boot image of Chrome OS there will be no kernel file but an dtb image. In that case the dtb image won’t be added when repacking boot image.

Signed-off-by: Shaka Huang <shakalaca@gmail.com>
2018-03-03 20:57:55 +08:00
Shaka Huang
968e6237bd Fix error parsing MTK boot.img
Should be copy & paste error:

1. boot->r_fmt should be re-checked instead of boot->k_fmt once MTK header was found in ramdisk.

2. ramdisk_size should be restored instead of kernel_size when uncompressed ramdisk was found.

3. Correct header of ramdisk

Signed-off-by: Shaka Huang <shakalaca@gmail.com>
2018-03-03 20:57:37 +08:00
worstperson
d780b5a0e4 Add support for the Nook Tablet, Acclaim
Also changed occurences of NOOK with NOOKHD
2018-03-03 20:55:44 +08:00
worstperson
3e48427eaf Add support for the new NOOK_MAGIC
The new cmdline value that's been in use since Marshmallow
2018-03-03 20:55:44 +08:00
worstperson
31360c34ed Set NOOK_PRE_HEADER_SZ from 0xFFFFF to 0x100000
All applicable Nook HD/HD+ roms are using this offset
2018-03-03 20:55:44 +08:00
23 changed files with 112 additions and 147 deletions

2
app

Submodule app updated: 3f38579529...e79d764148

View File

@@ -7,7 +7,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.0.1' classpath 'com.android.tools.build:gradle:3.1.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
@@ -19,9 +19,16 @@ allprojects {
repositories { repositories {
google() google()
jcenter() jcenter()
maven { url "https://jitpack.io" }
} }
} }
ext {
compileSdkVersion = 27
buildToolsVersion = "27.0.3"
supportLibVersion = "27.1.0"
}
task clean(type: Delete) { task clean(type: Delete) {
delete rootProject.buildDir delete rootProject.buildDir
} }

View File

@@ -1,7 +1,7 @@
# Tips and Tricks # Tips and Tricks
## OTA Installation Tips ## OTA Installation Tips
Magisk do modifications systemless-ly, which means applying official OTAs is much simpler. Here I provide a few tutorials for several different kind of devices to apply OTAs and preserve Magisk after the installation if possible. Magisk does modifications systemless-ly, which means applying official OTAs is much simpler. Here I provide a few tutorials for several different kind of devices to apply OTAs and preserve Magisk after the installation if possible.
**This tutorial is only for Magisk v14.1+** **This tutorial is only for Magisk v14.1+**
@@ -50,4 +50,4 @@ If you decide to start by installing Magisk without touching your recovery parti
How to remove a file systemless-ly? To actually make the file **disappear** is complicated (possible, not worth the effort). **Replacing it with a dummy file should be good enough**! Create an empty file with the same name and place it in the same path within a module, it shall replace your target file with a dummy file. How to remove a file systemless-ly? To actually make the file **disappear** is complicated (possible, not worth the effort). **Replacing it with a dummy file should be good enough**! Create an empty file with the same name and place it in the same path within a module, it shall replace your target file with a dummy file.
## Remove Folders ## Remove Folders
Same as mentioned above, actually making the folder to **disappear** is not worth the effort. **Replacing it with an empty folder should be good enough**! A handy trick for module developers using [Magisk Module Template](https://github.com/topjohnwu/magisk-module-template) is to add the folder you want to remove into the `REPLACE` list within `config.sh`. If your module doesn't provide a correspond folder, it will create an empty folder, and automatically add `.replace` into the empty folder so the dummy folder will properly replace the one in `/system`. Same as mentioned above, actually making the folder to **disappear** is not worth the effort. **Replacing it with an empty folder should be good enough**! A handy trick for module developers using [Magisk Module Template](https://github.com/topjohnwu/magisk-module-template) is to add the folder you want to remove into the `REPLACE` list within `config.sh`. If your module doesn't provide a correspond folder, it will create an empty folder, and automatically add `.replace` into the empty folder so the dummy folder will properly replace the one in `/system`.

View File

@@ -1,6 +1,6 @@
#Mon Dec 04 11:24:34 CST 2017 #Tue Mar 27 21:17:43 CST 2018
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

View File

@@ -1,7 +1,8 @@
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
android { android {
compileSdkVersion 27 compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
externalNativeBuild { externalNativeBuild {
ndkBuild { ndkBuild {

View File

@@ -127,6 +127,7 @@ void daemon_init() {
rm_rf("/data/magisk"); rm_rf("/data/magisk");
unlink("/data/magisk.img"); unlink("/data/magisk.img");
unlink("/data/magisk_debug.log"); unlink("/data/magisk_debug.log");
xmkdir("/data/adb", 0700);
chmod("/data/adb", 0700); chmod("/data/adb", 0700);
LOGI("* Creating /sbin overlay"); LOGI("* Creating /sbin overlay");
@@ -178,11 +179,6 @@ void daemon_init() {
close(root); close(root);
// Backward compatibility
xsymlink(DATABIN, "/data/magisk");
xsymlink(MAINIMG, "/data/magisk.img");
xsymlink(MOUNTPOINT, "/magisk");
xmount(NULL, "/", NULL, MS_REMOUNT | MS_RDONLY, NULL); xmount(NULL, "/", NULL, MS_REMOUNT | MS_RDONLY, NULL);
LOGI("* Mounting mirrors"); LOGI("* Mounting mirrors");

View File

@@ -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));
@@ -162,7 +168,7 @@ int parse_img(const char *image, boot_img *boot) {
if (pos < boot->map_size) { if (pos < boot->map_size) {
boot->tail = head + pos; boot->tail = head + pos;
boot->tail_size = boot->map_size - pos; boot->tail_size = boot->map_size - (boot->tail - boot->map_addr);
} }
// Check tail info, currently only for LG Bump and Samsung SEANDROIDENFORCE // Check tail info, currently only for LG Bump and Samsung SEANDROIDENFORCE
@@ -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,13 +320,14 @@ 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
if (access(DTB_FILE, R_OK) == 0) {
lheader(&boot, kernel_size, += restore(DTB_FILE, fd));
}
file_align();
} }
// dtb
if (access(DTB_FILE, R_OK) == 0) {
lheader(&boot, kernel_size, += restore(DTB_FILE, fd));
}
file_align();
// ramdisk // ramdisk
ramdisk_off = lseek(fd, 0, SEEK_CUR); ramdisk_off = lseek(fd, 0, SEEK_CUR);
if (boot.flags & MTK_RAMDISK) { if (boot.flags & MTK_RAMDISK) {
@@ -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();
} }

View File

@@ -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

View File

@@ -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 })

View File

@@ -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;

View File

@@ -54,6 +54,9 @@ void launch_magiskhide(int client) {
write_int(client, LOGD_DISABLED); write_int(client, LOGD_DISABLED);
close(client); close(client);
} }
setprop(MAGISKHIDE_PROP, "0");
// Remove without actually removing persist props
deleteprop2(MAGISKHIDE_PROP, 0);
return; return;
} }

View File

@@ -4,7 +4,6 @@
#include <pthread.h> #include <pthread.h>
#define TERM_THREAD SIGUSR1 #define TERM_THREAD SIGUSR1
#define HIDE_DONE SIGUSR2
// Kill process // Kill process
void kill_proc(int pid); void kill_proc(int pid);

View File

@@ -20,7 +20,7 @@
#include "magiskhide.h" #include "magiskhide.h"
static char init_ns[32], zygote_ns[2][32], cache_block[256]; static char init_ns[32], zygote_ns[2][32], cache_block[256];
static int hide_queue = 0, zygote_num, has_cache = 1, pipefd[2] = { -1, -1 }; static int zygote_num, has_cache = 1, pipefd[2] = { -1, -1 };
// Workaround for the lack of pthread_cancel // Workaround for the lack of pthread_cancel
static void term_thread(int sig) { static void term_thread(int sig) {
@@ -38,17 +38,6 @@ static void term_thread(int sig) {
pthread_exit(NULL); pthread_exit(NULL);
} }
static void hide_done(int sig) {
--hide_queue;
if (hide_queue == 0) {
xmount(NULL, "/", NULL, MS_REMOUNT, NULL);
xsymlink(DATABIN, "/data/magisk");
xsymlink(MAINIMG, "/data/magisk.img");
xsymlink(MOUNTPOINT, "/magisk");
xmount(NULL, "/", NULL, MS_REMOUNT | MS_RDONLY, NULL);
}
}
static int read_namespace(const int pid, char* target, const size_t size) { static int read_namespace(const int pid, char* target, const size_t size) {
char path[32]; char path[32];
snprintf(path, sizeof(path), "/proc/%d/ns/mnt", pid); snprintf(path, sizeof(path), "/proc/%d/ns/mnt", pid);
@@ -140,9 +129,6 @@ exit:
kill(pid, SIGCONT); kill(pid, SIGCONT);
// Free up memory // Free up memory
vec_destroy(&mount_list); vec_destroy(&mount_list);
// Wait a while and link it back
sleep(10);
kill(ppid, HIDE_DONE);
_exit(0); _exit(0);
} }
@@ -151,7 +137,6 @@ void proc_monitor() {
sigset_t block_set; sigset_t block_set;
sigemptyset(&block_set); sigemptyset(&block_set);
sigaddset(&block_set, TERM_THREAD); sigaddset(&block_set, TERM_THREAD);
sigaddset(&block_set, HIDE_DONE);
pthread_sigmask(SIG_UNBLOCK, &block_set, NULL); pthread_sigmask(SIG_UNBLOCK, &block_set, NULL);
// Register the cancel signal // Register the cancel signal
@@ -159,8 +144,6 @@ void proc_monitor() {
memset(&act, 0, sizeof(act)); memset(&act, 0, sizeof(act));
act.sa_handler = term_thread; act.sa_handler = term_thread;
sigaction(TERM_THREAD, &act, NULL); sigaction(TERM_THREAD, &act, NULL);
act.sa_handler = hide_done;
sigaction(HIDE_DONE, &act, NULL);
cache_block[0] = '\0'; cache_block[0] = '\0';
@@ -241,14 +224,6 @@ void proc_monitor() {
LOGI("proc_monitor: %s (PID=%d ns=%s)\n", processName, pid, ns); LOGI("proc_monitor: %s (PID=%d ns=%s)\n", processName, pid, ns);
xmount(NULL, "/", NULL, MS_REMOUNT, NULL);
unlink("/magisk");
unlink("/data/magisk");
unlink("/data/magisk.img");
unlink(MAGISKRC);
xmount(NULL, "/", NULL, MS_REMOUNT | MS_RDONLY, NULL);
++hide_queue;
/* /*
* The setns system call do not support multithread processes * The setns system call do not support multithread processes
* We have to fork a new process, setns, then do the unmounts * We have to fork a new process, setns, then do the unmounts

View File

@@ -2,52 +2,6 @@
* *
* Copyright 2016 nkk71 <nkk71x@gmail.com> * Copyright 2016 nkk71 <nkk71x@gmail.com>
* Copyright 2016 topjohnwu <topjohnwu@gmail.com> * Copyright 2016 topjohnwu <topjohnwu@gmail.com>
*
* Info:
*
* all changes are in
*
* bionic/libc/bionic/system_properties.cpp
*
* Functions that need to be patched/added in system_properties.cpp
*
* int __system_properties_init2()
* on android 7, first tear down the everything then let it initialize again:
* if (initialized) {
* //list_foreach(contexts, [](context_node* l) { l->reset_access(); });
* //return 0;
* free_and_unmap_contexts();
* initialized = false;
* }
*
*
* static prop_area* map_prop_area(const char* filename, bool is_legacy)
* we dont want this read only so change: 'O_RDONLY' to 'O_RDWR'
*
* static prop_area* map_fd_ro(const int fd)
* we dont want this read only so change: 'PROT_READ' to 'PROT_READ | PROT_WRITE'
*
*
* Copy the code of prop_info *prop_area::find_property, and modify to delete props
* const prop_info *prop_area::find_property_and_del(prop_bt *const trie, const char *name)
* {
* ...
* ... Do not alloc a new prop_bt here, remove all code involve alloc_if_needed
* ...
*
* if (prop_offset != 0) {
* atomic_store_explicit(&current->prop, 0, memory_order_release); // Add this line to nullify the prop entry
* return to_prop_info(&current->prop);
* } else {
*
* ....
* }
*
*
* by patching just those functions directly, all other functions should be ok
* as is.
*
*
*/ */
#include <stdio.h> #include <stdio.h>

View File

@@ -153,7 +153,7 @@ class prop_area {
} }
const prop_info* find(const char* name); const prop_info* find(const char* name);
bool del(const char *name); // resetprop add bool del(const char *name); /* resetprop add */
bool add(const char* name, unsigned int namelen, const char* value, unsigned int valuelen); bool add(const char* name, unsigned int namelen, const char* value, unsigned int valuelen);
bool foreach (void (*propfn)(const prop_info* pi, void* cookie), void* cookie); bool foreach (void (*propfn)(const prop_info* pi, void* cookie), void* cookie);
@@ -184,7 +184,7 @@ class prop_area {
const prop_info* find_property(prop_bt* const trie, const char* name, uint32_t namelen, const prop_info* find_property(prop_bt* const trie, const char* name, uint32_t namelen,
const char* value, uint32_t valuelen, bool alloc_if_needed); const char* value, uint32_t valuelen, bool alloc_if_needed);
bool find_property_and_del(prop_bt *const trie, const char *name); // resetprop add bool find_property_and_del(prop_bt *const trie, const char *name); /* resetprop add */
bool foreach_property(prop_bt* const trie, void (*propfn)(const prop_info* pi, void* cookie), bool foreach_property(prop_bt* const trie, void (*propfn)(const prop_info* pi, void* cookie),
void* cookie); void* cookie);
@@ -283,7 +283,8 @@ static prop_area* map_prop_area_rw(const char* filename, const char* context,
return pa; return pa;
} }
static prop_area* map_fd_ro(const int fd) { // resetprop: map the memory as rw
static prop_area* map_fd_rw(const int fd) {
struct stat fd_stat; struct stat fd_stat;
if (fstat(fd, &fd_stat) < 0) { if (fstat(fd, &fd_stat) < 0) {
return nullptr; return nullptr;
@@ -298,7 +299,7 @@ static prop_area* map_fd_ro(const int fd) {
pa_size = fd_stat.st_size; pa_size = fd_stat.st_size;
pa_data_size = pa_size - sizeof(prop_area); pa_data_size = pa_size - sizeof(prop_area);
void* const map_result = mmap(nullptr, pa_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); // resetprop: add PROT_WRITE void* const map_result = mmap(nullptr, pa_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); /* resetprop: add PROT_WRITE */
if (map_result == MAP_FAILED) { if (map_result == MAP_FAILED) {
return nullptr; return nullptr;
} }
@@ -313,10 +314,10 @@ static prop_area* map_fd_ro(const int fd) {
} }
static prop_area* map_prop_area(const char* filename) { static prop_area* map_prop_area(const char* filename) {
int fd = open(filename, O_CLOEXEC | O_NOFOLLOW | O_RDWR); // resetprop: O_RDONLY -> O_RDWR int fd = open(filename, O_CLOEXEC | O_NOFOLLOW | O_RDWR); /* resetprop: O_RDONLY -> O_RDWR */
if (fd == -1) return nullptr; if (fd == -1) return nullptr;
prop_area* map_result = map_fd_ro(fd); prop_area* map_result = map_fd_rw(fd);
close(fd); close(fd);
return map_result; return map_result;
@@ -530,7 +531,7 @@ bool prop_area::find_property_and_del(prop_bt* const trie, const char* name) {
uint_least32_t prop_offset = atomic_load_explicit(&current->prop, memory_order_relaxed); uint_least32_t prop_offset = atomic_load_explicit(&current->prop, memory_order_relaxed);
if (prop_offset != 0) { if (prop_offset != 0) {
atomic_store_explicit(&current->prop, 0, memory_order_release); // resetprop: nullify the offset to delete the prop atomic_store_explicit(&current->prop, 0, memory_order_release);
return true; return true;
} else { } else {
return false; return false;
@@ -1116,16 +1117,16 @@ 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")) { // Don't check for failure here, so we always have a sane list of properties.
return false; // E.g. In case of recovery, the vendor partition will not have mounted and we
} // still need the system / platform properties to function.
initialize_properties_from_file("/vendor/etc/selinux/nonplat_property_contexts") ||
initialize_properties_from_file("/vendor/etc/selinux/vendor_property_contexts");
} else { } else {
if (!initialize_properties_from_file("/plat_property_contexts")) { if (!initialize_properties_from_file("/plat_property_contexts")) {
return false; return false;
} }
if (!initialize_properties_from_file("/nonplat_property_contexts")) { initialize_properties_from_file("/nonplat_property_contexts");
return false;
}
} }
return true; return true;

View File

@@ -17,7 +17,7 @@ static int e2fsck(const char *img) {
// Check and repair ext4 image // Check and repair ext4 image
char buffer[128]; char buffer[128];
int pid, fd = -1; int pid, fd = -1;
pid = exec_command(1, &fd, NULL, "e2fsck", "-yf", img, NULL); pid = exec_command(1, &fd, NULL, "/system/bin/e2fsck", "-yf", img, NULL);
if (pid < 0) if (pid < 0)
return 1; return 1;
while (fdgets(buffer, sizeof(buffer), fd)) while (fdgets(buffer, sizeof(buffer), fd))
@@ -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("/system/bin/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("/system/bin/mke2fs", "-b", "4096", "-t", "ext4", img, size_str, NULL);
}
return ret; return ret;
} }
@@ -71,7 +73,7 @@ int get_img_size(const char *img, int *used, int *total) {
return 1; return 1;
char buffer[PATH_MAX]; char buffer[PATH_MAX];
int pid, fd = -1, status = 1; int pid, fd = -1, status = 1;
pid = exec_command(1, &fd, NULL, "e2fsck", "-n", img, NULL); pid = exec_command(1, &fd, NULL, "/system/bin/e2fsck", "-n", img, NULL);
if (pid < 0) if (pid < 0)
return 1; return 1;
while (fdgets(buffer, sizeof(buffer), fd)) { while (fdgets(buffer, sizeof(buffer), fd)) {
@@ -103,7 +105,7 @@ int resize_img(const char *img, int size) {
char buffer[128]; char buffer[128];
int pid, fd = -1, used, total; int pid, fd = -1, used, total;
snprintf(buffer, sizeof(buffer), "%dM", size); snprintf(buffer, sizeof(buffer), "%dM", size);
pid = exec_command(1, &fd, NULL, "resize2fs", img, buffer, NULL); pid = exec_command(1, &fd, NULL, "/system/bin/resize2fs", img, buffer, NULL);
if (pid < 0) if (pid < 0)
return 1; return 1;
while (fdgets(buffer, sizeof(buffer), fd)) while (fdgets(buffer, sizeof(buffer), fd))

View File

@@ -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;
} }

View File

@@ -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,18 +124,32 @@ case $? in
cp -af ramdisk.cpio ramdisk.cpio.orig cp -af ramdisk.cpio ramdisk.cpio.orig
;; ;;
1 ) # Magisk patched 1 ) # Magisk patched
ui_print "- Magisk patched image detected" MAGISK_PATCHED=true
# Find SHA1 of stock boot image HIGHCOMP=false
[ -z $SHA1 ] && SHA1=`./magiskboot --cpio ramdisk.cpio sha1 2>/dev/null`
./magiskboot --cpio ramdisk.cpio restore
cp -af ramdisk.cpio ramdisk.cpio.orig
;; ;;
2 ) # Other patched 2 ) # High compression mode
MAGISK_PATCHED=true
HIGHCOMP=true
;;
3 ) # Other patched
ui_print "! Boot image patched by other programs" ui_print "! Boot image patched by other programs"
abort "! Please restore stock boot image" abort "! Please restore stock boot image"
;; ;;
esac esac
if $MAGISK_PATCHED; then
ui_print "- Magisk patched image detected"
# Find SHA1 of stock boot image
[ -z $SHA1 ] && SHA1=`./magiskboot --cpio ramdisk.cpio sha1 2>/dev/null`
./magiskboot --cpio ramdisk.cpio restore
cp -af ramdisk.cpio ramdisk.cpio.orig
fi
if $HIGHCOMP; then
ui_print "! Insufficient boot partition size detected"
ui_print "- Enable high compression mode"
fi
########################################################################################## ##########################################################################################
# Ramdisk patches # Ramdisk patches
########################################################################################## ##########################################################################################

View File

@@ -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"
;; ;;

View File

@@ -1,13 +1,13 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
android { android {
compileSdkVersion 27 compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion "27.0.3" buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig { defaultConfig {
applicationId "com.topjohnwu.snet" applicationId "com.topjohnwu.snet"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 27 targetSdkVersion rootProject.ext.compileSdkVersion
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
} }
@@ -20,10 +20,6 @@ android {
} }
} }
repositories {
google()
}
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.gms:play-services-safetynet:7.0.0' /* The oldest version */ implementation 'com.google.android.gms:play-services-safetynet:7.0.0' /* The oldest version */

View File

@@ -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,