]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdanalyse.c
syntax sugar
[proxmark3-svn] / client / cmdanalyse.c
index 3cb1eb71a96e33433cd8c7db3d1025ebc7769702..a8deb67fa38bd970c4428d4d9d17fb3f68ebe4b6 100644 (file)
@@ -30,9 +30,10 @@ int usage_analyse_checksum(void) {
        PrintAndLog("The bytes will be added with eachother and than limited with the applied mask");
        PrintAndLog("Finally compute ones' complement of the least significant bytes");
        PrintAndLog("");
-       PrintAndLog("Usage:  analyse chksum [h] b <bytes> m <mask>");
+       PrintAndLog("Usage:  analyse chksum [h] [v] b <bytes> m <mask>");
        PrintAndLog("Options:");
        PrintAndLog("           h          This help");
+       PrintAndLog("           v          supress header");
        PrintAndLog("           b <bytes>  bytes to calc missing XOR in a LCR");
        PrintAndLog("           m <mask>   bit mask to limit the outpuyt");
        PrintAndLog("");
@@ -87,7 +88,7 @@ static uint16_t calcSumCrumbAdd( uint8_t* bytes, uint8_t len, uint32_t mask) {
     return sum;
 }
 static uint16_t calcSumCrumbAddOnes( uint8_t* bytes, uint8_t len, uint32_t mask) {
-       return ~calcSumCrumbAdd(bytes, len, mask);
+       return (~calcSumCrumbAdd(bytes, len, mask) & mask);
 }
 static uint16_t calcSumNibbleAdd( uint8_t* bytes, uint8_t len, uint32_t mask) {
     uint8_t sum = 0;
@@ -99,7 +100,7 @@ static uint16_t calcSumNibbleAdd( uint8_t* bytes, uint8_t len, uint32_t mask) {
     return sum;
 }
 static uint16_t calcSumNibbleAddOnes( uint8_t* bytes, uint8_t len, uint32_t mask){
-       return ~calcSumNibbleAdd(bytes, len, mask);
+       return (~calcSumNibbleAdd(bytes, len, mask) & mask);
 }
 static uint16_t calcSumCrumbXor(  uint8_t* bytes, uint8_t len, uint32_t mask) {
     uint8_t sum = 0;
@@ -137,7 +138,7 @@ static uint16_t calcSumByteAdd( uint8_t* bytes, uint8_t len, uint32_t mask) {
 }
 // Ones complement
 static uint16_t calcSumByteAddOnes( uint8_t* bytes, uint8_t len, uint32_t mask) {
-       return ~calcSumByteAdd(bytes, len, mask);
+       return (~calcSumByteAdd(bytes, len, mask) & mask);
 }
 
 static uint16_t calcSumByteSub( uint8_t* bytes, uint8_t len, uint32_t mask) {
@@ -148,7 +149,7 @@ static uint16_t calcSumByteSub( uint8_t* bytes, uint8_t len, uint32_t mask) {
     return sum;
 }
 static uint16_t calcSumByteSubOnes( uint8_t* bytes, uint8_t len, uint32_t mask){
-       return ~calcSumByteSub(bytes, len, mask);
+       return (~calcSumByteSub(bytes, len, mask) & mask);
 }
 static uint16_t calcSumNibbleSub( uint8_t* bytes, uint8_t len, uint32_t mask) {
     uint8_t sum = 0;
@@ -160,7 +161,7 @@ static uint16_t calcSumNibbleSub( uint8_t* bytes, uint8_t len, uint32_t mask) {
     return sum;
 }
 static uint16_t calcSumNibbleSubOnes( uint8_t* bytes, uint8_t len, uint32_t mask) {
-       return ~calcSumNibbleSub(bytes, len, mask);
+       return (~calcSumNibbleSub(bytes, len, mask) & mask);
 }
 
 // BSD shift checksum 8bit version
@@ -189,8 +190,6 @@ static uint16_t calcBSDchecksum4( uint8_t* bytes, uint8_t len, uint32_t mask){
        return sum;
 }
 
-
-
 // measuring LFSR maximum length
 int CmdAnalyseLfsr(const char *Cmd){
 
@@ -324,10 +323,10 @@ int CmdAnalyseCHKSUM(const char *Cmd){
        
        if (useHeader) {
                PrintAndLog("     add          | sub         | add 1's compl    | sub 1's compl   | xor");
-               PrintAndLog("byte nibble crumb | byte nibble | byte nibble cumb | byte nibble     | byte nibble cumb |  BSD");
+               PrintAndLog("byte nibble crumb | byte nibble | byte nibble cumb | byte nibble     | byte nibble cumb |  BSD       |");
                PrintAndLog("------------------+-------------+------------------+-----------------+--------------------");
        }
-       PrintAndLog("0x%X 0x%X   0x%X  | 0x%X 0x%X   | 0x%X 0x%X   0x%X | 0x%X 0x%X       | 0x%X 0x%X   0x%X  | 0x%X  0x%X\n",  
+       PrintAndLog("0x%X 0x%X   0x%X  | 0x%X 0x%X   | 0x%X 0x%X   0x%X | 0x%X 0x%X       | 0x%X 0x%X   0x%X  | 0x%X  0x%X |\n",        
                                  calcSumByteAdd(data, len, mask)
                                , calcSumNibbleAdd(data, len, mask)
                                , calcSumCrumbAdd(data, len, mask)
@@ -342,7 +341,7 @@ int CmdAnalyseCHKSUM(const char *Cmd){
                                , calcSumNibbleXor(data, len, mask)
                                , calcSumCrumbXor(data, len, mask)
                                , calcBSDchecksum8(data, len, mask)
-                               , calcBSDchecksum4(data, len, mask)                             
+                               , calcBSDchecksum4(data, len, mask)
                        );      
        return 0;
 }
Impressum, Datenschutz