2016-09-08 12:59:48 +00:00
|
|
|
#include <stdio.h>
|
2017-02-24 19:29:12 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2016-09-08 12:59:48 +00:00
|
|
|
|
2017-02-27 21:37:47 +00:00
|
|
|
#include "magiskboot.h"
|
2016-09-08 12:59:48 +00:00
|
|
|
|
|
|
|
/********************
|
|
|
|
Patch Boot Image
|
|
|
|
*********************/
|
|
|
|
|
2017-02-24 19:29:12 +00:00
|
|
|
static void usage(char *arg0) {
|
2016-09-08 12:59:48 +00:00
|
|
|
fprintf(stderr, "Boot Image Unpack/Repack Tool\n");
|
2017-02-24 06:58:44 +00:00
|
|
|
fprintf(stderr, "%s --unpack <bootimage>\n", arg0);
|
2016-09-08 12:59:48 +00:00
|
|
|
fprintf(stderr, " Unpack <bootimage> into current directory\n\n");
|
|
|
|
fprintf(stderr, "%s --repack <bootimage>\n", arg0);
|
2017-02-24 06:58:44 +00:00
|
|
|
fprintf(stderr, " Repack kernel, dtb, ramdisk... from current directory to new-image.img\n <bootimage> is the image you've just unpacked\n\n");
|
2016-09-08 12:59:48 +00:00
|
|
|
fprintf(stderr, "%s --hexpatch <bootimage> <hexpattern1> <hexpattern2>\n", arg0);
|
|
|
|
fprintf(stderr, " Search <hexpattern1> in <bootimage>, and replace with <hexpattern2>\n\n");
|
2017-02-24 19:29:12 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void error(int rc, const char *msg, ...) {
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, msg);
|
|
|
|
vfprintf(stderr, msg, ap);
|
|
|
|
fprintf(stderr,"\n\n");
|
|
|
|
va_end(ap);
|
|
|
|
exit(rc);
|
2016-09-08 12:59:48 +00:00
|
|
|
}
|
|
|
|
|
2017-02-24 06:58:44 +00:00
|
|
|
int main(int argc, char *argv[]) {
|
2017-02-24 19:29:12 +00:00
|
|
|
if (argc < 3)
|
|
|
|
usage(argv[0]);
|
|
|
|
|
|
|
|
if (strcmp(argv[1], "--unpack") == 0) {
|
|
|
|
unpack(argv[2]);
|
|
|
|
} else if (strcmp(argv[1], "--repack") == 0) {
|
|
|
|
repack(argv[2]);
|
|
|
|
} else if (strcmp(argv[1], "--hexpatch") == 0) {
|
|
|
|
if (argc < 5)
|
|
|
|
usage(argv[0]);
|
|
|
|
hexpatch(argv[2], argv[3], argv[4]);
|
|
|
|
} else {
|
|
|
|
usage(argv[0]);
|
2016-09-08 12:59:48 +00:00
|
|
|
}
|
2017-02-24 19:29:12 +00:00
|
|
|
|
2016-09-08 12:59:48 +00:00
|
|
|
return 0;
|
2017-02-24 19:29:12 +00:00
|
|
|
|
2017-02-24 06:58:44 +00:00
|
|
|
}
|