Merge pull request #2 from moqiaoduo/fix-extract

Fix extract
This commit is contained in:
Eren
2025-06-24 10:30:10 +03:00
5 changed files with 34 additions and 20 deletions
+11
View File
@@ -0,0 +1,11 @@
#ifndef COMMON_H
#include <direct.h>
#define PATH_SEPARATOR "\\"
#define MAX_PATH_LENGTH 256
#define MAX_FILENAME_LENGTH 256
#define MKDIR(path) _mkdir(path)
#endif // !COMMON_H
+13 -5
View File
@@ -3,9 +3,7 @@
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <direct.h>
#define MKDIR(path) _mkdir(path)
#define PATH_SEPARATOR "\\"
#include <locale.h>
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));
+1 -2
View File
@@ -4,10 +4,9 @@
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#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
+8 -7
View File
@@ -1,5 +1,7 @@
#include "ntfs.h"
#include <time.h>
#include <locale.h>
#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;
+1 -6
View File
@@ -7,20 +7,15 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "common.h"
#include <direct.h>
#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"