00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #define LIBSMBIOS_SOURCE
00021 #include "smbios/compat.h"
00022
00023 #include <stdio.h>
00024 #include <conio.h>
00025
00026 #include "CmosRWImpl.h"
00027 #include "miniddk.h"
00028
00029 using namespace std;
00030
00031 namespace cmos
00032 {
00033
00034
00035 ZwSystemDebugControlPtr ZwSystemDebugControl;
00036
00037 int LoadNtdllFuncs(void)
00038 {
00039 HMODULE hNtdll;
00040
00041 hNtdll = GetModuleHandle(L"ntdll.dll");
00042 if (!hNtdll)
00043 return FALSE;
00044
00045 ZwSystemDebugControl = (ZwSystemDebugControlPtr) GetProcAddress(hNtdll, "ZwSystemDebugControl");
00046 if (!ZwSystemDebugControl)
00047 return FALSE;
00048
00049 return TRUE;
00050 }
00051
00052 int EnableDebug(void)
00053 {
00054 HANDLE hToken;
00055 TOKEN_PRIVILEGES TP;
00056 NTSTATUS status;
00057
00058 status = OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);
00059 if (!NT_SUCCESS(status))
00060 {
00061 return FALSE;
00062 }
00063
00064 TP.PrivilegeCount = 1;
00065 TP.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
00066
00067 status = LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &TP.Privileges[0].Luid);
00068 if (!NT_SUCCESS(status))
00069 {
00070 return FALSE;
00071 }
00072
00073 status = AdjustTokenPrivileges(hToken, FALSE, &TP, sizeof(TP), NULL, NULL);
00074 if (!NT_SUCCESS(status))
00075 {
00076 return FALSE;
00077 }
00078
00079 return TRUE;
00080 }
00081
00082
00083
00084
00085
00086 CmosRWIo::CmosRWIo ()
00087 : ICmosRW(), Suppressable()
00088 {
00089
00090 if (!LoadNtdllFuncs())
00091 throw smbios::NotImplementedImpl("Error loading DLLs needed to call functions to read CMOS.");
00092
00093 if (!EnableDebug())
00094 throw smbios::NotImplementedImpl("Error loading DLLs needed to call functions to read CMOS.");
00095 }
00096
00097
00098 CmosRWIo::CmosRWIo (const CmosRWIo &)
00099 : ICmosRW(), Suppressable()
00100 {}
00101
00102
00103 CmosRWIo & CmosRWIo::operator = (const CmosRWIo &)
00104 {
00105 return *this;
00106 }
00107
00108
00109
00110 u8 CmosRWIo::readByte (u32 indexPort, u32 dataPort, u32 offset) const
00111 {
00112 NTSTATUS status;
00113 u8 Buf;
00114
00115 IO_STRUCT io;
00116
00117 memset(&io, 0, sizeof(io));
00118 io.Addr = indexPort;
00119 io.pBuf = &offset;
00120 io.NumBytes = 1;
00121 io.Reserved4 = 1;
00122 io.Reserved6 = 1;
00123
00124 status = ZwSystemDebugControl(DebugSysWriteIoSpace, &io, sizeof(io), NULL, 0, NULL);
00125 if (!NT_SUCCESS(status))
00126 throw smbios::NotImplementedImpl();
00127
00128 memset(&io, 0, sizeof(io));
00129 io.Addr = dataPort;
00130 io.pBuf = &Buf;
00131 io.NumBytes = 1;
00132 io.Reserved4 = 1;
00133 io.Reserved6 = 1;
00134
00135 status = ZwSystemDebugControl(DebugSysReadIoSpace, &io, sizeof(io), NULL, 0, NULL);
00136 if (!NT_SUCCESS(status))
00137 throw smbios::NotImplementedImpl();
00138
00139 return Buf;
00140 }
00141
00142
00143
00144 void CmosRWIo::writeByte (u32 indexPort, u32 dataPort, u32 offset, u8 byte) const
00145 {
00146 (void) indexPort;
00147 (void) dataPort;
00148 (void) offset;
00149 (void) byte;
00150 throw smbios::NotImplementedImpl();
00151
00152
00153 #if 0
00154 if(! isNotifySuppressed() )
00155 {
00156 notify();
00157 }
00158 #endif
00159 }
00160
00161 }