1
0
mirror of https://github.com/UzixLS/KernelEx.git synced 2025-07-18 23:11:19 +03:00

import KernelEx-4.5-Beta1

This commit is contained in:
UzixLS
2018-11-03 16:21:13 +03:00
parent d6aad6c6c5
commit 09929b2b7d
392 changed files with 17832 additions and 2491 deletions

0
common/is_sorted.hpp Normal file → Executable file
View File

1
common/k32ord.def Normal file → Executable file
View File

@ -10,6 +10,7 @@ EXPORTS
VxDCall6 @6 NONAME
VxDCall7 @7 NONAME
VxDCall8 @8 NONAME
_GetpWin16Lock @93 NONAME
_EnterSysLevel @97 NONAME
_LeaveSysLevel @98 NONAME
MakeCriticalSectionGlobal

1
common/k32ord.h Normal file → Executable file
View File

@ -43,6 +43,7 @@
extern "C" {
#endif
MAKE_HEADER(void __stdcall _GetpWin16Lock(CRITICAL_SECTION** cs))
MAKE_HEADER(void __stdcall _EnterSysLevel(CRITICAL_SECTION* cs))
MAKE_HEADER(void __stdcall _LeaveSysLevel(CRITICAL_SECTION* cs))

62
common/kexcoresdk.h Normal file → Executable file
View File

@ -113,7 +113,20 @@ _KEXCOREIMP unsigned long kexGetKEXVersion();
_KEXCOREIMP int kexIsDebugCore();
/** kexDebugPrint - output debug information
/** DBGPRINTF - convenience macro for including debug messages only in debugs.
*
* Sample usage: DBGPRINTF(("This is a test %d %s\n", 1, "ttt"));
*/
#ifndef KEXCORE_EXPORTS
#ifndef _DEBUG
#define DBGPRINTF(x) do { } while (0)
#else
#define DBGPRINTF(x) kexDebugPrint x
#endif
#endif
/** kexDebugPrint - output debug message
*
* Parameters are compatible with printf command,
* maximum output length is limited to 256 bytes.
@ -149,30 +162,67 @@ _KEXCOREIMP HANDLE kexOpenThread(DWORD dwDesiredAccess, BOOL bInheritHandle, DWO
_KEXCOREIMP BOOL kexAreExtensionsEnabled();
/** KernelEx resolver flags. */
#define KRF_KEX_DISABLE 1 /* disable KernelEx API extensions for this module */
#define KRF_OVERRIDE_PROC_MOD 2 /* use same configuration and flags for all modules in a process */
#define KRF_LOG_APIS 4 /* enable API tracing */
#define KRF_NO_INHERIT 16 /* don't inherit configuration and flags to child processes */
#define KRF_VALID_FLAG 128 /* denotes that flags field is valid */
/** kexGetModuleSettings - Retrieve per module settings.
*
* @param module Module path.
* @param conf_name Receives configuration name, has to be at least 256 bytes long.
* @param ldr_flags Receives flags.
* @param conf_name Receives configuration name, buffer has to be at least 256 bytes long.
* @param mod_flags Receives resolver flags.
*/
_KEXCOREIMP void kexGetModuleSettings(const char* module,
char* conf_name, BYTE* ldr_flags);
char* conf_name, DWORD* mod_flags);
/** kexSetModuleSettings - Set per module settings.
*
* @param module Module path.
* @param conf_name Configuration name to be set for the module.
* @param ldr_flags Flags to be set for the module.
* @param mod_flags Resolver flags to be set for the module.
*/
_KEXCOREIMP void kexSetModuleSettings(const char* module,
const char* conf_name, BYTE ldr_flags);
const char* conf_name, DWORD mod_flags);
/** kexFlushAppSettings - Reloads all module settings from registy. */
_KEXCOREIMP void kexFlushAppSettings(void);
/** kexPsAllocIndex - Reserve process storage entry.
*
* @return Index to access process storage.
*/
_KEXCOREIMP int kexPsAllocIndex(void);
/** kexPsGetValue - Get process value associated with tag.
*
* @param index Index allocated with kexPsAllocIndex.
*/
_KEXCOREIMP void* kexPsGetValue(int index);
/** kexPsSetValue - Set process value associated with tag.
*
* @param index Index allocated with kexPsAllocIndex.
* @param value Any data, pass zero to free storage associated with tag.
*/
_KEXCOREIMP int kexPsSetValue(int index, void* value);
/** kexGetK32Lock - obtain pointer to Kernel32 lock object.
*
* @return Pointer to Kernel32 lock object.
*/
_KEXCOREIMP void* kexGetK32Lock();
#ifdef __cplusplus
} /* extern "C" */
#endif

