]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
adjust ManchesterEncode 235/head
authormarshmellow42 <marshmellowrf@gmail.com>
Tue, 21 Mar 2017 13:53:14 +0000 (09:53 -0400)
committermarshmellow42 <marshmellowrf@gmail.com>
Tue, 21 Mar 2017 13:53:14 +0000 (09:53 -0400)
removed dead size check
added a max size of 2k input bits (4k out)
this shouldn't overload the array memory passed to it typically...

common/lfdemod.c

index 5a1007fb160e29cac7541a22ca5c2a413cc969fe..8307a89088f57c5e468665c602dea7effcc0e984 100644 (file)
@@ -308,15 +308,17 @@ uint32_t manchesterEncode2Bytes(uint16_t datain) {
 
 //by marshmellow
 //encode binary data into binary manchester 
 
 //by marshmellow
 //encode binary data into binary manchester 
-//NOTE: BitStream must have double the size available in memory to do the swap
+//NOTE: BitStream must have triple the size of "size" available in memory to do the swap
 int ManchesterEncode(uint8_t *BitStream, size_t size) {
 int ManchesterEncode(uint8_t *BitStream, size_t size) {
-       size_t modIdx=size, i=0;
-       if (size>modIdx) return -1;
+       //allow up to 4K out (means BitStream must be at least 2048+4096 to handle the swap)
+       size = (size>2048) ? 2048 : size;
+       size_t modIdx = size;
+       size_t i;
        for (size_t idx=0; idx < size; idx++){
                BitStream[idx+modIdx++] = BitStream[idx];
                BitStream[idx+modIdx++] = BitStream[idx]^1;
        }
        for (size_t idx=0; idx < size; idx++){
                BitStream[idx+modIdx++] = BitStream[idx];
                BitStream[idx+modIdx++] = BitStream[idx]^1;
        }
-       for (; i<(size*2); i++){
+       for (i=0; i<(size*2); i++){
                BitStream[i] = BitStream[i+size];
        }
        return i;
                BitStream[i] = BitStream[i+size];
        }
        return i;
Impressum, Datenschutz