@@ -1688,10 +1688,12 @@ bool HIDTryUnpack(wiegand_message_t *packed) {
16881688 );
16891689 }
16901690
1691- if (packed -> Length && ((found_cnt - found_invalid_par ) == 0 )) { // if length > 0 and no valid parity matches
1692- PrintAndLogEx (FAILED , "Parity tests failed" );
1691+ if (found_cnt > 0 ){
1692+ if (packed -> Length && ((found_cnt - found_invalid_par ) == 0 )) { // if length > 0 and no valid parity matches
1693+ PrintAndLogEx (FAILED , "Parity tests failed" );
1694+ }
1695+ PrintAndLogEx (NORMAL , "" );
16931696 }
1694- PrintAndLogEx (NORMAL , "" );
16951697
16961698 return ((found_cnt - found_invalid_par ) > 0 );
16971699}
@@ -1716,8 +1718,28 @@ bool decode_wiegand(uint32_t top, uint32_t mid, uint32_t bot, int n) {
17161718 if (n > 0 ) {
17171719 wiegand_message_t packed = initialize_message_object (top , mid , bot , n );
17181720 res = HIDTryUnpack (& packed );
1721+ } else if (n < 0 ) {
1722+ PrintAndLogEx (INFO , "Brute forcing all possible lengths..." );
1723+ int scan_end = (- n )* 4 ;
1724+ int scan_start = scan_end - 3 ;
1725+
1726+ wiegand_message_t packed = initialize_message_object (top , mid , bot , scan_end );
1727+
1728+ // find the first bit set in the first nibble
1729+ for (int i = 0 ; i < 4 ; i ++ ) {
1730+ if (get_bit_by_position (& packed , i ) == 1 ) {
1731+ scan_start = scan_end - i ;
1732+ break ;
1733+ }
1734+ }
1735+
1736+ PrintAndLogEx (INFO , "Scanning from bit %d to %d..." , scan_start , scan_end );
1737+ for (int i = scan_start ; i <= scan_end ; i ++ ) {
1738+ packed .Length = i ;
1739+ res |= HIDTryUnpack (& packed );
1740+ }
17191741 } else {
1720- wiegand_message_t packed = initialize_message_object (top , mid , bot , n ); // 26-37 bits
1742+ wiegand_message_t packed = initialize_message_object (top , mid , bot , 0 ); // 26-37 bits
17211743 res = HIDTryUnpack (& packed );
17221744
17231745 PrintAndLogEx (INFO , "Trying with a preamble bit..." );
0 commit comments