mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-02-28 18:14:39 +08:00
hook up 4x50 read for lua
This commit is contained in:
parent
8bb762dc5b
commit
df5c635a7d
1 changed files with 68 additions and 5 deletions
|
@ -37,6 +37,8 @@
|
||||||
#include "cmdlf.h" // lf_config
|
#include "cmdlf.h" // lf_config
|
||||||
#include "generator.h"
|
#include "generator.h"
|
||||||
#include "cmdlfem4x.h" // read 4305
|
#include "cmdlfem4x.h" // read 4305
|
||||||
|
#include "cmdlfem4x50.h" // read 4350
|
||||||
|
#include "em4x50.h" // 4x50 structs
|
||||||
|
|
||||||
static int returnToLuaWithError(lua_State *L, const char *fmt, ...) {
|
static int returnToLuaWithError(lua_State *L, const char *fmt, ...) {
|
||||||
char buffer[200];
|
char buffer[200];
|
||||||
|
@ -1088,7 +1090,7 @@ static int l_T55xx_detect(lua_State *L) {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
// 4305
|
||||||
static int l_em4x05_read(lua_State *L) {
|
static int l_em4x05_read(lua_State *L) {
|
||||||
|
|
||||||
bool use_pwd = false;
|
bool use_pwd = false;
|
||||||
|
@ -1103,12 +1105,12 @@ static int l_em4x05_read(lua_State *L) {
|
||||||
sscanf(p_addr, "%u", &addr);
|
sscanf(p_addr, "%u", &addr);
|
||||||
|
|
||||||
// get password
|
// get password
|
||||||
const char *p_pwd = luaL_checklstring(L, 2, &size);
|
const char *p_pwd = luaL_checkstring(L, 2);
|
||||||
if (size == 0) {
|
if (p_pwd == NULL || strlen(p_pwd) == 0 ) {
|
||||||
use_pwd = false;
|
use_pwd = false;
|
||||||
} else {
|
} else {
|
||||||
if (size != 8)
|
if (strlen(p_pwd) != 8)
|
||||||
return returnToLuaWithError(L, "Wrong size of password, got %zu , expected 8", size);
|
return returnToLuaWithError(L, "Wrong size of password, got %zu , expected 8", strlen(p_pwd));
|
||||||
|
|
||||||
sscanf(p_pwd, "%08x", &password);
|
sscanf(p_pwd, "%08x", &password);
|
||||||
use_pwd = true;
|
use_pwd = true;
|
||||||
|
@ -1128,6 +1130,66 @@ static int l_em4x05_read(lua_State *L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 4350
|
||||||
|
static int l_em4x50_read(lua_State *L) {
|
||||||
|
|
||||||
|
// get addr
|
||||||
|
size_t size = 0;
|
||||||
|
const char *p_addr = luaL_checklstring(L, 1, &size);
|
||||||
|
uint32_t addr = 0;
|
||||||
|
sscanf(p_addr, "%u", &addr);
|
||||||
|
|
||||||
|
if (addr > 33)
|
||||||
|
return returnToLuaWithError(L, "Address out-of-range (0..33) got %zu", addr);
|
||||||
|
|
||||||
|
// setting up structures
|
||||||
|
em4x50_data_t etd;
|
||||||
|
memset(&etd, 0x00, sizeof(em4x50_data_t));
|
||||||
|
etd.addr_given = true;
|
||||||
|
etd.address = addr & 0xFF;
|
||||||
|
etd.newpwd_given = false;
|
||||||
|
|
||||||
|
// get password
|
||||||
|
const char *p_pwd = luaL_checkstring(L, 2);
|
||||||
|
if (p_pwd == NULL || strlen(p_pwd) == 0) {
|
||||||
|
etd.pwd_given = false;
|
||||||
|
} else {
|
||||||
|
if (strlen(p_pwd) != 8)
|
||||||
|
return returnToLuaWithError(L, "Wrong size of password, got %zu , expected 8", strlen(p_pwd));
|
||||||
|
|
||||||
|
uint32_t pwd = 0;
|
||||||
|
sscanf(p_pwd, "%08x", &pwd);
|
||||||
|
|
||||||
|
PrintAndLogEx(DEBUG, " Pwd %08X", pwd);
|
||||||
|
|
||||||
|
etd.password[0] = pwd & 0xFF;
|
||||||
|
etd.password[1] = (pwd >> 8) & 0xFF;
|
||||||
|
etd.password[2] = (pwd >> 16) & 0xFF;
|
||||||
|
etd.password[3] = (pwd >> 24) & 0xFF;
|
||||||
|
etd.pwd_given = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrintAndLogEx(DEBUG, "Addr %u", etd.address);
|
||||||
|
if (etd.pwd_given)
|
||||||
|
PrintAndLogEx(DEBUG, " Pwd %08X", etd.password);
|
||||||
|
|
||||||
|
em4x50_word_t words[EM4X50_NO_WORDS];
|
||||||
|
|
||||||
|
int res = em4x50_read(&etd, words, false);
|
||||||
|
if (res != PM3_SUCCESS) {
|
||||||
|
return returnToLuaWithError(L, "Failed to read EM4x50 data");
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t word = (
|
||||||
|
words[etd.address].byte[0] << 24 |
|
||||||
|
words[etd.address].byte[1] << 16 |
|
||||||
|
words[etd.address].byte[2] << 8 |
|
||||||
|
words[etd.address].byte[3]
|
||||||
|
);
|
||||||
|
lua_pushinteger(L, word);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
static int l_ndefparse(lua_State *L) {
|
static int l_ndefparse(lua_State *L) {
|
||||||
|
|
||||||
|
@ -1320,6 +1382,7 @@ int set_pm3_libraries(lua_State *L) {
|
||||||
{"ud", l_ud},
|
{"ud", l_ud},
|
||||||
{"rem", l_remark},
|
{"rem", l_remark},
|
||||||
{"em4x05_read", l_em4x05_read},
|
{"em4x05_read", l_em4x05_read},
|
||||||
|
{"em4x50_read", l_em4x50_read},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue