用sdk对磁盘扇区数据进行读取和写入,代码存在风险,请酌情。
//
// Written by beiyu , beiyuly@gmail.com
// Read and Write Sectors with sdk function, v1.0
// WriteSectors do the job of writing
// ReadSectors do the job of reading
// good luck!
//
#include <windows.h>
#include <winioctl.h>
#include <stdio.h>
#define MAX_BUFFER 65535
//
// 对磁盘扇区数据的写入 dwStartSector为逻辑开始位置 0开始
//
BOOL WriteSectors(BYTE bDrive, DWORD dwStartSector, WORD wSectors, LPBYTE lpSectBuff)
{
if (bDrive < 0)
return FALSE;
char devName[] = ".//PHYSICALDRIVE0";
devName[strlen(devName) - 1] = devName[strlen(devName) - 1] + bDrive;
HANDLE hDev = CreateFile(devName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if (hDev == INVA