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 "../memory/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("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 {
00092
00093
00094 throw smbios::NotImplementedImpl("Error loading DLLs needed to call functions to read CMOS.");
00095 }
00096 if (!EnableDebug())
00097 {
00098
00099
00100 throw smbios::NotImplementedImpl("Error loading DLLs needed to call functions to read CMOS.");
00101 }
00102 }
00103
00104
00105 CmosRWIo::CmosRWIo (const CmosRWIo &)
00106 : ICmosRW(), Suppressable()
00107 {}
00108
00109
00110 CmosRWIo & CmosRWIo::operator = (const CmosRWIo &)
00111 {
00112 return *this;
00113 }
00114
00115
00116
00117 u8 CmosRWIo::readByte (u32 indexPort, u32 dataPort, u32 offset) const
00118 {
00119 NTSTATUS status;
00120 u8 Buf;
00121
00122 IO_STRUCT io;
00123
00124 memset(&io, 0, sizeof(io));
00125 io.Addr = indexPort;
00126 io.pBuf = &offset;
00127 io.NumBytes = 1;
00128 io.Reserved4 = 1;
00129 io.Reserved6 = 1;
00130
00131 status = ZwSystemDebugControl(DebugSysWriteIoSpace, &io, sizeof(io), NULL, 0, NULL);
00132
00133
00134
00135 memset(&io, 0, sizeof(io));
00136 io.Addr = dataPort;
00137 io.pBuf = &Buf;
00138 io.NumBytes = 1;
00139 io.Reserved4 = 1;
00140 io.Reserved6 = 1;
00141
00142 status = ZwSystemDebugControl(DebugSysReadIoSpace, &io, sizeof(io), NULL, 0, NULL);
00143
00144
00145
00146 return Buf;
00147 }
00148
00149
00150
00151 void CmosRWIo::writeByte (u32 indexPort, u32 dataPort, u32 offset, u8 byte) const
00152 {
00153 (void) indexPort;
00154 (void) dataPort;
00155 (void) offset;
00156 (void) byte;
00157 throw smbios::NotImplementedImpl();
00158
00159
00160 #if 0
00161 if(! isNotifySuppressed() )
00162 {
00163 notify();
00164 }
00165 #endif
00166 }
00167
00168 }