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

@ -1133,6 +1133,7 @@ static int CmdHF15ELoad(const char *Cmd) {
}
free(data);
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(INFO, "Done!");
@ -1288,12 +1289,13 @@ static int CmdHF15Sim(const char *Cmd) {
CLIParserFree(ctx);
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;
clearCommandBuffer();
SendCommandNG(CMD_HF_ISO15693_SIMULATE, (uint8_t *)&payload, sizeof(payload));
WaitForResponse(CMD_HF_ISO15693_SIMULATE, &resp);
PrintAndLogEx(INFO, "Done!");
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;
uint16_t bytes_remaining = n;
PrintAndLogEx(INFO, "Uploading to emulator memory");
PrintAndLogEx(INFO, "." NOLF);
while (bytes_remaining > 0) {
uint32_t bytes_in_packet = MIN(PM3_CMD_DATA_SIZE - 4, bytes_remaining);
if (bytes_in_packet == bytes_remaining) {
// Disable fast mode on last packet
g_conn.block_after_ACK = false;
}
clearCommandBuffer();
struct p *payload = calloc(4 + bytes_in_packet, sizeof(uint8_t));
payload->offset = *bytes_sent;
payload->len = 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);
free(payload);
bytes_remaining -= bytes_in_packet;
*bytes_sent += bytes_in_packet;
PrintAndLogEx(NORMAL, "." NOLF);
fflush(stdout);
}
PrintAndLogEx(NORMAL, "");
}
static const char *card_types[] = {
@ -1011,6 +1018,7 @@ static int CmdHFiClassELoad(const char *Cmd) {
arg_param_begin,
arg_str1("f", "file", "<fn>", "filename of dump (bin/eml/json)"),
arg_lit0("m", "mem", "use RDV4 spiffs"),
arg_lit0("v", "verbose", "verbose output"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
@ -1026,6 +1034,7 @@ static int CmdHFiClassELoad(const char *Cmd) {
}
bool use_spiffs = arg_get_lit(ctx, 2);
bool verbose = arg_get_lit(ctx, 3);
CLIParserFree(ctx);
// use RDV4 spiffs
@ -1073,15 +1082,21 @@ static int CmdHFiClassELoad(const char *Cmd) {
} else {
dump = newdump;
}
if (verbose) {
print_picopass_header((picopass_hdr_t *) dump);
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
uint16_t bytes_sent = 0;
iclass_upload_emul(dump, bytes_read, &bytes_sent);
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;
}

View file

@ -525,29 +525,36 @@ static int CmdHF14AJookiSim(const char *Cmd) {
// upload to emulator memory
PrintAndLogEx(INFO, "Uploading to emulator memory");
PrintAndLogEx(INFO, "." NOLF);
// fast push mode
g_conn.block_after_ACK = true;
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) {
if (datalen == blockwidth) {
// Disable fast mode on last packet
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);
free(data);
return PM3_ESOFT;
}
blockno += blocks_to_send;
counter += chunk_size;
datalen -= chunk_size;
PrintAndLogEx(NORMAL, "." NOLF);
fflush(stdout);
blockno++;
counter += blockwidth;
datalen -= blockwidth;
}
PrintAndLogEx(NORMAL, "\n");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(SUCCESS, "uploaded " _YELLOW_("%d") " bytes to emulator memory", counter);
struct {
uint8_t tagtype;
@ -566,6 +573,8 @@ static int CmdHF14AJookiSim(const char *Cmd) {
SendCommandNG(CMD_HF_ISO14443A_SIMULATE, (uint8_t *)&payload, sizeof(payload));
PacketResponseNG resp;
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(SUCCESS, "Starting simulating");
PrintAndLogEx(INFO, "Press " _GREEN_("<Enter>") " or pm3-button to abort simulation");
for (;;) {
if (kbd_enter_pressed()) {
@ -581,8 +590,8 @@ static int CmdHF14AJookiSim(const char *Cmd) {
break;
}
free(data);
PrintAndLogEx(INFO, "Done");
PrintAndLogEx(HINT, "Try `" _YELLOW_("hf 14a list") "` to view trace log");
PrintAndLogEx(INFO, "Done!");
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) {
PrintAndLogEx(INFO, "Uploading to emulator memory");
PrintAndLogEx(INFO, "." NOLF);
// fast push mode
g_conn.block_after_ACK = true;
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();
SendCommandNG(CMD_HF_LEGIC_ESET, (uint8_t *)payload, sizeof(legic_packet_t) + len);
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) {
@ -1100,10 +1107,11 @@ static int CmdLegicELoad(const char *Cmd) {
legic_xor(dump, bytes_read);
}
PrintAndLogEx(SUCCESS, "Uploading to emulator memory");
legic_seteml(dump, 0, bytes_read);
free(dump);
PrintAndLogEx(HINT, "You are ready to simulate. See " _YELLOW_("`hf legic sim -h`"));
PrintAndLogEx(SUCCESS, "Done!");
return PM3_SUCCESS;
}

View file

@ -4264,6 +4264,7 @@ int CmdHF14AMfELoad(const char *Cmd) {
arg_lit0(NULL, "ul", "MIFARE Ultralight family"),
arg_lit0("m", "mem", "use RDV4 spiffs"),
arg_int0("q", "qty", "<dec>", "manually set number of blocks (overrides)"),
arg_lit0("v", "verbose", "verbose output"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
@ -4280,7 +4281,7 @@ int CmdHF14AMfELoad(const char *Cmd) {
bool use_spiffs = arg_get_lit(ctx, 7);
int numblks = arg_get_int_def(ctx, 8, -1);
bool verbose = arg_get_lit(ctx, 9);
CLIParserFree(ctx);
// validations
@ -4372,8 +4373,10 @@ int CmdHF14AMfELoad(const char *Cmd) {
return res;
}
mfu_dump_t *mfu_dump = (mfu_dump_t *)data;
printMFUdumpEx(mfu_dump, mfu_dump->pages + 1, 0);
if (verbose) {
mfu_dump_t *mfu_dump = (mfu_dump_t *)data;
printMFUdumpEx(mfu_dump, mfu_dump->pages + 1, 0);
}
// update expected blocks to match converted data.
block_cnt = bytes_read / MFU_BLOCK_SIZE;
@ -4389,23 +4392,28 @@ int CmdHF14AMfELoad(const char *Cmd) {
size_t offset = 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) {
if (bytes_read == block_width) {
// Disable fast mode on last packet
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);
free(data);
return PM3_ESOFT;
}
cnt += blocks_to_send;
offset += chunk_size;
bytes_read -= chunk_size;
PrintAndLogEx(NORMAL, "." NOLF);
fflush(stdout);
cnt++;
offset += block_width;
bytes_read -= block_width;
}
free(data);
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);
return PM3_SUCCESS;
}
PrintAndLogEx(INFO, "Done!");
}
PrintAndLogEx(INFO, "Done!");
return PM3_SUCCESS;
}
@ -5327,6 +5335,10 @@ static int CmdHF14AMfCSave(const char *Cmd) {
if (mfEmlSetMem(dump + (i * MFBLOCK_SIZE), i, 5) != PM3_SUCCESS) {
PrintAndLogEx(WARNING, "Can't set emul block: " _YELLOW_("%d"), i);
}
if (i % 64 == 0) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "" NOLF) ;
}
PrintAndLogEx(NORMAL, "." NOLF);
fflush(stdout);
}
@ -7836,14 +7848,6 @@ static int CmdHF14AGen4View(const char *Cmd) {
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 ;
if (i == 0) flags |= MAGIC_INIT ;
if (i + 1 == block_cnt) flags |= MAGIC_OFF ;
@ -7855,6 +7859,14 @@ static int CmdHF14AGen4View(const char *Cmd) {
free(dump);
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, "");
@ -7939,8 +7951,6 @@ static int CmdHF14AGen4Save(const char *Cmd) {
PrintAndLogEx(WARNING, "Please specify a MIFARE Type");
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
clearCommandBuffer();
@ -7975,63 +7985,72 @@ static int CmdHF14AGen4Save(const char *Cmd) {
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++) {
// 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 ;
if (i == 0) flags |= MAGIC_INIT ;
if (i + 1 == block_cnt) flags |= MAGIC_OFF ;
if (i == 0) {
flags |= MAGIC_INIT;
}
if (i + 1 == block_cnt) {
flags |= MAGIC_OFF;
}
int res = mfG4GetBlock(pwd, i, dump + (i * MFBLOCK_SIZE), flags);
if (res != PM3_SUCCESS) {
PrintAndLogEx(NORMAL,"");
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");
free(dump);
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, "");
if (fill_emulator) {
PrintAndLogEx(INFO, "uploading to emulator memory" NOLF);
PrintAndLogEx(INFO, "uploading to emulator memory");
PrintAndLogEx(INFO, "." NOLF);
// fast push mode
g_conn.block_after_ACK = true;
size_t offset = 0;
int cnt = 0;
int cnt = 0;
uint16_t bytes_left = bytes ;
while (bytes_left > 0 && cnt < block_cnt) {
// 4k writes can be long, so we split status each 64 blocks.
if (cnt % 64 == 0) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "" NOLF) ;
}
PrintAndLogEx(NORMAL, "." NOLF);
fflush(stdout);
// 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) / MFBLOCK_SIZE) * MFBLOCK_SIZE;
while (bytes_left > 0 && cnt < block_cnt) {
if (bytes_left == MFBLOCK_SIZE) {
// Disable fast mode on last packet
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);
free(dump);
return PM3_ESOFT;
}
cnt++;
offset += MFBLOCK_SIZE;
bytes_left -= MFBLOCK_SIZE;
cnt += blocks_to_send;
offset += chunk_size;
bytes_left -= chunk_size;
PrintAndLogEx(NORMAL, "." NOLF);
fflush(stdout);
}
PrintAndLogEx(NORMAL, "");

View file

@ -3067,6 +3067,7 @@ static int CmdHF14AMfUeLoad(const char *Cmd) {
arg_param_begin,
arg_str1("f", "file", "<fn>", "Filename of dump"),
arg_int0("q", "qty", "<dec>", "Number of blocks to load from eml file"),
arg_lit0("v", "verbose", "verbose output"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
@ -3083,6 +3084,7 @@ static int CmdHF14AMfUeLoad(const char *Cmd) {
free(nc);
PrintAndLogEx(HINT, "Try " _YELLOW_("`hf mfu sim -t 7`") " to simulate an Amiibo.");
PrintAndLogEx(INFO, "Done!");
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) {
PrintAndLogEx(INFO, "uploading to emulator memory");
PrintAndLogEx(INFO, "." NOLF);
// fast push mode
g_conn.block_after_ACK = true;
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();
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) {
@ -208,9 +214,8 @@ int CmdEM4x50ELoad(const char *Cmd) {
}
// upload to emulator memory
PrintAndLogEx(INFO, "Uploading to emulator memory contents of " _YELLOW_("%s"), filename);
em4x50_seteml(data, 0, DUMP_FILESIZE);
PrintAndLogEx(HINT, "You are ready to simulate. See " _YELLOW_("`lf em 4x50 sim -h`"));
PrintAndLogEx(INFO, "Done!");
return PM3_SUCCESS;
}
@ -1221,7 +1226,7 @@ int CmdEM4x50Sim(const char *Cmd) {
}
int status = PM3_EFAILED;
PrintAndLogEx(INFO, "Simulating data from emulator memory");
PrintAndLogEx(INFO, "Starting simulating");
clearCommandBuffer();
SendCommandNG(CMD_LF_EM4X50_SIM, (uint8_t *)&password, sizeof(password));