90 lines
3.3 KiB
C
90 lines
3.3 KiB
C
#include <stdio.h>
|
|
#include "readFile.h"
|
|
|
|
/* The worst array ever */
|
|
/* I guess it's better than doing a cycle */
|
|
ColorRange colorRanges[] = {
|
|
{0, 4, ANSI_COLOR_MAGENTA},
|
|
{4, 16, ANSI_COLOR_CYAN},
|
|
/* Key A */
|
|
{48, 54, ANSI_COLOR_GREEN},
|
|
{48 + 64, 54 + 64, ANSI_COLOR_GREEN},
|
|
{48 + 64 * 2, 54 + 64 * 2, ANSI_COLOR_GREEN},
|
|
{48 + 64 * 3, 54 + 64 * 3, ANSI_COLOR_GREEN},
|
|
{48 + 64 * 4, 54 + 64 * 4, ANSI_COLOR_GREEN},
|
|
{48 + 64 * 5, 54 + 64 * 5, ANSI_COLOR_GREEN},
|
|
{48 + 64 * 6, 54 + 64 * 6, ANSI_COLOR_GREEN},
|
|
{48 + 64 * 7, 54 + 64 * 7, ANSI_COLOR_GREEN},
|
|
{48 + 64 * 8, 54 + 64 * 8, ANSI_COLOR_GREEN},
|
|
{48 + 64 * 9, 54 + 64 * 9, ANSI_COLOR_GREEN},
|
|
{48 + 64 * 10, 54 + 64 * 10, ANSI_COLOR_GREEN},
|
|
{48 + 64 * 11, 54 + 64 * 11, ANSI_COLOR_GREEN},
|
|
{48 + 64 * 12, 54 + 64 * 12, ANSI_COLOR_GREEN},
|
|
{48 + 64 * 13, 54 + 64 * 13, ANSI_COLOR_GREEN},
|
|
{48 + 64 * 14, 54 + 64 * 14, ANSI_COLOR_GREEN},
|
|
{48 + 64 * 15, 54 + 64 * 15, ANSI_COLOR_GREEN},
|
|
/* Access Bits */
|
|
{54, 58, ANSI_COLOR_RED},
|
|
{54 + 64, 58 + 64, ANSI_COLOR_RED},
|
|
{54 + 64 * 2, 58 + 64 * 2, ANSI_COLOR_RED},
|
|
{54 + 64 * 3, 58 + 64 * 3, ANSI_COLOR_RED},
|
|
{54 + 64 * 4, 58 + 64 * 4, ANSI_COLOR_RED},
|
|
{54 + 64 * 5, 58 + 64 * 5, ANSI_COLOR_RED},
|
|
{54 + 64 * 6, 58 + 64 * 6, ANSI_COLOR_RED},
|
|
{54 + 64 * 7, 58 + 64 * 7, ANSI_COLOR_RED},
|
|
{54 + 64 * 8, 58 + 64 * 8, ANSI_COLOR_RED},
|
|
{54 + 64 * 9, 58 + 64 * 9, ANSI_COLOR_RED},
|
|
{54 + 64 * 10, 58 + 64 * 10, ANSI_COLOR_RED},
|
|
{54 + 64 * 11, 58 + 64 * 11, ANSI_COLOR_RED},
|
|
{54 + 64 * 12, 58 + 64 * 12, ANSI_COLOR_RED},
|
|
{54 + 64 * 13, 58 + 64 * 13, ANSI_COLOR_RED},
|
|
{54 + 64 * 14, 58 + 64 * 14, ANSI_COLOR_RED},
|
|
{54 + 64 * 15, 58 + 64 * 15, ANSI_COLOR_RED},
|
|
/* Key B */
|
|
{58, 64, ANSI_COLOR_YELLOW},
|
|
{58 + 64, 64 + 64, ANSI_COLOR_YELLOW},
|
|
{58 + 64 * 2, 64 + 64 * 2, ANSI_COLOR_YELLOW},
|
|
{58 + 64 * 3, 64 + 64 * 3, ANSI_COLOR_YELLOW},
|
|
{58 + 64 * 4, 64 + 64 * 4, ANSI_COLOR_YELLOW},
|
|
{58 + 64 * 5, 64 + 64 * 5, ANSI_COLOR_YELLOW},
|
|
{58 + 64 * 6, 64 + 64 * 6, ANSI_COLOR_YELLOW},
|
|
{58 + 64 * 7, 64 + 64 * 7, ANSI_COLOR_YELLOW},
|
|
{58 + 64 * 8, 64 + 64 * 8, ANSI_COLOR_YELLOW},
|
|
{58 + 64 * 9, 64 + 64 * 9, ANSI_COLOR_YELLOW},
|
|
{58 + 64 * 10, 64 + 64 * 10, ANSI_COLOR_YELLOW},
|
|
{58 + 64 * 11, 64 + 64 * 11, ANSI_COLOR_YELLOW},
|
|
{58 + 64 * 12, 64 + 64 * 12, ANSI_COLOR_YELLOW},
|
|
{58 + 64 * 13, 64 + 64 * 13, ANSI_COLOR_YELLOW},
|
|
{58 + 64 * 14, 64 + 64 * 14, ANSI_COLOR_YELLOW},
|
|
{58 + 64 * 15, 64 + 64 * 15, ANSI_COLOR_YELLOW},
|
|
};
|
|
|
|
int colorRangesCount = sizeof(colorRanges) / sizeof(ColorRange);
|
|
|
|
void readFile(FILE *file) {
|
|
int count = 0;
|
|
unsigned char buffer[256];
|
|
size_t bytesRead;
|
|
puts("\nColor meaning:");
|
|
printf(ANSI_COLOR_MAGENTA "\tUID of the Card\n");
|
|
printf(ANSI_COLOR_CYAN "\tManufacturer Info\n");
|
|
printf(ANSI_COLOR_GREEN "\tKey A\n");
|
|
printf(ANSI_COLOR_YELLOW "\tKey B\n");
|
|
printf(ANSI_COLOR_RED "\tAccess Bits\n\n");
|
|
while ((bytesRead = fread(buffer, 1, sizeof(buffer), file)) > 0) {
|
|
for (size_t i = 0; i < bytesRead; i++) {
|
|
const char* color = ANSI_COLOR_RESET;
|
|
for (int j = 0; j < colorRangesCount; j++) {
|
|
if (count >= colorRanges[j].start && count < colorRanges[j].end) {
|
|
color = colorRanges[j].color;
|
|
break;
|
|
}
|
|
}
|
|
printf("%s%02x ", color, buffer[i]);
|
|
if(++count % 16 == 0) {
|
|
puts("");
|
|
}
|
|
}
|
|
}
|
|
}
|