I tried your code and works fine under both pcs. I do not want to use winring0 dlls. I would like to use only the driver (too many depedencies). I tried to "marry" your code (the first one) with mine with no success. I cannot even find the Class, even if I copied/pasted your code. The only thing that I didn't use is InitializeOls(). Here what I have writen (Request Administrator mode is checked in the compiler):
Code: Select all
IncludeFile "Driver.pb"
LoadDeviceDriver()
Reg_Address.l = $80000000 ;set Bit31
For Device = 0 To 31
Reg_Address & $FFFFF8FF ;set Functions=0
For Function = 0 To 7
WriteIoPortDword($0CF8, Reg_Address + $A) ;$A=Sub Class, $B=Base Class
Datas = ReadIoPortDword($0CFC)
Datas = (Datas >> 16) & $FFFF
If Datas = $0C05 ;SMB is Class $0C05
;Debug "Config_Address = " + Hex(Config_Address) + " " + "Reg_Address = " + Hex(Reg_Address)
WriteIoPortDword($0CF8, Reg_Address + $20) ;$20=Base Address Register (4) ...
Datas = ReadIoPortDword($0CFC)
Break 2
EndIf
Reg_Address + $100
Next
Next
Debug "Address = " + Hex(Datas & $FFFFFFFC)
UnloadDriver(DRIVER_FILE_NAME)
And driver.pb has these:
Code: Select all
Global handle.l
Global DRIVER_NAME.s = "WinRing0_1_2_0"
Global DRIVER_FILE_NAME.s
Global DRIVER_NAME_FULL.s = "\\.\WinRing0_1_2_0"
Structure PCIDEBUG_CONFREAD_INPUT
pci_address.l
pci_offset.l
EndStructure
Structure PCIDEBUG_MEMREAD_INPUT
address.q;l
unitsize.l
count.l
EndStructure
Import ""
GetNativeSystemInfo(*info)
EndImport
Structure OLS_WRITE_IO_PORT_INPUT
PortNumber.l
StructureUnion
LongData.l
ShortData.w
CharData.b
EndStructureUnion
EndStructure
Procedure.l ctl_code(DeviceType, Function, Method, Access)
ProcedureReturn ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method)
EndProcedure
Procedure WriteIoPortDWord(port.l, value.l)
returnedLength.w= 0;
result.l = #False;
length.l = 0;
inputBuffer.OLS_WRITE_IO_PORT_INPUT
inputBuffer\ShortData = value;
inputBuffer\PortNumber = port;
IOCTL_OLS_WRITE_IO_PORT_DWORD = ctl_code(40000,$838,0,1)
length = OffsetOf(OLS_WRITE_IO_PORT_INPUT\CharData) + SizeOf(inputBuffer\ShortData);
result = DeviceIoControl_(handle,IOCTL_OLS_WRITE_IO_PORT_DWORD, @inputBuffer, length,#Null,0, @returnedLength,#Null);
EndProcedure
Procedure.l ReadIoPortDWord(port.l)
If handle = #INVALID_HANDLE_VALUE
ProcedureReturn 101;
EndIf
IOCTL_OLS_READ_IO_PORT_DWORD.l = ctl_code(40000,$835,0,1)
returnedLength.l = 0;
result.l = #False;
value.l = 0;
result = DeviceIoControl_(handle, IOCTL_OLS_READ_IO_PORT_DWORD, @port, SizeOf(port), @value, SizeOf(value), @returnedLength, #Null)
ProcedureReturn value & $FFFF
EndProcedure
Procedure.l OpenDriver()
handle = CreateFile_(@DRIVER_NAME_FULL, #GENERIC_READ | #GENERIC_WRITE, #FILE_SHARE_READ | #FILE_SHARE_WRITE, 0, #OPEN_EXISTING, #FILE_ATTRIBUTE_NORMAL, 0)
If handle = #INVALID_HANDLE_VALUE
ProcedureReturn 0
EndIf
ProcedureReturn 1
EndProcedure
Procedure.l LoadDriver(filename.s, drivername.s)
hSCManager.l
hService.l
serviceStatus.SERVICE_STATUS
ret.l
hSCManager = OpenSCManager_(0, 0, #SC_MANAGER_ALL_ACCESS)
If Not hSCManager
ProcedureReturn 0
EndIf
hService = OpenService_(hSCManager, @drivername, #SERVICE_ALL_ACCESS)
If hService
ControlService_(hService, #SERVICE_CONTROL_STOP, @ServiceStatus)
DeleteService_(hService)
CloseServiceHandle_(hService)
EndIf
hService = CreateService_(hSCManager, @drivername, @drivername, #SERVICE_ALL_ACCESS, #SERVICE_KERNEL_DRIVER, #SERVICE_DEMAND_START, #SERVICE_ERROR_NORMAL, @filename, #Null, #Null, #Null, #Null, #Null)
ret = 0
If hService
ret = StartService_(hService, 0, 0)
CloseServiceHandle_(hService)
EndIf
CloseServiceHandle_(hSCManager)
ProcedureReturn ret
EndProcedure
Procedure.l UnloadDriver(drivername.s)
;SC_HANDLE
hSCManager.l
hService.l
serviceStatus.SERVICE_STATUS
ret.l = 0
hSCManager = OpenSCManager_(0, 0, #SC_MANAGER_ALL_ACCESS)
If hSCManager
ProcedureReturn 0
EndIf
hService = OpenService_(hSCManager, @drivername, #SERVICE_ALL_ACCESS)
If hService
ret = ControlService_(hService, #SERVICE_CONTROL_STOP, @serviceStatus)
If ret = 1
ret = DeleteService_(hService)
EndIf
CloseServiceHandle_(hService)
EndIf
CloseServiceHandle_(hSCManager)
ProcedureReturn ret
EndProcedure
Procedure.l GetRefCount(hHandle.l)
dwRefCount.l = -1
ReturnedLength.l: IoctlResult.l
IOCTL_GET_REFCONT.l = ctl_code(40000,$999,0,0)
If hHandle
IoctlResult = DeviceIoControl_(hHandle, IOCTL_GET_REFCONT, #Null, 0, @dwRefCount, SizeOf(dwRefCount), @ReturnedLength, #Null)
If Not IoctlResult
dwRefCount = -1
EndIf
EndIf
ProcedureReturn dwRefCount
EndProcedure
Procedure close()
dwRefCount.l = GetRefCount(handle)
If handle
CloseHandle_(handle)
EndIf
If dwRefCount = 1
UnloadDriver(DRIVER_NAME)
EndIf
handle = 0
EndProcedure
Procedure.l initialize(DRIVER_FILE_NAME.s)
ret.l
path.s
If OpenDriver()
ProcedureReturn 0; no error
EndIf
path = GetPathPart(ProgramFilename()) + DRIVER_FILE_NAME
ret = LoadDriver(path, DRIVER_NAME)
If ret = 0
ProcedureReturn 2; error
EndIf
If OpenDriver()
ProcedureReturn 0;no error
EndIf
ProcedureReturn 3;error
EndProcedure
Procedure.l LoadSYS()
ii.l: res.l
For ii=0 To 16
res = initialize(DRIVER_FILE_NAME)
If res = 0
;Debug "handle = " + Str(handle)
ProcedureReturn 1 ;Success
EndIf
Sleep_(100)
Next
msg.s = "An error occured when opening the driver " + DRIVER_FILE_NAME + " ."+Chr(10)+"The program will not run properly."
MessageRequester("Error",msg)
ProcedureReturn 0
EndProcedure
Procedure IsWin64(); is the OS 64;
Protected Info.SYSTEM_INFO
GetNativeSystemInfo(Info)
If info\wProcessorArchitecture
ProcedureReturn #True
EndIf
EndProcedure
Procedure LoadDeviceDriver()
Select OSVersion()
Case #PB_OS_Windows_95, #PB_OS_Windows_98, #PB_OS_Windows_ME
MessageRequester("Unsupported OS","Your OS is not supported.")
Default
If IsWin64() = 1
DRIVER_FILE_NAME = "WinRing0x64.sys"
Else
DRIVER_FILE_NAME = "WinRing0.sys"
EndIf
DrvStatus = LoadSYS()
EndSelect
EndProcedure
Any help to make it work would be appreciated.
I am wondering what InitializeOls() does more than me.... I wish I had the source code...