From b07d4ee83b77528c70938ccfcde1f557fd96c981 Mon Sep 17 00:00:00 2001 From: pox822 Date: Wed, 10 Jan 2024 21:54:24 +0100 Subject: [PATCH 1/5] fix warning strcpy and DES --- mac.c | 6 ++++++ mfterm.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mac.c b/mac.c index 7b57d9e..9e398e5 100644 --- a/mac.c +++ b/mac.c @@ -45,13 +45,19 @@ int compute_mac(const unsigned char* input, // Generate a key schedule. Don't be picky, allow bad keys. DES_key_schedule schedule; + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" DES_set_key_unchecked(&des_key, &schedule); + #pragma GCC diagnostic pop // IV is all zeroes unsigned char ivec[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; // Compute the DES in CBC + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" DES_ncbc_encrypt(padded_input, output, length, &schedule, &ivec, 1); + #pragma GCC diagnostic pop // Move up and truncate (we only want 8 bytes) for (int i = 0; i < 8; ++i) diff --git a/mfterm.c b/mfterm.c index 1baedf3..a2244d3 100644 --- a/mfterm.c +++ b/mfterm.c @@ -260,7 +260,7 @@ char* completion_sub_cmd_generator(const char* text, int state) { // Extract command and sub-command char buff[128]; - strncpy(buff, name, sizeof(buff)); + memcpy(buff, name, sizeof(buff)); char* cmd = strtok(buff, " "); char* sub = strtok(NULL, " "); From 360c3b8f4ceb4a23ffa39b87f552b18b5d7424fc Mon Sep 17 00:00:00 2001 From: pox822 Date: Sat, 13 Jan 2024 22:05:02 +0100 Subject: [PATCH 2/5] add warning instead memcpy --- mfterm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mfterm.c b/mfterm.c index a2244d3..756487b 100644 --- a/mfterm.c +++ b/mfterm.c @@ -260,7 +260,10 @@ char* completion_sub_cmd_generator(const char* text, int state) { // Extract command and sub-command char buff[128]; - memcpy(buff, name, sizeof(buff)); + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstringop-truncation" + strncpy(buff, name, sizeof(buff)); + #pragma GCC diagnostic pop char* cmd = strtok(buff, " "); char* sub = strtok(NULL, " "); From 29b074ee068103ec49e47e4cf15b666f0207e334 Mon Sep 17 00:00:00 2001 From: pox822 Date: Sun, 14 Jan 2024 11:53:06 +0100 Subject: [PATCH 3/5] Add changelog and News. Update README.md with install steps --- ChangeLog | 0 NEWS | 0 README.md | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 ChangeLog create mode 100644 NEWS diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..e69de29 diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index c11135d..a7492dc 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ terminal, will display the two bytes of data starting with byte 6. Building mfterm --------------- -Standard: ./configure; make; make install +Standard: ./autogen.sh; ./configure; make; make install See INSTALL file for details. From 6a4b94cfd267fa65ad170843b61536986d6a7753 Mon Sep 17 00:00:00 2001 From: pox Date: Sun, 14 Jan 2024 12:53:06 +0100 Subject: [PATCH 4/5] draft append --- tag.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/tag.c b/tag.c index 4b8e0d0..de72f8d 100644 --- a/tag.c +++ b/tag.c @@ -32,6 +32,7 @@ int load_mfd(const char* fn, mf_tag_t* tag); int save_mfd(const char* fn, const mf_tag_t* tag); int load_mfd(const char* fn, mf_tag_t* tag) { + FILE* mfd_file = fopen(fn, "rb"); if (mfd_file == NULL) { @@ -40,9 +41,32 @@ int load_mfd(const char* fn, mf_tag_t* tag) { } if (fread(tag, 1, sizeof(mf_tag_t), mfd_file) != sizeof(mf_tag_t)) { - printf("Could not read file: %s\n", fn); fclose(mfd_file); - return 1; + FILE *mfd_file_to_append = fopen(fn, "a"); + + if (mfd_file_to_append == NULL)) { + printf("Could not open file: %s\n", fn); + return 1; + } + + fseek(mfd_file_to_append, 0, SEEK_END); + long initialSize = currentSize; + long currentSize = ftell(file); + + while (currentSize < 4096) { + fputc('0', mfd_file_to_append); + currentSize++; + } + + fclose(mfd_file_to_append); + printf("0 appended for %s to %s\n", initialSize, currentSize); + + if (fread(tag, 1, sizeof(mf_tag_t), mfd_file) != sizeof(mf_tag_t)){ + printf("Could not read file: %s\n", fn); + return 1; + } + fclose(mfd_file); + return 0; } fclose(mfd_file); From 2b0075e5386f2bead756f43f6eb09c59e8a54d7a Mon Sep 17 00:00:00 2001 From: pox822 Date: Sun, 14 Jan 2024 14:53:27 +0100 Subject: [PATCH 5/5] append only on 1024 --- tag.c | 60 +++++++++++++++++++++++++++++++++++++++-------------------- tag.h | 2 +- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/tag.c b/tag.c index de72f8d..4a37510 100644 --- a/tag.c +++ b/tag.c @@ -31,46 +31,66 @@ void strip_non_auth_data(mf_tag_t* tag); int load_mfd(const char* fn, mf_tag_t* tag); int save_mfd(const char* fn, const mf_tag_t* tag); -int load_mfd(const char* fn, mf_tag_t* tag) { +int load_mfd_4k(const char *fn, mf_tag_t *tag); - FILE* mfd_file = fopen(fn, "rb"); +int append_to_4k(const char *fn); - if (mfd_file == NULL) { - printf("Could not open file: %s\n", fn); +int load_mfd(const char *fn, mf_tag_t *tag) { + int result = load_mfd_4k(fn, tag); + if (result == 0) { + return 0; + } + if (result == 2) { + return 1; + } + + if (append_to_4k(fn) == 1) { + return 1; + } + + if (load_mfd_4k(fn, tag) == 0) { + return 0; + } + printf("Could not read file: %s\n", fn); return 1; - } +} - if (fread(tag, 1, sizeof(mf_tag_t), mfd_file) != sizeof(mf_tag_t)) { - fclose(mfd_file); +int append_to_4k(const char *fn) { FILE *mfd_file_to_append = fopen(fn, "a"); - - if (mfd_file_to_append == NULL)) { + if (mfd_file_to_append == NULL) { printf("Could not open file: %s\n", fn); return 1; } fseek(mfd_file_to_append, 0, SEEK_END); + long currentSize = ftell(mfd_file_to_append); long initialSize = currentSize; - long currentSize = ftell(file); - + if (initialSize != 1024) { + printf("File needs to be either 1k or 4k\n"); + return 1; + } while (currentSize < 4096) { fputc('0', mfd_file_to_append); currentSize++; } fclose(mfd_file_to_append); - printf("0 appended for %s to %s\n", initialSize, currentSize); + printf("Zeros appended for %ld to %ld\n", initialSize, currentSize); + return 0; +} - if (fread(tag, 1, sizeof(mf_tag_t), mfd_file) != sizeof(mf_tag_t)){ - printf("Could not read file: %s\n", fn); - return 1; +int load_mfd_4k(const char *fn, mf_tag_t *tag) { + FILE* mfd_file = fopen(fn, "rb"); + if (mfd_file == NULL) { + printf("Could not open file: %s\n", fn); + return 2; } - fclose(mfd_file); - return 0; - } - fclose(mfd_file); - return 0; + if (fread(tag, 1, sizeof(mf_tag_t), mfd_file) == sizeof(mf_tag_t)) { + fclose(mfd_file); + return 0; + } + return 1; } int save_mfd(const char* fn, const mf_tag_t* tag) { diff --git a/tag.h b/tag.h index 5c1f27b..872fd12 100644 --- a/tag.h +++ b/tag.h @@ -68,7 +68,7 @@ void print_tag_bytes(size_t first_byte, size_t last_byte); void print_keys(const mf_tag_t* tag, mf_size_t size); void print_ac(const mf_tag_t* tag); -// Return a hex string representationon of the key +// Return a hex string representation of the key const char* sprint_key(const uint8_t* key); // Parse the string and set the key. Return the key, or NULL on error.