mirror of
https://github.com/UzixLS/KernelEx.git
synced 2025-07-18 23:11:19 +03:00
import KernelEx-4.5-RC1
This commit is contained in:
@ -224,6 +224,7 @@ void SettingsDB::write_single(const char* path, const char* conf_name, BYTE flag
|
||||
char path2[MAX_PATH];
|
||||
strncpy(path2, path, sizeof(path2));
|
||||
strupr(path2);
|
||||
path = path2;
|
||||
|
||||
//check if configuration name is valid
|
||||
as.conf = apiconfmgr.get_api_configuration(conf_name);
|
||||
@ -253,8 +254,43 @@ void SettingsDB::write_single(const char* path, const char* conf_name, BYTE flag
|
||||
|
||||
//add to DB
|
||||
EnterCriticalSection(&cs);
|
||||
db.erase(path2);
|
||||
db.insert(pair<sstring,appsetting>(path2, as));
|
||||
db.erase(path);
|
||||
db.insert(pair<sstring,appsetting>(path, as));
|
||||
LeaveCriticalSection(&cs);
|
||||
}
|
||||
|
||||
void SettingsDB::reset_single(const char* path)
|
||||
{
|
||||
LONG result;
|
||||
HKEY key;
|
||||
|
||||
//convert path to uppercase
|
||||
char path2[MAX_PATH];
|
||||
strncpy(path2, path, sizeof(path2));
|
||||
strupr(path2);
|
||||
path = path2;
|
||||
|
||||
//erase config
|
||||
result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
||||
"Software\\KernelEx\\AppSettings\\Configs", 0, KEY_WRITE, &key);
|
||||
if (result == ERROR_SUCCESS)
|
||||
{
|
||||
RegDeleteValue(key, path);
|
||||
RegCloseKey(key);
|
||||
}
|
||||
|
||||
//erase flags
|
||||
result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
||||
"Software\\KernelEx\\AppSettings\\Flags", 0, KEY_WRITE, &key);
|
||||
if (result == ERROR_SUCCESS)
|
||||
{
|
||||
RegDeleteValue(key, path);
|
||||
RegCloseKey(key);
|
||||
}
|
||||
|
||||
//erase from DB
|
||||
EnterCriticalSection(&cs);
|
||||
db.erase(path);
|
||||
LeaveCriticalSection(&cs);
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ public:
|
||||
void flush_all();
|
||||
appsetting get_appsetting(const char* path);
|
||||
void write_single(const char* path, const char* conf_name, BYTE flags);
|
||||
void reset_single(const char* path);
|
||||
#ifdef _DEBUG
|
||||
void dump_db();
|
||||
#endif
|
||||
|
@ -108,6 +108,11 @@ void kexSetModuleSettings(const char* module,
|
||||
SettingsDB::instance.write_single(module, conf_name, flags);
|
||||
}
|
||||
|
||||
void kexResetModuleSettings(const char* module)
|
||||
{
|
||||
SettingsDB::instance.reset_single(module);
|
||||
}
|
||||
|
||||
void kexFlushAppSettings(void)
|
||||
{
|
||||
SettingsDB::instance.flush_all();
|
||||
|
@ -40,7 +40,7 @@ char system_path[MAX_PATH];
|
||||
int system_path_len;
|
||||
|
||||
static PLONG jtab;
|
||||
static LONG old_jtab[JTAB_SIZE];
|
||||
LONG old_jtab[JTAB_SIZE];
|
||||
static HKEY known_dlls_key;
|
||||
|
||||
FLoadTreeNotify_t FLoadTreeNotify;
|
||||
@ -56,6 +56,7 @@ static bool get_config(MODREF* moduleMR, config_params& cp)
|
||||
IMTE** pmteModTable = *ppmteModTable;
|
||||
PDB98* ppdbCur = *pppdbCur;
|
||||
volatile MODREF_KEX module(moduleMR);
|
||||
DBGASSERT(ppdbCur->pExeMODREF != NULL);
|
||||
MODREF_KEX process(ppdbCur->pExeMODREF);
|
||||
|
||||
//shared modules should use standard api
|
||||
@ -599,6 +600,59 @@ bool are_extensions_enabled()
|
||||
return get_config(exe, cp);
|
||||
}
|
||||
|
||||
/** Determines whether module has API extensions enabled.
|
||||
* Use this function when there is no access to MODREF.
|
||||
* @param path Full path of the module (uppercase).
|
||||
*/
|
||||
bool are_extensions_enabled_module(const char* path)
|
||||
{
|
||||
//find entry for given module...
|
||||
appsetting as = SettingsDB::instance.get_appsetting(path);
|
||||
|
||||
if (!(as.flags & LDR_VALID_FLAG))
|
||||
{
|
||||
//...no entry? try process exe settings...
|
||||
PDB98* ppdbCur = *pppdbCur;
|
||||
MODREF* exe = ppdbCur->pExeMODREF;
|
||||
|
||||
if (exe != NULL)
|
||||
{
|
||||
config_params cp;
|
||||
|
||||
as.flags = LDR_VALID_FLAG;
|
||||
if (!get_config(exe, cp))
|
||||
as.flags |= LDR_KEX_DISABLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
//...so there is NO PROCESS exe yet? try with parent process exe...
|
||||
PDB98* ppdbParent = ppdbCur->ParentPDB;
|
||||
|
||||
if (ppdbParent && !(ppdbParent->Flags & (fTerminated | fTerminating |
|
||||
fNearlyTerminating | fDosProcess | fWin16Process)))
|
||||
{
|
||||
MODREF_KEX parent(ppdbParent->pExeMODREF);
|
||||
|
||||
//...unless parent disallows us to inherit
|
||||
if ((parent.as.flags & LDR_VALID_FLAG) && !(parent.as.flags & LDR_NO_INHERIT))
|
||||
as = parent.as;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//...so everything else failed eh? - take defaults then...
|
||||
if (!(as.flags & LDR_VALID_FLAG))
|
||||
{
|
||||
as.flags = LDR_VALID_FLAG;
|
||||
if (apiconfmgr.are_extensions_disabled())
|
||||
as.flags |= LDR_KEX_DISABLE;
|
||||
}
|
||||
|
||||
if (as.flags & LDR_KEX_DISABLE)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef BOOL (__stdcall *IsKnownDLL_t)(char*, const char*);
|
||||
|
||||
static BOOL WINAPI IsKnownKexDLL(char* name, const char* ext)
|
||||
@ -648,6 +702,29 @@ static BOOL WINAPI KexLoadTreeNotify(MODREF* mr, BOOL is_static)
|
||||
return FLoadTreeNotify(mr, is_static);
|
||||
}
|
||||
|
||||
typedef BOOL (WINAPI * GetOrdinal_t)(DWORD, DWORD, DWORD, DWORD*, WORD*, DWORD);
|
||||
|
||||
static BOOL WINAPI KexResourceCheck(DWORD un0, DWORD un1, DWORD un2, DWORD* pNameOrId, WORD* pResult, DWORD un3)
|
||||
{
|
||||
DWORD NameOrId = *pNameOrId; //parameter from IMAGE_RESOURCE_DIRECTORY_ENTRY
|
||||
|
||||
//not a named resource and index > 32767 allowed by 9x ?
|
||||
if (!(NameOrId & 0x80000000) && NameOrId >= 0x8000 && NameOrId < 0x10000)
|
||||
{
|
||||
//we need to check if module has extensions enabled
|
||||
if (mod_ext_ena)
|
||||
{
|
||||
NameOrId |= 0x8000; //??
|
||||
*pResult = NameOrId;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
//fall back
|
||||
GetOrdinal_t GetOrdinal = (GetOrdinal_t) old_jtab[JTAB_RES_CHK];
|
||||
return GetOrdinal(un0, un1, un2, pNameOrId, pResult, un3);
|
||||
}
|
||||
|
||||
PROC WINAPI iGetProcAddress(HMODULE hModule, LPCSTR lpProcName)
|
||||
{
|
||||
IMAGE_DOS_HEADER* dos_hdr;
|
||||
@ -805,6 +882,8 @@ void resolver_hook()
|
||||
old_jtab[JTAB_EFN_STA] = InterlockedExchange(jtab + JTAB_EFN_STA, (LONG) ExportFromNameStatic_thunk);
|
||||
old_jtab[JTAB_KNO_DLL] = InterlockedExchange(jtab + JTAB_KNO_DLL, (LONG) IsKnownKexDLL);
|
||||
old_jtab[JTAB_FLD_TRN] = InterlockedExchange(jtab + JTAB_FLD_TRN, (LONG) KexLoadTreeNotify);
|
||||
old_jtab[JTAB_SYS_CHK] = InterlockedExchange(jtab + JTAB_SYS_CHK, (LONG) SubSysCheck);
|
||||
old_jtab[JTAB_RES_CHK] = InterlockedExchange(jtab + JTAB_RES_CHK, (LONG) KexResourceCheck);
|
||||
}
|
||||
|
||||
void resolver_unhook()
|
||||
|
@ -85,7 +85,10 @@ struct config_params
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
extern LONG old_jtab[];
|
||||
|
||||
bool are_extensions_enabled();
|
||||
bool are_extensions_enabled_module(const char* path);
|
||||
DWORD encode_address(DWORD addr, const ApiLibrary* apilib);
|
||||
PROC WINAPI iGetProcAddress(HMODULE hModule, LPCSTR lpProcName);
|
||||
PROC WINAPI ExportFromOrdinal(IMTE_KEX* target, MODREF* caller, BOOL is_static, WORD ordinal);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* KernelEx
|
||||
* Copyright (C) 2008-2009, Xeno86
|
||||
* Copyright (C) 2008-2010, Xeno86
|
||||
*
|
||||
* This file is part of KernelEx source code.
|
||||
*
|
||||
@ -23,6 +23,7 @@
|
||||
#include "thunks.h"
|
||||
#include "internals.h"
|
||||
#include "resolver.h"
|
||||
#include "../setup/loadstub.h"
|
||||
|
||||
__declspec(naked)
|
||||
PROC ExportFromOrdinalStatic_thunk(IMAGE_NT_HEADERS* PEh, WORD ordinal)
|
||||
@ -102,3 +103,27 @@ __asm {
|
||||
jmp ExportFromName
|
||||
}
|
||||
}
|
||||
|
||||
BYTE mod_ext_ena;
|
||||
|
||||
__declspec(naked)
|
||||
void SubSysCheck()
|
||||
{
|
||||
__asm {
|
||||
seta al /* is subsystem value above supported by OS? */
|
||||
push eax
|
||||
|
||||
push [ebp+8]
|
||||
call are_extensions_enabled_module
|
||||
add esp, 4
|
||||
mov mod_ext_ena, al
|
||||
cmp al, 1
|
||||
clc
|
||||
|
||||
pop ecx
|
||||
jz __done
|
||||
cmp cl, 0
|
||||
__done:
|
||||
jmp [old_jtab+4*JTAB_SYS_CHK]
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* KernelEx
|
||||
* Copyright (C) 2008-2009, Xeno86
|
||||
* Copyright (C) 2008-2010, Xeno86
|
||||
*
|
||||
* This file is part of KernelEx source code.
|
||||
*
|
||||
@ -26,5 +26,7 @@ PROC ExportFromOrdinalStatic_thunk(IMAGE_NT_HEADERS* PEh, WORD ordinal);
|
||||
PROC ExportFromNameStatic_thunk(IMAGE_NT_HEADERS* PEh, WORD hint, LPCSTR name);
|
||||
PROC ExportFromOrdinalDynamic_thunk(IMAGE_NT_HEADERS* PEh, WORD ordinal);
|
||||
PROC ExportFromNameDynamic_thunk(IMAGE_NT_HEADERS* PEh, WORD hint, LPCSTR name);
|
||||
void SubSysCheck();
|
||||
extern BYTE mod_ext_ena;
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user