mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2024-09-22 00:06:13 +08:00
chg, clean up
This commit is contained in:
parent
1781837bf9
commit
125e05ec0e
|
@ -157,22 +157,22 @@ static int CmdScriptRun(const char *Cmd) {
|
||||||
int arg_len = 0;
|
int arg_len = 0;
|
||||||
static uint8_t luascriptfile_idx = 0;
|
static uint8_t luascriptfile_idx = 0;
|
||||||
sscanf(Cmd, "%127s%n %255[^\n\r]%n", preferredName, &name_len, arguments, &arg_len);
|
sscanf(Cmd, "%127s%n %255[^\n\r]%n", preferredName, &name_len, arguments, &arg_len);
|
||||||
|
|
||||||
char *extension_chk;
|
char *extension_chk;
|
||||||
extension_chk = str_dup(preferredName);
|
extension_chk = str_dup(preferredName);
|
||||||
str_lower(extension_chk);
|
str_lower(extension_chk);
|
||||||
pm3_scriptfile_t ext = PM3_LUA;
|
pm3_scriptfile_t ext = PM3_LUA;
|
||||||
|
|
||||||
if (str_endswith(extension_chk, ".cmd")) {
|
if (str_endswith(extension_chk, ".cmd")) {
|
||||||
ext = PM3_CMD;
|
ext = PM3_CMD;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_PYTHON
|
#ifdef HAVE_PYTHON
|
||||||
if (str_endswith(extension_chk, ".py")) {
|
if (str_endswith(extension_chk, ".py")) {
|
||||||
ext = PM3_PY;
|
ext = PM3_PY;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char *script_path = NULL;
|
char *script_path = NULL;
|
||||||
if ((ext == PM3_LUA) && (searchFile(&script_path, LUA_SCRIPTS_SUBDIR, preferredName, ".lua", true) == PM3_SUCCESS)) {
|
if ((ext == PM3_LUA) && (searchFile(&script_path, LUA_SCRIPTS_SUBDIR, preferredName, ".lua", true) == PM3_SUCCESS)) {
|
||||||
int error;
|
int error;
|
||||||
|
@ -241,8 +241,8 @@ static int CmdScriptRun(const char *Cmd) {
|
||||||
free(script_path);
|
free(script_path);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
For apt (Ubuntu, Debian...):
|
For apt (Ubuntu, Debian...):
|
||||||
sudo apt-get install python3-dev # for python3.x installs
|
sudo apt-get install python3-dev # for python3.x installs
|
||||||
|
|
||||||
|
@ -264,13 +264,12 @@ static int CmdScriptRun(const char *Cmd) {
|
||||||
|
|
||||||
For apt-cyg (Cygwin...):
|
For apt-cyg (Cygwin...):
|
||||||
apt-cyg install python3-devel # for python3.x installs
|
apt-cyg install python3-devel # for python3.x installs
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_PYTHON
|
#ifdef HAVE_PYTHON
|
||||||
|
|
||||||
if ((ext == PM3_PY) && (searchFile(&script_path, PYTHON_SCRIPTS_SUBDIR, preferredName, ".py", true) == PM3_SUCCESS)) {
|
if ((ext == PM3_PY) && (searchFile(&script_path, PYTHON_SCRIPTS_SUBDIR, preferredName, ".py", true) == PM3_SUCCESS)) {
|
||||||
|
|
||||||
PrintAndLogEx(SUCCESS, "executing python " _YELLOW_("%s"), script_path);
|
PrintAndLogEx(SUCCESS, "executing python " _YELLOW_("%s"), script_path);
|
||||||
PrintAndLogEx(SUCCESS, "args " _YELLOW_("'%s'"), arguments);
|
PrintAndLogEx(SUCCESS, "args " _YELLOW_("'%s'"), arguments);
|
||||||
|
|
||||||
|
@ -288,7 +287,6 @@ static int CmdScriptRun(const char *Cmd) {
|
||||||
//int argc, char ** argv
|
//int argc, char ** argv
|
||||||
char *argv[128];
|
char *argv[128];
|
||||||
int argc = split(arguments, argv);
|
int argc = split(arguments, argv);
|
||||||
|
|
||||||
wchar_t *py_args[argc];
|
wchar_t *py_args[argc];
|
||||||
py_args[0] = Py_DecodeLocale(preferredName, NULL);
|
py_args[0] = Py_DecodeLocale(preferredName, NULL);
|
||||||
for (int i = 0; i < argc; i++) {
|
for (int i = 0; i < argc; i++) {
|
||||||
|
@ -296,28 +294,24 @@ static int CmdScriptRun(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PySys_SetArgv(argc+1, py_args);
|
PySys_SetArgv(argc+1, py_args);
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
for (int i = 0; i < argc; ++i) {
|
for (int i = 0; i < argc; ++i) {
|
||||||
free(argv[i]);
|
free(argv[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup search paths.
|
// setup search paths.
|
||||||
set_python_paths();
|
set_python_paths();
|
||||||
|
|
||||||
FILE *f = fopen(script_path, "r");
|
FILE *f = fopen(script_path, "r");
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
PrintAndLogEx(ERR, "Could open file " _YELLOW_("%s"), script_path);
|
PrintAndLogEx(ERR, "Could open file " _YELLOW_("%s"), script_path);
|
||||||
free(script_path);
|
free(script_path);
|
||||||
return PM3_ESOFT;
|
return PM3_ESOFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
// to we need to manually call all importmodules?
|
|
||||||
//PyImport_ImportModule("requests");
|
|
||||||
PyRun_SimpleFileExFlags(f, preferredName, 1, NULL);
|
PyRun_SimpleFileExFlags(f, preferredName, 1, NULL);
|
||||||
|
|
||||||
Py_Finalize();
|
Py_Finalize();
|
||||||
|
|
||||||
PyMem_RawFree(program);
|
PyMem_RawFree(program);
|
||||||
free(script_path);
|
free(script_path);
|
||||||
PrintAndLogEx(SUCCESS, "\nfinished " _YELLOW_("%s"), preferredName);
|
PrintAndLogEx(SUCCESS, "\nfinished " _YELLOW_("%s"), preferredName);
|
||||||
|
|
Loading…
Reference in a new issue