converted CMD_LF_EM4X50_ESET to NG frame, thanks Claude

This commit is contained in:
iceman1001
2026-08-29 12:20:56 +02:00
parent 899ad1d467
commit b3048064f6
4 changed files with 59 additions and 6 deletions
+1
View File
@@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
## [unreleased][unreleased]
- Change NG: convert CMD_LF_EM4X50_ESET to em4x50_eset_t (@iceman1001)
- Change NG: convert CMD_LF_T55XX_SET_CONFIG to t55xx_setconfig_t (@iceman1001)
- Added a new ISo15693 v5 dump file format to handle 0x100 number of pages and 8 byte pages better (@iceman1001)
- Fixed ISO15693 v4 file handling and converting to v5 (@iceman1001)
+14 -1
View File
@@ -1697,7 +1697,20 @@ static void PacketReceived(PacketCommandNG *packet) {
// destroy the Emulator Memory.
//-----------------------------------------------------------------------------
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
emlSet(packet->data.asBytes, packet->oldarg[0], packet->oldarg[1]);
if (packet->length < sizeof(em4x50_eset_t)) {
reply_ng(CMD_LF_EM4X50_ESET, PM3_EINVARG, NULL, 0);
break;
}
em4x50_eset_t *payload = (em4x50_eset_t *)packet->data.asBytes;
if (payload->len > packet->length - sizeof(em4x50_eset_t)) {
reply_ng(CMD_LF_EM4X50_ESET, PM3_EINVARG, NULL, 0);
break;
}
int res = emlSet(payload->data, payload->offset, payload->len);
reply_ng(CMD_LF_EM4X50_ESET, res, NULL, 0);
break;
}
case CMD_LF_EM4X50_CHK: {
+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;
+7
View File
@@ -72,6 +72,13 @@ typedef struct {
uint8_t byte[4];
} PACKED em4x50_word_t;
// CMD_LF_EM4X50_ESET payload
typedef struct {
uint16_t offset;
uint16_t len;
uint8_t data[];
} PACKED em4x50_eset_t;
typedef struct {
uint8_t count;
uint32_t *words;