mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-06-12 13:17:39 +02:00
Add cpio extract all feature
This commit is contained in:
@ -168,7 +168,7 @@ void cpio_ln(struct vector *v, const char *target, const char *entry) {
|
||||
cpio_entry *f = xcalloc(sizeof(*f), 1);
|
||||
f->mode = S_IFLNK;
|
||||
f->filename = strdup(entry);
|
||||
f->filesize = strlen(target) + 1;
|
||||
f->filesize = strlen(target);
|
||||
f->data = strdup(target);
|
||||
cpio_vec_insert(v, f);
|
||||
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);
|
||||
close(fd);
|
||||
} 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;
|
||||
}
|
||||
@ -229,6 +231,27 @@ int cpio_extract(struct vector *v, const char *entry, const char *filename) {
|
||||
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) {
|
||||
#define STOCK_BOOT 0x0
|
||||
#define MAGISK_PATCH 0x1
|
||||
|
Reference in New Issue
Block a user