detect_magic_target/
detect_magic_target.rs1use std::thread::sleep;
2use std::time::Duration;
3
4const MAX_FRAME_LEN: usize = 264;
5const UNLOCK_1: [u8; 1] = [0x40];
6const UNLOCK_2: [u8; 1] = [0x40];
7
8fn main() -> nfc1::Result<()> {
9 let mut context = nfc1::Context::new()?;
10 let mut device = context.open()?;
11 print!("NFC reader: {} opened\n\n", device.name());
12 device.initiator_init()?;
13
14 device.set_property_bool(nfc1::Property::HandleCrc, false)?;
16 device.set_property_bool(nfc1::Property::EasyFraming, false)?;
18 device.set_property_bool(nfc1::Property::AutoIso144434, false)?;
20
21 loop {
22 println!("Looking for targets...\n");
23 match device.initiator_select_passive_target(&nfc1::Modulation{
24 modulation_type: nfc1::ModulationType::Iso14443a,
25 baud_rate: nfc1::BaudRate::Baud106,
26 }) {
27 Ok(target) => {
28 print!("Target found: {}", target.to_string(false)?);
29 match device.initiator_transceive_bits(&UNLOCK_1, 7, MAX_FRAME_LEN) {
30 Ok(rx) => print!("Received bits: {:02X?}\n", rx),
31 Err(err) => {
32 print!("This is NOT a backdoored rewritable UID chinese card ({:?})\n", err);
33 sleep(Duration::from_secs(5));
34 print!("Looking for targets...\n");
35 continue;
36 },
37 };
38
39 match device.initiator_transceive_bytes(&UNLOCK_2, MAX_FRAME_LEN, nfc1::Timeout::Default){
40 Ok(rx) => {
41 print!("Received bytes: {:02X?}\n", rx);
42 print!("This is a backdoored rewritable UID chinese card\n")
43 },
44 Err(err) => print!("This is NOT a backdoored rewritable UID chinese card ({:?})\n", err),
45 };
46 },
47 Err(_) => { continue; }
48 }
49 sleep(Duration::from_secs(5));
50 }
51}