Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

mfcuk_utils.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. Package:
  3. MiFare Classic Universal toolKit (MFCUK)
  4. Package version:
  5. 0.1
  6. Filename:
  7. mfcuk_utils.h
  8. Description:
  9. MFCUK common utility functions prototypes.
  10. License:
  11. GPL2 (see below), Copyright (C) 2009, Andrei Costin
  12. * @file mfcuk_utils.h/
  13. * @brief
  14. */
  15. /*
  16. VERSION HISTORY
  17. --------------------------------------------------------------------------------
  18. | Number : 0.1
  19. | dd/mm/yyyy : 23/11/2009
  20. | Author : zveriu@gmail.com, http://andreicostin.com
  21. | Description: Moved bulk of defines and prototypes from "mfcuk_keyrecovery_darkside.c"
  22. --------------------------------------------------------------------------------
  23. */
  24. /*
  25. LICENSE
  26. This program is free software: you can redistribute it and/or modify
  27. it under the terms of the GNU General Public License as published by
  28. the Free Software Foundation, either version 2 of the License, or
  29. (at your option) any later version.
  30. This program is distributed in the hope that it will be useful,
  31. but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33. GNU General Public License for more details.
  34. You should have received a copy of the GNU General Public License
  35. along with this program. If not, see <http://www.gnu.org/licenses/>.
  36. */
  37. #ifndef _MFCUK_UTILS_H_
  38. #define _MFCUK_UTILS_H_
  39. #include <stdio.h>
  40. #include <stdlib.h>
  41. #include <string.h>
  42. #ifdef WIN32
  43. #define NOMINMAX
  44. #include "windows.h"
  45. #include "xgetopt.h"
  46. #elif __STDC__
  47. #include <unistd.h>
  48. #include <sys/time.h>
  49. #include <sys/types.h>
  50. #endif
  51. // "Portable" sleep(miliseconds)
  52. #ifdef WIN32
  53. #define sleep(x) Sleep(x)
  54. #elif __STDC__
  55. extern struct timeval global_timeout;
  56. #define sleep(x) { global_timeout.tv_usec = 1000 * (x); select(0,NULL,NULL,NULL,&global_timeout); }
  57. #endif
  58. // "Portable" clear_screen() - NOTE: system performance penalty introduced
  59. #ifdef WIN32
  60. #define clear_screen() system("cls")
  61. #elif __STDC__
  62. #define clear_screen() system("sh -c clear")
  63. #endif
  64. /**
  65. * @fn int is_hex(char c)
  66. * @brief Checks if an ASCII character is a valid hexadecimal base digit
  67. * @param c The ASCII character to be checked
  68. * @return Returns true (non-zero) or false (zero)
  69. *
  70. * Checks if an ASCII character is a valid hexadecimal base digit.
  71. * Used for hex2bin() functionality.
  72. */
  73. int is_hex(char c);
  74. /**
  75. * @fn unsigned char hex2bin(unsigned char h, unsigned char l)
  76. * @brief Converts from two nibbles (4 bits) into the corresponding byte
  77. * @param h The HIGH (left-most in human reading) nibble of two-char hex representation of a byte
  78. * @param l The LOW (right-most in human reading) nibble of two-char hex representation of a byte
  79. * @return Returns the byte which is formed from the two-char hex representation of it
  80. *
  81. * Converts from two nibbles (4 bits) into the corresponding byte.
  82. * Uses the algorithm and implementation from here:
  83. * http://www.velocityreviews.com/forums/t451319-advice-required-on-my-ascii-to-hex-conversion-c.html
  84. */
  85. unsigned char hex2bin(unsigned char h, unsigned char l);
  86. #endif // _MFCUK_UTILS_H_