From 595b8a1885c131b3d3d9dbe79aa27518592e47b6 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 22 Aug 2019 19:36:20 +0200 Subject: [PATCH] introduce PREFIX for pm3 system directory and move to common.h --- client/cmdscript.c | 16 ++++++++-------- client/scripting.c | 18 +++++++++--------- client/scripting.h | 2 -- include/common.h | 6 ++++++ 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/client/cmdscript.c b/client/cmdscript.c index e506b1a37..9fdc3c0af 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -90,15 +90,15 @@ static int CmdScriptList(const char *Cmd) { } char *userpath = getenv("HOME"); if (userpath != NULL) { - char script_directory_path[strlen(userpath) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; + char script_directory_path[strlen(userpath) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; strcpy(script_directory_path, userpath); - strcat(script_directory_path, LUA_PM3_USER_DIRECTORY); + strcat(script_directory_path, PM3_USER_DIRECTORY); strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY); scriptlist(script_directory_path); } { - char script_directory_path[strlen(LUA_PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; - strcpy(script_directory_path, LUA_PM3_SYSTEM_DIRECTORY); + char script_directory_path[strlen(PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; + strcpy(script_directory_path, PM3_SYSTEM_DIRECTORY); strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY); scriptlist(script_directory_path); } @@ -161,9 +161,9 @@ static int CmdScriptRun(const char *Cmd) { } char *userpath = getenv("HOME"); if ((!found) && (userpath != NULL)) { - char script_path[strlen(userpath) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1]; + char script_path[strlen(userpath) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1]; strcpy(script_path, userpath); - strcat(script_path, LUA_PM3_USER_DIRECTORY); + strcat(script_path, PM3_USER_DIRECTORY); strcat(script_path, LUA_SCRIPTS_DIRECTORY); strcat(script_path, script_name); strcat(script_path, suffix); @@ -177,8 +177,8 @@ static int CmdScriptRun(const char *Cmd) { } } if (!found) { - char script_path[strlen(LUA_PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1]; - strcpy(script_path, LUA_PM3_SYSTEM_DIRECTORY); + char script_path[strlen(PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1]; + strcpy(script_path, PM3_SYSTEM_DIRECTORY); strcat(script_path, LUA_SCRIPTS_DIRECTORY); strcat(script_path, script_name); strcat(script_path, suffix); diff --git a/client/scripting.c b/client/scripting.c index a823df8d7..1f6c61ff8 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -1151,32 +1151,32 @@ int set_pm3_libraries(lua_State *L) { char *user_path = getenv("HOME"); if (user_path != NULL) { // from the ~/.proxmark3/luascripts/ directory - char scripts_path[strlen(user_path) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + char scripts_path[strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(scripts_path, user_path); - strcat(scripts_path, LUA_PM3_USER_DIRECTORY); + strcat(scripts_path, PM3_USER_DIRECTORY); strcat(scripts_path, LUA_SCRIPTS_DIRECTORY); strcat(scripts_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, scripts_path); // from the ~/.proxmark3/lualib/ directory - char libraries_path[strlen(user_path) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + char libraries_path[strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(libraries_path, user_path); - strcat(libraries_path, LUA_PM3_USER_DIRECTORY); + strcat(libraries_path, PM3_USER_DIRECTORY); strcat(libraries_path, LUA_LIBRARIES_DIRECTORY); strcat(libraries_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, libraries_path); } - if (strlen(LUA_PM3_SYSTEM_DIRECTORY) != 0 || strlen(LUA_SCRIPTS_DIRECTORY) != 0 || strlen(LUA_LIBRARIES_WILDCARD) != 0 ) { + if (strlen(PM3_SYSTEM_DIRECTORY) != 0 || strlen(LUA_SCRIPTS_DIRECTORY) != 0 || strlen(LUA_LIBRARIES_WILDCARD) != 0 ) { // from the /usr/local/share/proxmark3/luascripts/ directory - char scripts_path[strlen(LUA_PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; - strcpy(scripts_path, LUA_PM3_SYSTEM_DIRECTORY); + char scripts_path[strlen(PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(scripts_path, PM3_SYSTEM_DIRECTORY); strcat(scripts_path, LUA_SCRIPTS_DIRECTORY); strcat(scripts_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, scripts_path); // from the /usr/local/share/proxmark3/lualib/ directory - char libraries_path[strlen(LUA_PM3_SYSTEM_DIRECTORY) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; - strcpy(libraries_path, LUA_PM3_SYSTEM_DIRECTORY); + char libraries_path[strlen(PM3_SYSTEM_DIRECTORY) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(libraries_path, PM3_SYSTEM_DIRECTORY); strcat(libraries_path, LUA_LIBRARIES_DIRECTORY); strcat(libraries_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, libraries_path); diff --git a/client/scripting.h b/client/scripting.h index 12d6f1f0b..1a7b5a7e3 100644 --- a/client/scripting.h +++ b/client/scripting.h @@ -14,8 +14,6 @@ //#include //#include -#define LUA_PM3_SYSTEM_DIRECTORY "/usr/local/share/proxmark3/" -#define LUA_PM3_USER_DIRECTORY "/.proxmark3/" #define LUA_LIBRARIES_DIRECTORY "lualibs/" #define LUA_SCRIPTS_DIRECTORY "luascripts/" #define LUA_LIBRARIES_WILDCARD "?.lua" diff --git a/include/common.h b/include/common.h index f427cb221..d70bc484f 100644 --- a/include/common.h +++ b/include/common.h @@ -16,6 +16,12 @@ #include #include +#ifndef PREFIX +# define PREFIX "/usr/local/" +#endif +#define PM3_SYSTEM_DIRECTORY PREFIX "share/proxmark3/" +#define PM3_USER_DIRECTORY "/.proxmark3/" + #define PACKED __attribute__((packed)) // debug