diff --git a/unsegareborn/common.h b/unsegareborn/common.h new file mode 100644 index 0000000..853780f --- /dev/null +++ b/unsegareborn/common.h @@ -0,0 +1,11 @@ +#ifndef COMMON_H + +#include + +#define PATH_SEPARATOR "\\" +#define MAX_PATH_LENGTH 256 +#define MAX_FILENAME_LENGTH 256 +#define MKDIR(path) _mkdir(path) + +#endif // !COMMON_H + diff --git a/unsegareborn/exfat.c b/unsegareborn/exfat.c index 811c88d..7554727 100644 --- a/unsegareborn/exfat.c +++ b/unsegareborn/exfat.c @@ -3,9 +3,7 @@ #include #include #include -#include -#define MKDIR(path) _mkdir(path) -#define PATH_SEPARATOR "\\" +#include static bool create_directories(const char* path) { char temp[MAX_PATH_LENGTH]; @@ -56,6 +54,10 @@ static uint32_t get_next_cluster(ExfatContext* ctx, uint32_t cluster) { if (next >= 0xFFFFFFF8) { return 0; // end-of-chain } + if (next == 0) + { + return cluster + 1; // if cluster in FAT is 0, it means the cluster heap is continous (exfat only) + } return next; } @@ -147,6 +149,7 @@ static bool process_directory(ExfatContext* ctx, uint32_t start_cluster, const c int num_name_entries = (total_name_chars + 14) / 15; char full_name[MAX_FILENAME_LENGTH]; + wchar_t full_name_unicode[MAX_FILENAME_LENGTH]; int pos = 0; uint8_t* name_entry_ptr = entry_ptr + EXFAT_ENTRY_SIZE * 2; for (int k = 0; k < num_name_entries; k++) { @@ -154,11 +157,16 @@ static bool process_directory(ExfatContext* ctx, uint32_t start_cluster, const c int chars_in_this_entry = (total_name_chars - k * 15 < 15) ? (total_name_chars - k * 15) : 15; for (int j = 0; j < chars_in_this_entry; j++) { if (pos < MAX_FILENAME_LENGTH - 1) { - full_name[pos++] = (char)(name_entry->file_name[j] & 0xFF); + // you shouldn't cut of the wide char + full_name_unicode[pos++] = (wchar_t)name_entry->file_name[j]; } } } - full_name[pos] = '\0'; + full_name_unicode[pos] = L'\0'; + + // just convert it + _locale_t locale = _create_locale(LC_ALL, ""); + _wcstombs_l(full_name, full_name_unicode, MAX_FILENAME_LENGTH, locale); ExfatFileInfo file_info; memset(&file_info, 0, sizeof(file_info)); diff --git a/unsegareborn/exfat.h b/unsegareborn/exfat.h index 40b2471..2cd25f8 100644 --- a/unsegareborn/exfat.h +++ b/unsegareborn/exfat.h @@ -4,10 +4,9 @@ #include #include #include +#include "common.h" #define EXFAT_ENTRY_SIZE 32 -#define MAX_PATH_LENGTH 256 -#define MAX_FILENAME_LENGTH 256 #define EXFAT_ENTRY_EOD 0x00 #define EXFAT_ENTRY_BITMAP 0x81 diff --git a/unsegareborn/ntfs.c b/unsegareborn/ntfs.c index b045015..ab32c61 100644 --- a/unsegareborn/ntfs.c +++ b/unsegareborn/ntfs.c @@ -1,5 +1,7 @@ #include "ntfs.h" #include +#include +#define BUFFER_SIZE 65536 static uint16_t swap16(uint16_t value) { return ((value & 0xFF00) >> 8) | ((value & 0x00FF) << 8); @@ -58,11 +60,11 @@ static bool create_directories(const char* path) { } static void convert_name_to_ascii(const uint16_t* utf16_name, int name_length, char* ascii_name) { - int i; - for (i = 0; i < name_length && i < MAX_FILENAME_LENGTH - 1; i++) { - ascii_name[i] = (char)(utf16_name[i] & 0xFF); - } - ascii_name[i] = '\0'; + // just convert it + _locale_t locale = _create_locale(LC_ALL, ""); + int real_name_length = min(name_length, MAX_FILENAME_LENGTH - 1); + _wcstombs_l(ascii_name, utf16_name, real_name_length, locale); + ascii_name[real_name_length] = '\0'; } static bool ntfs_read(NTFSContext* ctx, void* buffer, uint64_t offset, size_t size) { @@ -810,8 +812,7 @@ bool ntfs_extract_all(NTFSContext* ctx) { printf("\rProgress: 100%%\n"); - printf("Extraction completed.\n", - (unsigned long long)processed_records, (unsigned long long)extracted_records); + printf("Extraction completed.\n"); free(record_buffer); return true; diff --git a/unsegareborn/ntfs.h b/unsegareborn/ntfs.h index 3e350c2..6293791 100644 --- a/unsegareborn/ntfs.h +++ b/unsegareborn/ntfs.h @@ -7,20 +7,15 @@ #include #include #include +#include "common.h" -#include -#define MKDIR(path) _mkdir(path) -#define PATH_SEPARATOR "\\" #define fseeko _fseeki64 #define ftello _ftelli64 #define VHD_FOOTER_SIZE 512 #define VHD_SECTOR_SIZE 512 #define VHD_BAT_ENTRY_RESERVED 0xFFFFFFFF -#define MAX_PATH_LENGTH 4096 #define NTFS_RECORD_SIZE 1024 -#define MAX_FILENAME_LENGTH 256 -#define BUFFER_SIZE 65536 #define MFT_RECORD_MAGIC "FILE" #define VHD_COOKIE "conectix" #define VHD_DYNAMIC_COOKIE "cxsparse"