mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-20 05:13:22 -07:00
Finally, rewrote bootrom and flasher program, much faster now
This commit is contained in:
parent
79a73ab2d1
commit
28fdb04fd8
38 changed files with 311 additions and 1032 deletions
|
@ -14,7 +14,7 @@ OBJDIR = obj
|
|||
|
||||
LDLIBS = -L/opt/local/lib -L/usr/local/lib -lusb -lreadline -lpthread
|
||||
LDFLAGS = $(COMMON_FLAGS)
|
||||
CFLAGS = -std=gnu99 -I. -I../include -I../common -I/opt/local/include -Wall -Wno-unused-function $(COMMON_FLAGS) -g -O3
|
||||
CFLAGS = -std=c99 -I. -I../include -I../common -I/opt/local/include -Wall -Wno-unused-function $(COMMON_FLAGS) -g -O4
|
||||
|
||||
ifneq (,$(findstring MINGW,$(platform)))
|
||||
CXXFLAGS = -I$(QTDIR)/include -I$(QTDIR)/include/QtCore -I$(QTDIR)/include/QtGui
|
||||
|
@ -30,7 +30,7 @@ CXXFLAGS = -I/Library/Frameworks/QtGui.framework/Versions/Current/Headers -I/Lib
|
|||
QTLDLIBS = -framework QtGui -framework QtCore
|
||||
MOC = moc
|
||||
else
|
||||
CXXFLAGS = $(shell pkg-config --cflags QtCore QtGui 2>/dev/null) -Wall -O3
|
||||
CXXFLAGS = $(shell pkg-config --cflags QtCore QtGui 2>/dev/null) -Wall -O4
|
||||
QTLDLIBS = $(shell pkg-config --libs QtCore QtGui 2>/dev/null)
|
||||
MOC = $(shell pkg-config --variable=moc_location QtCore)
|
||||
endif
|
||||
|
@ -67,14 +67,15 @@ CMDSRCS = \
|
|||
cmdhfmf.c \
|
||||
cmdhw.c \
|
||||
cmdlf.c \
|
||||
cmdlfem4x.c \
|
||||
cmdlfhid.c \
|
||||
cmdlfem4x.c \
|
||||
cmdlfhitag.c \
|
||||
cmdlfti.c \
|
||||
cmdparser.c \
|
||||
cmdmain.c \
|
||||
uart.c
|
||||
|
||||
|
||||
CMDOBJS = $(CMDSRCS:%.c=$(OBJDIR)/%.o)
|
||||
|
||||
RM = rm -f
|
||||
|
@ -87,16 +88,16 @@ all-static: LDLIBS:=-static $(LDLIBS)
|
|||
all-static: snooper cli flasher
|
||||
|
||||
proxmark3: LDLIBS+=$(QTLDLIBS)
|
||||
proxmark3: $(OBJDIR)/proxmark3.o $(CMDOBJS) $(OBJDIR)/proxusb.o $(QTGUI)
|
||||
proxmark3: $(OBJDIR)/proxmark3.o $(CMDOBJS) $(OBJDIR)/uart.o $(QTGUI)
|
||||
$(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o $@
|
||||
|
||||
snooper: $(OBJDIR)/snooper.o $(CMDOBJS) $(OBJDIR)/proxusb.o $(OBJDIR)/guidummy.o
|
||||
snooper: $(OBJDIR)/snooper.o $(CMDOBJS) $(OBJDIR)/uart.o $(OBJDIR)/guidummy.o
|
||||
$(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o $@
|
||||
|
||||
cli: $(OBJDIR)/cli.o $(CMDOBJS) $(OBJDIR)/proxusb.o $(OBJDIR)/guidummy.o
|
||||
cli: $(OBJDIR)/cli.o $(CMDOBJS) $(OBJDIR)/uart.o $(OBJDIR)/guidummy.o
|
||||
$(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o $@
|
||||
|
||||
flasher: $(OBJDIR)/flash.o $(OBJDIR)/flasher.o $(OBJDIR)/proxusb.o
|
||||
flasher: $(OBJDIR)/flash.o $(OBJDIR)/flasher.o $(OBJDIR)/uart.o
|
||||
$(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o $@
|
||||
|
||||
$(OBJDIR)/%.o: %.c
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include "proxusb.h"
|
||||
//#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "data.h"
|
||||
#include "ui.h"
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <stdio.h>
|
||||
#include "proxusb.h"
|
||||
//#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "graph.h"
|
||||
#include "ui.h"
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include "util.h"
|
||||
#include "iso14443crc.h"
|
||||
#include "data.h"
|
||||
#include "proxusb.h"
|
||||
//#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "ui.h"
|
||||
#include "cmdparser.h"
|
||||
|
@ -169,7 +169,6 @@ int CmdHF14AReader(const char *Cmd)
|
|||
WaitForResponse(CMD_ACK,&resp);
|
||||
|
||||
iso14a_card_select_t *card = (iso14a_card_select_t *)resp.d.asBytes;
|
||||
uint8_t * uid = card->uid;
|
||||
|
||||
if(resp.arg[0] == 0) {
|
||||
PrintAndLog("iso14443a card select failed");
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include "iso14443crc.h"
|
||||
#include "proxusb.h"
|
||||
//#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "data.h"
|
||||
#include "graph.h"
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include "proxusb.h"
|
||||
//#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "data.h"
|
||||
#include "graph.h"
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "util.h"
|
||||
#include "proxusb.h"
|
||||
//#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "ui.h"
|
||||
#include "cmdparser.h"
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include <string.h>
|
||||
#include "iso14443crc.h" // Can also be used for iClass, using 0xE012 as CRC-type
|
||||
#include "data.h"
|
||||
#include "proxusb.h"
|
||||
//#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "ui.h"
|
||||
#include "cmdparser.h"
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "proxusb.h"
|
||||
//#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "data.h"
|
||||
#include "ui.h"
|
||||
|
@ -324,7 +324,7 @@ int CmdLegicRfSim(const char *Cmd)
|
|||
c.arg[0] = 6;
|
||||
c.arg[1] = 3;
|
||||
c.arg[2] = 0;
|
||||
sscanf(Cmd, " %i %i %i", &c.arg[0], &c.arg[1], &c.arg[2]);
|
||||
sscanf(Cmd, " %lli %lli %lli", &c.arg[0], &c.arg[1], &c.arg[2]);
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
|
@ -332,7 +332,7 @@ int CmdLegicRfSim(const char *Cmd)
|
|||
int CmdLegicRfWrite(const char *Cmd)
|
||||
{
|
||||
UsbCommand c={CMD_WRITER_LEGIC_RF};
|
||||
int res = sscanf(Cmd, " 0x%x 0x%x", &c.arg[0], &c.arg[1]);
|
||||
int res = sscanf(Cmd, " 0x%llx 0x%llx", &c.arg[0], &c.arg[1]);
|
||||
if(res != 2) {
|
||||
PrintAndLog("Please specify the offset and length as two hex strings");
|
||||
return -1;
|
||||
|
@ -344,7 +344,7 @@ int CmdLegicRfWrite(const char *Cmd)
|
|||
int CmdLegicRfFill(const char *Cmd)
|
||||
{
|
||||
UsbCommand cmd ={CMD_WRITER_LEGIC_RF};
|
||||
int res = sscanf(Cmd, " 0x%x 0x%x 0x%x", &cmd.arg[0], &cmd.arg[1], &cmd.arg[2]);
|
||||
int res = sscanf(Cmd, " 0x%llx 0x%llx 0x%llx", &cmd.arg[0], &cmd.arg[1], &cmd.arg[2]);
|
||||
if(res != 3) {
|
||||
PrintAndLog("Please specify the offset, length and value as two hex strings");
|
||||
return -1;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "proxmark3.h"
|
||||
#include "iso14443crc.h"
|
||||
#include "data.h"
|
||||
#include "proxusb.h"
|
||||
//#include "proxusb.h"
|
||||
#include "ui.h"
|
||||
#include "cmdparser.h"
|
||||
#include "common.h"
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include "ui.h"
|
||||
#include "proxusb.h"
|
||||
//#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "cmdparser.h"
|
||||
#include "cmdhw.h"
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include "proxusb.h"
|
||||
//#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "data.h"
|
||||
#include "graph.h"
|
||||
|
@ -36,7 +36,7 @@ int CmdLFCommandRead(const char *Cmd)
|
|||
dummy[0]= ' ';
|
||||
|
||||
UsbCommand c = {CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K};
|
||||
sscanf(Cmd, "%i %i %i %s %s", &c.arg[0], &c.arg[1], &c.arg[2], (char *) &c.d.asBytes,(char *) &dummy+1);
|
||||
sscanf(Cmd, "%lli %lli %lli %s %s", &c.arg[0], &c.arg[1], &c.arg[2], (char *) &c.d.asBytes,(char *) &dummy+1);
|
||||
// in case they specified 'h'
|
||||
strcpy((char *)&c.d.asBytes + strlen((char *)c.d.asBytes), dummy);
|
||||
SendCommand(&c);
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include "proxusb.h"
|
||||
//#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "ui.h"
|
||||
#include "graph.h"
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <stdio.h>
|
||||
#include "proxusb.h"
|
||||
//#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "ui.h"
|
||||
#include "graph.h"
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "data.h"
|
||||
#include "proxusb.h"
|
||||
//#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "ui.h"
|
||||
#include "cmdparser.h"
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "crc16.h"
|
||||
#include "proxusb.h"
|
||||
//#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "data.h"
|
||||
#include "ui.h"
|
||||
|
@ -274,7 +274,7 @@ int CmdTIWrite(const char *Cmd)
|
|||
UsbCommand c = {CMD_WRITE_TI_TYPE};
|
||||
int res = 0;
|
||||
|
||||
res = sscanf(Cmd, "0x%x 0x%x 0x%x ", &c.arg[0], &c.arg[1], &c.arg[2]);
|
||||
res = sscanf(Cmd, "0x%llx 0x%llx 0x%llx ", &c.arg[0], &c.arg[1], &c.arg[2]);
|
||||
if (res == 2) c.arg[2]=0;
|
||||
if (res < 2)
|
||||
PrintAndLog("Please specify the data as two hex strings, optionally the CRC as a third");
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <stdint.h>
|
||||
#include "data.h"
|
||||
#include "ui.h"
|
||||
#include "proxusb.h"
|
||||
//#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "cmdmain.h"
|
||||
|
||||
|
|
|
@ -12,10 +12,16 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "sleep.h"
|
||||
#include "proxusb.h"
|
||||
//#include "proxusb.h"
|
||||
#include "flash.h"
|
||||
#include "elf.h"
|
||||
#include "proxendian.h"
|
||||
#include "usb_cmd.h"
|
||||
|
||||
void SendCommand(UsbCommand* txcmd);
|
||||
void ReceiveCommand(UsbCommand* rxcmd);
|
||||
void CloseProxmark();
|
||||
int OpenProxmark(size_t i);
|
||||
|
||||
// FIXME: what the fuckity fuck
|
||||
unsigned int current_command = CMD_UNKNOWN;
|
||||
|
@ -26,7 +32,7 @@ unsigned int current_command = CMD_UNKNOWN;
|
|||
#define BOOTLOADER_SIZE 0x2000
|
||||
#define BOOTLOADER_END (FLASH_START + BOOTLOADER_SIZE)
|
||||
|
||||
#define BLOCK_SIZE 0x100
|
||||
#define BLOCK_SIZE 0x200
|
||||
|
||||
static const uint8_t elf_ident[] = {
|
||||
0x7f, 'E', 'L', 'F',
|
||||
|
@ -267,11 +273,11 @@ fail:
|
|||
// Get the state of the proxmark, backwards compatible
|
||||
static int get_proxmark_state(uint32_t *state)
|
||||
{
|
||||
HidCommand c;
|
||||
UsbCommand c;
|
||||
c.cmd = CMD_DEVICE_INFO;
|
||||
SendCommand_(&c);
|
||||
|
||||
HidCommand resp;
|
||||
// SendCommand_(&c);
|
||||
SendCommand(&c);
|
||||
UsbCommand resp;
|
||||
ReceiveCommand(&resp);
|
||||
|
||||
// Three outcomes:
|
||||
|
@ -290,7 +296,7 @@ static int get_proxmark_state(uint32_t *state)
|
|||
*state = resp.arg[0];
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Error: Couldn't get proxmark state, bad response type: 0x%04x\n", resp.cmd);
|
||||
fprintf(stderr, "Error: Couldn't get proxmark state, bad response type: 0x%04llx\n", resp.cmd);
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
|
@ -313,7 +319,7 @@ static int enter_bootloader(void)
|
|||
|
||||
if (state & DEVICE_INFO_FLAG_CURRENT_MODE_OS) {
|
||||
fprintf(stderr,"Entering bootloader...\n");
|
||||
HidCommand c;
|
||||
UsbCommand c;
|
||||
memset(&c, 0, sizeof (c));
|
||||
|
||||
if ((state & DEVICE_INFO_FLAG_BOOTROM_PRESENT)
|
||||
|
@ -322,12 +328,12 @@ static int enter_bootloader(void)
|
|||
// New style handover: Send CMD_START_FLASH, which will reset the board
|
||||
// and enter the bootrom on the next boot.
|
||||
c.cmd = CMD_START_FLASH;
|
||||
SendCommand_(&c);
|
||||
SendCommand(&c);
|
||||
fprintf(stderr,"(Press and release the button only to abort)\n");
|
||||
} else {
|
||||
// Old style handover: Ask the user to press the button, then reset the board
|
||||
c.cmd = CMD_HARDWARE_RESET;
|
||||
SendCommand_(&c);
|
||||
SendCommand(&c);
|
||||
fprintf(stderr,"Press and hold down button NOW if your bootloader requires it.\n");
|
||||
}
|
||||
fprintf(stderr,"Waiting for Proxmark to reappear on USB...");
|
||||
|
@ -349,10 +355,10 @@ static int enter_bootloader(void)
|
|||
|
||||
static int wait_for_ack(void)
|
||||
{
|
||||
HidCommand ack;
|
||||
UsbCommand ack;
|
||||
ReceiveCommand(&ack);
|
||||
if (ack.cmd != CMD_ACK) {
|
||||
printf("Error: Unexpected reply 0x%04x (expected ACK)\n", ack.cmd);
|
||||
printf("Error: Unexpected reply 0x%04llx (expected ACK)\n", ack.cmd);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -372,7 +378,7 @@ int flash_start_flashing(int enable_bl_writes)
|
|||
if (state & DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH) {
|
||||
// This command is stupid. Why the heck does it care which area we're
|
||||
// flashing, as long as it's not the bootloader area? The mind boggles.
|
||||
HidCommand c = {CMD_START_FLASH};
|
||||
UsbCommand c = {CMD_START_FLASH};
|
||||
|
||||
if (enable_bl_writes) {
|
||||
c.arg[0] = FLASH_START;
|
||||
|
@ -383,7 +389,8 @@ int flash_start_flashing(int enable_bl_writes)
|
|||
c.arg[1] = FLASH_END;
|
||||
c.arg[2] = 0;
|
||||
}
|
||||
SendCommand_(&c);
|
||||
SendCommand(&c);
|
||||
// SendCommand_(&c);
|
||||
return wait_for_ack();
|
||||
} else {
|
||||
fprintf(stderr, "Note: Your bootloader does not understand the new START_FLASH command\n");
|
||||
|
@ -399,21 +406,26 @@ static int write_block(uint32_t address, uint8_t *data, uint32_t length)
|
|||
|
||||
memset(block_buf, 0xFF, BLOCK_SIZE);
|
||||
memcpy(block_buf, data, length);
|
||||
|
||||
HidCommand c = {CMD_SETUP_WRITE};
|
||||
UsbCommand c;
|
||||
/*
|
||||
c.cmd = {CMD_SETUP_WRITE};
|
||||
for (int i = 0; i < 240; i += 48) {
|
||||
memcpy(c.d.asBytes, block_buf + i, 48);
|
||||
c.arg[0] = i / 4;
|
||||
SendCommand_(&c);
|
||||
if (wait_for_ack() < 0)
|
||||
SendCommand(&c);
|
||||
// SendCommand_(&c);
|
||||
if (wait_for_ack() < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
c.cmd = CMD_FINISH_WRITE;
|
||||
c.arg[0] = address;
|
||||
memcpy(c.d.asBytes, block_buf+240, 16);
|
||||
SendCommand_(&c);
|
||||
return wait_for_ack();
|
||||
// memcpy(c.d.asBytes, block_buf+240, 16);
|
||||
// SendCommand_(&c);
|
||||
memcpy(c.d.asBytes, block_buf, length);
|
||||
SendCommand(&c);
|
||||
return wait_for_ack();
|
||||
}
|
||||
|
||||
// Write a file's segments to Flash
|
||||
|
@ -472,7 +484,8 @@ void flash_free(flash_file_t *ctx)
|
|||
|
||||
// just reset the unit
|
||||
int flash_stop_flashing(void) {
|
||||
HidCommand c = {CMD_HARDWARE_RESET};
|
||||
SendCommand_(&c);
|
||||
return 0;
|
||||
UsbCommand c = {CMD_HARDWARE_RESET};
|
||||
// SendCommand_(&c);
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -10,12 +10,71 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "sleep.h"
|
||||
#include "proxusb.h"
|
||||
//#include "proxusb.h"
|
||||
#include "flash.h"
|
||||
#include "uart.h"
|
||||
#include "usb_cmd.h"
|
||||
|
||||
static serial_port sp;
|
||||
static char* serial_port_name;
|
||||
|
||||
void cmd_debug(UsbCommand* UC) {
|
||||
// Debug
|
||||
printf("UsbCommand length[len=%zd]\n",sizeof(UsbCommand));
|
||||
printf(" cmd[len=%zd]: %016llx\n",sizeof(UC->cmd),UC->cmd);
|
||||
printf(" arg0[len=%zd]: %016llx\n",sizeof(UC->arg[0]),UC->arg[0]);
|
||||
printf(" arg1[len=%zd]: %016llx\n",sizeof(UC->arg[1]),UC->arg[1]);
|
||||
printf(" arg2[len=%zd]: %016llx\n",sizeof(UC->arg[2]),UC->arg[2]);
|
||||
printf(" data[len=%zd]: ",sizeof(UC->d.asBytes));
|
||||
for (size_t i=0; i<16; i++) {
|
||||
printf("%02x",UC->d.asBytes[i]);
|
||||
}
|
||||
printf("...\n");
|
||||
}
|
||||
|
||||
void SendCommand(UsbCommand* txcmd) {
|
||||
// printf("send: ");
|
||||
// cmd_debug(txcmd);
|
||||
if (!uart_send(sp,(byte_t*)txcmd,sizeof(UsbCommand))) {
|
||||
printf("Sending bytes to proxmark failed\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void ReceiveCommand(UsbCommand* rxcmd) {
|
||||
byte_t* prxcmd = (byte_t*)rxcmd;
|
||||
byte_t* prx = prxcmd;
|
||||
size_t rxlen;
|
||||
while (true) {
|
||||
rxlen = sizeof(UsbCommand) - (prx-prxcmd);
|
||||
if (uart_receive(sp,prx,&rxlen)) {
|
||||
// printf("received [%zd] bytes\n",rxlen);
|
||||
prx += rxlen;
|
||||
if ((prx-prxcmd) >= sizeof(UsbCommand)) {
|
||||
// printf("received: ");
|
||||
// cmd_debug(rxcmd);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CloseProxmark() {
|
||||
// Clean up the port
|
||||
uart_close(sp);
|
||||
}
|
||||
|
||||
int OpenProxmark(size_t i) {
|
||||
sp = uart_open(serial_port_name);
|
||||
if (sp == INVALID_SERIAL_PORT) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void usage(char *argv0)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [-b] image.elf [image.elf...]\n\n", argv0);
|
||||
fprintf(stderr, "Usage: %s <port> [-b] image.elf [image.elf...]\n\n", argv0);
|
||||
fprintf(stderr, "\t-b\tEnable flashing of bootloader area (DANGEROUS)\n\n");
|
||||
fprintf(stderr, "Example: %s path/to/osimage.elf path/to/fpgaimage.elf\n", argv0);
|
||||
}
|
||||
|
@ -31,12 +90,12 @@ int main(int argc, char **argv)
|
|||
|
||||
memset(files, 0, sizeof(files));
|
||||
|
||||
if (argc < 2) {
|
||||
if (argc < 3) {
|
||||
usage(argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
for (int i = 2; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
if (!strcmp(argv[i], "-b")) {
|
||||
can_write_bl = 1;
|
||||
|
@ -55,11 +114,9 @@ int main(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
usb_init();
|
||||
|
||||
serial_port_name = argv[1];
|
||||
fprintf(stderr, "Waiting for Proxmark to appear on USB...");
|
||||
while (!OpenProxmark(0)) {
|
||||
sleep(1);
|
||||
fprintf(stderr, ".");
|
||||
}
|
||||
fprintf(stderr, " Found.\n");
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include "proxmark3.h"
|
||||
|
||||
// MIFARE
|
||||
|
||||
int compar_int(const void * a, const void * b) {
|
||||
return (*(uint64_t*)b - *(uint64_t*)a);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include "cmdmain.h"
|
||||
#include "ui.h"
|
||||
#include "data.h"
|
||||
#include "proxusb.h"
|
||||
//#include "proxusb.h"
|
||||
#include "util.h"
|
||||
#include "nonce2key/nonce2key.h"
|
||||
#include "nonce2key/crapto1.h"
|
||||
|
|
222
client/proxusb.c
222
client/proxusb.c
|
@ -1,222 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
// USB utilities
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <usb.h>
|
||||
#include <strings.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "sleep.h"
|
||||
#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "usb_cmd.h"
|
||||
|
||||
// It seems to be missing for mingw
|
||||
#ifndef ETIMEDOUT
|
||||
#define ETIMEDOUT 116
|
||||
#endif
|
||||
|
||||
usb_dev_handle *devh = NULL;
|
||||
static unsigned int claimed_iface = 0;
|
||||
unsigned char return_on_error = 0;
|
||||
unsigned char error_occured = 0;
|
||||
extern unsigned int current_command;
|
||||
|
||||
void SendCommand_(HidCommand *c)
|
||||
{
|
||||
int ret;
|
||||
|
||||
#if 0
|
||||
printf("Sending %d bytes\n", sizeof(HidCommand));
|
||||
#endif
|
||||
current_command = c->cmd;
|
||||
ret = usb_bulk_write(devh, 0x01, (char*)c, sizeof(HidCommand), 1000);
|
||||
if (ret<0) {
|
||||
error_occured = 1;
|
||||
if (return_on_error)
|
||||
return;
|
||||
|
||||
fprintf(stderr, "write failed: %s!\nTrying to reopen device...\n",
|
||||
usb_strerror());
|
||||
|
||||
if (devh) {
|
||||
usb_close(devh);
|
||||
devh = NULL;
|
||||
}
|
||||
while(!OpenProxmark(0)) { sleep(1); }
|
||||
printf(PROXPROMPT);
|
||||
fflush(NULL);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool ReceiveCommandPoll(HidCommand *c)
|
||||
{
|
||||
int ret;
|
||||
|
||||
memset(c, 0, sizeof (HidCommand));
|
||||
ret = usb_bulk_read(devh, 0x82, (char*)c, sizeof(HidCommand), 500);
|
||||
if (ret<0) {
|
||||
if (ret != -ETIMEDOUT) {
|
||||
error_occured = 1;
|
||||
if (return_on_error)
|
||||
return false;
|
||||
|
||||
fprintf(stderr, "read failed: %s(%d)!\nTrying to reopen device...\n",
|
||||
usb_strerror(), ret);
|
||||
|
||||
if (devh) {
|
||||
usb_close(devh);
|
||||
devh = NULL;
|
||||
}
|
||||
while(!OpenProxmark(0)) { sleep(1); }
|
||||
printf(PROXPROMPT);
|
||||
fflush(NULL);
|
||||
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (ret && (ret < sizeof(HidCommand))) {
|
||||
fprintf(stderr, "Read only %d instead of requested %d bytes!\n",
|
||||
ret, (int)sizeof(HidCommand));
|
||||
}
|
||||
}
|
||||
|
||||
return ret > 0;
|
||||
}
|
||||
|
||||
void ReceiveCommand(HidCommand *c)
|
||||
{
|
||||
// printf("%s()\n", __FUNCTION__);
|
||||
int retval = 0;
|
||||
do {
|
||||
retval = ReceiveCommandPoll(c);
|
||||
if (retval != 1) printf("ReceiveCommandPoll returned %d\n", retval);
|
||||
} while(retval<0);
|
||||
// printf("recv %x\n", c->cmd);
|
||||
}
|
||||
|
||||
usb_dev_handle* findProxmark(int verbose, unsigned int *iface)
|
||||
{
|
||||
struct usb_bus *busses, *bus;
|
||||
usb_dev_handle *handle = NULL;
|
||||
struct prox_unit units[50];
|
||||
int iUnit = 0;
|
||||
|
||||
usb_find_busses();
|
||||
usb_find_devices();
|
||||
|
||||
busses = usb_get_busses();
|
||||
|
||||
for (bus = busses; bus; bus = bus->next) {
|
||||
struct usb_device *dev;
|
||||
|
||||
for (dev = bus->devices; dev; dev = dev->next) {
|
||||
struct usb_device_descriptor *desc = &(dev->descriptor);
|
||||
|
||||
if ((desc->idProduct == 0x4b8f) && (desc->idVendor == 0x9ac4)) {
|
||||
handle = usb_open(dev);
|
||||
if (!handle) {
|
||||
if (verbose)
|
||||
fprintf(stderr, "open fabiled: %s!\n", usb_strerror());
|
||||
//return NULL;
|
||||
continue;
|
||||
}
|
||||
*iface = dev->config[0].interface[0].altsetting[0].bInterfaceNumber;
|
||||
|
||||
struct prox_unit unit = {handle, {0}};
|
||||
usb_get_string_simple(handle, desc->iSerialNumber, unit.serial_number, sizeof(unit.serial_number));
|
||||
units[iUnit++] = unit;
|
||||
|
||||
//return handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (iUnit > 0) {
|
||||
int iSelection = 0;
|
||||
|
||||
fprintf(stdout, "\nConnected units:\n");
|
||||
|
||||
for (int i = 0; i < iUnit; i++) {
|
||||
struct usb_device * dev = usb_device(units[i].handle);
|
||||
fprintf(stdout, "\t%d. SN: %s [%s/%s]\n", i+1, units[i].serial_number, dev->bus->dirname, dev->filename);
|
||||
}
|
||||
if (iUnit > 1) {
|
||||
while (iSelection < 1 || iSelection > iUnit) {
|
||||
fprintf(stdout, "Which unit do you want to connect to? ");
|
||||
fscanf(stdin, "%d", &iSelection);
|
||||
}
|
||||
}
|
||||
else
|
||||
iSelection = 1;
|
||||
iSelection --;
|
||||
|
||||
for (int i = 0; i < iUnit; i++) {
|
||||
if (iSelection == i) continue;
|
||||
usb_close(units[i].handle);
|
||||
units[i].handle = NULL;
|
||||
}
|
||||
|
||||
return units[iSelection].handle;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
usb_dev_handle* OpenProxmark(int verbose)
|
||||
{
|
||||
int ret;
|
||||
usb_dev_handle *handle = NULL;
|
||||
unsigned int iface;
|
||||
|
||||
handle = findProxmark(verbose, &iface);
|
||||
if (!handle)
|
||||
return NULL;
|
||||
|
||||
#ifdef __linux__
|
||||
/* detach kernel driver first */
|
||||
ret = usb_detach_kernel_driver_np(handle, iface);
|
||||
/* don't complain if no driver attached */
|
||||
if (ret<0 && ret != -61 && verbose)
|
||||
fprintf(stderr, "detach kernel driver failed: (%d) %s!\n", ret, usb_strerror());
|
||||
#endif
|
||||
|
||||
// Needed for Windows. Optional for Mac OS and Linux
|
||||
ret = usb_set_configuration(handle, 1);
|
||||
if (ret < 0) {
|
||||
if (verbose)
|
||||
fprintf(stderr, "configuration set failed: %s!\n", usb_strerror());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = usb_claim_interface(handle, iface);
|
||||
if (ret < 0) {
|
||||
if (verbose)
|
||||
fprintf(stderr, "claim failed: %s!\n", usb_strerror());
|
||||
return NULL;
|
||||
}
|
||||
claimed_iface = iface;
|
||||
devh = handle;
|
||||
return handle;
|
||||
}
|
||||
|
||||
void CloseProxmark(void)
|
||||
{
|
||||
usb_release_interface(devh, claimed_iface);
|
||||
usb_close(devh);
|
||||
devh = NULL;
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
// USB utilities
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef PROXUSB_H__
|
||||
#define PROXUSB_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <usb.h>
|
||||
#include "usb_cmd.h"
|
||||
|
||||
extern unsigned char return_on_error;
|
||||
extern unsigned char error_occured;
|
||||
|
||||
void SendCommand_(HidCommand *c);
|
||||
bool ReceiveCommandPoll(HidCommand *c);
|
||||
void ReceiveCommand(HidCommand *c);
|
||||
struct usb_dev_handle* FindProxmark(int verbose, unsigned int *iface);
|
||||
struct usb_dev_handle* OpenProxmark(int verbose);
|
||||
void CloseProxmark(void);
|
||||
|
||||
struct prox_unit {
|
||||
usb_dev_handle *handle;
|
||||
char serial_number[256];
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue