summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2020-08-30 11:21:20 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2020-09-01 19:09:12 +0200
commit74f7cf79a3eb3b6b29609412a1f05de94b9bc9a4 (patch)
tree830d0c4333ee9462fbc2d15a7ac3e62a6e67e26c
parentb1376c4f9658c603c27e659d99c3a4c0ef4463e6 (diff)
Move low-level structure from fat.h to fat_common.h
-rw-r--r--src/fat.c1
-rw-r--r--src/fat.h112
-rw-r--r--src/fat_common.c1
-rw-r--r--src/fat_common.h110
-rw-r--r--src/fatn.c1
-rw-r--r--src/file_dir.c5
-rw-r--r--src/file_fat.c3
-rw-r--r--src/hpfs.c2
8 files changed, 118 insertions, 117 deletions
diff --git a/src/fat.c b/src/fat.c
index 70c78bf..667c778 100644
--- a/src/fat.c
+++ b/src/fat.c
@@ -43,7 +43,6 @@
#include "intrf.h"
#include "log.h"
#include "log_part.h"
-#include "fat_common.h"
#include "dir.h"
#include "fat_dir.h"
diff --git a/src/fat.h b/src/fat.h
index b6a043f..ea63cd7 100644
--- a/src/fat.h
+++ b/src/fat.h
@@ -26,93 +26,7 @@
extern "C" {
#endif
-#define FAT1X_PART_NAME 0x2B
-#define FAT32_PART_NAME 0x47
-#define FAT_NAME1 0x36
-#define FAT_NAME2 0x52 /* FAT32 only */
-#define NTFS_NAME 0x03
-#define OS2_NAME 0x03
-
-/*
- * FAT partition boot sector information, taken from the Linux
- * kernel sources.
- */
-
-struct fat_boot_sector {
- uint8_t ignored[3]; /* 0x00 Boot strap short or near jump */
- int8_t system_id[8]; /* 0x03 Name - can be used to special case
- partition manager volumes */
- uint8_t sector_size[2]; /* 0x0B bytes per logical sector */
- uint8_t sectors_per_cluster; /* 0x0D sectors/cluster */
- uint16_t reserved; /* 0x0E reserved sectors */
- uint8_t fats; /* 0x10 number of FATs */
- uint8_t dir_entries[2]; /* 0x11 root directory entries */
- uint8_t sectors[2]; /* 0x13 number of sectors */
- uint8_t media; /* 0x15 media code (unused) */
- uint16_t fat_length; /* 0x16 sectors/FAT */
- uint16_t secs_track; /* 0x18 sectors per track */
- uint16_t heads; /* 0x1A number of heads */
- uint32_t hidden; /* 0x1C hidden sectors (unused) */
- uint32_t total_sect; /* 0x20 number of sectors (if sectors == 0) */
-
- /* The following fields are only used by FAT32 */
- uint32_t fat32_length; /* 0x24=36 sectors/FAT */
- uint16_t flags; /* 0x28 bit 8: fat mirroring, low 4: active fat */
- uint8_t version[2]; /* 0x2A major, minor filesystem version */
- uint32_t root_cluster; /* 0x2C first cluster in root directory */
- uint16_t info_sector; /* 0x30 filesystem info sector */
- uint16_t backup_boot; /* 0x32 backup boot sector */
- uint8_t BPB_Reserved[12]; /* 0x34 Unused */
- uint8_t BS_DrvNum; /* 0x40 */
- uint8_t BS_Reserved1; /* 0x41 */
- uint8_t BS_BootSig; /* 0x42 */
- uint8_t BS_VolID[4]; /* 0x43 */
- uint8_t BS_VolLab[11]; /* 0x47 */
- uint8_t BS_FilSysType[8]; /* 0x52=82*/
-
- /* */
- uint8_t nothing[420]; /* 0x5A */
- uint16_t marker;
-} __attribute__ ((gcc_struct, __packed__));
-
-struct fat_fsinfo {
- uint32_t leadsig; /* 0x41615252 */
- uint8_t reserved1[480];
- uint32_t strucsig; /* 0x61417272 */
- uint32_t freecnt; /* free clusters 0xfffffffff if unknown */
- uint32_t nextfree; /* next free cluster */
- uint8_t reserved3[12];
- uint32_t magic3; /* 0xAA550000 */
-} __attribute__ ((gcc_struct, __packed__));
-
-struct msdos_dir_entry {
- int8_t name[8]; /* 00 name and extension */
- int8_t ext[3];
- uint8_t attr; /* 0B attribute bits */
- uint8_t lcase; /* 0C Case for base and extension */
- uint8_t ctime_ms; /* 0D Creation time, milliseconds */
- uint16_t ctime; /* 0E Creation time */
- uint16_t cdate; /* 10 Creation date */
- uint16_t adate; /* 12 Last access date */
- uint16_t starthi; /* 14 High 16 bits of cluster in FAT32 */
- uint16_t time; /* 16 time, date and first cluster */
- uint16_t date; /* 18 */
- uint16_t start; /* 1A */
- uint32_t size; /* 1C file size (in bytes) */
-} __attribute__ ((gcc_struct, __packed__));
-
-/* Up to 13 characters of the name */
-struct msdos_dir_slot {
- uint8_t id; /* 00 sequence number for slot */
- uint8_t name0_4[10]; /* 01 first 5 characters in name */
- uint8_t attr; /* 0B attribute byte */
- uint8_t reserved; /* 0C always 0 */
- uint8_t alias_checksum; /* 0D checksum for 8.3 alias */
- uint8_t name5_10[12]; /* 0E 6 more characters in name */
- uint16_t start; /* 1A starting cluster number, 0 in long slots */
- uint8_t name11_12[4]; /* 1C last 2 characters in name */
-};
-
+#include "fat_common.h"
/*@
@ requires \valid(disk);
@ requires \valid_read(partition);
@@ -198,29 +112,6 @@ unsigned long int fat32_get_free_count(const unsigned char *boot_fat32, const un
@*/
unsigned long int fat32_get_next_free(const unsigned char *boot_fat32, const unsigned int sector_size);
-#define DELETED_FLAG 0xe5 /* marks file as deleted when in name[0] */
-#define IS_FREE(n) (!*(n) || *(const unsigned char *) (n) == DELETED_FLAG)
-#define ATTR_RO 1 /* read-only */
-#define ATTR_HIDDEN 2 /* hidden */
-#define ATTR_SYS 4 /* system */
-#define ATTR_VOLUME 8 /* volume label */
-#define ATTR_DIR 16 /* directory */
-#define ATTR_ARCH 32 /* archived */
-
-#define ATTR_NONE 0 /* no attribute bits */
-#define ATTR_UNUSED (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
- /* attribute bits that are copied "as is" */
-#define ATTR_EXT (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
-#define ATTR_EXT_MASK (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME | ATTR_DIR | ATTR_ARCH)
- /* bits that are used by the Windows 95/Windows NT extended FAT */
-#define FAT12_BAD 0x0FF7
-#define FAT12_EOC 0x0FF8
-#define FAT16_BAD 0xFFF7
-#define FAT16_EOC 0xFFF8
-#define FAT32_BAD 0x0FFFFFF7
-#define FAT32_EOC 0x0FFFFFF8
-#define FAT1x_BOOT_SECTOR_SIZE 0x200
-
/*@
@ requires \valid(disk);
@ requires \valid_read(fat_header);
@@ -263,6 +154,7 @@ int check_OS2MB(disk_t *disk, partition_t *partition, const int verbose);
@ requires \valid_read(name);
@*/
int check_VFAT_volume_name(const char *name, const unsigned int max_size);
+
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif
diff --git a/src/fat_common.c b/src/fat_common.c
index ab1f181..2546026 100644
--- a/src/fat_common.c
+++ b/src/fat_common.c
@@ -28,7 +28,6 @@
#endif
#include "types.h"
#include "common.h"
-#include "fat.h"
#include "fat_common.h"
unsigned int fat_sector_size(const struct fat_boot_sector *fat_header)
diff --git a/src/fat_common.h b/src/fat_common.h
index 780b5cc..67fcc6b 100644
--- a/src/fat_common.h
+++ b/src/fat_common.h
@@ -24,6 +24,116 @@
#ifdef __cplusplus
extern "C" {
#endif
+
+#define FAT1X_PART_NAME 0x2B
+#define FAT32_PART_NAME 0x47
+#define FAT_NAME1 0x36
+#define FAT_NAME2 0x52 /* FAT32 only */
+
+#define DELETED_FLAG 0xe5 /* marks file as deleted when in name[0] */
+#define IS_FREE(n) (!*(n) || *(const unsigned char *) (n) == DELETED_FLAG)
+#define ATTR_RO 1 /* read-only */
+#define ATTR_HIDDEN 2 /* hidden */
+#define ATTR_SYS 4 /* system */
+#define ATTR_VOLUME 8 /* volume label */
+#define ATTR_DIR 16 /* directory */
+#define ATTR_ARCH 32 /* archived */
+
+#define ATTR_NONE 0 /* no attribute bits */
+#define ATTR_UNUSED (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
+ /* attribute bits that are copied "as is" */
+#define ATTR_EXT (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
+#define ATTR_EXT_MASK (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME | ATTR_DIR | ATTR_ARCH)
+ /* bits that are used by the Windows 95/Windows NT extended FAT */
+#define FAT12_BAD 0x0FF7
+#define FAT12_EOC 0x0FF8
+#define FAT16_BAD 0xFFF7
+#define FAT16_EOC 0xFFF8
+#define FAT32_BAD 0x0FFFFFF7
+#define FAT32_EOC 0x0FFFFFF8
+#define FAT1x_BOOT_SECTOR_SIZE 0x200
+
+/*
+ * FAT partition boot sector information, taken from the Linux
+ * kernel sources.
+ */
+
+struct fat_boot_sector {
+ uint8_t ignored[3]; /* 0x00 Boot strap short or near jump */
+ int8_t system_id[8]; /* 0x03 Name - can be used to special case
+ partition manager volumes */
+ uint8_t sector_size[2]; /* 0x0B bytes per logical sector */
+ uint8_t sectors_per_cluster; /* 0x0D sectors/cluster */
+ uint16_t reserved; /* 0x0E reserved sectors */
+ uint8_t fats; /* 0x10 number of FATs */
+ uint8_t dir_entries[2]; /* 0x11 root directory entries */
+ uint8_t sectors[2]; /* 0x13 number of sectors */
+ uint8_t media; /* 0x15 media code (unused) */
+ uint16_t fat_length; /* 0x16 sectors/FAT */
+ uint16_t secs_track; /* 0x18 sectors per track */
+ uint16_t heads; /* 0x1A number of heads */
+ uint32_t hidden; /* 0x1C hidden sectors (unused) */
+ uint32_t total_sect; /* 0x20 number of sectors (if sectors == 0) */
+
+ /* The following fields are only used by FAT32 */
+ uint32_t fat32_length; /* 0x24=36 sectors/FAT */
+ uint16_t flags; /* 0x28 bit 8: fat mirroring, low 4: active fat */
+ uint8_t version[2]; /* 0x2A major, minor filesystem version */
+ uint32_t root_cluster; /* 0x2C first cluster in root directory */
+ uint16_t info_sector; /* 0x30 filesystem info sector */
+ uint16_t backup_boot; /* 0x32 backup boot sector */
+ uint8_t BPB_Reserved[12]; /* 0x34 Unused */
+ uint8_t BS_DrvNum; /* 0x40 */
+ uint8_t BS_Reserved1; /* 0x41 */
+ uint8_t BS_BootSig; /* 0x42 */
+ uint8_t BS_VolID[4]; /* 0x43 */
+ uint8_t BS_VolLab[11]; /* 0x47 */
+ uint8_t BS_FilSysType[8]; /* 0x52=82*/
+
+ /* */
+ uint8_t nothing[420]; /* 0x5A */
+ uint16_t marker;
+} __attribute__ ((gcc_struct, __packed__));
+
+struct fat_fsinfo {
+ uint32_t leadsig; /* 0x41615252 */
+ uint8_t reserved1[480];
+ uint32_t strucsig; /* 0x61417272 */
+ uint32_t freecnt; /* free clusters 0xfffffffff if unknown */
+ uint32_t nextfree; /* next free cluster */
+ uint8_t reserved3[12];
+ uint32_t magic3; /* 0xAA550000 */
+} __attribute__ ((gcc_struct, __packed__));
+
+struct msdos_dir_entry {
+ int8_t name[8]; /* 00 name and extension */
+ int8_t ext[3];
+ uint8_t attr; /* 0B attribute bits */
+ uint8_t lcase; /* 0C Case for base and extension */
+ uint8_t ctime_ms; /* 0D Creation time, milliseconds */
+ uint16_t ctime; /* 0E Creation time */
+ uint16_t cdate; /* 10 Creation date */
+ uint16_t adate; /* 12 Last access date */
+ uint16_t starthi; /* 14 High 16 bits of cluster in FAT32 */
+ uint16_t time; /* 16 time, date and first cluster */
+ uint16_t date; /* 18 */
+ uint16_t start; /* 1A */
+ uint32_t size; /* 1C file size (in bytes) */
+} __attribute__ ((gcc_struct, __packed__));
+
+/* Up to 13 characters of the name */
+struct msdos_dir_slot {
+ uint8_t id; /* 00 sequence number for slot */
+ uint8_t name0_4[10]; /* 01 first 5 characters in name */
+ uint8_t attr; /* 0B attribute byte */
+ uint8_t reserved; /* 0C always 0 */
+ uint8_t alias_checksum; /* 0D checksum for 8.3 alias */
+ uint8_t name5_10[12]; /* 0E 6 more characters in name */
+ uint16_t start; /* 1A starting cluster number, 0 in long slots */
+ uint8_t name11_12[4]; /* 1C last 2 characters in name */
+};
+
+
/*@
@ requires \valid_read(entry);
@ assigns \nothing;
diff --git a/src/fatn.c b/src/fatn.c
index f86a704..c1ccf4f 100644
--- a/src/fatn.c
+++ b/src/fatn.c
@@ -32,7 +32,6 @@
#include "intrfn.h"
#include "fat.h"
#include "fatn.h"
-#include "fat_common.h"
int dump_fat_info_ncurses(const struct fat_boot_sector*fh1, const upart_type_t upart_type, const unsigned int sector_size)
{
diff --git a/src/file_dir.c b/src/file_dir.c
index a91bdaa..84f82f0 100644
--- a/src/file_dir.c
+++ b/src/file_dir.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_dir)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -33,10 +34,9 @@
#include "types.h"
#include "filegen.h"
#include "common.h"
-#include "fat.h"
+#include "fat_common.h"
#include "dir.h"
#include "fat_dir.h"
-#include "fat_common.h"
static void register_header_check_dir(file_stat_t *file_stat);
static int header_check_dir(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new);
@@ -119,3 +119,4 @@ static void register_header_check_dir(file_stat_t *file_stat)
{
register_header_check(0, ". ", 8+3, &header_check_dir, file_stat);
}
+#endif
diff --git a/src/file_fat.c b/src/file_fat.c
index 501b011..bd27eab 100644
--- a/src/file_fat.c
+++ b/src/file_fat.c
@@ -20,6 +20,7 @@
*/
+#if !defined(SINGLE_FORMAT) || defined(SINGLE_FORMAT_fat)
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -35,7 +36,6 @@
#include "filegen.h"
#include "log.h"
#include "memmem.h"
-#include "fat.h"
#include "fat_common.h"
static void register_header_check_fat(file_stat_t *file_stat);
@@ -136,3 +136,4 @@ static int header_check_fat(const unsigned char *buffer, const unsigned int buff
file_recovery_new->file_check=&file_check_size;
return 1;
}
+#endif
diff --git a/src/hpfs.c b/src/hpfs.c
index 645e810..e825525 100644
--- a/src/hpfs.c
+++ b/src/hpfs.c
@@ -51,7 +51,7 @@ static int test_HPFS(const disk_t *disk_car, const struct fat_boot_sector *hpfs_
const char*buffer=(const char*)hpfs_header;
if(le16(hpfs_header->marker)==0xAA55)
{
- if(memcmp(buffer+OS2_NAME,"IBM",3)==0)
+ if(memcmp(buffer+3,"IBM",3)==0)
{ /* D'apres une analyse de OS2 sur systeme FAT...
FAT_NAME1=FAT
*/