Skip to content

Commit

Permalink
lil fix
Browse files Browse the repository at this point in the history
  • Loading branch information
j-hc committed Sep 12, 2023
1 parent 4490a66 commit 647bc1d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
23 changes: 19 additions & 4 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ extern "C" {
}

fn main() -> ExitCode {
std::panic::set_hook(Box::new(|panic| {
use termion::raw::IntoRawMode;
if let Ok(mut stderr) = io::stderr().into_raw_mode() {
let _ = writeln!(stderr, "\r\n{panic}\r\n");
let _ = writeln!(stderr, "This should not have happened.\r");
let _ = writeln!(
stderr,
"Report at https://github.com/j-hc/zygisk-detach/issues\r"
);
let _ = write!(stderr, "{}", cursor::Show);
}
}));

let mut args = std::env::args().skip(1);
if matches!(args.next().as_deref(), Some("--serialize")) {
match args.next() {
Expand All @@ -52,7 +65,7 @@ fn main() -> ExitCode {
}

let ret = match interactive() {
Ok(_) => ExitCode::SUCCESS,
Ok(()) => ExitCode::SUCCESS,
Err(err) => {
eprintln!("\rERROR: {err}");
ExitCode::FAILURE
Expand Down Expand Up @@ -162,9 +175,11 @@ fn get_detached_apps(detach_txt: &[u8]) -> Vec<(String, Range<usize>)> {
let len: u8 = detach_txt[i];
const SZ_LEN: usize = size_of::<u8>();
i += SZ_LEN;
let encoded_name = &detach_txt
.get(i..i + len as usize)
.expect("corrupted detach.bin");
let Some(encoded_name) = &detach_txt.get(i..i + len as usize) else {
eprintln!("Corrupted detach.bin. Reset and try again.");
let _ = cursor_show();
std::process::exit(1);
};
let name = String::from_utf8(encoded_name.iter().step_by(2).cloned().collect()).unwrap();
detached.push((name, i - SZ_LEN..i + len as usize));
i += len as usize;
Expand Down
7 changes: 3 additions & 4 deletions zygisk/jni/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,11 @@ class Sigringe : public zygisk::ModuleBase {
FILE* fp = fopen("/proc/self/maps", "r");
if (!fp) return false;
char mapbuf[256];
while (fgets(mapbuf, sizeof mapbuf, fp)) {
while (fgets(mapbuf, sizeof(mapbuf), fp)) {
char flags[8];
unsigned int dev_major, dev_minor;
int cur;
sscanf(mapbuf, "%*s %s %*x %x:%x %lu%n", flags, &dev_major, &dev_minor, inode, &cur);
while (mapbuf[cur] != '\n') cur++;
sscanf(mapbuf, "%*s %s %*x %x:%x %lu %*s%n", flags, &dev_major, &dev_minor, inode, &cur);
if (memcmp(&mapbuf[cur - 12], "libbinder.so", 12) == 0 && flags[2] == 'x') {
*dev = makedev(dev_major, dev_minor);
fclose(fp);
Expand All @@ -140,7 +139,7 @@ class Sigringe : public zygisk::ModuleBase {
if (size <= 0) {
LOGD("ERROR: detach.bin <= 0");
return 0;
} else if (size > DETACH_CAP - 1) { // -1 because for the null terminator
} else if (size > DETACH_CAP - 1) { // -1 because of the null terminator
LOGD("ERROR: detach.bin > %d", DETACH_CAP - 1);
return 0;
}
Expand Down
21 changes: 11 additions & 10 deletions zygisk/jni/parcel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ char16_t* FakeParcel::readString16(uint32_t len) {
return s;
}

bool FakeParcel::enforceInterfaceIntent() {
readInt32();
readInt32();
uint32_t len = readInt32();
readString16(len); // pi;
readInt32();
return PM_DESCRIPTOR_LEN == len;
// return String16Eq(PM_DESCRIPTOR, PM_DESCRIPTOR_LEN, pi, len);
}
// bool FakeParcel::enforceInterfaceIntent() {
// readInt32();
// readInt32();
// uint32_t len = readInt32();
// readString16(len); // pi;
// readInt32();
// return PM_DESCRIPTOR_LEN == len;
// // return String16Eq(PM_DESCRIPTOR, PM_DESCRIPTOR_LEN, pi, len);
// }

bool FakeParcel::enforceInterfaceInfo() {
readInt32();
Expand All @@ -45,12 +45,13 @@ bool FakeParcel::enforceInterfaceInfo() {
uint32_t len = readInt32();
readString16(len); // pi;
return PM_DESCRIPTOR_LEN == len;
// return String16Eq(len == PM_DESCRIPTOR_LEN && !memcmp(pi, PM_DESCRIPTOR, len * sizeof(char16_t)));
// return String16Eq(PM_DESCRIPTOR, PM_DESCRIPTOR_LEN, pi, len);
}

bool FakeParcel::enforceInterface(uint32_t code) {
switch (code) {
case 3:
case 9:
case 51:
case 83:
return enforceInterfaceInfo();
Expand Down
2 changes: 1 addition & 1 deletion zygisk/jni/parcel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct FakeParcel {
void skip(size_t skip);
uint32_t readInt32();
char16_t* readString16(uint32_t len);
bool enforceInterfaceIntent();
// bool enforceInterfaceIntent();
bool enforceInterfaceInfo();
bool enforceInterface(uint32_t code);
};

0 comments on commit 647bc1d

Please sign in to comment.