Magisk/jni/bootimgtools/main.c

51 lines
1.3 KiB
C
Raw Normal View History

#include <stdio.h>
2017-02-24 20:29:12 +01:00
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
2016-12-09 08:57:10 +01:00
#include "bootimg.h"
/********************
Patch Boot Image
*********************/
2017-02-24 20:29:12 +01:00
static void usage(char *arg0) {
fprintf(stderr, "Boot Image Unpack/Repack Tool\n");
2017-02-24 07:58:44 +01:00
fprintf(stderr, "%s --unpack <bootimage>\n", arg0);
fprintf(stderr, " Unpack <bootimage> into current directory\n\n");
fprintf(stderr, "%s --repack <bootimage>\n", arg0);
2017-02-24 07:58:44 +01: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");
fprintf(stderr, "%s --hexpatch <bootimage> <hexpattern1> <hexpattern2>\n", arg0);
fprintf(stderr, " Search <hexpattern1> in <bootimage>, and replace with <hexpattern2>\n\n");
2017-02-24 20:29:12 +01: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);
}
2017-02-24 07:58:44 +01:00
int main(int argc, char *argv[]) {
2017-02-24 20:29:12 +01: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]);
}
2017-02-24 20:29:12 +01:00
return 0;
2017-02-24 20:29:12 +01:00
2017-02-24 07:58:44 +01:00
}