Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[APPHELP][APPHELP_APITEST] Implement various VersionLie shims. CORE-1…
…1299 #resolve

- Implement VersionLie shims
- Add tests for the VersionLie shims
- update get_host_winver prototype (thanks to Thomas for pointing out my err)

We cannot apply this shim yet, since a required part of the infrastructure is missing.

svn path=/trunk/; revision=71442
  • Loading branch information
learn-more committed May 28, 2016
1 parent 15082cc commit cc1a5a5
Show file tree
Hide file tree
Showing 12 changed files with 721 additions and 4 deletions.
1 change: 1 addition & 0 deletions reactos/dll/appcompat/shims/CMakeLists.txt
@@ -1,3 +1,4 @@

add_subdirectory(shimlib)
add_subdirectory(layer)

18 changes: 18 additions & 0 deletions reactos/dll/appcompat/shims/layer/CMakeLists.txt
@@ -0,0 +1,18 @@

include_directories(${SHIMLIB_DIR})

spec2def(aclayers.dll layer.spec)

list(APPEND SOURCE
versionlie.c
main.c
layer.spec)

add_library(aclayers SHARED
${SOURCE}
${CMAKE_CURRENT_BINARY_DIR}/aclayers.def)

set_module_type(aclayers win32dll)
target_link_libraries(aclayers shimlib)
add_importlibs(aclayers msvcrt kernel32 ntdll)
add_cd_file(TARGET aclayers DESTINATION reactos/AppPatch FOR all)
3 changes: 3 additions & 0 deletions reactos/dll/appcompat/shims/layer/layer.spec
@@ -0,0 +1,3 @@

@ stdcall GetHookAPIs(str wstr ptr)
@ stdcall NotifyShims(long ptr)
37 changes: 37 additions & 0 deletions reactos/dll/appcompat/shims/layer/main.c
@@ -0,0 +1,37 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Shim library
* FILE: dll/appcompat/shims/layer/main.c
* PURPOSE: Shim entrypoint
* PROGRAMMER: Mark Jansen
*/

#include <windows.h>
#include <strsafe.h>
#include <shimlib.h>

/* Forward to the generic implementation */
PHOOKAPI WINAPI GetHookAPIs(IN LPCSTR szCommandLine, IN LPCWSTR wszShimName, OUT PDWORD pdwHookCount)
{
return ShimLib_GetHookAPIs(szCommandLine, wszShimName, pdwHookCount);
}

/* PLDR_DATA_TABLE_ENTRY */
BOOL WINAPI NotifyShims(DWORD fdwReason, PVOID P)
{
return TRUE;
}

BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
switch(dwReason)
{
case DLL_PROCESS_ATTACH:
ShimLib_Init(hInstance);
break;
case DLL_PROCESS_DETACH:
ShimLib_Deinit();
break;
}
return TRUE;
}
232 changes: 232 additions & 0 deletions reactos/dll/appcompat/shims/layer/versionlie.c
@@ -0,0 +1,232 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Shim library
* FILE: dll/appcompat/shims/layer/versionlie.c
* PURPOSE: Version lie shims
* PROGRAMMER: Mark Jansen
*/

#include <windows.h>
#include <shimlib.h>
#include <strsafe.h>

/* Generic version info to use with the shims */
typedef struct VersionLieInfo
{
DWORD FullVersion;
WORD dwMajorVersion;
WORD dwMinorVersion;
DWORD dwBuildNumber;
WORD dwPlatformId;
WORD wServicePackMajor;
WORD wServicePackMinor;
char szCSDVersionA[20];
WCHAR szCSDVersionW[20];
} VersionLieInfo;

VersionLieInfo g_Win95 = { 0xC3B60004, 4, 0, 950, VER_PLATFORM_WIN32_WINDOWS, 0, 0 };
VersionLieInfo g_WinNT4SP5 = { 0x05650004, 4, 0, 1381, VER_PLATFORM_WIN32_NT, 5, 0 };
VersionLieInfo g_Win98 = { 0xC0000A04, 4, 10, 0x040A08AE, VER_PLATFORM_WIN32_WINDOWS, 0, 0 };

VersionLieInfo g_Win2000 = { 0x08930005, 5, 0, 2195, VER_PLATFORM_WIN32_NT, 0, 0 };
VersionLieInfo g_Win2000SP1 = { 0x08930005, 5, 0, 2195, VER_PLATFORM_WIN32_NT, 1, 0 };
VersionLieInfo g_Win2000SP2 = { 0x08930005, 5, 0, 2195, VER_PLATFORM_WIN32_NT, 2, 0 };
VersionLieInfo g_Win2000SP3 = { 0x08930005, 5, 0, 2195, VER_PLATFORM_WIN32_NT, 3, 0 };

VersionLieInfo g_WinXP = { 0x0a280105, 5, 1, 2600, VER_PLATFORM_WIN32_NT, 0, 0 };
VersionLieInfo g_WinXPSP1 = { 0x0a280105, 5, 1, 2600, VER_PLATFORM_WIN32_NT, 1, 0 };
VersionLieInfo g_WinXPSP2 = { 0x0a280105, 5, 1, 2600, VER_PLATFORM_WIN32_NT, 2, 0 };
VersionLieInfo g_WinXPSP3 = { 0x0a280105, 5, 1, 2600, VER_PLATFORM_WIN32_NT, 3, 0 };

VersionLieInfo g_Win2k3RTM = { 0x0ece0205, 5, 2, 3790, VER_PLATFORM_WIN32_NT, 0, 0 };
VersionLieInfo g_Win2k3SP1 = { 0x0ece0205, 5, 2, 3790, VER_PLATFORM_WIN32_NT, 1, 0 };

VersionLieInfo g_WinVistaRTM = { 0x17700006, 6, 0, 6000, VER_PLATFORM_WIN32_NT, 0, 0 };
VersionLieInfo g_WinVistaSP1 = { 0x17710006, 6, 0, 6001, VER_PLATFORM_WIN32_NT, 1, 0 };
VersionLieInfo g_WinVistaSP2 = { 0x17720006, 6, 0, 6002, VER_PLATFORM_WIN32_NT, 2, 0 };

VersionLieInfo g_Win7RTM = { 0x1db00106, 6, 1, 7600, VER_PLATFORM_WIN32_NT, 0, 0 };


/* Fill the OSVERSIONINFO[EX][W|A] struct with the info from the generic VersionLieInfo */

BOOL FakeVersion(LPOSVERSIONINFOEXA pResult, VersionLieInfo* pFake)
{
if (pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA) || pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOA) ||
pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW) || pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOW))
{
pResult->dwMajorVersion = pFake->dwMajorVersion;
pResult->dwMinorVersion = pFake->dwMinorVersion;
pResult->dwBuildNumber = pFake->dwBuildNumber;
pResult->dwPlatformId = pFake->dwPlatformId;
if (pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA) || pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOA))
{
if (FAILED(StringCbCopyA(pResult->szCSDVersion, sizeof(pResult->szCSDVersion), pFake->szCSDVersionA)))
return FALSE;
if (pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA) && pFake->dwPlatformId != VER_PLATFORM_WIN32_WINDOWS)
{
pResult->wServicePackMajor = pFake->wServicePackMajor;
pResult->wServicePackMinor = pFake->wServicePackMinor;
}
}
else
{
LPOSVERSIONINFOEXW pResultW = (LPOSVERSIONINFOEXW)pResult;
if (FAILED(StringCbCopyW(pResultW->szCSDVersion, sizeof(pResultW->szCSDVersion), pFake->szCSDVersionW)))
return FALSE;
if (pResultW->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW) && pFake->dwPlatformId != VER_PLATFORM_WIN32_WINDOWS)
{
pResultW->wServicePackMajor = pFake->wServicePackMajor;
pResultW->wServicePackMinor = pFake->wServicePackMinor;
}
}
return TRUE;
}
return FALSE;
}

typedef BOOL(WINAPI* GETVERSIONEXAPROC)(LPOSVERSIONINFOEXA);


#define SHIM_NS Win95VersionLie

#include <setup_shim.inl>

DWORD WINAPI SHIM_OBJ_NAME(APIHook_GetVersion)()
{
return g_Win95.FullVersion;
}

BOOL WINAPI SHIM_OBJ_NAME(APIHook_GetVersionExA)(LPOSVERSIONINFOEXA lpOsVersionInfo)
{
if (CALL_SHIM(1, GETVERSIONEXAPROC)(lpOsVersionInfo))
{
return FakeVersion(lpOsVersionInfo, &g_Win95);
}
return FALSE;
}

/* We do not call about the actual type, FakeVersion will correctly handle it either way */
BOOL WINAPI SHIM_OBJ_NAME(APIHook_GetVersionExW)(LPOSVERSIONINFOEXA lpOsVersionInfo)
{
if (CALL_SHIM(2, GETVERSIONEXAPROC)(lpOsVersionInfo))
{
return FakeVersion(lpOsVersionInfo, &g_Win95);
}
return FALSE;
}

