2010-02-21 08:47:22 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// 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.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Command parser
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2018-03-31 15:52:43 +08:00
|
|
|
#include "cmdparser.h"
|
|
|
|
|
Client cleanup and restructuring. Stage 1...
Next Step is refactoring some of the giant functions which are
just copy/paste of some other ones with just a few line changes,
removing unnecessary 'goto' etc.
The MS Windows version is broken with this commit but will be fixed
soon. Everything can't be done all at once :P
The commands are now hierarchical, for example:
"hf 14a read" vs. "hf 14b read".
You can also request help:
"hf help", "data help", "hf 15 help" etc.
Indents are now space-based, not tab-based anymore. Hopefully
no one will be trolling about it, considering the suicide-prone work
being done here ;)
client/cmdhw.c, client/proxusb.c, client/cmdhw.h, client/proxusb.h,
client/cmdmain.c, client/cmdlfhid.c, client/cmdmain.h, client/cmdlfhid.h,
client/data.c, client/data.h, client/cmdhf.c, client/cmdlf.c,
client/cmdhf.h, client/cmdhf15.c, client/cmdhf14b.c, client/cmdlf.h,
client/cmdhf15.h, client/cmdhf14b.h, client/cmddata.c, client/cmddata.h,
client/ui.c, client/cmdparser.c, client/cmdlfti.c, client/ui.h,
client/cmdlfem4x.c, client/cmdparser.h, client/cmdlfti.h, client/cmdlfem4x.h,
client/graph.c, client/graph.h, client/cmdhf14a.c, client/cmdhf14a.h,
client/cmdhflegic.c, client/cmdhflegic.c: New files.
client/cli.c, client/flasher.c, client/snooper.c, client/proxmark3.c,
client/proxmark3.h, client/Makefile: Update accordingly.
client/flash.h, client/flash.c, client/proxgui.cpp: Cosmetic changes.
client/translate.h, client/command.c, client/gui.c,
client/usb.c, client/prox.h: Remove.
include/usb_cmd.h (CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM): Remove dead cmd.
common/crc16.h: New file.
common/crc16.c: Modify accordingly.
common/iso14443crc.h: New file.
common/iso14443_crc.c: Rename to
common/iso14443crc.c: and modify accordingly.
armsrc/lfops.c, armsrc/iso14443.c,
armsrc/iso14443a.c: include .h files from
the common directory instead of including the c files.
common/Makefile.common, armsrc/Makefile: Modify accordingly.
2010-02-04 09:27:07 +08:00
|
|
|
#include <stdio.h>
|
2014-03-27 05:35:25 +08:00
|
|
|
#include <stdlib.h>
|
Client cleanup and restructuring. Stage 1...
Next Step is refactoring some of the giant functions which are
just copy/paste of some other ones with just a few line changes,
removing unnecessary 'goto' etc.
The MS Windows version is broken with this commit but will be fixed
soon. Everything can't be done all at once :P
The commands are now hierarchical, for example:
"hf 14a read" vs. "hf 14b read".
You can also request help:
"hf help", "data help", "hf 15 help" etc.
Indents are now space-based, not tab-based anymore. Hopefully
no one will be trolling about it, considering the suicide-prone work
being done here ;)
client/cmdhw.c, client/proxusb.c, client/cmdhw.h, client/proxusb.h,
client/cmdmain.c, client/cmdlfhid.c, client/cmdmain.h, client/cmdlfhid.h,
client/data.c, client/data.h, client/cmdhf.c, client/cmdlf.c,
client/cmdhf.h, client/cmdhf15.c, client/cmdhf14b.c, client/cmdlf.h,
client/cmdhf15.h, client/cmdhf14b.h, client/cmddata.c, client/cmddata.h,
client/ui.c, client/cmdparser.c, client/cmdlfti.c, client/ui.h,
client/cmdlfem4x.c, client/cmdparser.h, client/cmdlfti.h, client/cmdlfem4x.h,
client/graph.c, client/graph.h, client/cmdhf14a.c, client/cmdhf14a.h,
client/cmdhflegic.c, client/cmdhflegic.c: New files.
client/cli.c, client/flasher.c, client/snooper.c, client/proxmark3.c,
client/proxmark3.h, client/Makefile: Update accordingly.
client/flash.h, client/flash.c, client/proxgui.cpp: Cosmetic changes.
client/translate.h, client/command.c, client/gui.c,
client/usb.c, client/prox.h: Remove.
include/usb_cmd.h (CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM): Remove dead cmd.
common/crc16.h: New file.
common/crc16.c: Modify accordingly.
common/iso14443crc.h: New file.
common/iso14443_crc.c: Rename to
common/iso14443crc.c: and modify accordingly.
armsrc/lfops.c, armsrc/iso14443.c,
armsrc/iso14443a.c: include .h files from
the common directory instead of including the c files.
common/Makefile.common, armsrc/Makefile: Modify accordingly.
2010-02-04 09:27:07 +08:00
|
|
|
#include <string.h>
|
|
|
|
#include "ui.h"
|
2012-12-05 07:39:18 +08:00
|
|
|
#include "proxmark3.h"
|
2018-03-31 15:52:43 +08:00
|
|
|
#include "comms.h"
|
Client cleanup and restructuring. Stage 1...
Next Step is refactoring some of the giant functions which are
just copy/paste of some other ones with just a few line changes,
removing unnecessary 'goto' etc.
The MS Windows version is broken with this commit but will be fixed
soon. Everything can't be done all at once :P
The commands are now hierarchical, for example:
"hf 14a read" vs. "hf 14b read".
You can also request help:
"hf help", "data help", "hf 15 help" etc.
Indents are now space-based, not tab-based anymore. Hopefully
no one will be trolling about it, considering the suicide-prone work
being done here ;)
client/cmdhw.c, client/proxusb.c, client/cmdhw.h, client/proxusb.h,
client/cmdmain.c, client/cmdlfhid.c, client/cmdmain.h, client/cmdlfhid.h,
client/data.c, client/data.h, client/cmdhf.c, client/cmdlf.c,
client/cmdhf.h, client/cmdhf15.c, client/cmdhf14b.c, client/cmdlf.h,
client/cmdhf15.h, client/cmdhf14b.h, client/cmddata.c, client/cmddata.h,
client/ui.c, client/cmdparser.c, client/cmdlfti.c, client/ui.h,
client/cmdlfem4x.c, client/cmdparser.h, client/cmdlfti.h, client/cmdlfem4x.h,
client/graph.c, client/graph.h, client/cmdhf14a.c, client/cmdhf14a.h,
client/cmdhflegic.c, client/cmdhflegic.c: New files.
client/cli.c, client/flasher.c, client/snooper.c, client/proxmark3.c,
client/proxmark3.h, client/Makefile: Update accordingly.
client/flash.h, client/flash.c, client/proxgui.cpp: Cosmetic changes.
client/translate.h, client/command.c, client/gui.c,
client/usb.c, client/prox.h: Remove.
include/usb_cmd.h (CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM): Remove dead cmd.
common/crc16.h: New file.
common/crc16.c: Modify accordingly.
common/iso14443crc.h: New file.
common/iso14443_crc.c: Rename to
common/iso14443crc.c: and modify accordingly.
armsrc/lfops.c, armsrc/iso14443.c,
armsrc/iso14443a.c: include .h files from
the common directory instead of including the c files.
common/Makefile.common, armsrc/Makefile: Modify accordingly.
2010-02-04 09:27:07 +08:00
|
|
|
|
2015-11-06 18:34:43 +08:00
|
|
|
|
Client cleanup and restructuring. Stage 1...
Next Step is refactoring some of the giant functions which are
just copy/paste of some other ones with just a few line changes,
removing unnecessary 'goto' etc.
The MS Windows version is broken with this commit but will be fixed
soon. Everything can't be done all at once :P
The commands are now hierarchical, for example:
"hf 14a read" vs. "hf 14b read".
You can also request help:
"hf help", "data help", "hf 15 help" etc.
Indents are now space-based, not tab-based anymore. Hopefully
no one will be trolling about it, considering the suicide-prone work
being done here ;)
client/cmdhw.c, client/proxusb.c, client/cmdhw.h, client/proxusb.h,
client/cmdmain.c, client/cmdlfhid.c, client/cmdmain.h, client/cmdlfhid.h,
client/data.c, client/data.h, client/cmdhf.c, client/cmdlf.c,
client/cmdhf.h, client/cmdhf15.c, client/cmdhf14b.c, client/cmdlf.h,
client/cmdhf15.h, client/cmdhf14b.h, client/cmddata.c, client/cmddata.h,
client/ui.c, client/cmdparser.c, client/cmdlfti.c, client/ui.h,
client/cmdlfem4x.c, client/cmdparser.h, client/cmdlfti.h, client/cmdlfem4x.h,
client/graph.c, client/graph.h, client/cmdhf14a.c, client/cmdhf14a.h,
client/cmdhflegic.c, client/cmdhflegic.c: New files.
client/cli.c, client/flasher.c, client/snooper.c, client/proxmark3.c,
client/proxmark3.h, client/Makefile: Update accordingly.
client/flash.h, client/flash.c, client/proxgui.cpp: Cosmetic changes.
client/translate.h, client/command.c, client/gui.c,
client/usb.c, client/prox.h: Remove.
include/usb_cmd.h (CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM): Remove dead cmd.
common/crc16.h: New file.
common/crc16.c: Modify accordingly.
common/iso14443crc.h: New file.
common/iso14443_crc.c: Rename to
common/iso14443crc.c: and modify accordingly.
armsrc/lfops.c, armsrc/iso14443.c,
armsrc/iso14443a.c: include .h files from
the common directory instead of including the c files.
common/Makefile.common, armsrc/Makefile: Modify accordingly.
2010-02-04 09:27:07 +08:00
|
|
|
void CmdsHelp(const command_t Commands[])
|
|
|
|
{
|
|
|
|
if (Commands[0].Name == NULL)
|
|
|
|
return;
|
|
|
|
int i = 0;
|
|
|
|
while (Commands[i].Name)
|
|
|
|
{
|
2017-10-27 15:56:46 +08:00
|
|
|
if (!offline || Commands[i].Offline)
|
2014-03-27 06:51:22 +08:00
|
|
|
PrintAndLog("%-16s %s", Commands[i].Name, Commands[i].Help);
|
Client cleanup and restructuring. Stage 1...
Next Step is refactoring some of the giant functions which are
just copy/paste of some other ones with just a few line changes,
removing unnecessary 'goto' etc.
The MS Windows version is broken with this commit but will be fixed
soon. Everything can't be done all at once :P
The commands are now hierarchical, for example:
"hf 14a read" vs. "hf 14b read".
You can also request help:
"hf help", "data help", "hf 15 help" etc.
Indents are now space-based, not tab-based anymore. Hopefully
no one will be trolling about it, considering the suicide-prone work
being done here ;)
client/cmdhw.c, client/proxusb.c, client/cmdhw.h, client/proxusb.h,
client/cmdmain.c, client/cmdlfhid.c, client/cmdmain.h, client/cmdlfhid.h,
client/data.c, client/data.h, client/cmdhf.c, client/cmdlf.c,
client/cmdhf.h, client/cmdhf15.c, client/cmdhf14b.c, client/cmdlf.h,
client/cmdhf15.h, client/cmdhf14b.h, client/cmddata.c, client/cmddata.h,
client/ui.c, client/cmdparser.c, client/cmdlfti.c, client/ui.h,
client/cmdlfem4x.c, client/cmdparser.h, client/cmdlfti.h, client/cmdlfem4x.h,
client/graph.c, client/graph.h, client/cmdhf14a.c, client/cmdhf14a.h,
client/cmdhflegic.c, client/cmdhflegic.c: New files.
client/cli.c, client/flasher.c, client/snooper.c, client/proxmark3.c,
client/proxmark3.h, client/Makefile: Update accordingly.
client/flash.h, client/flash.c, client/proxgui.cpp: Cosmetic changes.
client/translate.h, client/command.c, client/gui.c,
client/usb.c, client/prox.h: Remove.
include/usb_cmd.h (CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM): Remove dead cmd.
common/crc16.h: New file.
common/crc16.c: Modify accordingly.
common/iso14443crc.h: New file.
common/iso14443_crc.c: Rename to
common/iso14443crc.c: and modify accordingly.
armsrc/lfops.c, armsrc/iso14443.c,
armsrc/iso14443a.c: include .h files from
the common directory instead of including the c files.
common/Makefile.common, armsrc/Makefile: Modify accordingly.
2010-02-04 09:27:07 +08:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-06 18:34:43 +08:00
|
|
|
|
|
|
|
int CmdsParse(const command_t Commands[], const char *Cmd)
|
Client cleanup and restructuring. Stage 1...
Next Step is refactoring some of the giant functions which are
just copy/paste of some other ones with just a few line changes,
removing unnecessary 'goto' etc.
The MS Windows version is broken with this commit but will be fixed
soon. Everything can't be done all at once :P
The commands are now hierarchical, for example:
"hf 14a read" vs. "hf 14b read".
You can also request help:
"hf help", "data help", "hf 15 help" etc.
Indents are now space-based, not tab-based anymore. Hopefully
no one will be trolling about it, considering the suicide-prone work
being done here ;)
client/cmdhw.c, client/proxusb.c, client/cmdhw.h, client/proxusb.h,
client/cmdmain.c, client/cmdlfhid.c, client/cmdmain.h, client/cmdlfhid.h,
client/data.c, client/data.h, client/cmdhf.c, client/cmdlf.c,
client/cmdhf.h, client/cmdhf15.c, client/cmdhf14b.c, client/cmdlf.h,
client/cmdhf15.h, client/cmdhf14b.h, client/cmddata.c, client/cmddata.h,
client/ui.c, client/cmdparser.c, client/cmdlfti.c, client/ui.h,
client/cmdlfem4x.c, client/cmdparser.h, client/cmdlfti.h, client/cmdlfem4x.h,
client/graph.c, client/graph.h, client/cmdhf14a.c, client/cmdhf14a.h,
client/cmdhflegic.c, client/cmdhflegic.c: New files.
client/cli.c, client/flasher.c, client/snooper.c, client/proxmark3.c,
client/proxmark3.h, client/Makefile: Update accordingly.
client/flash.h, client/flash.c, client/proxgui.cpp: Cosmetic changes.
client/translate.h, client/command.c, client/gui.c,
client/usb.c, client/prox.h: Remove.
include/usb_cmd.h (CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM): Remove dead cmd.
common/crc16.h: New file.
common/crc16.c: Modify accordingly.
common/iso14443crc.h: New file.
common/iso14443_crc.c: Rename to
common/iso14443crc.c: and modify accordingly.
armsrc/lfops.c, armsrc/iso14443.c,
armsrc/iso14443a.c: include .h files from
the common directory instead of including the c files.
common/Makefile.common, armsrc/Makefile: Modify accordingly.
2010-02-04 09:27:07 +08:00
|
|
|
{
|
2015-11-06 18:34:43 +08:00
|
|
|
if(strcmp( Cmd, "XX_internal_command_dump_XX") == 0)
|
|
|
|
{// Help dump children
|
|
|
|
dumpCommandsRecursive(Commands, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(strcmp( Cmd, "XX_internal_command_dump_markdown_XX") == 0)
|
|
|
|
{// Markdown help dump children
|
|
|
|
dumpCommandsRecursive(Commands, 1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
char cmd_name[32];
|
|
|
|
int len = 0;
|
|
|
|
memset(cmd_name, 0, 32);
|
|
|
|
sscanf(Cmd, "%31s%n", cmd_name, &len);
|
|
|
|
int i = 0;
|
|
|
|
while (Commands[i].Name && strcmp(Commands[i].Name, cmd_name))
|
|
|
|
++i;
|
2010-02-08 17:23:39 +08:00
|
|
|
|
2015-11-06 18:34:43 +08:00
|
|
|
/* try to find exactly one prefix-match */
|
|
|
|
if(!Commands[i].Name) {
|
|
|
|
int last_match = 0;
|
|
|
|
int matches = 0;
|
2010-02-08 17:23:39 +08:00
|
|
|
|
2015-11-06 18:34:43 +08:00
|
|
|
for(i=0;Commands[i].Name;i++) {
|
|
|
|
if( !strncmp(Commands[i].Name, cmd_name, strlen(cmd_name)) ) {
|
|
|
|
last_match = i;
|
|
|
|
matches++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(matches == 1) i=last_match;
|
|
|
|
}
|
2010-02-08 17:23:39 +08:00
|
|
|
|
2015-11-06 18:34:43 +08:00
|
|
|
if (Commands[i].Name) {
|
|
|
|
while (Cmd[len] == ' ')
|
|
|
|
++len;
|
|
|
|
return Commands[i].Parse(Cmd + len);
|
|
|
|
} else {
|
|
|
|
// show help for selected hierarchy or if command not recognised
|
|
|
|
CmdsHelp(Commands);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
Client cleanup and restructuring. Stage 1...
Next Step is refactoring some of the giant functions which are
just copy/paste of some other ones with just a few line changes,
removing unnecessary 'goto' etc.
The MS Windows version is broken with this commit but will be fixed
soon. Everything can't be done all at once :P
The commands are now hierarchical, for example:
"hf 14a read" vs. "hf 14b read".
You can also request help:
"hf help", "data help", "hf 15 help" etc.
Indents are now space-based, not tab-based anymore. Hopefully
no one will be trolling about it, considering the suicide-prone work
being done here ;)
client/cmdhw.c, client/proxusb.c, client/cmdhw.h, client/proxusb.h,
client/cmdmain.c, client/cmdlfhid.c, client/cmdmain.h, client/cmdlfhid.h,
client/data.c, client/data.h, client/cmdhf.c, client/cmdlf.c,
client/cmdhf.h, client/cmdhf15.c, client/cmdhf14b.c, client/cmdlf.h,
client/cmdhf15.h, client/cmdhf14b.h, client/cmddata.c, client/cmddata.h,
client/ui.c, client/cmdparser.c, client/cmdlfti.c, client/ui.h,
client/cmdlfem4x.c, client/cmdparser.h, client/cmdlfti.h, client/cmdlfem4x.h,
client/graph.c, client/graph.h, client/cmdhf14a.c, client/cmdhf14a.h,
client/cmdhflegic.c, client/cmdhflegic.c: New files.
client/cli.c, client/flasher.c, client/snooper.c, client/proxmark3.c,
client/proxmark3.h, client/Makefile: Update accordingly.
client/flash.h, client/flash.c, client/proxgui.cpp: Cosmetic changes.
client/translate.h, client/command.c, client/gui.c,
client/usb.c, client/prox.h: Remove.
include/usb_cmd.h (CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM): Remove dead cmd.
common/crc16.h: New file.
common/crc16.c: Modify accordingly.
common/iso14443crc.h: New file.
common/iso14443_crc.c: Rename to
common/iso14443crc.c: and modify accordingly.
armsrc/lfops.c, armsrc/iso14443.c,
armsrc/iso14443a.c: include .h files from
the common directory instead of including the c files.
common/Makefile.common, armsrc/Makefile: Modify accordingly.
2010-02-04 09:27:07 +08:00
|
|
|
}
|
2014-03-27 05:35:25 +08:00
|
|
|
|
|
|
|
char pparent[512] = {0};
|
|
|
|
char *parent = pparent;
|
|
|
|
|
2014-03-27 06:35:53 +08:00
|
|
|
void dumpCommandsRecursive(const command_t cmds[], int markdown)
|
2014-03-27 05:35:25 +08:00
|
|
|
{
|
2014-03-27 06:35:53 +08:00
|
|
|
if (cmds[0].Name == NULL)
|
2014-03-27 05:35:25 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
int i = 0;
|
2014-03-27 06:35:53 +08:00
|
|
|
int w_cmd=25;
|
|
|
|
int w_off=8;
|
2014-03-27 05:35:25 +08:00
|
|
|
// First, dump all single commands, which are not a container for
|
|
|
|
// other commands
|
2014-03-27 06:35:53 +08:00
|
|
|
if (markdown) {
|
2014-03-27 23:49:37 +08:00
|
|
|
printf("|%-*s|%-*s|%s\n",w_cmd,"command",w_off,"offline","description");
|
|
|
|
printf("|%-*s|%-*s|%s\n",w_cmd,"-------",w_off,"-------","-----------");
|
2014-03-27 06:35:53 +08:00
|
|
|
} else {
|
|
|
|
printf("%-*s|%-*s|%s\n",w_cmd,"command",w_off,"offline","description");
|
|
|
|
printf("%-*s|%-*s|%s\n",w_cmd,"-------",w_off,"-------","-----------");
|
|
|
|
}
|
2014-03-27 05:35:25 +08:00
|
|
|
|
|
|
|
while (cmds[i].Name)
|
|
|
|
{
|
2014-03-27 06:35:53 +08:00
|
|
|
char* cmd_offline = "N";
|
2014-03-27 05:35:25 +08:00
|
|
|
if(cmds[i].Help[0] == '{' && ++i) continue;
|
|
|
|
|
2014-03-27 06:35:53 +08:00
|
|
|
if ( cmds[i].Offline) cmd_offline = "Y";
|
|
|
|
if (markdown)
|
2014-03-27 23:49:37 +08:00
|
|
|
printf("|`%s%-*s`|%-*s|`%s`\n", parent, w_cmd-(int)strlen(parent)-2, cmds[i].Name, w_off, cmd_offline, cmds[i].Help);
|
2014-03-27 06:35:53 +08:00
|
|
|
else
|
|
|
|
printf("%s%-*s|%-*s|%s\n", parent, w_cmd-(int)strlen(parent), cmds[i].Name, w_off, cmd_offline, cmds[i].Help);
|
2014-03-27 05:35:25 +08:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
printf("\n\n");
|
|
|
|
i=0;
|
|
|
|
// Then, print the categories. These will go into subsections with their own tables
|
|
|
|
|
|
|
|
while (cmds[i].Name)
|
|
|
|
{
|
|
|
|
if(cmds[i].Help[0] != '{' && ++i) continue;
|
|
|
|
|
2014-03-27 06:35:53 +08:00
|
|
|
printf("### %s%s\n\n %s\n\n", parent, cmds[i].Name, cmds[i].Help);
|
2014-03-27 05:35:25 +08:00
|
|
|
|
|
|
|
char currentparent[512] = {0};
|
|
|
|
snprintf(currentparent, sizeof currentparent, "%s%s ", parent, cmds[i].Name);
|
|
|
|
char *old_parent = parent;
|
|
|
|
parent = currentparent;
|
|
|
|
// This is what causes the recursion, since commands Parse-implementation
|
|
|
|
// in turn calls the CmdsParse above.
|
2014-03-27 06:35:53 +08:00
|
|
|
if (markdown)
|
|
|
|
cmds[i].Parse("XX_internal_command_dump_markdown_XX");
|
|
|
|
else
|
|
|
|
cmds[i].Parse("XX_internal_command_dump_XX");
|
2014-03-27 05:35:25 +08:00
|
|
|
parent = old_parent;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|