mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-14 02:27:26 -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...
|
||||
|
||||
## [unreleased][unreleased]
|
||||
- Changed scripting string params to accept 1024 chars, Thanks @evildaemond! (@iceman1001)
|
||||
- Added detection for FM11NT021 (@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) {
|
||||
PyObject *m, *d, *v;
|
||||
int set_file_name = 0, ret = -1;
|
||||
|
||||
m = PyImport_AddModule("__main__");
|
||||
if (m == NULL)
|
||||
if (m == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Py_INCREF(m);
|
||||
d = PyModule_GetDict(m);
|
||||
|
||||
if (PyDict_GetItemString(d, "__file__") == NULL) {
|
||||
|
||||
PyObject *f;
|
||||
f = PyUnicode_DecodeFSDefault(filename);
|
||||
if (f == NULL)
|
||||
if (f == NULL) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (PyDict_SetItemString(d, "__file__", f) < 0) {
|
||||
Py_DECREF(f);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (PyDict_SetItemString(d, "__cached__", Py_None) < 0) {
|
||||
Py_DECREF(f);
|
||||
goto done;
|
||||
}
|
||||
|
||||
set_file_name = 1;
|
||||
Py_DECREF(f);
|
||||
}
|
||||
|
||||
v = PyRun_FileExFlags(fp, filename, Py_file_input, d, d, 1, NULL);
|
||||
if (v == NULL) {
|
||||
|
||||
Py_CLEAR(m);
|
||||
|
||||
if (PyErr_ExceptionMatches(PyExc_SystemExit)) {
|
||||
// PyErr_Print() exists if SystemExit so we've to handle it ourselves
|
||||
PyObject *ty = 0, *er = 0, *tr = 0;
|
||||
PyErr_Fetch(&ty, &er, &tr);
|
||||
|
||||
long err = PyLong_AsLong(er);
|
||||
if (err) {
|
||||
PrintAndLogEx(WARNING, "\nScript terminated by " _YELLOW_("SystemExit %li"), err);
|
||||
} else {
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
Py_DECREF(ty);
|
||||
Py_DECREF(er);
|
||||
Py_DECREF(er);
|
||||
PyErr_Clear();
|
||||
goto done;
|
||||
|
||||
} else {
|
||||
PyErr_Print();
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
|
||||
Py_DECREF(v);
|
||||
ret = 0;
|
||||
|
||||
done:
|
||||
if (set_file_name && PyDict_DelItemString(d, "__file__"))
|
||||
if (set_file_name && PyDict_DelItemString(d, "__file__")) {
|
||||
PyErr_Clear();
|
||||
}
|
||||
Py_XDECREF(m);
|
||||
return ret;
|
||||
}
|
||||
|
@ -129,16 +147,20 @@ static int split(char *str, char **arr) {
|
|||
int word_cnt = 0;
|
||||
|
||||
while (1) {
|
||||
|
||||
while (isspace(str[begin_index])) {
|
||||
++begin_index;
|
||||
}
|
||||
|
||||
if (str[begin_index] == '\0') {
|
||||
break;
|
||||
}
|
||||
|
||||
int end_index = begin_index;
|
||||
while (str[end_index] && !isspace(str[end_index])) {
|
||||
++end_index;
|
||||
}
|
||||
|
||||
int len = end_index - begin_index;
|
||||
char *tmp = calloc(len + 1, sizeof(char));
|
||||
memcpy(tmp, &str[begin_index], len);
|
||||
|
@ -227,13 +249,16 @@ static int CmdScriptList(const char *Cmd) {
|
|||
CLIParserFree(ctx);
|
||||
PrintAndLogEx(NORMAL, "\n" _YELLOW_("[ Lua scripts ]"));
|
||||
int ret = searchAndList(LUA_SCRIPTS_SUBDIR, ".lua");
|
||||
if (ret != PM3_SUCCESS)
|
||||
if (ret != PM3_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
PrintAndLogEx(NORMAL, "\n" _YELLOW_("[ Cmd scripts ]"));
|
||||
ret = searchAndList(CMD_SCRIPTS_SUBDIR, ".cmd");
|
||||
if (ret != PM3_SUCCESS)
|
||||
if (ret != PM3_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef HAVE_PYTHON
|
||||
PrintAndLogEx(NORMAL, "\n" _YELLOW_("[ Python scripts ]"));
|
||||
return searchAndList(PYTHON_SCRIPTS_SUBDIR, ".py");
|
||||
|
@ -265,19 +290,19 @@ static int CmdScriptRun(const char *Cmd) {
|
|||
};
|
||||
|
||||
int fnlen = 0;
|
||||
char filename[128] = {0};
|
||||
char filename[FILE_PATH_SIZE] = {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
|
||||
// since we don't want to use "-f" for script filename,
|
||||
// and be able to send in parameters into script meanwhile
|
||||
// being able to "-h" here too.
|
||||
if ((strlen(filename) == 0) ||
|
||||
(strcmp(filename, "-h") == 0) ||
|
||||
(strcmp(filename, "--help") == 0)) {
|
||||
(strcmp(filename, "-h") == 0) ||
|
||||
(strcmp(filename, "--help") == 0)) {
|
||||
ctx->argtable = argtable;
|
||||
ctx->argtableLen = arg_getsize(argtable);
|
||||
CLIParserPrintHelp(ctx);
|
||||
|
@ -428,7 +453,7 @@ static int CmdScriptRun(const char *Cmd) {
|
|||
#endif
|
||||
|
||||
//int argc, char ** argv
|
||||
char *argv[128];
|
||||
char *argv[FILE_PATH_SIZE];
|
||||
argv[0] = script_path;
|
||||
int argc = split(arguments, &argv[1]);
|
||||
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 10
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
#include "iso7816/iso7816core.h" // ISODEPSTATE
|
||||
|
||||
static int returnToLuaWithError(lua_State *L, const char *fmt, ...) {
|
||||
char buffer[200];
|
||||
char buffer[1024];
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
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
|
||||
if (enable == false) {
|
||||
SendCommandNG(CMD_PING, NULL, 0);
|
||||
if (!WaitForResponseTimeout(CMD_PING, NULL, 1000)) {
|
||||
if (WaitForResponseTimeout(CMD_PING, NULL, 1000) == false) {
|
||||
PrintAndLogEx(WARNING, "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
|
||||
int n = lua_gettop(L);
|
||||
if (n != 5)
|
||||
if (n != 5) {
|
||||
return returnToLuaWithError(L, "You need to supply five parameters");
|
||||
}
|
||||
|
||||
// parse input
|
||||
cmd = luaL_checknumber(L, 1);
|
||||
|
@ -1441,7 +1442,7 @@ int set_pm3_libraries(lua_State *L) {
|
|||
// put the function into the hash table.
|
||||
for (int i = 0; libs[i].name; i++) {
|
||||
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'
|
||||
lua_setfield(L, -2, "core");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue