mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 13:23:51 -07:00
chg: adding execute/home/current working directory functions to lua
This commit is contained in:
parent
23d754c85f
commit
966bcc0d28
5 changed files with 64 additions and 24 deletions
|
@ -7,15 +7,15 @@ local ansicolors = require('ansicolors')
|
|||
|
||||
copyright = ''
|
||||
author = 'Iceman'
|
||||
version = 'v1.0.2'
|
||||
version = 'v1.0.3'
|
||||
desc = [[
|
||||
This script will load several traces files in ../traces/ folder and do
|
||||
This script will load several traces files in current working directory/traces/ folder and do
|
||||
"data load"
|
||||
"lf search 1 u"
|
||||
|
||||
The following tracefiles will be loaded:
|
||||
em*.pm3
|
||||
m*.pm3
|
||||
modulation*.pm3
|
||||
]]
|
||||
example = [[
|
||||
1. script run tracetest
|
||||
|
@ -78,8 +78,10 @@ local function main(args)
|
|||
print( string.rep('--',20) )
|
||||
|
||||
local cmdDataLoad = 'data load %s';
|
||||
local tracesEM = "find '../traces/' -iname 'em*.pm3' -type f"
|
||||
local tracesMOD = "find '../traces/' -iname 'm*.pm3' -type f"
|
||||
local cwd = core.cwd();
|
||||
|
||||
local tracesEM = "find '"..cwd.."/traces/ ' -iname 'em*.pm3' -type f"
|
||||
local tracesMOD = "find '"..cwd.."/traces/' -iname 'modulation*.pm3' -type f"
|
||||
|
||||
local write2File = false
|
||||
local outputTemplate = os.date('testtest_%Y-%m-%d_%H%M%S')
|
||||
|
@ -100,7 +102,7 @@ local function main(args)
|
|||
end
|
||||
p.close();
|
||||
|
||||
-- Find a set of traces staring with MOD
|
||||
-- Find a set of traces staring with MODULATION
|
||||
p = assert( io.popen(tracesMOD) )
|
||||
for file in p:lines() do
|
||||
table.insert(files, file)
|
||||
|
|
|
@ -29,15 +29,6 @@
|
|||
static int CmdHelp(const char *Cmd);
|
||||
static int setCmdHelp(const char *Cmd);
|
||||
|
||||
// Load all settings into memory (struct)
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
#define GetCurrentDir _getcwd
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#define GetCurrentDir getcwd
|
||||
#endif
|
||||
|
||||
static char *prefGetFilename(void) {
|
||||
char *path;
|
||||
|
||||
|
|
|
@ -29,14 +29,6 @@
|
|||
#include "flash.h"
|
||||
#include "preferences.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
#define GetCurrentDir _getcwd
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#define GetCurrentDir getcwd
|
||||
#endif
|
||||
|
||||
// Used to enable/disable use of preferences json file
|
||||
#define USE_PREFERENCE_FILE
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#ifndef PROXMARK3_H__
|
||||
#define PROXMARK3_H__
|
||||
|
||||
#include <unistd.h>
|
||||
#include "common.h"
|
||||
|
||||
#define PROXPROMPT_MAX_SIZE 255
|
||||
|
@ -36,6 +37,14 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Load all settings into memory (struct)
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
#define GetCurrentDir _getcwd
|
||||
#else
|
||||
#define GetCurrentDir getcwd
|
||||
#endif
|
||||
|
||||
int push_cmdscriptfile(char *path, bool stayafter);
|
||||
const char *get_my_executable_path(void);
|
||||
const char *get_my_executable_directory(void);
|
||||
|
|
|
@ -12,9 +12,11 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "lauxlib.h"
|
||||
#include "cmdmain.h"
|
||||
#include "proxmark3.h"
|
||||
#include "comms.h"
|
||||
#include "mifare/mifarehost.h"
|
||||
#include "crc.h"
|
||||
|
@ -28,7 +30,7 @@
|
|||
#include "mifare/ndef.h" // ndef parsing
|
||||
#include "commonutil.h"
|
||||
#include "ui.h"
|
||||
#include "proxmark3.h"
|
||||
|
||||
#include "crc16.h"
|
||||
#include "protocols.h"
|
||||
#include "fileutils.h" // searchfile
|
||||
|
@ -912,6 +914,12 @@ static int l_detect_prng(lua_State *L) {
|
|||
* @return
|
||||
*/
|
||||
static int l_keygen_algoD(lua_State *L) {
|
||||
//Check number of arguments
|
||||
int n = lua_gettop(L);
|
||||
if (n != 1) {
|
||||
return returnToLuaWithError(L, "Only UID");
|
||||
}
|
||||
|
||||
size_t size;
|
||||
uint32_t tmp;
|
||||
const char *p_uid = luaL_checklstring(L, 1, &size);
|
||||
|
@ -1129,6 +1137,9 @@ static int l_remark(lua_State *L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
// 1. filename
|
||||
// 2. extension
|
||||
// output: full search path to file
|
||||
static int l_searchfile(lua_State *L) {
|
||||
//Check number of arguments
|
||||
int n = lua_gettop(L);
|
||||
|
@ -1154,6 +1165,38 @@ static int l_searchfile(lua_State *L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int l_ud(lua_State *L) {
|
||||
const char *ud = get_my_user_directory();
|
||||
lua_pushstring(L, ud);
|
||||
return 1;
|
||||
}
|
||||
static int l_ewd(lua_State *L) {
|
||||
const char *ewd = get_my_executable_directory();
|
||||
lua_pushstring(L, ewd);
|
||||
return 1;
|
||||
}
|
||||
static int l_cwd(lua_State *L) {
|
||||
|
||||
uint16_t path_len = FILENAME_MAX; // should be a good starting point
|
||||
bool error = false;
|
||||
char *cwd = NULL;
|
||||
cwd = (char *)calloc(path_len, sizeof(uint8_t));
|
||||
|
||||
while (!error && (GetCurrentDir(cwd, path_len) == NULL)) {
|
||||
if (errno == ERANGE) { // Need bigger buffer
|
||||
path_len += 10; // if buffer was too small add 10 characters and try again
|
||||
cwd = realloc(cwd, path_len);
|
||||
} else {
|
||||
error = true;
|
||||
free(cwd);
|
||||
return returnToLuaWithError(L, "Failed to get current working directory");
|
||||
}
|
||||
}
|
||||
lua_pushstring(L, cwd);
|
||||
free(cwd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the lua path to include "./lualibs/?.lua", in order for a script to be
|
||||
* able to do "require('foobar')" if foobar.lua is within lualibs folder.
|
||||
|
@ -1215,6 +1258,9 @@ int set_pm3_libraries(lua_State *L) {
|
|||
{"ndefparse", l_ndefparse},
|
||||
{"fast_push_mode", l_fast_push_mode},
|
||||
{"search_file", l_searchfile},
|
||||
{"cwd", l_cwd},
|
||||
{"ewd", l_ewd},
|
||||
{"ud", l_ud},
|
||||
{"rem", l_remark},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue