mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 05:13:46 -07:00
add: ndef parsing to LUA
This commit is contained in:
parent
03d6454d95
commit
67e3ac3f54
3 changed files with 50 additions and 5 deletions
|
@ -951,6 +951,45 @@ static int l_T55xx_detect(lua_State *L) {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
static int l_ndefparse(lua_State *L) {
|
||||||
|
|
||||||
|
size_t len = 0, size;
|
||||||
|
|
||||||
|
//Check number of arguments
|
||||||
|
int n = lua_gettop(L);
|
||||||
|
if (n != 3) {
|
||||||
|
return returnToLuaWithError(L, "You need to supply three parameters");
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t datalen = luaL_checknumber(L, 1);
|
||||||
|
bool verbose = luaL_checknumber(L, 2);
|
||||||
|
|
||||||
|
uint8_t *data = calloc(datalen, sizeof(uint8_t));
|
||||||
|
if (data == 0) {
|
||||||
|
return returnToLuaWithError(L, "Allocating memory failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
// data
|
||||||
|
const char *p_data = luaL_checklstring(L, 3, &size);
|
||||||
|
if (size) {
|
||||||
|
if (size > (datalen << 1) )
|
||||||
|
size = (datalen << 1);
|
||||||
|
|
||||||
|
uint32_t tmp;
|
||||||
|
for (int i = 0; i < size; i += 2) {
|
||||||
|
sscanf(&p_data[i], "%02x", &tmp);
|
||||||
|
data[i >> 1] = tmp & 0xFF;
|
||||||
|
len++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int res = NDEFDecodeAndPrint(data, datalen, verbose);
|
||||||
|
lua_pushinteger(L, res);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the lua path to include "./lualibs/?.lua", in order for a script to be
|
* @brief Sets the lua path to include "./lualibs/?.lua", in order for a script to be
|
||||||
* able to do "require('foobar')" if foobar.lua is within lualibs folder.
|
* able to do "require('foobar')" if foobar.lua is within lualibs folder.
|
||||||
|
@ -1009,6 +1048,7 @@ int set_pm3_libraries(lua_State *L) {
|
||||||
{"keygen_algo_d", l_keygen_algoD},
|
{"keygen_algo_d", l_keygen_algoD},
|
||||||
{"t55xx_readblock", l_T55xx_readblock},
|
{"t55xx_readblock", l_T55xx_readblock},
|
||||||
{"t55xx_detect", l_T55xx_detect},
|
{"t55xx_detect", l_T55xx_detect},
|
||||||
|
{"ndefparse" , l_ndefparse},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "cmdhfmfu.h"
|
#include "cmdhfmfu.h"
|
||||||
#include "protocols.h"
|
#include "protocols.h"
|
||||||
#include "cmdlft55xx.h" // read t55xx etc
|
#include "cmdlft55xx.h" // read t55xx etc
|
||||||
|
#include "mifare/ndef.h" // ndef parsing
|
||||||
|
|
||||||
#define LUA_LIBRARIES_DIRECTORY "lualibs/"
|
#define LUA_LIBRARIES_DIRECTORY "lualibs/"
|
||||||
#define LUA_SCRIPTS_DIRECTORY "scripts/"
|
#define LUA_SCRIPTS_DIRECTORY "scripts/"
|
||||||
|
|
|
@ -92,7 +92,7 @@ end
|
||||||
local function getBlock(blockno)
|
local function getBlock(blockno)
|
||||||
local block, err
|
local block, err
|
||||||
local c = Command:newMIX{cmd = cmds.CMD_MIFAREU_READBL, arg1 = blockno, data = 0}
|
local c = Command:newMIX{cmd = cmds.CMD_MIFAREU_READBL, arg1 = blockno, data = 0}
|
||||||
block, err = getblockdata(c:sendMIX(false))
|
block, err = getblockdata(c:scr(false))
|
||||||
if not block then return oops(err) end
|
if not block then return oops(err) end
|
||||||
|
|
||||||
if #block < 32 then
|
if #block < 32 then
|
||||||
|
@ -153,8 +153,9 @@ local function main( args)
|
||||||
end
|
end
|
||||||
-- Block 3 contains number of blocks
|
-- Block 3 contains number of blocks
|
||||||
local b3chars = utils.ConvertHexToBytes(blocks[4]);
|
local b3chars = utils.ConvertHexToBytes(blocks[4]);
|
||||||
local numBlocks = b3chars[3] * 2 + 6
|
local t5tarea = b3chars[3] * 8
|
||||||
print("Number of blocks:", numBlocks)
|
local t5tarea_blocks = t5tarea / 4;
|
||||||
|
print("Number of blocks:", t5tarea_blocks)
|
||||||
|
|
||||||
-- NDEF compliant?
|
-- NDEF compliant?
|
||||||
if b3chars[1] ~= 0xE1 then
|
if b3chars[1] ~= 0xE1 then
|
||||||
|
@ -173,7 +174,7 @@ local function main( args)
|
||||||
removing bytes from 5 to 18 from each answer.
|
removing bytes from 5 to 18 from each answer.
|
||||||
--]]
|
--]]
|
||||||
print('Dumping data...please wait')
|
print('Dumping data...please wait')
|
||||||
for i = 4, numBlocks - 1, 1 do
|
for i = 4, t5tarea_blocks - 1, 1 do
|
||||||
blocks, err = getBlock(i)
|
blocks, err = getBlock(i)
|
||||||
if err then
|
if err then
|
||||||
disconnect();
|
disconnect();
|
||||||
|
@ -190,6 +191,9 @@ local function main( args)
|
||||||
print('Manufacturer', info.manufacturer)
|
print('Manufacturer', info.manufacturer)
|
||||||
print('Type ', info.name)
|
print('Type ', info.name)
|
||||||
|
|
||||||
|
|
||||||
|
core.ndefparse( t5tarea, true, blockData);
|
||||||
|
|
||||||
for k,v in ipairs(blockData) do
|
for k,v in ipairs(blockData) do
|
||||||
print(string.format('Block %02x: %02x %02x %02x %02x', k-1, string.byte(v, 1,4)))
|
print(string.format('Block %02x: %02x %02x %02x %02x', k-1, string.byte(v, 1,4)))
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue