mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-24 02:25:28 +00:00
Add decompression command
This commit is contained in:
parent
1d3ce9fef1
commit
340bac7e42
@ -29,6 +29,7 @@ public:
|
||||
void restore();
|
||||
void backup(const char *orig);
|
||||
void compress();
|
||||
void decompress();
|
||||
};
|
||||
|
||||
void magisk_cpio::patch(bool keepverity, bool keepforceencrypt) {
|
||||
@ -206,6 +207,8 @@ void magisk_cpio::backup(const char *orig) {
|
||||
}
|
||||
|
||||
void magisk_cpio::compress() {
|
||||
if (exists(ramdisk_xz))
|
||||
return;
|
||||
fprintf(stderr, "Compressing cpio -> [%s]\n", ramdisk_xz);
|
||||
auto init = entries.extract("init");
|
||||
XZEncoder encoder;
|
||||
@ -219,6 +222,22 @@ void magisk_cpio::compress() {
|
||||
insert(xz);
|
||||
}
|
||||
|
||||
void magisk_cpio::decompress() {
|
||||
auto it = entries.find(ramdisk_xz);
|
||||
if (it == entries.end())
|
||||
return;
|
||||
fprintf(stderr, "Decompressing cpio [%s]\n", ramdisk_xz);
|
||||
LZMADecoder decoder;
|
||||
decoder.set_out(make_unique<BufOutStream>());
|
||||
decoder.write(it->second->data, it->second->filesize);
|
||||
decoder.finalize();
|
||||
entries.erase(it);
|
||||
char *buf;
|
||||
size_t sz;
|
||||
static_cast<BufOutStream *>(decoder.get_out())->getbuf(buf, sz);
|
||||
load_cpio(buf, sz);
|
||||
}
|
||||
|
||||
int cpio_commands(int argc, char *argv[]) {
|
||||
char *incpio = argv[0];
|
||||
++argv;
|
||||
@ -251,6 +270,8 @@ int cpio_commands(int argc, char *argv[]) {
|
||||
return 0;
|
||||
} else if (strcmp(cmdv[0], "compress") == 0){
|
||||
cpio.compress();
|
||||
} else if (strcmp(cmdv[0], "decompress") == 0){
|
||||
cpio.decompress();
|
||||
} else if (cmdc == 2 && strcmp(cmdv[0], "exists") == 0) {
|
||||
exit(!cpio.exists(cmdv[1]));
|
||||
} else if (cmdc == 2 && strcmp(cmdv[0], "backup") == 0) {
|
||||
|
@ -64,14 +64,20 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void release(void *&b, T &len) {
|
||||
template <typename bytes, typename length>
|
||||
void release(bytes *&b, length &len) {
|
||||
b = buf;
|
||||
len = off;
|
||||
buf = nullptr;
|
||||
off = cap = 0;
|
||||
}
|
||||
|
||||
template <typename bytes, typename length>
|
||||
void getbuf(bytes *&b, length &len) const {
|
||||
b = buf;
|
||||
len = off;
|
||||
}
|
||||
|
||||
~BufOutStream() override {
|
||||
free(buf);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user