1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2013 m h swende <martin at swende.se>
3 // Modified 2015,2016, iceman
5 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
6 // at your option, any later version. See the LICENSE.txt file for the text of
8 //-----------------------------------------------------------------------------
9 // Some lua scripting glue to proxmark core.
10 //-----------------------------------------------------------------------------
11 #include "scripting.h"
19 #include "proxmark3.h"
21 #include "mifare/mifarehost.h"
27 #include "cmdhfmfhard.h"
29 #include "cmdlft55xx.h" // read t55xx etc
30 #include "nfc/ndef.h" // ndef parsing
31 #include "commonutil.h"
35 #include "protocols.h"
36 #include "fileutils.h" // searchfile
37 #include "cmdlf.h" // lf_config
38 #include "generator.h"
39 #include "cmdlfem4x05.h" // read 4305
40 #include "cmdlfem4x50.h" // read 4350
41 #include "em4x50.h" // 4x50 structs
43 static int returnToLuaWithError(lua_State
*L
, const char *fmt
, ...) {
47 vsnprintf(buffer
, sizeof(buffer
), fmt
, args
);
51 lua_pushstring(L
, buffer
);
55 static int l_clearCommandBuffer(lua_State
*L
) {
61 * Enable / Disable fast push mode for lua scripts like hf_mf_keycheck
62 * The following params expected:
64 *@brief l_fast_push_mode
68 static int l_fast_push_mode(lua_State
*L
) {
70 luaL_checktype(L
, 1, LUA_TBOOLEAN
);
72 bool enable
= lua_toboolean(L
, 1);
74 conn
.block_after_ACK
= enable
;
76 // Disable fast mode and send a dummy command to make it effective
77 if (enable
== false) {
78 SendCommandNG(CMD_PING
, NULL
, 0);
79 if (!WaitForResponseTimeout(CMD_PING
, NULL
, 1000)) {
80 PrintAndLogEx(WARNING
, "command execution time out");
81 return returnToLuaWithError(L
, "command execution time out");
85 //Push the retval on the stack
86 lua_pushboolean(L
, enable
);
91 * The following params expected:
92 * @brief l_SendCommandOLD
93 * @param L - a lua string with the following five params.
94 * @param cmd must be hexstring, max u64
95 * @param arg0 must be hexstring, max u64
96 * @param arg1 must be hexstring, max u64
97 * @param arg2 must be hexstring, max u64
98 * @param data must be hexstring less than 1024 chars(512bytes)
101 static int l_SendCommandOLD(lua_State
*L
) {
102 // SendCommandMIX(CMD_HF_SNIFF, skippairs, skiptriggers, 0, NULL, 0);
103 // (uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len)
105 uint64_t cmd
, arg0
, arg1
, arg2
;
106 uint8_t data
[PM3_CMD_DATA_SIZE
] = {0};
107 size_t len
= 0, size
;
109 //Check number of arguments
110 int n
= lua_gettop(L
);
112 return returnToLuaWithError(L
, "You need to supply five parameters");
116 cmd
= luaL_checknumber(L
, 1);
117 arg0
= luaL_checknumber(L
, 2);
118 arg1
= luaL_checknumber(L
, 3);
119 arg2
= luaL_checknumber(L
, 4);
122 const char *p_data
= luaL_checklstring(L
, 5, &size
);
128 for (int i
= 0; i
< size
; i
+= 2) {
129 sscanf(&p_data
[i
], "%02x", &tmp
);
130 data
[i
>> 1] = tmp
& 0xFF;
135 clearCommandBuffer();
136 SendCommandOLD(cmd
, arg0
, arg1
, arg2
, data
, len
);
137 lua_pushboolean(L
, true);
142 * The following params expected:
143 * @brief l_SendCommandMIX
144 * @param L - a lua string with the following five params.
145 * @param cmd must be hexstring, max u64
146 * @param arg0 must be hexstring, max u64
147 * @param arg1 must be hexstring, max u64
148 * @param arg2 must be hexstring, max u64
149 * @param data must be hexstring less than 1024 chars(512bytes)
152 static int l_SendCommandMIX(lua_State
*L
) {
154 uint64_t cmd
, arg0
, arg1
, arg2
;
155 uint8_t data
[PM3_CMD_DATA_SIZE
] = {0};
156 size_t len
= 0, size
;
158 // check number of arguments
159 int n
= lua_gettop(L
);
161 return returnToLuaWithError(L
, "You need to supply five parameters");
164 cmd
= luaL_checknumber(L
, 1);
165 arg0
= luaL_checknumber(L
, 2);
166 arg1
= luaL_checknumber(L
, 3);
167 arg2
= luaL_checknumber(L
, 4);
170 const char *p_data
= luaL_checklstring(L
, 5, &size
);
176 for (int i
= 0; i
< size
; i
+= 2) {
177 sscanf(&p_data
[i
], "%02x", &tmp
);
178 data
[i
>> 1] = tmp
& 0xFF;
183 clearCommandBuffer();
184 SendCommandMIX(cmd
, arg0
, arg1
, arg2
, data
, len
);
185 lua_pushboolean(L
, true);
189 * The following params expected:
190 * @brief l_SendCommandMIX
191 * @param L - a lua string with the following two params.
192 * @param cmd must be hexstring, max u64
193 * @param data must be hexstring less than 1024 chars(512bytes)
196 static int l_SendCommandNG(lua_State
*L
) {
198 uint8_t data
[PM3_CMD_DATA_SIZE
] = {0};
199 size_t len
= 0, size
;
201 // check number of arguments
202 int n
= lua_gettop(L
);
204 return returnToLuaWithError(L
, "You need to supply two parameters");
207 uint16_t cmd
= luaL_checknumber(L
, 1);
210 const char *p_data
= luaL_checklstring(L
, 2, &size
);
216 for (int i
= 0; i
< size
; i
+= 2) {
217 sscanf(&p_data
[i
], "%02x", &tmp
);
218 data
[i
>> 1] = tmp
& 0xFF;
223 clearCommandBuffer();
224 SendCommandNG(cmd
, data
, len
);
225 lua_pushboolean(L
, true);
231 * @brief The following params expected:
238 static int l_GetFromBigBuf(lua_State
*L
) {
240 int len
= 0, startindex
= 0;
242 //Check number of arguments
243 int n
= lua_gettop(L
);
245 return returnToLuaWithError(L
, "You need to supply number of bytes and startindex");
249 startindex
= luaL_checknumber(L
, 1);
250 len
= luaL_checknumber(L
, 2);
254 return returnToLuaWithError(L
, "You need to supply number of bytes larger than zero");
257 uint8_t *data
= calloc(len
, sizeof(uint8_t));
259 return returnToLuaWithError(L
, "Allocating memory failed");
262 if (!GetFromDevice(BIG_BUF
, data
, len
, startindex
, NULL
, 0, NULL
, 2500, false)) {
264 return returnToLuaWithError(L
, "command execution time out");
267 //Push it as a string
268 lua_pushlstring(L
, (const char *)data
, len
);
270 return 1; // return 1 to signal one return value
274 * @brief The following params expected:
281 static int l_GetFromFlashMem(lua_State
*L
) {
284 int len
= 0, startindex
= 0;
286 int n
= lua_gettop(L
);
288 return returnToLuaWithError(L
, "You need to supply number of bytes and startindex");
291 startindex
= luaL_checknumber(L
, 1);
292 len
= luaL_checknumber(L
, 2);
296 return returnToLuaWithError(L
, "You need to supply number of bytes larger than zero");
298 uint8_t *data
= calloc(len
, sizeof(uint8_t));
300 return returnToLuaWithError(L
, "Allocating memory failed");
302 if (!GetFromDevice(FLASH_MEM
, data
, len
, startindex
, NULL
, 0, NULL
, -1, false)) {
304 return returnToLuaWithError(L
, "command execution time out");
307 lua_pushlstring(L
, (const char *)data
, len
);
311 return returnToLuaWithError(L
, "No FLASH MEM support");
316 * @brief The following params expected:
317 * uint8_t *destfilename
321 static int l_GetFromFlashMemSpiffs(lua_State
*L
) {
323 if (IfPm3Flash() == false) {
324 return returnToLuaWithError(L
, "No FLASH MEM support");
327 uint32_t start_index
= 0, len
= 0x40000; //FLASH_MEM_MAX_SIZE
328 char destfilename
[32] = {0};
331 int n
= lua_gettop(L
);
333 return returnToLuaWithError(L
, "You need to supply the destination filename");
336 const char *p_filename
= luaL_checklstring(L
, 1, &size
);
338 memcpy(destfilename
, p_filename
, 31);
341 if (destfilename
[0] == '\0')
342 return returnToLuaWithError(L
, "Filename missing or invalid");
344 // get size from spiffs itself !
345 SendCommandNG(CMD_SPIFFS_STAT
, (uint8_t *)destfilename
, 32);
346 PacketResponseNG resp
;
347 if (!WaitForResponseTimeout(CMD_SPIFFS_STAT
, &resp
, 2000))
348 return returnToLuaWithError(L
, "No response from the device");
350 len
= resp
.data
.asDwords
[0];
353 return returnToLuaWithError(L
, "Filename invalid or empty");
355 uint8_t *data
= calloc(len
, sizeof(uint8_t));
357 return returnToLuaWithError(L
, "Allocating memory failed");
359 if (!GetFromDevice(SPIFFS
, data
, len
, start_index
, (uint8_t *)destfilename
, 32, NULL
, -1, true)) {
361 return returnToLuaWithError(L
, "ERROR; downloading from spiffs(flashmemory)");
364 lua_pushlstring(L
, (const char *)data
, len
);
365 lua_pushunsigned(L
, len
);
371 * @brief The following params expected:
375 * @return struct of PacketResponseNG
377 static int l_WaitForResponseTimeout(lua_State
*L
) {
380 size_t ms_timeout
= -1;
382 //Check number of arguments
383 int n
= lua_gettop(L
);
385 return returnToLuaWithError(L
, "You need to supply at least command to wait for");
387 // extract first param. cmd byte to look for
389 cmd
= luaL_checkunsigned(L
, 1);
391 // extract second param. timeout value
393 ms_timeout
= luaL_checkunsigned(L
, 2);
395 PacketResponseNG resp
;
396 if (WaitForResponseTimeout(cmd
, &resp
, ms_timeout
) == false) {
397 return returnToLuaWithError(L
, "No response from the device");
400 char foo
[sizeof(PacketResponseNG
)];
403 memcpy(foo
+ n
, &resp
.cmd
, sizeof(resp
.cmd
));
404 n
+= sizeof(resp
.cmd
);
406 memcpy(foo
+ n
, &resp
.length
, sizeof(resp
.length
));
407 n
+= sizeof(resp
.length
);
409 memcpy(foo
+ n
, &resp
.magic
, sizeof(resp
.magic
));
410 n
+= sizeof(resp
.magic
);
412 memcpy(foo
+ n
, &resp
.status
, sizeof(resp
.status
));
413 n
+= sizeof(resp
.status
);
415 memcpy(foo
+ n
, &resp
.crc
, sizeof(resp
.crc
));
416 n
+= sizeof(resp
.crc
);
418 memcpy(foo
+ n
, &resp
.oldarg
[0], sizeof(resp
.oldarg
[0]));
419 n
+= sizeof(resp
.oldarg
[0]);
421 memcpy(foo
+ n
, &resp
.oldarg
[1], sizeof(resp
.oldarg
[1]));
422 n
+= sizeof(resp
.oldarg
[1]);
424 memcpy(foo
+ n
, &resp
.oldarg
[2], sizeof(resp
.oldarg
[2]));
425 n
+= sizeof(resp
.oldarg
[2]);
427 memcpy(foo
+ n
, resp
.data
.asBytes
, sizeof(resp
.data
));
428 n
+= sizeof(resp
.data
);
430 memcpy(foo
+ n
, &resp
.ng
, sizeof(resp
.ng
));
431 n
+= sizeof(resp
.ng
);
434 //Push it as a string
435 lua_pushlstring(L
, (const char *)&foo
, sizeof(foo
));
439 static int l_mfDarkside(lua_State
*L
) {
441 uint32_t blockno
= 0;
442 uint32_t keytype
= MIFARE_AUTH_KEYA
;
446 //Check number of arguments
447 int n
= lua_gettop(L
);
450 const char *p_keytype
= luaL_checklstring(L
, 2, &size
);
451 if (size
!= 2) return returnToLuaWithError(L
, "Wrong size of keytype, got %d bytes, expected 1", (int) size
);
452 sscanf(p_keytype
, "%x", &keytype
);
455 const char *p_blockno
= luaL_checklstring(L
, 1, &size
);
456 if (size
!= 2) return returnToLuaWithError(L
, "Wrong size of blockno, got %d bytes, expected 2", (int) size
);
457 sscanf(p_blockno
, "%02x", &blockno
);
464 int retval
= mfDarkside(blockno
& 0xFF, keytype
& 0xFF, &key
);
467 num_to_bytes(key
, sizeof(dest_key
), dest_key
);
469 //Push the retval on the stack
470 lua_pushinteger(L
, retval
);
471 lua_pushlstring(L
, (const char *) dest_key
, sizeof(dest_key
));
476 * @brief l_foobar is a dummy function to test lua-integration with
480 static int l_foobar(lua_State
*L
) {
481 //Check number of arguments
482 int n
= lua_gettop(L
);
483 PrintAndLogEx(INFO
, "foobar called with %d arguments", n
);
485 PrintAndLogEx(INFO
, "Arguments discarded, stack now contains %d elements", lua_gettop(L
));
487 // todo: this is not used, where was it intended for?
488 // PacketCommandOLD response = {CMD_HF_MIFARE_READBL, {1337, 1338, 1339}, {{0}}};
490 PrintAndLogEx(INFO
, "Now returning a uint64_t as a string");
491 uint64_t x
= 0xDEADC0DE;
492 uint8_t destination
[8];
493 num_to_bytes(x
, sizeof(x
), destination
);
494 lua_pushlstring(L
, (const char *)&x
, sizeof(x
));
495 lua_pushlstring(L
, (const char *)destination
, sizeof(destination
));
500 * @brief Utility to check if a key has been pressed by the user. This method does not block.
502 * @return boolean, true if kbhit, false otherwise.
504 static int l_kbd_enter_pressed(lua_State
*L
) {
505 lua_pushboolean(L
, kbd_enter_pressed() ? true : false);
510 * @brief Calls the command line parser to deal with the command. This enables
511 * lua-scripts to do stuff like "core.console('hf mf mifare')"
515 static int l_CmdConsole(lua_State
*L
) {
516 CommandReceived((char *)luaL_checkstring(L
, 1));
520 static int l_iso15693_crc(lua_State
*L
) {
522 unsigned char buf
[PM3_CMD_DATA_SIZE
] = {0x00};
524 const char *data
= luaL_checklstring(L
, 1, &size
);
526 for (int i
= 0; i
< size
; i
+= 2) {
527 sscanf(&data
[i
], "%02x", &tmp
);
528 buf
[i
/ 2] = tmp
& 0xFF;
532 compute_crc(CRC_15693
, buf
, size
, &buf
[size
], &buf
[size
+ 1]);
533 lua_pushlstring(L
, (const char *)&buf
, size
+ 2);
537 static int l_iso14443b_crc(lua_State
*L
) {
539 unsigned char buf
[PM3_CMD_DATA_SIZE
] = {0x00};
541 const char *data
= luaL_checklstring(L
, 1, &size
);
543 for (int i
= 0; i
< size
; i
+= 2) {
544 sscanf(&data
[i
], "%02x", &tmp
);
545 buf
[i
/ 2] = tmp
& 0xFF;
549 compute_crc(CRC_14443_B
, buf
, size
, &buf
[size
], &buf
[size
+ 1]);
550 lua_pushlstring(L
, (const char *)&buf
, size
+ 2);
555 Simple AES 128 cbc hook up to OpenSSL.
558 static int l_aes128decrypt_cbc(lua_State
*L
) {
559 //Check number of arguments
563 const char *p_key
= luaL_checklstring(L
, 1, &size
);
565 return returnToLuaWithError(L
, "Wrong size of key, got %d bytes, expected 32", (int) size
);
567 const char *p_encTxt
= luaL_checklstring(L
, 2, &size
);
569 unsigned char indata
[16] = {0x00};
570 unsigned char outdata
[16] = {0x00};
571 unsigned char aes_key
[16] = {0x00};
572 unsigned char iv
[16] = {0x00};
574 // convert key to bytearray and convert input to bytearray
575 for (i
= 0; i
< 32; i
+= 2) {
576 sscanf(&p_encTxt
[i
], "%02x", &tmp
);
577 indata
[i
/ 2] = tmp
& 0xFF;
578 sscanf(&p_key
[i
], "%02x", &tmp
);
579 aes_key
[i
/ 2] = tmp
& 0xFF;
582 mbedtls_aes_context ctx
;
583 mbedtls_aes_init(&ctx
);
584 mbedtls_aes_setkey_dec(&ctx
, aes_key
, 128);
585 mbedtls_aes_crypt_cbc(&ctx
, MBEDTLS_AES_DECRYPT
, sizeof(indata
), iv
, indata
, outdata
);
586 //Push decrypted array as a string
587 lua_pushlstring(L
, (const char *)&outdata
, sizeof(outdata
));
588 return 1;// return 1 to signal one return value
590 static int l_aes128decrypt_ecb(lua_State
*L
) {
591 //Check number of arguments
595 const char *p_key
= luaL_checklstring(L
, 1, &size
);
597 return returnToLuaWithError(L
, "Wrong size of key, got %d bytes, expected 32", (int) size
);
599 const char *p_encTxt
= luaL_checklstring(L
, 2, &size
);
601 unsigned char indata
[16] = {0x00};
602 unsigned char outdata
[16] = {0x00};
603 unsigned char aes_key
[16] = {0x00};
605 // convert key to bytearray and convert input to bytearray
606 for (i
= 0; i
< 32; i
+= 2) {
607 sscanf(&p_encTxt
[i
], "%02x", &tmp
);
608 indata
[i
/ 2] = tmp
& 0xFF;
609 sscanf(&p_key
[i
], "%02x", &tmp
);
610 aes_key
[i
/ 2] = tmp
& 0xFF;
612 mbedtls_aes_context ctx
;
613 mbedtls_aes_init(&ctx
);
614 mbedtls_aes_setkey_dec(&ctx
, aes_key
, 128);
615 mbedtls_aes_crypt_ecb(&ctx
, MBEDTLS_AES_DECRYPT
, indata
, outdata
);
617 //Push decrypted array as a string
618 lua_pushlstring(L
, (const char *)&outdata
, sizeof(outdata
));
619 return 1;// return 1 to signal one return value
622 static int l_aes128encrypt_cbc(lua_State
*L
) {
623 //Check number of arguments
627 const char *p_key
= luaL_checklstring(L
, 1, &size
);
629 return returnToLuaWithError(L
, "Wrong size of key, got %d bytes, expected 32", (int) size
);
631 const char *p_txt
= luaL_checklstring(L
, 2, &size
);
633 unsigned char indata
[16] = {0x00};
634 unsigned char outdata
[16] = {0x00};
635 unsigned char aes_key
[16] = {0x00};
636 unsigned char iv
[16] = {0x00};
638 for (i
= 0; i
< 32; i
+= 2) {
639 sscanf(&p_txt
[i
], "%02x", &tmp
);
640 indata
[i
/ 2] = tmp
& 0xFF;
641 sscanf(&p_key
[i
], "%02x", &tmp
);
642 aes_key
[i
/ 2] = tmp
& 0xFF;
645 mbedtls_aes_context ctx
;
646 mbedtls_aes_init(&ctx
);
647 mbedtls_aes_setkey_enc(&ctx
, aes_key
, 128);
648 mbedtls_aes_crypt_cbc(&ctx
, MBEDTLS_AES_ENCRYPT
, sizeof(indata
), iv
, indata
, outdata
);
649 //Push encrypted array as a string
650 lua_pushlstring(L
, (const char *)&outdata
, sizeof(outdata
));
651 return 1;// return 1 to signal one return value
654 static int l_aes128encrypt_ecb(lua_State
*L
) {
655 //Check number of arguments
659 const char *p_key
= luaL_checklstring(L
, 1, &size
);
661 return returnToLuaWithError(L
, "Wrong size of key, got %d bytes, expected 32", (int) size
);
663 const char *p_txt
= luaL_checklstring(L
, 2, &size
);
665 unsigned char indata
[16] = {0x00};
666 unsigned char outdata
[16] = {0x00};
667 unsigned char aes_key
[16] = {0x00};
669 for (i
= 0; i
< 32; i
+= 2) {
670 sscanf(&p_txt
[i
], "%02x", &tmp
);
671 indata
[i
/ 2] = tmp
& 0xFF;
672 sscanf(&p_key
[i
], "%02x", &tmp
);
673 aes_key
[i
/ 2] = tmp
& 0xFF;
675 mbedtls_aes_context ctx
;
676 mbedtls_aes_init(&ctx
);
677 mbedtls_aes_setkey_enc(&ctx
, aes_key
, 128);
678 mbedtls_aes_crypt_ecb(&ctx
, MBEDTLS_AES_ENCRYPT
, indata
, outdata
);
679 //Push encrypted array as a string
680 lua_pushlstring(L
, (const char *)&outdata
, sizeof(outdata
));
681 return 1;// return 1 to signal one return value
684 static int l_crc8legic(lua_State
*L
) {
686 const char *p_str
= luaL_checklstring(L
, 1, &size
);
688 uint16_t retval
= CRC8Legic((uint8_t *) p_str
, size
);
689 lua_pushunsigned(L
, retval
);
693 static int l_crc16(lua_State
*L
) {
695 const char *p_str
= luaL_checklstring(L
, 1, &size
);
697 uint16_t checksum
= Crc16ex(CRC_CCITT
, (uint8_t *) p_str
, size
);
698 lua_pushunsigned(L
, checksum
);
702 static int l_crc64(lua_State
*L
) {
705 unsigned char outdata
[8] = {0x00};
707 const char *p_str
= luaL_checklstring(L
, 1, &size
);
709 crc64((uint8_t *) p_str
, size
, &crc
);
711 outdata
[0] = (uint8_t)(crc
>> 56) & 0xff;
712 outdata
[1] = (uint8_t)(crc
>> 48) & 0xff;
713 outdata
[2] = (uint8_t)(crc
>> 40) & 0xff;
714 outdata
[3] = (uint8_t)(crc
>> 32) & 0xff;
715 outdata
[4] = (uint8_t)(crc
>> 24) & 0xff;
716 outdata
[5] = (uint8_t)(crc
>> 16) & 0xff;
717 outdata
[6] = (uint8_t)(crc
>> 8) & 0xff;
718 outdata
[7] = crc
& 0xff;
719 lua_pushlstring(L
, (const char *)&outdata
, sizeof(outdata
));
724 static int l_crc64_ecma182(lua_State
*L
) {
727 unsigned char outdata
[8] = {0x00};
728 //const char *p_str = luaL_checklstring(L, 1, &size);
731 //crc64_ecma182(NULL, 0, &crc);
732 crc
= 0x338103260CC4;
735 //crc64_ecma182((uint8_t*) p_str, size, &crc);
737 outdata
[0] = (uint8_t)(crc
>> 56) & 0xff;
738 outdata
[1] = (uint8_t)(crc
>> 48) & 0xff;
739 outdata
[2] = (uint8_t)(crc
>> 40) & 0xff;
740 outdata
[3] = (uint8_t)(crc
>> 32) & 0xff;
741 outdata
[4] = (uint8_t)(crc
>> 24) & 0xff;
742 outdata
[5] = (uint8_t)(crc
>> 16) & 0xff;
743 outdata
[6] = (uint8_t)(crc
>> 8) & 0xff;
744 outdata
[7] = crc
& 0xff;
745 lua_pushlstring(L
, (const char *)&outdata
, sizeof(outdata
));
749 static int l_sha1(lua_State
*L
) {
751 const char *p_str
= luaL_checklstring(L
, 1, &size
);
752 unsigned char outdata
[20] = {0x00};
753 mbedtls_sha1((uint8_t *) p_str
, size
, outdata
);
754 lua_pushlstring(L
, (const char *)&outdata
, sizeof(outdata
));
758 static int l_reveng_models(lua_State
*L
) {
760 // This array needs to be adjusted if RevEng adds more crc-models.
764 uint8_t in_width
= luaL_checkunsigned(L
, 1);
766 return returnToLuaWithError(L
, "Width cannot exceed 89, got %d", in_width
);
768 uint8_t width
[NMODELS
];
769 memset(width
, 0, sizeof(width
));
770 char *models
[NMODELS
];
774 if (!GetModels(models
, &count
, width
))
775 return returnToLuaWithError(L
, "didn't find any models");
778 for (int i
= 0; i
< count
; i
++) {
779 lua_pushstring(L
, (const char *)models
[i
]);
780 lua_rawseti(L
, -2, i
+ 1);
786 //Called with 4 parameters.
787 // inModel ,string containing the crc model name: 'CRC-8'
788 // inHexStr ,string containing the hex representation of the data that will be used for CRC calculations.
789 // reverse ,int 0/1 (bool) if 1, calculate the reverse CRC
790 // endian ,char, 'B','b','L','l','t','r' describing if Big-Endian or Little-Endian should be used in different combinations.
792 // outputs: string with hex representation of the CRC result
793 static int l_reveng_runmodel(lua_State
*L
) {
795 //inModel = valid model name string - CRC-8
796 //inHexStr = input hex string to calculate crc on
797 //reverse = reverse calc option if true
798 //endian = {0 = calc default endian input and output, b = big endian input and output, B = big endian output, r = right justified
799 // l = little endian input and output, L = little endian output only, t = left justified}
800 //result = calculated crc hex string
802 memset(result
, 0x00, sizeof(result
));
804 const char *inModel
= luaL_checkstring(L
, 1);
805 const char *inHexStr
= luaL_checkstring(L
, 2);
806 bool reverse
= lua_toboolean(L
, 3);
807 const char endian
= luaL_checkstring(L
, 4)[0];
809 int ans
= RunModel((char *)inModel
, (char *)inHexStr
, reverse
, endian
, result
);
811 return returnToLuaWithError(L
, "Reveng failed");
813 lua_pushstring(L
, result
);
817 static int l_hardnested(lua_State
*L
) {
819 bool haveTarget
= true;
822 const char *p_blockno
= luaL_checklstring(L
, 1, &size
);
824 return returnToLuaWithError(L
, "Wrong size of blockNo, got %d bytes, expected 2", (int) size
);
826 const char *p_keytype
= luaL_checklstring(L
, 2, &size
);
828 return returnToLuaWithError(L
, "Wrong size of keyType, got %d bytes, expected 1", (int) size
);
830 const char *p_key
= luaL_checklstring(L
, 3, &size
);
832 return returnToLuaWithError(L
, "Wrong size of key, got %d bytes, expected 12", (int) size
);
834 const char *p_trg_blockno
= luaL_checklstring(L
, 4, &size
);
836 return returnToLuaWithError(L
, "Wrong size of trgBlockNo, got %d bytes, expected 2", (int) size
);
838 const char *p_trg_keytype
= luaL_checklstring(L
, 5, &size
);
840 return returnToLuaWithError(L
, "Wrong size of trgKeyType, got %d bytes, expected 1", (int) size
);
842 const char *p_trgkey
= luaL_checklstring(L
, 6, &size
);
846 const char *p_nonce_file_read
= luaL_checklstring(L
, 7, &size
);
848 return returnToLuaWithError(L
, "Wrong size of nonce_file_read, got %d bytes, expected 1", (int) size
);
850 const char *p_nonce_file_write
= luaL_checklstring(L
, 8, &size
);
852 return returnToLuaWithError(L
, "Wrong size of nonce_file_write, got %d bytes, expected 1", (int) size
);
854 const char *p_slow
= luaL_checklstring(L
, 9, &size
);
856 return returnToLuaWithError(L
, "Wrong size of slow, got %d bytes, expected 1", (int) size
);
858 const char *p_tests
= luaL_checklstring(L
, 10, &size
);
860 return returnToLuaWithError(L
, "Wrong size of tests, got %d bytes, expected 1", (int) size
);
862 char filename
[FILE_PATH_SIZE
] = "nonces.bin";
863 const char *p_filename
= luaL_checklstring(L
, 11, &size
);
865 memcpy(filename
, p_filename
, FILE_PATH_SIZE
- 1);
867 uint32_t blockNo
= 0, keyType
= 0;
868 uint32_t trgBlockNo
= 0, trgKeyType
= 0;
869 uint32_t slow
= 0, tests
= 0;
870 uint32_t nonce_file_read
= 0, nonce_file_write
= 0;
871 sscanf(p_blockno
, "%02x", &blockNo
);
872 sscanf(p_keytype
, "%x", &keyType
);
873 sscanf(p_trg_blockno
, "%02x", &trgBlockNo
);
874 sscanf(p_trg_keytype
, "%x", &trgKeyType
);
875 sscanf(p_nonce_file_read
, "%x", &nonce_file_read
);
876 sscanf(p_nonce_file_write
, "%x", &nonce_file_write
);
878 sscanf(p_slow
, "%x", &slow
);
879 sscanf(p_tests
, "%x", &tests
);
881 uint8_t key
[6] = {0, 0, 0, 0, 0, 0};
882 uint8_t trgkey
[6] = {0, 0, 0, 0, 0, 0};
883 for (int i
= 0; i
< 12; i
+= 2) {
884 sscanf(&p_key
[i
], "%02x", &tmp
);
885 key
[i
/ 2] = tmp
& 0xFF;
887 sscanf(&p_trgkey
[i
], "%02x", &tmp
);
888 trgkey
[i
/ 2] = tmp
& 0xFF;
892 uint64_t foundkey
= 0;
893 int retval
= mfnestedhard(blockNo
, keyType
, key
, trgBlockNo
, trgKeyType
, haveTarget
? trgkey
: NULL
, nonce_file_read
, nonce_file_write
, slow
, tests
, &foundkey
, filename
);
896 //Push the key onto the stack
898 num_to_bytes(foundkey
, sizeof(dest_key
), dest_key
);
900 //Push the retval on the stack
901 lua_pushinteger(L
, retval
);
902 lua_pushlstring(L
, (const char *) dest_key
, sizeof(dest_key
));
903 return 2; //Two return values
907 * @brief l_validate_prng is a function to test is a nonce is using the weak PRNG
908 * detection = 1 == weak, 0 == hard , -1 = failed
912 static int l_detect_prng(lua_State
*L
) {
913 int res
= detect_classic_prng();
914 lua_pushinteger(L
, res
);
918 * @brief l_keygen_algoD is a function to calculate pwd/pack using UID, by algo D
922 static int l_keygen_algoD(lua_State
*L
) {
923 //Check number of arguments
924 int n
= lua_gettop(L
);
926 return returnToLuaWithError(L
, "Only UID");
931 const char *p_uid
= luaL_checklstring(L
, 1, &size
);
933 return returnToLuaWithError(L
, "Wrong size of UID, got %d bytes, expected 14", (int) size
);
935 uint8_t uid
[7] = {0, 0, 0, 0, 0, 0, 0};
937 for (int i
= 0; i
< 14; i
+= 2) {
938 sscanf(&p_uid
[i
], "%02x", &tmp
);
939 uid
[i
/ 2] = tmp
& 0xFF;
942 uint32_t pwd
= ul_ev1_pwdgenD(uid
);
943 uint16_t pack
= ul_ev1_packgenD(uid
);
945 lua_pushunsigned(L
, pwd
);
946 lua_pushunsigned(L
, pack
);
955 param4 uint32_t password
957 static int l_T55xx_readblock(lua_State
*L
) {
959 //Check number of arguments
960 int n
= lua_gettop(L
);
962 return returnToLuaWithError(L
, "Wrong number of arguments, got %d bytes, expected 4", n
);
964 uint32_t block
, usepage1
, override
, password
= 0;
968 const char *p_blockno
= luaL_checklstring(L
, 1, &size
);
969 if (size
< 1 || size
> 2)
970 return returnToLuaWithError(L
, "Wrong size of blockNo, got %d, expected 1 or 2", (int) size
);
972 sscanf(p_blockno
, "%x", &block
);
974 const char *p_usepage1
= luaL_checklstring(L
, 2, &size
);
976 return returnToLuaWithError(L
, "Wrong size of usePage1, got %d, expected 1", (int) size
);
978 sscanf(p_usepage1
, "%x", &usepage1
);
980 const char *p_override
= luaL_checklstring(L
, 3, &size
);
982 return returnToLuaWithError(L
, "Wrong size of override, got %d, expected 1", (int) size
);
984 sscanf(p_override
, "%x", &override
);
986 const char *p_pwd
= luaL_checklstring(L
, 4, &size
);
992 return returnToLuaWithError(L
, "Wrong size of pwd, got %d , expected 8", (int) size
);
994 sscanf(p_pwd
, "%08x", &password
);
1000 // try reading the config block and verify that PWD bit is set before doing this!
1003 if (!AcquireData(T55x7_PAGE0
, T55x7_CONFIGURATION_BLOCK
, false, 0, 0)) {
1004 return returnToLuaWithError(L
, "Failed to read config block");
1007 if (!t55xxTryDetectModulation(0, true)) { // Default to prev. behaviour (default dl mode and print config)
1008 PrintAndLogEx(NORMAL
, "Safety Check: Could not detect if PWD bit is set in config block. Exits.");
1011 PrintAndLogEx(NORMAL
, "Safety Check: PWD bit is NOT set in config block. Reading without password...");
1016 PrintAndLogEx(NORMAL
, "Safety Check Overridden - proceeding despite risk");
1020 if (!AcquireData(usepage1
, block
, usepwd
, password
, 0)) {
1021 return returnToLuaWithError(L
, "Failed to acquire data from card");
1024 if (!DecodeT55xxBlock()) {
1025 return returnToLuaWithError(L
, "Failed to decode signal");
1028 uint32_t blockData
= 0;
1029 if (GetT55xxBlockData(&blockData
) == false) {
1030 return returnToLuaWithError(L
, "Failed to get actual data");
1033 lua_pushunsigned(L
, blockData
);
1039 static int l_T55xx_detect(lua_State
*L
) {
1040 bool useGB
= false, usepwd
= false, isok
;
1041 uint32_t gb
, password
= 0;
1044 //Check number of arguments
1045 int n
= lua_gettop(L
);
1049 const char *p_gb
= luaL_checklstring(L
, 2, &size
);
1051 return returnToLuaWithError(L
, "Wrong size of useGB, got %d , expected 1", (int) size
);
1053 sscanf(p_gb
, "%u", &gb
);
1054 useGB
= (gb
) ? true : false;
1055 PrintAndLogEx(INFO
, "p_gb size %zu | %c", size
, useGB
? 'Y' : 'N');
1058 const char *p_pwd
= luaL_checklstring(L
, 1, &size
);
1064 return returnToLuaWithError(L
, "Wrong size of pwd, got %d , expected 8", (int) size
);
1066 sscanf(p_pwd
, "%08x", &password
);
1077 isok
= AcquireData(T55x7_PAGE0
, T55x7_CONFIGURATION_BLOCK
, usepwd
, password
, 0);
1078 if (isok
== false) {
1079 return returnToLuaWithError(L
, "Failed to acquire LF signal data");
1083 isok
= t55xxTryDetectModulation(0, true); // Default to prev. behaviour (default dl mode and print config)
1084 if (isok
== false) {
1085 return returnToLuaWithError(L
, "Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");
1088 lua_pushinteger(L
, isok
);
1089 lua_pushstring(L
, "Success");
1094 static int l_em4x05_read(lua_State
*L
) {
1096 bool use_pwd
= false;
1097 uint32_t addr
, password
= 0;
1099 //Check number of arguments
1100 //int n = lua_gettop(L);
1104 const char *p_addr
= luaL_checklstring(L
, 1, &size
);
1105 sscanf(p_addr
, "%u", &addr
);
1108 const char *p_pwd
= luaL_checkstring(L
, 2);
1109 if (p_pwd
== NULL
|| strlen(p_pwd
) == 0) {
1112 if (strlen(p_pwd
) != 8)
1113 return returnToLuaWithError(L
, "Wrong size of password, got %zu , expected 8", strlen(p_pwd
));
1115 sscanf(p_pwd
, "%08x", &password
);
1119 PrintAndLogEx(DEBUG
, "Addr %u", addr
);
1121 PrintAndLogEx(DEBUG
, " Pwd %08X", password
);
1124 int res
= em4x05_read_word_ext(addr
, password
, use_pwd
, &word
);
1125 if (res
!= PM3_SUCCESS
) {
1126 return returnToLuaWithError(L
, "Failed to read EM4x05 data");
1129 lua_pushinteger(L
, word
);
1134 static int l_em4x50_read(lua_State
*L
) {
1138 const char *p_addr
= luaL_checklstring(L
, 1, &size
);
1140 sscanf(p_addr
, "%u", &addr
);
1143 return returnToLuaWithError(L
, "Address out-of-range (0..31) got %u", addr
);
1145 // setting up structures
1147 memset(&etd
, 0x00, sizeof(em4x50_data_t
));
1148 etd
.addr_given
= true;
1149 etd
.addresses
= addr
& 0xFF;
1152 const char *p_pwd
= luaL_checkstring(L
, 2);
1153 if (p_pwd
== NULL
|| strlen(p_pwd
) == 0) {
1154 etd
.pwd_given
= false;
1156 if (strlen(p_pwd
) != 8)
1157 return returnToLuaWithError(L
, "Wrong size of password, got %zu , expected 8", strlen(p_pwd
));
1160 sscanf(p_pwd
, "%08x", &pwd
);
1162 PrintAndLogEx(DEBUG
, " Pwd %08X", pwd
);
1164 etd
.password1
= pwd
;
1165 etd
.pwd_given
= true;
1168 PrintAndLogEx(DEBUG
, "Addr %u", etd
.addresses
& 0xFF);
1170 PrintAndLogEx(DEBUG
, " Pwd %08x", etd
.password1
);
1172 em4x50_word_t words
[EM4X50_NO_WORDS
];
1174 int res
= em4x50_read(&etd
, words
);
1175 if (res
!= PM3_SUCCESS
) {
1176 return returnToLuaWithError(L
, "Failed to read EM4x50 data");
1180 words
[etd
.addresses
& 0xFF].byte
[0] << 24 |
1181 words
[etd
.addresses
& 0xFF].byte
[1] << 16 |
1182 words
[etd
.addresses
& 0xFF].byte
[2] << 8 |
1183 words
[etd
.addresses
& 0xFF].byte
[3]
1185 lua_pushinteger(L
, word
);
1191 static int l_ndefparse(lua_State
*L
) {
1195 //Check number of arguments
1196 int n
= lua_gettop(L
);
1198 return returnToLuaWithError(L
, "You need to supply three parameters");
1201 size_t datalen
= luaL_checknumber(L
, 1);
1202 bool verbose
= luaL_checknumber(L
, 2);
1204 uint8_t *data
= calloc(datalen
, sizeof(uint8_t));
1206 return returnToLuaWithError(L
, "Allocating memory failed");
1210 const char *p_data
= luaL_checklstring(L
, 3, &size
);
1212 if (size
> (datalen
<< 1))
1213 size
= (datalen
<< 1);
1216 for (int i
= 0; i
< size
; i
+= 2) {
1217 sscanf(&p_data
[i
], "%02x", &tmp
);
1218 data
[i
>> 1] = tmp
& 0xFF;
1222 int res
= NDEFDecodeAndPrint(data
, datalen
, verbose
);
1223 lua_pushinteger(L
, res
);
1227 static int l_remark(lua_State
*L
) {
1228 //Check number of arguments
1229 int n
= lua_gettop(L
);
1231 return returnToLuaWithError(L
, "Only one string allowed");
1235 const char *s
= luaL_checklstring(L
, 1, &size
);
1236 int res
= CmdRem(s
);
1237 lua_pushinteger(L
, res
);
1243 // output: full search path to file
1244 static int l_searchfile(lua_State
*L
) {
1245 //Check number of arguments
1246 int n
= lua_gettop(L
);
1248 return returnToLuaWithError(L
, "Only filename and extension");
1253 const char *filename
= luaL_checklstring(L
, 1, &size
);
1255 return returnToLuaWithError(L
, "Must specify filename");
1257 const char *suffix
= luaL_checklstring(L
, 2, &size
);
1259 int res
= searchFile(&path
, "", filename
, suffix
, false);
1260 if (res
!= PM3_SUCCESS
) {
1261 return returnToLuaWithError(L
, "Failed to find file");
1264 lua_pushstring(L
, path
);
1269 static int l_ud(lua_State
*L
) {
1270 const char *ud
= get_my_user_directory();
1271 lua_pushstring(L
, ud
);
1274 static int l_ewd(lua_State
*L
) {
1275 const char *ewd
= get_my_executable_directory();
1276 lua_pushstring(L
, ewd
);
1279 static int l_cwd(lua_State
*L
) {
1281 uint16_t path_len
= FILENAME_MAX
; // should be a good starting point
1282 char *cwd
= (char *)calloc(path_len
, sizeof(uint8_t));
1284 return returnToLuaWithError(L
, "Failed to allocate memory");
1287 while (GetCurrentDir(cwd
, path_len
) == NULL
) {
1288 if (errno
== ERANGE
) { // Need bigger buffer
1289 path_len
+= 10; // if buffer was too small add 10 characters and try again
1290 cwd
= realloc(cwd
, path_len
);
1293 return returnToLuaWithError(L
, "Failed to allocate memory");
1297 return returnToLuaWithError(L
, "Failed to get current working directory");
1300 lua_pushstring(L
, cwd
);
1305 // ref: https://github.com/RfidResearchGroup/proxmark3/issues/891
1306 // redirect LUA's print to Proxmark3 PrintAndLogEx
1307 static int l_printandlogex(lua_State
*L
) {
1308 int n
= lua_gettop(L
);
1309 for (int i
= 1; i
<= n
; i
++) {
1310 if (lua_isstring(L
, i
)) {
1311 PrintAndLogEx(NORMAL
, "%s\t" NOLF
, lua_tostring(L
, i
));
1314 PrintAndLogEx(NORMAL
, "");
1319 * @brief Sets the lua path to include "./lualibs/?.lua", in order for a script to be
1320 * able to do "require('foobar')" if foobar.lua is within lualibs folder.
1321 * Taken from http://stackoverflow.com/questions/4125971/setting-the-global-lua-path-variable-from-c-c
1326 static int setLuaPath(lua_State
*L
, const char *path
) {
1327 lua_getglobal(L
, "package");
1328 lua_getfield(L
, -1, "path"); // get field "path" from table at top of stack (-1)
1329 const char *cur_path
= lua_tostring(L
, -1); // grab path string from top of stack
1330 int requiredLength
= strlen(cur_path
) + strlen(path
) + 10; //A few bytes too many, whatever we can afford it
1331 char *buf
= calloc(requiredLength
, sizeof(char));
1332 snprintf(buf
, requiredLength
, "%s;%s", cur_path
, path
);
1333 lua_pop(L
, 1); // get rid of the string on the stack we just pushed on line 5
1334 lua_pushstring(L
, buf
); // push the new one
1335 lua_setfield(L
, -2, "path"); // set the field "path" in table at -2 with value at top of stack
1336 lua_pop(L
, 1); // get rid of package table from top of stack
1338 return 0; // all done!
1341 int set_pm3_libraries(lua_State
*L
) {
1342 static const luaL_Reg libs
[] = {
1343 {"SendCommandOLD", l_SendCommandOLD
},
1344 {"SendCommandMIX", l_SendCommandMIX
},
1345 {"SendCommandNG", l_SendCommandNG
},
1346 {"GetFromBigBuf", l_GetFromBigBuf
},
1347 {"GetFromFlashMem", l_GetFromFlashMem
},
1348 {"GetFromFlashMemSpiffs", l_GetFromFlashMemSpiffs
},
1349 {"WaitForResponseTimeout", l_WaitForResponseTimeout
},
1350 {"mfDarkside", l_mfDarkside
},
1351 {"foobar", l_foobar
},
1352 {"kbd_enter_pressed", l_kbd_enter_pressed
},
1353 {"clearCommandBuffer", l_clearCommandBuffer
},
1354 {"console", l_CmdConsole
},
1355 {"iso15693_crc", l_iso15693_crc
},
1356 {"iso14443b_crc", l_iso14443b_crc
},
1357 {"aes128_decrypt", l_aes128decrypt_cbc
},
1358 {"aes128_decrypt_ecb", l_aes128decrypt_ecb
},
1359 {"aes128_encrypt", l_aes128encrypt_cbc
},
1360 {"aes128_encrypt_ecb", l_aes128encrypt_ecb
},
1361 {"crc8legic", l_crc8legic
},
1364 {"crc64_ecma182", l_crc64_ecma182
},
1366 {"reveng_models", l_reveng_models
},
1367 {"reveng_runmodel", l_reveng_runmodel
},
1368 {"hardnested", l_hardnested
},
1369 {"detect_prng", l_detect_prng
},
1370 // {"keygen.algoA", l_keygen_algoA},
1371 // {"keygen.algoB", l_keygen_algoB},
1372 // {"keygen.algoC", l_keygen_algoC},
1373 {"keygen_algo_d", l_keygen_algoD
},
1374 {"t55xx_readblock", l_T55xx_readblock
},
1375 {"t55xx_detect", l_T55xx_detect
},
1376 {"ndefparse", l_ndefparse
},
1377 {"fast_push_mode", l_fast_push_mode
},
1378 {"search_file", l_searchfile
},
1383 {"em4x05_read", l_em4x05_read
},
1384 {"em4x50_read", l_em4x50_read
},
1388 lua_pushglobaltable(L
);
1389 // Core library is in this table. Contains '
1390 // this is 'pm3' table
1393 // put the function into the hash table.
1394 for (int i
= 0; libs
[i
].name
; i
++) {
1395 lua_pushcfunction(L
, libs
[i
].func
);
1396 lua_setfield(L
, -2, libs
[i
].name
);//set the name, pop stack
1399 lua_setfield(L
, -2, "core");
1401 // remove the global environment table from the stack
1404 // print redirect here
1405 lua_register(L
, "print", l_printandlogex
);
1407 // add to the LUA_PATH (package.path in lua)
1408 // so we can load scripts from various places:
1409 const char *exec_path
= get_my_executable_directory();
1410 if (exec_path
!= NULL
) {
1411 // from the ./luascripts/ directory
1412 char scripts_path
[strlen(exec_path
) + strlen(LUA_SCRIPTS_SUBDIR
) + strlen(LUA_LIBRARIES_WILDCARD
) + 1];
1413 strcpy(scripts_path
, exec_path
);
1414 strcat(scripts_path
, LUA_SCRIPTS_SUBDIR
);
1415 strcat(scripts_path
, LUA_LIBRARIES_WILDCARD
);
1416 setLuaPath(L
, scripts_path
);
1417 // from the ./lualib/ directory
1418 char libraries_path
[strlen(exec_path
) + strlen(LUA_LIBRARIES_SUBDIR
) + strlen(LUA_LIBRARIES_WILDCARD
) + 1];
1419 strcpy(libraries_path
, exec_path
);
1420 strcat(libraries_path
, LUA_LIBRARIES_SUBDIR
);
1421 strcat(libraries_path
, LUA_LIBRARIES_WILDCARD
);
1422 setLuaPath(L
, libraries_path
);
1424 const char *user_path
= get_my_user_directory();
1425 if (user_path
!= NULL
) {
1426 // from the $HOME/.proxmark3/luascripts/ directory
1427 char scripts_path
[strlen(user_path
) + strlen(PM3_USER_DIRECTORY
) + strlen(LUA_SCRIPTS_SUBDIR
) + strlen(LUA_LIBRARIES_WILDCARD
) + 1];
1428 strcpy(scripts_path
, user_path
);
1429 strcat(scripts_path
, PM3_USER_DIRECTORY
);
1430 strcat(scripts_path
, LUA_SCRIPTS_SUBDIR
);
1431 strcat(scripts_path
, LUA_LIBRARIES_WILDCARD
);
1432 setLuaPath(L
, scripts_path
);
1434 // from the $HOME/.proxmark3/lualib/ directory
1435 char libraries_path
[strlen(user_path
) + strlen(PM3_USER_DIRECTORY
) + strlen(LUA_LIBRARIES_SUBDIR
) + strlen(LUA_LIBRARIES_WILDCARD
) + 1];
1436 strcpy(libraries_path
, user_path
);
1437 strcat(libraries_path
, PM3_USER_DIRECTORY
);
1438 strcat(libraries_path
, LUA_LIBRARIES_SUBDIR
);
1439 strcat(libraries_path
, LUA_LIBRARIES_WILDCARD
);
1440 setLuaPath(L
, libraries_path
);
1443 if (exec_path
!= NULL
) {
1444 // from the $PREFIX/share/proxmark3/luascripts/ directory
1445 char scripts_path
[strlen(exec_path
) + strlen(PM3_SHARE_RELPATH
) + strlen(LUA_SCRIPTS_SUBDIR
) + strlen(LUA_LIBRARIES_WILDCARD
) + 1];
1446 strcpy(scripts_path
, exec_path
);
1447 strcat(scripts_path
, PM3_SHARE_RELPATH
);
1448 strcat(scripts_path
, LUA_SCRIPTS_SUBDIR
);
1449 strcat(scripts_path
, LUA_LIBRARIES_WILDCARD
);
1450 setLuaPath(L
, scripts_path
);
1451 // from the $PREFIX/share/proxmark3/lualib/ directory
1452 char libraries_path
[strlen(exec_path
) + strlen(PM3_SHARE_RELPATH
) + strlen(LUA_LIBRARIES_SUBDIR
) + strlen(LUA_LIBRARIES_WILDCARD
) + 1];
1453 strcpy(libraries_path
, exec_path
);
1454 strcat(libraries_path
, PM3_SHARE_RELPATH
);
1455 strcat(libraries_path
, LUA_LIBRARIES_SUBDIR
);
1456 strcat(libraries_path
, LUA_LIBRARIES_WILDCARD
);
1457 setLuaPath(L
, libraries_path
);