Skip to content

Commit b9ed8e6

Browse files
committed
mitm: implement Disable media sink option
1 parent 9860da4 commit b9ed8e6

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/io_uring.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ pub async fn io_loop(
267267
mitm: bool,
268268
dpi: Option<u16>,
269269
developer_mode: bool,
270+
disable_media_sink: bool,
270271
) -> Result<()> {
271272
info!("{} 🛰️ Starting TCP server...", NAME);
272273
let bind_addr = format!("0.0.0.0:{}", TCP_SERVER_PORT).parse().unwrap();
@@ -349,6 +350,7 @@ pub async fn io_loop(
349350
rxr_md,
350351
dpi,
351352
developer_mode,
353+
disable_media_sink,
352354
));
353355
from_stream = tokio_uring::spawn(proxy(
354356
ProxyType::MobileDevice,
@@ -359,6 +361,7 @@ pub async fn io_loop(
359361
rxr_hu,
360362
dpi,
361363
developer_mode,
364+
disable_media_sink,
362365
));
363366
} else {
364367
// We need to copy in both directions...

src/main.rs

Lines changed: 6 additions & 0 deletions
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: Disable media sink
102+
#[clap(long, requires("mitm"))]
103+
disable_media_sink: bool,
104+
101105
/// MITM: Developer mode
102106
#[clap(long, requires("mitm"))]
103107
developer_mode: bool,
@@ -299,6 +303,7 @@ fn main() {
299303
let mitm = args.mitm;
300304
let dpi = args.dpi;
301305
let developer_mode = args.developer_mode;
306+
let disable_media_sink = args.disable_media_sink;
302307

303308
// build and spawn main tokio runtime
304309
let runtime = Builder::new_multi_thread().enable_all().build().unwrap();
@@ -314,6 +319,7 @@ fn main() {
314319
mitm,
315320
dpi,
316321
developer_mode,
322+
disable_media_sink,
317323
));
318324

319325
info!(

src/mitm.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use tokio_uring::buf::BoundedBuf;
1515
// protobuf stuff:
1616
include!(concat!(env!("OUT_DIR"), "/protos/mod.rs"));
1717
use crate::mitm::protos::*;
18+
use crate::mitm::AudioStreamType::AUDIO_STREAM_MEDIA;
1819
use protobuf::text_format::print_to_string_pretty;
1920
use protobuf::{Enum, Message, MessageDyn};
2021
use protos::ControlMessageType::{self, *};
@@ -221,6 +222,7 @@ pub async fn pkt_modify_hook(
221222
pkt: &mut Packet,
222223
dpi: Option<u16>,
223224
developer_mode: bool,
225+
disable_media_sink: bool,
224226
) -> Result<()> {
225227
if pkt.channel != 0 {
226228
return Ok(());
@@ -259,6 +261,17 @@ pub async fn pkt_modify_hook(
259261
);
260262
}
261263

264+
// disable media sink
265+
if disable_media_sink {
266+
msg.services
267+
.retain(|svc| svc.media_sink_service.audio_type() != AUDIO_STREAM_MEDIA);
268+
info!(
269+
"{} <yellow>{:?}</>: media sink disabled",
270+
NAME,
271+
control.unwrap(),
272+
);
273+
}
274+
262275
// enabling developer mode
263276
if developer_mode {
264277
msg.set_make("Google".into());
@@ -411,6 +424,7 @@ pub async fn proxy<A: Endpoint<A> + 'static>(
411424
mut rxr: Receiver<Packet>,
412425
dpi: Option<u16>,
413426
developer_mode: bool,
427+
disable_media_sink: bool,
414428
) -> Result<()> {
415429
let ssl = ssl_builder(proxy_type).await?;
416430

@@ -484,7 +498,7 @@ pub async fn proxy<A: Endpoint<A> + 'static>(
484498
loop {
485499
// handling data from opposite device's thread, which needs to be transmitted
486500
if let Ok(mut pkt) = rx.try_recv() {
487-
pkt_modify_hook(&mut pkt, dpi, developer_mode).await?;
501+
pkt_modify_hook(&mut pkt, dpi, developer_mode, disable_media_sink).await?;
488502
pkt.encrypt_payload(&mut mem_buf, &mut server).await?;
489503
pkt.transmit(&mut device).await?;
490504

0 commit comments

Comments
 (0)