Skip to content

Commit

Permalink
'magiskboot hexpatch' will exit with status 1 when nothing patched.
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmacd authored and topjohnwu committed Jun 11, 2019
1 parent 8ebd9c8 commit 8513946
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion native/jni/magiskboot/hexpatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 patched = 1;
size_t filesize;
uint8_t *file, *pattern, *patch;
mmap_rw(image, file, filesize);
Expand All @@ -31,9 +32,12 @@ void hexpatch(const char *image, const char *from, const char *to) {
memset(file + i, 0, patternsize);
memcpy(file + i, patch, patchsize);
i += patternsize - 1;
patched = 0;
}
}
munmap(file, filesize);
free(pattern);
free(patch);

return patched;
}
2 changes: 1 addition & 1 deletion native/jni/magiskboot/magiskboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// Main entries
int unpack(const char *image, bool hdr = false);
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 dtb_commands(const char *cmd, int argc, char *argv[]);

Expand Down
2 changes: 1 addition & 1 deletion native/jni/magiskboot/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ int main(int argc, char *argv[]) {
} else if (argc > 2 && strncmp(argv[1], "compress", 8) == 0) {
compress(argv[1][8] == '=' ? &argv[1][9] : "gzip", argv[2], argv[3]);
} 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) {
if (cpio_commands(argc - 2, argv + 2)) usage(argv[0]);
} else if (argc > 2 && strncmp(argv[1], "dtb", 3) == 0) {
Expand Down

0 comments on commit 8513946

Please sign in to comment.