fix: CMD_DOWNLOAD_BIGBUF for getSamples() and download_trace()

This commit is contained in:
douniwan5788 2024-08-27 22:39:50 +08:00
commit 4b6653696c
2 changed files with 11 additions and 10 deletions

View file

@ -2391,15 +2391,15 @@ static void PacketReceived(PacketCommandNG *packet) {
// arg2 = BigBuf tracelen // arg2 = BigBuf tracelen
//Dbprintf("transfer to client parameters: %" PRIu32 " | %" PRIu32 " | %" PRIu32, startidx, numofbytes, packet->oldarg[2]); //Dbprintf("transfer to client parameters: %" PRIu32 " | %" PRIu32 " | %" PRIu32, startidx, numofbytes, packet->oldarg[2]);
for (size_t i = 0; i < numofbytes; i += PM3_CMD_DATA_SIZE) { for (size_t offset = 0; offset < numofbytes; offset += PM3_CMD_DATA_SIZE) {
size_t len = MIN((numofbytes - i), PM3_CMD_DATA_SIZE); size_t len = MIN((numofbytes - offset), PM3_CMD_DATA_SIZE);
int result = reply_old(CMD_DOWNLOADED_BIGBUF, i, len, BigBuf_get_traceLen(), mem + startidx + i, len); int result = reply_old(CMD_DOWNLOADED_BIGBUF, offset, len, BigBuf_get_traceLen(), &mem[startidx + offset], len);
if (result != PM3_SUCCESS) if (result != PM3_SUCCESS)
Dbprintf("transfer to client failed :: | bytes between %d - %d (%d) | result: %d", i, i + len, len, result); Dbprintf("transfer to client failed :: | bytes between %d - %d (%d) | result: %d", offset, offset + len, len, result);
} }
// Trigger a finish downloading signal with an ACK frame // Trigger a finish downloading signal with an ACK frame
// arg0 = status of download transfer // arg0 = status of download transfer
reply_mix(CMD_ACK, 1, 0, 0, 0, 0); reply_mix(CMD_ACK, 1, 0, BigBuf_get_traceLen(), NULL, 0);
LED_B_OFF(); LED_B_OFF();
break; break;
} }

View file

@ -29,6 +29,7 @@
#include "graph.h" // for graph data #include "graph.h" // for graph data
#include "comms.h" #include "comms.h"
#include "lfdemod.h" // for demod code #include "lfdemod.h" // for demod code
#include "cmdlf.h" // for lf_getconfig
#include "loclass/cipherutils.h" // for decimating samples in getsamples #include "loclass/cipherutils.h" // for decimating samples in getsamples
#include "cmdlfem410x.h" // askem410xdecode #include "cmdlfem410x.h" // askem410xdecode
#include "fileutils.h" // searchFile #include "fileutils.h" // searchFile
@ -1875,13 +1876,13 @@ int getSamplesEx(uint32_t start, uint32_t end, bool verbose, bool ignore_lf_conf
uint8_t bits_per_sample = 8; uint8_t bits_per_sample = 8;
// Old devices without this feature would send 0 at arg[0] if (IfPm3Lf() && ignore_lf_config == false) {
if (resp.oldarg[0] > 0 && (ignore_lf_config == false)) { sample_config sc;
sample_config *sc = (sample_config *) resp.data.asBytes; lf_getconfig(&sc);
if (verbose) { if (verbose) {
PrintAndLogEx(INFO, "Samples @ " _YELLOW_("%d") " bits/smpl, decimation 1:%d ", sc->bits_per_sample, sc->decimation); PrintAndLogEx(INFO, "Samples @ " _YELLOW_("%d") " bits/smpl, decimation 1:%d ", sc.bits_per_sample, sc.decimation);
} }
bits_per_sample = sc->bits_per_sample; bits_per_sample = sc.bits_per_sample;
} }
return getSamplesFromBufEx(got, n, bits_per_sample, verbose);; return getSamplesFromBufEx(got, n, bits_per_sample, verbose);;