Fix reveng

This commit is contained in:
marshmellow42 2015-06-07 00:10:54 -04:00
commit f46c366321
7 changed files with 68 additions and 39 deletions

View file

@ -10,43 +10,59 @@
#include <stdio.h>
#include <string.h>
//#include <stdlib.h>
//#include <ctype.h>
#include "cmdmain.h"
#include "cmdparser.h"
#include "cmdcrc.h"
#include "reveng/reveng.h"
//#include "reveng/cli.h"
static int CmdHelp(const char *Cmd);
#include "ui.h"
#include "util.h"
int CmdCrcCalc(const char *Cmd)
{
int argc = 0;
char Cmd2[CMD_BUFFER_SIZE] = {0x00};
char *argv[3];
#define MAX_ARGS 20
for (int i = 0; i < 50; i++)
if (Cmd[i]==0x00) argc=i;
int split(char *str, char *arr[MAX_ARGS]){
int beginIndex = 0;
int endIndex;
int maxWords = MAX_ARGS;
int wordCnt = 0;
memcpy(Cmd2, Cmd, argc);
argv[1]=Cmd2;
reveng_main(argc, argv);
return 0;
while(1){
while(isspace(str[beginIndex])){
++beginIndex;
}
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)
{
CmdsParse(CommandTable, Cmd);
char name[] = {"reveng "};
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;
}

View file

@ -12,5 +12,4 @@
#define CMDCRC_H__
int CmdCrc(const char *Cmd);
int CmdCrcCalc(const char *Cmd);
#endif

View file

@ -32,6 +32,7 @@ unsigned int current_command = CMD_UNKNOWN;
static int CmdHelp(const char *Cmd);
static int CmdQuit(const char *Cmd);
static int CmdRev(const char *Cmd);
//For storing command that are received from the device
static UsbCommand cmdBuffer[CMD_BUFFER_SIZE];
@ -43,12 +44,12 @@ static int cmd_tail;//Starts as 0
static command_t CommandTable[] =
{
{"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... }"},
{"hf", CmdHF, 1, "{ High Frequency commands... }"},
{"hw", CmdHW, 1, "{ Hardware 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"},
{"exit", CmdQuit, 1, "Exit program"},
{NULL, NULL, 0, NULL}
@ -69,6 +70,12 @@ int CmdQuit(const char *Cmd)
exit(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
* responses from previous commands are stored in the buffer, a call to this method should clear them.

View file

@ -89,7 +89,7 @@ int reveng_main(int argc, char *argv[]) {
model_t pset = model, *candmods, *mptr;
char *string;
//myname = argv[0];
myname = argv[0];
/* stdin must be binary */
#ifdef _WIN32
@ -98,6 +98,8 @@ int reveng_main(int argc, char *argv[]) {
SETBMP();
pos=0;
optind=1;
do {
c=getopt(argc, argv, "?A:BDFLMP:SVXa:bcdefhi:k:lm:p:q:rstuvw:x:yz");
switch(c) {
@ -487,7 +489,8 @@ void
uerror(const char *msg) {
/* Callback function to report fatal errors */
fprintf(stderr, "%s: %s\n", myname, msg);
exit(EXIT_FAILURE);
return;
//exit(EXIT_FAILURE);
}
void
@ -545,7 +548,8 @@ oread(const char *name) {
return(stdin);
if(!(handle = fopen(name, "rb"))) {
fprintf(stderr, "%s: cannot open '%s' for reading\n", myname, name);
exit(EXIT_FAILURE);
return 0;
//exit(EXIT_FAILURE);
}
return(handle);
}

View file

@ -61,7 +61,10 @@
* specific.
*/
/* #define PRESETS 1 */
#ifdef _WIN32
#define PRESETS 1 //
#endif
/* Macros defining the size of a bmp_t.
* Their values only matter if PRESETS and/or BMPMACRO are defined, in

View file

@ -30,10 +30,10 @@
char *optarg;
int optind = 1, opterr, optopt;
int pos = 0;
int getopt(int argc, char *argv[], const char *optstring)
{
static int pos = 0;
//static int pos = 0;
char *str;
if (pos == 0) {

View file

@ -21,5 +21,5 @@
*/
extern char *optarg;
extern int optind, opterr, optopt;
extern int optind, opterr, optopt, pos;
int getopt(int argc, char *argv[], const char *optstring);