-
-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation for android (maybe using termux) #78
Comments
Anything's possible. :) |
Have it in Android using Termux would be really awesome. |
For the compile step, these diff makes it almost work diff --git a/src/os/mod.rs b/src/os/mod.rs
index 056d44e..374fdbc 100644
--- a/src/os/mod.rs
+++ b/src/os/mod.rs
@@ -1,4 +1,4 @@
-#[cfg(target_os = "linux")]
+#[cfg(any(target_os = "linux", target_os = "android"))]
pub(self) mod linux;
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
diff --git a/src/os/shared.rs b/src/os/shared.rs
index 462f269..bcef6ea 100644
--- a/src/os/shared.rs
+++ b/src/os/shared.rs
@@ -11,7 +11,7 @@ use ::std::time;
use crate::os::errors::GetInterfaceErrorKind;
use signal_hook::iterator::Signals;
-#[cfg(target_os = "linux")]
+#[cfg(any(target_os = "linux", target_os = "android"))]
use crate::os::linux::get_open_sockets;
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
use crate::os::lsof::get_open_sockets;
@@ -245,7 +245,7 @@ fn eperm_message() -> &'static str {
}
#[inline]
-#[cfg(target_os = "linux")]
+#[cfg(any(target_os = "linux", target_os = "android"))]
fn eperm_message() -> &'static str {
r#"
Insufficient permissions to listen on network interface(s). You can work around procfs_diff diff --git a/src/process/mod.rs b/src/process/mod.rs
index 0c30c22..6915316 100644
--- a/src/process/mod.rs
+++ b/src/process/mod.rs
@@ -54,12 +54,12 @@
use super::*;
use crate::from_iter;
-
+use std::convert::TryFrom;
use std::ffi::OsString;
use std::fs;
use std::io::{self, Read};
-#[cfg(unix)]
-use std::os::linux::fs::MetadataExt;
+#[cfg(linux)]
+use std::os::unix::fs::MetadataExt;
use std::path::PathBuf;
use std::str::FromStr;
@@ -90,6 +90,9 @@ impl FakeMedatadataExt for std::fs::Metadata {
}
}
+#[cfg(target_os = "android")]
+use std::os::android::fs::MetadataExt;
+
bitflags! {
/// Kernel flags for a process
///
@@ -179,9 +182,9 @@ bitflags! {
bitflags! {
/// The mode (read/write permissions) for an open file descriptor
pub struct FDPermissions: u32 {
- const READ = libc::S_IRUSR;
- const WRITE = libc::S_IWUSR;
- const EXECUTE = libc::S_IXUSR;
+ const READ = libc::S_IRUSR as u32;
+ const WRITE = libc::S_IWUSR as u32;
+ const EXECUTE = libc::S_IXUSR as u32;
}
}
@@ -760,7 +763,7 @@ impl Process {
let link_os: &OsStr = link.as_ref();
vec.push(FDInfo {
fd,
- mode: md.st_mode() & libc::S_IRWXU,
+ mode: md.st_mode() & u32::try_from(libc::S_IRWXU).unwrap(),
target: expect!(FDTarget::from_str(expect!(link_os.to_str()))),
});
} with these changes it fails in linking:
hacking those lines out makes it compile and have a runtime error as expected, so this should be the last issue regarding compiling. Note: compile command: |
Turns out that the last compile issue was a cross-compilation problem, compiling from termux with the above diffs actually work. |
Wow @sigmaSd - that's wild! If this works, we can probably make a PR to procfs to make the changes there. If for some reason there's an issue with that, we could also use the mac way of getting the proc info with lsof (I'm guessing that would work on android too, but I don't know). |
Currently I don't have a rooted phone to test, and android avd emulator's arm vm is just a slideshow If someone want to test it and have a rooted andorid phone or arm android vm with good pc (you still need root acess https://stackoverflow.com/questions/5095234/how-to-get-root-access-on-android-emulator ) these are the steps: 1- install termux |
Hey @sigmaSd, I tried on my rooted android phone, but unfortunately it only has android 6.0.0. This means that I'm getting an outdated version of termux, which includes rust 1.38, which is not high enough to run bandwhich. :( |
Hi @imsnif , Honestly I don't think this is a priority anyway only because of the fact that it requires root. Note: If someone have a pc with good specs they can just test with an android emulator https://developer.android.com/studio/run/managing-avds (steps: 1) any hardware will do, 2) for the image select an arm based image with Google APIs flag (it can be rooted) 3: get root access https://stackoverflow.com/questions/5095234/how-to-get-root-access-on-android-emulator ) |
Hey @sigmaSd, my old phone died recently and I got a new one, and well... Two things that still aren't working:
I'm hoping to get a chance to look into this further soon, but great work so far!! |
Hi @imsnif , That's nice to see! |
Just to be sure: bandwhich will use |
Is it possible?
The text was updated successfully, but these errors were encountered: