Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
3.7 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: KernelIO.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // http://www.internals.com //
  13. //----------------------------------------------------------------------------
  14. // ---------------------------------------------------- //
  15. // WinIo v2.0 //
  16. // Direct Hardware Access Under Windows 9x/NT/2000/XP //
  17. // Copyright 1998-2002 Yariv Kaplan //
  18. // http://www.internals.com //
  19. // ---------------------------------------------------- //
  20. #include <windows.h>
  21. #include <winioctl.h>
  22. #include "k32call.h"
  23. #include "phys32.h"
  24. #include "drv\nt\winio_nt.h"
  25. #include "kernelio.h"
  26. HANDLE hDriver = INVALID_HANDLE_VALUE;
  27. bool IsNT;
  28. bool IsWinIoInitialized = false;
  29. char szWinIoDriverPath[MAX_PATH];
  30. bool IsWinNT()
  31. {
  32. OSVERSIONINFO OSVersionInfo;
  33. OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  34. GetVersionEx(&OSVersionInfo);
  35. return OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT;
  36. }
  37. bool GetDriverPath()
  38. {
  39. PSTR pszSlash;
  40. if (!GetModuleFileName(GetModuleHandle(NULL), szWinIoDriverPath, sizeof(szWinIoDriverPath)))
  41. return false;
  42. pszSlash = strrchr(szWinIoDriverPath, '\\');
  43. if (pszSlash)
  44. pszSlash[1] = 0;
  45. else
  46. return false;
  47. strcat(szWinIoDriverPath, "KernelIoNT.dll");
  48. return true;
  49. }
  50. bool _stdcall InitializeWinIo()
  51. {
  52. bool bResult;
  53. DWORD dwBytesReturned;
  54. IsNT = IsWinNT();
  55. if (IsNT)
  56. {
  57. hDriver = CreateFile("\\\\.\\WINIO",
  58. GENERIC_READ | GENERIC_WRITE,
  59. 0,
  60. NULL,
  61. OPEN_EXISTING,
  62. FILE_ATTRIBUTE_NORMAL,
  63. NULL);
  64. // If the driver is not running, install it
  65. if (hDriver == INVALID_HANDLE_VALUE)
  66. {
  67. GetDriverPath();
  68. bResult = InstallWinIoDriver(szWinIoDriverPath, true);
  69. if (!bResult)
  70. return false;
  71. bResult = StartWinIoDriver();
  72. if (!bResult)
  73. return false;
  74. hDriver = CreateFile("\\\\.\\WINIO",
  75. GENERIC_READ | GENERIC_WRITE,
  76. 0,
  77. NULL,
  78. OPEN_EXISTING,
  79. FILE_ATTRIBUTE_NORMAL,
  80. NULL);
  81. if (hDriver == INVALID_HANDLE_VALUE)
  82. return false;
  83. }
  84. // Enable I/O port access for this process
  85. if (!DeviceIoControl(hDriver, IOCTL_WINIO_ENABLEDIRECTIO, NULL,
  86. 0, NULL, 0, &dwBytesReturned, NULL))
  87. return false;
  88. }
  89. else
  90. {
  91. VxDCall = (DWORD (WINAPI *)(DWORD,DWORD,DWORD))GetK32ProcAddress(1);
  92. hDriver = CreateFile("\\\\.\\KernelIo9X.dll", 0, 0, 0, CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0);
  93. if (hDriver == INVALID_HANDLE_VALUE)
  94. return false;
  95. }
  96. IsWinIoInitialized = true;
  97. return true;
  98. }
  99. void _stdcall ShutdownWinIo()
  100. {
  101. DWORD dwBytesReturned;
  102. if (IsNT)
  103. {
  104. if (hDriver != INVALID_HANDLE_VALUE)
  105. {
  106. // Disable I/O port access
  107. DeviceIoControl(hDriver, IOCTL_WINIO_DISABLEDIRECTIO, NULL,
  108. 0, NULL, 0, &dwBytesReturned, NULL);
  109. CloseHandle(hDriver);
  110. }
  111. RemoveWinIoDriver();
  112. }
  113. else
  114. CloseHandle(hDriver);
  115. IsWinIoInitialized = false;
  116. hDriver = INVALID_HANDLE_VALUE;
  117. }