引用 张静茹:ntdll.dll并不是内核,而是一个内核调用的stub而已,可工作于R0和R3。NT内核下的Windows程序都会通过kernel32.dll间接链接此库,所以是可以调用的。
NTDLL.dll是内核吧,R3的程序能调R0的dll?
<code class="lang-cpp">typedef struct _OSVERSIONINFOEXW { DWORD dwOSVersionInfoSize; DWORD dwMajorVersion; DWORD dwMinorVersion; DWORD dwBuildNumber; DWORD dwPlatformId; WCHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage WORD wServicePackMajor; WORD wServicePackMinor; WORD wSuiteMask; BYTE wProductType; BYTE wReserved; } OSVERSIONINFOEXW, *POSVERSIONINFOW, *LPOSVERSIONINFOW, RTL_OSVERSIONINFOW, *PRTL_OSVERSIONINFOW;</code>
<code class="lang-cpp">BOOL GetVersionEx2(LPOSVERSIONINFOW lpVersionInformation) { HMODULE hNtDll = GetModuleHandleW(L"NTDLL"); // 获取ntdll.dll的句柄 typedef NTSTATUS (NTAPI*tRtlGetVersion)(PRTL_OSVERSIONINFOW povi); // RtlGetVersion的原型 tRtlGetVersion pRtlGetVersion = NULL; if (hNtDll) { pRtlGetVersion = (tRtlGetVersion)GetProcAddress(hNtDll, "RtlGetVersion"); // 获取RtlGetVersion地址 } if (pRtlGetVersion) { return pRtlGetVersion((PRTL_OSVERSIONINFOW)lpVersionInformation) >= 0; // 调用RtlGetVersion } return FALSE; }</code>
<code class="lang-cpp">#include <windows.h> #include <stdio.h> #include <atlbase.h> BOOL GetVersionEx2(LPOSVERSIONINFOW lpVersionInformation) { HMODULE hNtDll = GetModuleHandleW(L"NTDLL"); // 获取ntdll.dll的句柄 typedef NTSTATUS (NTAPI*tRtlGetVersion)(PRTL_OSVERSIONINFOW povi); // RtlGetVersion的原型 tRtlGetVersion pRtlGetVersion = NULL; if (hNtDll) { pRtlGetVersion = (tRtlGetVersion)GetProcAddress(hNtDll, "RtlGetVersion"); // 获取RtlGetVersion地址 } if (pRtlGetVersion) { return pRtlGetVersion((PRTL_OSVERSIONINFOW)lpVersionInformation) >= 0; // 调用RtlGetVersion } return FALSE; } #define NTDLL_RTL_GET_VERSION int main(int argc, _TCHAR* argv[]) { OSVERSIONINFOEXW ovi = {sizeof ovi}; #ifdef NTDLL_RTL_GET_VERSION GetVersionEx2((LPOSVERSIONINFOW)&ovi); printf("使用NTDLL->RtlGetVersion获取的信息:\n"); #else GetVersionExW((LPOSVERSIONINFOW)&ovi); printf("使用KERNEL32->GetVersionExW获取的信息:\n"); #endif printf("dwMajorVersion: %08x %d\n", ovi.dwMajorVersion, ovi.dwMajorVersion); printf("dwMinorVersion: %08x %d\n", ovi.dwMinorVersion, ovi.dwMinorVersion); printf("dwBuildNumber: %08x %d\n", ovi.dwBuildNumber, ovi.dwBuildNumber); printf("dwPlatformID: %08x %d\n", ovi.dwPlatformId, ovi.dwPlatformId); printf("szCSDVersion: %s\n", (char*)CW2A(ovi.szCSDVersion, 1)); printf("wServicePackMajor: %04x %d\n", ovi.wServicePackMajor, ovi.wServicePackMajor); printf("wServicePackMinor: %04x %d\n", ovi.wServicePackMinor, ovi.wServicePackMinor); printf("wSuitMask: %04x %d\n", ovi.wSuiteMask, ovi.wSuiteMask); printf("wProductType: %02x %d\n", ovi.wProductType, ovi.wProductType); printf("wReserved: %02x %d\n", ovi.wReserved, ovi.wReserved); return 0; }</atlbase.h></stdio.h></windows.h></code>
[修改于 9年3个月前 - 2015/09/19 10:37:02]
引用 张静茹:ntdll.dll并不是内核,而是一个内核调用的stub而已,可工作于R0和R3。NT内核下的Windows程序都会通过kernel32.dll间接链接此库,所以是可以调用的。
NTDLL.dll是内核吧,R3的程序能调R0的dll?
<code class="lang-cpp">typedef BOOL (WINAPI *tIsWow64Process) (HANDLE, PBOOL); BOOL bIsWow64 = FALSE; tIsWow64Process pIsWow64Process = (tIsWow64Process) GetProcAddress(GetModuleHandleW(L"kernel32"), "IsWow64Process"); if (NULL != pIsWow64Process) { if (!pIsWow64Process(GetCurrentProcess(),&bIsWow64)) printf("IsWow64Process error.\n"); } if (bIsWow64) { printf("IsWow64Process TRUE.\n"); } else { printf("IsWow64Process FALSE.\n"); }</code>
<code class="lang-cpp">//#include <commctrl.h> // 使用comctl32.dll版本6,这是个预处理指令 #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") // TaskDialog函数的原型 typedef HRESULT (WINAPI *tTaskDialog)(HWND hwndParent, HINSTANCE hInstance, PCWSTR pszWindowTitle, PCWSTR pszMainInstruction, PCWSTR pszContent, TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons, PCWSTR pszIcon, int *pnButton); // 加载comctl32.dll HMODULE hcomctl32 = LoadLibraryW(L"comctl32.dll"); // 加载成功 if (hcomctl32 != NULL) { // 获取TaskDialog函数地址 tTaskDialog pTaskDialog = (tTaskDialog)GetProcAddress(hcomctl32, "TaskDialog"); // 获取成功,调用TaskDIalog显示对话框 if (pTaskDialog != NULL) pTaskDialog(NULL, NULL, L"任务对话框", L"主指示", L"内容", TDCBF_OK_BUTTON|TDCBF_YES_BUTTON, TD_INFORMATION_ICON, NULL); // 释放comctl32.dll FreeLibrary(hcomctl32); }</commctrl.h></code>
<code class="lang-cpp">BOOL GetVersionEx2(LPOSVERSIONINFOW lpVersionInformation) { HMODULE hNtDll = GetModuleHandleW(L"NTDLL"); // 获取ntdll.dll的句柄 typedef NTSTATUS (NTAPI*tRtlGetVersion)(PRTL_OSVERSIONINFOW povi); // RtlGetVersion的原型 tRtlGetVersion pRtlGetVersion = NULL; if (hNtDll) { pRtlGetVersion = (tRtlGetVersion)GetProcAddress(hNtDll, "RtlGetVersion"); // 获取RtlGetVersion地址 } if (pRtlGetVersion) { return pRtlGetVersion((PRTL_OSVERSIONINFOW)lpVersionInformation) >= 0; // 调用RtlGetVersion } else { return GetVersionExW(lpVersionInformation); // Windows XP以下版本 } }</code>
Windows版本 | dwMajorVersion | dwMinorVersion | dwBuildNumber Win9x: byte-byte-word WinNT: dword | dwPlatformId |
Win32s on Windows 3.1 | 1 | 任意 | 任意 | 0 VER_PLATFORM_WIN32s |
Windows 95 | 4 | 0 | 4-0-950 4-0-1111(osr2) 4-3-1214(usb) | 1 VER_PLATFORM_WIN32_WINDOWS |
Windows 98 | 4 | 10 | 4-10-1998 4-10-2222(se) | 1 |
Windows Me | 4 | 90 | 4-90-3000 | 1 |
Windows NT 3.1 | 3 | 10 | 528 | [不支持GetVersionEx] |
Windows NT 3.5 | 3 | 50 | 807 | 2 VER_PLATFORM_WIN32_NT |
Windows NT 3.51 | 3 | 51 | 1057 | 2 |
Windows NT 4.0 | 4 | 0 | 1381 | 2 |
Windows 2000 | 5 | 0 | 2195 | 2 |
Windows XP | 5 | 1 | 2600 | 2 |
Windows Server 2003 Windows XP x64 | 5 | 2 | 3790 | 2 |
Windows Vista Windows Server 2008 | 6 | 0 | 6000/6001/6002 | 2 |
Windows 7 Windows Server 2008 R2 | 6 | 1 | 7600/7601 | 2 |
Windows 8 Windows Server 2012 | 6 | 2 | 9200 | 2 |
Windows 8.1 WindowsServer 2012 R2 | 6 | 3 | 9600 | 2 |
Windows 10 TH1 | 10 | 0 | 10240 | 2 |
时段 | 个数 |
---|---|
{{f.startingTime}}点 - {{f.endTime}}点 | {{f.fileCount}} |
200字以内,仅用于支线交流,主线讨论请采用回复功能。