From a97adcf862caa246b48a1e963dfd784b53c54c41 Mon Sep 17 00:00:00 2001 From: Atemu Date: Fri, 20 Dec 2024 14:14:00 +0100 Subject: [PATCH 1/4] attempt patching boot.img --- modules/release.nix | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/release.nix b/modules/release.nix index 782677cb..1622c022 100644 --- a/modules/release.nix +++ b/modules/release.nix @@ -55,10 +55,32 @@ let ) ''; otaScript = { targetFiles, prevTargetFiles ? null, out }: '' + targetFiles=targetFiles.zip + cp ${targetFiles} $targetFiles + + unzip ${/Users/atemu/Downloads/Magisk-v28.1.apk} + chmod +x assets/boot_patch.sh + # This is not cross-friendly + chmod +x lib/x86_64/libmagiskboot.so + ln -s ../lib/x86_64/libmagiskboot.so assets/magiskboot + ln -s ../lib/arm64-v8a/libmagisk64.so assets/magisk64 + ln -s ../lib/armeabi-v7a/libmagisk32.so assets/magisk32 + ln -s ../lib/arm64-v8a/libmagiskinit.so assets/magiskinit + + ln -s ../lib/x86_64/libmagisk.so assets/magisk + chmod +x lib/x86_64/libmagisk.so + + unzip $targetFiles IMAGES/boot.img -d assets/ + + export BOOTMODE=true + PATH=${pkgs.writeShellScriptBin "getprop" "echo \"$@\""}/bin/:$PATH sh assets/boot_patch.sh IMAGES/boot.img + + zip $targetFiles IMAGES/boot.img + ota_from_target_files \ ${toString config.otaArgs} \ ${lib.optionalString (prevTargetFiles != null) "-i ${prevTargetFiles}"} \ - ${targetFiles} ${out} + $targetFiles ${out} ''; imgScript = { targetFiles, out }: ''img_from_target_files ${targetFiles} ${out}''; factoryImgScript = { targetFiles, img, out }: '' From 54fe6af524d1eed8d95ce4c23780d54eb06c4faf Mon Sep 17 00:00:00 2001 From: Atemu Date: Mon, 23 Dec 2024 16:44:32 +0100 Subject: [PATCH 2/4] better method --- modules/release.nix | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/modules/release.nix b/modules/release.nix index 1622c022..e0b87dfe 100644 --- a/modules/release.nix +++ b/modules/release.nix @@ -58,24 +58,30 @@ let targetFiles=targetFiles.zip cp ${targetFiles} $targetFiles - unzip ${/Users/atemu/Downloads/Magisk-v28.1.apk} - chmod +x assets/boot_patch.sh - # This is not cross-friendly - chmod +x lib/x86_64/libmagiskboot.so - ln -s ../lib/x86_64/libmagiskboot.so assets/magiskboot - ln -s ../lib/arm64-v8a/libmagisk64.so assets/magisk64 - ln -s ../lib/armeabi-v7a/libmagisk32.so assets/magisk32 - ln -s ../lib/arm64-v8a/libmagiskinit.so assets/magiskinit - - ln -s ../lib/x86_64/libmagisk.so assets/magisk - chmod +x lib/x86_64/libmagisk.so - - unzip $targetFiles IMAGES/boot.img -d assets/ - - export BOOTMODE=true - PATH=${pkgs.writeShellScriptBin "getprop" "echo \"$@\""}/bin/:$PATH sh assets/boot_patch.sh IMAGES/boot.img - - zip $targetFiles IMAGES/boot.img + ( + mkdir magisk/ + pushd magisk/ + + # TODO + unzip ${/var/tmp/magisk-test/app-release.apk} + + # TODO is this correct? + pushd lib/x86_64/ + for file in lib*.so ; do + dest="../../${file:3:-3}" + ln -srfn "$file" "$dest" && chmod +x "$file" + done + popd + ln -sr assets/*.sh . + ln -sr assets/stub.apk . + + unzip $targetFiles IMAGES/boot.img -d assets/ + + export BOOTMODE=true + PATH=${pkgs.writeShellScriptBin "getprop" "echo \"$@\""}/bin/:$PATH sh assets/boot_patch.sh IMAGES/boot.img + + zip $targetFiles IMAGES/boot.img + ) ota_from_target_files \ ${toString config.otaArgs} \ From 9f21c23d9f5d67d7a6b901739406c1486e233666 Mon Sep 17 00:00:00 2001 From: Atemu Date: Mon, 23 Dec 2024 18:01:53 +0100 Subject: [PATCH 3/4] working patching --- modules/release.nix | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/release.nix b/modules/release.nix index e0b87dfe..bdc610a2 100644 --- a/modules/release.nix +++ b/modules/release.nix @@ -55,8 +55,9 @@ let ) ''; otaScript = { targetFiles, prevTargetFiles ? null, out }: '' - targetFiles=targetFiles.zip + targetFiles="$(pwd)/targetFiles.zip" cp ${targetFiles} $targetFiles + chmod +w $targetFiles ( mkdir magisk/ @@ -68,17 +69,17 @@ let # TODO is this correct? pushd lib/x86_64/ for file in lib*.so ; do - dest="../../${file:3:-3}" + dest="../../''${file:3:-3}" ln -srfn "$file" "$dest" && chmod +x "$file" done popd ln -sr assets/*.sh . ln -sr assets/stub.apk . - unzip $targetFiles IMAGES/boot.img -d assets/ + unzip $targetFiles IMAGES/boot.img export BOOTMODE=true - PATH=${pkgs.writeShellScriptBin "getprop" "echo \"$@\""}/bin/:$PATH sh assets/boot_patch.sh IMAGES/boot.img + PATH="$(pwd):${pkgs.writeShellScriptBin "getprop" "echo \"$@\""}/bin/:$PATH" bash boot_patch.sh IMAGES/boot.img zip $targetFiles IMAGES/boot.img ) From f26664aeac2552b5e2bfd76b35ebb56aacd4b79b Mon Sep 17 00:00:00 2001 From: Atemu Date: Mon, 23 Dec 2024 18:47:58 +0100 Subject: [PATCH 4/4] working in img! --- modules/release.nix | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/modules/release.nix b/modules/release.nix index bdc610a2..0ba28f26 100644 --- a/modules/release.nix +++ b/modules/release.nix @@ -55,6 +55,12 @@ let ) ''; otaScript = { targetFiles, prevTargetFiles ? null, out }: '' + ota_from_target_files \ + ${toString config.otaArgs} \ + ${lib.optionalString (prevTargetFiles != null) "-i ${prevTargetFiles}"} \ + ${targetFiles} ${out} + ''; + imgScript = { targetFiles, out }: '' targetFiles="$(pwd)/targetFiles.zip" cp ${targetFiles} $targetFiles chmod +w $targetFiles @@ -66,30 +72,28 @@ let # TODO unzip ${/var/tmp/magisk-test/app-release.apk} - # TODO is this correct? - pushd lib/x86_64/ - for file in lib*.so ; do - dest="../../''${file:3:-3}" - ln -srfn "$file" "$dest" && chmod +x "$file" - done - popd ln -sr assets/*.sh . ln -sr assets/stub.apk . + # Take everything from host arch and magiskboot from build arch + # TODO actually take the arches from the buildPlatform and the device platform + for file in lib/arm64-v8a/lib*.so lib/x86_64/libmagiskboot.so ; do + name="$(basename "$file")" + dest="''${name:3:-3}" + ln -srfn "$file" "$dest" && chmod +x "$file" + done + unzip $targetFiles IMAGES/boot.img export BOOTMODE=true PATH="$(pwd):${pkgs.writeShellScriptBin "getprop" "echo \"$@\""}/bin/:$PATH" bash boot_patch.sh IMAGES/boot.img + mv new-boot.img IMAGES/boot.img zip $targetFiles IMAGES/boot.img ) - ota_from_target_files \ - ${toString config.otaArgs} \ - ${lib.optionalString (prevTargetFiles != null) "-i ${prevTargetFiles}"} \ - $targetFiles ${out} + img_from_target_files $targetFiles ${out} ''; - imgScript = { targetFiles, out }: ''img_from_target_files ${targetFiles} ${out}''; factoryImgScript = { targetFiles, img, out }: '' ln -s ${targetFiles} ${config.device}-target_files-${config.buildNumber}.zip || true ln -s ${img} ${config.device}-img-${config.buildNumber}.zip || true