improved the eload upload times by using large chunks. Quite much faster now.\nAddapted the dots and text for eload / sim across the client

This commit is contained in:
iceman1001 2023-07-26 23:39:27 +02:00
commit b696a2036f
10 changed files with 133 additions and 67 deletions

View file

@ -68,8 +68,10 @@ static bool fill_eml_from_file(char *dumpfile) {
} }
//read and load dump file //read and load dump file
BigBuf_Clear(); BigBuf_Clear();
if (g_dbglevel >= DBG_INFO) if (g_dbglevel >= DBG_INFO) {
Dbprintf(_YELLOW_("Found dump file %s. Uploading to emulator memory..."), dumpfile); Dbprintf("Found dump file... `" _YELLOW_("%s") "`", dumpfile);
Dbprintf("Uploading to emulator memory...");
}
uint8_t *emCARD = BigBuf_get_EM_addr(); uint8_t *emCARD = BigBuf_get_EM_addr();
rdv40_spiffs_read_as_filetype(dumpfile, emCARD, size, RDV40_SPIFFS_SAFETY_SAFE); rdv40_spiffs_read_as_filetype(dumpfile, emCARD, size, RDV40_SPIFFS_SAFETY_SAFE);
return true; return true;

View file

@ -71,7 +71,8 @@ static bool fill_eml_from_file(char *dumpfile) {
//read and load dump file //read and load dump file
if (g_dbglevel >= DBG_INFO) { if (g_dbglevel >= DBG_INFO) {
Dbprintf(_YELLOW_("Found dump file %s. Uploading to emulator memory..."), dumpfile); Dbprintf("Found dump file... `" _YELLOW_("%s") "`", dumpfile);
Dbprintf("Uploading to emulator memory...");
} }
emlClearMem(); emlClearMem();

View file

@ -622,12 +622,15 @@ uint8_t FirstBlockOfSector(uint8_t sectorNo) {
// work with emulator memory // work with emulator memory
void emlSetMem(uint8_t *data, int blockNum, int blocksCount) { void emlSetMem(uint8_t *data, int blockNum, int blocksCount) {
emlSetMem_xt(data, blockNum, blocksCount, 16); uint32_t offset = blockNum * 16;
uint32_t len = blocksCount * 16;
emlSet(data, offset, len);
} }
void emlSetMem_xt(uint8_t *data, int blockNum, int blocksCount, int blockBtWidth) { void emlSetMem_xt(uint8_t *data, int blockNum, int blocksCount, int block_width) {
uint8_t *emCARD = BigBuf_get_EM_addr(); uint32_t offset = blockNum * block_width;
memcpy(emCARD + blockNum * blockBtWidth, data, blocksCount * blockBtWidth); uint32_t len = blocksCount * block_width;
emlSet(data, offset, len);
} }
void emlGetMem(uint8_t *data, int blockNum, int blocksCount) { void emlGetMem(uint8_t *data, int blockNum, int blocksCount) {

View file

@ -1133,6 +1133,7 @@ static int CmdHF15ELoad(const char *Cmd) {
} }
free(data); free(data);
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
PrintAndLogEx(SUCCESS, "uploaded " _YELLOW_("%d") " bytes to emulator memory", offset);
PrintAndLogEx(HINT, "You are ready to simulate. See " _YELLOW_("`hf 15 sim -h`")); PrintAndLogEx(HINT, "You are ready to simulate. See " _YELLOW_("`hf 15 sim -h`"));
PrintAndLogEx(INFO, "Done!"); PrintAndLogEx(INFO, "Done!");
@ -1288,12 +1289,13 @@ static int CmdHF15Sim(const char *Cmd) {
CLIParserFree(ctx); CLIParserFree(ctx);
PrintAndLogEx(SUCCESS, "Starting simulating UID " _YELLOW_("%s"), iso15693_sprintUID(NULL, payload.uid)); PrintAndLogEx(SUCCESS, "Starting simulating UID " _YELLOW_("%s"), iso15693_sprintUID(NULL, payload.uid));
PrintAndLogEx(INFO, "press " _YELLOW_("`Pm3 button`") " to cancel"); PrintAndLogEx(INFO, "Press " _YELLOW_("`pm3-button`") " to abort simulation");
PacketResponseNG resp; PacketResponseNG resp;
clearCommandBuffer(); clearCommandBuffer();
SendCommandNG(CMD_HF_ISO15693_SIMULATE, (uint8_t *)&payload, sizeof(payload)); SendCommandNG(CMD_HF_ISO15693_SIMULATE, (uint8_t *)&payload, sizeof(payload));
WaitForResponse(CMD_HF_ISO15693_SIMULATE, &resp); WaitForResponse(CMD_HF_ISO15693_SIMULATE, &resp);
PrintAndLogEx(INFO, "Done!");
return PM3_SUCCESS; return PM3_SUCCESS;
} }

View file

@ -144,25 +144,32 @@ static void iclass_upload_emul(uint8_t *d, uint16_t n, uint16_t *bytes_sent) {
*bytes_sent = 0; *bytes_sent = 0;
uint16_t bytes_remaining = n; uint16_t bytes_remaining = n;
PrintAndLogEx(INFO, "Uploading to emulator memory");
PrintAndLogEx(INFO, "." NOLF);
while (bytes_remaining > 0) { while (bytes_remaining > 0) {
uint32_t bytes_in_packet = MIN(PM3_CMD_DATA_SIZE - 4, bytes_remaining); uint32_t bytes_in_packet = MIN(PM3_CMD_DATA_SIZE - 4, bytes_remaining);
if (bytes_in_packet == bytes_remaining) { if (bytes_in_packet == bytes_remaining) {
// Disable fast mode on last packet // Disable fast mode on last packet
g_conn.block_after_ACK = false; g_conn.block_after_ACK = false;
} }
clearCommandBuffer();
struct p *payload = calloc(4 + bytes_in_packet, sizeof(uint8_t)); struct p *payload = calloc(4 + bytes_in_packet, sizeof(uint8_t));
payload->offset = *bytes_sent; payload->offset = *bytes_sent;
payload->len = bytes_in_packet; payload->len = bytes_in_packet;
memcpy(payload->data, d + *bytes_sent, bytes_in_packet); memcpy(payload->data, d + *bytes_sent, bytes_in_packet);
clearCommandBuffer();
SendCommandNG(CMD_HF_ICLASS_EML_MEMSET, (uint8_t *)payload, 4 + bytes_in_packet); SendCommandNG(CMD_HF_ICLASS_EML_MEMSET, (uint8_t *)payload, 4 + bytes_in_packet);
free(payload); free(payload);
bytes_remaining -= bytes_in_packet; bytes_remaining -= bytes_in_packet;
*bytes_sent += bytes_in_packet; *bytes_sent += bytes_in_packet;
PrintAndLogEx(NORMAL, "." NOLF);
fflush(stdout);
} }
PrintAndLogEx(NORMAL, "");
} }
static const char *card_types[] = { static const char *card_types[] = {
@ -1011,6 +1018,7 @@ static int CmdHFiClassELoad(const char *Cmd) {
arg_param_begin, arg_param_begin,
arg_str1("f", "file", "<fn>", "filename of dump (bin/eml/json)"), arg_str1("f", "file", "<fn>", "filename of dump (bin/eml/json)"),
arg_lit0("m", "mem", "use RDV4 spiffs"), arg_lit0("m", "mem", "use RDV4 spiffs"),
arg_lit0("v", "verbose", "verbose output"),
arg_param_end arg_param_end
}; };
CLIExecWithReturn(ctx, Cmd, argtable, false); CLIExecWithReturn(ctx, Cmd, argtable, false);
@ -1026,6 +1034,7 @@ static int CmdHFiClassELoad(const char *Cmd) {
} }
bool use_spiffs = arg_get_lit(ctx, 2); bool use_spiffs = arg_get_lit(ctx, 2);
bool verbose = arg_get_lit(ctx, 3);
CLIParserFree(ctx); CLIParserFree(ctx);
// use RDV4 spiffs // use RDV4 spiffs
@ -1074,14 +1083,20 @@ static int CmdHFiClassELoad(const char *Cmd) {
dump = newdump; dump = newdump;
} }
print_picopass_header((picopass_hdr_t *) dump); if (verbose) {
print_picopass_info((picopass_hdr_t *) dump); print_picopass_header((picopass_hdr_t *) dump);
print_picopass_info((picopass_hdr_t *) dump);
}
PrintAndLogEx(NORMAL, "");
//Send to device //Send to device
uint16_t bytes_sent = 0; uint16_t bytes_sent = 0;
iclass_upload_emul(dump, bytes_read, &bytes_sent); iclass_upload_emul(dump, bytes_read, &bytes_sent);
free(dump); free(dump);
PrintAndLogEx(SUCCESS, "sent %u bytes of data to device emulator memory", bytes_sent); PrintAndLogEx(SUCCESS, "uploaded " _YELLOW_("%d") " bytes to emulator memory", bytes_sent);
PrintAndLogEx(HINT, "You are ready to simulate. See " _YELLOW_("`hf iclass sim -h`"));
PrintAndLogEx(INFO, "Done!");
return PM3_SUCCESS; return PM3_SUCCESS;
} }

