mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-25 22:17:37 +00:00
Better error handling and logging
This commit is contained in:
parent
ff0a76606e
commit
2a694596b5
@ -346,6 +346,7 @@ void SARInit::early_mount() {
|
|||||||
auto init = raw_data::mmap_ro("/init");
|
auto init = raw_data::mmap_ro("/init");
|
||||||
is_two_stage = init.contains("selinux_setup");
|
is_two_stage = init.contains("selinux_setup");
|
||||||
}
|
}
|
||||||
|
LOGD("is_two_stage: [%d]\n", is_two_stage);
|
||||||
|
|
||||||
if (!is_two_stage) {
|
if (!is_two_stage) {
|
||||||
// Make dev writable
|
// Make dev writable
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int data_holder::patch(str_pairs list) {
|
int data_holder::patch(str_pairs list) {
|
||||||
|
if (buf == nullptr)
|
||||||
|
return 0;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (uint8_t *p = buf, *eof = buf + sz; p < eof; ++p) {
|
for (uint8_t *p = buf, *eof = buf + sz; p < eof; ++p) {
|
||||||
for (auto [from, to] : list) {
|
for (auto [from, to] : list) {
|
||||||
@ -19,10 +21,14 @@ int data_holder::patch(str_pairs list) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool data_holder::contains(string_view pattern) {
|
bool data_holder::contains(string_view pattern) {
|
||||||
|
if (buf == nullptr)
|
||||||
|
return false;
|
||||||
for (uint8_t *p = buf, *eof = buf + sz; p < eof; ++p) {
|
for (uint8_t *p = buf, *eof = buf + sz; p < eof; ++p) {
|
||||||
if (memcmp(p, pattern.data(), pattern.length() + 1) == 0)
|
if (memcmp(p, pattern.data(), pattern.length() + 1) == 0) {
|
||||||
|
LOGD("Found pattern [%s]\n", pattern.data());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,10 +273,17 @@ void fclone_attr(int src, int dest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void *__mmap(const char *filename, size_t *size, bool rw) {
|
void *__mmap(const char *filename, size_t *size, bool rw) {
|
||||||
|
int fd = xopen(filename, (rw ? O_RDWR : O_RDONLY) | O_CLOEXEC);
|
||||||
|
if (fd < 0) {
|
||||||
|
*size = 0;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
struct stat st;
|
struct stat st;
|
||||||
void *buf;
|
void *buf;
|
||||||
int fd = xopen(filename, (rw ? O_RDWR : O_RDONLY) | O_CLOEXEC);
|
if (fstat(fd, &st)) {
|
||||||
fstat(fd, &st);
|
*size = 0;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
if (S_ISBLK(st.st_mode))
|
if (S_ISBLK(st.st_mode))
|
||||||
ioctl(fd, BLKGETSIZE64, size);
|
ioctl(fd, BLKGETSIZE64, size);
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user