74
common/linear_table.hpp Executable file
View File

@ -0,0 +1,74 @@
#ifndef __LINEAR_TABLE_HPP
#define __LINEAR_TABLE_HPP
#include <algorithm>
template<typename _Key, typename _Value, int _N>
class linear_table
{
public:
linear_table()
{
m_count = 0;
}
void free(const _Key& _k)
{
for (int i = 0 ; i < m_count ; i++)
if (m_data[i].k == _k)
{
std::copy(m_data + i + 1, m_data + m_count, m_data + i);
--m_count;
break;
}
}
_Value get(const _Key& _k)
{
for (int i = 0 ; i < m_count ; i++)
if (m_data[i].k == _k)
return m_data[i].v;
return 0;
}
bool set(const _Key& _k, const _Value& _v)
{
for (int i = 0 ; i < m_count ; i++)
if (m_data[i].k == _k)
{
m_data[i].v = _v;
return true;
}
// alloc if there's no such key in table
if (!alloc(_k))
return false;
m_data[get_count() - 1].v = _v;
return true;
}
int get_count()
{
return m_count;
}
protected:
bool alloc(const _Key& _k)
{
if (m_count == _N)
return false;
m_data[m_count].k = _k;
m_data[m_count].v = 0;
++m_count;
return true;
}
private:
int m_count;
struct
{
_Key k;
_Value v;
} m_data[_N];
};
#endif

41
common/msvc_quirks.h Executable file
View File

@ -0,0 +1,41 @@
/*
* KernelEx
* Copyright (C) 2009, Xeno86
*
* This file is part of KernelEx source code.
*
* KernelEx is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; version 2 of the License.
*
* KernelEx is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/** @file
* This file contains workarounds for compiler bugs.
* This file is included in every file MSVC compiles via forced includes /FI flag.
*/
#ifndef __MSVC_QUIRKS_H
#define __MSVC_QUIRKS_H
/* MSVC 6.0 quirks */
#if defined(_MSC_VER) && _MSC_VER < 1201
/* MSVC 6.0 for-loop workaround. */
#define for if (0); else for
/* disable "identifier was truncated to '255' characters in the debug information" */
#pragma warning(disable:4786)
#endif /* MSVC 6.0 quirks */
#endif

0
common/pemanip.cpp Normal file → Executable file
View File

0
common/pemanip.h Normal file → Executable file
View File

0
common/sstring.hpp Normal file → Executable file
View File

184
common/stdint.h Executable file
View File

