@@ -672,6 +672,31 @@ def patch_avd_file():
672672
673673 header (f"Output: { output } " )
674674
675+ def patch_device_file ():
676+ input = Path (args .image )
677+ output = Path (args .output )
678+
679+ header (f"* Patching { input .name } " )
680+
681+ push_files (Path ("scripts" , "patch_boot.sh" ))
682+
683+ proc = execv ([adb_path , "push" , input , "/data/local/tmp" ])
684+ if proc .returncode != 0 :
685+ error ("adb push failed!" )
686+
687+ src_file = f"/data/local/tmp/{ input .name } "
688+ out_file = "/data/local/tmp/new-boot.img"
689+
690+ proc = execv ([adb_path , "shell" , "sh" , "/data/local/tmp/patch_boot.sh" , src_file ])
691+ if proc .returncode != 0 :
692+ error ("patch_boot.sh failed!" )
693+
694+ proc = execv ([adb_path , "pull" , out_file , output ])
695+ if proc .returncode != 0 :
696+ error ("adb pull failed!" )
697+
698+ header (f"Output: { output } " )
699+ execv ([adb_path , "shell" , "rm" , "/data/local/tmp/new-boot.img" ])
675700
676701##########################
677702# Config, paths, argparse
@@ -832,6 +857,16 @@ def parse_args():
832857 "-b" , "--build" , action = "store_true" , help = "build before patching"
833858 )
834859
860+ device_patch_parser = subparsers .add_parser (
861+ "device_patch" , help = "patch device boot.img or init_boot.img"
862+ )
863+ device_patch_parser .add_argument ("image" , help = "path to boot.img or init_boot.img" )
864+ device_patch_parser .add_argument ("output" , help = "output file name, default: new-boot.img" )
865+ device_patch_parser .add_argument ("--apk" , help = "a Magisk APK to use" )
866+ device_patch_parser .add_argument (
867+ "-b" , "--build" , action = "store_true" , help = "build before patching"
868+ )
869+
835870 cargo_parser = subparsers .add_parser (
836871 "cargo" , help = "call 'cargo' commands against the project"
837872 )
@@ -859,6 +894,7 @@ def parse_args():
859894 test_parser .set_defaults (func = build_test )
860895 emu_parser .set_defaults (func = setup_avd )
861896 avd_patch_parser .set_defaults (func = patch_avd_file )
897+ device_patch_parser .set_defaults (func = patch_device_file )
862898 clean_parser .set_defaults (func = cleanup )
863899 ndk_parser .set_defaults (func = setup_ndk )
864900
0 commit comments