converted CMD_LF_EM4X50_ESET to NG frame, thanks Claude

This commit is contained in:
iceman1001 committed 2026-08-29 12:20:56 +02:00
1 parent 899ad1d467
commit b3048064f6
4 files changed
+59 -6

No files matched your search

+37 -5
View File
@@ -163,26 +163,54 @@ static int em4x50_load_file(const char *filename, uint8_t *data, size_t data_len
return PM3_SUCCESS;
}
static void em4x50_seteml(uint8_t *src, uint32_t offset, uint32_t numofbytes) {
static int em4x50_seteml(const uint8_t *src, uint32_t offset, uint32_t numofbytes) {
const size_t max_chunk = PM3_CMD_DATA_SIZE - sizeof(em4x50_eset_t);
uint8_t buf[PM3_CMD_DATA_SIZE] = {0};
em4x50_eset_t *payload = (em4x50_eset_t *)buf;
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_MIX) {
for (size_t i = offset; i < numofbytes; i += max_chunk) {
size_t len = MIN((numofbytes - i), PM3_CMD_DATA_SIZE_MIX);
size_t len = MIN((numofbytes - i), max_chunk);
if (len == numofbytes - i) {
// Disable fast mode on last packet
g_conn.block_after_ACK = false;
}
payload->offset = i;
payload->len = len;
memcpy(payload->data, src + i, len);
clearCommandBuffer();
SendCommandMIX(CMD_LF_EM4X50_ESET, i, len, 0, src + i, len);
SendCommandNG(CMD_LF_EM4X50_ESET, buf, sizeof(em4x50_eset_t) + len);
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_LF_EM4X50_ESET, &resp, 2000) == false) {
g_conn.block_after_ACK = false;
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(WARNING, "timeout while waiting for reply");
return PM3_ETIMEOUT;
}
if (resp.status != PM3_SUCCESS) {
g_conn.block_after_ACK = false;
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(FAILED, "uploading to emulator memory ( " _RED_("fail") " )");
return resp.status;
}
PrintAndLogEx(NORMAL, "." NOLF);
fflush(stdout);
}
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(SUCCESS, "uploaded " _YELLOW_("%d") " bytes to emulator memory", numofbytes);
return PM3_SUCCESS;
}
static int CmdEM4x50ELoad(const char *Cmd) {
@@ -214,7 +242,11 @@ static int CmdEM4x50ELoad(const char *Cmd) {
}
// upload to emulator memory
em4x50_seteml(data, 0, EM4X50_DUMP_FILESIZE);
int res = em4x50_seteml(data, 0, EM4X50_DUMP_FILESIZE);
if (res != PM3_SUCCESS) {
return res;
}
PrintAndLogEx(HINT, "Hint: Use `" _YELLOW_("lf em 4x50 sim -h") "` to simulate");
PrintAndLogEx(INFO, "Done!");
return PM3_SUCCESS;