Skip to content

Commit ed51655

Browse files
committed
added "data qrcode" command to generate QR codes from inside the PM3 client
1 parent c4de141 commit ed51655

File tree

5 files changed

+97
-6
lines changed

5 files changed

+97
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ All notable changes to this project will be documented in this file.
33
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...
44

55
## [unreleased][unreleased]
6-
- fix `hf felica raw` - wrong length calculationes. Thanks @dxl for the solutions! (@iceman1001)
6+
- Added `data qrcode` - to generate QR codes from inside the pm3 client (@iceman1001)
7+
- Fix unicode on mingw/proxspace (@nvx)
8+
- Fix `hf felica raw` - wrong length calculationes. Thanks @dxl for the solutions! (@iceman1001)
79
- Added basic QR code generation support. Thanks @mistial-dev for the idea! (@iceman1001)
810
- Added identification of NDEF/Open print tag record (@iceman1001)
911
- Added support for Bruce dump files [.rfid] (@iceman1001)

client/src/cmddata.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "mbedtls/ctr_drbg.h" // random generator
4343
#include "atrs.h" // ATR lookup
4444
#include "crypto/libpcrypto.h" // Cryptography
45+
#include "qrcode/qrcode.h" // QR Code lib
4546

4647

4748
uint8_t g_DemodBuffer[MAX_DEMOD_BUF_LEN] = { 0x00 };
@@ -3976,6 +3977,74 @@ static int CmdTestSaveState32S(const char *Cmd) {
39763977
return PM3_SUCCESS;
39773978
}
39783979

