Skip to content

Commit 9860da4

Browse files
committed
mitm: add Developer mode option
1 parent 7fb83bc commit 9860da4

File tree

3 files changed

+49
-21
lines changed

3 files changed

+49
-21
lines changed

src/io_uring.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ pub async fn io_loop(
266266
full_frames: bool,
267267
mitm: bool,
268268
dpi: Option<u16>,
269+
developer_mode: bool,
269270
) -> Result<()> {
270271
info!("{} 🛰️ Starting TCP server...", NAME);
271272
let bind_addr = format!("0.0.0.0:{}", TCP_SERVER_PORT).parse().unwrap();
@@ -347,6 +348,7 @@ pub async fn io_loop(
347348
rx_hu,
348349
rxr_md,
349350
dpi,
351+
developer_mode,
350352
));
351353
from_stream = tokio_uring::spawn(proxy(
352354
ProxyType::MobileDevice,
@@ -356,6 +358,7 @@ pub async fn io_loop(
356358
rx_md,
357359
rxr_hu,
358360
dpi,
361+
developer_mode,
359362
));
360363
} else {
361364
// We need to copy in both directions...

src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,13 @@ struct Args {
9494
#[clap(short, long)]
9595
mitm: bool,
9696

97-
/// Force DPI (experimental)
97+
/// MITM: Force DPI (experimental)
9898
#[clap(long, requires("mitm"))]
9999
dpi: Option<u16>,
100+
101+
/// MITM: Developer mode
102+
#[clap(long, requires("mitm"))]
103+
developer_mode: bool,
100104
}
101105

102106
#[derive(Clone)]
@@ -294,6 +298,7 @@ fn main() {
294298
let full_frames = args.full_frames;
295299
let mitm = args.mitm;
296300
let dpi = args.dpi;
301+
let developer_mode = args.developer_mode;
297302

298303
// build and spawn main tokio runtime
299304
let runtime = Builder::new_multi_thread().enable_all().build().unwrap();
@@ -308,6 +313,7 @@ fn main() {
308313
full_frames,
309314
mitm,
310315
dpi,
316+
developer_mode,
311317
));
312318

313319
info!(

src/mitm.rs

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,11 @@ pub async fn pkt_debug(payload: &[u8]) -> Result<()> {
217217
}
218218

219219
/// packet modification hook
220-
pub async fn pkt_modify_hook(pkt: &mut Packet, new_dpi: u16) -> Result<()> {
220+
pub async fn pkt_modify_hook(
221+
pkt: &mut Packet,
222+
dpi: Option<u16>,
223+
developer_mode: bool,
224+
) -> Result<()> {
221225
if pkt.channel != 0 {
222226
return Ok(());
223227
}
@@ -234,22 +238,38 @@ pub async fn pkt_modify_hook(pkt: &mut Packet, new_dpi: u16) -> Result<()> {
234238
match control.unwrap_or(MESSAGE_UNEXPECTED_MESSAGE) {
235239
MESSAGE_SERVICE_DISCOVERY_RESPONSE => {
236240
let mut msg = ServiceDiscoveryResponse::parse_from_bytes(data)?;
237-
// get previous/original value
238-
let prev_val = msg.services[0].media_sink_service.video_configs[0].density();
239-
// set new value
240-
msg.services[0]
241-
.media_sink_service
242-
.as_mut()
243-
.unwrap()
244-
.video_configs[0]
245-
.set_density(new_dpi.into());
246-
info!(
247-
"{} <yellow>{:?}</> Replacing DPI value: from <b>{}</> to <b>{}</>",
248-
NAME,
249-
control.unwrap(),
250-
prev_val,
251-
new_dpi
252-
);
241+
242+
// DPI
243+
if let Some(new_dpi) = dpi {
244+
// get previous/original value
245+
let prev_val = msg.services[0].media_sink_service.video_configs[0].density();
246+
// set new value
247+
msg.services[0]
248+
.media_sink_service
249+
.as_mut()
250+
.unwrap()
251+
.video_configs[0]
252+
.set_density(new_dpi.into());
253+
info!(
254+
"{} <yellow>{:?}</>: replacing DPI value: from <b>{}</> to <b>{}</>",
255+
NAME,
256+
control.unwrap(),
257+
prev_val,
258+
new_dpi
259+
);
260+
}
261+
262+
// enabling developer mode
263+
if developer_mode {
264+
msg.set_make("Google".into());
265+
msg.set_model("Desktop Head Unit".into());
266+
info!(
267+
"{} <yellow>{:?}</>: enabling developer mode",
268+
NAME,
269+
control.unwrap(),
270+
);
271+
}
272+
253273
// rewrite payload to new message contents
254274
pkt.payload = msg.write_to_bytes()?;
255275
// inserting 2 bytes of message_id at the beginning
@@ -390,6 +410,7 @@ pub async fn proxy<A: Endpoint<A> + 'static>(
390410
mut rx: Receiver<Packet>,
391411
mut rxr: Receiver<Packet>,
392412
dpi: Option<u16>,
413+
developer_mode: bool,
393414
) -> Result<()> {
394415
let ssl = ssl_builder(proxy_type).await?;
395416

@@ -463,9 +484,7 @@ pub async fn proxy<A: Endpoint<A> + 'static>(
463484
loop {
464485
// handling data from opposite device's thread, which needs to be transmitted
465486
if let Ok(mut pkt) = rx.try_recv() {
466-
if let Some(dpi) = dpi {
467-
pkt_modify_hook(&mut pkt, dpi).await?;
468-
}
487+
pkt_modify_hook(&mut pkt, dpi, developer_mode).await?;
469488
pkt.encrypt_payload(&mut mem_buf, &mut server).await?;
470489
pkt.transmit(&mut device).await?;
471490

0 commit comments

Comments
 (0)