線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1347
推到 Plurk!
推到 Facebook!

如何在9x/Me/Dos下直接讀取硬碟的磁區

尚未結案
jimmy_and_you
初階會員


發表:20
回覆:74
積分:33
註冊:2003-05-12

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-05-06 13:07:53 IP:61.70.xxx.xxx 未訂閱
之前參考了一下下面的連結,寫了一些code在98 se下,想用int 13h的功能直接讀寫硬碟磁區,卻發現怎麼試都試不出來,在 href="http://delphi.ktop.com.tw/topic.php?topic_id=32307">http://delphi.ktop.com.tw/topic.php?topic_id=32307 http://delphi.ktop.com.tw/topic.php?topic_id=31797 其中第一個鏈結有關於int 13h AH=42h source code,可是要用到1,2個dll,所以我沒用... 中斷向量參考列表 http://www.delorie.com/djgpp/doc/rbinter/ix/ Source Code :
//---------------------------------------------------------------------------    #include 
#pragma hdrstop    #include "Unit1.h"
#include 
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"    typedef struct
{
    unsigned long   EBX;
    unsigned long   EDX;
    unsigned long   ECX;
    unsigned long   EAX;
    unsigned long   EDI;
    unsigned long   ESI;
    unsigned long   Flags;
}T32Regs, *P32Regs;    typedef struct
{
unsigned char        size;
unsigned char        reserved0;
unsigned short        Sectors;
unsigned short        buf_OFF;
unsigned short        buf_SEG;
unsigned int        LBA_Address;
unsigned int        LBA_Address_High;
}TestStruct;    #define     FILE_FLAG_DELETE_ON_CLOSE   (0x04000000)
#define     VWIN32_DIOC_DOS_IOCTL           (1)  //{ MS-DOS Int 21h 44xxh functions call }
#define     VWIN32_DIOC_DOS_INT25           (2)  //{ MS-DOS Int 25h function call }
#define     VWIN32_DIOC_DOS_INT26           (3)  //{ MS-DOS Int 26h function call }
#define     VWIN32_DIOC_DOS_INT13                (4)  //{ MS-DOS Int 13h functions call }
#define     VWIN32_DIOC_DOS_DRIVEINFO        (6)        //{MS-DOS Int 21h function 730X}    HANDLE    hDeviceHandle;
T32Regs   reg;    TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{    }
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
        unsigned char   divice=0;  //HD - 0            DWORD cb;
        AnsiString str;            unsigned char boot[512];
        memset(boot, 512, 0);        hDeviceHandle = CreateFile("\\\\.\\VWIN32",GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);        if( hDeviceHandle!=INVALID_HANDLE_VALUE )
    {                TestStruct IO_Info;
            IO_Info.reserved0 = 0;
            IO_Info.LBA_Address = 0;
            IO_Info.LBA_Address_High = 0;
                IO_Info.size = 16;
                IO_Info.Sectors = 1;
                IO_Info.buf_OFF =  ( ((unsigned int)boot) & 0x0000ffff);
                IO_Info.buf_SEG = ( ((unsigned int)boot) & 0xffff0000)>>16;                reg.EAX=  0x4200;
            reg.EDX = 0x80;
            reg.ESI = (WORD) (&IO_Info);
            reg.Flags = 0;                bool ans = DeviceIoControl(hDeviceHandle,VWIN32_DIOC_DOS_INT13,®,sizeof(reg),®,sizeof(reg),&cb,NULL);
            if ( (reg.Flags&1)==1 )
            {
                    AnsiString tmp;
                    tmp.printf("AX = 0xX" , reg.EAX&0xffff);
                    Memo1->Clear();
                    Memo1->Lines->Add(tmp);
                    if( ans )
            {
                        DWORD  error = GetLastError();
                        LPVOID lpMsgBuf;
                FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                               NULL,
                               error,
                               MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                               (LPTSTR) &lpMsgBuf,
                                0,
                                NULL );
                Memo1->Lines->Add(AnsiString((char *)lpMsgBuf));
                LocalFree( lpMsgBuf );
                        return;
            }
               }
               CloseHandle(hDeviceHandle);
    }
    
    str = "";
    AnsiString tmp;
    Memo1->Clear();
    for(int i=0 ; i<512 ; i   )
    {
            tmp.printf(" X", (unsigned char)boot[i]);
        str = str   tmp;
        if( (i)==7 )
                str = str   "  ";
        if( (i)==15 )
        {
            Memo1->Lines->Add(str);
            str = "";
        }
    }
}
//---------------------------------------------------------------------------
typedef struct
{
    unsigned long   dwStartSector;
    unsigned short  wSectors;
    unsigned char   *lpBuffer;
}TDiskIO;
TDiskIO   buffer;
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
        unsigned char   drive=3;  //C:            DWORD cb;
        AnsiString str;
        int i;
        unsigned char boot[512];
        memset(boot, 512, 0);        hDeviceHandle = CreateFile("\\\\.\\VWIN32",GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);        if( hDeviceHandle!=INVALID_HANDLE_VALUE )
    {                    buffer.dwStartSector=0;
                buffer.wSectors=1;
                buffer.lpBuffer=boot;
                reg.EAX=0x7305;
                reg.EBX = (unsigned)(&buffer);
                reg.ECX = -1;
                reg.EDX = drive;//1-A 2-b 3-c
                reg.ESI = 0;
                reg.Flags = 0;                bool ans;
            ans = DeviceIoControl(hDeviceHandle,VWIN32_DIOC_DOS_DRIVEINFO,®,sizeof(reg),®,sizeof(reg),&cb,NULL);
            if ( (reg.Flags&1)==1 )
            {
                    AnsiString tmp;
                    tmp.printf("0xX" , reg.EAX&0xffff);
                    Memo1->Lines->Add(tmp);
            if( ans )
            {
                        DWORD  error = GetLastError();
                        LPVOID lpMsgBuf;
                FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                               NULL,
                               error,
                               MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                               (LPTSTR) &lpMsgBuf,
                                0,
                                NULL );
                Memo1->Lines->Add(AnsiString((char *)lpMsgBuf));
                LocalFree( lpMsgBuf );
                        return;
            }
               }
    }
    
    str = "";
    AnsiString tmp;
    Memo1->Clear();
    for(int i=0 ; i<512 ; i   )
    {
            tmp.printf(" X", (unsigned char)boot[i]);
        str = str   tmp;
        if( (i)==7 )
                str = str   "  ";
        if( (i)==15 )
        {
            Memo1->Lines->Add(str);
            str = "";
        }
    }
}
//---------------------------------------------------------------------------
按button1時getlastError() message "是系統找不到指定的檔案。",按button2整個系統就當機(藍畫面)........... 希望有人能解決我的疑惑......
dllee
站務副站長


發表:321
回覆:2519
積分:1711
註冊:2002-04-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-05-07 13:04:24 IP:220.139.xxx.xxx 未訂閱
請參考: http://www.internals.com/ http://www.cppfans.com/articles/system/idehdparams.asp http://www.cppfans.com/articles/system/portrw_winio.asp    我是沒試過啦  <>沒空更新的網頁... href="http://dllee.adsldns.org">http://dllee.adsldns.org 介紹Shells,LiteStep,GeoShell....
------
http://www.ViewMove.com
系統時間:2024-11-23 2:07:24
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!