📄 win1.c
字号:
#include <stdio.h>
#include <windows.h>
int readWriteDrive(unsigned int cmd,
char *devicePar,
unsigned long startSectorPar,
DWORD sectorToDo,
unsigned char *buf)
{
DWORD deviceGeneric,open;
__int64 startSector=0;
__int64 startbPos;
DWORD sectorHigh;
HANDLE hDev=0;
DWORD bDone;
/*CString device;*/
char device[32];
char startSectorPar2[64];
/*device.Format("%d",devicePar);*/
memset(device,0,32);
memset(startSectorPar2,0,64);
sprintf(startSectorPar2,"%lu",startSectorPar);
startSector=_atoi64(startSectorPar2);
startbPos=startSector*512;
sectorHigh=startbPos>>32;
/*
if(device.IsEmpty()==TRUE)
{printf("请输入设备名。"); return 0;}
if(sectorToDo==0)
{printf("读取的扇区数不能为0。"); return 0;}
*/
/*device=CString("\\\\.\\PHYSICALDRIVE")+CString(device);*/
strcpy(device,"\\\\.\\PHYSICALDRIVE\0");
strcpy(device+strlen(device),devicePar);
/*printf("%s\n",device);*/
if(cmd==0x42)
{
deviceGeneric=GENERIC_READ;
}
else if(cmd==0x43)
{
deviceGeneric=GENERIC_WRITE;
}
hDev=CreateFile(device,deviceGeneric,FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
if(hDev==INVALID_HANDLE_VALUE)
{/*printf("打开硬盘 %s 失败。",device);*/ if(hDev!=INVALID_HANDLE_VALUE) CloseHandle(hDev);
return -1;}
// SetFilePointer(readHandle,startbPos,(LONG *)§orHigh,FILE_BEGIN);
SetFilePointer(hDev,startbPos,(LONG *)§orHigh,FILE_BEGIN);
if(cmd==0x42)
{
if(!ReadFile(hDev,buf,sectorToDo*512,&bDone,0))
{
printf("Failed to read %s\n",device);
return -1;
}
}
else if(cmd==0x43)
{
if(!WriteFile(hDev,buf,sectorToDo*512,&bDone,0))
{
printf("Failed to write %s\n",device);
return -1;
}
}
if(hDev!=INVALID_HANDLE_VALUE) CloseHandle(hDev);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -