mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
Concept
This commit is contained in:
parent
108b426c98
commit
8fea6cddf7
8 changed files with 242 additions and 2 deletions
|
@ -251,7 +251,8 @@ CMDSRCS = crapto1/crapto1.c \
|
||||||
flash.c \
|
flash.c \
|
||||||
wiegand_formats.c \
|
wiegand_formats.c \
|
||||||
wiegand_formatutils.c \
|
wiegand_formatutils.c \
|
||||||
cardhelper.c
|
cardhelper.c \
|
||||||
|
settings.c
|
||||||
|
|
||||||
cpu_arch = $(shell uname -m)
|
cpu_arch = $(shell uname -m)
|
||||||
ifneq ($(findstring 86, $(cpu_arch)), )
|
ifneq ($(findstring 86, $(cpu_arch)), )
|
||||||
|
|
|
@ -94,6 +94,9 @@ int JsonSaveStr(json_t *root, const char *path, const char *value) {
|
||||||
return JsonSaveJsonObject(root, path, json_string(value));
|
return JsonSaveJsonObject(root, path, json_string(value));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int JsonSaveBoolean(json_t *root, const char *path, bool value) {
|
||||||
|
return JsonSaveJsonObject(root, path, json_boolean(value));
|
||||||
|
}
|
||||||
int JsonSaveBufAsHexCompact(json_t *elm, const char *path, uint8_t *data, size_t datalen) {
|
int JsonSaveBufAsHexCompact(json_t *elm, const char *path, uint8_t *data, size_t datalen) {
|
||||||
char *msg = sprint_hex_inrow(data, datalen);
|
char *msg = sprint_hex_inrow(data, datalen);
|
||||||
if (msg && strlen(msg) && msg[strlen(msg) - 1] == ' ')
|
if (msg && strlen(msg) && msg[strlen(msg) - 1] == ' ')
|
||||||
|
|
|
@ -24,6 +24,7 @@ const char *GetApplicationDataName(tlv_tag_t tag);
|
||||||
|
|
||||||
int JsonSaveJsonObject(json_t *root, const char *path, json_t *value);
|
int JsonSaveJsonObject(json_t *root, const char *path, json_t *value);
|
||||||
int JsonSaveStr(json_t *root, const char *path, const char *value);
|
int JsonSaveStr(json_t *root, const char *path, const char *value);
|
||||||
|
int JsonSaveBoolean(json_t *root, const char *path, bool value);
|
||||||
int JsonSaveInt(json_t *root, const char *path, int value);
|
int JsonSaveInt(json_t *root, const char *path, int value);
|
||||||
int JsonSaveBufAsHexCompact(json_t *elm, const char *path, uint8_t *data, size_t datalen);
|
int JsonSaveBufAsHexCompact(json_t *elm, const char *path, uint8_t *data, size_t datalen);
|
||||||
int JsonSaveBufAsHex(json_t *elm, const char *path, uint8_t *data, size_t datalen);
|
int JsonSaveBufAsHex(json_t *elm, const char *path, uint8_t *data, size_t datalen);
|
||||||
|
|
|
@ -52,6 +52,9 @@
|
||||||
|
|
||||||
#define PATH_MAX_LENGTH 200
|
#define PATH_MAX_LENGTH 200
|
||||||
|
|
||||||
|
extern void JsonLoadSettingsCallback (json_t *root);
|
||||||
|
extern void JsonSaveSettingsCallback (json_t *root);
|
||||||
|
|
||||||
struct wave_info_t {
|
struct wave_info_t {
|
||||||
char signature[4];
|
char signature[4];
|
||||||
uint32_t filesize;
|
uint32_t filesize;
|
||||||
|
@ -425,6 +428,9 @@ int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case jsfSettings:
|
||||||
|
JsonSaveSettingsCallback (root);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -863,7 +869,9 @@ int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_
|
||||||
}
|
}
|
||||||
*datalen = sptr;
|
*datalen = sptr;
|
||||||
}
|
}
|
||||||
|
if (!strcmp(ctype,"settings")) {
|
||||||
|
JsonLoadSettingsCallback (root);
|
||||||
|
}
|
||||||
PrintAndLogEx(SUCCESS, "loaded from JSON file " _YELLOW_("%s"), fileName);
|
PrintAndLogEx(SUCCESS, "loaded from JSON file " _YELLOW_("%s"), fileName);
|
||||||
out:
|
out:
|
||||||
json_decref(root);
|
json_decref(root);
|
||||||
|
|
|
@ -62,6 +62,7 @@ typedef enum {
|
||||||
jsfT55x7,
|
jsfT55x7,
|
||||||
jsfT5555,
|
jsfT5555,
|
||||||
jsfMfPlusKeys,
|
jsfMfPlusKeys,
|
||||||
|
jsfSettings,
|
||||||
} JSONFileType;
|
} JSONFileType;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "comms.h"
|
#include "comms.h"
|
||||||
#include "fileutils.h"
|
#include "fileutils.h"
|
||||||
#include "flash.h"
|
#include "flash.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
static void showBanner(void) {
|
static void showBanner(void) {
|
||||||
g_printAndLog = PRINTANDLOG_PRINT;
|
g_printAndLog = PRINTANDLOG_PRINT;
|
||||||
|
@ -557,6 +558,7 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
/* initialize history */
|
/* initialize history */
|
||||||
using_history();
|
using_history();
|
||||||
|
|
||||||
|
|
||||||
#ifdef RL_STATE_READCMD
|
#ifdef RL_STATE_READCMD
|
||||||
rl_extend_line_buffer(1024);
|
rl_extend_line_buffer(1024);
|
||||||
|
@ -581,6 +583,12 @@ int main(int argc, char *argv[]) {
|
||||||
set_my_executable_path();
|
set_my_executable_path();
|
||||||
set_my_user_directory();
|
set_my_user_directory();
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
settingsLoad ();
|
||||||
|
settingsSave ();
|
||||||
|
printf ("Ver : %s\n",mySettings.version);
|
||||||
|
// End Settings
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
|
|
||||||
if (argv[i][0] != '-') {
|
if (argv[i][0] != '-') {
|
||||||
|
|
186
client/settings.c
Normal file
186
client/settings.c
Normal file
|
@ -0,0 +1,186 @@
|
||||||
|
/*****************************************************************************
|
||||||
|
* WARNING
|
||||||
|
*
|
||||||
|
* THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY.
|
||||||
|
*
|
||||||
|
* USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL
|
||||||
|
* PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL,
|
||||||
|
* AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES.
|
||||||
|
*
|
||||||
|
* THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS.
|
||||||
|
*
|
||||||
|
*****************************************************************************
|
||||||
|
*
|
||||||
|
* This file is part of loclass. It is a reconstructon of the cipher engine
|
||||||
|
* used in iClass, and RFID techology.
|
||||||
|
*
|
||||||
|
* The implementation is based on the work performed by
|
||||||
|
* Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and
|
||||||
|
* Milosch Meriac in the paper "Dismantling IClass".
|
||||||
|
*
|
||||||
|
* Copyright (C) 2014 Martin Holst Swende
|
||||||
|
*
|
||||||
|
* This is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License version 2 as published
|
||||||
|
* by the Free Software Foundation, or, at your option, any later version.
|
||||||
|
*
|
||||||
|
* This file is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with loclass. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Settings Functions
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "settings.h"
|
||||||
|
#include "comms.h"
|
||||||
|
#include "emv/emvjson.h"
|
||||||
|
|
||||||
|
// settings_t mySettings;
|
||||||
|
|
||||||
|
// Load all settings into memory (struct)
|
||||||
|
void settingsLoad (void)
|
||||||
|
{
|
||||||
|
// loadFileJson wants these, so pass in place holder values, though not used
|
||||||
|
// in settings load;
|
||||||
|
uint8_t dummyData = 0x00;
|
||||||
|
size_t dummyDL = 0x00;
|
||||||
|
|
||||||
|
// clear all settings
|
||||||
|
memset (&mySettings,0x00,sizeof(mySettings));
|
||||||
|
|
||||||
|
if (loadFileJSON(settingsFilename, &dummyData, sizeof(dummyData), &dummyDL) == PM3_SUCCESS) {
|
||||||
|
printf ("==> Settings Loaded\n");
|
||||||
|
mySettings.loaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Test results
|
||||||
|
/*
|
||||||
|
bool os_windows_usecolor;
|
||||||
|
bool os_windows_useansicolor;
|
||||||
|
int window_xpos;
|
||||||
|
int window_ypos;
|
||||||
|
int window_hsize;
|
||||||
|
int window_wsize;
|
||||||
|
*/
|
||||||
|
printf (" Settings Version : [%s]\n",mySettings.version);
|
||||||
|
printf (" os_windows_usecolor (bool) : [%d]\n",mySettings.os_windows_usecolor);
|
||||||
|
printf (" os_windows_useAnsicolor (bool) : [%d]\n",mySettings.os_windows_useansicolor);
|
||||||
|
printf (" window_xpos (int) : [%d]\n",mySettings.window_xpos);
|
||||||
|
printf (" window_ypos (int) : [%d]\n",mySettings.window_ypos);
|
||||||
|
printf (" window_hsize (int) : [%d]\n",mySettings.window_hsize);
|
||||||
|
printf (" window_wsize (int) : [%d]\n",mySettings.window_wsize);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save all settings from memory (struct) to file
|
||||||
|
int settingsSave (void)
|
||||||
|
{
|
||||||
|
// Note sure if backup has value ?
|
||||||
|
char backupFilename[500];
|
||||||
|
// if (mySettings.loaded)
|
||||||
|
|
||||||
|
snprintf (backupFilename,sizeof(backupFilename),"%s.bak",settingsFilename);
|
||||||
|
|
||||||
|
if (fileExists (backupFilename)) {
|
||||||
|
if (remove (backupFilename) != 0) {
|
||||||
|
PrintAndLogEx (FAILED, "Error - could not delete old settings backup file \"%s\"",backupFilename);
|
||||||
|
return PM3_ESOFT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileExists (settingsFilename)) {
|
||||||
|
if (rename (settingsFilename,backupFilename) != 0) {
|
||||||
|
PrintAndLogEx (FAILED, "Error - could not backup settings file \"%s\" to \"%s\"",settingsFilename,backupFilename);
|
||||||
|
return PM3_ESOFT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t dummyData = 0x00;
|
||||||
|
size_t dummyDL = 0x00;
|
||||||
|
|
||||||
|
// int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, size_t datalen);
|
||||||
|
|
||||||
|
if (saveFileJSON(settingsFilename, jsfSettings, &dummyData, dummyDL) == PM3_SUCCESS)
|
||||||
|
PrintAndLogEx (NORMAL, "settings have been saved to \"%s\"",settingsFilename);
|
||||||
|
|
||||||
|
return PM3_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JsonSaveSettingsCallback (json_t *root)
|
||||||
|
{
|
||||||
|
// extern settings_t mySettings;
|
||||||
|
|
||||||
|
printf ("==> Save Settings\n");
|
||||||
|
//JsonSaveStr(root, "FileType", "settings");
|
||||||
|
//JsonSaveStr (root,"Test1.Test2","test settings");
|
||||||
|
/*
|
||||||
|
"version": "1.0 Nov 2019",
|
||||||
|
"os.windows.usecolor": true,
|
||||||
|
"os.windows.useAnsiColor": true,
|
||||||
|
"window.xpos": 10,
|
||||||
|
"window.ypos": 10,
|
||||||
|
"window.hsize": 300,
|
||||||
|
"window.wsize": 600
|
||||||
|
*/
|
||||||
|
JsonSaveStr (root,"FileType","settings");
|
||||||
|
JsonSaveStr (root,"version","1.0 Nov 2019");//mySettings.version);
|
||||||
|
JsonSaveBoolean (root,"os.windows.useColor",mySettings.os_windows_usecolor);
|
||||||
|
JsonSaveBoolean (root,"os.windows.useAnsiColor",mySettings.os_windows_useansicolor);
|
||||||
|
JsonSaveInt (root,"window.xpos",mySettings.window_xpos);
|
||||||
|
JsonSaveInt (root,"window.ypos",mySettings.window_ypos);
|
||||||
|
JsonSaveInt (root,"window.hsize",mySettings.window_hsize);
|
||||||
|
JsonSaveInt (root,"window.wsize",mySettings.window_wsize);
|
||||||
|
}
|
||||||
|
|
||||||
|
void JsonLoadSettingsCallback (json_t *root)
|
||||||
|
{
|
||||||
|
// extern settings_t mySettings;
|
||||||
|
json_error_t up_error = {0};
|
||||||
|
int b1;
|
||||||
|
int i1;
|
||||||
|
const char *s1;
|
||||||
|
|
||||||
|
if (json_unpack_ex(root, &up_error , 0, "{s:s}","version",&s1) == 0)
|
||||||
|
strncpy (mySettings.version,s1,sizeof (mySettings.version) - 1);
|
||||||
|
else
|
||||||
|
strncpy (mySettings.version,"unknown",sizeof (mySettings.version) - 1);
|
||||||
|
|
||||||
|
// os.windows...
|
||||||
|
if (json_unpack_ex(root,&up_error, 0, "{s:b}","os.windows.useColor",&b1) == 0)
|
||||||
|
mySettings.os_windows_usecolor = b1;
|
||||||
|
else // default
|
||||||
|
mySettings.os_windows_useansicolor = false;
|
||||||
|
|
||||||
|
if (json_unpack_ex(root,&up_error, 0, "{s:b}","os.windows.useAnsiColor",&b1) == 0)
|
||||||
|
mySettings.os_windows_useansicolor = b1;
|
||||||
|
else // default
|
||||||
|
mySettings.os_windows_useansicolor = false;
|
||||||
|
|
||||||
|
// window...
|
||||||
|
if (json_unpack_ex(root,&up_error, 0, "{s:i}","window.xpos",&i1) == 0)
|
||||||
|
mySettings.window_xpos = i1;
|
||||||
|
else // default
|
||||||
|
mySettings.window_xpos = 0;
|
||||||
|
if (json_unpack_ex(root,&up_error, 0, "{s:i}","window.ypos",&i1) == 0)
|
||||||
|
mySettings.window_ypos = i1;
|
||||||
|
else // default
|
||||||
|
mySettings.window_ypos = 0;
|
||||||
|
if (json_unpack_ex(root,&up_error, 0, "{s:i}","window.hsize",&i1) == 0)
|
||||||
|
mySettings.window_hsize = i1;
|
||||||
|
else // default
|
||||||
|
mySettings.window_hsize = 0;
|
||||||
|
if (json_unpack_ex(root,&up_error, 0, "{s:i}","window.wsize",&i1) == 0)
|
||||||
|
mySettings.window_wsize = i1;
|
||||||
|
else // default
|
||||||
|
mySettings.window_wsize = 0;
|
||||||
|
|
||||||
|
}
|
32
client/settings.h
Normal file
32
client/settings.h
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Copyright (C) 2009 Michael Gernoth <michael at gernoth.net>
|
||||||
|
// Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
|
||||||
|
//
|
||||||
|
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||||
|
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||||
|
// the license.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Settings Functions
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "fileutils.h"
|
||||||
|
|
||||||
|
#define settingsFilename "settings.json"
|
||||||
|
typedef struct {
|
||||||
|
bool loaded;
|
||||||
|
char version[20];
|
||||||
|
bool os_windows_usecolor;
|
||||||
|
bool os_windows_useansicolor;
|
||||||
|
int window_xpos;
|
||||||
|
int window_ypos;
|
||||||
|
int window_hsize;
|
||||||
|
int window_wsize;
|
||||||
|
} settings_t;
|
||||||
|
|
||||||
|
settings_t mySettings;
|
||||||
|
|
||||||
|
void settingsLoad (void);
|
||||||
|
int settingsSave (void);
|
||||||
|
|
||||||
|
void JsonSaveCallback ( json_t *root);
|
||||||
|
void JsonLoadCallback ( json_t *root);
|
Loading…
Add table
Add a link
Reference in a new issue