mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 05:13:46 -07:00
ADD: 'script list' - now sorts the scripts in alphabetic order. It needs the extra define, in order to scandir and alphasort to work.
and this made our own version of le32toh function complain. So this is removed from util.c and where it was used a new define replaced it (LE32TOH)
This commit is contained in:
parent
db34c61aa0
commit
6c4d1560e9
5 changed files with 31 additions and 33 deletions
|
@ -8,6 +8,9 @@
|
|||
// Some lua scripting glue to proxmark core.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// this define is needed for scandir/alphasort to work
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -68,32 +71,32 @@ int CmdHelp(const char * Cmd)
|
|||
}
|
||||
|
||||
/**
|
||||
* Generate list of available commands, what it does is
|
||||
* Generate a sorted list of available commands, what it does is
|
||||
* generate a file listing of the script-directory for files
|
||||
* ending with .lua
|
||||
*
|
||||
*/
|
||||
int CmdList(const char *Cmd)
|
||||
{
|
||||
DIR *dp;
|
||||
struct dirent *ep;
|
||||
int CmdList(const char *Cmd) {
|
||||
|
||||
char script_directory_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + 1];
|
||||
strcpy(script_directory_path, get_my_executable_directory());
|
||||
strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY);
|
||||
dp = opendir(script_directory_path);
|
||||
|
||||
if (dp != NULL)
|
||||
{
|
||||
while ((ep = readdir (dp)) != NULL)
|
||||
{
|
||||
if(str_ends_with(ep->d_name, ".lua"))
|
||||
PrintAndLog("%-21s %s", ep->d_name, "A script file");
|
||||
struct dirent **namelist;
|
||||
int n;
|
||||
|
||||
n = scandir(script_directory_path, &namelist, NULL, alphasort);
|
||||
if (n == -1) {
|
||||
PrintAndLog ("Couldn't open the scripts-directory");
|
||||
return 1;
|
||||
}
|
||||
(void) closedir (dp);
|
||||
}
|
||||
else
|
||||
PrintAndLog ("Couldn't open the scripts-directory");
|
||||
return 0;
|
||||
|
||||
for (uint16_t i = 0; i < n; i++) {
|
||||
if(str_ends_with(namelist[i]->d_name, ".lua"))
|
||||
PrintAndLog("%-21s %s", namelist[i]->d_name, "A script file");
|
||||
free(namelist[i]);
|
||||
}
|
||||
free(namelist);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue