- trace = p;
- GetFromBigBuf(trace, traceLen, 0);
- WaitForResponse(CMD_ACK, NULL);
+ if ((tracefile = fopen(filename,"rb")) == NULL) {
+ PrintAndLog("Could not open file %s", filename);
+ free(trace);
+ return 0;
+ }
+ while (!feof(tracefile)) {
+ bytes_read = fread(trace+traceLen, 1, TRACE_CHUNK_SIZE, tracefile);
+ traceLen += bytes_read;
+ if (!feof(tracefile)) {
+ uint8_t *p = realloc(trace, traceLen + TRACE_CHUNK_SIZE);
+ if (p == NULL) {
+ PrintAndLog("Cannot allocate memory for trace");
+ free(trace);
+ fclose(tracefile);
+ return 2;
+ }
+ trace = p;
+ }
+ }
+ fclose(tracefile);
+ } else {
+ trace = malloc(USB_CMD_DATA_SIZE);
+ // Query for the size of the trace
+ UsbCommand response;
+ GetFromBigBuf(trace, USB_CMD_DATA_SIZE, 0, &response, -1, false);
+ traceLen = response.arg[2];
+ if (traceLen > USB_CMD_DATA_SIZE) {
+ uint8_t *p = realloc(trace, traceLen);
+ if (p == NULL) {
+ PrintAndLog("Cannot allocate memory for trace");
+ free(trace);
+ return 2;
+ }
+ trace = p;
+ GetFromBigBuf(trace, traceLen, 0, NULL, -1, false);
+ }