📄 win2.c
字号:
#include <stdio.h>
#include <windows.h>
int readWriteDrive(unsigned int cmd,
int devicePar,
unsigned long startSectorPar,
DWORD sectorToDo,
BYTE* buf)
{
DWORD deviceGeneric,open;
__int64 startSector=0;
__int64 startbPos;
DWORD sectorHigh;
HANDLE hDev=0;
DWORD bDone;
char device[32];
char startSectorPar2[64];
memset(device,0,32);
/*device.Format("%d",devicePar);*/
strcpy(device,"\\\\.\\PHYSICALDRIVE");
sprintf(device+strlen(device),"%d",devicePar);
memset(startSectorPar2,0,64);
sprintf(startSectorPar2,"%lu",startSectorPar);
startSector=_atoi64(startSectorPar2);
startbPos=startSector*512;
sectorHigh=startbPos>>32;
if(cmd==0x42)
{
deviceGeneric=GENERIC_READ;
open=CREATE_ALWAYS;
}
else if(cmd==0x43)
{
deviceGeneric=GENERIC_WRITE;
open=OPEN_EXISTING;
}
hDev=CreateFile(device,deviceGeneric,FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
if(hDev==INVALID_HANDLE_VALUE)
{printf("打开硬盘失败。"); return 0;}
SetFilePointer(hDev,startbPos,(LONG *)§orHigh,FILE_BEGIN);
if(cmd==0x42) ReadFile(hDev,buf,sectorToDo*512,&bDone,0);
else if(cmd==0x43) WriteFile(hDev,buf,sectorToDo*512,&bDone,0);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -