在Windows下进行底层IO操作之CMOS数据的读取和显示

Windows下进行底层IO操作之CMOS数据的读取和显示

作者:彭学周(Favory.Peng)

 

CPU执行命令一般分为:特权(Privileged-Ring0)和非特权(Non-Privileged Mode-Ring3)两种模式;

Windows系统下的程序都是在Ring3下执行,无法进行任意I/O端口的操作;

要是能让程序在Ring0下执行,自然就可以顺利的进行读写I/O端口的操作;lcsboy编写的WinRing就提供了这个功能,下面以CMOS数据的读取为例介绍WinRing的使用;

编辑环境:BCB 6.0 需要文件:WINRING.sys(端口操作驱动)WinRing.hpp(WinRing应用处理函数)

 

CMOS数据读取原理:

       在计算机系统中,对CMOS中数据的读写是通过两个I/O端口来实现的,其中,端口70H是一个字节的只写端口,用它来设置CMOS中的数据地址;而端口71H是用来读写端口70H设置的CMOS地址中的数据单元字节内容。

//-----------------------------------------------------------------------------------------------------

CMOS代码:

asm{  

mov al, Index    //将需要读取的位置传到AL寄存器

    out 0x70, al        //将读取地址写到70H端口

    in al, 0x71       //71H端口读取数据送AL

    mov Val, al      //AL中的数据送变量Val

}

CMOS代码:

          asm{

            mov al, Index      //将需要写入的地址送AL

            out 0x70, al        //AL中的地址写入70H端口

            mov al, Val        //将需要写入的值送到AL

            out 0x71, al               //将值写入71H端口完成数据写操作

}

//-----------------------------------------------------------------------------------------------------

1、在程序段加入WinRing.hpp的引用:#include "WinRing.hpp"

2、在窗口程序FormCreate事件中加入:OpenWinRing();

3、在窗口程序FormCloseQuery事件中加入:CloseWinRing();

4、编写CMOS读写函数:(要求代码精简,不能有控件操作等)

BYTE CMOSData[128];  //存储CMOS数据

void __fastcall TForm1::ReadComs(void)  //CMOS数据

{

        BYTE Val, Index;

        asm cli;  //关中断

        for (int i=0;i<128; i++)

        {

          Index=i;

          asm{

            mov al, Index

            out 0x70, al

            in al, 0x71

            mov Val, al}

            CMOSData[i]=Val;

        }

        asm sti;  //开中断

}

//---------------------------------------------------------------------------

void __fastcall  TForm1::WriteComs(void) //CMOS数据

{

        BYTE Val, Index;

        asm cli;  //关中断

        for (int i=0x10;i<128; i++)

        {

          Index=i;

          Val=CMOSData[i];

          asm{

            mov al, Index

            out 0x70, al

            mov al, Val

            out 0x71, al}

        }

        asm sti; //开中断

}

//---------------------------------------------------------------------------

5、在Ring0下执行读写函数:

       ProcessRing0(WriteComs);

ProcessRing0(ReadComs);

 

说明:编译好的目标程序的使用必须在WINRING.sys同级目录下,否则将找不到驱动,这样貌似很麻烦;不过这个SYS的文件大小不大,不到2K,所以我们可以将WINRING.SYS数据保存到数组中,在应用程序运行前判断是否有这个SYS文件在同级目录下,若没有再将这些数据保存到文件WINRING.SYS中;

附代码:WinRing.hpp (声明:版权归原作者Chun-Hsueh Lin所有

/************************************************************************

* <WinRing.hpp> Ver 1.0

*

* Adjust the privilege of Application from Ring 3 to Ring 0

*

* Caution: 1. WinRing.sys support Win2K/WinXP serial only.

*         2. Don't use VCL in your procedure that it will be adjusted to Ring 0.

*          3. Don't use any command about Far-Jump.

*

* Copyright by Chun-Hsueh Lin, 03/12/2003

************************************************************************/

#ifndef DRIVER

#define DRIVER     "WINRING"

#endif

#ifndef DEVIO_H

#define DEVIO_H

 

//===============================================

#ifndef CTL_CODE

#define CTL_CODE( DeviceType, Function, Method, Access ) (                 /

    ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) /

)

