mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-01-01 05:07:03 +08:00
cppchecker fixes
This commit is contained in:
parent
603e288c4f
commit
4620c0b21e
6 changed files with 41 additions and 46 deletions
|
@ -193,8 +193,8 @@ static uint64_t PackEmID(uint64_t original, int newCardNum) {
|
|||
buf &= ~(1 << i);
|
||||
}
|
||||
buf |= (newCardNum & 0xFFFF) << 1;
|
||||
buf |= oddparity32((buf >> 1) & 0xFFF) & 1;
|
||||
buf |= (evenparity32((buf >> 13) & 0xFFF) & 1) << 25;
|
||||
buf |= oddparity32((buf >> 1) & 0xFFF);
|
||||
buf |= (evenparity32((buf >> 13) & 0xFFF)) << 25;
|
||||
|
||||
uint32_t cardnumNew = (buf >> 1) & 0xFFFF;
|
||||
uint32_t fcNew = (buf >> 17) & 0xFF;
|
||||
|
|
|
@ -37,22 +37,21 @@ static int CmdKeriMSScramble(KeriMSScramble_t Action, uint32_t *FC, uint32_t *ID
|
|||
255, 255, 2, 255, 255, 255, 3, 255, 4, 255, 255, 255, 255, 255, 1, 255
|
||||
};
|
||||
|
||||
uint8_t CardIdx; // 0 - 31
|
||||
bool BitState;
|
||||
uint8_t card_idx; // 0 - 31
|
||||
|
||||
if (Action == Descramble) {
|
||||
*FC = 0;
|
||||
*ID = 0;
|
||||
for (CardIdx = 0; CardIdx < 32; CardIdx++) {
|
||||
for (card_idx = 0; card_idx < 32; card_idx++) {
|
||||
// Get Bit State
|
||||
BitState = (*CardID >> CardIdx) & 1;
|
||||
bool BitState = (*CardID >> card_idx) & 1;
|
||||
// Card ID
|
||||
if (CardToID[CardIdx] < 32) {
|
||||
*ID = *ID | (BitState << CardToID[CardIdx]);
|
||||
if (CardToID[card_idx] < 32) {
|
||||
*ID = *ID | (BitState << CardToID[card_idx]);
|
||||
}
|
||||
// Card FC
|
||||
if (CardToFC[CardIdx] < 32) {
|
||||
*FC = *FC | (BitState << CardToFC[CardIdx]);
|
||||
if (CardToFC[card_idx] < 32) {
|
||||
*FC = *FC | (BitState << CardToFC[card_idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,16 +59,16 @@ static int CmdKeriMSScramble(KeriMSScramble_t Action, uint32_t *FC, uint32_t *ID
|
|||
if (Action == Scramble) {
|
||||
*CardID = 0; // set to 0
|
||||
|
||||
for (CardIdx = 0; CardIdx < 32; CardIdx++) {
|
||||
for (card_idx = 0; card_idx < 32; card_idx++) {
|
||||
// Card ID
|
||||
if (CardToID[CardIdx] < 32) {
|
||||
if ((*ID & (1 << CardToID[CardIdx])) > 0)
|
||||
*CardID |= (1 << CardIdx);
|
||||
if (CardToID[card_idx] < 32) {
|
||||
if ((*ID & (1U << CardToID[card_idx])) > 0)
|
||||
*CardID |= (1U << card_idx);
|
||||
}
|
||||
// Card FC
|
||||
if (CardToFC[CardIdx] < 32) {
|
||||
if ((*FC & (1 << CardToFC[CardIdx])) > 0)
|
||||
*CardID |= (1 << CardIdx);
|
||||
if (CardToFC[card_idx] < 32) {
|
||||
if ((*FC & (1U << CardToFC[card_idx])) > 0)
|
||||
*CardID |= (1U << card_idx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,11 +82,11 @@ static int CmdKeriMSScramble(KeriMSScramble_t Action, uint32_t *FC, uint32_t *ID
|
|||
*CardID |= (1 << 3);
|
||||
|
||||
// Check/Parity Bits
|
||||
int Parity = 1;
|
||||
for (CardIdx = 4; CardIdx <= 31; CardIdx += 2) {
|
||||
Parity = Parity ^ ((*CardID >> CardIdx) & 11);
|
||||
int parity = 1;
|
||||
for (card_idx = 4; card_idx <= 31; card_idx += 2) {
|
||||
parity ^= ((*CardID >> card_idx) & 11);
|
||||
}
|
||||
*CardID = *CardID | Parity;
|
||||
*CardID = *CardID | parity;
|
||||
|
||||
// Bit 31 was fixed but not in check/parity bits
|
||||
*CardID |= 1UL << 31;
|
||||
|
|
|
@ -23,8 +23,8 @@ static bool Pack_H10301(wiegand_card_t *card, wiegand_message_t *packed, bool pr
|
|||
packed->Length = 26; // Set number of bits
|
||||
packed->Bot |= (card->CardNumber & 0xFFFF) << 1;
|
||||
packed->Bot |= (card->FacilityCode & 0xFF) << 17;
|
||||
packed->Bot |= oddparity32((packed->Bot >> 1) & 0xFFF) & 1;
|
||||
packed->Bot |= (evenparity32((packed->Bot >> 13) & 0xFFF) & 1) << 25;
|
||||
packed->Bot |= oddparity32((packed->Bot >> 1) & 0xFFF);
|
||||
packed->Bot |= (evenparity32((packed->Bot >> 13) & 0xFFF)) << 25;
|
||||
if (preamble)
|
||||
return add_HID_header(packed);
|
||||
return true;
|
||||
|
@ -38,7 +38,7 @@ static bool Unpack_H10301(wiegand_message_t *packed, wiegand_card_t *card) {
|
|||
card->FacilityCode = (packed->Bot >> 17) & 0xFF;
|
||||
card->ParityValid =
|
||||
(oddparity32((packed->Bot >> 1) & 0xFFF) == (packed->Bot & 1)) &&
|
||||
((evenparity32((packed->Bot >> 13) & 0xFFF) & 1) == ((packed->Bot >> 25) & 1));
|
||||
((evenparity32((packed->Bot >> 13) & 0xFFF)) == ((packed->Bot >> 25) & 1));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -271,8 +271,8 @@ static bool Pack_H10306(wiegand_card_t *card, wiegand_message_t *packed, bool pr
|
|||
packed->Bot |= (card->CardNumber & 0xFFFF) << 1;
|
||||
packed->Bot |= (card->FacilityCode & 0x7FFF) << 17;
|
||||
packed->Mid |= (card->FacilityCode & 0x8000) >> 15;
|
||||
packed->Mid |= (evenparity32((packed->Mid & 0x00000001) ^ (packed->Bot & 0xFFFE0000)) & 1) << 1;
|
||||
packed->Bot |= (oddparity32(packed->Bot & 0x0001FFFE) & 1);
|
||||
packed->Mid |= (evenparity32((packed->Mid & 0x00000001) ^ (packed->Bot & 0xFFFE0000))) << 1;
|
||||
packed->Bot |= (oddparity32(packed->Bot & 0x0001FFFE));
|
||||
if (preamble)
|
||||
return add_HID_header(packed);
|
||||
return true;
|
||||
|
@ -331,9 +331,9 @@ static bool Pack_C1k35s(wiegand_card_t *card, wiegand_message_t *packed, bool pr
|
|||
packed->Bot |= (card->CardNumber & 0x000FFFFF) << 1;
|
||||
packed->Bot |= (card->FacilityCode & 0x000007FF) << 21;
|
||||
packed->Mid |= (card->FacilityCode & 0x00000800) >> 11;
|
||||
packed->Mid |= (evenparity32((packed->Mid & 0x00000001) ^ (packed->Bot & 0xB6DB6DB6)) & 1) << 1;
|
||||
packed->Bot |= (oddparity32((packed->Mid & 0x00000003) ^ (packed->Bot & 0x6DB6DB6C)) & 1);
|
||||
packed->Mid |= (oddparity32((packed->Mid & 0x00000003) ^ (packed->Bot & 0xFFFFFFFF)) & 1) << 2;
|
||||
packed->Mid |= (evenparity32((packed->Mid & 0x00000001) ^ (packed->Bot & 0xB6DB6DB6))) << 1;
|
||||
packed->Bot |= (oddparity32((packed->Mid & 0x00000003) ^ (packed->Bot & 0x6DB6DB6C)));
|
||||
packed->Mid |= (oddparity32((packed->Mid & 0x00000003) ^ (packed->Bot & 0xFFFFFFFF))) << 2;
|
||||
if (preamble)
|
||||
return add_HID_header(packed);
|
||||
return true;
|
||||
|
@ -711,9 +711,9 @@ static bool Pack_C1k48s(wiegand_card_t *card, wiegand_message_t *packed, bool pr
|
|||
packed->Bot |= (card->CardNumber & 0x007FFFFF) << 1;
|
||||
packed->Bot |= (card->FacilityCode & 0x000000FF) << 24;
|
||||
packed->Mid |= (card->FacilityCode & 0x003FFF00) >> 8;
|
||||
packed->Mid |= (evenparity32((packed->Mid & 0x00001B6D) ^ (packed->Bot & 0xB6DB6DB6)) & 1) << 14;
|
||||
packed->Bot |= (oddparity32((packed->Mid & 0x000036DB) ^ (packed->Bot & 0x6DB6DB6C)) & 1);
|
||||
packed->Mid |= (oddparity32((packed->Mid & 0x00007FFF) ^ (packed->Bot & 0xFFFFFFFF)) & 1) << 15;
|
||||
packed->Mid |= (evenparity32((packed->Mid & 0x00001B6D) ^ (packed->Bot & 0xB6DB6DB6))) << 14;
|
||||
packed->Bot |= (oddparity32((packed->Mid & 0x000036DB) ^ (packed->Bot & 0x6DB6DB6C)));
|
||||
packed->Mid |= (oddparity32((packed->Mid & 0x00007FFF) ^ (packed->Bot & 0xFFFFFFFF))) << 15;
|
||||
if (preamble)
|
||||
return add_HID_header(packed);
|
||||
return true;
|
||||
|
|
|
@ -15,12 +15,12 @@
|
|||
#include "wiegand_formatutils.h"
|
||||
#include "ui.h"
|
||||
|
||||
bool get_bit_by_position(wiegand_message_t *data, uint8_t pos) {
|
||||
uint8_t get_bit_by_position(wiegand_message_t *data, uint8_t pos) {
|
||||
if (pos >= data->Length) return false;
|
||||
pos = (data->Length - pos) - 1; // invert ordering; Indexing goes from 0 to 1. Subtract 1 for weight of bit.
|
||||
bool result = false;
|
||||
uint8_t result = 0;
|
||||
if (pos > 95)
|
||||
result = false;
|
||||
result = 0;
|
||||
else if (pos > 63)
|
||||
result = (data->Top >> (pos - 64)) & 1;
|
||||
else if (pos > 31)
|
||||
|
@ -80,7 +80,7 @@ static void message_datacopy(wiegand_message_t *src, wiegand_message_t *dest) {
|
|||
uint64_t get_linear_field(wiegand_message_t *data, uint8_t firstBit, uint8_t length) {
|
||||
uint64_t result = 0;
|
||||
for (uint8_t i = 0; i < length; i++) {
|
||||
result = (result << 1) | (get_bit_by_position(data, firstBit + i));
|
||||
result = (result << 1) | get_bit_by_position(data, firstBit + i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ bool set_linear_field(wiegand_message_t *data, uint64_t value, uint8_t firstBit,
|
|||
uint64_t get_nonlinear_field(wiegand_message_t *data, uint8_t numBits, uint8_t *bits) {
|
||||
uint64_t result = 0;
|
||||
for (int i = 0; i < numBits; i++) {
|
||||
result = (result << 1) | (get_bit_by_position(data, *(bits + i)) & 1);
|
||||
result = (result << 1) | get_bit_by_position(data, *(bits + i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ typedef struct {
|
|||
bool ParityValid; // Only valid for responses
|
||||
} wiegand_card_t;
|
||||
|
||||
bool get_bit_by_position(wiegand_message_t *data, uint8_t pos);
|
||||
uint8_t get_bit_by_position(wiegand_message_t *data, uint8_t pos);
|
||||
bool set_bit_by_position(wiegand_message_t *data, bool value, uint8_t pos);
|
||||
|
||||
uint64_t get_linear_field(wiegand_message_t *data, uint8_t firstBit, uint8_t length);
|
||||
|
|
|
@ -15,18 +15,15 @@
|
|||
|
||||
extern const uint8_t OddByteParity[256];
|
||||
|
||||
|
||||
static inline bool oddparity8(const uint8_t x) {
|
||||
static inline uint8_t oddparity8(const uint8_t x) {
|
||||
return OddByteParity[x];
|
||||
}
|
||||
|
||||
|
||||
static inline bool evenparity8(const uint8_t x) {
|
||||
static inline uint8_t evenparity8(const uint8_t x) {
|
||||
return !OddByteParity[x];
|
||||
}
|
||||
|
||||
|
||||
static inline bool evenparity32(uint32_t x) {
|
||||
static inline uint8_t evenparity32(uint32_t x) {
|
||||
#if !defined __GNUC__
|
||||
x ^= x >> 16;
|
||||
x ^= x >> 8;
|
||||
|
@ -36,8 +33,7 @@ static inline bool evenparity32(uint32_t x) {
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
static inline bool oddparity32(uint32_t x) {
|
||||
static inline uint8_t oddparity32(uint32_t x) {
|
||||
#if !defined __GNUC__
|
||||
x ^= x >> 16;
|
||||
x ^= x >> 8;
|
||||
|
|
Loading…
Reference in a new issue