77
88from enum import Enum
99import ctypes
10+ from ctypes import wintypes
1011
1112from .baseportio import PortIOClass
1213
@@ -16,27 +17,28 @@ class WinPortIO(PortIOClass):
1617 A class to interact with the WinRing0 library for port I/O on Windows.
1718 """
1819
19- winring0 = None
20+ winring0 : "ctypes.WinDLL | None" = None
21+ "The WinRing0 library instance."
2022
2123 def __init__ (self ):
2224 """
2325 Load and initialize the WinRing0 library.
2426 """
2527 self .winring0 = ctypes .WinDLL ("WinRing0x64.dll" )
26- self .winring0 .InitializeOls .restype = ctypes . c_bool
27- self .winring0 .GetDllStatus .restype = ctypes . c_ulong
28+ self .winring0 .InitializeOls .restype = wintypes . BOOL
29+ self .winring0 .GetDllStatus .restype = wintypes . DWORD
2830 self .winring0 .DeinitializeOls .restype = None
2931 # ReadIoPort (port)
30- self .winring0 .ReadIoPortByte .restype = ctypes . c_ubyte
31- self .winring0 .ReadIoPortByte .argtypes = [ctypes . c_ushort ]
32- self .winring0 .ReadIoPortWord .restype = ctypes . c_ushort
33- self .winring0 .ReadIoPortWord .argtypes = [ctypes . c_ushort ]
34- self .winring0 .ReadIoPortDword .restype = ctypes . c_ulong
35- self .winring0 .ReadIoPortDword .argtypes = [ctypes . c_ushort ]
32+ self .winring0 .ReadIoPortByte .restype = wintypes . BYTE
33+ self .winring0 .ReadIoPortByte .argtypes = [wintypes . WORD ]
34+ self .winring0 .ReadIoPortWord .restype = wintypes . WORD
35+ self .winring0 .ReadIoPortWord .argtypes = [wintypes . WORD ]
36+ self .winring0 .ReadIoPortDword .restype = wintypes . DWORD
37+ self .winring0 .ReadIoPortDword .argtypes = [wintypes . WORD ]
3638 # WriteIoPort (port, data)
37- self .winring0 .WriteIoPortByte .argtypes = [ctypes . c_ushort , ctypes . c_ubyte ]
38- self .winring0 .WriteIoPortWord .argtypes = [ctypes . c_ushort , ctypes . c_ushort ]
39- self .winring0 .WriteIoPortDword .argtypes = [ctypes . c_ushort , ctypes . c_ulong ]
39+ self .winring0 .WriteIoPortByte .argtypes = [wintypes . WORD , wintypes . BYTE ]
40+ self .winring0 .WriteIoPortWord .argtypes = [wintypes . WORD , wintypes . WORD ]
41+ self .winring0 .WriteIoPortDword .argtypes = [wintypes . WORD , wintypes . DWORD ]
4042
4143 self .winring0 .InitializeOls ()
4244 if error := self .winring0 .GetDllStatus ():
@@ -49,21 +51,6 @@ def __del__(self):
4951 if self .winring0 :
5052 self .winring0 .DeinitializeOls ()
5153
52- class Status (Enum ):
53- OLS_DLL_NO_ERROR = 0
54- OLS_DLL_UNSUPPORTED_PLATFORM = 1
55- OLS_DLL_DRIVER_NOT_LOADED = 2
56- OLS_DLL_DRIVER_NOT_FOUND = 3
57- OLS_DLL_DRIVER_UNLOADED = 4
58- OLS_DLL_DRIVER_NOT_LOADED_ON_NETWORK = 5
59- OLS_DLL_UNKNOWN_ERROR = 9
60-
61- OLS_DLL_DRIVER_INVALID_PARAM = 10
62- OLS_DLL_DRIVER_SC_MANAGER_NOT_OPENED = 11
63- OLS_DLL_DRIVER_SC_DRIVER_NOT_INSTALLED = 12
64- OLS_DLL_DRIVER_SC_DRIVER_NOT_STARTED = 13
65- OLS_DLL_DRIVER_SC_DRIVER_NOT_REMOVED = 14
66-
6754 def outb (self , data : int , port : int ) -> None :
6855 """
6956 Write a byte (8 bit) to the specified port.
@@ -123,3 +110,22 @@ def iopl(self, level: int) -> None:
123110 `iopl` stub function. It's not required for WinRing0.
124111 """
125112 pass
113+
114+ class Status (Enum ):
115+ """
116+ WinRing0 status codes.
117+ """
118+
119+ OLS_DLL_NO_ERROR = 0
120+ OLS_DLL_UNSUPPORTED_PLATFORM = 1
121+ OLS_DLL_DRIVER_NOT_LOADED = 2
122+ OLS_DLL_DRIVER_NOT_FOUND = 3
123+ OLS_DLL_DRIVER_UNLOADED = 4
124+ OLS_DLL_DRIVER_NOT_LOADED_ON_NETWORK = 5
125+ OLS_DLL_UNKNOWN_ERROR = 9
126+
127+ OLS_DLL_DRIVER_INVALID_PARAM = 10
128+ OLS_DLL_DRIVER_SC_MANAGER_NOT_OPENED = 11
129+ OLS_DLL_DRIVER_SC_DRIVER_NOT_INSTALLED = 12
130+ OLS_DLL_DRIVER_SC_DRIVER_NOT_STARTED = 13
131+ OLS_DLL_DRIVER_SC_DRIVER_NOT_REMOVED = 14
0 commit comments