Improve system-dependent compilation

This commit is contained in:
Marcos Vives Del Sol 2015-05-06 16:39:37 +02:00 committed by Romain Tartière
parent 1fb6a02359
commit 92f7413beb
7 changed files with 69 additions and 47 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
.svn
*.o
*~
aclocal.m4
autom4te.cache/*
compile

View File

@ -30,7 +30,6 @@ AC_TYPE_UINT8_T
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_CHECK_HEADERS([sys/time.h])
AC_CHECK_FUNCS([memset strchr strtoul])
# Checks for endianness convertion
@ -41,6 +40,9 @@ fi
AC_CHECK_HEADERS([byteswap.h])
AC_CHECK_HEADERS([unistd.h])
AM_CONDITIONAL([HAVE_UNISTD], [test $ac_cv_header_unistd_h = "yes"])
AC_DEFINE([_XOPEN_SOURCE], [600], [Define to 500 if Single Unix conformance is wanted, 600 for sixth revision.])
# Help us to write great code ;-)

View File

@ -2,9 +2,14 @@ AM_CFLAGS = @libnfc_CFLAGS@
bin_PROGRAMS = mfcuk
noinst_HEADERS = crapto1.h mifare.h nfc-utils.h mfcuk_mifare.h mfcuk_finger.h mfcuk_utils.h xgetopt.h mfcuk.h
noinst_HEADERS = crapto1.h mifare.h nfc-utils.h mfcuk_mifare.h mfcuk_finger.h mfcuk_utils.h mfcuk.h xgetopt.h
mfcuk_SOURCES = crapto1.c crypto1.c mifare.c nfc-utils.c mfcuk_mifare.c mfcuk_finger.c mfcuk_utils.c xgetopt.c mfcuk.c
mfcuk_SOURCES = crapto1.c crypto1.c mifare.c nfc-utils.c mfcuk_mifare.c mfcuk_finger.c mfcuk_utils.c mfcuk.c
mfcuk_LDADD = @libnfc_LIBS@
# If system does not have unistd.h, use our own getopt function from xgetopt.c
if ! HAVE_UNISTD
mfcuk_SOURCES += xgetopt.c
endif
# dist_man_MANS = mfcuk.1

View File

@ -174,15 +174,7 @@ static inline uint64_t bswap_64(uint64_t x)
#include <err.h>
#include <errno.h>
#ifdef WIN32
#define NOMINMAX
#include "windows.h"
#include "xgetopt.h"
#elif __STDC__
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#endif
// NFC
#include <nfc/nfc.h>
@ -497,7 +489,7 @@ static uint32_t mfcuk_key_recovery_block(nfc_device *pnd, uint32_t uiUID, uint64
if (ptrFoundTagNonceEntry->current_out_of_8 >= MFCUK_DARKSIDE_MAX_LEVELS)
{
//printf("FAILURE - This Nt, {Pfx}, consecutive {Nr}s and {ParBits} combination cannot produce a key-recoverable state\n");
//printf("\tINFO: try changing initial {Nr}, {Ar} and timings of sleep()\n");
//printf("\tINFO: try changing initial {Nr}, {Ar} and timings of sleepmillis()\n");
//printf("{Nr} is not a DEADBEEF.... Need to find BEEF ALIVE!... Trying next one...\n");
ptrFoundTagNonceEntry->spoofNrEnc++;
@ -516,7 +508,7 @@ static uint32_t mfcuk_key_recovery_block(nfc_device *pnd, uint32_t uiUID, uint64
if (ptrFoundTagNonceEntry->parBitsCrntCombination[ptrFoundTagNonceEntry->current_out_of_8] >= 0x20)
{
//printf("FAILURE - This consecutive {Nr}s and {ParBits} combination cannot produce all 8 required NACKs and KSs of NACKs\n");
//printf("\tINFO: try changing initial {Nr}, {Ar} and timings of sleep()\n");
//printf("\tINFO: try changing initial {Nr}, {Ar} and timings of sleepmillis()\n");
//printf("{Nr} is not a DEADBEEF.... Need to find BEEF ALIVE!... Trying next one...\n");
ptrFoundTagNonceEntry->spoofNrEnc++;
@ -838,7 +830,7 @@ static bool mfcuk_darkside_select_tag(nfc_device *pnd, int iSleepAtFieldOFF, int
}
// {WPMCC09} 2.4. Tag nonces: "drop the field (for approximately 30us) to discharge all capacitors"
sleep(iSleepAtFieldOFF);
sleepmillis(iSleepAtFieldOFF);
// Let the reader only try once to find a tag
if (0 > nfc_device_set_property_bool(pnd, NP_INFINITE_SELECT, false)) {
@ -864,7 +856,7 @@ static bool mfcuk_darkside_select_tag(nfc_device *pnd, int iSleepAtFieldOFF, int
}
// Switch the field back on, and wait for a constant amount of time before authenticating
sleep(iSleepAfterFieldON);
sleepmillis(iSleepAfterFieldON);
// Poll for a ISO14443A (MIFARE) tag
if (0 >= nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &ti_tmp)) {

View File

@ -45,12 +45,19 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mfcuk_utils.h"
#include "config.h"
#ifdef __STDC__
struct timeval global_timeout;
#if defined(WIN32)
#include <windows.h>
#elif defined(HAVE_UNISTD_H)
#include <unistd.h>
#else
#error "Unsupported system"
#endif
#include "mfcuk_utils.h"
#include <stdio.h>
/*
http://www.velocityreviews.com/forums/t451319-advice-required-on-my-ascii-to-hex-conversion-c.html
Basically, converting a hex digit into a hex nibble (4 binary digits) algorithm looks like;
@ -79,3 +86,22 @@ unsigned char hex2bin(unsigned char h, unsigned char l)
l -= -(l > 9) & 0x27;
return h << 4 | l;
}
void sleepmillis(unsigned int millis)
{
#ifdef WIN32 // If system is Windows, use system's own function if possible to reduce overhead, even if a standard C library is available
Sleep(millis);
#else
usleep(millis * 1000);
#endif
}
void clear_screen()
{
#ifdef WIN32 // On Windows, use "cls" command
system("cls");
#else // Otherwise fall back to TTY control characters
printf("\033[1;1H\033[J");
#endif
}

View File

@ -48,35 +48,6 @@
#ifndef _MFCUK_UTILS_H_
#define _MFCUK_UTILS_H_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
#define NOMINMAX
#include "windows.h"
#include "xgetopt.h"
#elif __STDC__
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#endif
// "Portable" sleep(miliseconds)
#ifdef WIN32
#define sleep(x) Sleep(x)
#elif __STDC__
extern struct timeval global_timeout;
#define sleep(x) { global_timeout.tv_usec = 1000 * (x); select(0,NULL,NULL,NULL,&global_timeout); }
#endif
// "Portable" clear_screen() - NOTE: system performance penalty introduced
#ifdef WIN32
#define clear_screen() system("cls")
#elif __STDC__
#define clear_screen() system("sh -c clear")
#endif
/**
* @fn int is_hex(char c)
* @brief Checks if an ASCII character is a valid hexadecimal base digit
@ -101,4 +72,23 @@ int is_hex(char c);
*/
unsigned char hex2bin(unsigned char h, unsigned char l);
/**
* @fn void sleepmillis(unsigned int millis)
* @brief Pauses execution for a certain amount of milliseconds
* @param millis Number of milliseconds to sleep
*
* Wrapper for system-dependant sleep function. It pauses execution for a certain amount of milliseconds.
*/
void sleepmillis(unsigned int millis);
/**
* @fn void clear_screen(void);
* @brief Clears output console
*
* Wrapper for system-dependant clear screen function.
* Resets output console, clearing text and resetting character pointer.
*/
void clear_screen(void);
#endif // _MFCUK_UTILS_H_

View File

@ -15,9 +15,15 @@
#ifndef XGETOPT_H
#define XGETOPT_H
#if HAVE_UNISTD_H
#include <unistd.h>
#else
extern int optind, opterr;
extern char *optarg;
int getopt(int argc, char *argv[], char *optstring);
#endif
#endif //XGETOPT_H