@@ -625,6 +625,31 @@ def patch_avd_file():
625625
626626 header (f"Output: { output } " )
627627
628+ def patch_device_file ():
629+ input = Path (args .image )
630+ output = Path (args .output )
631+
632+ header (f"* Patching { input .name } " )
633+
634+ push_files (Path ("scripts" , "patch_boot.sh" ))
635+
636+ proc = execv ([adb_path , "push" , input , "/data/local/tmp" ])
637+ if proc .returncode != 0 :
638+ error ("adb push failed!" )
639+
640+ src_file = f"/data/local/tmp/{ input .name } "
641+ out_file = "/data/local/tmp/new-boot.img"
642+
643+ proc = execv ([adb_path , "shell" , "sh" , "/data/local/tmp/patch_boot.sh" , src_file ])
644+ if proc .returncode != 0 :
645+ error ("patch_boot.sh failed!" )
646+
647+ proc = execv ([adb_path , "pull" , out_file , output ])
648+ if proc .returncode != 0 :
649+ error ("adb pull failed!" )
650+
651+ header (f"Output: { output } " )
652+ execv ([adb_path , "shell" , "rm" , "/data/local/tmp/new-boot.img" ])
628653
629654###################
630655# Config, argparse
@@ -763,6 +788,16 @@ def parse_args():
763788 "-b" , "--build" , action = "store_true" , help = "build before patching"
764789 )
765790
791+ device_patch_parser = subparsers .add_parser (
792+ "device_patch" , help = "patch device boot.img or init_boot.img"
793+ )
794+ device_patch_parser .add_argument ("image" , help = "path to boot.img or init_boot.img" )
795+ device_patch_parser .add_argument ("output" , help = "output file name, default: new-boot.img" )
796+ device_patch_parser .add_argument ("--apk" , help = "a Magisk APK to use" )
797+ device_patch_parser .add_argument (
798+ "-b" , "--build" , action = "store_true" , help = "build before patching"
799+ )
800+
766801 cargo_parser = subparsers .add_parser (
767802 "cargo" , help = "call 'cargo' commands against the project"
768803 )
@@ -800,6 +835,7 @@ def parse_args():
800835 test_parser .set_defaults (func = build_test )
801836 emu_parser .set_defaults (func = setup_avd )
802837 avd_patch_parser .set_defaults (func = patch_avd_file )
838+ device_patch_parser .set_defaults (func = patch_device_file )
803839 clean_parser .set_defaults (func = cleanup )
804840 ndk_parser .set_defaults (func = setup_ndk )
805841
0 commit comments