RAW Zugriff auf Platte unter Win9x



  • Hallo Leute,

    habe diesen Coden zum Auslesen des Master Boot Rekord:

    char mbr[512];
    char device[] = ""\\\\.\\PhysicalDrive0";
    DWORD to_read, read;
    HANDLE hFile;
    hFile = CreateFile(device, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0,NULL);
    to_read = sizeof(mbr);
    ReadFile(hFile, mbr, to_read, &read, NULL);
    

    Diese Methode funzt aber leider nur unter WinNT, 2000, WinXP.
    Hat jemand von Euch ne Ahnung wie diese Problematik unter Win9x gehen könnte.

    Vielen Dank für Eure Tips..

    Torsten



  • Da gibt es den Artikel Q125712 in der KB. Den finde ich online aber gerade auch nicht. Deswegen gibt es hier jetzt einfach mal ein Copy&Paste. Ansonsten hilft Dir vielleicht auch dieser Artikel:
    http://www.codeproject.com/system/cfloppydisk.asp

    SUMMARY
    Windows 95 does not support opening disk drives or disk partitions with CreateFile(), as Windows NT does. Windows 95 also does not support the DeviceIoControl() IOCTL APIs, as Windows NT does. Instead, low-level disk access in Windows 95 can be achieved through DeviceIoControl() calls to the VWIN32 VxD.

    MORE INFORMATION
    Windows NT supports obtaining a handle to a disk drive or disk partition by using CreateFile() and specifying the name of the drive or partition as the filename (e.g. "\.\PHYSICALDRIVE0" or "\.\C:"). This handle can then be used in the DeviceIoControl() Win32 API.

    Windows 95 differs in the following ways:

    1. Obtaining a disk drive or disk partition handle is not supported. The call to CreateFile() will fail, and GetLastError() will return error code 2, ERROR_FILE_NOT_FOUND.

    2. The DeviceIoControl IOCTL functions (such as IOCTL_DISK_FORMAT_TRACKS) are not supported. These IOCTLs require the handle to a disk drive or disk partition and thus can't be used.

    3. DeviceIoControl() is called using a handle to a VxD rather than a handle to a disk drive or disk partition. Obtain a handle to VWIN32.VXD by using CreateFile( "\\\.\\VWIN32", ... ). Use this handle in calls to DeviceIoControl() to perform volume locking (Int 21h Function 440Dh, Subfunctions 4Ah and 4Bh), and then to perform BIOS calls (Int 13h), Absolute Disk Reads/Writes (Int 25h and 26h), or MS-DOS IOCTL functions (Int 21h Function 440Dh).

    REFERENCES
    For information on using DeviceIoControl() in Windows 95 and the IOCTL functions supported by the VWIN32 VxD, please see the help file "Windows 95 Guide to Programming". Go to "Using Windows 95 features" and select "Using Device I/O Control."

    For information on using CreateFile() to obtain disk drive or disk partition handles under Windows NT, see the description for CreateFile() in the Microsoft Windows Programmer's Reference, Volume 3.

    For information on Windows 95 extensions to the MS-DOS interrupts, please see the help file "Windows 95 Guide to Programming." Go to "Using Microsoft MS-DOS Extensions" and select "Exclusive Volume Locking", then "About Exclusive Volume Locking", then "Exclusive Use Lock".

    For a complete list of IOCTLs, see the description of the DeviceIoControl() function in the Microsoft Windows Programmer's Reference, Volume 3.



  • Moin, Moin...

    Hier ist ein kleines Beispielprogramm zur Demonstration. Es liest per Interrupt 13h Sektoren der Diskette. Geht natürlich auch mit Festplatte.

    // Demoprogramm, das einen Sektor direkt von der Diskette liest
    
    #include <windows.h>
    #include <iostream.h>
    #include <stdlib.h>
    
    #define VWIN32_DIOC_DOS_INT13 4 
    
    #pragma pack(1)
    typedef struct _DIOC_REGISTERS
    {
      DWORD reg_EBX;
      DWORD reg_EDX;
      DWORD reg_ECX;
      DWORD reg_EAX;
      DWORD reg_EDI;
      DWORD reg_ESI;
      DWORD reg_Flags;
    } DIOC_REGISTERS, *PDIOC_REGISTERS;
    
    DIOC_REGISTERS  rp;
    HANDLE          hDevice;
    DWORD           cb;
    BOOL            fResult;
    
    unsigned char   sector[512];
    
    int main()
    {
      hDevice = CreateFile("\\\\.\\vwin32", 0, 0, NULL, 0, FILE_FLAG_DELETE_ON_CLOSE, NULL);
    
      rp.reg_EAX = 0x0201;                 // ah = Funktion 02h(Sektor lesen) , al = Anzahl der Sektoren
                                            // ah = 03(Sektor schreiben)
      rp.reg_EBX = (DWORD)sector;          // Zeiger auf den Puffer, der Daten enthält
      rp.reg_ECX = 0x0002;                 // ch = Spurnummer(0 - 79), cl = Sektornummer(1 - N)
      rp.reg_EDX = 0x0000;                 // dh = Diskettenseite, dl = Diskettenlaufwerknummer
                                            // dl = 0x00->A, 0x01->B, 0x80->HD 1, 0x81->HD 2
      rp.reg_Flags = 0x0000; 
    
        fResult = DeviceIoControl(hDevice, VWIN32_DIOC_DOS_INT13, &rp, sizeof(rp), &rp, sizeof(rp), &cb, 0);
    
        if(!fResult || (rp.reg_Flags & 0x0001))
        {
          cout << "FEHLER: Sektor konnte nicht gelesen werden..." << endl << endl;
        }
        else
        {
          cout << "Sektor gelesen..." << endl << endl;
        }
    
        CloseHandle(hDevice);
      }
    
      system("PAUSE");
      return 0;
    }
    

    Für Festplattenzugriff müssen die Parameter in den Registern entsprechend angepasst werden. Siehe hierzu BIOS-Funktion 02h bzw. 03h des Interrupt 013h.

    Ciao...

    [ Dieser Beitrag wurde am 12.12.2002 um 08:07 Uhr von Kal El editiert. ]



  • Das Beispiel ist sehr gut, vielen Dank..
    Aber diese Möglichkeit Sektoren auszulesen funktioniert nun wieder unter Win200, NT, u. XP nicht.
    Gibt es eigentlich auch ne allgemeine Methode auf Festplatten zuzugreifen und Sektoren auszulesen, welche mit allen Microsoft Betriebssystemen funktonieren?

    Torsten



  • Moin, Moin...

    Soweit ich weiß gibt es keine Möglichkeit, die auf allen Windows-Systemen läuft. Du könntest aber am Anfang Deines Programms eine Abfrage machen, welches OS läuft und dann die entsprechende Routine für Win 9x bzw. Win2k/XP aufrufen.

    Ciao...



  • Stichwort GetVersion, GetVersionEx.


Anmelden zum Antworten