mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
chg: unifying some different download functions from device.
This commit is contained in:
parent
b279d04c85
commit
295054c190
4 changed files with 81 additions and 65 deletions
|
@ -534,7 +534,7 @@ int CmdAnalyseA(const char *Cmd){
|
||||||
uint8_t got[0x3FFFF];
|
uint8_t got[0x3FFFF];
|
||||||
memset(got, 0, sizeof(got));
|
memset(got, 0, sizeof(got));
|
||||||
PrintAndLogEx(NORMAL, "downloading %u bytes from flashmem", sizeof(got));
|
PrintAndLogEx(NORMAL, "downloading %u bytes from flashmem", sizeof(got));
|
||||||
GetFromFlashMen(got, sizeof(got), 0, NULL, -1, true);
|
GetFromDevice(FLASH_MEM, got, sizeof(got), 0, NULL, -1, true);
|
||||||
|
|
||||||
print_hex(got, 8);
|
print_hex(got, 8);
|
||||||
|
|
||||||
|
@ -543,6 +543,12 @@ int CmdAnalyseA(const char *Cmd){
|
||||||
printf("I %u (0x%x) | %x \n", i, i, got[i] );
|
printf("I %u (0x%x) | %x \n", i, i, got[i] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// binary
|
||||||
|
saveFile("flash_mem", "bin", got, sizeof(got));
|
||||||
|
|
||||||
|
// eml
|
||||||
|
saveFileEML("flash_mem", "eml", got, sizeof(got), 16);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// wipe
|
// wipe
|
||||||
|
|
|
@ -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);
|
PrintAndLogEx(WARNING, "Fail, only managed to read %u bytes", *outlen);
|
||||||
|
|
||||||
// copy data from device
|
// copy data from device
|
||||||
if ( !GetEMLFromBigBuf(out, *outlen, 0, NULL, 2500, false) ) {
|
if ( !GetFromDevice( BIG_BUF_EML, out, *outlen, 0, NULL, 2500, false) ) {
|
||||||
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
||||||
return 4;
|
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);
|
PrintAndLogEx(WARNING, "Fail, only managed to read 0x%02X bytes of 0x%02X", readlen, dumplen);
|
||||||
|
|
||||||
// copy data from device
|
// copy data from device
|
||||||
if (!GetEMLFromBigBuf(data, readlen, 0, NULL, 2500, false) ) {
|
if (!GetFromDevice( BIG_BUF_EML, data, readlen, 0, NULL, 2500, false) ) {
|
||||||
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
||||||
free(data);
|
free(data);
|
||||||
return 4;
|
return 4;
|
||||||
|
@ -1170,7 +1170,7 @@ int CmdLegicESave(const char *Cmd) {
|
||||||
|
|
||||||
// download emulator memory
|
// download emulator memory
|
||||||
PrintAndLogEx(NORMAL, "Reading emulator memory...");
|
PrintAndLogEx(NORMAL, "Reading emulator memory...");
|
||||||
if (!GetEMLFromBigBuf(data, numofbytes, 0, NULL, 2500, false)) {
|
if (!GetFromDevice( BIG_BUF_EML, data, numofbytes, 0, NULL, 2500, false)) {
|
||||||
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
||||||
free(data);
|
free(data);
|
||||||
return 4;
|
return 4;
|
||||||
|
|
|
@ -7,28 +7,7 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Main command parser entry point
|
// Main command parser entry point
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "cmdmain.h"
|
#include "cmdmain.h"
|
||||||
#include "util_posix.h"
|
|
||||||
#include "cmdparser.h"
|
|
||||||
#include "proxmark3.h"
|
|
||||||
#include "data.h"
|
|
||||||
#include "usb_cmd.h"
|
|
||||||
#include "ui.h"
|
|
||||||
#include "cmdhf.h"
|
|
||||||
#include "cmddata.h"
|
|
||||||
#include "cmdhw.h"
|
|
||||||
#include "cmdlf.h"
|
|
||||||
#include "cmdtrace.h"
|
|
||||||
#include "util.h"
|
|
||||||
#include "cmdscript.h"
|
|
||||||
#include "cmdcrc.h"
|
|
||||||
#include "cmdanalyse.h"
|
|
||||||
|
|
||||||
static int CmdHelp(const char *Cmd);
|
static int CmdHelp(const char *Cmd);
|
||||||
static int CmdQuit(const char *Cmd);
|
static int CmdQuit(const char *Cmd);
|
||||||
|
@ -236,6 +215,44 @@ void UsbCommandReceived(UsbCommand* _ch) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GetFromDevice(DeviceMemType_t memtype, 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 resp;
|
||||||
|
if (response == NULL)
|
||||||
|
response = &resp;
|
||||||
|
|
||||||
|
// clear
|
||||||
|
clearCommandBuffer();
|
||||||
|
|
||||||
|
switch (memtype) {
|
||||||
|
case BIG_BUF: {
|
||||||
|
UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {start_index, bytes, 0}};
|
||||||
|
SendCommand(&c);
|
||||||
|
return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);
|
||||||
|
}
|
||||||
|
case BIG_BUF_EML: {
|
||||||
|
UsbCommand c = {CMD_DOWNLOAD_EML_BIGBUF, {start_index, bytes, 0}};
|
||||||
|
SendCommand(&c);
|
||||||
|
return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);
|
||||||
|
}
|
||||||
|
case FLASH_MEM: {
|
||||||
|
UsbCommand c = {CMD_DOWNLOAND_FLASH_MEM, {start_index, bytes, 0}};
|
||||||
|
SendCommand(&c);
|
||||||
|
return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_FLASHMEM);
|
||||||
|
}
|
||||||
|
case SIM_MEM: {
|
||||||
|
//UsbCommand c = {CMD_DOWNLOAND_SIM_MEM, {start_index, bytes, 0}};
|
||||||
|
//SendCommand(&c);
|
||||||
|
//return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_SIMMEM);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data transfer from Proxmark to client. This method times out after
|
* Data transfer from Proxmark to client. This method times out after
|
||||||
* ms_timeout milliseconds.
|
* ms_timeout milliseconds.
|
||||||
|
@ -256,45 +273,10 @@ bool GetFromBigBuf(uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbComma
|
||||||
UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {start_index, bytes, 0}};
|
UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {start_index, bytes, 0}};
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
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);
|
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) {
|
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) {
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,36 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "util_posix.h"
|
||||||
|
#include "proxmark3.h"
|
||||||
#include "usb_cmd.h"
|
#include "usb_cmd.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "ui.h"
|
||||||
#include "cmdparser.h"
|
#include "cmdparser.h"
|
||||||
|
#include "loclass/fileutils.h"
|
||||||
|
#include "cmdhf.h"
|
||||||
|
#include "cmddata.h"
|
||||||
|
#include "cmdhw.h"
|
||||||
|
#include "cmdlf.h"
|
||||||
|
#include "cmdtrace.h"
|
||||||
|
#include "cmdscript.h"
|
||||||
|
#include "cmdcrc.h"
|
||||||
|
#include "cmdanalyse.h"
|
||||||
|
|
||||||
|
//For storing command that are received from the device
|
||||||
|
#define CMD_BUFFER_SIZE 50
|
||||||
|
typedef enum {
|
||||||
|
BIG_BUF,
|
||||||
|
BIG_BUF_EML,
|
||||||
|
FLASH_MEM,
|
||||||
|
SIM_MEM,
|
||||||
|
} DeviceMemType_t;
|
||||||
|
|
||||||
extern void UsbCommandReceived(UsbCommand *c);
|
extern void UsbCommandReceived(UsbCommand *c);
|
||||||
extern int CommandReceived(char *Cmd);
|
extern int CommandReceived(char *Cmd);
|
||||||
extern bool WaitForResponseTimeoutW(uint32_t cmd, UsbCommand* response, size_t ms_timeout, bool show_warning);
|
extern bool WaitForResponseTimeoutW(uint32_t cmd, UsbCommand* response, size_t ms_timeout, bool show_warning);
|
||||||
|
@ -23,10 +51,10 @@ extern bool WaitForResponse(uint32_t cmd, UsbCommand* response);
|
||||||
extern void clearCommandBuffer();
|
extern void clearCommandBuffer();
|
||||||
extern command_t* getTopLevelCommandTable();
|
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 GetFromDevice(DeviceMemType_t memtype, 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);
|
bool GetFromBigBuf(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
|
//bool GetEMLFromBigBuf(uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbCommand *response, size_t ms_timeout, bool show_warning);
|
||||||
#define CMD_BUFFER_SIZE 50
|
//bool GetFromFlashMen(uint8_t *dest, uint32_t bytes, uint32_t start_index, UsbCommand *response, size_t ms_timeout, bool show_warning);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue