chg: some more checks in pathing

This commit is contained in:
iceman1001 2019-08-22 17:44:08 +02:00
commit ab38130c3e
2 changed files with 21 additions and 16 deletions

View file

@ -142,9 +142,11 @@ static int CmdScriptRun(const char *Cmd) {
bool found = false; bool found = false;
int error; int error;
if (get_my_executable_directory() != NULL) { const char* exec_path = get_my_executable_directory();
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()); if (exec_path != NULL) {
char script_path[strlen(exec_path) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1];
strcpy(script_path, exec_path);
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

@ -1133,38 +1133,41 @@ int set_pm3_libraries(lua_State *L) {
//--add to the LUA_PATH (package.path in lua) //--add to the LUA_PATH (package.path in lua)
// so we can load scripts from various places: // so we can load scripts from various places:
if (get_my_executable_directory() != NULL) { const char *exec_path = get_my_executable_directory();
if (exec_path != NULL) {
// from the ./luascripts/ directory // from the ./luascripts/ directory
char scripts_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; char scripts_path[strlen(exec_path) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1];
strcpy(scripts_path, get_my_executable_directory()); strcpy(scripts_path, exec_path);
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 ./lualib/ directory // from the ./lualib/ directory
char libraries_path[strlen(get_my_executable_directory()) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; char libraries_path[strlen(exec_path) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1];
strcpy(libraries_path, get_my_executable_directory()); strcpy(libraries_path, exec_path);
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);
} }
char *userpath = getenv("HOME"); char *user_path = getenv("HOME");
if (userpath != NULL) { if (user_path != NULL) {
// from the ~/.proxmark3/luascripts/ directory // from the ~/.proxmark3/luascripts/ directory
char scripts_path[strlen(userpath) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; char scripts_path[strlen(user_path) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1];
strcpy(scripts_path, userpath); strcpy(scripts_path, user_path);
strcat(scripts_path, LUA_PM3_USER_DIRECTORY); strcat(scripts_path, LUA_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(userpath) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; char libraries_path[strlen(user_path) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1];
strcpy(libraries_path, userpath); strcpy(libraries_path, user_path);
strcat(libraries_path, LUA_PM3_USER_DIRECTORY); strcat(libraries_path, LUA_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 ) {
// 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(LUA_PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1];
strcpy(scripts_path, LUA_PM3_SYSTEM_DIRECTORY); strcpy(scripts_path, LUA_PM3_SYSTEM_DIRECTORY);