'magiskboot hexpatch' will exit with status 1 when nothing patched.

This commit is contained in:
Ian Macdonald 2019-06-08 14:29:30 +02:00 committed by John Wu
parent 8ebd9c8927
commit 8513946e09
3 changed files with 7 additions and 3 deletions

View File

@ -16,8 +16,9 @@ static void hex2byte(uint8_t *hex, uint8_t *str) {
} }
} }
void hexpatch(const char *image, const char *from, const char *to) { int hexpatch(const char *image, const char *from, const char *to) {
int patternsize = strlen(from) / 2, patchsize = strlen(to) / 2; int patternsize = strlen(from) / 2, patchsize = strlen(to) / 2;
int patched = 1;
size_t filesize; size_t filesize;
uint8_t *file, *pattern, *patch; uint8_t *file, *pattern, *patch;
mmap_rw(image, file, filesize); mmap_rw(image, file, filesize);
@ -31,9 +32,12 @@ void hexpatch(const char *image, const char *from, const char *to) {
memset(file + i, 0, patternsize); memset(file + i, 0, patternsize);
memcpy(file + i, patch, patchsize); memcpy(file + i, patch, patchsize);
i += patternsize - 1; i += patternsize - 1;
patched = 0;
} }
} }
munmap(file, filesize); munmap(file, filesize);
free(pattern); free(pattern);
free(patch); free(patch);
return patched;
} }

View File

@ -15,7 +15,7 @@
// Main entries // Main entries
int unpack(const char *image, bool hdr = false); int unpack(const char *image, bool hdr = false);
void repack(const char* orig_image, const char* out_image); void repack(const char* orig_image, const char* out_image);
void hexpatch(const char *image, const char *from, const char *to); int hexpatch(const char *image, const char *from, const char *to);
int cpio_commands(int argc, char *argv[]); int cpio_commands(int argc, char *argv[]);
int dtb_commands(const char *cmd, int argc, char *argv[]); int dtb_commands(const char *cmd, int argc, char *argv[]);

View File

@ -151,7 +151,7 @@ int main(int argc, char *argv[]) {
} else if (argc > 2 && strncmp(argv[1], "compress", 8) == 0) { } else if (argc > 2 && strncmp(argv[1], "compress", 8) == 0) {
compress(argv[1][8] == '=' ? &argv[1][9] : "gzip", argv[2], argv[3]); compress(argv[1][8] == '=' ? &argv[1][9] : "gzip", argv[2], argv[3]);
} else if (argc > 4 && strcmp(argv[1], "hexpatch") == 0) { } else if (argc > 4 && strcmp(argv[1], "hexpatch") == 0) {
hexpatch(argv[2], argv[3], argv[4]); return hexpatch(argv[2], argv[3], argv[4]);
} else if (argc > 2 && strcmp(argv[1], "cpio") == 0) { } else if (argc > 2 && strcmp(argv[1], "cpio") == 0) {
if (cpio_commands(argc - 2, argv + 2)) usage(argv[0]); if (cpio_commands(argc - 2, argv + 2)) usage(argv[0]);
} else if (argc > 2 && strncmp(argv[1], "dtb", 3) == 0) { } else if (argc > 2 && strncmp(argv[1], "dtb", 3) == 0) {