read raw from the hd

This is a discussion on read raw from the hd within the Windows Programming forums, part of the Platform Specific Boards category; SUPER KOOL! I'll be spending a while looking at that (hopefully); recently I've been discovering that alot more things are ...

  1. #16
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,605
    SUPER KOOL! I'll be spending a while looking at that (hopefully); recently I've been discovering that alot more things are open-source that I knew.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  2. #17
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by Yarin View Post
    SUPER KOOL! I'll be spending a while looking at that (hopefully); recently I've been discovering that alot more things are open-source that I knew.
    Sourceforge is your friend.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  3. #18
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,605
    To bad, I looked through it this morning, and I see that all it does is look for fragmented files, then tell windows to move the file to a location where it fits whole, so windows ends up grouping all the fragments it's self. So there is no real "raw" reading going on. Defragers are simpler than I thought. Does anyone know how to read/write the FS? Kind of like biosdisk (but without biosdisk).
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  4. #19
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by Yarin View Post
    To bad, I looked through it this morning, and I see that all it does is look for fragmented files, then tell windows to move the file to a location where it fits whole, so windows ends up grouping all the fragments it's self. So there is no real "raw" reading going on. Defragers are simpler than I thought. Does anyone know how to read/write the FS? Kind of like biosdisk (but without biosdisk).
    You probably can't do it from usermode. And drivers ain't very easy to do.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  5. #20
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Give the following sample a try to see if it works..

    Code:
    #pragma comment( lib, "user32.lib" ) 
    #define _WIN32_WINNT 0x0500
    #include <windows.h>
    #include <stdio.h>
    #include <winioctl.h>
    
    int ReadSectors(DISK_GEOMETRY dg, HANDLE hDrive, DWORD dwCylinder, DWORD dwTrack, DWORD dwSector, DWORD dwNumberOfSectors)
    {
        DWORD dwCylinders, dwTracksPerCylinder, dwSectorsPerTrack, dwBytesPerSector;
        DWORD dwReadOffset = 0;
        DWORD dwNotUsed;
        char *pSectorData = NULL;
        dwCylinders = dg.Cylinders.QuadPart;
        dwTracksPerCylinder = dg.TracksPerCylinder;
        dwSectorsPerTrack = dg.SectorsPerTrack;
        dwBytesPerSector = dg.BytesPerSector;
        DWORD dwNumberOfBytesToRead = dwBytesPerSector;
        printf("Cylinders: %d\nTracks Per Cylinder: %d\nBytes Per Sector: %d\n\n", dwCylinders, dwTracksPerCylinder, dwBytesPerSector);
        dwNumberOfBytesToRead *= dwNumberOfSectors;
        dwReadOffset = ((dwCylinder * dwTracksPerCylinder + dwTrack) * dwSectorsPerTrack + dwSector) * dwBytesPerSector;
        LARGE_INTEGER liOffset = {dwReadOffset};
        pSectorData = (char*) malloc(dwNumberOfBytesToRead);
        memset(pSectorData, 0, sizeof pSectorData);
        if(dwReadOffset != 0)
        {
            if(!SetFilePointer(hDrive, (liOffset.LowPart), &liOffset.HighPart, FILE_BEGIN))
            {
                printf("SetFilePointer failed\n");
                return -1;
            }
        }   
        if(!ReadFile(hDrive, pSectorData, dwNumberOfBytesToRead, &dwNotUsed, NULL))
        {
            printf("readfile failed\n");
            return -2;
        }
        for(int iIndex = 0; iIndex <= dwNumberOfBytesToRead; iIndex++)
            printf("%02x", pSectorData[iIndex]);
        return 0;
    }
    
    
    int main(void)
    {
        int iDiskInputID = 0;
        char cDriveLetter = 'c';
        DISK_GEOMETRY dg;
        DWORD dwNotUsed;
        char cPhysicalDisk[24];
        ZeroMemory(cPhysicalDisk, 24);
        wsprintf(cPhysicalDisk, "\\\\.\\PhysicalDrive%d", iDiskInputID);
        HANDLE hDrive = CreateFile(cPhysicalDisk, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
        if (!DeviceIoControl(hDrive, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &dg, sizeof(dg), &dwNotUsed, (LPOVERLAPPED)NULL))
        {
            printf("Deviceiocontrol failed\n");
            return -3;
        }
        CloseHandle(hDrive);
        ZeroMemory(cPhysicalDisk, 24);
        wsprintf(cPhysicalDisk, "\\\\.\\%c:", cDriveLetter);
        hDrive = CreateFile(cPhysicalDisk, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
        return ReadSectors(dg, hDrive, 0 ,0 ,1 ,1);   
    }

  6. #21
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,605
    Thanks.
    I'm having some problems with my computer right now so it'll have to wait a bit.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I know the actual bytes read in a file read
    By pliang in forum C++ Programming
    Replies: 1
    Last Post: 06-08-2005, 04:23 PM
  2. What Would You Use To Read User Input?
    By djwicks in forum C Programming
    Replies: 11
    Last Post: 04-05-2005, 03:32 PM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. Read Array pro!!Plz help!!
    By Supra in forum C Programming
    Replies: 2
    Last Post: 03-04-2002, 02:49 PM
  5. Help! Can't read decimal number
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 09-07-2001, 02:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21