#define METHOD_BUFFERED                 0

#define METHOD_IN_DIRECT                1

#define METHOD_OUT_DIRECT               2

#define METHOD_NEITHER                  3

#define FILE_ANY_ACCESS                 0

#define FILE_READ_ACCESS                            ( 0x0001 )    // file & pipe

#define FILE_WRITE_ACCESS                           ( 0x0002 )    // file & pipe

#define FILE_DEVICE_UNKNOWN             0x00000022

#endif

 

#define WINRING_Access        CTL_CODE(            /

                     FILE_DEVICE_UNKNOWN,            /

                     0x999,                       /

                     METHOD_BUFFERED,             /

                     FILE_ANY_ACCESS)

#endif

 

//===============================================

class TRingData

{

public:

       ULONG AdjRing0Entry;

       ULONG RegData[7];

};

//===============================================

 

HANDLE DriverHandle;

 

TRingData Ring;

DWORD retbyte;

 

#define WinRing(); DeviceIoControl(DriverHandle, WINRING_Access, &Ring, sizeof(Ring), &Ring, sizeof(Ring), &retbyte, 0);

 

bool BuildDriverService()

{

       SC_HANDLE scHandle, srvHandle;

       scHandle=OpenSCManager(0,0,SC_MANAGER_ALL_ACCESS);

       if (!scHandle)

       {

              return false;

       }

       srvHandle=OpenService(scHandle,DRIVER,SERVICE_ALL_ACCESS);

       if (srvHandle==0)

       {

              char path[MAX_PATH]={0};

              String DriverPath=ExtractFilePath(Application->ExeName)+DRIVER+".sys";

              strcat(path, DriverPath.c_str());

             

              srvHandle=CreateService(

                     scHandle,

                     DRIVER,

                     DRIVER,

                     SERVICE_ALL_ACCESS,

                     SERVICE_KERNEL_DRIVER,

                     SERVICE_DEMAND_START,

                     SERVICE_ERROR_NORMAL,

                     path,

                     0,0,0,0,0);

       }

       if (srvHandle==0)

         return false;

 

       StartService(srvHandle,0,0);

       CloseServiceHandle(srvHandle);

       CloseServiceHandle(scHandle);

       return true;

}

 

//===============================================

bool DeleteDriverService()

{

       SERVICE_STATUS  srvStatus;

       SC_HANDLE scHandle,srvHandle;

 

       scHandle=OpenSCManager(0,0,SC_MANAGER_ALL_ACCESS);

       if (!scHandle)

       {

              return false;

       }

 

       srvHandle=OpenService(scHandle,DRIVER,SERVICE_ALL_ACCESS);

       if (srvHandle)

       {

              ControlService(srvHandle,SERVICE_CONTROL_STOP,&srvStatus);

 

              DeleteService(srvHandle);

       }

       CloseServiceHandle(srvHandle);

       CloseServiceHandle(scHandle);

       return true;

}

 

//===============================================

bool OpenDriver()

{

       if (!BuildDriverService())

         return false;

       DriverHandle=CreateFile(

              "////.//" DRIVER,

              GENERIC_READ|GENERIC_WRITE,

              0,

              0,

              OPEN_EXISTING,

              0,

              0);

 

       if (DriverHandle==INVALID_HANDLE_VALUE)

       {

              return false;

       }

       return true;

}

 

//===============================================

bool CloseDriver()

{

       CloseHandle(DriverHandle);

       if (!DeleteDriverService())

         return false;

       return true;

}

 

//===============================================

BYTE OSVersion;

void __fastcall (__closure *Ring3ProcName)();

 

// Get major version numbers of Windows

