]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdscript.c
Paradox clone functionality implemented (#747)
[proxmark3-svn] / client / cmdscript.c
index 8c1acf27104aa8443581c5b9b0245e4c2093841f..7b0e9000d6b66acfbff31790008d54c768f4aaa9 100644 (file)
@@ -17,7 +17,6 @@
 
 #include "proxmark3.h"
 #include "scripting.h"
-#include "data.h"
 #include "ui.h"
 #include "graph.h"
 #include "cmdparser.h"
 #include "cmdscript.h"
 #include "cmdhfmf.h"
 #include "pm3_binlib.h"
-
+#include "pm3_bitlib.h"
 #include <lua.h>
 #include <lualib.h>
 #include <lauxlib.h>
 
-
 static int CmdHelp(const char *Cmd);
 static int CmdList(const char *Cmd);
 static int CmdRun(const char *Cmd);
@@ -77,13 +75,19 @@ int CmdList(const char *Cmd)
 {
     DIR *dp;
     struct dirent *ep;
-    dp = opendir ("./scripts/");
+       char const * exedir = get_my_executable_directory();
+       if (exedir == NULL)
+           return 0;
+       char script_directory_path[strlen(exedir) + strlen(LUA_SCRIPTS_DIRECTORY) + 1];
+       strcpy(script_directory_path, exedir);
+       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"))
+            if(str_ends_with(ep->d_name, ".lua"))
                 PrintAndLog("%-16s %s", ep->d_name, "A script file");
         }
         (void) closedir (dp);
@@ -133,6 +137,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,17 +153,19 @@ 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)
     {
 
Impressum, Datenschutz