Winio64在64位系统中初始化失败问题

时间:2021-03-15 17:30:42


Winio64在64位系统中初始化失败问题

系统是win7 64位。

语言是C#

http://www.internals.com/下载的winio3.0,下载后的Binaries文件夹中包含WinIo64.dll,WinIo64.sys,将这两个文件放在debug文件夹下,与执行文件放在一起。

引入winio64.dll和一些基本操作的代码如下:

       //引入一些函数

        public const int KBC_KEY_CMD = 0x64;//输入键盘按下消息的端口

        public const int KBC_KEY_DATA = 0x60;//输入键盘弹起消息的端口

        [DllImport("WinIo64.dll")]

        public static extern bool InitializeWinIo();

        [DllImport("WinIo64.dll")]

        public static extern bool GetPortVal(IntPtr wPortAddr, out int pdwPortVal,

                    byte bSize);

        [DllImport("WinIo64.dll")]

        public static extern bool SetPortVal(uint wPortAddr, IntPtr dwPortVal,

                    byte bSize);

        [DllImport("WinIo64.dll")]

        public static extern byte MapPhysToLin(byte pbPhysAddr, uint dwPhysSize,

                        IntPtr PhysicalMemoryHandle);

        [DllImport("WinIo64.dll")]

        public static extern bool UnmapPhysicalMemory(IntPtr PhysicalMemoryHandle,

                        byte pbLinAddr);

        [DllImport("WinIo64.dll")]

        public static extern bool GetPhysLong(IntPtr pbPhysAddr, byte pdwPhysVal);

        [DllImport("WinIo64.dll")]

        public static extern bool SetPhysLong(IntPtr pbPhysAddr, byte dwPhysVal);

        [DllImport("WinIo64.dll")]

        public static extern void ShutdownWinIo();

        [DllImport("user32.dll")]

        public static extern int MapVirtualKey(uint Ucode, uint uMapType);

        //初始化,安装驱动?

        public void Initialize()

        {

            if (InitializeWinIo())

            {

                b = "1";

                KBCWait4IBE();

            }

            else

            {

                MessageBox.Show("failed");

                b = "3";

            }

        }

        //应该是调用结束要用的,卸载驱动?

        public void Shutdown()

        {

            ShutdownWinIo();

            KBCWait4IBE();

        }

        ///等待键盘缓冲区为空

        public void KBCWait4IBE()

        {

            int dwVal = 0;

            do

            {

                bool flag = GetPortVal((IntPtr)0x64, out dwVal, 1);

            }

            //while ((dwVal & 0x2) > 0);

            while((dwVal & 0x2)>0);

        }

        /// 模拟键盘标按下

        public void KeyDown(Keys vKeyCoad)

        {

            int btScancode = 0;

            btScancode = MapVirtualKey((uint)vKeyCoad, 0);

            KBCWait4IBE();

            SetPortVal(KBC_KEY_CMD, (IntPtr)0xD2, 1);

            KBCWait4IBE();

            SetPortVal(KBC_KEY_DATA, (IntPtr)0x60, 1);

            KBCWait4IBE();

            SetPortVal(KBC_KEY_CMD, (IntPtr)0xD2, 1);

            KBCWait4IBE();

            SetPortVal(KBC_KEY_DATA, (IntPtr)btScancode, 1);

        }

        /// 模拟键盘弹出

        public void KeyUp(Keys vKeyCoad)

        {

            int btScancode = 0;

            btScancode = MapVirtualKey((uint)vKeyCoad, 0);

            KBCWait4IBE();

            SetPortVal(KBC_KEY_CMD, (IntPtr)0xD2, 1);

            KBCWait4IBE();

            SetPortVal(KBC_KEY_DATA, (IntPtr)0x60, 1);

            KBCWait4IBE();

            SetPortVal(KBC_KEY_CMD, (IntPtr)0xD2, 1);

            KBCWait4IBE();

            SetPortVal(KBC_KEY_DATA, (IntPtr)(btScancode | 0x80), 1);

        }

        /// 模拟一次按键

        public void KeyDownUp(Keys vKeyCoad)

        {          

            KeyDown(vKeyCoad);

            Thread.Sleep(100);

            KeyUp(vKeyCoad);

        }

但是发现InitializeWinIo()一直返回的是false。在百度上搜索了N,说要看dll中的代码,然后改存放文件的地址,但是无果。继续调试,发现偶尔会有winio64.sys的数字签名无效的提示。后来在google上搜索了N久发现,果然是这个问题。Winio64.sys没有正式的数字签名,只有测试的。需要修改一些东西,具体如下:

cmd->bcdedit /set testsigning on

bcdedit /set testsigning off

然后修改WinIo64.sys的测试签名

1.打开 WinIO64.sys的属性框,翻到“数字签名”选项卡,点击“详细信息”
2.在新出来的对话框中点击“查看证书”
3.在又新出来的对话框中点击“安装证书”
4.点击“下一步”,然后选择“将所有的证书放入下列存储”
5.点击浏览,选择“受信任的根证书发布机构”

Winio64在64位系统中初始化失败问题

6.点击“下一步”,然后点击“完成”
7.在弹出的“安全性警告”对话框中选择“是”,才能导入成功

然后重启。

再调试程序,就可以成功初始化了。




http://blog.sina.com.cn/s/blog_8bd0deda01019fld.html