#define SHIM_NUM_HOOKS 3
#define SHIM_SETUP_HOOKS \
SHIM_HOOK(0, "KERNEL32.DLL", "GetVersion", SHIM_OBJ_NAME(APIHook_GetVersion)) \
SHIM_HOOK(1, "KERNEL32.DLL", "GetVersionExA", SHIM_OBJ_NAME(APIHook_GetVersionExA)) \
SHIM_HOOK(2, "KERNEL32.DLL", "GetVersionExW", SHIM_OBJ_NAME(APIHook_GetVersionExW))

#include <implement_shim.inl>




#define SHIM_NS Win98VersionLie

#include <setup_shim.inl>

DWORD WINAPI SHIM_OBJ_NAME(APIHook_GetVersion)()
{
return g_Win98.FullVersion;
}

BOOL WINAPI SHIM_OBJ_NAME(APIHook_GetVersionExA)(LPOSVERSIONINFOEXA lpOsVersionInfo)
{
if (CALL_SHIM(0, GETVERSIONEXAPROC)(lpOsVersionInfo))
{
return FakeVersion(lpOsVersionInfo, &g_Win98);
}
return FALSE;
}

/* We do not call about the actual type, FakeVersion will correctly handle it either way */
BOOL WINAPI SHIM_OBJ_NAME(APIHook_GetVersionExW)(LPOSVERSIONINFOEXA lpOsVersionInfo)
{
if (CALL_SHIM(1, GETVERSIONEXAPROC)(lpOsVersionInfo))
{
return FakeVersion(lpOsVersionInfo, &g_Win98);
}
return FALSE;
}

#define SHIM_NUM_HOOKS 3
#define SHIM_SETUP_HOOKS \
SHIM_HOOK(2, "KERNEL32.DLL", "GetVersion", SHIM_OBJ_NAME(APIHook_GetVersion)) \
SHIM_HOOK(0, "KERNEL32.DLL", "GetVersionExA", SHIM_OBJ_NAME(APIHook_GetVersionExA)) \
SHIM_HOOK(1, "KERNEL32.DLL", "GetVersionExW", SHIM_OBJ_NAME(APIHook_GetVersionExW))

#include <implement_shim.inl>



#define SHIM_NS WinNT4SP5VersionLie
#define VERSION_INFO g_WinNT4SP5
#include "versionlie.inl"

#define SHIM_NS Win2000VersionLie
#define VERSION_INFO g_Win2000
#include "versionlie.inl"

#define SHIM_NS Win2000SP1VersionLie
#define VERSION_INFO g_Win2000SP1
#include "versionlie.inl"

#define SHIM_NS Win2000SP2VersionLie
#define VERSION_INFO g_Win2000SP2
#include "versionlie.inl"

#define SHIM_NS Win2000SP3VersionLie
#define VERSION_INFO g_Win2000SP3
#include "versionlie.inl"


#define SHIM_NS WinXPVersionLie
#define VERSION_INFO g_WinXP
#include "versionlie.inl"

#define SHIM_NS WinXPSP1VersionLie
#define VERSION_INFO g_WinXPSP1
#include "versionlie.inl"

#define SHIM_NS WinXPSP2VersionLie
#define VERSION_INFO g_WinXPSP2
#include "versionlie.inl"

#define SHIM_NS WinXPSP3VersionLie
#define VERSION_INFO g_WinXPSP3
#include "versionlie.inl"


#define SHIM_NS Win2k3RTMVersionLie
#define VERSION_INFO g_Win2k3RTM
#include "versionlie.inl"

#define SHIM_NS Win2k3SP1VersionLie
#define VERSION_INFO g_Win2k3SP1
#include "versionlie.inl"


#define SHIM_NS VistaRTMVersionLie
#define VERSION_INFO g_WinVistaRTM
#include "versionlie.inl"

#define SHIM_NS VistaSP1VersionLie
#define VERSION_INFO g_WinVistaSP1
#include "versionlie.inl"

#define SHIM_NS VistaSP2VersionLie
#define VERSION_INFO g_WinVistaSP2
#include "versionlie.inl"


#define SHIM_NS Win7RTMVersionLie
#define VERSION_INFO g_Win7RTM
#include "versionlie.inl"


