mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-01-12 17:33:37 +00:00
Several improvements
This commit is contained in:
parent
ee2a30470a
commit
6f609f0dd7
@ -3,6 +3,6 @@ LOCAL_PATH := $(call my-dir)
|
|||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
LOCAL_MODULE := bootimgtools
|
LOCAL_MODULE := bootimgtools
|
||||||
LOCAL_MODULE_TAGS := optional
|
LOCAL_MODULE_TAGS := optional
|
||||||
LOCAL_SRC_FILES := main.c extract.c repack.c hexpatch.c
|
LOCAL_SRC_FILES := main.c unpack.c repack.c hexpatch.c
|
||||||
LOCAL_CFLAGS += -std=gnu11
|
LOCAL_CFLAGS += -std=gnu11
|
||||||
include $(BUILD_EXECUTABLE)
|
include $(BUILD_EXECUTABLE)
|
||||||
|
@ -93,7 +93,7 @@ struct boot_img_hdr
|
|||||||
** else: jump to kernel_addr
|
** else: jump to kernel_addr
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int extract(const char *image);
|
int unpack(const char *image);
|
||||||
int repack(const char *image);
|
int repack(const char *image);
|
||||||
int hexpatch(char *image, char *from, char *to);
|
int hexpatch(char *image, char *from, char *to);
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
#include "bootimg.h"
|
#include "bootimg.h"
|
||||||
|
|
||||||
int hex2int(char c) {
|
static int hex2int(char c) {
|
||||||
int first = c / 16 - 3;
|
int first = c / 16 - 3;
|
||||||
int second = c % 16;
|
int second = c % 16;
|
||||||
int result = first * 10 + second;
|
int result = first * 10 + second;
|
||||||
@ -17,13 +17,13 @@ int hex2int(char c) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int hex2ascii(char c, char d) {
|
static int hex2ascii(char c, char d) {
|
||||||
int high = hex2int(c) * 16;
|
int high = hex2int(c) * 16;
|
||||||
int low = hex2int(d);
|
int low = hex2int(d);
|
||||||
return high+low;
|
return high+low;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hexstr2str(char *hex, char *str) {
|
static void hexstr2str(char *hex, char *str) {
|
||||||
char buf = 0;
|
char buf = 0;
|
||||||
for(int i = 0, length = strlen(hex); i < length; ++i){
|
for(int i = 0, length = strlen(hex); i < length; ++i){
|
||||||
if(i % 2){
|
if(i % 2){
|
||||||
|
@ -7,22 +7,21 @@
|
|||||||
Patch Boot Image
|
Patch Boot Image
|
||||||
*********************/
|
*********************/
|
||||||
|
|
||||||
int usage(char *arg0) {
|
static int usage(char *arg0) {
|
||||||
fprintf(stderr, "Boot Image Unpack/Repack Tool\n");
|
fprintf(stderr, "Boot Image Unpack/Repack Tool\n");
|
||||||
fprintf(stderr, "%s --extract <bootimage>\n", arg0);
|
fprintf(stderr, "%s --unpack <bootimage>\n", arg0);
|
||||||
fprintf(stderr, " Unpack <bootimage> into current directory\n\n");
|
fprintf(stderr, " Unpack <bootimage> into current directory\n\n");
|
||||||
fprintf(stderr, "%s --repack <bootimage>\n", arg0);
|
fprintf(stderr, "%s --repack <bootimage>\n", arg0);
|
||||||
fprintf(stderr, " Repack kernel, dt, ramdisk... from current directory to new-image.img\n <bootimage> is the image you've just unpacked\n\n");
|
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, "%s --hexpatch <bootimage> <hexpattern1> <hexpattern2>\n", arg0);
|
||||||
fprintf(stderr, " Search <hexpattern1> in <bootimage>, and replace with <hexpattern2>\n\n");
|
fprintf(stderr, " Search <hexpattern1> in <bootimage>, and replace with <hexpattern2>\n\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[]) {
|
||||||
{
|
|
||||||
char ch;
|
char ch;
|
||||||
struct option long_options[] = {
|
struct option long_options[] = {
|
||||||
{"extract", required_argument, NULL, 'e'},
|
{"unpack", required_argument, NULL, 'u'},
|
||||||
{"repack", required_argument, NULL, 'r'},
|
{"repack", required_argument, NULL, 'r'},
|
||||||
{"hexpatch", required_argument, NULL, 'p'},
|
{"hexpatch", required_argument, NULL, 'p'},
|
||||||
{NULL, 0, NULL, 0}
|
{NULL, 0, NULL, 0}
|
||||||
@ -30,7 +29,7 @@ int main(int argc, char *argv[])
|
|||||||
while ((ch = getopt_long(argc, argv, "e:r:p:", long_options, NULL)) != -1) {
|
while ((ch = getopt_long(argc, argv, "e:r:p:", long_options, NULL)) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'e':
|
case 'e':
|
||||||
return extract(optarg);
|
return unpack(optarg);
|
||||||
case 'r':
|
case 'r':
|
||||||
return repack(optarg);
|
return repack(optarg);
|
||||||
case 'p':
|
case 'p':
|
||||||
@ -42,4 +41,4 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
#include "bootimg.h"
|
#include "bootimg.h"
|
||||||
|
|
||||||
// Global pointer of current positions
|
// Global pointer of current positions
|
||||||
void *ibase, *ipos;
|
static void *ibase, *ipos;
|
||||||
int ofd, opos;
|
static int ofd, opos;
|
||||||
|
|
||||||
static size_t dump(const char *filename) {
|
static size_t dump(const char *filename) {
|
||||||
int fd = open(filename, O_RDONLY);
|
int fd = open(filename, O_RDONLY);
|
||||||
@ -60,7 +60,7 @@ static int aosp() {
|
|||||||
printf("AOSP Boot Image Detected\n");
|
printf("AOSP Boot Image Detected\n");
|
||||||
|
|
||||||
char *name;
|
char *name;
|
||||||
struct boot_img_hdr hdr, ihdr;
|
boot_img_hdr hdr, ihdr;
|
||||||
|
|
||||||
// Read the original header
|
// Read the original header
|
||||||
memcpy(&ihdr, ibase, sizeof(ihdr));
|
memcpy(&ihdr, ibase, sizeof(ihdr));
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#include "bootimg.h"
|
#include "bootimg.h"
|
||||||
|
|
||||||
// Global pointer of current positions
|
// Global pointer of current positions
|
||||||
unsigned char *base, *pos;
|
static unsigned char *base, *pos;
|
||||||
|
|
||||||
static void dump(size_t size, const char *filename) {
|
static void dump(size_t size, const char *filename) {
|
||||||
unlink(filename);
|
unlink(filename);
|
||||||
@ -37,7 +37,7 @@ static int aosp() {
|
|||||||
char name[PATH_MAX], *ext;
|
char name[PATH_MAX], *ext;
|
||||||
|
|
||||||
// Read the header
|
// Read the header
|
||||||
struct boot_img_hdr hdr;
|
boot_img_hdr hdr;
|
||||||
memcpy(&hdr, base, sizeof(hdr));
|
memcpy(&hdr, base, sizeof(hdr));
|
||||||
|
|
||||||
pos = base + hdr.page_size;
|
pos = base + hdr.page_size;
|
||||||
@ -108,7 +108,7 @@ static int aosp() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int extract(const char* image) {
|
int unpack(const char* image) {
|
||||||
int fd = open(image, O_RDONLY), ret = 0;
|
int fd = open(image, O_RDONLY), ret = 0;
|
||||||
size_t size = lseek(fd, 0, SEEK_END);
|
size_t size = lseek(fd, 0, SEEK_END);
|
||||||
lseek(fd, 0, SEEK_SET);
|
lseek(fd, 0, SEEK_SET);
|
Loading…
x
Reference in New Issue
Block a user