3980+
static int CmdQRcode(const char *Cmd) {
3981+
CLIParserContext *ctx;
3982+
CLIParserInit(&ctx, "data qrcode",
3983+
"Generate a QR code with the input data",
3984+
"data qrcode -f <filename>\n"
3985+
"data qrcode -d 123456789\n"
3986+
);
3987+
3988+
void *argtable[] = {
3989+
arg_param_begin,
3990+
arg_str0("f", "file", "<fn>", "Specify a filename"),
3991+
arg_str0("d", "data", "<hex>", "message as hex bytes"),
3992+
arg_param_end
3993+
};
3994+
CLIExecWithReturn(ctx, Cmd, argtable, false);
3995+
3996+
int fnlen = 0;
3997+
char filename[FILE_PATH_SIZE] = { 0 };
3998+
CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen);
3999+
4000+
int dlen = 0;
4001+
char data[1024] = { 0 };
4002+
CLIParamStrToBuf(arg_get_str(ctx, 2), (uint8_t *)data, sizeof(data), &dlen);
4003+
CLIParserFree(ctx);
4004+
4005+
if (fnlen && dlen) {
4006+
PrintAndLogEx(WARNING, "Please specify filename or datastring");
4007+
return PM3_EINVARG;
4008+
}
4009+
4010+
QRCode qrcode;
4011+
4012+
if (fnlen) {
4013+
4014+
uint8_t *dump = NULL;
4015+
size_t bytes_read = 0;
4016+
4017+
// read from file
4018+
int res = pm3_load_dump(filename, (void **)&dump, &bytes_read, (MFBLOCK_SIZE * MIFARE_4K_MAXBLOCK));
4019+
if (res != PM3_SUCCESS) {
4020+
return res;
4021+
}
4022+
4023+
// check file size corresponds to card size.
4024+
if (dump != NULL) {
4025+
free(dump);
4026+
return PM3_EFILE;
4027+
}
4028+
}
4029+
4030+
if (dlen) {
4031+
4032+
// calc size of input data to get the correct
4033+
int smallest_version = (dlen + 17) / 20;
4034+
uint8_t qr_arr[qrcode_getBufferSize(smallest_version)];
4035+
qrcode_initText(&qrcode, qr_arr, smallest_version, ECC_LOW, (char *) data);
4036+
4037+
PrintAndLogEx(NORMAL, "");
4038+
qrcode_print_matrix_utf8(&qrcode);
4039+
PrintAndLogEx(NORMAL, "");
4040+
PrintAndLogEx(NORMAL, "");
4041+
qrcode_print_matrix_utf8_2x2(&qrcode);
4042+
PrintAndLogEx(NORMAL, "");
4043+
}
4044+
4045+
return PM3_SUCCESS;
4046+
}
4047+
39794048
static command_t CommandTable[] = {
39804049
{"help", CmdHelp, AlwaysAvailable, "This help"},
39814050
{"-----------", CmdHelp, AlwaysAvailable, "------------------------- " _CYAN_("General") "-------------------------"},
@@ -4028,6 +4097,7 @@ static command_t CommandTable[] = {
40284097
{"diff", CmdDiff, AlwaysAvailable, "Diff of input files"},
40294098
{"hexsamples", CmdHexsamples, IfPm3Present, "Dump big buffer as hex bytes"},
40304099
{"samples", CmdSamples, IfPm3Present, "Get raw samples for graph window ( GraphBuffer )"},
4100+
{"qrcode", CmdQRcode, AlwaysAvailable, "Create a QR code"},
40314101

40324102
{"-----------", CmdHelp, IfClientDebugEnabled, "------------------------- " _CYAN_("Debug") "-------------------------"},
40334103
{"test_ss8", CmdTestSaveState8, IfClientDebugEnabled, "Test the implementation of Buffer Save States (8-bit buffer)"},

client/src/pm3line_vocabulary.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ const static vocabulary_t vocabulary[] = {
120120
{ 1, "data diff" },
121121
{ 0, "data hexsamples" },
122122
{ 0, "data samples" },
123+
{ 1, "data qrcode" },
123124
{ 0, "data test_ss8" },
124125
{ 0, "data test_ss32" },
125126
{ 0, "data test_ss32s" },
@@ -928,6 +929,7 @@ const static vocabulary_t vocabulary[] = {
928929
{ 0, "script run pm3_mfd2eml.py" },
929930
{ 0, "script run pm3_nfc2eml.py" },
930931
{ 0, "script run pm3_resources.py" },
932+
{ 0, "script run read_t-union.py" },
931933
{ 0, "script run spi_flash_decode.py" },
932934
{ 0, "script run theremin.py" },
933935
{ 0, "script run xorcheck.py" },

doc/commands.json

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@
434434
},
435435
"data help": {
436436
"command": "data help",
437-
"description": "help This help ----------- ------------------------- General------------------------- clear Clears various buffers used by the graph window hide Hide the graph window load Load contents of file into graph window num Converts dec/hex/bin plot Show the graph window print Print the data in the DemodBuffer save Save signal trace data setdebugmode Set Debugging Level on client side xor Xor a input string ----------- ------------------------- Modulation------------------------- biphaserawdecode Biphase decode bin stream in DemodBuffer detectclock Detect ASK, FSK, NRZ, PSK clock rate of wave in GraphBuffer fsktonrz Convert fsk2 to nrz wave for alternate fsk demodulating (for weak fsk) manrawdecode Manchester decode binary stream in DemodBuffer modulation Identify LF signal for clock and modulation rawdemod Demodulate the data in the GraphBuffer and output binary ----------- ------------------------- Graph------------------------- askedgedetect Adjust Graph for manual ASK demod autocorr Autocorrelation over window convertbitstream Convert GraphBuffer's 0/1 values to 127 / -127 cthreshold Average out all values between dirthreshold Max rising higher up-thres/ Min falling lower down-thres decimate Decimate samples envelope Generate square envelope of samples grid overlay grid on graph window getbitstream Convert GraphBuffer's >=1 values to 1 and <1 to 0 hpf Remove DC offset from trace iir Apply IIR buttersworth filter on plot data ltrim Trim samples from left of trace mtrim Trim out samples from the specified start to the specified stop norm Normalize max/min to +/-128 rtrim Trim samples from right of trace setgraphmarkers Set the markers in the graph window shiftgraphzero Shift 0 for Graphed wave + or - shift value timescale Set cursor display timescale undecimate Un-decimate samples zerocrossings Count time between zero-crossings ----------- ------------------------- Operations------------------------- asn1 ASN1 decoder atr ATR lookup bmap Convert hex value according a binary template crypto Encrypt and decrypt data diff Diff of input files --------------------------------------------------------------------------------------- data clear available offline: yes This function clears the BigBuf on device side and graph window ( graphbuffer )",
437+
"description": "help This help ----------- ------------------------- General------------------------- clear Clears various buffers used by the graph window hide Hide the graph window load Load contents of file into graph window num Converts dec/hex/bin plot Show the graph window print Print the data in the DemodBuffer save Save signal trace data setdebugmode Set Debugging Level on client side xor Xor a input string ----------- ------------------------- Modulation------------------------- biphaserawdecode Biphase decode bin stream in DemodBuffer detectclock Detect ASK, FSK, NRZ, PSK clock rate of wave in GraphBuffer fsktonrz Convert fsk2 to nrz wave for alternate fsk demodulating (for weak fsk) manrawdecode Manchester decode binary stream in DemodBuffer modulation Identify LF signal for clock and modulation rawdemod Demodulate the data in the GraphBuffer and output binary ----------- ------------------------- Graph------------------------- askedgedetect Adjust Graph for manual ASK demod autocorr Autocorrelation over window convertbitstream Convert GraphBuffer's 0/1 values to 127 / -127 cthreshold Average out all values between dirthreshold Max rising higher up-thres/ Min falling lower down-thres decimate Decimate samples envelope Generate square envelope of samples grid overlay grid on graph window getbitstream Convert GraphBuffer's >=1 values to 1 and <1 to 0 hpf Remove DC offset from trace iir Apply IIR buttersworth filter on plot data ltrim Trim samples from left of trace mtrim Trim out samples from the specified start to the specified stop norm Normalize max/min to +/-128 rtrim Trim samples from right of trace setgraphmarkers Set the markers in the graph window shiftgraphzero Shift 0 for Graphed wave + or - shift value timescale Set cursor display timescale undecimate Un-decimate samples zerocrossings Count time between zero-crossings ----------- ------------------------- Operations------------------------- asn1 ASN1 decoder atr ATR lookup bmap Convert hex value according a binary template crypto Encrypt and decrypt data diff Diff of input files qrcode Create a QR code --------------------------------------------------------------------------------------- data clear available offline: yes This function clears the BigBuf on device side and graph window ( graphbuffer )",
438438
"notes": [
439439
"data clear"
440440
],
@@ -622,6 +622,21 @@
622622
],
623623
"usage": "data print [-hisx] [-o <dec>]"
624624
},
625+
"data qrcode": {
626+
"command": "data qrcode",
627+
"description": "Generate a QR code with the input data",
628+
"notes": [
629+
"data qrcode -f <filename>",
630+
"data qrcode -d 123456789"
631+
],
632+
"offline": true,
633+
"options": [
634+
"-h, --help This help",
635+
"-f, --file <fn> Specify a filename",
636+
"-d, --data <hex> message as hex bytes"
637+
],
638+
"usage": "data qrcode [-h] [-f <fn>] [-d <hex>]"
639+
},
625640
"data rawdemod": {
626641
"command": "data rawdemod",
627642
"description": "Demodulate the data in the GraphBuffer and output binary",
@@ -7442,9 +7457,10 @@
74427457
"-e enable special write version/signature -MAGIC NTAG 21* ONLY-",
74437458
"-r use password found in dumpfile to configure tag. Requires '-e' parameter to work",
74447459
"-v, --verbose verbose output",
7445-
"-z, --dense dense dump output style"
7460+
"-z, --dense dense dump output style",
7461+
"--schann use secure channel. Must have key"
74467462
],
7447-
"usage": "hf mfu restore [-hlservz] -f <fn> [-k <hex>]"
7463+
"usage": "hf mfu restore [-hlservz] -f <fn> [-k <hex>] [--schann]"
74487464
},
74497465
"hf mfu setkey": {
74507466
"command": "hf mfu setkey",
@@ -13681,8 +13697,8 @@
1368113697
}
1368213698
},
1368313699
"metadata": {
13684-
"commands_extracted": 784,
13700+
"commands_extracted": 785,
1368513701
"extracted_by": "PM3Help2JSON v1.00",
13686-
"extracted_on": "2025-10-17T11:36:43"
13702+
"extracted_on": "2025-11-10T15:12:49"
1368713703
}
1368813704
}

doc/commands.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ Check column "offline" for their availability.
139139
|`data diff `|Y |`Diff of input files`
140140
|`data hexsamples `|N |`Dump big buffer as hex bytes`
141141
|`data samples `|N |`Get raw samples for graph window ( GraphBuffer )`
142+
|`data qrcode `|Y |`Create a QR code`
142143
|`data test_ss8 `|N |`Test the implementation of Buffer Save States (8-bit buffer)`
143144
|`data test_ss32 `|N |`Test the implementation of Buffer Save States (32-bit buffer)`
144145
|`data test_ss32s `|N |`Test the implementation of Buffer Save States (32-bit signed buffer)`

0 commit comments

Comments
 (0)