Lua: look for scripts also in ~/.proxmark/{luascripts,lualibs} and /usr/local/share/proxmark3/...

This commit is contained in:
Philippe Teuwen 2019-08-21 23:50:41 +02:00
parent a8ee33baf4
commit 3c6500a1b2
3 changed files with 52 additions and 16 deletions

View file

@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
## [unreleased][unreleased]
- Add Lua paths: look for scripts also in ~/.proxmark/lua{scripts,libs} and /usr/local/share/proxmark3/lua{scripts,libs} (@doegox)
- Change Lua directory scripts/ to luascript/ (@doegox)
- Change non-rdv4 PLATFORM must now use the generic PM3OTHER, simpler (@doegox)
- Fix reveng integration for all platforms else than WIN32 (@doegox)
- Add cheat sheet for easy operations of the Proxmark3 (scund00r)

View file

@ -1131,21 +1131,52 @@ int set_pm3_libraries(lua_State *L) {
//-- remove the global environment table from the stack
lua_pop(L, 1);
//--add to the LUA_PATH (package.path in lua)
// so we can load scripts from the ./luascripts/ - directory
char scripts_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1];
strcpy(scripts_path, get_my_executable_directory());
strcat(scripts_path, LUA_SCRIPTS_DIRECTORY);
strcat(scripts_path, LUA_LIBRARIES_WILDCARD);
setLuaPath(L, scripts_path);
//-- Last but not least, add to the LUA_PATH (package.path in lua)
// so we can load libraries from the ./lualib/ - directory
char libraries_path[strlen(get_my_executable_directory()) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1];
strcpy(libraries_path, get_my_executable_directory());
strcat(libraries_path, LUA_LIBRARIES_DIRECTORY);
strcat(libraries_path, LUA_LIBRARIES_WILDCARD);
setLuaPath(L, libraries_path);
return 1;
// so we can load scripts from various places:
{
// from the ./luascripts/ directory
char scripts_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1];
strcpy(scripts_path, get_my_executable_directory());
strcat(scripts_path, LUA_SCRIPTS_DIRECTORY);
strcat(scripts_path, LUA_LIBRARIES_WILDCARD);
setLuaPath(L, scripts_path);
// from the ./lualib/ directory
char libraries_path[strlen(get_my_executable_directory()) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1];
strcpy(libraries_path, get_my_executable_directory());
strcat(libraries_path, LUA_LIBRARIES_DIRECTORY);
strcat(libraries_path, LUA_LIBRARIES_WILDCARD);
setLuaPath(L, libraries_path);
}
char *userpath = getenv("HOME");
if (userpath != NULL) {
// from the ~/.proxmark3/luascripts/ directory
char scripts_path[strlen(userpath) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1];
strcpy(scripts_path, userpath);
strcat(scripts_path, LUA_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(userpath) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1];
strcpy(libraries_path, userpath);
strcat(libraries_path, LUA_PM3_USER_DIRECTORY);
strcat(libraries_path, LUA_LIBRARIES_DIRECTORY);
strcat(libraries_path, LUA_LIBRARIES_WILDCARD);
setLuaPath(L, libraries_path);
}
{
// 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);
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);
strcat(libraries_path, LUA_LIBRARIES_DIRECTORY);
strcat(libraries_path, LUA_LIBRARIES_WILDCARD);
setLuaPath(L, libraries_path);
return 1;
}
}

View file

@ -14,6 +14,8 @@
//#include <lualib.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_SCRIPTS_DIRECTORY "luascripts/"
#define LUA_LIBRARIES_WILDCARD "?.lua"