mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-07-27 17:38:10 -07:00
uz801: cargo fmt run
This commit is contained in:
+1
-1
@@ -243,7 +243,7 @@ async fn run_with_config(
|
|||||||
Device::Tmobile => display::tmobile::update_ui,
|
Device::Tmobile => display::tmobile::update_ui,
|
||||||
Device::Wingtech => display::wingtech::update_ui,
|
Device::Wingtech => display::wingtech::update_ui,
|
||||||
Device::Pinephone => display::headless::update_ui,
|
Device::Pinephone => display::headless::update_ui,
|
||||||
Device::Uz801 => display::uz801::update_ui
|
Device::Uz801 => display::uz801::update_ui,
|
||||||
};
|
};
|
||||||
update_ui(&task_tracker, &config, ui_shutdown_rx, ui_update_rx);
|
update_ui(&task_tracker, &config, ui_shutdown_rx, ui_update_rx);
|
||||||
|
|
||||||
|
|||||||
+21
-9
@@ -49,7 +49,7 @@ impl DiskStats {
|
|||||||
}
|
}
|
||||||
df_cmd.arg(qmdl_path);
|
df_cmd.arg(qmdl_path);
|
||||||
let stdout = get_cmd_output(df_cmd).await?;
|
let stdout = get_cmd_output(df_cmd).await?;
|
||||||
|
|
||||||
if matches!(device, Device::Uz801) {
|
if matches!(device, Device::Uz801) {
|
||||||
// Handle Uz801 format:
|
// Handle Uz801 format:
|
||||||
// Filesystem Size Used Free Blksize
|
// Filesystem Size Used Free Blksize
|
||||||
@@ -61,10 +61,22 @@ impl DiskStats {
|
|||||||
let data_line = lines[1];
|
let data_line = lines[1];
|
||||||
let mut parts = data_line.split_whitespace();
|
let mut parts = data_line.split_whitespace();
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
partition: parts.next().ok_or("error parsing df output: missing filesystem")?.to_string(),
|
partition: parts
|
||||||
total_size: parts.next().ok_or("error parsing df output: missing size")?.to_string(),
|
.next()
|
||||||
used_size: parts.next().ok_or("error parsing df output: missing used")?.to_string(),
|
.ok_or("error parsing df output: missing filesystem")?
|
||||||
available_size: parts.next().ok_or("error parsing df output: missing free")?.to_string(),
|
.to_string(),
|
||||||
|
total_size: parts
|
||||||
|
.next()
|
||||||
|
.ok_or("error parsing df output: missing size")?
|
||||||
|
.to_string(),
|
||||||
|
used_size: parts
|
||||||
|
.next()
|
||||||
|
.ok_or("error parsing df output: missing used")?
|
||||||
|
.to_string(),
|
||||||
|
available_size: parts
|
||||||
|
.next()
|
||||||
|
.ok_or("error parsing df output: missing free")?
|
||||||
|
.to_string(),
|
||||||
used_percent: "N/A".to_string(), // Uz801 df doesn't provide percentage
|
used_percent: "N/A".to_string(), // Uz801 df doesn't provide percentage
|
||||||
mounted_on: qmdl_path.to_string(), // Use the path we queried
|
mounted_on: qmdl_path.to_string(), // Use the path we queried
|
||||||
})
|
})
|
||||||
@@ -116,10 +128,10 @@ impl MemoryStats {
|
|||||||
let meminfo_content = tokio::fs::read_to_string("/proc/meminfo")
|
let meminfo_content = tokio::fs::read_to_string("/proc/meminfo")
|
||||||
.await
|
.await
|
||||||
.map_err(|e| format!("error reading /proc/meminfo: {}", e))?;
|
.map_err(|e| format!("error reading /proc/meminfo: {}", e))?;
|
||||||
|
|
||||||
let mut mem_total_kb = None;
|
let mut mem_total_kb = None;
|
||||||
let mut mem_free_kb = None;
|
let mut mem_free_kb = None;
|
||||||
|
|
||||||
for line in meminfo_content.lines() {
|
for line in meminfo_content.lines() {
|
||||||
if let Some(value_str) = line.strip_prefix("MemTotal:") {
|
if let Some(value_str) = line.strip_prefix("MemTotal:") {
|
||||||
if let Some(kb_str) = value_str.trim().strip_suffix(" kB") {
|
if let Some(kb_str) = value_str.trim().strip_suffix(" kB") {
|
||||||
@@ -131,11 +143,11 @@ impl MemoryStats {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let total = mem_total_kb.ok_or("error parsing MemTotal from /proc/meminfo")?;
|
let total = mem_total_kb.ok_or("error parsing MemTotal from /proc/meminfo")?;
|
||||||
let free = mem_free_kb.ok_or("error parsing MemFree from /proc/meminfo")?;
|
let free = mem_free_kb.ok_or("error parsing MemFree from /proc/meminfo")?;
|
||||||
let used = total - free;
|
let used = total - free;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
total: humanize_kb(total),
|
total: humanize_kb(total),
|
||||||
used: humanize_kb(used),
|
used: humanize_kb(used),
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ mod orbic;
|
|||||||
mod pinephone;
|
mod pinephone;
|
||||||
mod tmobile;
|
mod tmobile;
|
||||||
mod tplink;
|
mod tplink;
|
||||||
mod uz801;
|
|
||||||
mod util;
|
mod util;
|
||||||
|
mod uz801;
|
||||||
mod wingtech;
|
mod wingtech;
|
||||||
|
|
||||||
pub static CONFIG_TOML: &str = include_str!("../../dist/config.toml.in");
|
pub static CONFIG_TOML: &str = include_str!("../../dist/config.toml.in");
|
||||||
|
|||||||
+43
-34
@@ -7,10 +7,10 @@
|
|||||||
/// 4. Modify startup script to launch rayhunter on boot
|
/// 4. Modify startup script to launch rayhunter on boot
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::Result;
|
|
||||||
use tokio::time::sleep;
|
|
||||||
use adb_client::{ADBDeviceExt, ADBUSBDevice, RustADBError};
|
use adb_client::{ADBDeviceExt, ADBUSBDevice, RustADBError};
|
||||||
|
use anyhow::Result;
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
|
use tokio::time::sleep;
|
||||||
|
|
||||||
use crate::Uz801Args as Args;
|
use crate::Uz801Args as Args;
|
||||||
use crate::util::echo;
|
use crate::util::echo;
|
||||||
@@ -57,27 +57,28 @@ pub async fn activate_usb_debug(admin_ip: &str) -> Result<()> {
|
|||||||
let url = format!("http://{}/usbdebug.html", admin_ip);
|
let url = format!("http://{}/usbdebug.html", admin_ip);
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let response = client.get(&url).send().await?;
|
let response = client.get(&url).send().await?;
|
||||||
|
|
||||||
if !response.status().is_success() {
|
if !response.status().is_success() {
|
||||||
anyhow::bail!("Failed to activate USB debug: HTTP {}", response.status());
|
anyhow::bail!("Failed to activate USB debug: HTTP {}", response.status());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn wait_for_adb() -> Result<ADBUSBDevice> {
|
async fn wait_for_adb() -> Result<ADBUSBDevice> {
|
||||||
const MAX_ATTEMPTS: u32 = 30; // 30 seconds
|
const MAX_ATTEMPTS: u32 = 30; // 30 seconds
|
||||||
let mut attempts = 0;
|
let mut attempts = 0;
|
||||||
|
|
||||||
// Wait a bit for the reboot to start
|
// Wait a bit for the reboot to start
|
||||||
sleep(Duration::from_secs(5)).await;
|
sleep(Duration::from_secs(5)).await;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if attempts >= MAX_ATTEMPTS {
|
if attempts >= MAX_ATTEMPTS {
|
||||||
anyhow::bail!("Timeout waiting for ADB connection after USB debug activation");
|
anyhow::bail!("Timeout waiting for ADB connection after USB debug activation");
|
||||||
}
|
}
|
||||||
|
|
||||||
match ADBUSBDevice::new(0x05c6, 0x9025) { // Common Qualcomm ADB VID/PID
|
match ADBUSBDevice::new(0x05c6, 0x9025) {
|
||||||
|
// Common Qualcomm ADB VID/PID
|
||||||
Ok(mut device) => {
|
Ok(mut device) => {
|
||||||
// Test ADB connection
|
// Test ADB connection
|
||||||
if test_adb_connection(&mut device).await.is_ok() {
|
if test_adb_connection(&mut device).await.is_ok() {
|
||||||
@@ -91,7 +92,7 @@ async fn wait_for_adb() -> Result<ADBUSBDevice> {
|
|||||||
anyhow::bail!("ADB connection error: {}", e);
|
anyhow::bail!("ADB connection error: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep(Duration::from_secs(1)).await;
|
sleep(Duration::from_secs(1)).await;
|
||||||
attempts += 1;
|
attempts += 1;
|
||||||
}
|
}
|
||||||
@@ -112,22 +113,24 @@ async fn install_rayhunter_files(adb_device: &mut ADBUSBDevice) -> Result<()> {
|
|||||||
// Create rayhunter directory
|
// Create rayhunter directory
|
||||||
let mut buf = Vec::<u8>::new();
|
let mut buf = Vec::<u8>::new();
|
||||||
adb_device.shell_command(&["mkdir", "-p", "/data/rayhunter"], &mut buf)?;
|
adb_device.shell_command(&["mkdir", "-p", "/data/rayhunter"], &mut buf)?;
|
||||||
|
|
||||||
// Install rayhunter daemon binary
|
// Install rayhunter daemon binary
|
||||||
let rayhunter_daemon_bin = include_bytes!(env!("FILE_RAYHUNTER_DAEMON"));
|
let rayhunter_daemon_bin = include_bytes!(env!("FILE_RAYHUNTER_DAEMON"));
|
||||||
let mut daemon_data = rayhunter_daemon_bin.as_slice();
|
let mut daemon_data = rayhunter_daemon_bin.as_slice();
|
||||||
adb_device.push(&mut daemon_data, &"/data/rayhunter/rayhunter-daemon")?;
|
adb_device.push(&mut daemon_data, &"/data/rayhunter/rayhunter-daemon")?;
|
||||||
|
|
||||||
// Install config file
|
// Install config file
|
||||||
let config_content = crate::CONFIG_TOML
|
let config_content = crate::CONFIG_TOML.replace("#device = \"orbic\"", "device = \"uz801\"");
|
||||||
.replace("#device = \"orbic\"", "device = \"uz801\"");
|
|
||||||
let mut config_data = config_content.as_bytes();
|
let mut config_data = config_content.as_bytes();
|
||||||
adb_device.push(&mut config_data, &"/data/rayhunter/config.toml")?;
|
adb_device.push(&mut config_data, &"/data/rayhunter/config.toml")?;
|
||||||
|
|
||||||
// Make daemon executable
|
// Make daemon executable
|
||||||
let mut buf = Vec::<u8>::new();
|
let mut buf = Vec::<u8>::new();
|
||||||
adb_device.shell_command(&["chmod", "755", "/data/rayhunter/rayhunter-daemon"], &mut buf)?;
|
adb_device.shell_command(
|
||||||
|
&["chmod", "755", "/data/rayhunter/rayhunter-daemon"],
|
||||||
|
&mut buf,
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,50 +138,56 @@ async fn modify_startup_script(adb_device: &mut ADBUSBDevice) -> Result<()> {
|
|||||||
// Pull the existing startup script
|
// Pull the existing startup script
|
||||||
let mut script_content = Vec::<u8>::new();
|
let mut script_content = Vec::<u8>::new();
|
||||||
adb_device.pull(&"/system/bin/initmifiservice.sh", &mut script_content)?;
|
adb_device.pull(&"/system/bin/initmifiservice.sh", &mut script_content)?;
|
||||||
|
|
||||||
// Convert to string and add our line
|
// Convert to string and add our line
|
||||||
let mut script_str = String::from_utf8_lossy(&script_content).into_owned();
|
let mut script_str = String::from_utf8_lossy(&script_content).into_owned();
|
||||||
|
|
||||||
// Add rayhunter startup line if not already present
|
// Add rayhunter startup line if not already present
|
||||||
let rayhunter_line = "/data/rayhunter/rayhunter-daemon /data/rayhunter/config.toml &\n";
|
let rayhunter_line = "/data/rayhunter/rayhunter-daemon /data/rayhunter/config.toml &\n";
|
||||||
if !script_str.contains("/data/rayhunter/rayhunter-daemon") {
|
if !script_str.contains("/data/rayhunter/rayhunter-daemon") {
|
||||||
script_str.push_str(rayhunter_line);
|
script_str.push_str(rayhunter_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push the modified script back
|
// Push the modified script back
|
||||||
let mut modified_script = script_str.as_bytes();
|
let mut modified_script = script_str.as_bytes();
|
||||||
adb_device.push(&mut modified_script, &"/system/bin/initmifiservice.sh")?;
|
adb_device.push(&mut modified_script, &"/system/bin/initmifiservice.sh")?;
|
||||||
|
|
||||||
// Make sure it's executable
|
// Make sure it's executable
|
||||||
let mut buf = Vec::<u8>::new();
|
let mut buf = Vec::<u8>::new();
|
||||||
adb_device.shell_command(&["chmod", "755", "/system/bin/initmifiservice.sh"], &mut buf)?;
|
adb_device.shell_command(
|
||||||
|
&["chmod", "755", "/system/bin/initmifiservice.sh"],
|
||||||
|
&mut buf,
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn start_rayhunter(adb_device: &mut ADBUSBDevice) -> Result<()> {
|
async fn start_rayhunter(adb_device: &mut ADBUSBDevice) -> Result<()> {
|
||||||
let mut buf = Vec::<u8>::new();
|
let mut buf = Vec::<u8>::new();
|
||||||
adb_device.shell_command(&[
|
adb_device.shell_command(
|
||||||
"/data/rayhunter/rayhunter-daemon",
|
&[
|
||||||
"/data/rayhunter/config.toml",
|
"/data/rayhunter/rayhunter-daemon",
|
||||||
"&"
|
"/data/rayhunter/config.toml",
|
||||||
], &mut buf)?;
|
"&",
|
||||||
|
],
|
||||||
|
&mut buf,
|
||||||
|
)?;
|
||||||
|
|
||||||
// Give it a moment to start
|
// Give it a moment to start
|
||||||
sleep(Duration::from_secs(3)).await;
|
sleep(Duration::from_secs(3)).await;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn test_rayhunter(admin_ip: &str) -> Result<()> {
|
async fn test_rayhunter(admin_ip: &str) -> Result<()> {
|
||||||
const MAX_FAILURES: u32 = 10;
|
const MAX_FAILURES: u32 = 10;
|
||||||
let mut failures = 0;
|
let mut failures = 0;
|
||||||
|
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
|
|
||||||
while failures < MAX_FAILURES {
|
while failures < MAX_FAILURES {
|
||||||
let url = format!("http://{}:8080/index.html", admin_ip);
|
let url = format!("http://{}:8080/index.html", admin_ip);
|
||||||
|
|
||||||
if let Ok(response) = client.get(&url).send().await {
|
if let Ok(response) = client.get(&url).send().await {
|
||||||
if response.status().is_success() {
|
if response.status().is_success() {
|
||||||
if let Ok(body) = response.text().await {
|
if let Ok(body) = response.text().await {
|
||||||
@@ -188,10 +197,10 @@ async fn test_rayhunter(admin_ip: &str) -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
failures += 1;
|
failures += 1;
|
||||||
sleep(Duration::from_secs(3)).await;
|
sleep(Duration::from_secs(3)).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
anyhow::bail!("timeout reached! failed to reach rayhunter, something went wrong :(")
|
anyhow::bail!("timeout reached! failed to reach rayhunter, something went wrong :(")
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -25,5 +25,5 @@ pub enum Device {
|
|||||||
Tmobile,
|
Tmobile,
|
||||||
Wingtech,
|
Wingtech,
|
||||||
Pinephone,
|
Pinephone,
|
||||||
Uz801
|
Uz801,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user