mirror of
https://github.com/topjohnwu/Magisk.git
synced 2026-01-12 13:05:30 -08:00
Better bytes support in C++
This commit is contained in:
@@ -223,7 +223,7 @@ static bool fdt_patch(void *fdt) {
|
||||
// Force remove AVB for 2SI since it may bootloop some devices
|
||||
int len;
|
||||
const void *value = fdt_getprop(fdt, node, "fsmgr_flags", &len);
|
||||
heap_data copy(value, len);
|
||||
heap_data copy = byte_view(value, len).clone();
|
||||
if (patch_verity(copy)) {
|
||||
modified = true;
|
||||
fdt_setprop(fdt, node, "fsmgr_flags", copy.buf(), copy.sz());
|
||||
@@ -291,8 +291,7 @@ static bool dt_table_patch(const Header *hdr, const char *out) {
|
||||
total_size += xwrite(fd, buf, dtb_map.begin()->first);
|
||||
|
||||
// mmap rw to patch table values retroactively
|
||||
auto mmap_sz = lseek(fd, 0, SEEK_CUR);
|
||||
auto addr = (uint8_t *) xmmap(nullptr, mmap_sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
mmap_data m(fd, lseek(fd, 0, SEEK_CUR), true);
|
||||
|
||||
// Guess alignment using gcd
|
||||
uint32_t align = 1;
|
||||
@@ -319,17 +318,16 @@ static bool dt_table_patch(const Header *hdr, const char *out) {
|
||||
|
||||
// Patch headers
|
||||
if constexpr (is_aosp) {
|
||||
auto hdr_rw = reinterpret_cast<Header *>(addr);
|
||||
auto hdr_rw = reinterpret_cast<Header *>(m.buf());
|
||||
hdr_rw->total_size = le_to_be(total_size);
|
||||
}
|
||||
auto tables_rw = reinterpret_cast<Table *>(addr + sizeof(Header));
|
||||
auto tables_rw = reinterpret_cast<Table *>(m.buf() + sizeof(Header));
|
||||
for (int i = 0; i < num_dtb; ++i) {
|
||||
auto &blob = dtb_map[be_to_le(tables_rw[i].offset)];
|
||||
tables_rw[i].offset = le_to_be(blob.offset);
|
||||
tables_rw[i].len = le_to_be(blob.len);
|
||||
}
|
||||
|
||||
munmap(addr, mmap_sz);
|
||||
close(fd);
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user