@ -0,0 +1,184 @@
/* ISO C9x 7.18 Integer types <stdint.h>
* Based on ISO/IEC SC22/WG14 9899 Committee draft (SC22 N2794)
*
* THIS SOFTWARE IS NOT COPYRIGHTED
*
* Contributor: Danny Smith <danny_r_smith_2001@yahoo.co.nz>
*
* This source code is offered for use in the public domain. You may
* use, modify or distribute it freely.
*
* This code is distributed in the hope that it will be useful but
* WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
* DISCLAIMED. This includes but is not limited to warranties of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* Date: 2000-12-02
*/
#ifndef _STDINT_H
#define _STDINT_H
#define __need_wint_t
#define __need_wchar_t
#include <stddef.h>
/* 7.18.1.1 Exact-width integer types */
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef int int32_t;
typedef unsigned uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
/* 7.18.1.2 Minimum-width integer types */
typedef signed char int_least8_t;
typedef unsigned char uint_least8_t;
typedef short int_least16_t;
typedef unsigned short uint_least16_t;
typedef int int_least32_t;
typedef unsigned uint_least32_t;
typedef __int64 int_least64_t;
typedef unsigned __int64 uint_least64_t;
/* 7.18.1.3 Fastest minimum-width integer types
* Not actually guaranteed to be fastest for all purposes
* Here we use the exact-width types for 8 and 16-bit ints.
*/
typedef char int_fast8_t;
typedef unsigned char uint_fast8_t;
typedef short int_fast16_t;
typedef unsigned short uint_fast16_t;
typedef int int_fast32_t;
typedef unsigned int uint_fast32_t;
typedef __int64 int_fast64_t;
typedef unsigned __int64 uint_fast64_t;
/* 7.18.1.4 Integer types capable of holding object pointers */
typedef int intptr_t;
typedef unsigned uintptr_t;
/* 7.18.1.5 Greatest-width integer types */
typedef __int64 intmax_t;
typedef unsigned __int64 uintmax_t;
/* 7.18.2 Limits of specified-width integer types */
#if !defined ( __cplusplus) || defined (__STDC_LIMIT_MACROS)
/* 7.18.2.1 Limits of exact-width integer types */
#define INT8_MIN (-128)
#define INT16_MIN (-32768)
#define INT32_MIN (-2147483647 - 1)
#define INT64_MIN (-9223372036854775807LL - 1)
#define INT8_MAX 127
#define INT16_MAX 32767
#define INT32_MAX 2147483647
#define INT64_MAX 9223372036854775807LL
#define UINT8_MAX 0xff /* 255U */
#define UINT16_MAX 0xffff /* 65535U */
#define UINT32_MAX 0xffffffff /* 4294967295U */
#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */
/* 7.18.2.2 Limits of minimum-width integer types */
#define INT_LEAST8_MIN INT8_MIN
#define INT_LEAST16_MIN INT16_MIN
#define INT_LEAST32_MIN INT32_MIN
#define INT_LEAST64_MIN INT64_MIN
#define INT_LEAST8_MAX INT8_MAX
#define INT_LEAST16_MAX INT16_MAX
#define INT_LEAST32_MAX INT32_MAX
#define INT_LEAST64_MAX INT64_MAX
#define UINT_LEAST8_MAX UINT8_MAX
#define UINT_LEAST16_MAX UINT16_MAX
#define UINT_LEAST32_MAX UINT32_MAX
#define UINT_LEAST64_MAX UINT64_MAX
/* 7.18.2.3 Limits of fastest minimum-width integer types */
#define INT_FAST8_MIN INT8_MIN
#define INT_FAST16_MIN INT16_MIN
#define INT_FAST32_MIN INT32_MIN
#define INT_FAST64_MIN INT64_MIN
#define INT_FAST8_MAX INT8_MAX
#define INT_FAST16_MAX INT16_MAX
#define INT_FAST32_MAX INT32_MAX
#define INT_FAST64_MAX INT64_MAX
#define UINT_FAST8_MAX UINT8_MAX
#define UINT_FAST16_MAX UINT16_MAX
#define UINT_FAST32_MAX UINT32_MAX
#define UINT_FAST64_MAX UINT64_MAX
/* 7.18.2.4 Limits of integer types capable of holding
object pointers */
#define INTPTR_MIN INT32_MIN
#define INTPTR_MAX INT32_MAX
#define UINTPTR_MAX UINT32_MAX
/* 7.18.2.5 Limits of greatest-width integer types */
#define INTMAX_MIN INT64_MIN
#define INTMAX_MAX INT64_MAX
#define UINTMAX_MAX UINT64_MAX
/* 7.18.3 Limits of other integer types */
#define PTRDIFF_MIN INT32_MIN
#define PTRDIFF_MAX INT32_MAX
#define SIG_ATOMIC_MIN INT32_MIN
#define SIG_ATOMIC_MAX INT32_MAX
#define SIZE_MAX UINT32_MAX
#ifndef WCHAR_MIN /* also in wchar.h */
#define WCHAR_MIN 0
#define WCHAR_MAX 0xffff /* UINT16_MAX */
#endif
/*
* wint_t is unsigned short for compatibility with MS runtime
*/
#define WINT_MIN 0
#define WINT_MAX 0xffff /* UINT16_MAX */
#endif /* !defined ( __cplusplus) || defined __STDC_LIMIT_MACROS */
/* 7.18.4 Macros for integer constants */
#if !defined ( __cplusplus) || defined (__STDC_CONSTANT_MACROS)
/* 7.18.4.1 Macros for minimum-width integer constants
Accoding to Douglas Gwyn <gwyn@arl.mil>:
"This spec was changed in ISO/IEC 9899:1999 TC1; in ISO/IEC
9899:1999 as initially published, the expansion was required
to be an integer constant of precisely matching type, which
is impossible to accomplish for the shorter types on most
platforms, because C99 provides no standard way to designate
an integer constant with width less than that of type int.
TC1 changed this to require just an integer constant
*expression* with *promoted* type."
*/
#define INT8_C(val) ((int8_t) + (val))
#define UINT8_C(val) ((uint8_t) + (val##U))
#define INT16_C(val) ((int16_t) + (val))
#define UINT16_C(val) ((uint16_t) + (val##U))
#define INT32_C(val) val##L
#define UINT32_C(val) val##UL
#define INT64_C(val) val##LL
#define UINT64_C(val) val##ULL
/* 7.18.4.2 Macros for greatest-width integer constants */
#define INTMAX_C(val) INT64_C(val)
#define UINTMAX_C(val) UINT64_C(val)
#endif /* !defined ( __cplusplus) || defined __STDC_CONSTANT_MACROS */
#endif