73 changes: 73 additions & 0 deletions reactos/dll/appcompat/shims/layer/versionlie.inl
@@ -0,0 +1,73 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Shim library
* FILE: dll/appcompat/shims/layer/versionlie.inl
* PURPOSE: Version lie implementation helper
* PROGRAMMER: Mark Jansen
*/


#include <setup_shim.inl>

DWORD WINAPI SHIM_OBJ_NAME(APIHook_GetVersion)()
{
return VERSION_INFO.FullVersion;
}

BOOL WINAPI SHIM_OBJ_NAME(APIHook_GetVersionExA)(LPOSVERSIONINFOEXA lpOsVersionInfo)
{
if (CALL_SHIM(0, GETVERSIONEXAPROC)(lpOsVersionInfo))
{
return FakeVersion(lpOsVersionInfo, &VERSION_INFO);
}
return FALSE;
}

/* We do not care about the actual type, FakeVersion will correctly handle it either way */
BOOL WINAPI SHIM_OBJ_NAME(APIHook_GetVersionExW)(LPOSVERSIONINFOEXA lpOsVersionInfo)
{
if (CALL_SHIM(1, GETVERSIONEXAPROC)(lpOsVersionInfo))
{
return FakeVersion(lpOsVersionInfo, &VERSION_INFO);
}
return FALSE;
}

/* We do not care about the actual type, FakeVersion will correctly handle it either way */
BOOL WINAPI SHIM_OBJ_NAME(APIHook_RtlGetVersion)(LPOSVERSIONINFOEXA lpOsVersionInfo)
{
if (CALL_SHIM(3, GETVERSIONEXAPROC)(lpOsVersionInfo))
{
return FakeVersion(lpOsVersionInfo, &VERSION_INFO);
}
return FALSE;
}

BOOL WINAPI SHIM_OBJ_NAME(Notify)(DWORD fdwReason)
{
if (fdwReason == SHIM_REASON_ATTACH && VERSION_INFO.wServicePackMajor)
{
HRESULT hr = StringCbPrintfA(VERSION_INFO.szCSDVersionA, sizeof(VERSION_INFO.szCSDVersionA),
"Service Pack %u", VERSION_INFO.wServicePackMajor);
if (FAILED(hr))
return FALSE;
StringCbPrintfW(VERSION_INFO.szCSDVersionW, sizeof(VERSION_INFO.szCSDVersionW),
(CONST WCHAR[]){'S','e','r','v','i','c','e',' ','P','a','c','k',' ','%','u',0}, VERSION_INFO.wServicePackMajor);
if (FAILED(hr))
return FALSE;
}
return TRUE;
}


#define SHIM_NUM_HOOKS 4
#define SHIM_SETUP_HOOKS \
SHIM_HOOK(0, "KERNEL32.DLL", "GetVersionExA", SHIM_OBJ_NAME(APIHook_GetVersionExA)) \
SHIM_HOOK(1, "KERNEL32.DLL", "GetVersionExW", SHIM_OBJ_NAME(APIHook_GetVersionExW)) \
SHIM_HOOK(2, "KERNEL32.DLL", "GetVersion", SHIM_OBJ_NAME(APIHook_GetVersion)) \
SHIM_HOOK(3, "NTDLL.DLL", "RtlGetVersion", SHIM_OBJ_NAME(APIHook_RtlGetVersion))
#define SHIM_NOTIFY_FN SHIM_OBJ_NAME(Notify)

#include <implement_shim.inl>

#undef VERSION_INFO
3 changes: 2 additions & 1 deletion rostests/apitests/apphelp/CMakeLists.txt
@@ -1,11 +1,12 @@

project(appcompat)
add_definitions(-D__ROS_LONG64__)

list(APPEND SOURCE
apphelp.c
data.c
db.c
layerapi.c
versionlie.c
testlist.c)

add_executable(apphelp_apitest ${SOURCE})
Expand Down
2 changes: 1 addition & 1 deletion rostests/apitests/apphelp/apphelp.c
Expand Up @@ -40,7 +40,7 @@
void test_create_exe_imp(const char* name, int skip_rsrc_exports);
void test_create_file_imp(const char* name, const char* contents, size_t len);
void test_create_ne_imp(const char* name, int skip_names);
DWORD get_host_winver();
DWORD get_host_winver(void);

#define test_create_exe (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : test_create_exe_imp
#define test_create_file (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : test_create_file_imp
Expand Down

0 comments on commit cc1a5a5

Please sign in to comment.