show injection status

This commit is contained in:
5ec1cff
2023-12-12 00:43:30 +08:00
parent 993b18752b
commit db60c3185e
5 changed files with 54 additions and 20 deletions

View File

@@ -25,6 +25,7 @@ pub const PATH_CP_BIN32: &str = "bin/zygisk-cp32";
pub const PATH_CP_BIN64: &str = "bin/zygisk-cp64";
pub const PATH_PT_BIN32: &str = "bin/zygisk-ptracer32";
pub const PATH_PT_BIN64: &str = "bin/zygisk-ptracer64";
pub const ZYGOTE_INJECTED: i32 = lp_select!(5, 4);
pub const MAX_RESTART_COUNT: i32 = 5;

View File

@@ -2,10 +2,12 @@ use anyhow::Result;
use std::{fs, io::{Read, Write}, os::unix::net::UnixStream};
use std::ffi::{c_char, c_void, CStr, CString};
use std::os::fd::{AsFd, AsRawFd};
use std::os::unix::net::UnixListener;
use std::os::unix::net::{UnixDatagram, UnixListener};
use std::process::Command;
use std::sync::OnceLock;
use rustix::net::{AddressFamily, bind_unix, listen, socket, SocketAddrUnix, SocketType};
use bitflags::Flags;
use rustix::net::{AddressFamily, bind_unix, connect_unix, listen, SendFlags, sendto_unix, socket, SocketAddrUnix, SocketType};
use rustix::path::Arg;
use rustix::thread::gettid;
#[cfg(target_pointer_width = "64")]
@@ -63,6 +65,11 @@ pub fn set_socket_create_context(context: &str) -> Result<()> {
}
}
pub fn get_current_attr() -> Result<String> {
let s = fs::read("/proc/self/attr/current")?;
Ok(s.to_string_lossy().to_string())
}
pub fn chcon(path: &str, context: &str) -> Result<()> {
Command::new("chcon").arg(context).arg(path).status()?;
Ok(())
@@ -195,6 +202,14 @@ pub fn unix_listener_from_path(path: &str) -> Result<UnixListener> {
Ok(UnixListener::from(socket))
}
pub fn unix_datagram_sendto_abstract(path: &str, buf: &[u8]) -> Result<()> {
let addr = SocketAddrUnix::new_abstract_name(path.as_bytes())?;
let socket = socket(AddressFamily::UNIX, SocketType::DGRAM, None)?;
connect_unix(&socket, &addr)?;
sendto_unix(socket, buf, SendFlags::empty(), &addr)?;
Ok(())
}
pub fn check_unix_socket(stream: &UnixStream, block: bool) -> bool {
unsafe {
let mut pfd = libc::pollfd {

View File

@@ -50,7 +50,13 @@ pub fn main() -> Result<()> {
log::trace!("New daemon action {:?}", action);
match action {
DaemonSocketAction::PingHeartbeat => {
// Do nothing
utils::set_socket_create_context(utils::get_current_attr()?.as_str())?;
let magic_path = std::env::var("MAGIC")?;
let socket_path = format!("init_monitor{}", magic_path);
log::info!("socket path {}", socket_path);
let value = constants::ZYGOTE_INJECTED;
utils::unix_datagram_sendto_abstract(socket_path.as_str(), &value.to_le_bytes())?;
utils::set_socket_create_context("u:r:zygote:s0")?;
}
DaemonSocketAction::ZygoteRestart => {
info!("Zygote restarted, clean up companions");