Add cpio extract all feature
This commit is contained in:
parent
e649b0a2df
commit
4672a5fad6
@ -51,6 +51,7 @@ void cpio_ln(struct vector *v, const char *target, const char *entry);
|
|||||||
void cpio_add(struct vector *v, mode_t mode, const char *entry, const char *filename);
|
void cpio_add(struct vector *v, mode_t mode, const char *entry, const char *filename);
|
||||||
int cpio_mv(struct vector *v, const char *from, const char *to);
|
int cpio_mv(struct vector *v, const char *from, const char *to);
|
||||||
int cpio_extract(struct vector *v, const char *entry, const char *filename);
|
int cpio_extract(struct vector *v, const char *entry, const char *filename);
|
||||||
|
void cpio_extract_all(struct vector *v);
|
||||||
|
|
||||||
// Magisk specific
|
// Magisk specific
|
||||||
int cpio_test(struct vector *v);
|
int cpio_test(struct vector *v);
|
||||||
|
@ -44,8 +44,8 @@ static void usage(char *arg0) {
|
|||||||
" Add <infile> as an <entry>; replaces <entry> if already exists\n"
|
" Add <infile> as an <entry>; replaces <entry> if already exists\n"
|
||||||
" -mv <from-entry> <to-entry>\n"
|
" -mv <from-entry> <to-entry>\n"
|
||||||
" Move <from-entry> to <to-entry>\n"
|
" Move <from-entry> to <to-entry>\n"
|
||||||
" -extract <entry> <outfile>\n"
|
" -extract [<entry> <outfile>]\n"
|
||||||
" Extract <entry> to <outfile>\n"
|
" Extract <entry> to <outfile>, or extract all to current directory\n"
|
||||||
" -test\n"
|
" -test\n"
|
||||||
" Return value: 0/stock 1/Magisk 2/other (phh, SuperSU, Xposed)\n"
|
" Return value: 0/stock 1/Magisk 2/other (phh, SuperSU, Xposed)\n"
|
||||||
" -patch <KEEPVERITY> <KEEPFORCEENCRYPT>\n"
|
" -patch <KEEPVERITY> <KEEPFORCEENCRYPT>\n"
|
||||||
|
@ -93,7 +93,6 @@ int cpio_commands(const char *command, int argc, char *argv[]) {
|
|||||||
if (argc == 2 && strcmp(argv[0], "-r") == 0) {
|
if (argc == 2 && strcmp(argv[0], "-r") == 0) {
|
||||||
recursive = 1;
|
recursive = 1;
|
||||||
++argv;
|
++argv;
|
||||||
--argc;
|
|
||||||
}
|
}
|
||||||
cpio_rm(&v, recursive, argv[0]);
|
cpio_rm(&v, recursive, argv[0]);
|
||||||
} else if (argc == 2 && strcmp(command, "mv") == 0) {
|
} else if (argc == 2 && strcmp(command, "mv") == 0) {
|
||||||
@ -101,8 +100,13 @@ int cpio_commands(const char *command, int argc, char *argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
} else if (argc == 2 && strcmp(command, "patch") == 0) {
|
} else if (argc == 2 && strcmp(command, "patch") == 0) {
|
||||||
cpio_patch(&v, strcmp(argv[0], "true") == 0, strcmp(argv[1], "true") == 0);
|
cpio_patch(&v, strcmp(argv[0], "true") == 0, strcmp(argv[1], "true") == 0);
|
||||||
} else if (argc == 2 && strcmp(command, "extract") == 0) {
|
} else if (strcmp(command, "extract") == 0) {
|
||||||
return cpio_extract(&v, argv[0], argv[1]);
|
if (argc == 2) {
|
||||||
|
return cpio_extract(&v, argv[0], argv[1]);
|
||||||
|
} else {
|
||||||
|
cpio_extract_all(&v);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
} else if (argc == 2 && strcmp(command, "mkdir") == 0) {
|
} else if (argc == 2 && strcmp(command, "mkdir") == 0) {
|
||||||
cpio_mkdir(&v, strtoul(argv[0], NULL, 8), argv[1]);
|
cpio_mkdir(&v, strtoul(argv[0], NULL, 8), argv[1]);
|
||||||
} else if (argc == 2 && strcmp(command, "ln") == 0) {
|
} else if (argc == 2 && strcmp(command, "ln") == 0) {
|
||||||
|
@ -168,7 +168,7 @@ void cpio_ln(struct vector *v, const char *target, const char *entry) {
|
|||||||
cpio_entry *f = xcalloc(sizeof(*f), 1);
|
cpio_entry *f = xcalloc(sizeof(*f), 1);
|
||||||
f->mode = S_IFLNK;
|
f->mode = S_IFLNK;
|
||||||
f->filename = strdup(entry);
|
f->filename = strdup(entry);
|
||||||
f->filesize = strlen(target) + 1;
|
f->filesize = strlen(target);
|
||||||
f->data = strdup(target);
|
f->data = strdup(target);
|
||||||
cpio_vec_insert(v, f);
|
cpio_vec_insert(v, f);
|
||||||
fprintf(stderr, "Create symlink [%s] -> [%s]\n", entry, target);
|
fprintf(stderr, "Create symlink [%s] -> [%s]\n", entry, target);
|
||||||
@ -220,7 +220,9 @@ int cpio_extract(struct vector *v, const char *entry, const char *filename) {
|
|||||||
fchown(fd, f->uid, f->gid);
|
fchown(fd, f->uid, f->gid);
|
||||||
close(fd);
|
close(fd);
|
||||||
} else if (S_ISLNK(f->mode)) {
|
} else if (S_ISLNK(f->mode)) {
|
||||||
symlink(f->data, filename);
|
char *target = xcalloc(f->filesize + 1, 1);
|
||||||
|
memcpy(target, f->data, f->filesize);
|
||||||
|
symlink(target, filename);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -229,6 +231,27 @@ int cpio_extract(struct vector *v, const char *entry, const char *filename) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cpio_extract_all(struct vector *v) {
|
||||||
|
cpio_entry *f;
|
||||||
|
vec_for_each(v, f) {
|
||||||
|
fprintf(stderr, "Extracting [%s]\n", f->filename);
|
||||||
|
unlink(f->filename);
|
||||||
|
rmdir(f->filename);
|
||||||
|
if (S_ISDIR(f->mode)) {
|
||||||
|
mkdir(f->filename, f->mode & 0777);
|
||||||
|
} else if (S_ISREG(f->mode)) {
|
||||||
|
int fd = creat(f->filename, f->mode & 0777);
|
||||||
|
xwrite(fd, f->data, f->filesize);
|
||||||
|
fchown(fd, f->uid, f->gid);
|
||||||
|
close(fd);
|
||||||
|
} else if (S_ISLNK(f->mode)) {
|
||||||
|
char *target = xcalloc(f->filesize + 1, 1);
|
||||||
|
memcpy(target, f->data, f->filesize);
|
||||||
|
symlink(target, f->filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int cpio_test(struct vector *v) {
|
int cpio_test(struct vector *v) {
|
||||||
#define STOCK_BOOT 0x0
|
#define STOCK_BOOT 0x0
|
||||||
#define MAGISK_PATCH 0x1
|
#define MAGISK_PATCH 0x1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user