// OSVersion=4 : Win9x serial

// OSVersion=5 : WinNT serial

//===============================================

void OpenWinRing()

{

        OSVersion = LOBYTE(LOWORD(GetVersion()));

        if (OSVersion!=4)

        {

          if (!OpenDriver())

          {

            ShowMessage("Driver not ready!!!");

            CloseDriver();

            Application->Terminate();

          }

        }

}

 

//===============================================

void CloseWinRing()

{

        if (OSVersion !=4)

        {

          if (!CloseDriver())

            ShowMessage("Close Driver Fail!");

        }

}

 

//===============================================

void __fastcall SaveAllReg(void)

{

        asm {

          push eax

          mov eax, offset Ring.RegData

          mov [eax][04], ebx

          mov [eax][08], ecx

          mov [eax][12], edx

          mov [eax][16], esi

          mov [eax][20], edi

          mov [eax][24], ebp

          mov ebx, eax

          pop eax

          mov [ebx], eax}

}

 

//===============================================

//Edit by: favory.peng 2008-9-27   for BCB6.0

void __fastcall Ring0Proc()

{

        DWORD Adj0Address;

        SaveAllReg();

        #pragma inline

        asm mov Adj0Address, offset ADJRing0

        Ring.AdjRing0Entry=Adj0Address;

        WinRing();

        asm{

          jmp ADJRing3

ADJRing0:

          mov eax, [esp+4]}

        Ring3ProcName();

        asm{

          ret

ADJRing3:}

}

 

#define ProcessRing0(x) Ring3ProcName=x; Ring0Proc();

//============= <WinRing.hpp 代码结束>================

 

WINRING.sys数据文件数组,可以保存到文件中生成运行需要的文件

//=================================================

