mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 13:00:42 -07:00
the string params for scripting was limited to 256 chars, this has been increased to 1024 chars, allowing for 512 hex bytes to be read. remember spaces will count as a char when using the quotes. Also increased file name array to match the rest of the pm3 client length.
This commit is contained in:
parent
781bde832c
commit
a18ec2b54e
3 changed files with 42 additions and 15 deletions
|
@ -3,6 +3,7 @@ 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...
|
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]
|
## [unreleased][unreleased]
|
||||||
|
- Changed scripting string params to accept 1024 chars, Thanks @evildaemond! (@iceman1001)
|
||||||
- Added detection for FM11NT021 (@iceman1001)
|
- Added detection for FM11NT021 (@iceman1001)
|
||||||
- Added detection of a magic NTAG 215 (@iceman1001)
|
- Added detection of a magic NTAG 215 (@iceman1001)
|
||||||
|
|
||||||
|
|
|
@ -55,55 +55,73 @@ extern PyObject *PyInit__pm3(void);
|
||||||
static int Pm3PyRun_SimpleFileNoExit(FILE *fp, const char *filename) {
|
static int Pm3PyRun_SimpleFileNoExit(FILE *fp, const char *filename) {
|
||||||
PyObject *m, *d, *v;
|
PyObject *m, *d, *v;
|
||||||
int set_file_name = 0, ret = -1;
|
int set_file_name = 0, ret = -1;
|
||||||
|
|
||||||
m = PyImport_AddModule("__main__");
|
m = PyImport_AddModule("__main__");
|
||||||
if (m == NULL)
|
if (m == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
Py_INCREF(m);
|
Py_INCREF(m);
|
||||||
d = PyModule_GetDict(m);
|
d = PyModule_GetDict(m);
|
||||||
|
|
||||||
if (PyDict_GetItemString(d, "__file__") == NULL) {
|
if (PyDict_GetItemString(d, "__file__") == NULL) {
|
||||||
|
|
||||||
PyObject *f;
|
PyObject *f;
|
||||||
f = PyUnicode_DecodeFSDefault(filename);
|
f = PyUnicode_DecodeFSDefault(filename);
|
||||||
if (f == NULL)
|
if (f == NULL) {
|
||||||
goto done;
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
if (PyDict_SetItemString(d, "__file__", f) < 0) {
|
if (PyDict_SetItemString(d, "__file__", f) < 0) {
|
||||||
Py_DECREF(f);
|
Py_DECREF(f);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PyDict_SetItemString(d, "__cached__", Py_None) < 0) {
|
if (PyDict_SetItemString(d, "__cached__", Py_None) < 0) {
|
||||||
Py_DECREF(f);
|
Py_DECREF(f);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
set_file_name = 1;
|
set_file_name = 1;
|
||||||
Py_DECREF(f);
|
Py_DECREF(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
v = PyRun_FileExFlags(fp, filename, Py_file_input, d, d, 1, NULL);
|
v = PyRun_FileExFlags(fp, filename, Py_file_input, d, d, 1, NULL);
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
|
|
||||||
Py_CLEAR(m);
|
Py_CLEAR(m);
|
||||||
|
|
||||||
if (PyErr_ExceptionMatches(PyExc_SystemExit)) {
|
if (PyErr_ExceptionMatches(PyExc_SystemExit)) {
|
||||||
// PyErr_Print() exists if SystemExit so we've to handle it ourselves
|
// PyErr_Print() exists if SystemExit so we've to handle it ourselves
|
||||||
PyObject *ty = 0, *er = 0, *tr = 0;
|
PyObject *ty = 0, *er = 0, *tr = 0;
|
||||||
PyErr_Fetch(&ty, &er, &tr);
|
PyErr_Fetch(&ty, &er, &tr);
|
||||||
|
|
||||||
long err = PyLong_AsLong(er);
|
long err = PyLong_AsLong(er);
|
||||||
if (err) {
|
if (err) {
|
||||||
PrintAndLogEx(WARNING, "\nScript terminated by " _YELLOW_("SystemExit %li"), err);
|
PrintAndLogEx(WARNING, "\nScript terminated by " _YELLOW_("SystemExit %li"), err);
|
||||||
} else {
|
} else {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_DECREF(ty);
|
Py_DECREF(ty);
|
||||||
Py_DECREF(er);
|
Py_DECREF(er);
|
||||||
Py_DECREF(er);
|
Py_DECREF(er);
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
PyErr_Print();
|
PyErr_Print();
|
||||||
}
|
}
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (set_file_name && PyDict_DelItemString(d, "__file__"))
|
if (set_file_name && PyDict_DelItemString(d, "__file__")) {
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
|
}
|
||||||
Py_XDECREF(m);
|
Py_XDECREF(m);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -129,16 +147,20 @@ static int split(char *str, char **arr) {
|
||||||
int word_cnt = 0;
|
int word_cnt = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
while (isspace(str[begin_index])) {
|
while (isspace(str[begin_index])) {
|
||||||
++begin_index;
|
++begin_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str[begin_index] == '\0') {
|
if (str[begin_index] == '\0') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int end_index = begin_index;
|
int end_index = begin_index;
|
||||||
while (str[end_index] && !isspace(str[end_index])) {
|
while (str[end_index] && !isspace(str[end_index])) {
|
||||||
++end_index;
|
++end_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
int len = end_index - begin_index;
|
int len = end_index - begin_index;
|
||||||
char *tmp = calloc(len + 1, sizeof(char));
|
char *tmp = calloc(len + 1, sizeof(char));
|
||||||
memcpy(tmp, &str[begin_index], len);
|
memcpy(tmp, &str[begin_index], len);
|
||||||
|
@ -227,13 +249,16 @@ static int CmdScriptList(const char *Cmd) {
|
||||||
CLIParserFree(ctx);
|
CLIParserFree(ctx);
|
||||||
PrintAndLogEx(NORMAL, "\n" _YELLOW_("[ Lua scripts ]"));
|
PrintAndLogEx(NORMAL, "\n" _YELLOW_("[ Lua scripts ]"));
|
||||||
int ret = searchAndList(LUA_SCRIPTS_SUBDIR, ".lua");
|
int ret = searchAndList(LUA_SCRIPTS_SUBDIR, ".lua");
|
||||||
if (ret != PM3_SUCCESS)
|
if (ret != PM3_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, "\n" _YELLOW_("[ Cmd scripts ]"));
|
PrintAndLogEx(NORMAL, "\n" _YELLOW_("[ Cmd scripts ]"));
|
||||||
ret = searchAndList(CMD_SCRIPTS_SUBDIR, ".cmd");
|
ret = searchAndList(CMD_SCRIPTS_SUBDIR, ".cmd");
|
||||||
if (ret != PM3_SUCCESS)
|
if (ret != PM3_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_PYTHON
|
#ifdef HAVE_PYTHON
|
||||||
PrintAndLogEx(NORMAL, "\n" _YELLOW_("[ Python scripts ]"));
|
PrintAndLogEx(NORMAL, "\n" _YELLOW_("[ Python scripts ]"));
|
||||||
return searchAndList(PYTHON_SCRIPTS_SUBDIR, ".py");
|
return searchAndList(PYTHON_SCRIPTS_SUBDIR, ".py");
|
||||||
|
@ -265,19 +290,19 @@ static int CmdScriptRun(const char *Cmd) {
|
||||||
};
|
};
|
||||||
|
|
||||||
int fnlen = 0;
|
int fnlen = 0;
|
||||||
char filename[128] = {0};
|
char filename[FILE_PATH_SIZE] = {0};
|
||||||
int arg_len = 0;
|
int arg_len = 0;
|
||||||
char arguments[256] = {0};
|
char arguments[1025] = {0};
|
||||||
|
|
||||||
sscanf(Cmd, "%127s%n %255[^\n\r]%n", filename, &fnlen, arguments, &arg_len);
|
sscanf(Cmd, "%999s%n %1024[^\n\r]%n", filename, &fnlen, arguments, &arg_len);
|
||||||
|
|
||||||
// hack
|
// hack
|
||||||
// since we don't want to use "-f" for script filename,
|
// since we don't want to use "-f" for script filename,
|
||||||
// and be able to send in parameters into script meanwhile
|
// and be able to send in parameters into script meanwhile
|
||||||
// being able to "-h" here too.
|
// being able to "-h" here too.
|
||||||
if ((strlen(filename) == 0) ||
|
if ((strlen(filename) == 0) ||
|
||||||
(strcmp(filename, "-h") == 0) ||
|
(strcmp(filename, "-h") == 0) ||
|
||||||
(strcmp(filename, "--help") == 0)) {
|
(strcmp(filename, "--help") == 0)) {
|
||||||
ctx->argtable = argtable;
|
ctx->argtable = argtable;
|
||||||
ctx->argtableLen = arg_getsize(argtable);
|
ctx->argtableLen = arg_getsize(argtable);
|
||||||
CLIParserPrintHelp(ctx);
|
CLIParserPrintHelp(ctx);
|
||||||
|
@ -428,7 +453,7 @@ static int CmdScriptRun(const char *Cmd) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//int argc, char ** argv
|
//int argc, char ** argv
|
||||||
char *argv[128];
|
char *argv[FILE_PATH_SIZE];
|
||||||
argv[0] = script_path;
|
argv[0] = script_path;
|
||||||
int argc = split(arguments, &argv[1]);
|
int argc = split(arguments, &argv[1]);
|
||||||
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 10
|
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 10
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
#include "iso7816/iso7816core.h" // ISODEPSTATE
|
#include "iso7816/iso7816core.h" // ISODEPSTATE
|
||||||
|
|
||||||
static int returnToLuaWithError(lua_State *L, const char *fmt, ...) {
|
static int returnToLuaWithError(lua_State *L, const char *fmt, ...) {
|
||||||
char buffer[200];
|
char buffer[1024];
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
vsnprintf(buffer, sizeof(buffer), fmt, args);
|
vsnprintf(buffer, sizeof(buffer), fmt, args);
|
||||||
|
@ -83,7 +83,7 @@ static int l_fast_push_mode(lua_State *L) {
|
||||||
// Disable fast mode and send a dummy command to make it effective
|
// Disable fast mode and send a dummy command to make it effective
|
||||||
if (enable == false) {
|
if (enable == false) {
|
||||||
SendCommandNG(CMD_PING, NULL, 0);
|
SendCommandNG(CMD_PING, NULL, 0);
|
||||||
if (!WaitForResponseTimeout(CMD_PING, NULL, 1000)) {
|
if (WaitForResponseTimeout(CMD_PING, NULL, 1000) == false) {
|
||||||
PrintAndLogEx(WARNING, "command execution time out");
|
PrintAndLogEx(WARNING, "command execution time out");
|
||||||
return returnToLuaWithError(L, "command execution time out");
|
return returnToLuaWithError(L, "command execution time out");
|
||||||
}
|
}
|
||||||
|
@ -113,8 +113,9 @@ static int l_SendCommandMIX(lua_State *L) {
|
||||||
|
|
||||||
// check number of arguments
|
// check number of arguments
|
||||||
int n = lua_gettop(L);
|
int n = lua_gettop(L);
|
||||||
if (n != 5)
|
if (n != 5) {
|
||||||
return returnToLuaWithError(L, "You need to supply five parameters");
|
return returnToLuaWithError(L, "You need to supply five parameters");
|
||||||
|
}
|
||||||
|
|
||||||
// parse input
|
// parse input
|
||||||
cmd = luaL_checknumber(L, 1);
|
cmd = luaL_checknumber(L, 1);
|
||||||
|
@ -1441,7 +1442,7 @@ int set_pm3_libraries(lua_State *L) {
|
||||||
// put the function into the hash table.
|
// put the function into the hash table.
|
||||||
for (int i = 0; libs[i].name; i++) {
|
for (int i = 0; libs[i].name; i++) {
|
||||||
lua_pushcfunction(L, libs[i].func);
|
lua_pushcfunction(L, libs[i].func);
|
||||||
lua_setfield(L, -2, libs[i].name);//set the name, pop stack
|
lua_setfield(L, -2, libs[i].name); // set the name, pop stack
|
||||||
}
|
}
|
||||||
// Name of 'core'
|
// Name of 'core'
|
||||||
lua_setfield(L, -2, "core");
|
lua_setfield(L, -2, "core");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue