mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-19 04:49:38 -07:00
Fix reveng
This commit is contained in:
parent
fe81b47811
commit
f46c366321
7 changed files with 68 additions and 39 deletions
|
@ -10,43 +10,59 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
//#include <stdlib.h>
|
||||||
|
//#include <ctype.h>
|
||||||
#include "cmdmain.h"
|
#include "cmdmain.h"
|
||||||
#include "cmdparser.h"
|
|
||||||
#include "cmdcrc.h"
|
#include "cmdcrc.h"
|
||||||
#include "reveng/reveng.h"
|
#include "reveng/reveng.h"
|
||||||
//#include "reveng/cli.h"
|
#include "ui.h"
|
||||||
static int CmdHelp(const char *Cmd);
|
#include "util.h"
|
||||||
|
|
||||||
int CmdCrcCalc(const char *Cmd)
|
#define MAX_ARGS 20
|
||||||
{
|
|
||||||
int argc = 0;
|
|
||||||
char Cmd2[CMD_BUFFER_SIZE] = {0x00};
|
|
||||||
char *argv[3];
|
|
||||||
|
|
||||||
for (int i = 0; i < 50; i++)
|
int split(char *str, char *arr[MAX_ARGS]){
|
||||||
if (Cmd[i]==0x00) argc=i;
|
int beginIndex = 0;
|
||||||
|
int endIndex;
|
||||||
|
int maxWords = MAX_ARGS;
|
||||||
|
int wordCnt = 0;
|
||||||
|
|
||||||
memcpy(Cmd2, Cmd, argc);
|
while(1){
|
||||||
argv[1]=Cmd2;
|
while(isspace(str[beginIndex])){
|
||||||
reveng_main(argc, argv);
|
++beginIndex;
|
||||||
return 0;
|
}
|
||||||
|
if(str[beginIndex] == '\0')
|
||||||
|
break;
|
||||||
|
endIndex = beginIndex;
|
||||||
|
while (str[endIndex] && !isspace(str[endIndex])){
|
||||||
|
++endIndex;
|
||||||
|
}
|
||||||
|
int len = endIndex - beginIndex;
|
||||||
|
char *tmp = calloc(len + 1, sizeof(char));
|
||||||
|
memcpy(tmp, &str[beginIndex], len);
|
||||||
|
arr[wordCnt++] = tmp;
|
||||||
|
//PrintAndLog("cnt: %d, %s",wordCnt-1, arr[wordCnt-1]);
|
||||||
|
beginIndex = endIndex;
|
||||||
|
if (wordCnt == maxWords)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return wordCnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static command_t CommandTable[] =
|
|
||||||
{
|
|
||||||
{"help", CmdHelp, 1, "This help"},
|
|
||||||
{"calc", CmdCrcCalc, 1, "{ Calculate CRC's }"},
|
|
||||||
{NULL, NULL, 0, NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
int CmdCrc(const char *Cmd)
|
int CmdCrc(const char *Cmd)
|
||||||
{
|
{
|
||||||
CmdsParse(CommandTable, Cmd);
|
char name[] = {"reveng "};
|
||||||
return 0;
|
char Cmd2[50 + 7];
|
||||||
|
memcpy(Cmd2, name, 7);
|
||||||
|
memcpy(Cmd2 + 7, Cmd, 50);
|
||||||
|
char *argv[MAX_ARGS];
|
||||||
|
int argc = split(Cmd2, argv);
|
||||||
|
//PrintAndLog("argc: %d, %s %s Cmd: %s",argc, argv[0], Cmd2, Cmd);
|
||||||
|
reveng_main(argc, argv);
|
||||||
|
for(int i = 0; i < argc; ++i){
|
||||||
|
//puts(arr[i]);
|
||||||
|
free(argv[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdHelp(const char *Cmd)
|
|
||||||
{
|
|
||||||
CmdsHelp(CommandTable);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
|
@ -12,5 +12,4 @@
|
||||||
#define CMDCRC_H__
|
#define CMDCRC_H__
|
||||||
|
|
||||||
int CmdCrc(const char *Cmd);
|
int CmdCrc(const char *Cmd);
|
||||||
int CmdCrcCalc(const char *Cmd);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -32,6 +32,7 @@ unsigned int current_command = CMD_UNKNOWN;
|
||||||
|
|
||||||
static int CmdHelp(const char *Cmd);
|
static int CmdHelp(const char *Cmd);
|
||||||
static int CmdQuit(const char *Cmd);
|
static int CmdQuit(const char *Cmd);
|
||||||
|
static int CmdRev(const char *Cmd);
|
||||||
|
|
||||||
//For storing command that are received from the device
|
//For storing command that are received from the device
|
||||||
static UsbCommand cmdBuffer[CMD_BUFFER_SIZE];
|
static UsbCommand cmdBuffer[CMD_BUFFER_SIZE];
|
||||||
|
@ -43,12 +44,12 @@ static int cmd_tail;//Starts as 0
|
||||||
static command_t CommandTable[] =
|
static command_t CommandTable[] =
|
||||||
{
|
{
|
||||||
{"help", CmdHelp, 1, "This help. Use '<command> help' for details of a particular command."},
|
{"help", CmdHelp, 1, "This help. Use '<command> help' for details of a particular command."},
|
||||||
{"crc", CmdCrc, 1, "Crc calculations from the software reveng1-30"},
|
|
||||||
{"data", CmdData, 1, "{ Plot window / data buffer manipulation... }"},
|
{"data", CmdData, 1, "{ Plot window / data buffer manipulation... }"},
|
||||||
{"hf", CmdHF, 1, "{ High Frequency commands... }"},
|
{"hf", CmdHF, 1, "{ High Frequency commands... }"},
|
||||||
{"hw", CmdHW, 1, "{ Hardware commands... }"},
|
{"hw", CmdHW, 1, "{ Hardware commands... }"},
|
||||||
{"lf", CmdLF, 1, "{ Low Frequency commands... }"},
|
{"lf", CmdLF, 1, "{ Low Frequency commands... }"},
|
||||||
{"script",CmdScript,1,"{ Scripting commands }"},
|
{"reveng",CmdRev, 1, "Crc calculations from the software reveng1-30"},
|
||||||
|
{"script",CmdScript,1, "{ Scripting commands }"},
|
||||||
{"quit", CmdQuit, 1, "Exit program"},
|
{"quit", CmdQuit, 1, "Exit program"},
|
||||||
{"exit", CmdQuit, 1, "Exit program"},
|
{"exit", CmdQuit, 1, "Exit program"},
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
|
@ -69,6 +70,12 @@ int CmdQuit(const char *Cmd)
|
||||||
exit(0);
|
exit(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CmdRev(const char *Cmd)
|
||||||
|
{
|
||||||
|
CmdCrc(Cmd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @brief This method should be called when sending a new command to the pm3. In case any old
|
* @brief This method should be called when sending a new command to the pm3. In case any old
|
||||||
* responses from previous commands are stored in the buffer, a call to this method should clear them.
|
* responses from previous commands are stored in the buffer, a call to this method should clear them.
|
||||||
|
|
|
@ -89,7 +89,7 @@ int reveng_main(int argc, char *argv[]) {
|
||||||
model_t pset = model, *candmods, *mptr;
|
model_t pset = model, *candmods, *mptr;
|
||||||
char *string;
|
char *string;
|
||||||
|
|
||||||
//myname = argv[0];
|
myname = argv[0];
|
||||||
|
|
||||||
/* stdin must be binary */
|
/* stdin must be binary */
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -97,7 +97,9 @@ int reveng_main(int argc, char *argv[]) {
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
SETBMP();
|
SETBMP();
|
||||||
|
|
||||||
|
pos=0;
|
||||||
|
optind=1;
|
||||||
do {
|
do {
|
||||||
c=getopt(argc, argv, "?A:BDFLMP:SVXa:bcdefhi:k:lm:p:q:rstuvw:x:yz");
|
c=getopt(argc, argv, "?A:BDFLMP:SVXa:bcdefhi:k:lm:p:q:rstuvw:x:yz");
|
||||||
switch(c) {
|
switch(c) {
|
||||||
|
@ -487,7 +489,8 @@ void
|
||||||
uerror(const char *msg) {
|
uerror(const char *msg) {
|
||||||
/* Callback function to report fatal errors */
|
/* Callback function to report fatal errors */
|
||||||
fprintf(stderr, "%s: %s\n", myname, msg);
|
fprintf(stderr, "%s: %s\n", myname, msg);
|
||||||
exit(EXIT_FAILURE);
|
return;
|
||||||
|
//exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -545,7 +548,8 @@ oread(const char *name) {
|
||||||
return(stdin);
|
return(stdin);
|
||||||
if(!(handle = fopen(name, "rb"))) {
|
if(!(handle = fopen(name, "rb"))) {
|
||||||
fprintf(stderr, "%s: cannot open '%s' for reading\n", myname, name);
|
fprintf(stderr, "%s: cannot open '%s' for reading\n", myname, name);
|
||||||
exit(EXIT_FAILURE);
|
return 0;
|
||||||
|
//exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
return(handle);
|
return(handle);
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,10 @@
|
||||||
* specific.
|
* specific.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* #define PRESETS 1 */
|
#ifdef _WIN32
|
||||||
|
#define PRESETS 1 //
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Macros defining the size of a bmp_t.
|
/* Macros defining the size of a bmp_t.
|
||||||
* Their values only matter if PRESETS and/or BMPMACRO are defined, in
|
* Their values only matter if PRESETS and/or BMPMACRO are defined, in
|
||||||
|
|
|
@ -30,10 +30,10 @@
|
||||||
|
|
||||||
char *optarg;
|
char *optarg;
|
||||||
int optind = 1, opterr, optopt;
|
int optind = 1, opterr, optopt;
|
||||||
|
int pos = 0;
|
||||||
int getopt(int argc, char *argv[], const char *optstring)
|
int getopt(int argc, char *argv[], const char *optstring)
|
||||||
{
|
{
|
||||||
static int pos = 0;
|
//static int pos = 0;
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
if (pos == 0) {
|
if (pos == 0) {
|
||||||
|
|
|
@ -21,5 +21,5 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern char *optarg;
|
extern char *optarg;
|
||||||
extern int optind, opterr, optopt;
|
extern int optind, opterr, optopt, pos;
|
||||||
int getopt(int argc, char *argv[], const char *optstring);
|
int getopt(int argc, char *argv[], const char *optstring);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue