uz801: cargo fmt run

This commit is contained in:
Andrej
2025-08-02 21:03:28 -04:00
parent 6473c05e3e
commit 7a053a4f89
5 changed files with 67 additions and 46 deletions

View File

@@ -6,8 +6,8 @@ mod orbic;
mod pinephone;
mod tmobile;
mod tplink;
mod uz801;
mod util;
mod uz801;
mod wingtech;
pub static CONFIG_TOML: &str = include_str!("../../dist/config.toml.in");

View File

@@ -7,10 +7,10 @@
/// 4. Modify startup script to launch rayhunter on boot
use std::time::Duration;
use anyhow::Result;
use tokio::time::sleep;
use adb_client::{ADBDeviceExt, ADBUSBDevice, RustADBError};
use anyhow::Result;
use std::io::ErrorKind;
use tokio::time::sleep;
use crate::Uz801Args as Args;
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 client = reqwest::Client::new();
let response = client.get(&url).send().await?;
if !response.status().is_success() {
anyhow::bail!("Failed to activate USB debug: HTTP {}", response.status());
}
Ok(())
}
async fn wait_for_adb() -> Result<ADBUSBDevice> {
const MAX_ATTEMPTS: u32 = 30; // 30 seconds
let mut attempts = 0;
// Wait a bit for the reboot to start
sleep(Duration::from_secs(5)).await;
loop {
if attempts >= MAX_ATTEMPTS {
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) => {
// Test ADB connection
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);
}
}
sleep(Duration::from_secs(1)).await;
attempts += 1;
}
@@ -112,22 +113,24 @@ async fn install_rayhunter_files(adb_device: &mut ADBUSBDevice) -> Result<()> {
// Create rayhunter directory
let mut buf = Vec::<u8>::new();
adb_device.shell_command(&["mkdir", "-p", "/data/rayhunter"], &mut buf)?;
// Install rayhunter daemon binary
let rayhunter_daemon_bin = include_bytes!(env!("FILE_RAYHUNTER_DAEMON"));
let mut daemon_data = rayhunter_daemon_bin.as_slice();
adb_device.push(&mut daemon_data, &"/data/rayhunter/rayhunter-daemon")?;
// Install config file
let config_content = crate::CONFIG_TOML
.replace("#device = \"orbic\"", "device = \"uz801\"");
let config_content = crate::CONFIG_TOML.replace("#device = \"orbic\"", "device = \"uz801\"");
let mut config_data = config_content.as_bytes();
adb_device.push(&mut config_data, &"/data/rayhunter/config.toml")?;
// Make daemon executable
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(())
}
@@ -135,50 +138,56 @@ async fn modify_startup_script(adb_device: &mut ADBUSBDevice) -> Result<()> {
// Pull the existing startup script
let mut script_content = Vec::<u8>::new();
adb_device.pull(&"/system/bin/initmifiservice.sh", &mut script_content)?;
// Convert to string and add our line
let mut script_str = String::from_utf8_lossy(&script_content).into_owned();
// Add rayhunter startup line if not already present
let rayhunter_line = "/data/rayhunter/rayhunter-daemon /data/rayhunter/config.toml &\n";
if !script_str.contains("/data/rayhunter/rayhunter-daemon") {
script_str.push_str(rayhunter_line);
}
// Push the modified script back
let mut modified_script = script_str.as_bytes();
adb_device.push(&mut modified_script, &"/system/bin/initmifiservice.sh")?;
// Make sure it's executable
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(())
}
async fn start_rayhunter(adb_device: &mut ADBUSBDevice) -> Result<()> {
let mut buf = Vec::<u8>::new();
adb_device.shell_command(&[
"/data/rayhunter/rayhunter-daemon",
"/data/rayhunter/config.toml",
"&"
], &mut buf)?;
adb_device.shell_command(
&[
"/data/rayhunter/rayhunter-daemon",
"/data/rayhunter/config.toml",
"&",
],
&mut buf,
)?;
// Give it a moment to start
sleep(Duration::from_secs(3)).await;
Ok(())
}
async fn test_rayhunter(admin_ip: &str) -> Result<()> {
const MAX_FAILURES: u32 = 10;
let mut failures = 0;
let client = reqwest::Client::new();
while failures < MAX_FAILURES {
let url = format!("http://{}:8080/index.html", admin_ip);
if let Ok(response) = client.get(&url).send().await {
if response.status().is_success() {
if let Ok(body) = response.text().await {
@@ -188,10 +197,10 @@ async fn test_rayhunter(admin_ip: &str) -> Result<()> {
}
}
}
failures += 1;
sleep(Duration::from_secs(3)).await;
}
anyhow::bail!("timeout reached! failed to reach rayhunter, something went wrong :(")
}