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.
|
||||||
|
@ -702,18 +703,18 @@ readysim:
|
||||||
|
|
||||||
uint16_t flags;
|
uint16_t flags;
|
||||||
switch (p_card.uidlen) {
|
switch (p_card.uidlen) {
|
||||||
case 10:
|
case 10:
|
||||||
flags = FLAG_10B_UID_IN_DATA;
|
flags = FLAG_10B_UID_IN_DATA;
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
flags = FLAG_7B_UID_IN_DATA;
|
flags = FLAG_7B_UID_IN_DATA;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
flags = FLAG_4B_UID_IN_DATA;
|
flags = FLAG_4B_UID_IN_DATA;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
flags = FLAG_UID_IN_EMUL;
|
flags = FLAG_UID_IN_EMUL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use UID, SAK, ATQA from EMUL, if uid not defined
|
// Use UID, SAK, ATQA from EMUL, if uid not defined
|
||||||
|
@ -1031,7 +1032,7 @@ int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *data
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((mifare_sendcmd_short(NULL, 0, 0xA0, blockNo, receivedAnswer, receivedAnswerPar, NULL) != 1) ||
|
if ((mifare_sendcmd_short(NULL, 0, 0xA0, blockNo, receivedAnswer, receivedAnswerPar, NULL) != 1) ||
|
||||||
(receivedAnswer[0] != 0x0a)) {
|
(receivedAnswer[0] != 0x0a)) {
|
||||||
DbprintfEx(FLAG_NEWLINE, "write block send command error");
|
DbprintfEx(FLAG_NEWLINE, "write block send command error");
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
2050
armsrc/frozen.c
2050
armsrc/frozen.c
File diff suppressed because it is too large
Load diff
|
@ -36,18 +36,18 @@ enum { false = 0, true = 1 };
|
||||||
|
|
||||||
/* JSON token type */
|
/* JSON token type */
|
||||||
enum json_token_type {
|
enum json_token_type {
|
||||||
JSON_TYPE_INVALID = 0, /* memsetting to 0 should create INVALID value */
|
JSON_TYPE_INVALID = 0, /* memsetting to 0 should create INVALID value */
|
||||||
JSON_TYPE_STRING,
|
JSON_TYPE_STRING,
|
||||||
JSON_TYPE_NUMBER,
|
JSON_TYPE_NUMBER,
|
||||||
JSON_TYPE_TRUE,
|
JSON_TYPE_TRUE,
|
||||||
JSON_TYPE_FALSE,
|
JSON_TYPE_FALSE,
|
||||||
JSON_TYPE_NULL,
|
JSON_TYPE_NULL,
|
||||||
JSON_TYPE_OBJECT_START,
|
JSON_TYPE_OBJECT_START,
|
||||||
JSON_TYPE_OBJECT_END,
|
JSON_TYPE_OBJECT_END,
|
||||||
JSON_TYPE_ARRAY_START,
|
JSON_TYPE_ARRAY_START,
|
||||||
JSON_TYPE_ARRAY_END,
|
JSON_TYPE_ARRAY_END,
|
||||||
|
|
||||||
JSON_TYPES_CNT
|
JSON_TYPES_CNT
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -55,9 +55,9 @@ enum json_token_type {
|
||||||
* `json_scanf()` with the format specifier `%T`.
|
* `json_scanf()` with the format specifier `%T`.
|
||||||
*/
|
*/
|
||||||
struct json_token {
|
struct json_token {
|
||||||
const char *ptr; /* Points to the beginning of the value */
|
const char *ptr; /* Points to the beginning of the value */
|
||||||
int len; /* Value length */
|
int len; /* Value length */
|
||||||
enum json_token_type type; /* Type of the token, possible values are above */
|
enum json_token_type type; /* Type of the token, possible values are above */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define JSON_INVALID_TOKEN \
|
#define JSON_INVALID_TOKEN \
|
||||||
|
@ -110,16 +110,16 @@ int json_walk(const char *json_string, int json_string_length,
|
||||||
* struct json_out abstracts output, allowing alternative printing plugins.
|
* struct json_out abstracts output, allowing alternative printing plugins.
|
||||||
*/
|
*/
|
||||||
struct json_out {
|
struct json_out {
|
||||||
int (*printer)(struct json_out *, const char *str, size_t len);
|
int (*printer)(struct json_out *, const char *str, size_t len);
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
char *buf;
|
char *buf;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t len;
|
size_t len;
|
||||||
} buf;
|
} buf;
|
||||||
void *data;
|
void *data;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
} u;
|
} u;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern int json_printer_buf(struct json_out *, const char *, size_t);
|
extern int json_printer_buf(struct json_out *, const char *, size_t);
|
||||||
|
|
|
@ -496,44 +496,44 @@ RAMFUNC int ManchesterDecoding_Thinfilm(uint8_t bit) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (IsManchesterModulationNibble1(Demod.twoBits >> Demod.syncBit)) { // modulation in first half
|
if (IsManchesterModulationNibble1(Demod.twoBits >> Demod.syncBit)) { // modulation in first half
|
||||||
if (IsManchesterModulationNibble2(Demod.twoBits >> Demod.syncBit)) { // ... and in second half = collision
|
if (IsManchesterModulationNibble2(Demod.twoBits >> Demod.syncBit)) { // ... and in second half = collision
|
||||||
if (!Demod.collisionPos) {
|
if (!Demod.collisionPos) {
|
||||||
Demod.collisionPos = (Demod.len << 3) + Demod.bitCount;
|
Demod.collisionPos = (Demod.len << 3) + Demod.bitCount;
|
||||||
}
|
}
|
||||||
} // modulation in first half only - Sequence D = 1
|
} // modulation in first half only - Sequence D = 1
|
||||||
|
Demod.bitCount++;
|
||||||
|
Demod.shiftReg = (Demod.shiftReg << 1) | 0x1; // in both cases, add a 1 to the shiftreg
|
||||||
|
if (Demod.bitCount == 8) { // if we decoded a full byte
|
||||||
|
Demod.output[Demod.len++] = (Demod.shiftReg & 0xff);
|
||||||
|
Demod.bitCount = 0;
|
||||||
|
Demod.shiftReg = 0;
|
||||||
|
}
|
||||||
|
Demod.endTime = Demod.startTime + 8 * (8 * Demod.len + Demod.bitCount + 1) - 4;
|
||||||
|
} else { // no modulation in first half
|
||||||
|
if (IsManchesterModulationNibble2(Demod.twoBits >> Demod.syncBit)) { // and modulation in second half = Sequence E = 0
|
||||||
Demod.bitCount++;
|
Demod.bitCount++;
|
||||||
Demod.shiftReg = (Demod.shiftReg << 1) | 0x1; // in both cases, add a 1 to the shiftreg
|
Demod.shiftReg = (Demod.shiftReg << 1); // add a 0 to the shiftreg
|
||||||
if (Demod.bitCount == 8) { // if we decoded a full byte
|
if (Demod.bitCount >= 8) { // if we decoded a full byte
|
||||||
Demod.output[Demod.len++] = (Demod.shiftReg & 0xff);
|
Demod.output[Demod.len++] = (Demod.shiftReg & 0xff);
|
||||||
Demod.bitCount = 0;
|
Demod.bitCount = 0;
|
||||||
Demod.shiftReg = 0;
|
Demod.shiftReg = 0;
|
||||||
}
|
}
|
||||||
Demod.endTime = Demod.startTime + 8 * (8 * Demod.len + Demod.bitCount + 1) - 4;
|
Demod.endTime = Demod.startTime + 8 * (8 * Demod.len + Demod.bitCount + 1);
|
||||||
} else { // no modulation in first half
|
} else { // no modulation in both halves - End of communication
|
||||||
if (IsManchesterModulationNibble2(Demod.twoBits >> Demod.syncBit)) { // and modulation in second half = Sequence E = 0
|
if (Demod.bitCount > 0) { // there are some remaining data bits
|
||||||
Demod.bitCount++;
|
Demod.shiftReg <<= (8 - Demod.bitCount); // left align the decoded bits
|
||||||
Demod.shiftReg = (Demod.shiftReg << 1); // add a 0 to the shiftreg
|
Demod.output[Demod.len++] = Demod.shiftReg & 0xff; // and add them to the output
|
||||||
if (Demod.bitCount >= 8) { // if we decoded a full byte
|
return true;
|
||||||
Demod.output[Demod.len++] = (Demod.shiftReg & 0xff);
|
}
|
||||||
Demod.bitCount = 0;
|
if (Demod.len) {
|
||||||
Demod.shiftReg = 0;
|
return true; // we are finished with decoding the raw data sequence
|
||||||
}
|
} else { // nothing received. Start over
|
||||||
Demod.endTime = Demod.startTime + 8 * (8 * Demod.len + Demod.bitCount + 1);
|
DemodReset();
|
||||||
} else { // no modulation in both halves - End of communication
|
|
||||||
if (Demod.bitCount > 0) { // there are some remaining data bits
|
|
||||||
Demod.shiftReg <<= (8 - Demod.bitCount); // left align the decoded bits
|
|
||||||
Demod.output[Demod.len++] = Demod.shiftReg & 0xff; // and add them to the output
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (Demod.len) {
|
|
||||||
return true; // we are finished with decoding the raw data sequence
|
|
||||||
} else { // nothing received. Start over
|
|
||||||
DemodReset();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false; // not finished yet, need more data
|
return false; // not finished yet, need more data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -655,7 +655,7 @@ void RAMFUNC SniffIso14443a(uint8_t param) {
|
||||||
Uart.len,
|
Uart.len,
|
||||||
Uart.startTime * 16 - DELAY_READER_AIR2ARM_AS_SNIFFER,
|
Uart.startTime * 16 - DELAY_READER_AIR2ARM_AS_SNIFFER,
|
||||||
Uart.endTime * 16 - DELAY_READER_AIR2ARM_AS_SNIFFER,
|
Uart.endTime * 16 - DELAY_READER_AIR2ARM_AS_SNIFFER,
|
||||||
Uart.parity,
|
Uart.parity,
|
||||||
true)) break;
|
true)) break;
|
||||||
}
|
}
|
||||||
/* ready to receive another command. */
|
/* ready to receive another command. */
|
||||||
|
|
1247
armsrc/nprintf.c
1247
armsrc/nprintf.c
File diff suppressed because it is too large
Load diff
|
@ -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
|
||||||
|
|
196
armsrc/string.c
196
armsrc/string.c
|
@ -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,97 +249,87 @@ 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')
|
||||||
{
|
base = 8;
|
||||||
if (*p == '0')
|
else
|
||||||
base = 8;
|
base = 10;
|
||||||
else
|
}
|
||||||
base = 10;
|
while (1) {
|
||||||
}
|
char c = *p;
|
||||||
while (1)
|
if ((c >= '0') && (c <= '9') && (c - '0' < base))
|
||||||
{
|
v = (v * base) + (c - '0');
|
||||||
char c = *p;
|
else if ((c >= 'a') && (c <= 'z') && (c - 'a' + 10 < base))
|
||||||
if ((c >= '0') && (c <= '9') && (c - '0' < base))
|
v = (v * base) + (c - 'a' + 10);
|
||||||
v = (v * base) + (c - '0');
|
else if ((c >= 'A') && (c <= 'Z') && (c - 'A' + 10 < base))
|
||||||
else if ((c >= 'a') && (c <= 'z') && (c - 'a' + 10 < base))
|
v = (v * base) + (c - 'A' + 10);
|
||||||
v = (v * base) + (c - 'a' + 10);
|
else
|
||||||
else if ((c >= 'A') && (c <= 'Z') && (c - 'A' + 10 < base))
|
break;
|
||||||
v = (v * base) + (c - 'A' + 10);
|
p++;
|
||||||
else
|
}
|
||||||
break;
|
|
||||||
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;
|
|
||||||
|
|
||||||
while (isspace(*p))
|
while (isspace(*p))
|
||||||
p++;
|
p++;
|
||||||
if (*p == '-')
|
if (*p == '-')
|
||||||
is_neg = 1, p++;
|
is_neg = 1, p++;
|
||||||
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')
|
||||||
{
|
base = 8;
|
||||||
if (*p == '0')
|
else
|
||||||
base = 8;
|
base = 10;
|
||||||
else
|
}
|
||||||
base = 10;
|
while (1) {
|
||||||
}
|
char c = *p;
|
||||||
while (1)
|
if ((c >= '0') && (c <= '9') && (c - '0' < base))
|
||||||
{
|
v = (v * base) + (c - '0');
|
||||||
char c = *p;
|
else if ((c >= 'a') && (c <= 'z') && (c - 'a' + 10 < base))
|
||||||
if ((c >= '0') && (c <= '9') && (c - '0' < base))
|
v = (v * base) + (c - 'a' + 10);
|
||||||
v = (v * base) + (c - '0');
|
else if ((c >= 'A') && (c <= 'Z') && (c - 'A' + 10 < base))
|
||||||
else if ((c >= 'a') && (c <= 'z') && (c - 'a' + 10 < base))
|
v = (v * base) + (c - 'A' + 10);
|
||||||
v = (v * base) + (c - 'a' + 10);
|
else
|
||||||
else if ((c >= 'A') && (c <= 'Z') && (c - 'A' + 10 < base))
|
break;
|
||||||
v = (v * base) + (c - 'A' + 10);
|
p++;
|
||||||
else
|
}
|
||||||
break;
|
if (is_neg)
|
||||||
p++;
|
v = -v;
|
||||||
}
|
if (out_p) *out_p = (char *)p;
|
||||||
if (is_neg)
|
return v;
|
||||||
v = -v;
|
|
||||||
if (out_p) *out_p = (char*)p;
|
|
||||||
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;
|
||||||
|
@ -36,8 +36,8 @@ static int print_barcode(uint8_t *barcode, const size_t barcode_len) {
|
||||||
|
|
||||||
PrintAndLogEx(SUCCESS, " checksum : "_YELLOW_("%02X %02X")"- %s", b2, b1, (isok) ? _GREEN_("OK") : _RED_("fail"));
|
PrintAndLogEx(SUCCESS, " checksum : "_YELLOW_("%02X %02X")"- %s", b2, b1, (isok) ? _GREEN_("OK") : _RED_("fail"));
|
||||||
PrintAndLogEx(SUCCESS, " Raw data : "_YELLOW_("%s"),
|
PrintAndLogEx(SUCCESS, " Raw data : "_YELLOW_("%s"),
|
||||||
sprint_hex(barcode, barcode_len)
|
sprint_hex(barcode, barcode_len)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
char s[45];
|
char s[45];
|
||||||
|
@ -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