View file

@ -525,29 +525,36 @@ static int CmdHF14AJookiSim(const char *Cmd) {
// upload to emulator memory // upload to emulator memory
PrintAndLogEx(INFO, "Uploading to emulator memory"); PrintAndLogEx(INFO, "Uploading to emulator memory");
PrintAndLogEx(INFO, "." NOLF); PrintAndLogEx(INFO, "." NOLF);
// fast push mode // fast push mode
g_conn.block_after_ACK = true; g_conn.block_after_ACK = true;
uint8_t blockwidth = 4, counter = 0, blockno = 0; uint8_t blockwidth = 4, counter = 0, blockno = 0;
// 12 is the size of the struct the fct mfEmlSetMem_xt uses to transfer to device
uint16_t max_avail_blocks = ((PM3_CMD_DATA_SIZE - 12) / blockwidth) * blockwidth;
while (datalen) { while (datalen) {
if (datalen == blockwidth) { if (datalen == blockwidth) {
// Disable fast mode on last packet // Disable fast mode on last packet
g_conn.block_after_ACK = false; g_conn.block_after_ACK = false;
} }
uint16_t chunk_size = MIN(max_avail_blocks, datalen);
uint16_t blocks_to_send = chunk_size / blockwidth;
if (mfEmlSetMem_xt(data + counter, blockno, 1, blockwidth) != PM3_SUCCESS) { if (mfEmlSetMem_xt(data + counter, blockno, blocks_to_send, blockwidth) != PM3_SUCCESS) {
PrintAndLogEx(FAILED, "Cant set emul block: %3d", blockno); PrintAndLogEx(FAILED, "Cant set emul block: %3d", blockno);
free(data); free(data);
return PM3_ESOFT; return PM3_ESOFT;
} }
blockno += blocks_to_send;
counter += chunk_size;
datalen -= chunk_size;
PrintAndLogEx(NORMAL, "." NOLF); PrintAndLogEx(NORMAL, "." NOLF);
fflush(stdout); fflush(stdout);
blockno++;
counter += blockwidth;
datalen -= blockwidth;
} }
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(NORMAL, "");
PrintAndLogEx(SUCCESS, "uploaded " _YELLOW_("%d") " bytes to emulator memory", counter);
struct { struct {
uint8_t tagtype; uint8_t tagtype;
@ -566,6 +573,8 @@ static int CmdHF14AJookiSim(const char *Cmd) {
SendCommandNG(CMD_HF_ISO14443A_SIMULATE, (uint8_t *)&payload, sizeof(payload)); SendCommandNG(CMD_HF_ISO14443A_SIMULATE, (uint8_t *)&payload, sizeof(payload));
PacketResponseNG resp; PacketResponseNG resp;
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(SUCCESS, "Starting simulating");
PrintAndLogEx(INFO, "Press " _GREEN_("<Enter>") " or pm3-button to abort simulation"); PrintAndLogEx(INFO, "Press " _GREEN_("<Enter>") " or pm3-button to abort simulation");
for (;;) { for (;;) {
if (kbd_enter_pressed()) { if (kbd_enter_pressed()) {
@ -581,8 +590,8 @@ static int CmdHF14AJookiSim(const char *Cmd) {
break; break;
} }
free(data); free(data);
PrintAndLogEx(INFO, "Done");
PrintAndLogEx(HINT, "Try `" _YELLOW_("hf 14a list") "` to view trace log"); PrintAndLogEx(HINT, "Try `" _YELLOW_("hf 14a list") "` to view trace log");
PrintAndLogEx(INFO, "Done!");
return PM3_SUCCESS; return PM3_SUCCESS;
} }

View file

@ -805,6 +805,9 @@ void legic_chk_iv(uint32_t *iv) {
void legic_seteml(uint8_t *src, uint32_t offset, uint32_t numofbytes) { void legic_seteml(uint8_t *src, uint32_t offset, uint32_t numofbytes) {
PrintAndLogEx(INFO, "Uploading to emulator memory");
PrintAndLogEx(INFO, "." NOLF);
// fast push mode // fast push mode
g_conn.block_after_ACK = true; g_conn.block_after_ACK = true;
for (size_t i = offset; i < numofbytes; i += LEGIC_PACKET_SIZE) { for (size_t i = offset; i < numofbytes; i += LEGIC_PACKET_SIZE) {
@ -823,7 +826,11 @@ void legic_seteml(uint8_t *src, uint32_t offset, uint32_t numofbytes) {
clearCommandBuffer(); clearCommandBuffer();
SendCommandNG(CMD_HF_LEGIC_ESET, (uint8_t *)payload, sizeof(legic_packet_t) + len); SendCommandNG(CMD_HF_LEGIC_ESET, (uint8_t *)payload, sizeof(legic_packet_t) + len);
free(payload); free(payload);
PrintAndLogEx(NORMAL, "." NOLF);
fflush(stdout);
} }
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(SUCCESS, "uploaded " _YELLOW_("%d") " bytes to emulator memory", numofbytes);
} }
static int CmdLegicReader(const char *Cmd) { static int CmdLegicReader(const char *Cmd) {
@ -1100,10 +1107,11 @@ static int CmdLegicELoad(const char *Cmd) {
legic_xor(dump, bytes_read); legic_xor(dump, bytes_read);
} }
PrintAndLogEx(SUCCESS, "Uploading to emulator memory");
legic_seteml(dump, 0, bytes_read); legic_seteml(dump, 0, bytes_read);
free(dump); free(dump);
PrintAndLogEx(HINT, "You are ready to simulate. See " _YELLOW_("`hf legic sim -h`"));
PrintAndLogEx(SUCCESS, "Done!"); PrintAndLogEx(SUCCESS, "Done!");
return PM3_SUCCESS; return PM3_SUCCESS;
} }

View file

@ -4264,6 +4264,7 @@ int CmdHF14AMfELoad(const char *Cmd) {
arg_lit0(NULL, "ul", "MIFARE Ultralight family"), arg_lit0(NULL, "ul", "MIFARE Ultralight family"),
arg_lit0("m", "mem", "use RDV4 spiffs"), arg_lit0("m", "mem", "use RDV4 spiffs"),
arg_int0("q", "qty", "<dec>", "manually set number of blocks (overrides)"), arg_int0("q", "qty", "<dec>", "manually set number of blocks (overrides)"),
arg_lit0("v", "verbose", "verbose output"),
arg_param_end arg_param_end
}; };
CLIExecWithReturn(ctx, Cmd, argtable, false); CLIExecWithReturn(ctx, Cmd, argtable, false);
@ -4280,7 +4281,7 @@ int CmdHF14AMfELoad(const char *Cmd) {
bool use_spiffs = arg_get_lit(ctx, 7); bool use_spiffs = arg_get_lit(ctx, 7);
int numblks = arg_get_int_def(ctx, 8, -1); int numblks = arg_get_int_def(ctx, 8, -1);
bool verbose = arg_get_lit(ctx, 9);
CLIParserFree(ctx); CLIParserFree(ctx);
// validations // validations
@ -4372,8 +4373,10 @@ int CmdHF14AMfELoad(const char *Cmd) {
return res; return res;
} }
mfu_dump_t *mfu_dump = (mfu_dump_t *)data; if (verbose) {
printMFUdumpEx(mfu_dump, mfu_dump->pages + 1, 0); mfu_dump_t *mfu_dump = (mfu_dump_t *)data;
printMFUdumpEx(mfu_dump, mfu_dump->pages + 1, 0);
}
// update expected blocks to match converted data. // update expected blocks to match converted data.
block_cnt = bytes_read / MFU_BLOCK_SIZE; block_cnt = bytes_read / MFU_BLOCK_SIZE;
@ -4389,23 +4392,28 @@ int CmdHF14AMfELoad(const char *Cmd) {
size_t offset = 0; size_t offset = 0;
int cnt = 0; int cnt = 0;
// 12 is the size of the struct the fct mfEmlSetMem_xt uses to transfer to device
uint16_t max_avail_blocks = ((PM3_CMD_DATA_SIZE - 12) / block_width) * block_width;
while (bytes_read && cnt < block_cnt) { while (bytes_read && cnt < block_cnt) {
if (bytes_read == block_width) { if (bytes_read == block_width) {
// Disable fast mode on last packet // Disable fast mode on last packet
g_conn.block_after_ACK = false; g_conn.block_after_ACK = false;
} }
if (mfEmlSetMem_xt(data + offset, cnt, 1, block_width) != PM3_SUCCESS) { uint16_t chunk_size = MIN(max_avail_blocks, bytes_read);
uint16_t blocks_to_send = chunk_size / block_width;
if (mfEmlSetMem_xt(data + offset, cnt, blocks_to_send, block_width) != PM3_SUCCESS) {
PrintAndLogEx(FAILED, "Can't set emulator mem at block: %3d", cnt); PrintAndLogEx(FAILED, "Can't set emulator mem at block: %3d", cnt);
free(data); free(data);
return PM3_ESOFT; return PM3_ESOFT;
} }
cnt += blocks_to_send;
offset += chunk_size;
bytes_read -= chunk_size;
PrintAndLogEx(NORMAL, "." NOLF); PrintAndLogEx(NORMAL, "." NOLF);
fflush(stdout); fflush(stdout);
cnt++;
offset += block_width;
bytes_read -= block_width;
} }
free(data); free(data);
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
@ -4424,8 +4432,8 @@ int CmdHF14AMfELoad(const char *Cmd) {
PrintAndLogEx(WARNING, "Error, file content, Only loaded %d blocks, must be %d blocks into emulator memory", cnt, block_cnt); PrintAndLogEx(WARNING, "Error, file content, Only loaded %d blocks, must be %d blocks into emulator memory", cnt, block_cnt);
return PM3_SUCCESS; return PM3_SUCCESS;
} }
PrintAndLogEx(INFO, "Done!");
} }
PrintAndLogEx(INFO, "Done!");
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -5327,6 +5335,10 @@ static int CmdHF14AMfCSave(const char *Cmd) {
if (mfEmlSetMem(dump + (i * MFBLOCK_SIZE), i, 5) != PM3_SUCCESS) { if (mfEmlSetMem(dump + (i * MFBLOCK_SIZE), i, 5) != PM3_SUCCESS) {
PrintAndLogEx(WARNING, "Can't set emul block: " _YELLOW_("%d"), i); PrintAndLogEx(WARNING, "Can't set emul block: " _YELLOW_("%d"), i);
} }
if (i % 64 == 0) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "" NOLF) ;
}
PrintAndLogEx(NORMAL, "." NOLF); PrintAndLogEx(NORMAL, "." NOLF);
fflush(stdout); fflush(stdout);
} }
@ -7836,14 +7848,6 @@ static int CmdHF14AGen4View(const char *Cmd) {
for (uint16_t i = 0; i < block_cnt; i++) { for (uint16_t i = 0; i < block_cnt; i++) {
// 4k READs can be long, so we split status each 64 blocks.
if (i % 64 == 0) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "" NOLF) ;
}
PrintAndLogEx(NORMAL, "." NOLF);
fflush(stdout);
uint8_t flags = 0 ; uint8_t flags = 0 ;
if (i == 0) flags |= MAGIC_INIT ; if (i == 0) flags |= MAGIC_INIT ;
if (i + 1 == block_cnt) flags |= MAGIC_OFF ; if (i + 1 == block_cnt) flags |= MAGIC_OFF ;
@ -7855,6 +7859,14 @@ static int CmdHF14AGen4View(const char *Cmd) {
free(dump); free(dump);
return PM3_ESOFT; return PM3_ESOFT;
} }
PrintAndLogEx(NORMAL, "." NOLF);
fflush(stdout);
// 4k READs can be long, so we split status each 64 blocks.
if (i % 64 == 0) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "" NOLF) ;
}
} }
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
@ -7939,8 +7951,6 @@ static int CmdHF14AGen4Save(const char *Cmd) {
PrintAndLogEx(WARNING, "Please specify a MIFARE Type"); PrintAndLogEx(WARNING, "Please specify a MIFARE Type");
return PM3_EINVARG; return PM3_EINVARG;
} }
PrintAndLogEx(SUCCESS, "Dumping magic gen4 GTU MIFARE Classic " _GREEN_("%s") " card memory", s);
PrintAndLogEx(INFO, "." NOLF);
// Select card to get UID/UIDLEN information // Select card to get UID/UIDLEN information
clearCommandBuffer(); clearCommandBuffer();
@ -7975,63 +7985,72 @@ static int CmdHF14AGen4Save(const char *Cmd) {
return PM3_EMALLOC; return PM3_EMALLOC;
} }
PrintAndLogEx(SUCCESS, "Dumping magic gen4 GTU MIFARE Classic " _GREEN_("%s") " card memory", s);
PrintAndLogEx(INFO, "." NOLF);
for (uint16_t i = 0; i < block_cnt; i++) { for (uint16_t i = 0; i < block_cnt; i++) {
// 4k READs can be long, so we split status each 64 blocks.
if (i % 64 == 0) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "" NOLF) ;
}
PrintAndLogEx(NORMAL, "." NOLF);
fflush(stdout);
uint8_t flags = 0 ; uint8_t flags = 0 ;
if (i == 0) flags |= MAGIC_INIT ; if (i == 0) {
if (i + 1 == block_cnt) flags |= MAGIC_OFF ; flags |= MAGIC_INIT;
}
if (i + 1 == block_cnt) {
flags |= MAGIC_OFF;
}
int res = mfG4GetBlock(pwd, i, dump + (i * MFBLOCK_SIZE), flags); int res = mfG4GetBlock(pwd, i, dump + (i * MFBLOCK_SIZE), flags);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(NORMAL,"");
PrintAndLogEx(WARNING, "Can't get magic card block: %u. error=%d", i, res); PrintAndLogEx(WARNING, "Can't get magic card block: %u. error=%d", i, res);
PrintAndLogEx(HINT, "Verify your card size, and try again or try another tag position"); PrintAndLogEx(HINT, "Verify your card size, and try again or try another tag position");
free(dump); free(dump);
return PM3_ESOFT; return PM3_ESOFT;
} }
PrintAndLogEx(NORMAL, "." NOLF);
fflush(stdout);
// 4k READs can be long, so we split status each 64 blocks.
if (i % 64 == 0 && i != 0) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "" NOLF) ;
}
} }
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
if (fill_emulator) { if (fill_emulator) {
PrintAndLogEx(INFO, "uploading to emulator memory" NOLF); PrintAndLogEx(INFO, "uploading to emulator memory");
PrintAndLogEx(INFO, "." NOLF);
// fast push mode // fast push mode
g_conn.block_after_ACK = true; g_conn.block_after_ACK = true;
size_t offset = 0; size_t offset = 0;
int cnt = 0; int cnt = 0;
uint16_t bytes_left = bytes ; uint16_t bytes_left = bytes ;
while (bytes_left > 0 && cnt < block_cnt) { // 12 is the size of the struct the fct mfEmlSetMem_xt uses to transfer to device
// 4k writes can be long, so we split status each 64 blocks. uint16_t max_avail_blocks = ((PM3_CMD_DATA_SIZE - 12) / MFBLOCK_SIZE) * MFBLOCK_SIZE;
if (cnt % 64 == 0) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "" NOLF) ;
}
PrintAndLogEx(NORMAL, "." NOLF);
fflush(stdout);
while (bytes_left > 0 && cnt < block_cnt) {
if (bytes_left == MFBLOCK_SIZE) { if (bytes_left == MFBLOCK_SIZE) {
// Disable fast mode on last packet // Disable fast mode on last packet
g_conn.block_after_ACK = false; g_conn.block_after_ACK = false;
} }
if (mfEmlSetMem_xt(dump + offset, cnt, 1, MFBLOCK_SIZE) != PM3_SUCCESS) { uint16_t chunk_size = MIN(max_avail_blocks, bytes_left);
uint16_t blocks_to_send = chunk_size / MFBLOCK_SIZE;
if (mfEmlSetMem_xt(dump + offset, cnt, blocks_to_send, MFBLOCK_SIZE) != PM3_SUCCESS) {
PrintAndLogEx(FAILED, "Can't set emulator mem at block: %3d", cnt); PrintAndLogEx(FAILED, "Can't set emulator mem at block: %3d", cnt);
free(dump); free(dump);
return PM3_ESOFT; return PM3_ESOFT;
} }
cnt++; cnt += blocks_to_send;
offset += MFBLOCK_SIZE; offset += chunk_size;
bytes_left -= MFBLOCK_SIZE; bytes_left -= chunk_size;
PrintAndLogEx(NORMAL, "." NOLF);
fflush(stdout);
} }
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");

View file

@ -3067,6 +3067,7 @@ static int CmdHF14AMfUeLoad(const char *Cmd) {
arg_param_begin, arg_param_begin,
arg_str1("f", "file", "<fn>", "Filename of dump"), arg_str1("f", "file", "<fn>", "Filename of dump"),
arg_int0("q", "qty", "<dec>", "Number of blocks to load from eml file"), arg_int0("q", "qty", "<dec>", "Number of blocks to load from eml file"),
arg_lit0("v", "verbose", "verbose output"),
arg_param_end arg_param_end
}; };
CLIExecWithReturn(ctx, Cmd, argtable, false); CLIExecWithReturn(ctx, Cmd, argtable, false);
@ -3083,6 +3084,7 @@ static int CmdHF14AMfUeLoad(const char *Cmd) {
free(nc); free(nc);
PrintAndLogEx(HINT, "Try " _YELLOW_("`hf mfu sim -t 7`") " to simulate an Amiibo."); PrintAndLogEx(HINT, "Try " _YELLOW_("`hf mfu sim -t 7`") " to simulate an Amiibo.");
PrintAndLogEx(INFO, "Done!");
return res; return res;
} }

View file

@ -165,6 +165,8 @@ static int em4x50_load_file(const char *filename, uint8_t *data, size_t data_len
static void em4x50_seteml(uint8_t *src, uint32_t offset, uint32_t numofbytes) { static void em4x50_seteml(uint8_t *src, uint32_t offset, uint32_t numofbytes) {
PrintAndLogEx(INFO, "uploading to emulator memory");
PrintAndLogEx(INFO, "." NOLF);
// fast push mode // fast push mode
g_conn.block_after_ACK = true; g_conn.block_after_ACK = true;
for (size_t i = offset; i < numofbytes; i += PM3_CMD_DATA_SIZE) { for (size_t i = offset; i < numofbytes; i += PM3_CMD_DATA_SIZE) {
@ -176,7 +178,11 @@ static void em4x50_seteml(uint8_t *src, uint32_t offset, uint32_t numofbytes) {
} }
clearCommandBuffer(); clearCommandBuffer();
SendCommandOLD(CMD_LF_EM4X50_ESET, i, len, 0, src + i, len); SendCommandOLD(CMD_LF_EM4X50_ESET, i, len, 0, src + i, len);
PrintAndLogEx(NORMAL, "." NOLF);
fflush(stdout);
} }
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(SUCCESS, "uploaded " _YELLOW_("%d") " bytes to emulator memory", numofbytes);
} }
int CmdEM4x50ELoad(const char *Cmd) { int CmdEM4x50ELoad(const char *Cmd) {
@ -208,9 +214,8 @@ int CmdEM4x50ELoad(const char *Cmd) {
} }
// upload to emulator memory // upload to emulator memory
PrintAndLogEx(INFO, "Uploading to emulator memory contents of " _YELLOW_("%s"), filename);
em4x50_seteml(data, 0, DUMP_FILESIZE); em4x50_seteml(data, 0, DUMP_FILESIZE);
PrintAndLogEx(HINT, "You are ready to simulate. See " _YELLOW_("`lf em 4x50 sim -h`"));
PrintAndLogEx(INFO, "Done!"); PrintAndLogEx(INFO, "Done!");
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -1221,7 +1226,7 @@ int CmdEM4x50Sim(const char *Cmd) {
} }
int status = PM3_EFAILED; int status = PM3_EFAILED;
PrintAndLogEx(INFO, "Simulating data from emulator memory"); PrintAndLogEx(INFO, "Starting simulating");
clearCommandBuffer(); clearCommandBuffer();
SendCommandNG(CMD_LF_EM4X50_SIM, (uint8_t *)&password, sizeof(password)); SendCommandNG(CMD_LF_EM4X50_SIM, (uint8_t *)&password, sizeof(password));