mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -07:00
style
This commit is contained in:
parent
faf68081b0
commit
2400418067
11 changed files with 1882 additions and 1914 deletions
|
@ -85,7 +85,8 @@ static const uint8_t is_hex[] = {
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||||
|
};
|
||||||
|
|
||||||
static inline uint64_t hex2i(const char *s) {
|
static inline uint64_t hex2i(const char *s) {
|
||||||
uint64_t val = 0;
|
uint64_t val = 0;
|
||||||
|
@ -333,41 +334,41 @@ void RunMod() {
|
||||||
uint64_t key64; // Defines current key
|
uint64_t key64; // Defines current key
|
||||||
uint8_t *keyBlock; // Where the keys will be held in memory.
|
uint8_t *keyBlock; // Where the keys will be held in memory.
|
||||||
|
|
||||||
/* VIGIK EXPIRED DUMP FOR STUDY
|
/* VIGIK EXPIRED DUMP FOR STUDY
|
||||||
Sector 0
|
Sector 0
|
||||||
121C7F730208040001FA33F5CB2D021D
|
121C7F730208040001FA33F5CB2D021D
|
||||||
44001049164916491649000000000000
|
44001049164916491649000000000000
|
||||||
00000000000000000000000000000000
|
00000000000000000000000000000000
|
||||||
A0A1A2A3A4A579678800010203040506
|
A0A1A2A3A4A579678800010203040506
|
||||||
Sector 1
|
Sector 1
|
||||||
0F000000000000000000000000000000
|
0F000000000000000000000000000000
|
||||||
AA0700002102080000740C110600AF13
|
AA0700002102080000740C110600AF13
|
||||||
000000000000000001740C1108220000
|
000000000000000001740C1108220000
|
||||||
314B4947495679678800010203040506
|
314B4947495679678800010203040506
|
||||||
Sector 2
|
Sector 2
|
||||||
24E572B923A3D243B402D60CAB576956
|
24E572B923A3D243B402D60CAB576956
|
||||||
216D6501FC8618B6C426762511AC2DEE
|
216D6501FC8618B6C426762511AC2DEE
|
||||||
25BF4CEC3618D0BAB3A6E9210D887746
|
25BF4CEC3618D0BAB3A6E9210D887746
|
||||||
314B4947495679678800010203040506
|
314B4947495679678800010203040506
|
||||||
Sector 3
|
Sector 3
|
||||||
0FBC41A5D95398E76A1B2029E8EA9735
|
0FBC41A5D95398E76A1B2029E8EA9735
|
||||||
088BA2CE732653D0C1147596AFCF94D7
|
088BA2CE732653D0C1147596AFCF94D7
|
||||||
77B4D91F0442182273A29DEAF7A2D095
|
77B4D91F0442182273A29DEAF7A2D095
|
||||||
314B4947495679678800010203040506
|
314B4947495679678800010203040506
|
||||||
Sector 4
|
Sector 4
|
||||||
4CEE715866E508CDBC95C640EC9D1E58
|
4CEE715866E508CDBC95C640EC9D1E58
|
||||||
E800457CF8B079414E1B45DD3E6C9317
|
E800457CF8B079414E1B45DD3E6C9317
|
||||||
77B4D91F0442182273A29DEAF7A2D095
|
77B4D91F0442182273A29DEAF7A2D095
|
||||||
314B4947495679678800010203040506
|
314B4947495679678800010203040506
|
||||||
010203040506 0
|
010203040506 0
|
||||||
Sector 5-0F
|
Sector 5-0F
|
||||||
00000000000000000000000000000000
|
00000000000000000000000000000000
|
||||||
00000000000000000000000000000000
|
00000000000000000000000000000000
|
||||||
00000000000000000000000000000000
|
00000000000000000000000000000000
|
||||||
FFFFFFFFFFFFFF078069FFFFFFFFFFFF
|
FFFFFFFFFFFFFF078069FFFFFFFFFFFF
|
||||||
KEY A : 1KGIV ;
|
KEY A : 1KGIV ;
|
||||||
ACCBITS : 796788[00]+VALUE
|
ACCBITS : 796788[00]+VALUE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//----------------------------
|
//----------------------------
|
||||||
// Set of keys to be used.
|
// Set of keys to be used.
|
||||||
|
|
|
@ -554,7 +554,7 @@ static int b64dec(const char *src, int n, char *dst) {
|
||||||
static unsigned char hexdec(const char *s) {
|
static unsigned char hexdec(const char *s) {
|
||||||
#define HEXTOI(x) (x >= '0' && x <= '9' ? x - '0' : x - 'W')
|
#define HEXTOI(x) (x >= '0' && x <= '9' ? x - '0' : x - 'W')
|
||||||
int a = c_tolower(*(const unsigned char *) s);
|
int a = c_tolower(*(const unsigned char *) s);
|
||||||
int b = c_tolower(*(const unsigned char *) (s + 1));
|
int b = c_tolower(*(const unsigned char *)(s + 1));
|
||||||
return (HEXTOI(a) << 4) | HEXTOI(b);
|
return (HEXTOI(a) << 4) | HEXTOI(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1047,7 +1047,7 @@ int json_vscanf(const char *s, int len, const char *fmt, va_list ap) {
|
||||||
strcat(path, ".");
|
strcat(path, ".");
|
||||||
i++;
|
i++;
|
||||||
} else if (fmt[i] == '}') {
|
} else if (fmt[i] == '}') {
|
||||||
if ((p = strrchr(path, '.')) != NULL) *p = '\0';
|
if ((p = strrchr(path, '.')) != NULL) * p = '\0';
|
||||||
i++;
|
i++;
|
||||||
} else if (fmt[i] == '%') {
|
} else if (fmt[i] == '%') {
|
||||||
info.target = va_arg(ap, void *);
|
info.target = va_arg(ap, void *);
|
||||||
|
|
221
armsrc/nprintf.c
221
armsrc/nprintf.c
|
@ -119,36 +119,38 @@
|
||||||
|
|
||||||
|
|
||||||
// output function type
|
// output function type
|
||||||
typedef void (*out_fct_type)(char character, void* buffer, size_t idx, size_t maxlen);
|
typedef void (*out_fct_type)(char character, void *buffer, size_t idx, size_t maxlen);
|
||||||
|
|
||||||
|
|
||||||
// wrapper (used as buffer) for output function type
|
// wrapper (used as buffer) for output function type
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void (*fct)(char character, void* arg);
|
void (*fct)(char character, void *arg);
|
||||||
void* arg;
|
void *arg;
|
||||||
} out_fct_wrap_type;
|
} out_fct_wrap_type;
|
||||||
|
|
||||||
|
|
||||||
// internal buffer output
|
// internal buffer output
|
||||||
static inline void _out_buffer(char character, void* buffer, size_t idx, size_t maxlen)
|
static inline void _out_buffer(char character, void *buffer, size_t idx, size_t maxlen) {
|
||||||
{
|
|
||||||
if (idx < maxlen) {
|
if (idx < maxlen) {
|
||||||
((char*)buffer)[idx] = character;
|
((char *)buffer)[idx] = character;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// internal null output
|
// internal null output
|
||||||
static inline void _out_null(char character, void* buffer, size_t idx, size_t maxlen)
|
static inline void _out_null(char character, void *buffer, size_t idx, size_t maxlen) {
|
||||||
{
|
(void)character;
|
||||||
(void)character; (void)buffer; (void)idx; (void)maxlen;
|
(void)buffer;
|
||||||
|
(void)idx;
|
||||||
|
(void)maxlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// internal _putchar wrapper
|
// internal _putchar wrapper
|
||||||
static inline void _out_char(char character, void* buffer, size_t idx, size_t maxlen)
|
static inline void _out_char(char character, void *buffer, size_t idx, size_t maxlen) {
|
||||||
{
|
(void)buffer;
|
||||||
(void)buffer; (void)idx; (void)maxlen;
|
(void)idx;
|
||||||
|
(void)maxlen;
|
||||||
if (character) {
|
if (character) {
|
||||||
_putchar(character);
|
_putchar(character);
|
||||||
}
|
}
|
||||||
|
@ -156,21 +158,20 @@ static inline void _out_char(char character, void* buffer, size_t idx, size_t ma
|
||||||
|
|
||||||
|
|
||||||
// internal output function wrapper
|
// internal output function wrapper
|
||||||
static inline void _out_fct(char character, void* buffer, size_t idx, size_t maxlen)
|
static inline void _out_fct(char character, void *buffer, size_t idx, size_t maxlen) {
|
||||||
{
|
(void)idx;
|
||||||
(void)idx; (void)maxlen;
|
(void)maxlen;
|
||||||
if (character) {
|
if (character) {
|
||||||
// buffer is the output fct pointer
|
// buffer is the output fct pointer
|
||||||
((out_fct_wrap_type*)buffer)->fct(character, ((out_fct_wrap_type*)buffer)->arg);
|
((out_fct_wrap_type *)buffer)->fct(character, ((out_fct_wrap_type *)buffer)->arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// internal secure strlen
|
// internal secure strlen
|
||||||
// \return The length of the string (excluding the terminating 0) limited by 'maxsize'
|
// \return The length of the string (excluding the terminating 0) limited by 'maxsize'
|
||||||
static inline unsigned int _strnlen_s(const char* str, size_t maxsize)
|
static inline unsigned int _strnlen_s(const char *str, size_t maxsize) {
|
||||||
{
|
const char *s;
|
||||||
const char* s;
|
|
||||||
for (s = str; *s && maxsize--; ++s);
|
for (s = str; *s && maxsize--; ++s);
|
||||||
return (unsigned int)(s - str);
|
return (unsigned int)(s - str);
|
||||||
}
|
}
|
||||||
|
@ -178,15 +179,13 @@ static inline unsigned int _strnlen_s(const char* str, size_t maxsize)
|
||||||
|
|
||||||
// internal test if char is a digit (0-9)
|
// internal test if char is a digit (0-9)
|
||||||
// \return true if char is a digit
|
// \return true if char is a digit
|
||||||
static inline bool _is_digit(char ch)
|
static inline bool _is_digit(char ch) {
|
||||||
{
|
|
||||||
return (ch >= '0') && (ch <= '9');
|
return (ch >= '0') && (ch <= '9');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// internal ASCII string to unsigned int conversion
|
// internal ASCII string to unsigned int conversion
|
||||||
static unsigned int _atoi(const char** str)
|
static unsigned int _atoi(const char **str) {
|
||||||
{
|
|
||||||
unsigned int i = 0U;
|
unsigned int i = 0U;
|
||||||
while (_is_digit(**str)) {
|
while (_is_digit(**str)) {
|
||||||
i = i * 10U + (unsigned int)(*((*str)++) - '0');
|
i = i * 10U + (unsigned int)(*((*str)++) - '0');
|
||||||
|
@ -196,8 +195,7 @@ static unsigned int _atoi(const char** str)
|
||||||
|
|
||||||
|
|
||||||
// output the specified string in reverse, taking care of any zero-padding
|
// output the specified string in reverse, taking care of any zero-padding
|
||||||
static size_t _out_rev(out_fct_type out, char* buffer, size_t idx, size_t maxlen, const char* buf, size_t len, unsigned int width, unsigned int flags)
|
static size_t _out_rev(out_fct_type out, char *buffer, size_t idx, size_t maxlen, const char *buf, size_t len, unsigned int width, unsigned int flags) {
|
||||||
{
|
|
||||||
const size_t start_idx = idx;
|
const size_t start_idx = idx;
|
||||||
|
|
||||||
// pad spaces up to given width
|
// pad spaces up to given width
|
||||||
|
@ -224,8 +222,7 @@ static size_t _out_rev(out_fct_type out, char* buffer, size_t idx, size_t maxlen
|
||||||
|
|
||||||
|
|
||||||
// internal itoa format
|
// internal itoa format
|
||||||
static size_t _ntoa_format(out_fct_type out, char* buffer, size_t idx, size_t maxlen, char* buf, size_t len, bool negative, unsigned int base, unsigned int prec, unsigned int width, unsigned int flags)
|
static size_t _ntoa_format(out_fct_type out, char *buffer, size_t idx, size_t maxlen, char *buf, size_t len, bool negative, unsigned int base, unsigned int prec, unsigned int width, unsigned int flags) {
|
||||||
{
|
|
||||||
// pad leading zeros
|
// pad leading zeros
|
||||||
if (!(flags & FLAGS_LEFT)) {
|
if (!(flags & FLAGS_LEFT)) {
|
||||||
if (width && (flags & FLAGS_ZEROPAD) && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) {
|
if (width && (flags & FLAGS_ZEROPAD) && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) {
|
||||||
|
@ -249,11 +246,9 @@ static size_t _ntoa_format(out_fct_type out, char* buffer, size_t idx, size_t ma
|
||||||
}
|
}
|
||||||
if ((base == 16U) && !(flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
if ((base == 16U) && !(flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
||||||
buf[len++] = 'x';
|
buf[len++] = 'x';
|
||||||
}
|
} else if ((base == 16U) && (flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
||||||
else if ((base == 16U) && (flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
|
||||||
buf[len++] = 'X';
|
buf[len++] = 'X';
|
||||||
}
|
} else if ((base == 2U) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
||||||
else if ((base == 2U) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
|
||||||
buf[len++] = 'b';
|
buf[len++] = 'b';
|
||||||
}
|
}
|
||||||
if (len < PRINTF_NTOA_BUFFER_SIZE) {
|
if (len < PRINTF_NTOA_BUFFER_SIZE) {
|
||||||
|
@ -264,11 +259,9 @@ static size_t _ntoa_format(out_fct_type out, char* buffer, size_t idx, size_t ma
|
||||||
if (len < PRINTF_NTOA_BUFFER_SIZE) {
|
if (len < PRINTF_NTOA_BUFFER_SIZE) {
|
||||||
if (negative) {
|
if (negative) {
|
||||||
buf[len++] = '-';
|
buf[len++] = '-';
|
||||||
}
|
} else if (flags & FLAGS_PLUS) {
|
||||||
else if (flags & FLAGS_PLUS) {
|
|
||||||
buf[len++] = '+'; // ignore the space if the '+' exists
|
buf[len++] = '+'; // ignore the space if the '+' exists
|
||||||
}
|
} else if (flags & FLAGS_SPACE) {
|
||||||
else if (flags & FLAGS_SPACE) {
|
|
||||||
buf[len++] = ' ';
|
buf[len++] = ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -278,8 +271,7 @@ static size_t _ntoa_format(out_fct_type out, char* buffer, size_t idx, size_t ma
|
||||||
|
|
||||||
|
|
||||||
// internal itoa for 'long' type
|
// internal itoa for 'long' type
|
||||||
static size_t _ntoa_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen, unsigned long value, bool negative, unsigned long base, unsigned int prec, unsigned int width, unsigned int flags)
|
static size_t _ntoa_long(out_fct_type out, char *buffer, size_t idx, size_t maxlen, unsigned long value, bool negative, unsigned long base, unsigned int prec, unsigned int width, unsigned int flags) {
|
||||||
{
|
|
||||||
char buf[PRINTF_NTOA_BUFFER_SIZE];
|
char buf[PRINTF_NTOA_BUFFER_SIZE];
|
||||||
size_t len = 0U;
|
size_t len = 0U;
|
||||||
|
|
||||||
|
@ -303,8 +295,7 @@ static size_t _ntoa_long(out_fct_type out, char* buffer, size_t idx, size_t maxl
|
||||||
|
|
||||||
// internal itoa for 'long long' type
|
// internal itoa for 'long long' type
|
||||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||||
static size_t _ntoa_long_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen, unsigned long long value, bool negative, unsigned long long base, unsigned int prec, unsigned int width, unsigned int flags)
|
static size_t _ntoa_long_long(out_fct_type out, char *buffer, size_t idx, size_t maxlen, unsigned long long value, bool negative, unsigned long long base, unsigned int prec, unsigned int width, unsigned int flags) {
|
||||||
{
|
|
||||||
char buf[PRINTF_NTOA_BUFFER_SIZE];
|
char buf[PRINTF_NTOA_BUFFER_SIZE];
|
||||||
size_t len = 0U;
|
size_t len = 0U;
|
||||||
|
|
||||||
|
@ -331,13 +322,12 @@ static size_t _ntoa_long_long(out_fct_type out, char* buffer, size_t idx, size_t
|
||||||
|
|
||||||
#if defined(PRINTF_SUPPORT_EXPONENTIAL)
|
#if defined(PRINTF_SUPPORT_EXPONENTIAL)
|
||||||
// forward declaration so that _ftoa can switch to exp notation for values > PRINTF_MAX_FLOAT
|
// forward declaration so that _ftoa can switch to exp notation for values > PRINTF_MAX_FLOAT
|
||||||
static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags);
|
static size_t _etoa(out_fct_type out, char *buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// internal ftoa for fixed decimal floating point
|
// internal ftoa for fixed decimal floating point
|
||||||
static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags)
|
static size_t _ftoa(out_fct_type out, char *buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags) {
|
||||||
{
|
|
||||||
char buf[PRINTF_FTOA_BUFFER_SIZE];
|
char buf[PRINTF_FTOA_BUFFER_SIZE];
|
||||||
size_t len = 0U;
|
size_t len = 0U;
|
||||||
double diff = 0.0;
|
double diff = 0.0;
|
||||||
|
@ -392,10 +382,8 @@ static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
|
||||||
frac = 0;
|
frac = 0;
|
||||||
++whole;
|
++whole;
|
||||||
}
|
}
|
||||||
}
|
} else if (diff < 0.5) {
|
||||||
else if (diff < 0.5) {
|
} else if ((frac == 0U) || (frac & 1U)) {
|
||||||
}
|
|
||||||
else if ((frac == 0U) || (frac & 1U)) {
|
|
||||||
// if halfway, round up if odd OR if last digit is 0
|
// if halfway, round up if odd OR if last digit is 0
|
||||||
++frac;
|
++frac;
|
||||||
}
|
}
|
||||||
|
@ -407,8 +395,7 @@ static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
|
||||||
// 1.5 -> 2, but 2.5 -> 2
|
// 1.5 -> 2, but 2.5 -> 2
|
||||||
++whole;
|
++whole;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
unsigned int count = prec;
|
unsigned int count = prec;
|
||||||
// now do fractional part, as an unsigned number
|
// now do fractional part, as an unsigned number
|
||||||
while (len < PRINTF_FTOA_BUFFER_SIZE) {
|
while (len < PRINTF_FTOA_BUFFER_SIZE) {
|
||||||
|
@ -449,11 +436,9 @@ static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
|
||||||
if (len < PRINTF_FTOA_BUFFER_SIZE) {
|
if (len < PRINTF_FTOA_BUFFER_SIZE) {
|
||||||
if (negative) {
|
if (negative) {
|
||||||
buf[len++] = '-';
|
buf[len++] = '-';
|
||||||
}
|
} else if (flags & FLAGS_PLUS) {
|
||||||
else if (flags & FLAGS_PLUS) {
|
|
||||||
buf[len++] = '+'; // ignore the space if the '+' exists
|
buf[len++] = '+'; // ignore the space if the '+' exists
|
||||||
}
|
} else if (flags & FLAGS_SPACE) {
|
||||||
else if (flags & FLAGS_SPACE) {
|
|
||||||
buf[len++] = ' ';
|
buf[len++] = ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -464,8 +449,7 @@ static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
|
||||||
|
|
||||||
#if defined(PRINTF_SUPPORT_EXPONENTIAL)
|
#if defined(PRINTF_SUPPORT_EXPONENTIAL)
|
||||||
// internal ftoa variant for exponential floating-point type, contributed by Martijn Jasperse <m.jasperse@gmail.com>
|
// internal ftoa variant for exponential floating-point type, contributed by Martijn Jasperse <m.jasperse@gmail.com>
|
||||||
static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags)
|
static size_t _etoa(out_fct_type out, char *buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags) {
|
||||||
{
|
|
||||||
// check for NaN and special values
|
// check for NaN and special values
|
||||||
if ((value != value) || (value > DBL_MAX) || (value < -DBL_MAX)) {
|
if ((value != value) || (value > DBL_MAX) || (value < -DBL_MAX)) {
|
||||||
return _ftoa(out, buffer, idx, maxlen, value, prec, width, flags);
|
return _ftoa(out, buffer, idx, maxlen, value, prec, width, flags);
|
||||||
|
@ -516,16 +500,14 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
|
||||||
if ((value >= 1e-4) && (value < 1e6)) {
|
if ((value >= 1e-4) && (value < 1e6)) {
|
||||||
if ((int)prec > expval) {
|
if ((int)prec > expval) {
|
||||||
prec = (unsigned)((int)prec - expval - 1);
|
prec = (unsigned)((int)prec - expval - 1);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
prec = 0;
|
prec = 0;
|
||||||
}
|
}
|
||||||
flags |= FLAGS_PRECISION; // make sure _ftoa respects precision
|
flags |= FLAGS_PRECISION; // make sure _ftoa respects precision
|
||||||
// no characters in exponent
|
// no characters in exponent
|
||||||
minwidth = 0U;
|
minwidth = 0U;
|
||||||
expval = 0;
|
expval = 0;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// we use one sigfig for the whole part
|
// we use one sigfig for the whole part
|
||||||
if ((prec > 0) && (flags & FLAGS_PRECISION)) {
|
if ((prec > 0) && (flags & FLAGS_PRECISION)) {
|
||||||
--prec;
|
--prec;
|
||||||
|
@ -561,7 +543,7 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
|
||||||
// output the exponential symbol
|
// output the exponential symbol
|
||||||
out((flags & FLAGS_UPPERCASE) ? 'E' : 'e', buffer, idx++, maxlen);
|
out((flags & FLAGS_UPPERCASE) ? 'E' : 'e', buffer, idx++, maxlen);
|
||||||
// output the exponent value
|
// output the exponent value
|
||||||
idx = _ntoa_long(out, buffer, idx, maxlen, (expval < 0) ? -expval : expval, expval < 0, 10, 0, minwidth-1, FLAGS_ZEROPAD | FLAGS_PLUS);
|
idx = _ntoa_long(out, buffer, idx, maxlen, (expval < 0) ? -expval : expval, expval < 0, 10, 0, minwidth - 1, FLAGS_ZEROPAD | FLAGS_PLUS);
|
||||||
// might need to right-pad spaces
|
// might need to right-pad spaces
|
||||||
if (flags & FLAGS_LEFT) {
|
if (flags & FLAGS_LEFT) {
|
||||||
while (idx - start_idx < width) out(' ', buffer, idx++, maxlen);
|
while (idx - start_idx < width) out(' ', buffer, idx++, maxlen);
|
||||||
|
@ -574,8 +556,7 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
|
||||||
|
|
||||||
|
|
||||||
// internal vsnprintf
|
// internal vsnprintf
|
||||||
static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const char* format, va_list va)
|
static int _vsnprintf(out_fct_type out, char *buffer, const size_t maxlen, const char *format, va_list va) {
|
||||||
{
|
|
||||||
unsigned int flags, width, precision, n;
|
unsigned int flags, width, precision, n;
|
||||||
size_t idx = 0U;
|
size_t idx = 0U;
|
||||||
|
|
||||||
|
@ -584,16 +565,14 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
|
||||||
out = _out_null;
|
out = _out_null;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*format)
|
while (*format) {
|
||||||
{
|
|
||||||
// format specifier? %[flags][width][.precision][length]
|
// format specifier? %[flags][width][.precision][length]
|
||||||
if (*format != '%') {
|
if (*format != '%') {
|
||||||
// no
|
// no
|
||||||
out(*format, buffer, idx++, maxlen);
|
out(*format, buffer, idx++, maxlen);
|
||||||
format++;
|
format++;
|
||||||
continue;
|
continue;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// yes, evaluate it
|
// yes, evaluate it
|
||||||
format++;
|
format++;
|
||||||
}
|
}
|
||||||
|
@ -602,12 +581,34 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
|
||||||
flags = 0U;
|
flags = 0U;
|
||||||
do {
|
do {
|
||||||
switch (*format) {
|
switch (*format) {
|
||||||
case '0': flags |= FLAGS_ZEROPAD; format++; n = 1U; break;
|
case '0':
|
||||||
case '-': flags |= FLAGS_LEFT; format++; n = 1U; break;
|
flags |= FLAGS_ZEROPAD;
|
||||||
case '+': flags |= FLAGS_PLUS; format++; n = 1U; break;
|
format++;
|
||||||
case ' ': flags |= FLAGS_SPACE; format++; n = 1U; break;
|
n = 1U;
|
||||||
case '#': flags |= FLAGS_HASH; format++; n = 1U; break;
|
break;
|
||||||
default : n = 0U; break;
|
case '-':
|
||||||
|
flags |= FLAGS_LEFT;
|
||||||
|
format++;
|
||||||
|
n = 1U;
|
||||||
|
break;
|
||||||
|
case '+':
|
||||||
|
flags |= FLAGS_PLUS;
|
||||||
|
format++;
|
||||||
|
n = 1U;
|
||||||
|
break;
|
||||||
|
case ' ':
|
||||||
|
flags |= FLAGS_SPACE;
|
||||||
|
format++;
|
||||||
|
n = 1U;
|
||||||
|
break;
|
||||||
|
case '#':
|
||||||
|
flags |= FLAGS_HASH;
|
||||||
|
format++;
|
||||||
|
n = 1U;
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
n = 0U;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} while (n);
|
} while (n);
|
||||||
|
|
||||||
|
@ -615,14 +616,12 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
|
||||||
width = 0U;
|
width = 0U;
|
||||||
if (_is_digit(*format)) {
|
if (_is_digit(*format)) {
|
||||||
width = _atoi(&format);
|
width = _atoi(&format);
|
||||||
}
|
} else if (*format == '*') {
|
||||||
else if (*format == '*') {
|
|
||||||
const int w = va_arg(va, int);
|
const int w = va_arg(va, int);
|
||||||
if (w < 0) {
|
if (w < 0) {
|
||||||
flags |= FLAGS_LEFT; // reverse padding
|
flags |= FLAGS_LEFT; // reverse padding
|
||||||
width = (unsigned int)-w;
|
width = (unsigned int) - w;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
width = (unsigned int)w;
|
width = (unsigned int)w;
|
||||||
}
|
}
|
||||||
format++;
|
format++;
|
||||||
|
@ -635,8 +634,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
|
||||||
format++;
|
format++;
|
||||||
if (_is_digit(*format)) {
|
if (_is_digit(*format)) {
|
||||||
precision = _atoi(&format);
|
precision = _atoi(&format);
|
||||||
}
|
} else if (*format == '*') {
|
||||||
else if (*format == '*') {
|
|
||||||
const int prec = (int)va_arg(va, int);
|
const int prec = (int)va_arg(va, int);
|
||||||
precision = prec > 0 ? (unsigned int)prec : 0U;
|
precision = prec > 0 ? (unsigned int)prec : 0U;
|
||||||
format++;
|
format++;
|
||||||
|
@ -692,14 +690,11 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
|
||||||
unsigned int base;
|
unsigned int base;
|
||||||
if (*format == 'x' || *format == 'X') {
|
if (*format == 'x' || *format == 'X') {
|
||||||
base = 16U;
|
base = 16U;
|
||||||
}
|
} else if (*format == 'o') {
|
||||||
else if (*format == 'o') {
|
|
||||||
base = 8U;
|
base = 8U;
|
||||||
}
|
} else if (*format == 'b') {
|
||||||
else if (*format == 'b') {
|
|
||||||
base = 2U;
|
base = 2U;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
base = 10U;
|
base = 10U;
|
||||||
flags &= ~FLAGS_HASH; // no hash for dec format
|
flags &= ~FLAGS_HASH; // no hash for dec format
|
||||||
}
|
}
|
||||||
|
@ -726,27 +721,22 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
|
||||||
const long long value = va_arg(va, long long);
|
const long long value = va_arg(va, long long);
|
||||||
idx = _ntoa_long_long(out, buffer, idx, maxlen, (unsigned long long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags);
|
idx = _ntoa_long_long(out, buffer, idx, maxlen, (unsigned long long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags);
|
||||||
#endif
|
#endif
|
||||||
}
|
} else if (flags & FLAGS_LONG) {
|
||||||
else if (flags & FLAGS_LONG) {
|
|
||||||
const long value = va_arg(va, long);
|
const long value = va_arg(va, long);
|
||||||
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags);
|
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
const int value = (flags & FLAGS_CHAR) ? (char)va_arg(va, int) : (flags & FLAGS_SHORT) ? (short int)va_arg(va, int) : va_arg(va, int);
|
const int value = (flags & FLAGS_CHAR) ? (char)va_arg(va, int) : (flags & FLAGS_SHORT) ? (short int)va_arg(va, int) : va_arg(va, int);
|
||||||
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned int)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags);
|
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned int)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// unsigned
|
// unsigned
|
||||||
if (flags & FLAGS_LONG_LONG) {
|
if (flags & FLAGS_LONG_LONG) {
|
||||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||||
idx = _ntoa_long_long(out, buffer, idx, maxlen, va_arg(va, unsigned long long), false, base, precision, width, flags);
|
idx = _ntoa_long_long(out, buffer, idx, maxlen, va_arg(va, unsigned long long), false, base, precision, width, flags);
|
||||||
#endif
|
#endif
|
||||||
}
|
} else if (flags & FLAGS_LONG) {
|
||||||
else if (flags & FLAGS_LONG) {
|
|
||||||
idx = _ntoa_long(out, buffer, idx, maxlen, va_arg(va, unsigned long), false, base, precision, width, flags);
|
idx = _ntoa_long(out, buffer, idx, maxlen, va_arg(va, unsigned long), false, base, precision, width, flags);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
const unsigned int value = (flags & FLAGS_CHAR) ? (unsigned char)va_arg(va, unsigned int) : (flags & FLAGS_SHORT) ? (unsigned short int)va_arg(va, unsigned int) : va_arg(va, unsigned int);
|
const unsigned int value = (flags & FLAGS_CHAR) ? (unsigned char)va_arg(va, unsigned int) : (flags & FLAGS_SHORT) ? (unsigned short int)va_arg(va, unsigned int) : va_arg(va, unsigned int);
|
||||||
idx = _ntoa_long(out, buffer, idx, maxlen, value, false, base, precision, width, flags);
|
idx = _ntoa_long(out, buffer, idx, maxlen, value, false, base, precision, width, flags);
|
||||||
}
|
}
|
||||||
|
@ -766,8 +756,8 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
|
||||||
case 'E':
|
case 'E':
|
||||||
case 'g':
|
case 'g':
|
||||||
case 'G':
|
case 'G':
|
||||||
if ((*format == 'g')||(*format == 'G')) flags |= FLAGS_ADAPT_EXP;
|
if ((*format == 'g') || (*format == 'G')) flags |= FLAGS_ADAPT_EXP;
|
||||||
if ((*format == 'E')||(*format == 'G')) flags |= FLAGS_UPPERCASE;
|
if ((*format == 'E') || (*format == 'G')) flags |= FLAGS_UPPERCASE;
|
||||||
idx = _etoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags);
|
idx = _etoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags);
|
||||||
format++;
|
format++;
|
||||||
break;
|
break;
|
||||||
|
@ -794,8 +784,8 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
|
||||||
}
|
}
|
||||||
|
|
||||||
case 's' : {
|
case 's' : {
|
||||||
const char* p = va_arg(va, char*);
|
const char *p = va_arg(va, char *);
|
||||||
unsigned int l = _strnlen_s(p, precision ? precision : (size_t)-1);
|
unsigned int l = _strnlen_s(p, precision ? precision : (size_t) -1);
|
||||||
// pre padding
|
// pre padding
|
||||||
if (flags & FLAGS_PRECISION) {
|
if (flags & FLAGS_PRECISION) {
|
||||||
l = (l < precision ? l : precision);
|
l = (l < precision ? l : precision);
|
||||||
|
@ -820,16 +810,15 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'p' : {
|
case 'p' : {
|
||||||
width = sizeof(void*) * 2U;
|
width = sizeof(void *) * 2U;
|
||||||
flags |= FLAGS_ZEROPAD | FLAGS_UPPERCASE;
|
flags |= FLAGS_ZEROPAD | FLAGS_UPPERCASE;
|
||||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||||
const bool is_ll = sizeof(uintptr_t) == sizeof(long long);
|
const bool is_ll = sizeof(uintptr_t) == sizeof(long long);
|
||||||
if (is_ll) {
|
if (is_ll) {
|
||||||
idx = _ntoa_long_long(out, buffer, idx, maxlen, (uintptr_t)va_arg(va, void*), false, 16U, precision, width, flags);
|
idx = _ntoa_long_long(out, buffer, idx, maxlen, (uintptr_t)va_arg(va, void *), false, 16U, precision, width, flags);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
#endif
|
#endif
|
||||||
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)((uintptr_t)va_arg(va, void*)), false, 16U, precision, width, flags);
|
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)((uintptr_t)va_arg(va, void *)), false, 16U, precision, width, flags);
|
||||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -859,29 +848,26 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int printf_(const char* format, ...)
|
int printf_(const char *format, ...) {
|
||||||
{
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
char buffer[1];
|
char buffer[1];
|
||||||
const int ret = _vsnprintf(_out_char, buffer, (size_t)-1, format, va);
|
const int ret = _vsnprintf(_out_char, buffer, (size_t) -1, format, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int sprintf_(char* buffer, const char* format, ...)
|
int sprintf_(char *buffer, const char *format, ...) {
|
||||||
{
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
const int ret = _vsnprintf(_out_buffer, buffer, (size_t)-1, format, va);
|
const int ret = _vsnprintf(_out_buffer, buffer, (size_t) -1, format, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int snprintf_(char* buffer, size_t count, const char* format, ...)
|
int snprintf_(char *buffer, size_t count, const char *format, ...) {
|
||||||
{
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
const int ret = _vsnprintf(_out_buffer, buffer, count, format, va);
|
const int ret = _vsnprintf(_out_buffer, buffer, count, format, va);
|
||||||
|
@ -890,25 +876,22 @@ int snprintf_(char* buffer, size_t count, const char* format, ...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int vprintf_(const char* format, va_list va)
|
int vprintf_(const char *format, va_list va) {
|
||||||
{
|
|
||||||
char buffer[1];
|
char buffer[1];
|
||||||
return _vsnprintf(_out_char, buffer, (size_t)-1, format, va);
|
return _vsnprintf(_out_char, buffer, (size_t) -1, format, va);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int vsnprintf_(char* buffer, size_t count, const char* format, va_list va)
|
int vsnprintf_(char *buffer, size_t count, const char *format, va_list va) {
|
||||||
{
|
|
||||||
return _vsnprintf(_out_buffer, buffer, count, format, va);
|
return _vsnprintf(_out_buffer, buffer, count, format, va);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...)
|
int fctprintf(void (*out)(char character, void *arg), void *arg, const char *format, ...) {
|
||||||
{
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
const out_fct_wrap_type out_fct_wrap = { out, arg };
|
const out_fct_wrap_type out_fct_wrap = { out, arg };
|
||||||
const int ret = _vsnprintf(_out_fct, (char*)(uintptr_t)&out_fct_wrap, (size_t)-1, format, va);
|
const int ret = _vsnprintf(_out_fct, (char *)(uintptr_t)&out_fct_wrap, (size_t) -1, format, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ void _putchar(char character);
|
||||||
* \return The number of characters that are written into the array, not counting the terminating null character
|
* \return The number of characters that are written into the array, not counting the terminating null character
|
||||||
*/
|
*/
|
||||||
#define printf printf_
|
#define printf printf_
|
||||||
int printf_(const char* format, ...);
|
int printf_(const char *format, ...);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,7 +69,7 @@ int printf_(const char* format, ...);
|
||||||
* \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
|
* \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
|
||||||
*/
|
*/
|
||||||
#define sprintf sprintf_
|
#define sprintf sprintf_
|
||||||
int sprintf_(char* buffer, const char* format, ...);
|
int sprintf_(char *buffer, const char *format, ...);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,8 +84,8 @@ int sprintf_(char* buffer, const char* format, ...);
|
||||||
*/
|
*/
|
||||||
#define snprintf snprintf_
|
#define snprintf snprintf_
|
||||||
#define vsnprintf vsnprintf_
|
#define vsnprintf vsnprintf_
|
||||||
int snprintf_(char* buffer, size_t count, const char* format, ...);
|
int snprintf_(char *buffer, size_t count, const char *format, ...);
|
||||||
int vsnprintf_(char* buffer, size_t count, const char* format, va_list va);
|
int vsnprintf_(char *buffer, size_t count, const char *format, va_list va);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,7 +95,7 @@ int vsnprintf_(char* buffer, size_t count, const char* format, va_list va);
|
||||||
* \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
|
* \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
|
||||||
*/
|
*/
|
||||||
#define vprintf vprintf_
|
#define vprintf vprintf_
|
||||||
int vprintf_(const char* format, va_list va);
|
int vprintf_(const char *format, va_list va);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -106,7 +106,7 @@ int vprintf_(const char* format, va_list va);
|
||||||
* \param format A string that specifies the format of the output
|
* \param format A string that specifies the format of the output
|
||||||
* \return The number of characters that are sent to the output function, not counting the terminating null character
|
* \return The number of characters that are sent to the output function, not counting the terminating null character
|
||||||
*/
|
*/
|
||||||
int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...);
|
int fctprintf(void (*out)(char character, void *arg), void *arg, const char *format, ...);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -197,56 +197,50 @@ char *strtok(char *s, const char *delim) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *strchr(const char *s, int c)
|
char *strchr(const char *s, int c) {
|
||||||
{
|
|
||||||
while (*s != (char)c)
|
while (*s != (char)c)
|
||||||
if (!*s++)
|
if (!*s++)
|
||||||
return 0;
|
return 0;
|
||||||
return (char *)s;
|
return (char *)s;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t strspn(const char *s1, const char *s2)
|
size_t strspn(const char *s1, const char *s2) {
|
||||||
{
|
size_t ret = 0;
|
||||||
size_t ret=0;
|
while (*s1 && strchr(s2, *s1++))
|
||||||
while(*s1 && strchr(s2,*s1++))
|
|
||||||
ret++;
|
ret++;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *strrchr(const char *s, int c)
|
char *strrchr(const char *s, int c) {
|
||||||
{
|
const char *ret = 0;
|
||||||
const char* ret=0;
|
|
||||||
do {
|
do {
|
||||||
if( *s == (char)c )
|
if (*s == (char)c)
|
||||||
ret=s;
|
ret = s;
|
||||||
} while(*s++);
|
} while (*s++);
|
||||||
return (char *)ret;
|
return (char *)ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t strcspn(const char *s1, const char *s2)
|
size_t strcspn(const char *s1, const char *s2) {
|
||||||
{
|
size_t ret = 0;
|
||||||
size_t ret=0;
|
while (*s1)
|
||||||
while(*s1)
|
if (strchr(s2, *s1))
|
||||||
if(strchr(s2,*s1))
|
|
||||||
return ret;
|
return ret;
|
||||||
else
|
else
|
||||||
s1++,ret++;
|
s1++, ret++;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *strpbrk(const char *s1, const char *s2)
|
char *strpbrk(const char *s1, const char *s2) {
|
||||||
{
|
while (*s1)
|
||||||
while(*s1)
|
if (strchr(s2, *s1++))
|
||||||
if(strchr(s2, *s1++))
|
return (char *)--s1;
|
||||||
return (char*)--s1;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int strncmp(const char* s1, const char* s2, size_t n)
|
int strncmp(const char *s1, const char *s2, size_t n) {
|
||||||
{
|
while (n--)
|
||||||
while(n--)
|
if (*s1++ != *s2++)
|
||||||
if(*s1++!=*s2++)
|
return *(unsigned char *)(s1 - 1) - *(unsigned char *)(s2 - 1);
|
||||||
return *(unsigned char*)(s1 - 1) - *(unsigned char*)(s2 - 1);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,27 +249,23 @@ int strncmp(const char* s1, const char* s2, size_t n)
|
||||||
|
|
||||||
#define isspace(a) __extension__ ({ unsigned char bb__isspace = (a) - 9; bb__isspace == (' ' - 9) || bb__isspace <= (13 - 9); })
|
#define isspace(a) __extension__ ({ unsigned char bb__isspace = (a) - 9; bb__isspace == (' ' - 9) || bb__isspace <= (13 - 9); })
|
||||||
|
|
||||||
unsigned long strtoul(const char *p, char **out_p, int base)
|
unsigned long strtoul(const char *p, char **out_p, int base) {
|
||||||
{
|
|
||||||
unsigned long v = 0;
|
unsigned long v = 0;
|
||||||
|
|
||||||
while (isspace(*p))
|
while (isspace(*p))
|
||||||
p++;
|
p++;
|
||||||
if (((base == 16) || (base == 0)) &&
|
if (((base == 16) || (base == 0)) &&
|
||||||
((*p == '0') && ((p[1] == 'x') || (p[1] == 'X'))))
|
((*p == '0') && ((p[1] == 'x') || (p[1] == 'X')))) {
|
||||||
{
|
|
||||||
p += 2;
|
p += 2;
|
||||||
base = 16;
|
base = 16;
|
||||||
}
|
}
|
||||||
if (base == 0)
|
if (base == 0) {
|
||||||
{
|
|
||||||
if (*p == '0')
|
if (*p == '0')
|
||||||
base = 8;
|
base = 8;
|
||||||
else
|
else
|
||||||
base = 10;
|
base = 10;
|
||||||
}
|
}
|
||||||
while (1)
|
while (1) {
|
||||||
{
|
|
||||||
char c = *p;
|
char c = *p;
|
||||||
if ((c >= '0') && (c <= '9') && (c - '0' < base))
|
if ((c >= '0') && (c <= '9') && (c - '0' < base))
|
||||||
v = (v * base) + (c - '0');
|
v = (v * base) + (c - '0');
|
||||||
|
@ -288,12 +278,11 @@ unsigned long strtoul(const char *p, char **out_p, int base)
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out_p) *out_p = (char*)p;
|
if (out_p) *out_p = (char *)p;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
long strtol(const char *p, char **out_p, int base)
|
long strtol(const char *p, char **out_p, int base) {
|
||||||
{
|
|
||||||
long v = 0;
|
long v = 0;
|
||||||
int is_neg = 0;
|
int is_neg = 0;
|
||||||
|
|
||||||
|
@ -304,20 +293,17 @@ long strtol(const char *p, char **out_p, int base)
|
||||||
else if (*p == '+')
|
else if (*p == '+')
|
||||||
is_neg = 0;
|
is_neg = 0;
|
||||||
if (((base == 16) || (base == 0)) &&
|
if (((base == 16) || (base == 0)) &&
|
||||||
((*p == '0') && ((p[1] == 'x') || (p[1] == 'X'))))
|
((*p == '0') && ((p[1] == 'x') || (p[1] == 'X')))) {
|
||||||
{
|
|
||||||
p += 2;
|
p += 2;
|
||||||
base = 16;
|
base = 16;
|
||||||
}
|
}
|
||||||
if (base == 0)
|
if (base == 0) {
|
||||||
{
|
|
||||||
if (*p == '0')
|
if (*p == '0')
|
||||||
base = 8;
|
base = 8;
|
||||||
else
|
else
|
||||||
base = 10;
|
base = 10;
|
||||||
}
|
}
|
||||||
while (1)
|
while (1) {
|
||||||
{
|
|
||||||
char c = *p;
|
char c = *p;
|
||||||
if ((c >= '0') && (c <= '9') && (c - '0' < base))
|
if ((c >= '0') && (c <= '9') && (c - '0' < base))
|
||||||
v = (v * base) + (c - '0');
|
v = (v * base) + (c - '0');
|
||||||
|
@ -331,21 +317,19 @@ long strtol(const char *p, char **out_p, int base)
|
||||||
}
|
}
|
||||||
if (is_neg)
|
if (is_neg)
|
||||||
v = -v;
|
v = -v;
|
||||||
if (out_p) *out_p = (char*)p;
|
if (out_p) *out_p = (char *)p;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
char c_tolower(int c)
|
char c_tolower(int c) {
|
||||||
{
|
|
||||||
// (int)a = 97, (int)A = 65
|
// (int)a = 97, (int)A = 65
|
||||||
// (a)97 - (A)65 = 32
|
// (a)97 - (A)65 = 32
|
||||||
// therefore 32 + 65 = a
|
// therefore 32 + 65 = a
|
||||||
return c > 64 && c < 91 ? c + 32 : c;
|
return c > 64 && c < 91 ? c + 32 : c;
|
||||||
}
|
}
|
||||||
|
|
||||||
char c_isprint (unsigned char c)
|
char c_isprint(unsigned char c) {
|
||||||
{
|
if (c >= 0x20 && c <= 0x7e)
|
||||||
if ( c >= 0x20 && c <= 0x7e )
|
|
||||||
return 1;
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,9 +32,9 @@ size_t strspn(const char *s1, const char *s2);
|
||||||
char *strrchr(const char *s, int c);
|
char *strrchr(const char *s, int c);
|
||||||
size_t strcspn(const char *s1, const char *s2);
|
size_t strcspn(const char *s1, const char *s2);
|
||||||
char *strpbrk(const char *s1, const char *s2);
|
char *strpbrk(const char *s1, const char *s2);
|
||||||
int strncmp(const char * s1, const char * s2, size_t n);
|
int strncmp(const char *s1, const char *s2, size_t n);
|
||||||
char c_tolower(int c);
|
char c_tolower(int c);
|
||||||
char c_isprint (unsigned char c);
|
char c_isprint(unsigned char c);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ static int usage_thinfilm_info(void) {
|
||||||
// https://github.com/nfc-tools/libnfc/blob/master/utils/nfc-barcode.c
|
// https://github.com/nfc-tools/libnfc/blob/master/utils/nfc-barcode.c
|
||||||
static int print_barcode(uint8_t *barcode, const size_t barcode_len) {
|
static int print_barcode(uint8_t *barcode, const size_t barcode_len) {
|
||||||
|
|
||||||
PrintAndLogEx(SUCCESS, " Manufacturer : "_YELLOW_("%s") "[0x%02X]", (barcode[0] == 0xB7) ? "Thinfilm" : "unknown", barcode[0] );
|
PrintAndLogEx(SUCCESS, " Manufacturer : "_YELLOW_("%s") "[0x%02X]", (barcode[0] == 0xB7) ? "Thinfilm" : "unknown", barcode[0]);
|
||||||
PrintAndLogEx(SUCCESS, " Data format : "_YELLOW_("%02X"), barcode[1]);
|
PrintAndLogEx(SUCCESS, " Data format : "_YELLOW_("%02X"), barcode[1]);
|
||||||
|
|
||||||
uint8_t b1, b2;
|
uint8_t b1, b2;
|
||||||
|
@ -48,7 +48,7 @@ static int print_barcode(uint8_t *barcode, const size_t barcode_len) {
|
||||||
printf("Data Format Field: Reserved for allocation by tag manufacturer\n");
|
printf("Data Format Field: Reserved for allocation by tag manufacturer\n");
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
case 1:
|
case 1:
|
||||||
snprintf(s, sizeof(s), "http://www." );
|
snprintf(s, sizeof(s), "http://www.");
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
snprintf(s, sizeof(s), "https://www.");
|
snprintf(s, sizeof(s), "https://www.");
|
||||||
|
@ -60,15 +60,15 @@ static int print_barcode(uint8_t *barcode, const size_t barcode_len) {
|
||||||
snprintf(s, sizeof(s), "https://");
|
snprintf(s, sizeof(s), "https://");
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
PrintAndLogEx(SUCCESS, "EPC: %s", sprint_hex(barcode + 2, 12) );
|
PrintAndLogEx(SUCCESS, "EPC: %s", sprint_hex(barcode + 2, 12));
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
default:
|
default:
|
||||||
PrintAndLogEx(SUCCESS, "Data Format Field: unknown (%02X)", barcode[1]);
|
PrintAndLogEx(SUCCESS, "Data Format Field: unknown (%02X)", barcode[1]);
|
||||||
PrintAndLogEx(SUCCESS, "Data:" _YELLOW_("%s"), sprint_hex(barcode + 2, barcode_len - 2) );
|
PrintAndLogEx(SUCCESS, "Data:" _YELLOW_("%s"), sprint_hex(barcode + 2, barcode_len - 2));
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(s + strlen(s), barcode_len - 3, (const char*)&barcode[2] , barcode_len - 4);
|
snprintf(s + strlen(s), barcode_len - 3, (const char *)&barcode[2], barcode_len - 4);
|
||||||
|
|
||||||
for (uint8_t i = 0; i < strlen(s); i++) {
|
for (uint8_t i = 0; i < strlen(s); i++) {
|
||||||
|
|
||||||
|
@ -118,8 +118,8 @@ int infoThinFilm(void) {
|
||||||
return PM3_ETIMEOUT;
|
return PM3_ETIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( resp.status == PM3_SUCCESS ) {
|
if (resp.status == PM3_SUCCESS) {
|
||||||
print_barcode( resp.data.asBytes, resp.length );
|
print_barcode(resp.data.asBytes, resp.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
return resp.status;
|
return resp.status;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue