@@ -633,6 +633,31 @@ def patch_avd_file():
633633
634634 header (f"Output: { output } " )
635635
636+ def patch_device_file ():
637+ input = Path (args .image )
638+ output = Path (args .output )
639+
640+ header (f"* Patching { input .name } " )
641+
642+ push_files (Path ("scripts" , "patch_boot.sh" ))
643+
644+ proc = execv ([adb_path , "push" , input , "/data/local/tmp" ])
645+ if proc .returncode != 0 :
646+ error ("adb push failed!" )
647+
648+ src_file = f"/data/local/tmp/{ input .name } "
649+ out_file = "/data/local/tmp/new-boot.img"
650+
651+ proc = execv ([adb_path , "shell" , "sh" , "/data/local/tmp/patch_boot.sh" , src_file ])
652+ if proc .returncode != 0 :
653+ error ("patch_boot.sh failed!" )
654+
655+ proc = execv ([adb_path , "pull" , out_file , output ])
656+ if proc .returncode != 0 :
657+ error ("adb pull failed!" )
658+
659+ header (f"Output: { output } " )
660+ execv ([adb_path , "shell" , "rm" , "/data/local/tmp/new-boot.img" ])
636661
637662##########################
638663# Config, paths, argparse
@@ -789,6 +814,16 @@ def parse_args():
789814 "-b" , "--build" , action = "store_true" , help = "build before patching"
790815 )
791816
817+ device_patch_parser = subparsers .add_parser (
818+ "device_patch" , help = "patch device boot.img or init_boot.img"
819+ )
820+ device_patch_parser .add_argument ("image" , help = "path to boot.img or init_boot.img" )
821+ device_patch_parser .add_argument ("output" , help = "output file name, default: new-boot.img" )
822+ device_patch_parser .add_argument ("--apk" , help = "a Magisk APK to use" )
823+ device_patch_parser .add_argument (
824+ "-b" , "--build" , action = "store_true" , help = "build before patching"
825+ )
826+
792827 cargo_parser = subparsers .add_parser (
793828 "cargo" , help = "call 'cargo' commands against the project"
794829 )
@@ -812,6 +847,7 @@ def parse_args():
812847 test_parser .set_defaults (func = build_test )
813848 emu_parser .set_defaults (func = setup_avd )
814849 avd_patch_parser .set_defaults (func = patch_avd_file )
850+ device_patch_parser .set_defaults (func = patch_device_file )
815851 clean_parser .set_defaults (func = cleanup )
816852 ndk_parser .set_defaults (func = setup_ndk )
817853
0 commit comments