mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-07 08:12:38 +00:00
Improve byte_data const correctness
This commit is contained in:
@@ -151,8 +151,8 @@ void dyn_img_hdr::load_hdr_file() {
|
||||
|
||||
boot_img::boot_img(const char *image) : map(image) {
|
||||
fprintf(stderr, "Parsing boot image: [%s]\n", image);
|
||||
for (const uint8_t *addr = map.buf; addr < map.buf + map.sz; ++addr) {
|
||||
format_t fmt = check_fmt(addr, map.sz);
|
||||
for (const uint8_t *addr = map.buf(); addr < map.buf() + map.sz(); ++addr) {
|
||||
format_t fmt = check_fmt(addr, map.sz());
|
||||
switch (fmt) {
|
||||
case CHROMEOS:
|
||||
// chromeos require external signing
|
||||
@@ -425,9 +425,9 @@ void boot_img::parse_image(const uint8_t *addr, format_t type) {
|
||||
fprintf(stderr, "%-*s [%s]\n", PADDING, "EXTRA_FMT", fmt2name[e_fmt]);
|
||||
}
|
||||
|
||||
if (addr + off < map.buf + map.sz) {
|
||||
if (addr + off < map.buf() + map.sz()) {
|
||||
tail = addr + off;
|
||||
tail_size = map.buf + map.sz - tail;
|
||||
tail_size = map.buf() + map.sz() - tail;
|
||||
|
||||
// Check special flags
|
||||
if (tail_size >= 16 && BUFFER_MATCH(tail, SEANDROID_MAGIC)) {
|
||||
@@ -454,18 +454,18 @@ void boot_img::parse_image(const uint8_t *addr, format_t type) {
|
||||
}
|
||||
|
||||
int split_image_dtb(const char *filename) {
|
||||
auto img = mmap_data(filename);
|
||||
mmap_data img(filename);
|
||||
|
||||
if (int off = find_dtb_offset(img.buf, img.sz); off > 0) {
|
||||
format_t fmt = check_fmt_lg(img.buf, img.sz);
|
||||
if (int off = find_dtb_offset(img.buf(), img.sz()); off > 0) {
|
||||
format_t fmt = check_fmt_lg(img.buf(), img.sz());
|
||||
if (COMPRESSED(fmt)) {
|
||||
int fd = creat(KERNEL_FILE, 0644);
|
||||
decompress(fmt, fd, img.buf, off);
|
||||
decompress(fmt, fd, img.buf(), off);
|
||||
close(fd);
|
||||
} else {
|
||||
dump(img.buf, off, KERNEL_FILE);
|
||||
dump(img.buf(), off, KERNEL_FILE);
|
||||
}
|
||||
dump(img.buf + off, img.sz - off, KER_DTB_FILE);
|
||||
dump(img.buf() + off, img.sz() - off, KER_DTB_FILE);
|
||||
return 0;
|
||||
} else {
|
||||
fprintf(stderr, "Cannot find DTB in %s\n", filename);
|
||||
@@ -569,11 +569,11 @@ void repack(const char *src_img, const char *out_img, bool skip_comp) {
|
||||
// Skip DHTB header
|
||||
write_zero(fd, sizeof(dhtb_hdr));
|
||||
} else if (boot.flags[BLOB_FLAG]) {
|
||||
xwrite(fd, boot.map.buf, sizeof(blob_hdr));
|
||||
xwrite(fd, boot.map.buf(), sizeof(blob_hdr));
|
||||
} else if (boot.flags[NOOKHD_FLAG]) {
|
||||
xwrite(fd, boot.map.buf, NOOKHD_PRE_HEADER_SZ);
|
||||
xwrite(fd, boot.map.buf(), NOOKHD_PRE_HEADER_SZ);
|
||||
} else if (boot.flags[ACCLAIM_FLAG]) {
|
||||
xwrite(fd, boot.map.buf, ACCLAIM_PRE_HEADER_SZ);
|
||||
xwrite(fd, boot.map.buf(), ACCLAIM_PRE_HEADER_SZ);
|
||||
}
|
||||
|
||||
// Copy raw header
|
||||
@@ -591,13 +591,13 @@ void repack(const char *src_img, const char *out_img, bool skip_comp) {
|
||||
xwrite(fd, boot.z_hdr, boot.z_info.hdr_sz);
|
||||
}
|
||||
if (access(KERNEL_FILE, R_OK) == 0) {
|
||||
auto m = mmap_data(KERNEL_FILE);
|
||||
if (!skip_comp && !COMPRESSED_ANY(check_fmt(m.buf, m.sz)) && COMPRESSED(boot.k_fmt)) {
|
||||
mmap_data m(KERNEL_FILE);
|
||||
if (!skip_comp && !COMPRESSED_ANY(check_fmt(m.buf(), m.sz())) && COMPRESSED(boot.k_fmt)) {
|
||||
// Always use zopfli for zImage compression
|
||||
auto fmt = (boot.flags[ZIMAGE_KERNEL] && boot.k_fmt == GZIP) ? ZOPFLI : boot.k_fmt;
|
||||
hdr->kernel_size() = compress(fmt, fd, m.buf, m.sz);
|
||||
hdr->kernel_size() = compress(fmt, fd, m.buf(), m.sz());
|
||||
} else {
|
||||
hdr->kernel_size() = xwrite(fd, m.buf, m.sz);
|
||||
hdr->kernel_size() = xwrite(fd, m.buf(), m.sz());
|
||||
}
|
||||
|
||||
if (boot.flags[ZIMAGE_KERNEL]) {
|
||||
@@ -608,7 +608,7 @@ void repack(const char *src_img, const char *out_img, bool skip_comp) {
|
||||
} else if (!skip_comp) {
|
||||
// Pad zeros to make sure the zImage file size does not change
|
||||
// Also ensure the last 4 bytes are the uncompressed vmlinux size
|
||||
uint32_t sz = m.sz;
|
||||
uint32_t sz = m.sz();
|
||||
write_zero(fd, boot.hdr->kernel_size() - hdr->kernel_size() - sizeof(sz));
|
||||
xwrite(fd, &sz, sizeof(sz));
|
||||
}
|
||||
@@ -638,7 +638,7 @@ void repack(const char *src_img, const char *out_img, bool skip_comp) {
|
||||
xwrite(fd, boot.r_hdr, sizeof(mtk_hdr));
|
||||
}
|
||||
if (access(RAMDISK_FILE, R_OK) == 0) {
|
||||
auto m = mmap_data(RAMDISK_FILE);
|
||||
mmap_data m(RAMDISK_FILE);
|
||||
auto r_fmt = boot.r_fmt;
|
||||
if (!skip_comp && !hdr->is_vendor && hdr->header_version() == 4 && r_fmt != LZ4_LEGACY) {
|
||||
// A v4 boot image ramdisk will have to be merged with other vendor ramdisks,
|
||||
@@ -647,10 +647,10 @@ void repack(const char *src_img, const char *out_img, bool skip_comp) {
|
||||
fprintf(stderr, "RAMDISK_FMT: [%s] -> [%s]\n", fmt2name[r_fmt], fmt2name[LZ4_LEGACY]);
|
||||
r_fmt = LZ4_LEGACY;
|
||||
}
|
||||
if (!skip_comp && !COMPRESSED_ANY(check_fmt(m.buf, m.sz)) && COMPRESSED(r_fmt)) {
|
||||
hdr->ramdisk_size() = compress(r_fmt, fd, m.buf, m.sz);
|
||||
if (!skip_comp && !COMPRESSED_ANY(check_fmt(m.buf(), m.sz())) && COMPRESSED(r_fmt)) {
|
||||
hdr->ramdisk_size() = compress(r_fmt, fd, m.buf(), m.sz());
|
||||
} else {
|
||||
hdr->ramdisk_size() = xwrite(fd, m.buf, m.sz);
|
||||
hdr->ramdisk_size() = xwrite(fd, m.buf(), m.sz());
|
||||
}
|
||||
file_align();
|
||||
}
|
||||
@@ -665,11 +665,11 @@ void repack(const char *src_img, const char *out_img, bool skip_comp) {
|
||||
// extra
|
||||
off.extra = lseek(fd, 0, SEEK_CUR);
|
||||
if (access(EXTRA_FILE, R_OK) == 0) {
|
||||
auto m = mmap_data(EXTRA_FILE);
|
||||
if (!skip_comp && !COMPRESSED_ANY(check_fmt(m.buf, m.sz)) && COMPRESSED(boot.e_fmt)) {
|
||||
hdr->extra_size() = compress(boot.e_fmt, fd, m.buf, m.sz);
|
||||
mmap_data m(EXTRA_FILE);
|
||||
if (!skip_comp && !COMPRESSED_ANY(check_fmt(m.buf(), m.sz())) && COMPRESSED(boot.e_fmt)) {
|
||||
hdr->extra_size() = compress(boot.e_fmt, fd, m.buf(), m.sz());
|
||||
} else {
|
||||
hdr->extra_size() = xwrite(fd, m.buf, m.sz);
|
||||
hdr->extra_size() = xwrite(fd, m.buf(), m.sz());
|
||||
}
|
||||
file_align();
|
||||
}
|
||||
@@ -720,8 +720,8 @@ void repack(const char *src_img, const char *out_img, bool skip_comp) {
|
||||
// Pad image to original size if not chromeos (as it requires post processing)
|
||||
if (!boot.flags[CHROMEOS_FLAG]) {
|
||||
off_t current = lseek(fd, 0, SEEK_CUR);
|
||||
if (current < boot.map.sz) {
|
||||
write_zero(fd, boot.map.sz - current);
|
||||
if (current < boot.map.sz()) {
|
||||
write_zero(fd, boot.map.sz() - current);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -732,16 +732,16 @@ void repack(const char *src_img, const char *out_img, bool skip_comp) {
|
||||
******************/
|
||||
|
||||
// Map output image as rw
|
||||
auto out = mmap_data(out_img, true);
|
||||
mmap_data out(out_img, true);
|
||||
|
||||
// MTK headers
|
||||
if (boot.flags[MTK_KERNEL]) {
|
||||
auto m_hdr = reinterpret_cast<mtk_hdr *>(out.buf + off.kernel);
|
||||
auto m_hdr = reinterpret_cast<mtk_hdr *>(out.buf() + off.kernel);
|
||||
m_hdr->size = hdr->kernel_size();
|
||||
hdr->kernel_size() += sizeof(mtk_hdr);
|
||||
}
|
||||
if (boot.flags[MTK_RAMDISK]) {
|
||||
auto m_hdr = reinterpret_cast<mtk_hdr *>(out.buf + off.ramdisk);
|
||||
auto m_hdr = reinterpret_cast<mtk_hdr *>(out.buf() + off.ramdisk);
|
||||
m_hdr->size = hdr->ramdisk_size();
|
||||
hdr->ramdisk_size() += sizeof(mtk_hdr);
|
||||
}
|
||||
@@ -754,28 +754,28 @@ void repack(const char *src_img, const char *out_img, bool skip_comp) {
|
||||
HASH_CTX ctx;
|
||||
boot.flags[SHA256_FLAG] ? SHA256_init(&ctx) : SHA_init(&ctx);
|
||||
uint32_t size = hdr->kernel_size();
|
||||
HASH_update(&ctx, out.buf + off.kernel, size);
|
||||
HASH_update(&ctx, out.buf() + off.kernel, size);
|
||||
HASH_update(&ctx, &size, sizeof(size));
|
||||
size = hdr->ramdisk_size();
|
||||
HASH_update(&ctx, out.buf + off.ramdisk, size);
|
||||
HASH_update(&ctx, out.buf() + off.ramdisk, size);
|
||||
HASH_update(&ctx, &size, sizeof(size));
|
||||
size = hdr->second_size();
|
||||
HASH_update(&ctx, out.buf + off.second, size);
|
||||
HASH_update(&ctx, out.buf() + off.second, size);
|
||||
HASH_update(&ctx, &size, sizeof(size));
|
||||
size = hdr->extra_size();
|
||||
if (size) {
|
||||
HASH_update(&ctx, out.buf + off.extra, size);
|
||||
HASH_update(&ctx, out.buf() + off.extra, size);
|
||||
HASH_update(&ctx, &size, sizeof(size));
|
||||
}
|
||||
uint32_t ver = hdr->header_version();
|
||||
if (ver == 1 || ver == 2) {
|
||||
size = hdr->recovery_dtbo_size();
|
||||
HASH_update(&ctx, out.buf + hdr->recovery_dtbo_offset(), size);
|
||||
HASH_update(&ctx, out.buf() + hdr->recovery_dtbo_offset(), size);
|
||||
HASH_update(&ctx, &size, sizeof(size));
|
||||
}
|
||||
if (ver == 2) {
|
||||
size = hdr->dtb_size();
|
||||
HASH_update(&ctx, out.buf + off.dtb, size);
|
||||
HASH_update(&ctx, out.buf() + off.dtb, size);
|
||||
HASH_update(&ctx, &size, sizeof(size));
|
||||
}
|
||||
memset(id, 0, BOOT_ID_SIZE);
|
||||
@@ -788,15 +788,15 @@ void repack(const char *src_img, const char *out_img, bool skip_comp) {
|
||||
// Copy main header
|
||||
if (boot.flags[AMONET_FLAG]) {
|
||||
auto real_hdr_sz = std::min(hdr->hdr_space() - AMONET_MICROLOADER_SZ, hdr->hdr_size());
|
||||
memcpy(out.buf + off.header + AMONET_MICROLOADER_SZ, hdr->raw_hdr(), real_hdr_sz);
|
||||
memcpy(out.buf() + off.header + AMONET_MICROLOADER_SZ, hdr->raw_hdr(), real_hdr_sz);
|
||||
} else {
|
||||
memcpy(out.buf + off.header, hdr->raw_hdr(), hdr->hdr_size());
|
||||
memcpy(out.buf() + off.header, hdr->raw_hdr(), hdr->hdr_size());
|
||||
}
|
||||
|
||||
if (boot.flags[AVB_FLAG]) {
|
||||
// Copy and patch AVB structures
|
||||
auto footer = reinterpret_cast<AvbFooter*>(out.buf + out.sz - sizeof(AvbFooter));
|
||||
auto vbmeta = reinterpret_cast<AvbVBMetaImageHeader*>(out.buf + off.vbmeta);
|
||||
auto footer = reinterpret_cast<AvbFooter*>(out.buf() + out.sz() - sizeof(AvbFooter));
|
||||
auto vbmeta = reinterpret_cast<AvbVBMetaImageHeader*>(out.buf() + off.vbmeta);
|
||||
memcpy(footer, boot.avb_footer, sizeof(AvbFooter));
|
||||
footer->original_image_size = __builtin_bswap64(off.total);
|
||||
footer->vbmeta_offset = __builtin_bswap64(off.vbmeta);
|
||||
@@ -807,13 +807,13 @@ void repack(const char *src_img, const char *out_img, bool skip_comp) {
|
||||
|
||||
if (boot.flags[DHTB_FLAG]) {
|
||||
// DHTB header
|
||||
auto d_hdr = reinterpret_cast<dhtb_hdr *>(out.buf);
|
||||
auto d_hdr = reinterpret_cast<dhtb_hdr *>(out.buf());
|
||||
memcpy(d_hdr, DHTB_MAGIC, 8);
|
||||
d_hdr->size = off.total - sizeof(dhtb_hdr);
|
||||
SHA256_hash(out.buf + sizeof(dhtb_hdr), d_hdr->size, d_hdr->checksum);
|
||||
SHA256_hash(out.buf() + sizeof(dhtb_hdr), d_hdr->size, d_hdr->checksum);
|
||||
} else if (boot.flags[BLOB_FLAG]) {
|
||||
// Blob header
|
||||
auto b_hdr = reinterpret_cast<blob_hdr *>(out.buf);
|
||||
auto b_hdr = reinterpret_cast<blob_hdr *>(out.buf());
|
||||
b_hdr->size = off.total - sizeof(blob_hdr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ static uint32_t x8u(const char *hex) {
|
||||
|
||||
cpio_entry::cpio_entry(uint32_t mode) : mode(mode), uid(0), gid(0), data(0) {}
|
||||
|
||||
cpio_entry::cpio_entry(uint32_t mode, const byte_data &data) :
|
||||
cpio_entry::cpio_entry(uint32_t mode, const byte_view &data) :
|
||||
mode(mode), uid(0), gid(0), data(data.clone()) {}
|
||||
|
||||
cpio_entry::cpio_entry(const cpio_newc_header *h) :
|
||||
@@ -89,13 +89,13 @@ static void extract_entry(const cpio::entry_map::value_type &e, const char *file
|
||||
xmkdir(file, e.second->mode & 0777);
|
||||
} else if (S_ISREG(e.second->mode)) {
|
||||
int fd = xopen(file, O_CREAT | O_WRONLY | O_TRUNC, e.second->mode & 0777);
|
||||
xwrite(fd, e.second->data.buf, e.second->data.sz);
|
||||
xwrite(fd, e.second->data.buf(), e.second->data.sz());
|
||||
fchown(fd, e.second->uid, e.second->gid);
|
||||
close(fd);
|
||||
} else if (S_ISLNK(e.second->mode) && e.second->data.sz < 4096) {
|
||||
} else if (S_ISLNK(e.second->mode) && e.second->data.sz() < 4096) {
|
||||
char target[4096];
|
||||
memcpy(target, e.second->data.buf, e.second->data.sz);
|
||||
target[e.second->data.sz] = '\0';
|
||||
memcpy(target, e.second->data.buf(), e.second->data.sz());
|
||||
target[e.second->data.sz()] = '\0';
|
||||
symlink(target, file);
|
||||
}
|
||||
}
|
||||
@@ -134,7 +134,7 @@ void cpio::dump(FILE *out) {
|
||||
e.second->gid,
|
||||
1, // e->nlink
|
||||
0, // e->mtime
|
||||
(uint32_t) e.second->data.sz,
|
||||
(uint32_t) e.second->data.sz(),
|
||||
0, // e->devmajor
|
||||
0, // e->devminor
|
||||
0, // e->rdevmajor
|
||||
@@ -145,8 +145,8 @@ void cpio::dump(FILE *out) {
|
||||
do_out(header, 110);
|
||||
do_out(e.first.data(), e.first.size() + 1);
|
||||
out_align();
|
||||
if (e.second->data.sz) {
|
||||
do_out(e.second->data.buf, e.second->data.sz);
|
||||
if (e.second->data.sz()) {
|
||||
do_out(e.second->data.buf(), e.second->data.sz());
|
||||
out_align();
|
||||
}
|
||||
}
|
||||
@@ -161,8 +161,8 @@ void cpio::dump(FILE *out) {
|
||||
|
||||
void cpio::load_cpio(const char *file) {
|
||||
fprintf(stderr, "Loading cpio: [%s]\n", file);
|
||||
auto m = mmap_data(file);
|
||||
load_cpio(reinterpret_cast<char *>(m.buf), m.sz);
|
||||
mmap_data m(file);
|
||||
load_cpio(reinterpret_cast<char *>(m.buf()), m.sz());
|
||||
}
|
||||
|
||||
void cpio::insert(string_view name, cpio_entry *e) {
|
||||
@@ -187,7 +187,7 @@ void cpio::mkdir(mode_t mode, const char *name) {
|
||||
}
|
||||
|
||||
void cpio::ln(const char *target, const char *name) {
|
||||
byte_data link(target);
|
||||
byte_view link(target);
|
||||
auto e = new cpio_entry(S_IFLNK, link);
|
||||
insert(name, e);
|
||||
fprintf(stderr, "Create symlink [%s] -> [%s]\n", name, target);
|
||||
@@ -234,8 +234,8 @@ void cpio::load_cpio(const char *buf, size_t sz) {
|
||||
continue;
|
||||
}
|
||||
auto entry = new cpio_entry(hdr);
|
||||
memcpy(entry->data.buf, buf + pos, entry->data.sz);
|
||||
pos += entry->data.sz;
|
||||
memcpy(entry->data.buf(), buf + pos, entry->data.sz());
|
||||
pos += entry->data.sz();
|
||||
insert(name, entry);
|
||||
pos_align(pos);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ struct cpio_entry {
|
||||
heap_data data;
|
||||
|
||||
explicit cpio_entry(uint32_t mode);
|
||||
explicit cpio_entry(uint32_t mode, const byte_data &data);
|
||||
explicit cpio_entry(uint32_t mode, const byte_view &data);
|
||||
explicit cpio_entry(const cpio_newc_header *h);
|
||||
};
|
||||
|
||||
|
||||
@@ -95,9 +95,9 @@ static int find_fstab(const void *fdt, int node = 0) {
|
||||
|
||||
template<typename Func>
|
||||
static void for_each_fdt(const char *file, bool rw, Func fn) {
|
||||
auto m = mmap_data(file, rw);
|
||||
uint8_t *end = m.buf + m.sz;
|
||||
for (uint8_t *fdt = m.buf; fdt < end;) {
|
||||
mmap_data m(file, rw);
|
||||
uint8_t *end = m.buf() + m.sz();
|
||||
for (uint8_t *fdt = m.buf(); fdt < end;) {
|
||||
fdt = static_cast<uint8_t*>(memmem(fdt, end - fdt, DTB_MAGIC, sizeof(fdt32_t)));
|
||||
if (fdt == nullptr)
|
||||
break;
|
||||
@@ -226,7 +226,7 @@ static bool fdt_patch(void *fdt) {
|
||||
heap_data copy(value, len);
|
||||
if (patch_verity(copy)) {
|
||||
modified = true;
|
||||
fdt_setprop(fdt, node, "fsmgr_flags", copy.buf, copy.sz);
|
||||
fdt_setprop(fdt, node, "fsmgr_flags", copy.buf(), copy.sz());
|
||||
}
|
||||
if (name == "system"sv) {
|
||||
fprintf(stderr, "Setting [mnt_point] to [/system_root]\n");
|
||||
|
||||
@@ -1,41 +1,24 @@
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <base.hpp>
|
||||
|
||||
#include "magiskboot.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
static void hex2byte(const char *hex, uint8_t *buf) {
|
||||
static void hex2byte(string_view hex, uint8_t *buf) {
|
||||
char high, low;
|
||||
for (int i = 0, length = strlen(hex); i < length; i += 2) {
|
||||
for (int i = 0, length = hex.length(); i < length; i += 2) {
|
||||
high = toupper(hex[i]) - '0';
|
||||
low = toupper(hex[i + 1]) - '0';
|
||||
buf[i / 2] = ((high > 9 ? high - 7 : high) << 4) + (low > 9 ? low - 7 : low);
|
||||
}
|
||||
}
|
||||
|
||||
int hexpatch(const char *file, const char *from, const char *to) {
|
||||
int patched = 1;
|
||||
int hexpatch(const char *file, string_view from, string_view to) {
|
||||
mmap_data m(file, true);
|
||||
|
||||
auto m = mmap_data(file, true);
|
||||
|
||||
vector<uint8_t> pattern(strlen(from) / 2);
|
||||
vector<uint8_t> patch(strlen(to) / 2);
|
||||
vector<uint8_t> pattern(from.length() / 2);
|
||||
vector<uint8_t> patch(to.length() / 2);
|
||||
|
||||
hex2byte(from, pattern.data());
|
||||
hex2byte(to, patch.data());
|
||||
|
||||
uint8_t * const end = m.buf + m.sz;
|
||||
for (uint8_t *curr = m.buf; curr < end; curr += pattern.size()) {
|
||||
curr = static_cast<uint8_t*>(memmem(curr, end - curr, pattern.data(), pattern.size()));
|
||||
if (curr == nullptr)
|
||||
return patched;
|
||||
fprintf(stderr, "Patch @ %08X [%s] -> [%s]\n", (unsigned)(curr - m.buf), from, to);
|
||||
memset(curr, 0, pattern.size());
|
||||
memcpy(curr, patch.data(), patch.size());
|
||||
patched = 0;
|
||||
}
|
||||
|
||||
return patched;
|
||||
return m.patch({ make_pair(pattern, patch) }) > 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
int unpack(const char *image, bool skip_decomp = false, bool hdr = false);
|
||||
void repack(const char *src_img, const char *out_img, bool skip_comp = false);
|
||||
int split_image_dtb(const char *filename);
|
||||
int hexpatch(const char *file, const char *from, const char *to);
|
||||
int hexpatch(const char *file, std::string_view from, std::string_view to);
|
||||
int cpio_commands(int argc, char *argv[]);
|
||||
int dtb_commands(int argc, char *argv[]);
|
||||
|
||||
|
||||
@@ -159,8 +159,8 @@ int main(int argc, char *argv[]) {
|
||||
unlink(DTB_FILE);
|
||||
} else if (argc > 2 && action == "sha1") {
|
||||
uint8_t sha1[SHA_DIGEST_SIZE];
|
||||
auto m = mmap_data(argv[2]);
|
||||
SHA_hash(m.buf, m.sz, sha1);
|
||||
mmap_data m(argv[2]);
|
||||
SHA_hash(m.buf(), m.sz(), sha1);
|
||||
for (uint8_t i : sha1)
|
||||
printf("%02x", i);
|
||||
printf("\n");
|
||||
|
||||
@@ -40,21 +40,21 @@ static int skip_encryption_pattern(const char *s) {
|
||||
}
|
||||
|
||||
static bool remove_pattern(byte_data &data, int(*pattern_skip)(const char *)) {
|
||||
char *src = reinterpret_cast<char *>(data.buf);
|
||||
size_t orig_sz = data.sz;
|
||||
char *src = reinterpret_cast<char *>(data.buf());
|
||||
size_t orig_sz = data.sz();
|
||||
int write = 0;
|
||||
int read = 0;
|
||||
while (read < orig_sz) {
|
||||
if (int skip = pattern_skip(src + read); skip > 0) {
|
||||
fprintf(stderr, "Remove pattern [%.*s]\n", skip, src + read);
|
||||
data.sz -= skip;
|
||||
data.sz() -= skip;
|
||||
read += skip;
|
||||
} else {
|
||||
src[write++] = src[read++];
|
||||
}
|
||||
}
|
||||
memset(src + write, 0, orig_sz - write);
|
||||
return data.sz != orig_sz;
|
||||
return data.sz() != orig_sz;
|
||||
}
|
||||
|
||||
bool patch_verity(byte_data &data) {
|
||||
|
||||
@@ -111,7 +111,7 @@ void magisk_cpio::restore() {
|
||||
rm(bk);
|
||||
rm(mg);
|
||||
if (rl != entries.end()) {
|
||||
for_each_str(file, rl->second->data.buf, rl->second->data.sz) {
|
||||
for_each_str(file, rl->second->data.buf(), rl->second->data.sz()) {
|
||||
rm(file);
|
||||
}
|
||||
rm(rl);
|
||||
@@ -186,7 +186,7 @@ void magisk_cpio::backup(const char *orig) {
|
||||
}
|
||||
|
||||
if (!rm_list.empty()) {
|
||||
byte_data rm(rm_list);
|
||||
byte_view rm(rm_list);
|
||||
auto rm_list_file = new cpio_entry(S_IFREG, rm);
|
||||
backups.emplace(".backup/.rmlist", rm_list_file);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user