分享
 
 
 

Reading/Writing Disk Sectors (Absolute Disk Read/Write)

王朝vc·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

Windows 9x

Windows 9x provides a vxd called vwin32.vxd using which msdos functions including absolute disk read/write can be performed. A handle to vwin32.vxd must be first created using the CreateFile function. After creating the handle DeviceIoControl function must be used with the correct control code to read or write from the disk drives. The control code depends on the type of the function you want to perform.

The control codes for vwin32.vxd are ...

Code

Description

VWIN32_DIOC_DOS_IOCTL (1)

Interrupt 21h Function 4400h through 4411h

VWIN32_DIOC_DOS_INT25 (2)

Performs the Absolute Disk Read command (Interrupt 25h)

VWIN32_DIOC_DOS_INT26 (3)

Performs the Absolute Disk Write command (Interrupt 25h)

VWIN32_DIOC_DOS_INT13 (4)

Performs Interrupt 13h commands

VWIN32_DIOC_DOS_DRIVEINFO (6)

Interrupt 21h Function 730X commands

The lpvInBuffer & lpvOutBuffer params of DeviceIoControl function must point to addresses of DIOC_REGISTERS structures . This structure contains the state of the processor registers before ioctl and after ioctl.

Windows NT/2K/XP

In Windows NT/2K/XP the CreateFile function can be used to open a disk drive or a partition on it. After getting a handle to the disk drive using CreateFile function the ReadFile function can be used to read sectors and the WriteFile function can be used to write to the drive.If you want to open a logical drive give the filename param of the CreateFile function as "\\\\.\\a:" or "\\\\.\\c:" ... etc. and if you want to open a physical drive for raw reading/writing give the filename param as "\\\\.\\PhysicalDrive0" or "\\\\.\\PhysicalDrive1" ... etc

Code to read disk sectors from win 9x/NT/2K/XP

Reads [numberofsectors] disk sectors from [drive {0=A, 1=B, 2=C, ...}] drive starting from [startinglogicalsector]

To read sectors from win 9x int 21h's 7305h extention is used (Extended Absolute Disk Read/Write). For more info about int 21h's 7305h extention refer Ralf Brown's interrupt list.

char * ReadSectors(int drive, DWORD startinglogicalsector, int numberofsectors)

{

// All msdos data structures must be packed on a 1 byte boundary

#pragma pack (1)

struct

{

DWORD StartingSector ;

WORD NumberOfSectors ;

DWORD pBuffer;

}ControlBlock;

#pragma pack ()

#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 ;

#pragma pack ()

char* buffer = (char*)malloc (512*numberofsectors);

HANDLE hDevice ;

DIOC_REGISTERS reg ;

BOOL fResult ;

DWORD cb ;

// Creating handle to vwin32.vxd (win 9x)

hDevice = CreateFile ( "\\\\.\\vwin32",

0,

0,

NULL,

0,

FILE_FLAG_DELETE_ON_CLOSE,

NULL );

if ( hDevice == INVALID_HANDLE_VALUE )

{

// win NT/2K/XP code

HANDLE hDevice;

DWORD bytesread;

char _devicename[] = "\\\\.\\A:";

_devicename[4] += drive;

// Creating a handle to disk drive using CreateFile () function ..

hDevice = CreateFile(_devicename,

GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,

NULL, OPEN_EXISTING, 0, NULL);

if (hDevice == INVALID_HANDLE_VALUE)

return NULL;

// Setting the pointer to point to the start of the sector we want to read ..

SetFilePointer (hDevice, (startinglogicalsector*512), NULL, FILE_BEGIN);

if (!ReadFile (hDevice, buffer, 512*numberofsectors, &bytesread, NULL) )

return NULL;

}

else

{

// code for win 95/98

ControlBlock.StartingSector = (DWORD)startinglogicalsector;

ControlBlock.NumberOfSectors = (DWORD)numberofsectors ;

ControlBlock.pBuffer = (DWORD)buffer ;

//-----------------------------------------------------------

// SI contains read/write mode flags

// SI=0h for read and SI=1h for write

// CX must be equal to ffffh for

// int 21h's 7305h extention

// DS:BX -> base addr of the

// control block structure

// DL must contain the drive number

// (01h=A:, 02h=B: etc)

//-----------------------------------------------------------

reg.reg_ESI = 0x00 ;

reg.reg_ECX = -1 ;

reg.reg_EBX = (DWORD)(&ControlBlock);

reg.reg_EDX = drive+1;

reg.reg_EAX = 0x7305 ;

// 6 == VWIN32_DIOC_DOS_DRIVEINFO

fResult = DeviceIoControl ( hDevice,

6,

&(reg),

sizeof (reg),

&(reg),

sizeof (reg),

&cb,

0);

if (!fResult || (reg.reg_Flags & 0x0001)) return NULL;

}

CloseHandle(hDevice);

return buffer;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有