Skip to content

Commit 23f8be2

Browse files
committed
mitm: add remove tap restriction feature
1 parent d056cc6 commit 23f8be2

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Currently it is intended to run as a more-or-less drop-in replacement of the `aa
1212
- stall transfer detection
1313
- MITM (man-in-the-middle) mode support with the following features:
1414
- DPI change
15+
- Remove tap restriction
1516
- Disable media sink
1617
- Disable TTS sink
1718
- Developer mode
@@ -189,6 +190,9 @@ OPTIONS:
189190
-m, --mitm
190191
Enable MITM mode (experimental)
191192
193+
--remove-tap-restriction
194+
MITM: remove tap restriction
195+
192196
-s, --stats-interval <SECONDS>
193197
Interval of showing data transfer statistics (0 = disabled) [default: 0]
194198

src/io_uring.rs

+3
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ pub async fn io_loop(
269269
developer_mode: bool,
270270
disable_media_sink: bool,
271271
disable_tts_sink: bool,
272+
remove_tap_restriction: bool,
272273
) -> Result<()> {
273274
info!("{} 🛰️ Starting TCP server...", NAME);
274275
let bind_addr = format!("0.0.0.0:{}", TCP_SERVER_PORT).parse().unwrap();
@@ -353,6 +354,7 @@ pub async fn io_loop(
353354
developer_mode,
354355
disable_media_sink,
355356
disable_tts_sink,
357+
remove_tap_restriction,
356358
));
357359
from_stream = tokio_uring::spawn(proxy(
358360
ProxyType::MobileDevice,
@@ -365,6 +367,7 @@ pub async fn io_loop(
365367
developer_mode,
366368
disable_media_sink,
367369
disable_tts_sink,
370+
remove_tap_restriction,
368371
));
369372
} else {
370373
// We need to copy in both directions...

src/main.rs

+6
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ struct Args {
9898
#[clap(long, requires("mitm"))]
9999
dpi: Option<u16>,
100100

101+
/// MITM: remove tap restriction
102+
#[clap(long, requires("mitm"))]
103+
remove_tap_restriction: bool,
104+
101105
/// MITM: Disable media sink
102106
#[clap(long, requires("mitm"))]
103107
disable_media_sink: bool,
@@ -309,6 +313,7 @@ fn main() {
309313
let developer_mode = args.developer_mode;
310314
let disable_media_sink = args.disable_media_sink;
311315
let disable_tts_sink = args.disable_tts_sink;
316+
let remove_tap_restriction = args.remove_tap_restriction;
312317

313318
// build and spawn main tokio runtime
314319
let runtime = Builder::new_multi_thread().enable_all().build().unwrap();
@@ -326,6 +331,7 @@ fn main() {
326331
developer_mode,
327332
disable_media_sink,
328333
disable_tts_sink,
334+
remove_tap_restriction,
329335
));
330336

331337
info!(

src/mitm.rs

+19
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use tokio_uring::buf::BoundedBuf;
1717
include!(concat!(env!("OUT_DIR"), "/protos/mod.rs"));
1818
use crate::mitm::protos::*;
1919
use crate::mitm::AudioStreamType::*;
20+
use crate::mitm::SensorType::*;
2021
use protobuf::text_format::print_to_string_pretty;
2122
use protobuf::{Enum, Message, MessageDyn};
2223
use protos::ControlMessageType::{self, *};
@@ -244,6 +245,7 @@ pub async fn pkt_modify_hook(
244245
developer_mode: bool,
245246
disable_media_sink: bool,
246247
disable_tts_sink: bool,
248+
remove_tap_restriction: bool,
247249
) -> Result<()> {
248250
if pkt.channel != 0 {
249251
return Ok(());
@@ -311,6 +313,21 @@ pub async fn pkt_modify_hook(
311313
);
312314
}
313315

316+
// remove tap restriction by removing SENSOR_SPEED
317+
if remove_tap_restriction {
318+
if let Some(svc) = msg
319+
.services
320+
.iter_mut()
321+
.find(|svc| !svc.sensor_source_service.sensors.is_empty())
322+
{
323+
svc.sensor_source_service
324+
.as_mut()
325+
.unwrap()
326+
.sensors
327+
.retain(|s| s.sensor_type() != SENSOR_SPEED);
328+
}
329+
}
330+
314331
// enabling developer mode
315332
if developer_mode {
316333
msg.set_make("Google".into());
@@ -465,6 +482,7 @@ pub async fn proxy<A: Endpoint<A> + 'static>(
465482
developer_mode: bool,
466483
disable_media_sink: bool,
467484
disable_tts_sink: bool,
485+
remove_tap_restriction: bool,
468486
) -> Result<()> {
469487
let ssl = ssl_builder(proxy_type).await?;
470488

@@ -545,6 +563,7 @@ pub async fn proxy<A: Endpoint<A> + 'static>(
545563
developer_mode,
546564
disable_media_sink,
547565
disable_tts_sink,
566+
remove_tap_restriction,
548567
)
549568
.await?;
550569
pkt.encrypt_payload(&mut mem_buf, &mut server).await?;

0 commit comments

Comments
 (0)