mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-24 07:05:40 -07:00
fix when length is not even dividable with four.
This commit is contained in:
parent
4dc1f9c62d
commit
d635f39048
1 changed files with 16 additions and 12 deletions
|
@ -20,9 +20,10 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
#include "proxgui.h"
|
#include "proxgui.h"
|
||||||
#include "util.h" //param_get32ex
|
#include "util.h" // param_get32ex
|
||||||
#include "lfdemod.h"
|
#include "lfdemod.h"
|
||||||
#include "cmddata.h" //for g_debugmode
|
#include "cmddata.h" // for g_debugmode
|
||||||
|
#include "commonutil.h" // Uint4bytetomemle
|
||||||
|
|
||||||
|
|
||||||
int32_t g_GraphBuffer[MAX_GRAPH_TRACE_LEN];
|
int32_t g_GraphBuffer[MAX_GRAPH_TRACE_LEN];
|
||||||
|
@ -500,16 +501,19 @@ buffer_savestate_t save_buffer8(uint8_t *src, size_t length) {
|
||||||
// We are going to be packing the 8-bit source buffer into
|
// We are going to be packing the 8-bit source buffer into
|
||||||
// the 32-bit backing buffer, so the input length is going to be
|
// the 32-bit backing buffer, so the input length is going to be
|
||||||
// 1/4 of the size needed
|
// 1/4 of the size needed
|
||||||
size_t buffSize = (length/4);
|
size_t buffSize = (length / 4);
|
||||||
|
|
||||||
//calloc the memory needed
|
if (length % 4) {
|
||||||
|
buffSize++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// calloc the memory needed
|
||||||
uint32_t* savedBuffer = (uint32_t*)calloc(buffSize, sizeof(uint32_t));
|
uint32_t* savedBuffer = (uint32_t*)calloc(buffSize, sizeof(uint32_t));
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
|
|
||||||
//Pack the source array into the backing array
|
// Pack the source array into the backing array
|
||||||
for(size_t i = 0; i < length; i += 4) {
|
for(size_t i = 0; i < length; i += 4) {
|
||||||
savedBuffer[index] = (uint32_t)src[i] | ((uint32_t)src[i+1] << 8) |
|
savedBuffer[index] = MemLeToUint4byte(src + i);
|
||||||
((uint32_t)src[i+2] << 16) | ((uint32_t)src[i+3] << 24);
|
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -557,10 +561,10 @@ size_t restore_buffer8(buffer_savestate_t saveState, uint8_t *dest) {
|
||||||
|
|
||||||
// Unpack the array
|
// Unpack the array
|
||||||
for(size_t i = 0; i < saveState.bufferSize; i++) {
|
for(size_t i = 0; i < saveState.bufferSize; i++) {
|
||||||
dest[index++] = (uint8_t)(saveState.buffer[i] & 0xFF);
|
dest[index++] = saveState.buffer[i];
|
||||||
dest[index++] = (uint8_t)((saveState.buffer[i] >> 8) & 0xFF);
|
dest[index++] = (saveState.buffer[i] >> 8) & 0xFF;
|
||||||
dest[index++] = (uint8_t)((saveState.buffer[i] >> 16) & 0xFF);
|
dest[index++] = (saveState.buffer[i] >> 16) & 0xFF;
|
||||||
dest[index++] = (uint8_t)((saveState.buffer[i] >> 24) & 0xFF);
|
dest[index++] = (saveState.buffer[i] >> 24) & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue