From ce8c61543a897df513cc20ef3e82be75757e480a Mon Sep 17 00:00:00 2001 From: Redbeanw44602 Date: Sat, 24 Jan 2026 19:15:29 +0800 Subject: [PATCH 1/5] add --connstring --- src/tools/nfc-staticnested/main.cpp | 6 +++++- src/tools/nfc-staticnested/pwn_host.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/tools/nfc-staticnested/main.cpp b/src/tools/nfc-staticnested/main.cpp index f87b9f2..457d35e 100644 --- a/src/tools/nfc-staticnested/main.cpp +++ b/src/tools/nfc-staticnested/main.cpp @@ -20,6 +20,10 @@ auto load_args(int argc, char* argv[]) { InputArguments args; + program.add_argument("-c", "--connstring") + .default_value("") + .store_into(args.connstring) + .help("Specify the device's connstring."); program.add_argument("-m", "--mifare-classic") .default_value("1k") .choices("mini", "1k", "2k", "4k") @@ -98,7 +102,7 @@ int main(int argc, char* argv[]) CPPTRACE_TRY { // Start libnfc lifecycle NfcContext context; - auto device = context.open_device(); + auto device = context.open_device(args.connstring); if (!device) { throw std::runtime_error("No device found."); } diff --git a/src/tools/nfc-staticnested/pwn_host.h b/src/tools/nfc-staticnested/pwn_host.h index 37dc74f..5c5c7a8 100644 --- a/src/tools/nfc-staticnested/pwn_host.h +++ b/src/tools/nfc-staticnested/pwn_host.h @@ -16,6 +16,7 @@ namespace nfcpp { struct InputArguments { + std::string connstring; mifare::MifareCard type; bool force_detect_distance; std::string dump_keys; From 054546074a260ec05810a326470a9e9da561d4f1 Mon Sep 17 00:00:00 2001 From: Redbeanw44602 Date: Sat, 24 Jan 2026 19:48:58 +0800 Subject: [PATCH 2/5] scan device. --- src/tools/nfc-staticnested/main.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/tools/nfc-staticnested/main.cpp b/src/tools/nfc-staticnested/main.cpp index 457d35e..11b641e 100644 --- a/src/tools/nfc-staticnested/main.cpp +++ b/src/tools/nfc-staticnested/main.cpp @@ -103,9 +103,27 @@ int main(int argc, char* argv[]) CPPTRACE_TRY { NfcContext context; auto device = context.open_device(args.connstring); + if (!device && args.connstring.empty()) { + std::println("Scanning device..."); + auto connstrings = context.list_devices(); + if (connstrings.empty()) { + throw std::runtime_error("No device found."); + } + for (auto i : connstrings) { + std::println("* {}", i); + } + args.connstring = connstrings[0]; + std::println( + "The first device has been selected. You can use --connstring " + "\"{}\" to avoid repeated scanning next time.", + args.connstring + ); + device = context.open_device(args.connstring); + } if (!device) { - throw std::runtime_error("No device found."); + throw std::runtime_error("Failed to open device!"); } + std::println("NFC device opened: {}", device->get_name()); auto initiator = device->as_initiator(); From f4aef56361de5ebc8cacb8c0efacfba21840d241 Mon Sep 17 00:00:00 2001 From: Redbeanw44602 Date: Sat, 24 Jan 2026 20:18:09 +0800 Subject: [PATCH 3/5] hack lib. --- src/tools/nfc-staticnested/main.cpp | 12 ++++++++++++ src/utility.h | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/tools/nfc-staticnested/main.cpp b/src/tools/nfc-staticnested/main.cpp index 11b641e..65a5e26 100644 --- a/src/tools/nfc-staticnested/main.cpp +++ b/src/tools/nfc-staticnested/main.cpp @@ -12,6 +12,8 @@ #include "pwn_host.h" +#include "utility.h" + using namespace nfcpp; using namespace nfcpp::mifare; @@ -102,9 +104,19 @@ int main(int argc, char* argv[]) CPPTRACE_TRY { // Start libnfc lifecycle NfcContext context; + auto hack_ctx = reinterpret_cast(context.get()); + + // We do not want to scan for new devices in nfc_open. + hack_ctx->allow_autoscan = false; + auto device = context.open_device(args.connstring); if (!device && args.connstring.empty()) { std::println("Scanning device..."); + + // Re-enable it. + hack_ctx->allow_autoscan = true; + hack_ctx->allow_intrusive_scan = true; + auto connstrings = context.list_devices(); if (connstrings.empty()) { throw std::runtime_error("No device found."); diff --git a/src/utility.h b/src/utility.h index 842b856..2b19f08 100644 --- a/src/utility.h +++ b/src/utility.h @@ -85,4 +85,24 @@ constexpr auto start_block_sequence(MifareCard type) { } // namespace mifare +namespace libhack { + +typedef char nfc_connstring[1024]; + +struct nfc_user_defined_device { + char name[256]; + nfc_connstring connstring; + bool optional; +}; + +struct nfc_context { + bool allow_autoscan; + bool allow_intrusive_scan; + uint32_t log_level; + struct nfc_user_defined_device user_defined_devices[4]; + unsigned int user_defined_device_count; +}; + +} // namespace libhack + } // namespace nfcpp From 9bcc3979917ac0bf17294fd487f68fb27d09c181 Mon Sep 17 00:00:00 2001 From: Redbeanw44602 Date: Sat, 24 Jan 2026 20:29:54 +0800 Subject: [PATCH 4/5] clean cache --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c05fdec..93f553f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -154,6 +154,7 @@ jobs: - name: Configure run: | + xmake lua private.xrepo clean xmake f ${{ matrix.plat.extra-configure-flags }} -a ${{ matrix.plat.arch }} -m ${{ matrix.mode }} -p ${{ matrix.plat.os }} --toolchain=${{ matrix.plat.toolchain }} -vD -y - name: Build From d9ccf5a8117d232a67f7e07fc96fe93e57c712ab Mon Sep 17 00:00:00 2001 From: Redbeanw44602 Date: Sat, 24 Jan 2026 23:20:03 +0800 Subject: [PATCH 5/5] update. --- src/tools/nfc-staticnested/main.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/tools/nfc-staticnested/main.cpp b/src/tools/nfc-staticnested/main.cpp index 65a5e26..48cca2b 100644 --- a/src/tools/nfc-staticnested/main.cpp +++ b/src/tools/nfc-staticnested/main.cpp @@ -121,13 +121,14 @@ int main(int argc, char* argv[]) CPPTRACE_TRY { if (connstrings.empty()) { throw std::runtime_error("No device found."); } - for (auto i : connstrings) { - std::println("* {}", i); + // TODO: Libc++ does not yet support C++23 std::views::enumerate + for (auto i : std::views::iota(0uz, connstrings.size())) { + std::println("{} {}", i == 0 ? "*" : "-", connstrings[i]); } args.connstring = connstrings[0]; std::println( - "The first device has been selected. You can use --connstring " - "\"{}\" to avoid repeated scanning next time.", + "You can use '--connstring \"{}\"' or add it to libnfc.conf to " + "avoid duplicated scanning.", args.connstring ); device = context.open_device(args.connstring);