10
common/version.h Normal file → Executable file
View File

@ -1,6 +1,6 @@
/*
* KernelEx
* Copyright (C) 2009, Xeno86
* Copyright (C) 2009-2010, Xeno86
*
* This file is part of KernelEx source code.
*
@ -22,9 +22,9 @@
#ifndef __VERSION_H
#define __VERSION_H
#define VERSION_STR "4.0 Final 2"
#define VERSION_CODE 0x04000066
#define RCVERSION 4, 0, 10, 2
#define _RCVERSION_ "4, 0, 10, 2"
#define VERSION_STR "4.5 Beta 1"
#define VERSION_CODE 0x04050001
#define RCVERSION 4, 5, 0, 1
#define _RCVERSION_ "4, 5, 0, 1"
#endif

113
common/winheap_allocator.hpp Executable file
View File

@ -0,0 +1,113 @@
#include <windows.h>
#include "debug.h"
template <class T>
class winheap_allocator
{
public:
typedef T value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
template <class U>
struct rebind { typedef winheap_allocator<U> other; };
winheap_allocator(HANDLE heap)
{
this->heap = heap;
}
// winheap_allocator(const winheap_allocator& a)
// {
// heap = a.heap;
// }
template <class U>
winheap_allocator(const winheap_allocator<U>& a)
{
heap = a.heap;
}
~winheap_allocator()
{
}
pointer address(reference x) const
{
return &x;
}
const_pointer address(const_reference x) const
{
return x;
}
pointer allocate(size_type n, const_pointer = 0)
{
void* p = HeapAlloc(heap, 0, n * sizeof(T));
// if (!p)
// throw std::bad_alloc();
return static_cast<pointer>(p);
}
char* _Charalloc(size_type n)
{
return rebind<char>::other(*this).allocate(n, (char*) 0);
}
void deallocate(void* p, size_type)
{
BOOL ret = HeapFree(heap, 0, p);
DBGASSERT(ret == TRUE);
}
size_type max_size() const
{
return static_cast<size_type>(-1) / sizeof(T);
}
void construct(pointer p, const value_type& x)
{
new (p) value_type(x);
}
void destroy(pointer p)
{
p->~value_type();
}
HANDLE heap;
private:
void operator=(const winheap_allocator&);
};
template<>
class winheap_allocator<void>
{
typedef void value_type;
typedef void* pointer;
typedef const void* const_pointer;
template <class U>
struct rebind { typedef winheap_allocator<U> other; };
};
template <class T>
inline bool operator==(const winheap_allocator<T>& a,
const winheap_allocator<T>& b)
{
return a.heap == b.heap;
}
template <class T>
inline bool operator!=(const winheap_allocator<T>& a,
const winheap_allocator<T>& b)
{
return a.heap != b.heap;
}