python: adjust help, hide more if no python available, search lua/cmd/py if no extension given

This commit is contained in:
Philippe Teuwen 2020-05-27 01:15:20 +02:00
commit fcfdd92407
2 changed files with 25 additions and 8 deletions

View file

@ -372,10 +372,14 @@ else
endif endif
endif endif
ifeq ($(PYTHON_FOUND),1) ifeq ($(SKIPPYTHON),1)
$(info Python3 library: Python3 v$(shell pkg-config --modversion python3) found, enabled) $(info Python3 library: skipped)
else else
ifeq ($(PYTHON_FOUND),1)
$(info Python3 library: Python3 v$(shell pkg-config --modversion python3) found, enabled)
else
$(info Python3 library: Python3 not found, disabled) $(info Python3 library: Python3 not found, disabled)
endif
endif endif
ifeq ($(SKIPWHEREAMISYSTEM),1) ifeq ($(SKIPWHEREAMISYSTEM),1)

View file

@ -139,8 +139,11 @@ static int CmdScriptList(const char *Cmd) {
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
return searchAndList(PYTHON_SCRIPTS_SUBDIR, ".py"); return searchAndList(PYTHON_SCRIPTS_SUBDIR, ".py");
#else
return ret;
#endif
} }
/** /**
@ -158,7 +161,10 @@ 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);
if (strlen(preferredName) == 0) {
PrintAndLogEx(FAILED, "no script name provided");
return PM3_EINVARG;
}
char *extension_chk; char *extension_chk;
extension_chk = str_dup(preferredName); extension_chk = str_dup(preferredName);
str_lower(extension_chk); str_lower(extension_chk);
@ -329,15 +335,18 @@ static int CmdScriptRun(const char *Cmd) {
#ifdef HAVE_PYTHON #ifdef HAVE_PYTHON
else if (ext == PM3_PY) else if (ext == PM3_PY)
ret = searchFile(&script_path, PYTHON_SCRIPTS_SUBDIR, preferredName, ".py", false); ret = searchFile(&script_path, PYTHON_SCRIPTS_SUBDIR, preferredName, ".py", false);
#endif
else if (ext == PM3_UNSPECIFIED) else if (ext == PM3_UNSPECIFIED)
PrintAndLogEx(FAILED, "Error - can't find %s.[lua|cmd|py]", preferredName); PrintAndLogEx(FAILED, "Error - can't find %s.[lua|cmd|py]", preferredName);
#else
else if (ext == PM3_UNSPECIFIED)
PrintAndLogEx(FAILED, "Error - can't find %s.[lua|cmd]", preferredName);
#endif
free(script_path); free(script_path);
return ret; return ret;
} }
static command_t CommandTable[] = { static command_t CommandTable[] = {
{"help", CmdHelp, AlwaysAvailable, "This help"}, {"help", CmdHelp, AlwaysAvailable, "Usage info"},
{"list", CmdScriptList, AlwaysAvailable, "List available scripts"}, {"list", CmdScriptList, AlwaysAvailable, "List available scripts"},
{"run", CmdScriptRun, AlwaysAvailable, "<name> -- execute a script"}, {"run", CmdScriptRun, AlwaysAvailable, "<name> -- execute a script"},
{NULL, NULL, NULL, NULL} {NULL, NULL, NULL, NULL}
@ -351,7 +360,11 @@ static command_t CommandTable[] = {
*/ */
static int CmdHelp(const char *Cmd) { static int CmdHelp(const char *Cmd) {
(void)Cmd; // Cmd is not used so far (void)Cmd; // Cmd is not used so far
PrintAndLogEx(NORMAL, "This is a feature to run Lua-scripts. You can place Lua-scripts within the luascripts/-folder. "); #ifdef HAVE_PYTHON
PrintAndLogEx(NORMAL, "This is a feature to run Lua/Cmd/Python scripts. You can place scripts within the luascripts/cmdscripts/pyscripts folders. ");
#else
PrintAndLogEx(NORMAL, "This is a feature to run Lua/Cmd scripts. You can place scripts within the luascripts/cmdscripts folders. ");
#endif
return PM3_SUCCESS; return PM3_SUCCESS;
} }