diff --git a/native/src/core/daemon.cpp b/native/src/core/daemon.cpp index 0e1b39379..937a35e6f 100644 --- a/native/src/core/daemon.cpp +++ b/native/src/core/daemon.cpp @@ -151,7 +151,7 @@ bool get_client_cred(int fd, sock_cred *cred) { bool read_string(int fd, std::string &str) { str.clear(); - auto len = read_any(fd); + int len = read_int(fd); str.resize(len); return xxread(fd, str.data(), len) == len; } @@ -164,7 +164,7 @@ string read_string(int fd) { void write_string(int fd, string_view str) { if (fd < 0) return; - write_any(fd, str.size()); + write_int(fd, str.size()); xwrite(fd, str.data(), str.size()); } diff --git a/native/src/core/include/core.hpp b/native/src/core/include/core.hpp index f164cefdd..b6d90ff53 100644 --- a/native/src/core/include/core.hpp +++ b/native/src/core/include/core.hpp @@ -59,19 +59,6 @@ void write_any(int fd, T val) { xwrite(fd, &val, sizeof(val)); } -template requires(std::is_trivially_copyable_v) -void write_vector(int fd, const std::vector &vec) { - write_any(fd, vec.size()); - xwrite(fd, vec.data(), vec.size() * sizeof(T)); -} - -template requires(std::is_trivially_copyable_v) -bool read_vector(int fd, std::vector &vec) { - auto size = read_any(fd); - vec.resize(size); - return xread(fd, vec.data(), size * sizeof(T)) == size * sizeof(T); -} - bool get_client_cred(int fd, sock_cred *cred); static inline int read_int(int fd) { return read_any(fd); } static inline void write_int(int fd, int val) { write_any(fd, val); } @@ -79,6 +66,19 @@ std::string read_string(int fd); bool read_string(int fd, std::string &str); void write_string(int fd, std::string_view str); +template requires(std::is_trivially_copyable_v) +void write_vector(int fd, const std::vector &vec) { + write_int(fd, vec.size()); + xwrite(fd, vec.data(), vec.size() * sizeof(T)); +} + +template requires(std::is_trivially_copyable_v) +bool read_vector(int fd, std::vector &vec) { + int size = read_int(fd); + vec.resize(size); + return xread(fd, vec.data(), size * sizeof(T)) == size * sizeof(T); +} + // Poll control using poll_callback = void(*)(pollfd*); void register_poll(const pollfd *pfd, poll_callback callback); diff --git a/native/src/core/socket.rs b/native/src/core/socket.rs index 06b339578..98eff6911 100644 --- a/native/src/core/socket.rs +++ b/native/src/core/socket.rs @@ -65,19 +65,19 @@ impl Decodable for bool { impl Encodable for Vec { fn encoded_len(&self) -> usize { - size_of::() + size_of::() * self.len() + size_of::() + size_of::() * self.len() } fn encode(&self, w: &mut impl Write) -> io::Result<()> { - self.len().encode(w)?; + (self.len() as i32).encode(w)?; self.iter().try_for_each(|e| e.encode(w)) } } impl Decodable for Vec { fn decode(r: &mut impl Read) -> io::Result { - let len = usize::decode(r)?; - let mut val = Vec::with_capacity(len); + let len = i32::decode(r)?; + let mut val = Vec::with_capacity(len as usize); for _ in 0..len { val.push(T::decode(r)?); } @@ -87,11 +87,11 @@ impl Decodable for Vec { impl Encodable for str { fn encoded_len(&self) -> usize { - size_of::() + self.len() + size_of::() + self.len() } fn encode(&self, w: &mut impl Write) -> io::Result<()> { - self.len().encode(w)?; + (self.len() as i32).encode(w)?; w.write_all(self.as_bytes()) } } @@ -108,10 +108,9 @@ impl Encodable for String { impl Decodable for String { fn decode(r: &mut impl Read) -> io::Result { - let len = usize::decode(r)?; - let mut val = String::with_capacity(len); - let mut r = r.take(len as u64); - r.read_to_string(&mut val)?; + let len = i32::decode(r)?; + let mut val = String::with_capacity(len as usize); + r.take(len as u64).read_to_string(&mut val)?; Ok(val) } } diff --git a/native/src/core/zygisk/daemon.rs b/native/src/core/zygisk/daemon.rs index 36de82772..77a99b34a 100644 --- a/native/src/core/zygisk/daemon.rs +++ b/native/src/core/zygisk/daemon.rs @@ -22,6 +22,7 @@ pub fn zygisk_should_load_module(flags: u32) -> bool { flags & UNMOUNT_MASK != UNMOUNT_MASK && flags & ZygiskStateFlags::ProcessIsMagiskApp.repr == 0 } +#[allow(unused_variables)] fn exec_zygiskd(is_64_bit: bool, remote: UnixStream) { // This fd has to survive exec unsafe {