Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- #include <stdlib.h>
- typedef struct fat_BS
- {
- unsigned char bootjmp[3];
- unsigned char oem_name[8];
- unsigned short bytes_per_sector;
- unsigned char sectors_per_cluster;
- unsigned short reserved_sector_count;
- unsigned char table_count;
- unsigned short root_entry_count;
- unsigned short total_sectors_16;
- unsigned char media_type;
- unsigned short table_size_16;
- unsigned short sectors_per_track;
- unsigned short head_side_count;
- unsigned int hidden_sector_count;
- unsigned int total_sectors_32;
- }__attribute__((packed)) fat_BS_t;
- typedef struct boot_sec{
- unsigned char bios_int;
- unsigned char not_used;
- unsigned char extended_boot;
- unsigned int volume_number;
- unsigned char volume_label[11];
- unsigned char file_system[8];
- unsigned char not_used2[448];
- unsigned char signature_value[2];
- }__attribute__((packed)) boot_sec_struct;
- typedef struct root_dir{
- unsigned char filename_first_char;
- unsigned char filename[10];
- unsigned char file_attributes;
- unsigned char reserved;
- unsigned char file_creation_time;
- unsigned short creation_time;
- unsigned short creation_date;
- unsigned short access_date;
- unsigned short high_order_bytes;
- unsigned short modified_time;
- unsigned short modified_date;
- unsigned short low_order_bytes;
- unsigned int file_size;
- }__attribute__((packed)) root_dir_struct;
- int main() {
- struct fat_BS *test = malloc(sizeof(fat_BS_t));
- struct boot_sec *test2 = malloc(sizeof(boot_sec_struct));
- FILE *testing = fopen("fat12_c1.bin", "rb");
- fread(test, sizeof(fat_BS_t), 1, testing);
- fread(test2, sizeof(boot_sec_struct), 1, testing);
- int fat_size = test->table_size_16 * test->bytes_per_sector;
- unsigned char *test3 = malloc(fat_size);
- unsigned char *test4 = malloc(fat_size);
- int reserved_size = test->reserved_sector_count * test->bytes_per_sector;
- fseek(testing, reserved_size, SEEK_SET);
- fread(test3, fat_size, 1, testing);
- fread(test4, fat_size, 1, testing);
- struct root_dir *array_of_root = malloc(sizeof(root_dir_struct)*test->root_entry_count);
- fseek(testing, reserved_size + fat_size * (unsigned int) (test->table_count), SEEK_SET);
- for(int x = 0; x < test->root_entry_count; x++){
- fread((array_of_root+x), sizeof(root_dir_struct), 1, testing);
- }
- int curr_pos = ftell(testing);
- unsigned char *file_from_bin;
- for(int x = 0; x < test->root_entry_count; x++){
- fseek(testing, curr_pos, SEEK_SET);
- fseek(testing, (array_of_root->low_order_bytes -2 ) * test->bytes_per_sector, SEEK_CUR);
- file_from_bin = malloc(array_of_root->file_size+10);
- fread(file_from_bin, array_of_root->file_size, 1, testing);
- printf("%d", x);
- }
- fclose(testing);
- free(test);
- free(test2);
- free(test3);
- free(test4);
- free(file_from_bin);
- return 0;
- }
Add Comment
Please, Sign In to add comment