Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 37 additions & 2 deletions src/tools/nfc-staticnested/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include "pwn_host.h"

#include "utility.h"

using namespace nfcpp;
using namespace nfcpp::mifare;

Expand All @@ -20,6 +22,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")
Expand Down Expand Up @@ -98,10 +104,39 @@ int main(int argc, char* argv[]) CPPTRACE_TRY {
// Start libnfc lifecycle
NfcContext context;

auto device = context.open_device();
auto hack_ctx = reinterpret_cast<libhack::nfc_context*>(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.");
}
// 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(
"You can use '--connstring \"{}\"' or add it to libnfc.conf to "
"avoid duplicated scanning.",
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();
Expand Down
1 change: 1 addition & 0 deletions src/tools/nfc-staticnested/pwn_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace nfcpp {

struct InputArguments {
std::string connstring;
mifare::MifareCard type;
bool force_detect_distance;
std::string dump_keys;
Expand Down
20 changes: 20 additions & 0 deletions src/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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