introduce PREFIX for pm3 system directory and move to common.h

This commit is contained in:
Philippe Teuwen 2019-08-22 19:36:20 +02:00
parent ab38130c3e
commit 595b8a1885
4 changed files with 23 additions and 19 deletions

View file

@ -90,15 +90,15 @@ static int CmdScriptList(const char *Cmd) {
} }
char *userpath = getenv("HOME"); char *userpath = getenv("HOME");
if (userpath != NULL) { 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); 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); strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY);
scriptlist(script_directory_path); scriptlist(script_directory_path);
} }
{ {
char script_directory_path[strlen(LUA_PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; char script_directory_path[strlen(PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + 1];
strcpy(script_directory_path, LUA_PM3_SYSTEM_DIRECTORY); strcpy(script_directory_path, PM3_SYSTEM_DIRECTORY);
strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY); strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY);
scriptlist(script_directory_path); scriptlist(script_directory_path);
} }
@ -161,9 +161,9 @@ static int CmdScriptRun(const char *Cmd) {
} }
char *userpath = getenv("HOME"); char *userpath = getenv("HOME");
if ((!found) && (userpath != NULL)) { 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); 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, LUA_SCRIPTS_DIRECTORY);
strcat(script_path, script_name); strcat(script_path, script_name);
strcat(script_path, suffix); strcat(script_path, suffix);
@ -177,8 +177,8 @@ static int CmdScriptRun(const char *Cmd) {
} }
} }
if (!found) { if (!found) {
char script_path[strlen(LUA_PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1]; char script_path[strlen(PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1];
strcpy(script_path, LUA_PM3_SYSTEM_DIRECTORY); strcpy(script_path, PM3_SYSTEM_DIRECTORY);
strcat(script_path, LUA_SCRIPTS_DIRECTORY); strcat(script_path, LUA_SCRIPTS_DIRECTORY);
strcat(script_path, script_name); strcat(script_path, script_name);
strcat(script_path, suffix); strcat(script_path, suffix);

View file

@ -1151,32 +1151,32 @@ int set_pm3_libraries(lua_State *L) {
char *user_path = getenv("HOME"); char *user_path = getenv("HOME");
if (user_path != NULL) { if (user_path != NULL) {
// from the ~/.proxmark3/luascripts/ directory // 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); 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_SCRIPTS_DIRECTORY);
strcat(scripts_path, LUA_LIBRARIES_WILDCARD); strcat(scripts_path, LUA_LIBRARIES_WILDCARD);
setLuaPath(L, scripts_path); setLuaPath(L, scripts_path);
// from the ~/.proxmark3/lualib/ directory // 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); 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_DIRECTORY);
strcat(libraries_path, LUA_LIBRARIES_WILDCARD); strcat(libraries_path, LUA_LIBRARIES_WILDCARD);
setLuaPath(L, libraries_path); 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 // 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]; char scripts_path[strlen(PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1];
strcpy(scripts_path, LUA_PM3_SYSTEM_DIRECTORY); strcpy(scripts_path, PM3_SYSTEM_DIRECTORY);
strcat(scripts_path, LUA_SCRIPTS_DIRECTORY); strcat(scripts_path, LUA_SCRIPTS_DIRECTORY);
strcat(scripts_path, LUA_LIBRARIES_WILDCARD); strcat(scripts_path, LUA_LIBRARIES_WILDCARD);
setLuaPath(L, scripts_path); setLuaPath(L, scripts_path);
// from the /usr/local/share/proxmark3/lualib/ directory // 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]; char libraries_path[strlen(PM3_SYSTEM_DIRECTORY) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1];
strcpy(libraries_path, LUA_PM3_SYSTEM_DIRECTORY); strcpy(libraries_path, PM3_SYSTEM_DIRECTORY);
strcat(libraries_path, LUA_LIBRARIES_DIRECTORY); strcat(libraries_path, LUA_LIBRARIES_DIRECTORY);
strcat(libraries_path, LUA_LIBRARIES_WILDCARD); strcat(libraries_path, LUA_LIBRARIES_WILDCARD);
setLuaPath(L, libraries_path); setLuaPath(L, libraries_path);

View file

@ -14,8 +14,6 @@
//#include <lualib.h> //#include <lualib.h>
//#include <lauxlib.h> //#include <lauxlib.h>
#define LUA_PM3_SYSTEM_DIRECTORY "/usr/local/share/proxmark3/"
#define LUA_PM3_USER_DIRECTORY "/.proxmark3/"
#define LUA_LIBRARIES_DIRECTORY "lualibs/" #define LUA_LIBRARIES_DIRECTORY "lualibs/"
#define LUA_SCRIPTS_DIRECTORY "luascripts/" #define LUA_SCRIPTS_DIRECTORY "luascripts/"
#define LUA_LIBRARIES_WILDCARD "?.lua" #define LUA_LIBRARIES_WILDCARD "?.lua"

View file

@ -16,6 +16,12 @@
#include <stddef.h> #include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
#ifndef PREFIX
# define PREFIX "/usr/local/"
#endif
#define PM3_SYSTEM_DIRECTORY PREFIX "share/proxmark3/"
#define PM3_USER_DIRECTORY "/.proxmark3/"
#define PACKED __attribute__((packed)) #define PACKED __attribute__((packed))
// debug // debug