Fixed - search in inverted bitsteam as well

This commit is contained in:
Philippe Teuwen 2022-05-03 15:18:05 +02:00
commit cc7054fc9b
2 changed files with 42 additions and 18 deletions

View file

@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
## [unreleased][unreleased] ## [unreleased][unreleased]
- Fixed `lf viking reader` - search in inverted bitsteam as well (#doegox)
- Added more default keys (@CONIGUERO) - Added more default keys (@CONIGUERO)
- Change `hf 14a info` - it now detects FUDAN (@iceman1001) Thanks to @secit-pl - Change `hf 14a info` - it now detects FUDAN (@iceman1001) Thanks to @secit-pl
- Fixed support to clone Pyramic, Paradox and Awid on EM4x05 (@doegox) - Fixed support to clone Pyramic, Paradox and Awid on EM4x05 (@doegox)

View file

@ -266,28 +266,51 @@ uint64_t getVikingBits(uint32_t id) {
return ret; return ret;
} }
static bool isValidVikingChecksum(uint8_t *src) {
uint32_t checkCalc = bytebits_to_byte(src, 8) ^
bytebits_to_byte(src + 8, 8) ^
bytebits_to_byte(src + 16, 8) ^
bytebits_to_byte(src + 24, 8) ^
bytebits_to_byte(src + 32, 8) ^
bytebits_to_byte(src + 40, 8) ^
bytebits_to_byte(src + 48, 8) ^
bytebits_to_byte(src + 56, 8) ^
0xA8;
return checkCalc == 0;
}
// find viking preamble 0xF200 in already demoded data // find viking preamble 0xF200 in already demoded data
int detectViking(uint8_t *src, size_t *size) { int detectViking(uint8_t *src, size_t *size) {
//make sure buffer has data //make sure buffer has data
if (*size < 64) return -2; if (*size < 64) return -2;
size_t tsize = *size;
size_t startIdx = 0; size_t startIdx = 0;
bool preamblefound = false;
uint8_t preamble[] = {1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t preamble[] = {1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
if (!preambleSearch(src, preamble, sizeof(preamble), size, &startIdx)) if (preambleSearch(src, preamble, sizeof(preamble), size, &startIdx)) {
return -4; //preamble not found preamblefound = true;
uint32_t checkCalc = bytebits_to_byte(src + startIdx, 8) ^
bytebits_to_byte(src + startIdx + 8, 8) ^
bytebits_to_byte(src + startIdx + 16, 8) ^
bytebits_to_byte(src + startIdx + 24, 8) ^
bytebits_to_byte(src + startIdx + 32, 8) ^
bytebits_to_byte(src + startIdx + 40, 8) ^
bytebits_to_byte(src + startIdx + 48, 8) ^
bytebits_to_byte(src + startIdx + 56, 8);
if (checkCalc != 0xA8) return -5;
if (*size != 64) return -6; if (*size != 64) return -6;
if (isValidVikingChecksum(src + startIdx)) {
//return start position //return start position
return (int)startIdx; return (int)startIdx;
} }
}
// Invert bits and try again
*size = tsize;
for (uint32_t i = 0; i < *size; i++) src[i] ^= 1;
if (preambleSearch(src, preamble, sizeof(preamble), size, &startIdx)) {
preamblefound = true;
if (*size != 64) return -6;
if (isValidVikingChecksum(src + startIdx)) {
//return start position
return (int)startIdx;
}
}
// Restore buffer
*size = tsize;
for (uint32_t i = 0; i < *size; i++) src[i] ^= 1;
if (preamblefound)
return -5;
else
return -4;
}