之前參考了一下下面的連結,寫了一些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整個系統就當機(藍畫面)........... 希望有人能解決我的疑惑......