add separate file for delayed imports

This commit is contained in:
FunkyFr3sh 2024-12-31 04:00:22 +01:00
parent 883aadd449
commit 8c587b21dd
7 changed files with 65 additions and 29 deletions

33
src/delay_imports.c Normal file
View file

@ -0,0 +1,33 @@
#include <windows.h>
#include "versionhelpers.h"
typedef NTSTATUS(WINAPI* RTLVERIFYVERSIONINFOPROC)(PRTL_OSVERSIONINFOEXW, ULONG, ULONGLONG);
typedef ULONGLONG(WINAPI* VERSETCONDITIONMASKPROC)(ULONGLONG, DWORD, BYTE);
typedef const char* (CDECL* WINE_GET_VERSIONPROC)();
typedef void (CDECL* WINE_GET_HOST_VERSIONPROC)(const char** sysname, const char** release);
typedef NTSTATUS(WINAPI* NTQUERYINFORMATIONTHREADPROC)(HANDLE, LONG, PVOID, ULONG, PULONG);
NTQUERYINFORMATIONTHREADPROC NtQueryInformationThread;
RTLVERIFYVERSIONINFOPROC RtlVerifyVersionInfo;
WINE_GET_VERSIONPROC wine_get_version;
WINE_GET_HOST_VERSIONPROC wine_get_host_version;
VERSETCONDITIONMASKPROC VerSetConditionMaskProc;
void imports_init()
{
HMODULE mod = GetModuleHandleA("ntdll.dll");
if (mod)
{
NtQueryInformationThread = (NTQUERYINFORMATIONTHREADPROC)GetProcAddress(mod, "NtQueryInformationThread");
RtlVerifyVersionInfo = (RTLVERIFYVERSIONINFOPROC)GetProcAddress(mod, "RtlVerifyVersionInfo");
wine_get_version = (WINE_GET_VERSIONPROC)GetProcAddress(mod, "wine_get_version");
wine_get_host_version = (WINE_GET_HOST_VERSIONPROC)GetProcAddress(mod, "wine_get_host_version");
}
mod = GetModuleHandleA("Kernel32.dll");
if (mod)
{
VerSetConditionMaskProc = (VERSETCONDITIONMASKPROC)GetProcAddress(mod, "VerSetConditionMask");
}
}

View file

@ -12,6 +12,7 @@
#include "indeo.h"
#include "utils.h"
#include "versionhelpers.h"
#include "delay_imports.h"
#include "keyboard.h"
@ -33,7 +34,7 @@ BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
{
g_ddraw_module = hDll;
verhelp_init();
imports_init();
if (GetEnvironmentVariable("cnc_ddraw_config_init", NULL, 0))
{

View file

@ -1,33 +1,7 @@
#include <windows.h>
#include "versionhelpers.h"
#include "delay_imports.h"
typedef NTSTATUS(WINAPI* RTLVERIFYVERSIONINFOPROC)(PRTL_OSVERSIONINFOEXW, ULONG, ULONGLONG);
typedef ULONGLONG(WINAPI* VERSETCONDITIONMASKPROC)(ULONGLONG, DWORD, BYTE);
typedef const char* (CDECL* WINE_GET_VERSIONPROC)();
typedef void (CDECL* WINE_GET_HOST_VERSIONPROC)(const char** sysname, const char** release);
static RTLVERIFYVERSIONINFOPROC RtlVerifyVersionInfo;
static VERSETCONDITIONMASKPROC VerSetConditionMaskProc;
static WINE_GET_VERSIONPROC wine_get_version;
static WINE_GET_HOST_VERSIONPROC wine_get_host_version;
/* GetProcAddress is rather slow so we use a function to initialize it once on startup */
void verhelp_init()
{
HMODULE mod = GetModuleHandleA("ntdll.dll");
if (mod)
{
RtlVerifyVersionInfo = (RTLVERIFYVERSIONINFOPROC)GetProcAddress(mod, "RtlVerifyVersionInfo");
wine_get_version = (WINE_GET_VERSIONPROC)GetProcAddress(mod, "wine_get_version");
wine_get_host_version = (WINE_GET_HOST_VERSIONPROC)GetProcAddress(mod, "wine_get_host_version");
}
mod = GetModuleHandleA("Kernel32.dll");
if (mod)
{
VerSetConditionMaskProc = (VERSETCONDITIONMASKPROC)GetProcAddress(mod, "VerSetConditionMask");
}
}
BOOL verhelp_verify_version(PRTL_OSVERSIONINFOEXW versionInfo, ULONG typeMask, ULONGLONG conditionMask)
{