added "data qrcode" command to generate QR codes from inside the PM3 client

This commit is contained in:
iceman1001
2025-11-10 16:20:00 +01:00
parent c4de141d03
commit ed516550ca
5 changed files with 97 additions and 6 deletions
+3 -1
View File
@@ -3,7 +3,9 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
## [unreleased][unreleased]
- fix `hf felica raw` - wrong length calculationes. Thanks @dxl for the solutions! (@iceman1001)
- Added `data qrcode` - to generate QR codes from inside the pm3 client (@iceman1001)
- Fix unicode on mingw/proxspace (@nvx)
- Fix `hf felica raw` - wrong length calculationes. Thanks @dxl for the solutions! (@iceman1001)
- Added basic QR code generation support. Thanks @mistial-dev for the idea! (@iceman1001)
- Added identification of NDEF/Open print tag record (@iceman1001)
- Added support for Bruce dump files [.rfid] (@iceman1001)
+70
View File
@@ -42,6 +42,7 @@
#include "mbedtls/ctr_drbg.h" // random generator
#include "atrs.h" // ATR lookup
#include "crypto/libpcrypto.h" // Cryptography
#include "qrcode/qrcode.h" // QR Code lib
uint8_t g_DemodBuffer[MAX_DEMOD_BUF_LEN] = { 0x00 };
@@ -3976,6 +3977,74 @@ static int CmdTestSaveState32S(const char *Cmd) {
return PM3_SUCCESS;
}
static int CmdQRcode(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "data qrcode",
"Generate a QR code with the input data",
"data qrcode -f <filename>\n"
"data qrcode -d 123456789\n"
);
void *argtable[] = {
arg_param_begin,
arg_str0("f", "file", "<fn>", "Specify a filename"),
arg_str0("d", "data", "<hex>", "message as hex bytes"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
int fnlen = 0;
char filename[FILE_PATH_SIZE] = { 0 };
CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen);
int dlen = 0;
char data[1024] = { 0 };
CLIParamStrToBuf(arg_get_str(ctx, 2), (uint8_t *)data, sizeof(data), &dlen);
CLIParserFree(ctx);
if (fnlen && dlen) {
PrintAndLogEx(WARNING, "Please specify filename or datastring");
return PM3_EINVARG;
}
QRCode qrcode;
if (fnlen) {
uint8_t *dump = NULL;
size_t bytes_read = 0;
// read from file
int res = pm3_load_dump(filename, (void **)&dump, &bytes_read, (MFBLOCK_SIZE * MIFARE_4K_MAXBLOCK));
if (res != PM3_SUCCESS) {
return res;
}
// check file size corresponds to card size.
if (dump != NULL) {
free(dump);
return PM3_EFILE;
}
}
if (dlen) {
// calc size of input data to get the correct
int smallest_version = (dlen + 17) / 20;
uint8_t qr_arr[qrcode_getBufferSize(smallest_version)];
qrcode_initText(&qrcode, qr_arr, smallest_version, ECC_LOW, (char *) data);
PrintAndLogEx(NORMAL, "");
qrcode_print_matrix_utf8(&qrcode);
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "");
qrcode_print_matrix_utf8_2x2(&qrcode);
PrintAndLogEx(NORMAL, "");
}
return PM3_SUCCESS;
}
static command_t CommandTable[] = {
{"help", CmdHelp, AlwaysAvailable, "This help"},
{"-----------", CmdHelp, AlwaysAvailable, "------------------------- " _CYAN_("General") "-------------------------"},
@@ -4028,6 +4097,7 @@ static command_t CommandTable[] = {
{"diff", CmdDiff, AlwaysAvailable, "Diff of input files"},
{"hexsamples", CmdHexsamples, IfPm3Present, "Dump big buffer as hex bytes"},
{"samples", CmdSamples, IfPm3Present, "Get raw samples for graph window ( GraphBuffer )"},
{"qrcode", CmdQRcode, AlwaysAvailable, "Create a QR code"},
{"-----------", CmdHelp, IfClientDebugEnabled, "------------------------- " _CYAN_("Debug") "-------------------------"},
{"test_ss8", CmdTestSaveState8, IfClientDebugEnabled, "Test the implementation of Buffer Save States (8-bit buffer)"},
+2
View File
@@ -120,6 +120,7 @@ const static vocabulary_t vocabulary[] = {
{ 1, "data diff" },
{ 0, "data hexsamples" },
{ 0, "data samples" },
{ 1, "data qrcode" },
{ 0, "data test_ss8" },
{ 0, "data test_ss32" },
{ 0, "data test_ss32s" },
@@ -928,6 +929,7 @@ const static vocabulary_t vocabulary[] = {
{ 0, "script run pm3_mfd2eml.py" },
{ 0, "script run pm3_nfc2eml.py" },
{ 0, "script run pm3_resources.py" },
{ 0, "script run read_t-union.py" },
{ 0, "script run spi_flash_decode.py" },
{ 0, "script run theremin.py" },
{ 0, "script run xorcheck.py" },
+21 -5
View File
File diff suppressed because one or more lines are too long
+1
View File
@@ -139,6 +139,7 @@ Check column "offline" for their availability.
|`data diff `|Y |`Diff of input files`
|`data hexsamples `|N |`Dump big buffer as hex bytes`
|`data samples `|N |`Get raw samples for graph window ( GraphBuffer )`
|`data qrcode `|Y |`Create a QR code`
|`data test_ss8 `|N |`Test the implementation of Buffer Save States (8-bit buffer)`
|`data test_ss32 `|N |`Test the implementation of Buffer Save States (32-bit buffer)`
|`data test_ss32s `|N |`Test the implementation of Buffer Save States (32-bit signed buffer)`