X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/0a85b72549d294b127c3224610870be4f9382f9a..1b6cc9746e25e93b9c8d76e193af4796c942b167:/client/cmdscript.c diff --git a/client/cmdscript.c b/client/cmdscript.c index 8c1acf27..760d74e1 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -25,12 +25,11 @@ #include "cmdscript.h" #include "cmdhfmf.h" #include "pm3_binlib.h" - +#include "pm3_bitlib.h" #include #include #include - static int CmdHelp(const char *Cmd); static int CmdList(const char *Cmd); static int CmdRun(const char *Cmd); @@ -72,36 +71,42 @@ int CmdHelp(const char * Cmd) * Generate list of available commands, what it does is * generate a file listing of the script-directory for files * ending with .lua +* */ int CmdList(const char *Cmd) { DIR *dp; struct dirent *ep; - dp = opendir ("./scripts/"); + char script_directory_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; + strcpy(script_directory_path, get_my_executable_directory()); + strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY); + dp = opendir(script_directory_path); if (dp != NULL) { - while ((ep = readdir (dp)) != NULL) - { - if(ep->d_name != NULL && str_ends_with(ep->d_name, ".lua")) - PrintAndLog("%-16s %s", ep->d_name, "A script file"); - } - (void) closedir (dp); + while ((ep = readdir (dp)) != NULL) + { + if(str_ends_with(ep->d_name, ".lua")) + PrintAndLog("%-21s %s", ep->d_name, "A script file"); + } + (void) closedir (dp); } else PrintAndLog ("Couldn't open the scripts-directory"); return 0; } + + /** * Finds a matching script-file * @brief CmdScript * @param Cmd * @return */ -int CmdScript(const char *Cmd) -{ - CmdsParse(CommandTable, Cmd); - return 0; +int CmdScript(const char *Cmd) { + clearCommandBuffer(); + CmdsParse(CommandTable, Cmd); + return 0; } /** * Utility to check the ending of a string (used to check file suffix) @@ -133,6 +138,8 @@ int CmdRun(const char *Cmd) //Add the 'bin' library set_bin_library(lua_state); + //Add the 'bit' library + set_bit_library(lua_state); char script_name[128] = {0}; char arguments[256] = {0}; @@ -147,20 +154,21 @@ int CmdRun(const char *Cmd) suffix = ".lua"; } - char buf[256]; - snprintf(buf, sizeof buf, "./scripts/%s%s", script_name, suffix); - - printf("--- Executing: %s, args'%s'\n",buf,arguments); + char script_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1]; + strcpy(script_path, get_my_executable_directory()); + strcat(script_path, LUA_SCRIPTS_DIRECTORY); + strcat(script_path, script_name); + strcat(script_path, suffix); + printf("--- Executing: %s%s, args '%s'\n", script_name, suffix, arguments); // run the Lua script - int error = luaL_loadfile(lua_state, buf); + int error = luaL_loadfile(lua_state, script_path); if(!error) { - lua_pushstring(lua_state, arguments); lua_setglobal(lua_state, "args");