unsigned char WINRING_Data[1988] = {

       0x4D, 0x 5A , 0x90, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00,

       0xB8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00,

       0x0E, 0x 1F , 0xBA, 0x0E, 0x00, 0xB4, 0x09, 0xCD, 0x21, 0xB8, 0x01, 0x 4C , 0xCD, 0x21, 0x54, 0x68,

       0x69, 0x73, 0x20, 0x70, 0x72, 0x 6F , 0x67, 0x72, 0x61, 0x6D, 0x20, 0x63, 0x61, 0x6E, 0x6E, 0x 6F ,

       0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6E, 0x20, 0x69, 0x6E, 0x20, 0x44, 0x 4F , 0x53, 0x20,

       0x6D, 0x 6F , 0x64, 0x65, 0x2E, 0x0D, 0x0D, 0x 0A , 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0xB5, 0x44, 0xC2, 0xFD, 0xF1, 0x25, 0xAC, 0xAE, 0xF1, 0x25, 0xAC, 0xAE, 0xF1, 0x25, 0xAC, 0xAE,

       0xA8, 0x06, 0xBF, 0xAE, 0xF8, 0x25, 0xAC, 0xAE, 0x19, 0x 3A , 0xA7, 0xAE, 0xF0, 0x25, 0xAC, 0xAE,

       0x52, 0x69, 0x63, 0x68, 0xF1, 0x25, 0xAC, 0xAE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x50, 0x45, 0x00, 0x00, 0x 4C , 0x01, 0x05, 0x00, 0x49, 0x8D, 0x70, 0x3E, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x0E, 0x01, 0x0B, 0x01, 0x05, 0x 0C , 0x60, 0x02, 0x00, 0x00,

       0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00,

       0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,

       0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x 0A , 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x06, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0xB1, 0x87, 0x00, 0x00, 0x01, 0x00, 0x00, 0x20,

       0x00, 0x00, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0xE0, 0x04, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0xC0, 0x05, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x20, 0x04, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x 1C , 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2E, 0x74, 0x65, 0x78, 0x74, 0x00, 0x00, 0x00,

       0x77, 0x01, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x68,

       0x2E, 0x72, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,

       0x80, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x48, 0x2E, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00,

       0x48, 0x00, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0xC8,

       0x49, 0x4E, 0x49, 0x54, 0x00, 0x00, 0x00, 0x00, 0xD4, 0x00, 0x00, 0x00, 0xE0, 0x04, 0x00, 0x00,

       0xE0, 0x00, 0x00, 0x00, 0xE0, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0xE2, 0x2E, 0x72, 0x65, 0x 6C , 0x 6F , 0x63, 0x00, 0x00,

       0x32, 0x00, 0x00, 0x00, 0xC0, 0x05, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0xC0, 0x05, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x42,

       0x55, 0x8B, 0xEC, 0x83, 0xEC, 0x14, 0x56, 0x57, 0x8B, 0x3D, 0x04, 0x04, 0x01, 0x00, 0x8D, 0x45,

       0xF4, 0x68, 0xA8, 0x04, 0x01, 0x00, 0x50, 0xFF, 0xD7, 0x8B, 0x75, 0x08, 0x8D, 0x45, 0xFC, 0x50,

       0x 6A , 0x00, 0x 6A , 0x00, 0x8D, 0x45, 0xF4, 0x 6A , 0x22, 0x50, 0x 6A , 0x00, 0x56, 0xFF, 0x15, 0x00,

       0x04, 0x01, 0x00, 0x85, 0xC0, 0x 7C , 0x35, 0x8D, 0x45, 0xEC, 0x68, 0x80, 0x04, 0x01, 0x00, 0x50,

       0xC7, 0x46, 0x38, 0x20, 0x03, 0x01, 0x00, 0xC7, 0x46, 0x70, 0x30, 0x03, 0x01, 0x00, 0xC7, 0x46,

       0x40, 0x20, 0x03, 0x01, 0x00, 0xC7, 0x46, 0x34, 0xF2, 0x02, 0x01, 0x00, 0xFF, 0xD7, 0x8D, 0x45,

       0xF4, 0x50, 0x8D, 0x45, 0xEC, 0x50, 0xFF, 0x15, 0x14, 0x04, 0x01, 0x00, 0x 5F , 0x5E, 0xC9, 0xC2,

       0x08, 0x00, 0x55, 0x8B, 0xEC, 0x51, 0x51, 0x8D, 0x45, 0xF8, 0x68, 0x80, 0x04, 0x01, 0x00, 0x50,

       0xFF, 0x15, 0x04, 0x04, 0x01, 0x00, 0x8D, 0x45, 0xF8, 0x50, 0xFF, 0x15, 0x 0C , 0x04, 0x01, 0x00,

       0x8B, 0x45, 0x08, 0xFF, 0x70, 0x04, 0xFF, 0x15, 0x08, 0x04, 0x01, 0x00, 0xC9, 0xC2, 0x04, 0x00,

       0x 6A , 0x00, 0x 6A , 0x00, 0xFF, 0x74, 0x24, 0x10, 0xE8, 0x2B, 0x00, 0x00, 0x00, 0xC2, 0x08, 0x00,

       0x8B, 0x44, 0x24, 0x08, 0x8B, 0x48, 0x60, 0x81, 0x79, 0x 0C , 0x64, 0x26, 0x22, 0x00, 0x74, 0x 0F ,

       0x 6A , 0x00, 0x68, 0x10, 0x00, 0x00, 0xC0, 0x50, 0xE8, 0x0B, 0x00, 0x00, 0x00, 0xEB, 0x06, 0x50,

       0xE8, 0x25, 0x00, 0x00, 0x00, 0xC2, 0x08, 0x00, 0x8B, 0x 4C , 0x24, 0x04, 0x8B, 0x44, 0x24, 0x 0C ,

       0x56, 0x8B, 0x74, 0x24, 0x 0C , 0x32, 0xD2, 0x89, 0x71, 0x18, 0x89, 0x41, 0x 1C , 0xFF, 0x15, 0x10,

       0x04, 0x01, 0x00, 0x8B, 0xC6, 0x5E, 0xC2, 0x 0C , 0x00, 0xCC, 0x56, 0x57, 0x8B, 0x 7C , 0x24, 0x 0C ,

       0x8B, 0x47, 0x60, 0x8B, 0x70, 0x08, 0x3B, 0x70, 0x04, 0x74, 0x0E, 0x83, 0xFE, 0x20, 0x73, 0x09,

       0x 6A , 0x00, 0x68, 0x 9C , 0x00, 0x00, 0xC0, 0xEB, 0x0B, 0xFF, 0x77, 0x 0C , 0xE8, 0x 0F , 0x00, 0x00,

       0x00, 0x56, 0x 6A , 0x00, 0x57, 0xE8, 0xAE, 0xFF, 0xFF, 0xFF, 0x 5F , 0x5E, 0xC2, 0x04, 0x00, 0xCC,

       0x55, 0x8B, 0xEC, 0x83, 0xEC, 0x20, 0x53, 0x56, 0x8B, 0x75, 0x08, 0x57, 0x 6A , 0x08, 0x8D, 0x7D,

       0xE0, 0x59, 0x8D, 0x45, 0xE4, 0xF3, 0xA5, 0x89, 0x45, 0x08, 0x60, 0x8B, 0x45, 0xE0, 0x50, 0x8B,

       0x45, 0x08, 0x8B, 0x58, 0x04, 0x8B, 0x48, 0x08, 0x8B, 0x50, 0x 0C , 0x8B, 0x70, 0x10, 0x8B, 0x78,

       0x14, 0x8B, 0x68, 0x18, 0xFF, 0x30, 0x8B, 0x44, 0x24, 0x04, 0xFF, 0xD0, 0x83, 0xC4, 0x08, 0x61,

       0x 5F , 0x5E, 0x5B, 0xC9, 0xC2, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x 3C , 0x05, 0x00, 0x00, 0x4E, 0x05, 0x00, 0x00, 0x66, 0x05, 0x00, 0x00, 0x78, 0x05, 0x00, 0x00,

       0x90, 0x05, 0x00, 0x00, 0x24, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x49, 0x8D, 0x70, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,

       0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x49, 0x8D, 0x70, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x10, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x8D, 0x70, 0x3E,

       0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x90, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x 5C , 0x00, 0x44, 0x00, 0x 6F , 0x00, 0x73, 0x00, 0x44, 0x00, 0x65, 0x00, 0x76, 0x00, 0x69, 0x00,

       0x63, 0x00, 0x65, 0x00, 0x73, 0x00, 0x 5C , 0x00, 0x57, 0x00, 0x49, 0x00, 0x4E, 0x00, 0x52, 0x00,

       0x49, 0x00, 0x4E, 0x00, 0x47, 0x00, 0x00, 0x00, 0x 5C , 0x00, 0x44, 0x00, 0x65, 0x00, 0x76, 0x00,

       0x69, 0x00, 0x63, 0x00, 0x65, 0x00, 0x 5C , 0x00, 0x57, 0x00, 0x49, 0x00, 0x4E, 0x00, 0x52, 0x00,

       0x49, 0x00, 0x4E, 0x00, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x08, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA6, 0x05, 0x00, 0x00,

       0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x 3C , 0x05, 0x00, 0x00, 0x4E, 0x05, 0x00, 0x00,

       0x66, 0x05, 0x00, 0x00, 0x78, 0x05, 0x00, 0x00, 0x90, 0x05, 0x00, 0x00, 0x24, 0x05, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x3D, 0x00, 0x49, 0x 6F , 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x79,

       0x6D, 0x62, 0x 6F , 0x 6C , 0x69, 0x63, 0x 4C , 0x69, 0x6E, 0x6B, 0x00, 0x00, 0x 3A , 0x00, 0x49, 0x 6F ,

       0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x00, 0x00, 0xDE, 0x00,

       0x52, 0x74, 0x 6C , 0x49, 0x6E, 0x69, 0x74, 0x55, 0x6E, 0x69, 0x63, 0x 6F , 0x64, 0x65, 0x53, 0x74,

       0x72, 0x69, 0x6E, 0x67, 0x00, 0x00, 0x 3F , 0x00, 0x49, 0x 6F , 0x44, 0x65, 0x 6C , 0x65, 0x74, 0x65,

       0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x00, 0x00, 0x40, 0x00, 0x49, 0x 6F , 0x44, 0x65, 0x 6C , 0x65,

       0x74, 0x65, 0x53, 0x79, 0x6D, 0x62, 0x 6F , 0x 6C , 0x69, 0x63, 0x 4C , 0x69, 0x6E, 0x6B, 0x00, 0x00,

       0x70, 0x00, 0x49, 0x 6F , 0x66, 0x43, 0x 6F , 0x6D, 0x70, 0x 6C , 0x65, 0x74, 0x65, 0x52, 0x65, 0x71,

       0x75, 0x65, 0x73, 0x74, 0x00, 0x00, 0x4E, 0x54, 0x 4F , 0x53, 0x4B, 0x52, 0x4E, 0x 4C , 0x2E, 0x45,

       0x58, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x 8A , 0x32, 0x92, 0x32, 0xAF, 0x32, 0xBB, 0x32,

       0xC3, 0x32, 0xCA, 0x32, 0xD1, 0x32, 0xD8, 0x32, 0xE8, 0x32, 0xFB, 0x32, 0x02, 0x33, 0x 0C , 0x33,

       0x18, 0x33, 0x 6F , 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x01, 0x00, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0xD2, 0x 4A , 0x00, 0x2E, 0x 5C , 0x69, 0x33,

       0x38, 0x36, 0x 5C , 0x57, 0x49, 0x4E, 0x52, 0x49, 0x4E, 0x47, 0x2E, 0x73, 0x79, 0x73, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

       0x80, 0x02, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x08, 0xD2,

       0xF2, 0x02, 0x00, 0x00, 0x2E, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0xD0,

       0x20, 0x03, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,

       0x20, 0x03, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,

       0x30, 0x03, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,

       0x58, 0x03, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x01,

       0x 7A , 0x03, 0x00, 0x00, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02,

       0xB0, 0x03, 0x00, 0x00, 0x47, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x01, 0x00, 0x 0C , 0xD3,

       0x4E, 0x42, 0x31, 0x30, 0x00, 0x00, 0x00, 0x00, 0x49, 0x8D, 0x70, 0x3E, 0x01, 0x00, 0x00, 0x00,

       0x44, 0x 3A , 0x 5C , 0x44, 0x 6F , 0x77, 0x6E, 0x 4C , 0x 6F , 0x61, 0x64, 0x 5C , 0x44, 0x72, 0x69, 0x76,

       0x65, 0x72, 0x 5C , 0x69, 0x33, 0x38, 0x36, 0x 5C , 0x57, 0x49, 0x4E, 0x52, 0x49, 0x4E, 0x47, 0x2E,

       0x70, 0x64, 0x62, 0x00

};

//---------------------------------------------------------------------------

定义创建<WINRING.sys>文件的函数:

void __fastcall TFmain::CreateSYS(void)

{

        FILE* fp;

        fp=fopen("WINRING.sys","wb+");

        fwrite(WINRING_Data,sizeof(unsigned char),1988,fp);

        fclose(fp);

}

FormCreate消息中加入:

         if(FileExists("WINRING.sys"))

         {

                OpenWinRing();

         }

         else

         {

                CreateSYS();

                Sleep(10);

                OpenWinRing();

         }

//=================================================

作者:Favory.Peng(彭学周)  2008-10-09

本文到此结束,有不足之处,希望各位高手指教,谢谢!

你可能感兴趣的:(c,windows,IO,service,File,Access)