asdasdasdasdl;kkaspjoyui8d67hbgasd8us7aidsa

This commit is contained in:
Fijxu 2023-12-14 16:17:51 -03:00
commit f6defc402e
2 changed files with 98 additions and 0 deletions

2
Makefile Normal file
View File

@ -0,0 +1,2 @@
all:
gcc -g -o main main.c

96
main.c Normal file
View File

@ -0,0 +1,96 @@
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include <getopt.h>
#define ANSI_COLOR_RED "\x1b[31m"
#define ANSI_COLOR_GREEN "\x1b[32m"
#define ANSI_COLOR_YELLOW "\x1b[33m"
#define ANSI_COLOR_BLUE "\x1b[34m"
#define ANSI_COLOR_MAGENTA "\x1b[35m"
#define ANSI_COLOR_CYAN "\x1b[36m"
#define ANSI_COLOR_RESET "\x1b[0m"
void read_file(FILE *file) {
int count = 0;
unsigned char buffer[1000000];
size_t bytesRead;
while ((bytesRead = fread(buffer, 1, sizeof(buffer), file)) > 0) {
for (size_t i = 0; i < bytesRead; i++) {
printf("%02x ", buffer[i]);
if(++count % 16 == 0) {
puts("");
}
}
}
}
void get_size(FILE *file, int argc, char *argv[]) {
fseek(file, 0L, SEEK_END);
long bytes = ftell(file);
fseek(file, 0L, SEEK_SET);
if (bytes == 1024) {
printf("Bytes of %s: %ld\n", argv[argc-1], bytes);
puts("This looks like a Mifare Classic 1K dump file");
} else if (bytes == 4096) {
printf("Bytes of %s: %ld\n", argv[argc-1], bytes);
puts("This lokks like a Mifare Classic 4K dump file");
} else {
printf("Bytes of %s: %ld\n", argv[argc-1], bytes);
printf(ANSI_COLOR_RED "This doesn't look like a Mifare Classic 1K or 4K at all\n" ANSI_COLOR_RESET);
}
}
int main (int argc, char *argv[]) {
if (argc <= 1)
{
printf("Usage:\n %s [OPTION]... [FILE]\n\n", argv[0]);
puts("Tool to modify Mifare Classic dump files");
puts("\nOptions:");
puts("\t-s display the size of the file in bytes\n");
exit(EXIT_SUCCESS);
}
struct option longopts[] = {
{"size", no_argument, NULL, 's'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
{NULL, no_argument, NULL, 0}
};
FILE *file;
unsigned char ch;
char *binfile = malloc(64 * sizeof(char));
if ( binfile == NULL ) {
puts("Failed to allocate memory");
exit(EXIT_FAILURE);
}
file = fopen(argv[argc-1], "rb");
if( file == NULL )
{
perror("Error while opening the file");
exit(EXIT_FAILURE);
}
int args;
while ((args = getopt_long(argc, argv, "s", longopts, NULL)) != -1) {
switch (args) {
case 's':
{
get_size(file, argc, argv);
}
default:
exit(EXIT_SUCCESS);
}
}
read_file(file);
fclose(file);
free(binfile);
exit(EXIT_SUCCESS);
}