From f2492bdf904705c9d2f184de3d4b0b35001c253c Mon Sep 17 00:00:00 2001 From: Alex Stanev Date: Fri, 17 May 2024 20:04:44 +0300 Subject: [PATCH 1/7] Refactor isasciistring() --- include/strings.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/strings.c b/include/strings.c index 6fea9aadd..16b499601 100644 --- a/include/strings.c +++ b/include/strings.c @@ -14,13 +14,14 @@ for(p = 0; p < len; p++) return true; } /*===========================================================================*/ -bool isasciistring(int len, uint8_t *buffer) +bool isasciistring(size_t len, uint8_t *buffer) { -uint8_t p; -for(p = 0; p < len; p++) +size_t i; + +for(i = 0; i < len; i++) { - if(buffer[p] == 0) return true; - if((buffer[p] < 0x20) || (buffer[p] == 0x7f)) return false; + if(buffer[i] == 0) return true; + if((buffer[i] < 0x20) || (buffer[i] == 0x7f)) return false; } return true; } From bbdd5303a10cedaa2e98a4ed67c1495da0d5265d Mon Sep 17 00:00:00 2001 From: Alex Stanev Date: Fri, 17 May 2024 20:06:58 +0300 Subject: [PATCH 2/7] Refactor ispotfilestring() --- include/strings.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/strings.c b/include/strings.c index 16b499601..7160de66e 100644 --- a/include/strings.c +++ b/include/strings.c @@ -4,12 +4,13 @@ #include /*===========================================================================*/ -bool ispotfilestring(int len, char *buffer) +bool ispotfilestring(size_t len, char *buffer) { -uint8_t p; -for(p = 0; p < len; p++) +size_t i; + +for(i = 0; i < len; i++) { - if((buffer[p] < 0x20) || (buffer[p] > 0x7e) || (buffer[p] == ':')) return false; + if((buffer[i] < 0x20) || (buffer[i] > 0x7e) || (buffer[i] == ':')) return false; } return true; } From 89ec9f44a5461642c5e9303760d2028b98afcb99 Mon Sep 17 00:00:00 2001 From: Alex Stanev Date: Fri, 17 May 2024 20:10:30 +0300 Subject: [PATCH 3/7] Refactor ishexvalue() --- include/strings.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/include/strings.c b/include/strings.c index 7160de66e..6b9bc0ad2 100644 --- a/include/strings.c +++ b/include/strings.c @@ -29,14 +29,11 @@ return true; /*===========================================================================*/ bool ishexvalue(const char *str, size_t len) { -size_t c; +size_t i; -for(c = 0; c < len; c++) +for(i = 0; i < len; i++) { - if(str[c] < '0') return false; - if(str[c] > 'f') return false; - if((str[c] > '9') && (str[c] < 'A')) return false; - if((str[c] > 'F') && (str[c] < 'a')) return false; + if(!isxdigit(str[i])) return false; } return true; } From 3cbacb5759b621e07366fb2d2803e8873a8d2e69 Mon Sep 17 00:00:00 2001 From: Alex Stanev Date: Sun, 19 May 2024 21:52:56 +0300 Subject: [PATCH 4/7] Refactor ishexify() --- include/strings.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/include/strings.c b/include/strings.c index 6b9bc0ad2..639216f4b 100644 --- a/include/strings.c +++ b/include/strings.c @@ -72,14 +72,10 @@ size_t ishexify(const char *string) size_t len; len = strlen(string); -if (len < 6) return 0; -if ((len &1) == 1) return 0; -if (string[0] != '$') return 0; -if (string[1] != 'H') return 0; -if (string[2] != 'E') return 0; -if (string[3] != 'X') return 0; -if (string[4] != '[') return 0; -if (string[len -1] != ']') return 0; +if (len < 6) return -1; +if (strncmp("$HEX[", string, 5)) return -1; +if (string[len -1] != ']') return -1; +if ((len &1) == 1) return -1; return (len -6)/2; } /*===========================================================================*/ From d18208583bb2c06aa964d76322ca33cd97d1ca9f Mon Sep 17 00:00:00 2001 From: Alex Stanev Date: Sun, 19 May 2024 22:57:00 +0300 Subject: [PATCH 5/7] Finish refactor hex2bin() --- hcxhash2cap.c | 8 +++--- hcxpmktool.c | 68 +++++++++++------------------------------------ hcxpsktool.c | 12 ++++----- include/strings.c | 10 +++---- whoismac.c | 4 +-- 5 files changed, 33 insertions(+), 69 deletions(-) diff --git a/hcxhash2cap.c b/hcxhash2cap.c index 3f36b3b5c..d232253ad 100644 --- a/hcxhash2cap.c +++ b/hcxhash2cap.c @@ -806,25 +806,25 @@ while(1) pmkcapskipped++; continue; } - if(hex2bin(&linein[0], pmkid, 16) != true) + if(hex2bin(&linein[0], pmkid, 16) == -1) { fprintf(stderr, "reading hash line %d failed: %s\n", aktread, linein); pmkcapskipped++; continue; } - if(hex2bin(&linein[33], macap, 6) != true) + if(hex2bin(&linein[33], macap, 6) == -1) { fprintf(stderr, "reading hash line %d failed: %s\n", aktread, linein); pmkcapskipped++; continue; } - if(hex2bin(&linein[46], macsta, 6) != true) + if(hex2bin(&linein[46], macsta, 6) == -1) { fprintf(stderr, "reading hash line %d failed: %s\n", aktread, linein); pmkcapskipped++; continue; } - if(hex2bin(&linein[59], essid, essidlen/2) != true) + if(hex2bin(&linein[59], essid, essidlen/2) == -1) { fprintf(stderr, "reading hash line %d failed: %s\n", aktread, linein); pmkcapskipped++; diff --git a/hcxpmktool.c b/hcxpmktool.c index b8ca172a3..ab6d5bfb1 100644 --- a/hcxpmktool.c +++ b/hcxpmktool.c @@ -47,7 +47,7 @@ static uint8_t miccalculated[128]; static int psklen; static char *pskstring; -static size_t essidlen; +static ssize_t essidlen; static uint8_t essid[34]; static uint8_t macap[8]; static uint8_t macclient[8]; @@ -290,45 +290,11 @@ status |= HAS_PMK_CALC; return true; } /*===========================================================================*/ -static size_t hex2bin2(const char *str, uint8_t *bytes, size_t blen) -{ -size_t pos; -uint8_t idx0; -uint8_t idx1; - -uint8_t hashmap[] = -{ -0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // 01234567 -0x08, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 89:;<=>? -0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, // @ABCDEFG -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // HIJKLMNO -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // PQRSTUVW -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // XYZ[\]^_ -0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, // `abcdefg -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // hijklmno -}; - -if(ishexvalue(str, blen) == false) return 0; -memset(bytes, 0, blen); -pos = 0; -while(str[pos+0] != 0) - { - idx0 = ((uint8_t)str[pos+0] & 0x1F) ^ 0x10; - idx1 = ((uint8_t)str[pos+1] & 0x1F) ^ 0x10; - bytes[pos/2] = (uint8_t)(hashmap[idx0] << 4) | hashmap[idx1]; - pos += 2; - if(str[pos+0] == '*') return pos/2; - if(pos/2 > blen) return 0; - }; -if((pos %2) != 0) return 0; -return pos/2; -} -/*===========================================================================*/ static bool parsehashlinestring(char *hashlinestring) { static size_t hlen; static size_t plen; -static size_t flen; +static ssize_t flen; static const char *wpa1 = "WPA*01*"; static const char *wpa2 = "WPA*02*"; @@ -338,21 +304,20 @@ if(hlen < 71) return false; plen = 7; if(memcmp(wpa1, hashlinestring, 7) == 0) { - flen = hex2bin2(&hashlinestring[plen], pmkid, 16); + flen = hex2bin(&hashlinestring[plen], pmkid, 16); if(flen != 16) return false; plen += flen *2; if(hashlinestring[plen++] != '*') return false; - flen = hex2bin2(&hashlinestring[plen], macap, 6); + flen = hex2bin(&hashlinestring[plen], macap, 6); if(flen != 6) return false; plen += flen *2; if(hashlinestring[plen++] != '*') return false; - flen = hex2bin2(&hashlinestring[plen], macclient, 6); + flen = hex2bin(&hashlinestring[plen], macclient, 6); if(flen != 6) return false; plen += flen *2; if(hashlinestring[plen++] != '*') return false; - essidlen = 0; - essidlen = hex2bin2(&hashlinestring[plen], essid, 34); - if((essidlen == 0) || (essidlen > 32)) return false; + essidlen = hex2bin(&hashlinestring[plen], essid, 34); + if((essidlen <= 0) || (essidlen > 32)) return false; plen += essidlen *2; if(hashlinestring[plen++] != '*') return false; status |= HAS_PMKID_LINE; @@ -364,28 +329,27 @@ if(memcmp(wpa1, hashlinestring, 7) == 0) } if(memcmp(wpa2, hashlinestring, 7) == 0) { - flen = hex2bin2(&hashlinestring[plen], mic, 16); + flen = hex2bin(&hashlinestring[plen], mic, 16); if(flen != 16) return false; plen += flen *2; if(hashlinestring[plen++] != '*') return false; - flen = hex2bin2(&hashlinestring[plen], macap, 6); + flen = hex2bin(&hashlinestring[plen], macap, 6); if(flen != 6) return false; plen += flen *2; if(hashlinestring[plen++] != '*') return false; - flen = hex2bin2(&hashlinestring[plen], macclient, 6); + flen = hex2bin(&hashlinestring[plen], macclient, 6); if(flen != 6) return false; plen += flen *2; if(hashlinestring[plen++] != '*') return false; - essidlen = 0; - essidlen = hex2bin2(&hashlinestring[plen], essid, 34); - if((essidlen == 0) || (essidlen > 32)) return false; + essidlen = hex2bin(&hashlinestring[plen], essid, 34); + if((essidlen <= 0) || (essidlen > 32)) return false; plen += essidlen *2; if(hashlinestring[plen++] != '*') return false; - flen = hex2bin2(&hashlinestring[plen], anonce, 32); + flen = hex2bin(&hashlinestring[plen], anonce, 32); + if(flen == -1) return false; plen += flen *2; if(hashlinestring[plen++] != '*') return false; - eapollen = 0; - eapollen = hex2bin2(&hashlinestring[plen], eapol, 1024); + eapollen = hex2bin(&hashlinestring[plen], eapol, 1024); eapptr = (eapauth_t*)eapol; eapauthlen = ntohs(eapptr->len); if(eapollen < eapauthlen +4) return false; @@ -588,7 +552,7 @@ if(pskstring != NULL) } else if(psklen == 64) { - if(hex2bin2(pskstring, pmkcalculated, 32) != 32) + if(hex2bin(pskstring, pmkcalculated, 32) != 32) { fprintf(stderr, "\nPMK error\n"); return EXIT_FAILURE; diff --git a/hcxpsktool.c b/hcxpsktool.c index 59cb712a8..f35a02c4d 100644 --- a/hcxpsktool.c +++ b/hcxpsktool.c @@ -2540,7 +2540,7 @@ static void readpmkidfile(char *pmkidname) { static int len; static int aktread = 1; -static int essidlen; +static ssize_t essidlen; static char *macaddrstop = NULL; static unsigned long long int macaddr; static FILE *fh_file; @@ -2583,7 +2583,7 @@ while(1) aktread++; continue; } - if(hex2bin(&linein[59], essid, essidlen/2) == true) addapessid(macaddr, essidlen/2, essid); + if(hex2bin(&linein[59], essid, essidlen/2) != -1) addapessid(macaddr, essidlen/2, essid); aktread++; } fclose(fh_file); @@ -2594,7 +2594,7 @@ static void readpmkideapolfile(char *pmkideapolname) { static int len; static int aktread = 1; -static int essidlen; +static ssize_t essidlen; static char *macaddrstop = NULL; static char *essidstop = NULL; static unsigned long long int macaddr; @@ -2653,7 +2653,7 @@ while(1) aktread++; continue; } - if(hex2bin(&linein[66], essid, essidlen/2) == true) addapessid(macaddr, essidlen/2, essid); + if(hex2bin(&linein[66], essid, essidlen/2) != -1) addapessid(macaddr, essidlen/2, essid); aktread++; } fclose(fh_file); @@ -2791,7 +2791,7 @@ return; static void readcommandline(char *macapname, char *essidname) { static int essidlen = 0; -static int essidlenuh = 0; +static ssize_t essidlenuh = 0; static char *macaddrstop = NULL; static unsigned long long int macaddr = 0xffffffffffffL; static uint8_t essid[ESSID_LEN_MAX]; @@ -2808,7 +2808,7 @@ if(essidname != NULL) essidlenuh = ishexify(essidname); if((essidlenuh > 0) && (essidlenuh <= ESSID_LEN_MAX)) { - if(hex2bin(&essidname[5], essid, essidlenuh) == true) addapessid(macaddr, essidlenuh, essid); + if(hex2bin(&essidname[5], essid, essidlenuh) != -1) addapessid(macaddr, essidlenuh, essid); return; } memset(&essid, 0, ESSID_LEN_MAX); diff --git a/include/strings.c b/include/strings.c index 639216f4b..4117566c9 100644 --- a/include/strings.c +++ b/include/strings.c @@ -38,13 +38,13 @@ for(i = 0; i < len; i++) return true; } /*===========================================================================*/ -bool hex2bin(const char *str, uint8_t *bytes, size_t blen) +ssize_t hex2bin(const char *str, uint8_t *bytes, size_t blen) { uint8_t pos; uint8_t idx0; uint8_t idx1; -uint8_t hashmap[] = +const uint8_t hashmap[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // 01234567 0x08, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 89:;<=>? @@ -56,7 +56,7 @@ uint8_t hashmap[] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // hijklmno }; -if(ishexvalue(str, blen) == false) return false; +if(ishexvalue(str, blen) == false) return -1; memset(bytes, 0, blen); for (pos = 0; ((pos < (blen*2)) && (pos < strlen(str))); pos += 2) { @@ -64,10 +64,10 @@ for (pos = 0; ((pos < (blen*2)) && (pos < strlen(str))); pos += 2) idx1 = ((uint8_t)str[pos+1] & 0x1F) ^ 0x10; bytes[pos/2] = (uint8_t)(hashmap[idx0] << 4) | hashmap[idx1]; }; -return true; +return pos/2; } /*===========================================================================*/ -size_t ishexify(const char *string) +ssize_t ishexify(const char *string) { size_t len; diff --git a/whoismac.c b/whoismac.c index 9dccf4326..7cfc60c4d 100644 --- a/whoismac.c +++ b/whoismac.c @@ -91,7 +91,7 @@ for(p = 0; p < l; p++) } memset(&essidbuffer, 0, 66); -if(hex2bin(essidname, essidbuffer, l /2) == false) +if(hex2bin(essidname, essidbuffer, l /2) == -1) { fprintf(stderr, "not a valid ESSID hex string\n"); return; @@ -155,7 +155,7 @@ if((l%2 != 0) || (l > 64)) return; } memset(&essidbuffer, 0, 66); -if(hex2bin(essidptr, essidbuffer, l /2) == false) +if(hex2bin(essidptr, essidbuffer, l /2) == -1) { fprintf(stderr, "wrong ESSID %s\n", essidptr); return; From 3b38aafae897eda989b1545a961cc51deda9f3a7 Mon Sep 17 00:00:00 2001 From: Alex Stanev Date: Sun, 19 May 2024 23:42:03 +0300 Subject: [PATCH 6/7] Call memcmp() once per compare values during sort --- include/hcxhashtool.h | 42 ++++++++----- include/hcxpcapngtool.h | 130 +++++++++++++++++++++++++--------------- include/hcxpsktool.h | 14 +++-- 3 files changed, 119 insertions(+), 67 deletions(-) diff --git a/include/hcxhashtool.h b/include/hcxhashtool.h index 8b257ab5a..3243b900d 100644 --- a/include/hcxhashtool.h +++ b/include/hcxhashtool.h @@ -92,9 +92,11 @@ static int sort_hashlist_by_essid(const void *a, const void *b) { const hashlist_t *ia = (const hashlist_t *)a; const hashlist_t *ib = (const hashlist_t *)b; +int cmp; -if(memcmp(ia->essid, ib->essid, ESSID_LEN_MAX) > 0) return 1; -else if(memcmp(ia->essid, ib->essid, ESSID_LEN_MAX) < 0) return -1; +cmp = memcmp(ia->essid, ib->essid, ESSID_LEN_MAX); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; return 0; } @@ -102,11 +104,13 @@ static int sort_hashlist_by_essidlen(const void *a, const void *b) { const hashlist_t *ia = (const hashlist_t *)a; const hashlist_t *ib = (const hashlist_t *)b; +int cmp; if(ia->essidlen > ib->essidlen) return 1; else if(ia->essidlen < ib->essidlen) return -1; -if(memcmp(ia->essid, ib->essid, ia->essidlen) > 0) return 1; -else if(memcmp(ia->essid, ib->essid, ia->essidlen) < 0) return -1; +cmp = memcmp(ia->essid, ib->essid, ia->essidlen); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; return 0; } @@ -114,9 +118,11 @@ static int sort_hashlist_by_macap(const void *a, const void *b) { const hashlist_t *ia = (const hashlist_t *)a; const hashlist_t *ib = (const hashlist_t *)b; +int cmp; -if(memcmp(ia->ap, ib->ap, 6) > 0) return 1; -else if(memcmp(ia->ap, ib->ap, 6) < 0) return -1; +cmp = memcmp(ia->ap, ib->ap, 6); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; return 0; } @@ -124,9 +130,11 @@ static int sort_hashlist_by_macclient(const void *a, const void *b) { const hashlist_t *ia = (const hashlist_t *)a; const hashlist_t *ib = (const hashlist_t *)b; +int cmp; -if(memcmp(ia->client, ib->client, 6) > 0) return 1; -else if(memcmp(ia->client, ib->client, 6) < 0) return -1; +cmp = memcmp(ia->client, ib->client, 6); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; return 0; } @@ -156,9 +164,11 @@ static int sort_ouilist_by_oui(const void *a, const void *b) { const ouilist_t *ia = (const ouilist_t *)a; const ouilist_t *ib = (const ouilist_t *)b; +int cmp; -if(memcmp(ia->oui, ib->oui, 3) > 0) return 1; -else if(memcmp(ia->oui, ib->oui, 3) < 0) return -1; +cmp = memcmp(ia->oui, ib->oui, 3); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; return 0; } /*===========================================================================*/ @@ -174,11 +184,13 @@ static int sort_essidlistin(const void *a, const void *b) { const essidlist_t *ia = (const essidlist_t *)a; const essidlist_t *ib = (const essidlist_t *)b; +int cmp; if(ia->essidlen > ib->essidlen) return 1; else if(ia->essidlen < ib->essidlen) return -1; -if(memcmp(ia->essid, ib->essid, ia->essidlen) > 0) return 1; -else if(memcmp(ia->essid, ib->essid, ia->essidlen) < 0) return -1; +cmp = memcmp(ia->essid, ib->essid, ia->essidlen); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; return 0; } /*===========================================================================*/ @@ -193,9 +205,11 @@ static int sort_maclistin(const void *a, const void *b) { const maclist_t *ia = (const maclist_t *)a; const maclist_t *ib = (const maclist_t *)b; +int cmp; -if(memcmp(ia->mac, ib->mac, 6) > 0) return 1; -else if(memcmp(ia->mac, ib->mac, 6) < 0) return -1; +cmp = memcmp(ia->mac, ib->mac, 6); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; return 0; } /*===========================================================================*/ diff --git a/include/hcxpcapngtool.h b/include/hcxpcapngtool.h index b6638f2c2..d588e4874 100644 --- a/include/hcxpcapngtool.h +++ b/include/hcxpcapngtool.h @@ -191,12 +191,16 @@ static int sort_maclist_by_mac(const void *a, const void *b) { const maclist_t *ia = (const maclist_t *)a; const maclist_t *ib = (const maclist_t *)b; -if(memcmp(ia->addr, ib->addr, 6) > 0) return 1; -else if(memcmp(ia->addr, ib->addr, 6) < 0) return -1; +int cmp; + +cmp = memcmp(ia->addr, ib->addr, 6); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; if(ia->essidlen < ib->essidlen) return 1; else if(ia->essidlen > ib->essidlen) return -1; -if(memcmp(ia->essid, ib->essid, ib->essidlen) < 0) return 1; -else if(memcmp(ia->essid, ib->essid, ib->essidlen) > 0) return -1; +cmp = memcmp(ia->essid, ib->essid, ib->essidlen); +if(cmp < 0) return 1; +else if(cmp > 0) return -1; return 0; } @@ -204,14 +208,18 @@ static int sort_maclist_by_mac_count(const void *a, const void *b) { const maclist_t *ia = (const maclist_t *)a; const maclist_t *ib = (const maclist_t *)b; -if(memcmp(ia->addr, ib->addr, 6) > 0) return 1; -else if(memcmp(ia->addr, ib->addr, 6) < 0) return -1; +int cmp; + +cmp = memcmp(ia->addr, ib->addr, 6); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; if(ia->count < ib->count) return 1; else if(ia->count > ib->count) return -1; if(ia->essidlen < ib->essidlen) return 1; else if(ia->essidlen > ib->essidlen) return -1; -if(memcmp(ia->essid, ib->essid, ib->essidlen) < 0) return 1; -else if(memcmp(ia->essid, ib->essid, ib->essidlen) > 0) return -1; +cmp = memcmp(ia->essid, ib->essid, ib->essidlen); +if(cmp < 0) return 1; +else if(cmp > 0) return -1; return 0; } @@ -219,9 +227,11 @@ static int sort_maclist_by_essidlen(const void *a, const void *b) { const maclist_t *ia = (const maclist_t *)a; const maclist_t *ib = (const maclist_t *)b; +int cmp; -if(memcmp(ia->essid, ib->essid, ib->essidlen) > 0) return 1; -else if(memcmp(ia->essid, ib->essid, ib->essidlen) < 0) return -1; +cmp = memcmp(ia->essid, ib->essid, ib->essidlen); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; if(ia->essidlen > ib->essidlen) return 1; else if(ia->essidlen < ib->essidlen) return -1; return 0; @@ -231,13 +241,16 @@ static int sort_maclist_by_manufacturer(const void *a, const void *b) { const maclist_t *ia = (const maclist_t *)a; const maclist_t *ib = (const maclist_t *)b; +int cmp; -if(memcmp(ia->manufacturer, ib->manufacturer, ib->manufacturerlen) > 0) return 1; -else if(memcmp(ia->manufacturer, ib->manufacturer, ib->manufacturerlen) < 0) return -1; +cmp = memcmp(ia->manufacturer, ib->manufacturer, ib->manufacturerlen); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; if(ia->manufacturerlen > ib->manufacturerlen) return 1; else if(ia->manufacturerlen < ib->manufacturerlen) return -1; -if(memcmp(ia->addr, ib->addr, 6) > 0) return 1; -else if(memcmp(ia->addr, ib->addr, 6) < 0) return -1; +cmp = memcmp(ia->addr, ib->addr, 6); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; return 0; } /*===========================================================================*/ @@ -307,11 +320,14 @@ static int sort_handshakelist_by_timegap(const void *a, const void *b) { const handshakelist_t *ia = (const handshakelist_t *)a; const handshakelist_t *ib = (const handshakelist_t *)b; - -if(memcmp(ia->ap, ib->ap, 6) > 0) return 1; -else if(memcmp(ia->ap, ib->ap, 6) < 0) return -1; -if(memcmp(ia->client, ib->client, 6) > 0) return 1; -else if(memcmp(ia->client, ib->client, 6) < 0) return -1; +int cmp; + +cmp = memcmp(ia->ap, ib->ap, 6); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; +cmp = memcmp(ia->client, ib->client, 6); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; if(ia->timestampgap > ib->timestampgap) return 1; else if(ia->timestampgap < ib->timestampgap) return -1; if(ia->rcgap > ib->rcgap) return 1; @@ -325,11 +341,14 @@ static int sort_handshakelist_by_rcgap(const void *a, const void *b) { const handshakelist_t *ia = (const handshakelist_t *)a; const handshakelist_t *ib = (const handshakelist_t *)b; - -if(memcmp(ia->ap, ib->ap, 6) > 0) return 1; -else if(memcmp(ia->ap, ib->ap, 6) < 0) return -1; -if(memcmp(ia->client, ib->client, 6) > 0) return 1; -else if(memcmp(ia->client, ib->client, 6) < 0) return -1; +int cmp; + +cmp = memcmp(ia->ap, ib->ap, 6); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; +cmp = memcmp(ia->client, ib->client, 6); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; if(ia->rcgap > ib->rcgap) return 1; else if(ia->rcgap < ib->rcgap) return -1; if(ia->timestampgap > ib->timestampgap) return 1; @@ -357,13 +376,17 @@ static int sort_pmkidlist_by_mac(const void *a, const void *b) { const pmkidlist_t *ia = (const pmkidlist_t *)a; const pmkidlist_t *ib = (const pmkidlist_t *)b; - -if(memcmp(ia->ap, ib->ap, 6) > 0) return 1; -else if(memcmp(ia->ap, ib->ap, 6) < 0) return -1; -if(memcmp(ia->client, ib->client, 6) > 0) return 1; -else if(memcmp(ia->client, ib->client, 6) < 0) return -1; -if(memcmp(ia->pmkid, ib->pmkid, 6) < 0) return 1; -else if(memcmp(ia->pmkid, ib->pmkid, 6) > 0) return -1; +int cmp; + +cmp = memcmp(ia->ap, ib->ap, 6); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; +cmp = memcmp(ia->client, ib->client, 6); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; +cmp = memcmp(ia->pmkid, ib->pmkid, 6); +if(cmp < 0) return 1; +else if(cmp > 0) return -1; return 0; } /*===========================================================================*/ @@ -402,13 +425,16 @@ static int sort_eapmd5hashlist_by_id(const void *a, const void *b) { const eapmd5hashlist_t *ia = (const eapmd5hashlist_t *)a; const eapmd5hashlist_t *ib = (const eapmd5hashlist_t *)b; +int cmp; if(ia->id < ib->id) return 1; else if(ia->id > ib->id) return -1; -if(memcmp(ia->md5request, ib->md5request, EAPMD5_LEN_MAX) > 0) return 1; -else if(memcmp(ia->md5request, ib->md5request, EAPMD5_LEN_MAX) < 0) return -1; -if(memcmp(ia->md5response, ib->md5request, EAPMD5_LEN_MAX) > 0) return 1; -else if(memcmp(ia->md5response, ib->md5response, EAPMD5_LEN_MAX) < 0) return -1; +cmp = memcmp(ia->md5request, ib->md5request, EAPMD5_LEN_MAX); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; +cmp = memcmp(ia->md5response, ib->md5response, EAPMD5_LEN_MAX); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; return 0; } /*===========================================================================*/ @@ -452,18 +478,21 @@ static int sort_eapleaphashlist_by_id(const void *a, const void *b) { const eapleaphashlist_t *ia = (const eapleaphashlist_t *)a; const eapleaphashlist_t *ib = (const eapleaphashlist_t *)b; +int cmp; if(ia->id < ib->id) return 1; else if(ia->id > ib->id) return -1; if(ia->leapusernamelen > ib->leapusernamelen) return 1; if(ia->leapusernamelen < ib->leapusernamelen) return -1; -if(memcmp(ia->leaprequest, ib->leaprequest, LEAPREQ_LEN_MAX) > 0) return 1; -else if(memcmp(ia->leaprequest, ib->leaprequest, LEAPREQ_LEN_MAX) < 0) return -1; -if(memcmp(ia->leapresponse, ib->leapresponse, LEAPRESP_LEN_MAX) > 0) return 1; -else if(memcmp(ia->leapresponse, ib->leapresponse, LEAPRESP_LEN_MAX) < 0) return -1; -else if(memcmp(ia->leapusername, ib->leapusername, ia->leapusernamelen) < 0) return -1; -if(memcmp(ia->leapusername, ib->leapusername, ia->leapusernamelen) > 0) return 1; -else if(memcmp(ia->leapusername, ib->leapusername, ia->leapusernamelen) < 0) return -1; +cmp = memcmp(ia->leaprequest, ib->leaprequest, LEAPREQ_LEN_MAX); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; +cmp = memcmp(ia->leapresponse, ib->leapresponse, LEAPRESP_LEN_MAX); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; +cmp = memcmp(ia->leapusername, ib->leapusername, ia->leapusernamelen); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; return 0; } /*===========================================================================*/ @@ -507,18 +536,21 @@ static int sort_eapmschapv2hashlist_by_id(const void *a, const void *b) { const eapmschapv2hashlist_t *ia = (const eapmschapv2hashlist_t *)a; const eapmschapv2hashlist_t *ib = (const eapmschapv2hashlist_t *)b; +int cmp; if(ia->id < ib->id) return 1; else if(ia->id > ib->id) return -1; if(ia->mschapv2usernamelen > ib->mschapv2usernamelen) return 1; if(ia->mschapv2usernamelen < ib->mschapv2usernamelen) return -1; -if(memcmp(ia->mschapv2request, ib->mschapv2request, MSCHAPV2REQ_LEN_MAX) > 0) return 1; -else if(memcmp(ia->mschapv2request, ib->mschapv2request, MSCHAPV2REQ_LEN_MAX) < 0) return -1; -if(memcmp(ia->mschapv2response, ib->mschapv2response, MSCHAPV2RESP_LEN_MAX) > 0) return 1; -else if(memcmp(ia->mschapv2response, ib->mschapv2response, MSCHAPV2RESP_LEN_MAX) < 0) return -1; -else if(memcmp(ia->mschapv2username, ib->mschapv2username, ia->mschapv2usernamelen) < 0) return -1; -if(memcmp(ia->mschapv2username, ib->mschapv2username, ia->mschapv2usernamelen) > 0) return 1; -else if(memcmp(ia->mschapv2username, ib->mschapv2username, ia->mschapv2usernamelen) < 0) return -1; +cmp = memcmp(ia->mschapv2request, ib->mschapv2request, MSCHAPV2REQ_LEN_MAX); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; +cmp = memcmp(ia->mschapv2response, ib->mschapv2response, MSCHAPV2RESP_LEN_MAX); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; +cmp = memcmp(ia->mschapv2username, ib->mschapv2username, ia->mschapv2usernamelen); +if(cmp > 0) return 1; +else if(cmp < 0) return -1; return 0; } /*===========================================================================*/ diff --git a/include/hcxpsktool.h b/include/hcxpsktool.h index ecc334553..ceb7189a0 100644 --- a/include/hcxpsktool.h +++ b/include/hcxpsktool.h @@ -52,13 +52,16 @@ static int sort_apessidlist_by_ap(const void *a, const void *b) { const apessidl_t *ia = (const apessidl_t *)a; const apessidl_t *ib = (const apessidl_t *)b; +int cmp; + if(ia->macaddr > ib->macaddr) return 1; if(ia->macaddr < ib->macaddr) return -1; -if(memcmp(ia->essid, ib->essid, ESSID_LEN_MAX) > 0) +cmp = memcmp(ia->essid, ib->essid, ESSID_LEN_MAX); +if(cmp > 0) return 1; -else if(memcmp(ia->essid, ib->essid, ESSID_LEN_MAX) < 0) +else if(cmp < 0) return -1; return 0; @@ -68,9 +71,12 @@ static int sort_apessidlist_by_essid(const void *a, const void *b) { const apessidl_t *ia = (const apessidl_t *)a; const apessidl_t *ib = (const apessidl_t *)b; -if(memcmp(ia->essid, ib->essid, ESSID_LEN_MAX) > 0) +int cmp; + +cmp = memcmp(ia->essid, ib->essid, ESSID_LEN_MAX); +if(cmp > 0) return 1; -else if(memcmp(ia->essid, ib->essid, ESSID_LEN_MAX) < 0) +else if(cmp < 0) return -1; if(ia->macaddr > ib->macaddr) return 1; From ff97e4478c98a0d49284814683345020f1bb7f4b Mon Sep 17 00:00:00 2001 From: Alex Stanev Date: Sun, 19 May 2024 23:49:25 +0300 Subject: [PATCH 7/7] Typo verfified -> verified --- include/johnops.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/include/johnops.c b/include/johnops.c index 45d8941ae..c8ed42c1a 100644 --- a/include/johnops.c +++ b/include/johnops.c @@ -138,11 +138,11 @@ if(((zeiger->endianess & 0x10) == 0x10) || ((message_pair &0x10) == 0x10) || ((m } if((message_pair &0x07) > 1) { - fprintf(fhjohn, ":verfified:%s\n", basename); + fprintf(fhjohn, ":verified:%s\n", basename); } else { - fprintf(fhjohn, ":not verfified:%s\n", basename); + fprintf(fhjohn, ":not verified:%s\n", basename); } } else if((zeiger->endianess & 0x20) == 0x20) @@ -168,11 +168,11 @@ else if((zeiger->endianess & 0x20) == 0x20) } if((message_pair &0x07) > 1) { - fprintf(fhjohn, ":verfified:%s\n", basename); + fprintf(fhjohn, ":verified:%s\n", basename); } else { - fprintf(fhjohn, ":not verfified:%s\n", basename); + fprintf(fhjohn, ":not verified:%s\n", basename); } anonce++; } @@ -200,11 +200,11 @@ else if((zeiger->endianess & 0x40) == 0x40) } if((message_pair &0x07) > 1) { - fprintf(fhjohn, ":verfified:%s\n", basename); + fprintf(fhjohn, ":verified:%s\n", basename); } else { - fprintf(fhjohn, ":not verfified:%s\n", basename); + fprintf(fhjohn, ":not verified:%s\n", basename); } anonce++; } @@ -232,11 +232,11 @@ else } if((message_pair &0x07) > 1) { - fprintf(fhjohn, ":verfified:%s\n", basename); + fprintf(fhjohn, ":verified:%s\n", basename); } else { - fprintf(fhjohn, ":not verfified:%s\n", basename); + fprintf(fhjohn, ":not verified:%s\n", basename); } anonce++; } @@ -261,11 +261,11 @@ else } if((message_pair &0x07) > 1) { - fprintf(fhjohn, ":verfified:%s\n", basename); + fprintf(fhjohn, ":verified:%s\n", basename); } else { - fprintf(fhjohn, ":not verfified:%s\n", basename); + fprintf(fhjohn, ":not verified:%s\n", basename); } anonce++; }