mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-01-24 00:50:27 +08:00
add: potential fix for OSX uses, by @piwi
chg: adapting fix to support iceman forks extended commands.
This commit is contained in:
parent
886f7fbdad
commit
207fa2b574
39 changed files with 160 additions and 129 deletions
|
@ -350,7 +350,7 @@ void printUSBSpeed(void) {
|
|||
uint32_t bytes_transferred = 0;
|
||||
|
||||
LED_B_ON();
|
||||
while(end_time < start_time + USB_SPEED_TEST_MIN_TIME) {
|
||||
while (end_time < start_time + USB_SPEED_TEST_MIN_TIME) {
|
||||
cmd_send(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K, 0, USB_CMD_DATA_SIZE, 0, test_data, USB_CMD_DATA_SIZE);
|
||||
end_time = GetTickCount();
|
||||
bytes_transferred += USB_CMD_DATA_SIZE;
|
||||
|
|
|
@ -534,8 +534,7 @@ int CmdAnalyseA(const char *Cmd){
|
|||
uint8_t got[0x3FFFF];
|
||||
memset(got, 0, sizeof(got));
|
||||
PrintAndLogEx(NORMAL, "downloading %u bytes from flashmem", sizeof(got));
|
||||
GetFromFlashMen(got, sizeof(got), 0);
|
||||
WaitForResponse(CMD_ACK, NULL);
|
||||
GetFromFlashMen(got, sizeof(got), 0, NULL, -1, true);
|
||||
|
||||
print_hex(got, 8);
|
||||
|
||||
|
|
|
@ -805,8 +805,7 @@ int CmdBitsamples(const char *Cmd)
|
|||
int cnt = 0;
|
||||
uint8_t got[12288];
|
||||
|
||||
GetFromBigBuf(got, sizeof(got), 0);
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, NULL, 2500) ) {
|
||||
if (!GetFromBigBuf(got, sizeof(got), 0, NULL, 2500 , false)) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
return false;
|
||||
}
|
||||
|
@ -1338,8 +1337,7 @@ int CmdHexsamples(const char *Cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
GetFromBigBuf(got, requested, offset);
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, NULL, 2500) ) {
|
||||
if ( !GetFromBigBuf(got, requested, offset, NULL, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
return false;
|
||||
}
|
||||
|
@ -1416,10 +1414,9 @@ int getSamples(int n, bool silent) {
|
|||
n = sizeof(got);
|
||||
|
||||
if (!silent) PrintAndLogEx(NORMAL, "Reading %d bytes from device memory\n", n);
|
||||
GetFromBigBuf(got, n, 0);
|
||||
|
||||
UsbCommand response;
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, &response, 10000) ) {
|
||||
if ( !GetFromBigBuf(got, n, 0, &response, 10000, true) ) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include <string.h> // also included in util.h
|
||||
#include <inttypes.h>
|
||||
#include <limits.h> // for CmdNorm INT_MIN && INT_MAX
|
||||
#include "data.h" // also included in util.h
|
||||
#include "util.h"
|
||||
#include "cmdmain.h"
|
||||
#include "proxmark3.h" // sendcommand
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include "cmdparser.h"
|
||||
#include "cmdmain.h"
|
||||
#include "iso14443crc.h"
|
||||
#include "data.h"
|
||||
#include "mifare.h"
|
||||
#include "cmdhfmf.h"
|
||||
#include "cmdhfmfu.h"
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include <stdint.h>
|
||||
#include "crc16.h"
|
||||
#include "proxmark3.h"
|
||||
#include "data.h"
|
||||
#include "graph.h"
|
||||
#include "util.h"
|
||||
#include "ui.h"
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#include "proxmark3.h"
|
||||
#include "data.h"
|
||||
#include "graph.h"
|
||||
#include "ui.h"
|
||||
#include "util.h"
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "proxmark3.h"
|
||||
#include "data.h"
|
||||
#include "ui.h"
|
||||
#include "cmdparser.h"
|
||||
#include "cmdmain.h"
|
||||
|
|
|
@ -390,9 +390,8 @@ int CmdHFFelicaDumpLite(const char *Cmd) {
|
|||
|
||||
// only download data if there is any.
|
||||
if ( tracelen > 0 ) {
|
||||
GetFromBigBuf(trace, tracelen, 0);
|
||||
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, NULL, 2500) ) {
|
||||
|
||||
if ( !GetFromBigBuf(trace, tracelen, 0, NULL, 2500, false) ){
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
free(trace);
|
||||
return 0;
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "cmdparser.h"
|
||||
#include "cmdmain.h"
|
||||
#include "iso14443crc.h"
|
||||
#include "data.h"
|
||||
#include "cmdhf.h" // list cmd
|
||||
#include "mifare.h" // felica_card_select_t struct
|
||||
|
||||
|
|
|
@ -1066,8 +1066,7 @@ int CmdHFiClassReader_Dump(const char *Cmd) {
|
|||
}
|
||||
|
||||
// response ok - now get bigbuf content of the dump
|
||||
GetFromBigBuf(tag_data+(blockno*8), blocksRead*8, startindex);
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, NULL, 2500) ) {
|
||||
if ( !GetFromBigBuf(tag_data+(blockno*8), blocksRead*8, startindex, NULL, 2500, false) ) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
return 0;
|
||||
}
|
||||
|
@ -1112,8 +1111,7 @@ int CmdHFiClassReader_Dump(const char *Cmd) {
|
|||
blocksRead = (sizeof(tag_data) - gotBytes)/8;
|
||||
}
|
||||
// get dumped data from bigbuf
|
||||
GetFromBigBuf(tag_data + gotBytes, blocksRead * 8, startindex);
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, NULL, 2500) ) {
|
||||
if ( !GetFromBigBuf(tag_data + gotBytes, blocksRead * 8, startindex, NULL, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include "iso14443crc.h" // Can also be used for iClass, using 0xE012 as CRC-type
|
||||
#include "data.h"
|
||||
#include "proxmark3.h"
|
||||
#include "ui.h"
|
||||
#include "cmdparser.h"
|
||||
|
|
|
@ -759,7 +759,7 @@ int legic_read_mem(uint32_t offset, uint32_t len, uint32_t iv, uint8_t *out, uin
|
|||
PrintAndLogEx(WARNING, "Fail, only managed to read %u bytes", *outlen);
|
||||
|
||||
// copy data from device
|
||||
if ( !GetEMLFromBigBuf(out, *outlen, 0) ) {
|
||||
if ( !GetEMLFromBigBuf(out, *outlen, 0, NULL, 2500, false) ) {
|
||||
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
||||
return 4;
|
||||
}
|
||||
|
@ -924,7 +924,7 @@ int CmdLegicDump(const char *Cmd){
|
|||
PrintAndLogEx(WARNING, "Fail, only managed to read 0x%02X bytes of 0x%02X", readlen, dumplen);
|
||||
|
||||
// copy data from device
|
||||
if (!GetEMLFromBigBuf(data, readlen, 0) ) {
|
||||
if (!GetEMLFromBigBuf(data, readlen, 0, NULL, 2500, false) ) {
|
||||
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
||||
free(data);
|
||||
return 4;
|
||||
|
@ -1170,7 +1170,7 @@ int CmdLegicESave(const char *Cmd) {
|
|||
|
||||
// download emulator memory
|
||||
PrintAndLogEx(NORMAL, "Reading emulator memory...");
|
||||
if (!GetEMLFromBigBuf(data, numofbytes, 0)) {
|
||||
if (!GetEMLFromBigBuf(data, numofbytes, 0, NULL, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
||||
free(data);
|
||||
return 4;
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "proxmark3.h"
|
||||
#include "data.h"
|
||||
#include "ui.h"
|
||||
#include "cmdparser.h"
|
||||
#include "cmdmain.h"
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "util.h"
|
||||
#include "data.h"
|
||||
#include "ui.h"
|
||||
#include "cmdhf14a.h" // ISO14443-A
|
||||
#include "cmdhf14b.h" // ISO14443-B
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include <time.h>
|
||||
#include "proxmark3.h"
|
||||
#include "iso14443crc.h"
|
||||
#include "data.h"
|
||||
#include "ui.h"
|
||||
#include "cmdparser.h"
|
||||
#include "common.h"
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "../include/common.h"
|
||||
#include "../include/mifare.h"
|
||||
#include "iso14443crc.h"
|
||||
#include "data.h"
|
||||
#include "ui.h"
|
||||
#include "cmdparser.h"
|
||||
#include "util.h"
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include "mifare.h"
|
||||
#include "util.h"
|
||||
#include "protocols.h"
|
||||
#include "data.h"
|
||||
|
||||
typedef struct {
|
||||
uint8_t version[8];
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "cmdhw.h"
|
||||
#include "cmdmain.h"
|
||||
#include "cmddata.h"
|
||||
#include "data.h"
|
||||
|
||||
/* low-level hardware control */
|
||||
|
||||
|
@ -274,9 +273,6 @@ int CmdVersion(const char *Cmd) {
|
|||
}
|
||||
|
||||
int CmdStatus(const char *Cmd) {
|
||||
uint8_t speed_test_buffer[USB_CMD_DATA_SIZE];
|
||||
sample_buf = speed_test_buffer;
|
||||
sample_buf_size = USB_CMD_DATA_SIZE;
|
||||
clearCommandBuffer();
|
||||
UsbCommand c = {CMD_STATUS};
|
||||
SendCommand(&c);
|
||||
|
|
|
@ -22,8 +22,7 @@
|
|||
#include "ui.h" // for show graph controls
|
||||
#include "graph.h" // for graph data
|
||||
#include "cmdparser.h" // for getting cli commands included in cmdmain.h
|
||||
#include "cmdmain.h" // for sending cmds to device
|
||||
#include "data.h" // for GetFromBigBuf
|
||||
#include "cmdmain.h" // for sending cmds to device. GetFromBigBuf
|
||||
#include "cmddata.h" // for `lf search`
|
||||
#include "cmdlfawid.h" // for awid menu
|
||||
#include "cmdlfem4x.h" // for em4x menu
|
||||
|
|
|
@ -90,12 +90,12 @@ int CmdCOTAGRead(const char *Cmd) {
|
|||
break;
|
||||
}
|
||||
case 1: {
|
||||
GetFromBigBuf(DemodBuffer, COTAG_BITS, 0);
|
||||
DemodBufferLen = COTAG_BITS;
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, NULL, 1000) ) {
|
||||
|
||||
if ( !GetFromBigBuf(DemodBuffer, COTAG_BITS, 0, NULL, 1000, false)) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||
return -1;
|
||||
}
|
||||
DemodBufferLen = COTAG_BITS;
|
||||
return CmdCOTAGDemod("");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -995,8 +995,7 @@ bool downloadSamplesEM(){
|
|||
|
||||
// 8 bit preamble + 32 bit word response (max clock (128) * 40bits = 5120 samples)
|
||||
uint8_t got[6000];
|
||||
GetFromBigBuf(got, sizeof(got), 0);
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, NULL, 2500) ) {
|
||||
if ( !GetFromBigBuf(got, sizeof(got), 0, NULL, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "data.h"
|
||||
#include "proxmark3.h"
|
||||
#include "ui.h"
|
||||
#include "cmdparser.h"
|
||||
|
@ -39,8 +38,7 @@ int CmdLFHitagList(const char *Cmd) {
|
|||
|
||||
// Query for the actual size of the trace
|
||||
UsbCommand response;
|
||||
GetFromBigBuf(got, USB_CMD_DATA_SIZE, 0);
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, &response, 2500) ) {
|
||||
if ( !GetFromBigBuf(got, USB_CMD_DATA_SIZE, 0, &response, 2500, false) ) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
free(got);
|
||||
return 2;
|
||||
|
@ -55,8 +53,7 @@ int CmdLFHitagList(const char *Cmd) {
|
|||
return 2;
|
||||
}
|
||||
got = p;
|
||||
GetFromBigBuf(got, traceLen, 0);
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, NULL, 2500) ) {
|
||||
if ( !GetFromBigBuf(got, traceLen, 0, NULL, 2500, false) ) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
free(got);
|
||||
return 2;
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "lfdemod.h" // parityTest, bitbytes_to_byte
|
||||
#include "util.h" // weigandparity
|
||||
#include "protocols.h" // for T55xx config register definitions
|
||||
#include "data.h"
|
||||
#include "cmdmain.h"
|
||||
#include "cmddata.h"
|
||||
#include "cmdlf.h" // lf_read
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include "lfdemod.h" // parityTest, bitbytes_to_byte
|
||||
#include "util.h" // weigandparity
|
||||
#include "protocols.h" // for T55xx config register definitions
|
||||
#include "data.h"
|
||||
#include "cmdmain.h"
|
||||
#include "cmddata.h"
|
||||
|
||||
|
|
|
@ -146,7 +146,6 @@ int CmdParadoxRead(const char *Cmd) {
|
|||
return CmdParadoxDemod(Cmd);
|
||||
}
|
||||
|
||||
|
||||
int CmdParadoxSim(const char *Cmd) {
|
||||
|
||||
char cmdp = param_getchar(Cmd, 0);
|
||||
|
|
|
@ -1309,8 +1309,7 @@ bool AquireData( uint8_t page, uint8_t block, bool pwdmode, uint32_t password ){
|
|||
|
||||
//uint8_t got[12288];
|
||||
uint8_t got[7679];
|
||||
GetFromBigBuf(got, sizeof(got), 0);
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, NULL, 6000) ) {
|
||||
if ( !GetFromBigBuf(got, sizeof(got), 0, NULL, 6000, true)) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
return false;
|
||||
}
|
||||
|
@ -1442,8 +1441,7 @@ int CmdResetRead(const char *Cmd) {
|
|||
}
|
||||
|
||||
uint8_t got[BIGBUF_SIZE-1];
|
||||
GetFromBigBuf(got, sizeof(got), 0);
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, NULL, 2500) ) {
|
||||
if ( !GetFromBigBuf(got, sizeof(got), 0, NULL, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "cmddata.h"
|
||||
#include "cmdlf.h"
|
||||
#include "util.h"
|
||||
#include "data.h"
|
||||
#include "lfdemod.h"
|
||||
#include "cmdhf14a.h" //for getTagInfo
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include <inttypes.h>
|
||||
#include "crc16.h"
|
||||
#include "proxmark3.h"
|
||||
#include "data.h"
|
||||
#include "ui.h"
|
||||
#include "graph.h"
|
||||
#include "cmdparser.h"
|
||||
|
|
160
client/cmdmain.c
160
client/cmdmain.c
|
@ -45,6 +45,15 @@ static int cmd_tail;//Starts as 0
|
|||
// to lock cmdBuffer operations from different threads
|
||||
static pthread_mutex_t cmdBufferMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
int CmdQuit(const char *Cmd) {
|
||||
return 99;
|
||||
}
|
||||
|
||||
int CmdRev(const char *Cmd) {
|
||||
CmdCrc(Cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static command_t CommandTable[] = {
|
||||
{"help", CmdHelp, 1, "This help. Use '<command> help' for details of a particular command."},
|
||||
{"analyse", CmdAnalyse, 1, "{ Analyse bytes... }"},
|
||||
|
@ -69,14 +78,7 @@ int CmdHelp(const char *Cmd) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int CmdQuit(const char *Cmd) {
|
||||
return 99;
|
||||
}
|
||||
|
||||
int CmdRev(const char *Cmd) {
|
||||
CmdCrc(Cmd);
|
||||
return 0;
|
||||
}
|
||||
bool dl_it(uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbCommand *response, size_t ms_timeout, bool show_warning, uint32_t rec_cmd);
|
||||
/**
|
||||
* @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.
|
||||
|
@ -140,7 +142,7 @@ int getCommand(UsbCommand* response) {
|
|||
*@brief WaitForResponseTimeout
|
||||
* @param cmd command to wait for, or CMD_UNKNOWN to take any command.
|
||||
* @param response struct to copy received command into.
|
||||
* @param ms_timeout
|
||||
* @param ms_timeout display message after 2 seconds
|
||||
* @return true if command was returned, otherwise false
|
||||
*/
|
||||
bool WaitForResponseTimeoutW(uint32_t cmd, UsbCommand* response, size_t ms_timeout, bool show_warning) {
|
||||
|
@ -224,32 +226,124 @@ void UsbCommandReceived(UsbCommand* _ch) {
|
|||
PrintAndLogEx(NORMAL, "#db# %08x, %08x, %08x", c->arg[0], c->arg[1], c->arg[2]);
|
||||
break;
|
||||
}
|
||||
case CMD_DOWNLOADED_FLASHMEM:
|
||||
case CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K:
|
||||
case CMD_DOWNLOADED_EML_BIGBUF: {
|
||||
|
||||
// sample_buf is a array pointer, located in data.c
|
||||
// arg0 = offset in transfer. Startindex of this chunk
|
||||
// arg1 = length bytes to transfer
|
||||
// arg2 = bigbuff tracelength (?)
|
||||
uint32_t offset = c->arg[0];
|
||||
uint32_t len = MIN(c->arg[1], sample_buf_size);
|
||||
//uint32_t tracelen = c->arg[2];
|
||||
|
||||
// extended bounds check.
|
||||
if ( offset + len > sample_buf_size ) {
|
||||
PrintAndLogEx(FAILED, "ERROR: Out of bounds when downloading from device, offset %u | len %u | total len %u > sample_buf_size %u", offset, len, offset+len, sample_buf_size);
|
||||
break;
|
||||
}
|
||||
//printf("SAMPLE_BUF_SIZE %u | adjusted len %u | offset %u\n", sample_buf_size, len, offset);
|
||||
|
||||
memcpy( sample_buf + offset, c->d.asBytes, len);
|
||||
//PrintAndLogEx(NORMAL, "ICE:: Download from device. chunk %" PRIu32 " | size %" PRIu32 " | tracelen:%" PRIu32 " \n", offset, len, c->arg[2]);
|
||||
break;
|
||||
}
|
||||
// iceman: hw status - down the path on device, runs printusbspeed which starts sending a lot of
|
||||
// CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K packages which is not dealt with. I wonder if simply ignoring them will
|
||||
// work. lets try it.
|
||||
default: {
|
||||
storeCommand(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data transfer from Proxmark to client. This method times out after
|
||||
* ms_timeout milliseconds.
|
||||
* @brief GetFromBigBuf
|
||||
* @param dest Destination address for transfer
|
||||
* @param bytes number of bytes to be transferred
|
||||
* @param start_index offset into Proxmark3 BigBuf[]
|
||||
* @param response struct to copy last command (CMD_ACK) into
|
||||
* @param ms_timeout timeout in milliseconds
|
||||
* @param show_warning display message after 2 seconds
|
||||
* @return true if command was returned, otherwise false
|
||||
*/
|
||||
bool GetFromBigBuf(uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbCommand *response, size_t ms_timeout, bool show_warning) {
|
||||
|
||||
if (dest == NULL) return false;
|
||||
if (bytes == 0) return true;
|
||||
|
||||
UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {start_index, bytes, 0}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
|
||||
UsbCommand resp;
|
||||
if (response == NULL)
|
||||
response = &resp;
|
||||
|
||||
return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);
|
||||
}
|
||||
|
||||
bool GetEMLFromBigBuf(uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbCommand *response, size_t ms_timeout, bool show_warning) {
|
||||
|
||||
if (dest == NULL) return false;
|
||||
if (bytes == 0) return true;
|
||||
|
||||
UsbCommand c = {CMD_DOWNLOAD_EML_BIGBUF, {start_index, bytes, 0}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
|
||||
UsbCommand resp;
|
||||
if (response == NULL)
|
||||
response = &resp;
|
||||
|
||||
return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_EML_BIGBUF);
|
||||
}
|
||||
|
||||
bool GetFromFlashMen(uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbCommand *response, size_t ms_timeout, bool show_warning) {
|
||||
|
||||
if (dest == NULL) return false;
|
||||
if (bytes == 0) return true;
|
||||
|
||||
UsbCommand c = {CMD_DOWNLOAND_FLASH_MEM, {start_index, bytes, 0}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
|
||||
UsbCommand resp;
|
||||
if (response == NULL)
|
||||
response = &resp;
|
||||
|
||||
return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_FLASHMEM);
|
||||
}
|
||||
|
||||
bool dl_it(uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbCommand *response, size_t ms_timeout, bool show_warning, uint32_t rec_cmd) {
|
||||
|
||||
uint32_t bytes_completed = 0;
|
||||
uint64_t start_time = msclock();
|
||||
|
||||
while (true) {
|
||||
|
||||
if (getCommand(response)) {
|
||||
|
||||
// sample_buf is a array pointer, located in data.c
|
||||
// arg0 = offset in transfer. Startindex of this chunk
|
||||
// arg1 = length bytes to transfer
|
||||
// arg2 = bigbuff tracelength (?)
|
||||
if (response->cmd == rec_cmd) {
|
||||
|
||||
uint32_t offset = response->arg[0];
|
||||
uint32_t copy_bytes = MIN(bytes - bytes_completed, response->arg[1]);
|
||||
//uint32_t tracelen = c->arg[2];
|
||||
|
||||
// extended bounds check1. upper limit is USB_CMD_DATA_SIZE
|
||||
// shouldn't happen
|
||||
copy_bytes = MIN(copy_bytes, USB_CMD_DATA_SIZE);
|
||||
|
||||
// extended bounds check2.
|
||||
if ( offset + copy_bytes > bytes ) {
|
||||
PrintAndLogEx(FAILED, "ERROR: Out of bounds when downloading from device, offset %u | len %u | total len %u > buf_size %u", offset, copy_bytes, offset+copy_bytes, bytes);
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy(dest + offset, response->d.asBytes, copy_bytes);
|
||||
bytes_completed += copy_bytes;
|
||||
} else if (response->cmd == CMD_ACK) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (msclock() - start_time > ms_timeout) {
|
||||
PrintAndLogEx(FAILED, "Timed out while trying to download data from device");
|
||||
break;
|
||||
}
|
||||
|
||||
if (msclock() - start_time > 3000 && show_warning) {
|
||||
// 3 seconds elapsed (but this doesn't mean the timeout was exceeded)
|
||||
PrintAndLogEx(NORMAL, "Waiting for a response from the proxmark...");
|
||||
PrintAndLogEx(NORMAL, "You can cancel this operation by pressing the pm3 button");
|
||||
show_warning = false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,9 @@ extern bool WaitForResponse(uint32_t cmd, UsbCommand* response);
|
|||
extern void clearCommandBuffer();
|
||||
extern command_t* getTopLevelCommandTable();
|
||||
|
||||
extern bool GetFromBigBuf(uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbCommand *response, size_t ms_timeout, bool show_warning);
|
||||
extern bool GetEMLFromBigBuf(uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbCommand *response, size_t ms_timeout, bool show_warning);
|
||||
extern bool GetFromFlashMen(uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbCommand *response, size_t ms_timeout, bool show_warning);
|
||||
//For storing command that are received from the device
|
||||
#define CMD_BUFFER_SIZE 50
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
#include "proxmark3.h"
|
||||
#include "scripting.h"
|
||||
#include "data.h"
|
||||
#include "ui.h"
|
||||
#include "graph.h"
|
||||
#include "cmdparser.h"
|
||||
|
|
|
@ -487,8 +487,7 @@ int CmdTraceList(const char *Cmd) {
|
|||
if ( isOnline ) {
|
||||
// Query for the size of the trace, downloading USB_CMD_DATA_SIZE
|
||||
UsbCommand response;
|
||||
GetFromBigBuf(trace, USB_CMD_DATA_SIZE, 0);
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, &response, 4000) ) {
|
||||
if ( !GetFromBigBuf(trace, USB_CMD_DATA_SIZE, 0, &response, 4000, true)) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||
return 1;
|
||||
}
|
||||
|
@ -502,8 +501,7 @@ int CmdTraceList(const char *Cmd) {
|
|||
return 2;
|
||||
}
|
||||
trace = p;
|
||||
GetFromBigBuf(trace, traceLen, 0);
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, NULL, 2500) ) {
|
||||
if ( !GetFromBigBuf(trace, traceLen, 0, NULL, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
free(trace);
|
||||
return 3;
|
||||
|
|
|
@ -24,8 +24,7 @@
|
|||
#include "util.h" // for parsing cli command utils
|
||||
#include "ui.h" // for show graph controls
|
||||
#include "cmdparser.h" // for getting cli commands included in cmdmain.h
|
||||
#include "cmdmain.h" // for sending cmds to device
|
||||
#include "data.h" // for GetFromBigBuf
|
||||
#include "cmdmain.h" // for sending cmds to device. GetFromBigBuf
|
||||
#include "loclass/fileutils.h" // for saveFile
|
||||
|
||||
extern int CmdTrace(const char *Cmd);
|
||||
|
|
|
@ -15,41 +15,16 @@
|
|||
#include "proxmark3.h"
|
||||
#include "cmdmain.h"
|
||||
|
||||
uint32_t sample_buf_size;
|
||||
uint8_t* sample_buf;
|
||||
|
||||
// this triggers a download sequence from device, its received inside cmdmain.c UsbCommandReceived()
|
||||
void GetFromBigBuf(uint8_t *dest, uint32_t len, uint32_t start_index) {
|
||||
// global
|
||||
sample_buf = dest;
|
||||
sample_buf_size = len;
|
||||
UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {start_index, len, 0}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
}
|
||||
|
||||
|
||||
// this will download the EMULATOR memory part from device,
|
||||
// inside the BigBuf EML zon.
|
||||
bool GetEMLFromBigBuf(uint8_t *dest, uint32_t len, uint32_t start_index) {
|
||||
sample_buf = dest;
|
||||
sample_buf_size = len;
|
||||
UsbCommand c = {CMD_DOWNLOAD_EML_BIGBUF, {start_index, len, 0}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
|
||||
// the download will be done inside cmdmain.c function UsbCommandReceived(UsbCommand *UC)
|
||||
|
||||
// we are waiting for the ACK
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, NULL, 2500))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Download data from flashmem, rdv40
|
||||
void GetFromFlashMen(uint8_t *dest, uint32_t len, uint32_t start_index) {
|
||||
sample_buf = dest;
|
||||
sample_buf_size = len;
|
||||
UsbCommand c = {CMD_DOWNLOAND_FLASH_MEM, {start_index, len, 0}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
}
|
||||
|
|
|
@ -14,11 +14,13 @@
|
|||
#include <stdbool.h>
|
||||
#include "util.h"
|
||||
|
||||
#define FILE_PATH_SIZE 1000
|
||||
//#define FILE_PATH_SIZE 1000
|
||||
|
||||
/*
|
||||
extern uint32_t sample_buf_size;
|
||||
extern uint8_t* sample_buf;
|
||||
extern void GetFromBigBuf(uint8_t *dest, uint32_t len, uint32_t start_index);
|
||||
extern bool GetEMLFromBigBuf(uint8_t *dest, uint32_t len, uint32_t start_index);
|
||||
extern void GetFromFlashMen(uint8_t *dest, uint32_t len, uint32_t start_index);
|
||||
*/
|
||||
#endif
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include "common.h"
|
||||
#include "cmdmain.h"
|
||||
#include "ui.h"
|
||||
#include "data.h"
|
||||
#include "util.h"
|
||||
#include "crapto1/crapto1.h"
|
||||
#include "crc16.h"
|
||||
|
|
|
@ -79,9 +79,7 @@ static int l_GetFromBigBuf(lua_State *L){
|
|||
return 2; // two return values
|
||||
}
|
||||
|
||||
GetFromBigBuf(data, len, startindex);
|
||||
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, NULL, 2500) ) {
|
||||
if ( !GetFromBigBuf(data, len, startindex, NULL, 2500, false)) {
|
||||
free(data);
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L,"command execution time out");
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "data.h"
|
||||
#include "ui.h" // PrintAndLog
|
||||
|
||||
#ifdef ANDROID
|
||||
|
|
Loading…
Reference in a new issue