解锁磁盘
2021-09-07
35
0
void CKDiskInitDlg::OnButtonUnlock()
{
// TODO: Add your control notification handler code here
CComboBox* pList =(CComboBox*)GetDlgItem(IDC_COMBO_DISK_LIST);
int nId = pList->GetCurSel();
char buff[1024];
sprintf(buff,"\\\\.\\PhysicalDrive%d",nId);
HANDLE h = CreateFile(buff,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,NULL);
if(h == INVALID_HANDLE_VALUE)
{
printf("打开磁盘失败:%d\n",GetLastError());
return ;
}
memset(buff,0,sizeof(buff));
#pragma warning(disable:4305)
#pragma warning(disable:4309)
#pragma warning(disable:4244)
buff[0] = 0x28;
buff[2] = 0x05;
buff[9] = 0x02;
buff[12] = 0x1e;
buff[20]= 0xa8;
buff[21] = 0xef;
buff[22] = 0x12;
buff[33] = 0x6f;
buff[34] = 0xfe;
buff[35] = 0xef;
buff[37] = 0xa0;
buff[38] = 0xf2;
USHORT data[0x100];
memset(data,0,sizeof(data));
ULONG pt = (ULONG)data;
buff[20] = pt & 0xff;
buff[21] = (pt>>8) & 0xff;
buff[22] = (pt>>16) & 0xff;
buff[23] = (pt>>24) & 0xff;
#pragma warning(default:4305)
#pragma warning(default:4309)
#pragma warning(default:4244)
ULONG d;
BOOL ok = DeviceIoControl(h,IOCTL_ATA_PASS_THROUGH_DIRECT,buff,40,buff,40,&d,NULL);
if(!ok)
{
CString str;
str.Format("%d",GetLastError());
MessageBox(str);
}
else
{
MessageBox("unlock ok!");
}
CloseHandle(h);
return ;
}