mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-25 02:55:33 +00:00
Stop embedding stub.apk in magiskinit
This commit is contained in:
parent
a4a734458b
commit
ad0e6511e1
@ -131,7 +131,7 @@ abstract class MagiskInstallImpl protected constructor(
|
||||
}
|
||||
|
||||
// Extract scripts
|
||||
for (script in listOf("util_functions.sh", "boot_patch.sh", "addon.d.sh")) {
|
||||
for (script in listOf("util_functions.sh", "boot_patch.sh", "addon.d.sh", "stub.apk")) {
|
||||
val dest = File(installDir, script)
|
||||
context.assets.open(script).writeTo(dest)
|
||||
}
|
||||
|
15
build.py
15
build.py
@ -309,13 +309,7 @@ def binary_dump(src, var_name, compressor=xz):
|
||||
|
||||
|
||||
def dump_bin_header(args):
|
||||
stub = op.join(config['outdir'], f'stub-{"release" if args.release else "debug"}.apk')
|
||||
if not op.exists(stub):
|
||||
error('Build stub APK before building "magiskinit"')
|
||||
mkdir_p(native_gen_path)
|
||||
with open(stub, 'rb') as src:
|
||||
text = binary_dump(src, 'manager_xz')
|
||||
write_if_diff(op.join(native_gen_path, 'binaries.h'), text)
|
||||
for arch in archs:
|
||||
preload = op.join('native', 'out', arch, 'libinit-ld.so')
|
||||
with open(preload, 'rb') as src:
|
||||
@ -432,11 +426,6 @@ def build_app(args):
|
||||
build_apk(args, 'app')
|
||||
|
||||
|
||||
def build_stub(args):
|
||||
header('* Building the stub app')
|
||||
build_apk(args, 'stub')
|
||||
|
||||
|
||||
def cleanup(args):
|
||||
support_targets = {'native', 'java'}
|
||||
if args.target:
|
||||
@ -554,7 +543,6 @@ def patch_avd_ramdisk(args):
|
||||
|
||||
|
||||
def build_all(args):
|
||||
build_stub(args)
|
||||
build_binary(args)
|
||||
build_app(args)
|
||||
|
||||
@ -582,9 +570,6 @@ binary_parser.set_defaults(func=build_binary)
|
||||
app_parser = subparsers.add_parser('app', help='build the Magisk app')
|
||||
app_parser.set_defaults(func=build_app)
|
||||
|
||||
stub_parser = subparsers.add_parser('stub', help='build the stub app')
|
||||
stub_parser.set_defaults(func=build_stub)
|
||||
|
||||
avd_parser = subparsers.add_parser(
|
||||
'emulator', help='setup AVD for development')
|
||||
avd_parser.add_argument('-s', '--skip', action='store_true',
|
||||
|
@ -15,8 +15,7 @@ import org.gradle.api.tasks.Copy
|
||||
import org.gradle.api.tasks.Delete
|
||||
import org.gradle.api.tasks.StopExecutionException
|
||||
import org.gradle.api.tasks.Sync
|
||||
import org.gradle.kotlin.dsl.filter
|
||||
import org.gradle.kotlin.dsl.named
|
||||
import org.gradle.kotlin.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
@ -40,7 +39,7 @@ private fun BaseExtension.kotlinOptions(configure: Action<KotlinJvmOptions>) =
|
||||
}
|
||||
|
||||
private val Project.android: BaseAppModuleExtension
|
||||
get() = extensions.getByName("android") as BaseAppModuleExtension
|
||||
get() = extensions["android"] as BaseAppModuleExtension
|
||||
|
||||
fun Project.setupCommon() {
|
||||
androidBase {
|
||||
@ -112,14 +111,14 @@ private fun Project.setupAppCommon() {
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
signingConfigs.getByName("config").also {
|
||||
getByName("debug") {
|
||||
signingConfigs["config"].also {
|
||||
debug {
|
||||
signingConfig = if (it.storeFile?.exists() == true) it
|
||||
else signingConfigs.getByName("debug")
|
||||
else signingConfigs["debug"]
|
||||
}
|
||||
getByName("release") {
|
||||
release {
|
||||
signingConfig = if (it.storeFile?.exists() == true) it
|
||||
else signingConfigs.getByName("debug")
|
||||
else signingConfigs["debug"]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -147,7 +146,7 @@ private fun Project.setupAppCommon() {
|
||||
fun Project.setupApp() {
|
||||
setupAppCommon()
|
||||
|
||||
val syncLibs = tasks.register("syncLibs", Sync::class.java) {
|
||||
val syncLibs by tasks.registering(Sync::class) {
|
||||
into("src/main/jniLibs")
|
||||
into("armeabi-v7a") {
|
||||
from(rootProject.file("native/out/armeabi-v7a")) {
|
||||
@ -180,35 +179,8 @@ fun Project.setupApp() {
|
||||
}
|
||||
}
|
||||
|
||||
val syncAssets = tasks.register("syncAssets", Sync::class.java) {
|
||||
val syncResources by tasks.registering(Sync::class) {
|
||||
dependsOn(syncLibs)
|
||||
inputs.property("version", Config.version)
|
||||
inputs.property("versionCode", Config.versionCode)
|
||||
into("src/main/assets")
|
||||
from(rootProject.file("scripts")) {
|
||||
include("util_functions.sh", "boot_patch.sh", "addon.d.sh")
|
||||
include("uninstaller.sh", "module_installer.sh")
|
||||
}
|
||||
from(rootProject.file("tools/bootctl"))
|
||||
into("chromeos") {
|
||||
from(rootProject.file("tools/futility"))
|
||||
from(rootProject.file("tools/keys")) {
|
||||
include("kernel_data_key.vbprivk", "kernel.keyblock")
|
||||
}
|
||||
}
|
||||
filesMatching("**/util_functions.sh") {
|
||||
filter {
|
||||
it.replace(
|
||||
"#MAGISK_VERSION_STUB",
|
||||
"MAGISK_VER='${Config.version}'\nMAGISK_VER_CODE=${Config.versionCode}"
|
||||
)
|
||||
}
|
||||
filter<FixCrLfFilter>("eol" to FixCrLfFilter.CrLf.newInstance("lf"))
|
||||
}
|
||||
}
|
||||
|
||||
val syncResources = tasks.register("syncResources", Sync::class.java) {
|
||||
dependsOn(syncAssets)
|
||||
into("src/main/resources/META-INF/com/google/android")
|
||||
from(rootProject.file("scripts/update_binary.sh")) {
|
||||
rename { "update-binary" }
|
||||
@ -222,20 +194,42 @@ fun Project.setupApp() {
|
||||
val variantCapped = name.capitalize(Locale.ROOT)
|
||||
val variantLowered = name.toLowerCase(Locale.ROOT)
|
||||
|
||||
val copyStub = tasks.register("copy${variantCapped}StubApk", Copy::class.java) {
|
||||
val syncAssets = tasks.register("sync${variantCapped}Assets", Sync::class) {
|
||||
dependsOn(syncResources)
|
||||
inputs.property("version", Config.version)
|
||||
inputs.property("versionCode", Config.versionCode)
|
||||
into("src/main/assets")
|
||||
from(rootProject.file("out/stub-${variantLowered}.apk")) {
|
||||
from(rootProject.file("scripts")) {
|
||||
include("util_functions.sh", "boot_patch.sh", "addon.d.sh")
|
||||
include("uninstaller.sh", "module_installer.sh")
|
||||
}
|
||||
from(rootProject.file("tools/bootctl"))
|
||||
into("chromeos") {
|
||||
from(rootProject.file("tools/futility"))
|
||||
from(rootProject.file("tools/keys")) {
|
||||
include("kernel_data_key.vbprivk", "kernel.keyblock")
|
||||
}
|
||||
}
|
||||
val task = tasks.getByPath(":stub:package$variantCapped")
|
||||
dependsOn(task)
|
||||
val apk = task.outputs.files.asFileTree.filter {
|
||||
it.name.endsWith(".apk")
|
||||
}
|
||||
from(apk) {
|
||||
rename { "stub.apk" }
|
||||
}
|
||||
onlyIf {
|
||||
if (inputs.sourceFiles.files.size != 1)
|
||||
throw StopExecutionException("Please build stub first! (./build.py stub)")
|
||||
true
|
||||
filesMatching("**/util_functions.sh") {
|
||||
filter {
|
||||
it.replace(
|
||||
"#MAGISK_VERSION_STUB",
|
||||
"MAGISK_VER='${Config.version}'\nMAGISK_VER_CODE=${Config.versionCode}"
|
||||
)
|
||||
}
|
||||
filter<FixCrLfFilter>("eol" to FixCrLfFilter.CrLf.newInstance("lf"))
|
||||
}
|
||||
}
|
||||
|
||||
preBuildProvider.get().dependsOn(copyStub)
|
||||
preBuildProvider.get().dependsOn(syncAssets)
|
||||
|
||||
val keysDir = rootProject.file("tools/keys")
|
||||
val outSrcDir = File(buildDir, "generated/source/keydata/$name")
|
||||
|
@ -1,5 +1,3 @@
|
||||
#include <binaries.h>
|
||||
|
||||
#if defined(__arm__)
|
||||
#include <armeabi-v7a_binaries.h>
|
||||
#elif defined(__aarch64__)
|
||||
|
@ -61,10 +61,6 @@ void restore_ramdisk_init() {
|
||||
}
|
||||
}
|
||||
|
||||
int dump_manager(const char *path, mode_t mode) {
|
||||
return dump_bin(manager_xz, sizeof(manager_xz), path, mode);
|
||||
}
|
||||
|
||||
int dump_preload(const char *path, mode_t mode) {
|
||||
return dump_bin(init_ld_xz, sizeof(init_ld_xz), path, mode);
|
||||
}
|
||||
@ -87,12 +83,6 @@ int main(int argc, char *argv[]) {
|
||||
if (name == "magisk"sv)
|
||||
return magisk_proxy_main(argc, argv);
|
||||
|
||||
if (argc > 1 && argv[1] == "-x"sv) {
|
||||
if (argc > 2 && argv[2] == "manager"sv)
|
||||
return dump_manager(argv[3], 0644);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (getpid() != 1)
|
||||
return 1;
|
||||
|
||||
|
@ -36,7 +36,6 @@ bool check_two_stage();
|
||||
void setup_klog();
|
||||
const char *backup_init();
|
||||
void restore_ramdisk_init();
|
||||
int dump_manager(const char *path, mode_t mode);
|
||||
int dump_preload(const char *path, mode_t mode);
|
||||
|
||||
/***************
|
||||
|
@ -151,6 +151,7 @@ static void patch_socket_name(const char *path) {
|
||||
static void extract_files(bool sbin) {
|
||||
const char *m32 = sbin ? "/sbin/magisk32.xz" : "magisk32.xz";
|
||||
const char *m64 = sbin ? "/sbin/magisk64.xz" : "magisk64.xz";
|
||||
const char *stub_xz = sbin ? "/sbin/stub.xz" : "stub.xz";
|
||||
|
||||
if (access(m32, F_OK) == 0) {
|
||||
auto magisk = mmap_data(m32);
|
||||
@ -172,7 +173,13 @@ static void extract_files(bool sbin) {
|
||||
xsymlink("./magisk32", "magisk");
|
||||
}
|
||||
|
||||
dump_manager("stub.apk", 0);
|
||||
{
|
||||
auto stub = mmap_data(stub_xz);
|
||||
unlink(stub_xz);
|
||||
int fd = xopen("stub.apk", O_WRONLY | O_CREAT, 0);
|
||||
unxz(fd, stub.buf, stub.sz);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
#define ROOTMIR MIRRDIR "/system_root"
|
||||
|
@ -120,6 +120,7 @@ fi
|
||||
# Magisk stuff
|
||||
mkdir -p $MAGISKBIN 2>/dev/null
|
||||
unzip -oj magisk.apk 'assets/*.sh' -d $MAGISKBIN
|
||||
unzip -oj magisk.apk 'assets/stub.apk' -d $MAGISKTMP
|
||||
mkdir $NVBASE/modules 2>/dev/null
|
||||
mkdir $POSTFSDATAD 2>/dev/null
|
||||
mkdir $SERVICED 2>/dev/null
|
||||
@ -143,8 +144,6 @@ ln -s ./magisk $MAGISKTMP/resetprop
|
||||
ln -s ./magisk $MAGISKTMP/magiskhide
|
||||
ln -s ./magiskpolicy $MAGISKTMP/supolicy
|
||||
|
||||
./magiskinit -x manager $MAGISKTMP/stub.apk
|
||||
|
||||
mkdir -p $MAGISKTMP/.magisk/mirror
|
||||
mkdir $MAGISKTMP/.magisk/block
|
||||
touch $MAGISKTMP/.magisk/config
|
||||
|
@ -43,7 +43,7 @@ if [ -z "$FIRST_STAGE" ]; then
|
||||
fi
|
||||
|
||||
# Extract files from APK
|
||||
unzip -oj magisk.apk 'assets/util_functions.sh'
|
||||
unzip -oj magisk.apk 'assets/util_functions.sh' 'assets/stub.apk'
|
||||
. ./util_functions.sh
|
||||
|
||||
api_level_arch_detect
|
||||
@ -65,6 +65,7 @@ touch config
|
||||
|
||||
./magiskboot compress=xz magisk32 magisk32.xz
|
||||
./magiskboot compress=xz magisk64 magisk64.xz
|
||||
./magiskboot compress=xz stub.apk stub.xz
|
||||
|
||||
export KEEPVERITY=false
|
||||
export KEEPFORCEENCRYPT=true
|
||||
@ -75,10 +76,11 @@ export KEEPFORCEENCRYPT=true
|
||||
"mkdir 0750 overlay.d/sbin" \
|
||||
"add 0644 overlay.d/sbin/magisk32.xz magisk32.xz" \
|
||||
"add 0644 overlay.d/sbin/magisk64.xz magisk64.xz" \
|
||||
"add 0644 overlay.d/sbin/stub.xz stub.xz" \
|
||||
"patch" \
|
||||
"backup ramdisk.cpio.orig" \
|
||||
"mkdir 000 .backup" \
|
||||
"add 000 .backup/.magisk config"
|
||||
|
||||
rm -f ramdisk.cpio.orig config magisk*.xz
|
||||
rm -f ramdisk.cpio.orig config magisk*.xz stub.xz
|
||||
./magiskboot compress=gzip ramdisk.cpio ramdisk.cpio.gz
|
||||
|
@ -164,6 +164,7 @@ if [ -f magisk64 ]; then
|
||||
./magiskboot compress=xz magisk64 magisk64.xz
|
||||
unset SKIP64
|
||||
fi
|
||||
./magiskboot compress=xz stub.apk stub.xz
|
||||
|
||||
./magiskboot cpio ramdisk.cpio \
|
||||
"add 0750 $INIT magiskinit" \
|
||||
@ -171,12 +172,13 @@ fi
|
||||
"mkdir 0750 overlay.d/sbin" \
|
||||
"$SKIP32 add 0644 overlay.d/sbin/magisk32.xz magisk32.xz" \
|
||||
"$SKIP64 add 0644 overlay.d/sbin/magisk64.xz magisk64.xz" \
|
||||
"add 0644 overlay.d/sbin/stub.xz stub.xz" \
|
||||
"patch" \
|
||||
"backup ramdisk.cpio.orig" \
|
||||
"mkdir 000 .backup" \
|
||||
"add 000 .backup/.magisk config"
|
||||
|
||||
rm -f ramdisk.cpio.orig config magisk*.xz
|
||||
rm -f ramdisk.cpio.orig config magisk*.xz stub.xz
|
||||
|
||||
#################
|
||||
# Binary Patches
|
||||
|
Loading…
Reference in New Issue
Block a user