win2.c
来自「内含纯DOS,WIN32控制台和WIN32 GUI三个版本.它们生成的备份文件可」· C语言 代码 · 共 64 行
C
64 行
#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 + =
减小字号Ctrl + -
显示快捷键?