#include "type_fix.h" #pragma pack(1) uint64_t reverseByte(uint8_t* byte, unsigned int count) { uint64_t result = 0; int i; for (i = count - 1; i >= 0; i--) result = (result << 8) | byte[i]; return result; } int ReadSector(LPCWSTR drive, int readPoint, BYTE sector[512], long posSector) { int retCode = 0; DWORD bytesRead; HANDLE device = NULL; device = CreateFile(drive, // Drive to open GENERIC_READ, // Access mode FILE_SHARE_READ | FILE_SHARE_WRITE, // Share Mode NULL, // Security Descriptor OPEN_EXISTING, // How to create 0, // File attributes NULL); // Handle to template if (device == INVALID_HANDLE_VALUE) // Open Error { printf("CreateFile: %u\n", GetLastError()); return 1; } SetFilePointer(device, readPoint + 512 * posSector, NULL, FILE_BEGIN);//Set a Point to Read if (!ReadFile(device, sector, 512, &bytesRead, NULL)) { printf("ReadFile: %u\n", GetLastError()); } else { printf("Success!\n"); } } #pragma pack() void PrintFloppyInformationNTFS(NTFS _ntfs) { printf("Floppy Disk Information: \n"); printf("===========================\n"); printf("FAT: %s\n", _ntfs.OEMID); //Loai FAT printf("Bytes per sector: %d\n", reverseByte(_ntfs.Bytes_Sector, 2)); // So Byte cho 1 sector printf("Sector per cluster: %d\n", _ntfs.Sectors_Cluster); // So Sector cho 1 cluster printf("Reserved Sector: %d\n", reverseByte(_ntfs.Reserved_Sector, 2)); // So Sector vung boot Sector printf("Total Sectors : %lld\n", _ntfs.total_sectors); //Tong so sector, kich thuoc Volume printf("Logical Cluster Number for the file $MFT : %lld\n", _ntfs.Logical_MFT); // so cum cluster cho MFT printf("Logical Cluster Number for the file $MFTMirr : %lld\n", _ntfs.Logical_MFTMirr); // so cum cluster cho MFTMIRR } int PrintFloppyInformationFAT32(FAT32 fat32) { printf("FAT: %s\n", fat32.Fat_name); //Loai FAT printf("Bytes per sector: %d\n", reverseByte(fat32.bytePerSector, 2));// So Byte cho 1 sector printf("Sector per cluster: %d\n", fat32.sectorPerCluster);// So Sector cho 1 cluster printf("Reserved sectors (Sb): %d\n", reverseByte(fat32.reservedSector, 2));// So Sector vung boot Sector printf("FAT copies: %d\n", fat32.fatCopy); // So bang FAT printf("Total sector: %d\n", reverseByte(fat32.Total_sector, 4));//Tong so sector, kich thuoc Volume printf("Sector per FAT: %d\n", reverseByte(fat32.SectorperFAT, 4));// so sector cho 1 bang fat printf("Root directory entries: %d\n", reverseByte(fat32.rdetEntry, 2)); // So Entry cho bang RDET printf("first sector of FAT1: %d\n", reverseByte(fat32.reservedSector, 2)); // sector dau tien cua bang FAT1 int s = int(reverseByte(fat32.reservedSector, 2)) + int(reverseByte(fat32.SectorperFAT, 4)) * int(fat32.fatCopy); printf("first sector of RDET: %d\n", s); // sector dau tien cua vung RDET int d = s + int(reverseByte(fat32.rdetEntry, 2)); printf("first sector of DATA: %d\n", s); // sector dau tien cua vung DATA return s; } int main(int argc, TCHAR* argv[], TCHAR* envp[]) { BYTE sector[512]; NTFS ntfs; FAT32 fat32; ReadSector(L"\\\\.\\H:", 0, sector,0); memcpy(&ntfs, sector, 512); long size = 0; if (ntfs.OEMID[0] == 'N') PrintFloppyInformationNTFS(ntfs); else { memcpy(&fat32, sector, 512); size = PrintFloppyInformationFAT32(fat32); } printf("%d", size * 512); ReadSector(L"\\\\.\\H:", 0, sector, size); system("pause"); }