From af47a3fd347dd5ad85e5267e7b2ae2c21ecca5af Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 13 May 2020 20:16:29 +0200 Subject: [PATCH] chg: copied from pm3 repo --- tools/hitag2crack/crack5/ht2crack5.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/tools/hitag2crack/crack5/ht2crack5.c b/tools/hitag2crack/crack5/ht2crack5.c index 7f10ccd6b..d07d03b64 100644 --- a/tools/hitag2crack/crack5/ht2crack5.c +++ b/tools/hitag2crack/crack5/ht2crack5.c @@ -93,6 +93,24 @@ const uint64_t unbitslice(const bitslice_t *restrict b, const uint8_t s, const u return result; } + +// determine number of logical CPU cores (use for multithreaded functions) +static int num_CPUs(void) { +#if defined(_WIN32) +#include + SYSTEM_INFO sysinfo; + GetSystemInfo(&sysinfo); + return sysinfo.dwNumberOfProcessors; +#else +#include + int count = sysconf(_SC_NPROCESSORS_ONLN); + if (count < 2) + count = 2; + return count; +#endif +} + + uint32_t uid, nR1, aR1, nR2, aR2; uint64_t candidates[(1 << 20)]; @@ -116,12 +134,7 @@ int main(int argc, char *argv[]) { uint32_t target = 0; -#ifndef __WIN32 - thread_count = sysconf(_SC_NPROCESSORS_CONF); - if (thread_count < 2) - thread_count = 2; -#endif /* _WIN32 */ - + thread_count = num_CPUs(); if (!strncmp(argv[1], "0x", 2) || !strncmp(argv[1], "0X", 2)) { uid = rev32(hexreversetoulong(argv[1] + 2));