From d4e042029542417b68988f5ceafb45a2ddefde1d Mon Sep 17 00:00:00 2001 From: UzixLS Date: Sat, 3 Nov 2018 16:18:57 +0300 Subject: [PATCH] import KernelEx-4.0-RC1 --- KernelEx.dsw | 131 ++ KernelEx.nsi | 313 ++++ License.txt | 281 +++ UpdateDLL.nsh | 180 ++ apilibs/CORE.INI | 136 ++ apilibs/kexbasen/advapi32/_advapi32_apilist.c | 66 + apilibs/kexbasen/advapi32/_advapi32_apilist.h | 55 + apilibs/kexbasen/advapi32/uniadvapi32.c | 44 + apilibs/kexbasen/auxdecl.h | 132 ++ apilibs/kexbasen/comdlg32/_comdlg32_apilist.c | 54 + apilibs/kexbasen/comdlg32/_comdlg32_apilist.h | 43 + apilibs/kexbasen/comdlg32/unicomdlg32.c | 32 + apilibs/kexbasen/common.c | 59 + apilibs/kexbasen/common.h | 107 ++ apilibs/kexbasen/dirlist | 6 + apilibs/kexbasen/gdi32/UberGDI.c | 335 ++++ apilibs/kexbasen/gdi32/_gdi32_apilist.c | 82 + apilibs/kexbasen/gdi32/_gdi32_apilist.h | 71 + apilibs/kexbasen/gdi32/unigdi32.c | 54 + apilibs/kexbasen/kernel32/_kernel32_apilist.c | 129 ++ apilibs/kexbasen/kernel32/_kernel32_apilist.h | 118 ++ apilibs/kexbasen/kernel32/unikernel32.c | 107 ++ apilibs/kexbasen/kexbasen.def | 1 + apilibs/kexbasen/kexbasen.dsp | 295 +++ apilibs/kexbasen/kexbasen.rc | 109 ++ apilibs/kexbasen/main.c | 77 + apilibs/kexbasen/resource.h | 15 + .../kexbasen/shell32/SHGetFolderLocation.c | 307 ++++ apilibs/kexbasen/shell32/SHGetFolderPath.c | 80 + apilibs/kexbasen/shell32/_shell32_apilist.c | 62 + apilibs/kexbasen/shell32/_shell32_apilist.h | 49 + apilibs/kexbasen/shell32/auxshlguid.h | 24 + apilibs/kexbasen/shell32/pidl.h | 286 +++ apilibs/kexbasen/shell32/unishell32.c | 35 + apilibs/kexbasen/shell32ord.def | 8 + apilibs/kexbasen/unifwd.c | 53 + apilibs/kexbasen/unifwd.h | 88 + apilibs/kexbasen/user32/_user32_apilist.c | 163 ++ apilibs/kexbasen/user32/_user32_apilist.h | 152 ++ apilibs/kexbasen/user32/uniuser32.c | 170 ++ .../Advapi32/RegDisablePredefinedCache.c | 28 + .../kexbases/Advapi32/RegOpenCurrentUser.c | 28 + apilibs/kexbases/Advapi32/TraceMessage.c | 34 + apilibs/kexbases/Advapi32/_advapi32_apilist.c | 120 ++ apilibs/kexbases/Advapi32/_advapi32_apilist.h | 109 ++ apilibs/kexbases/Advapi32/_advapi32_stubs.c | 46 + apilibs/kexbases/Advapi32/security.c | 1613 +++++++++++++++++ apilibs/kexbases/Advapi32/uniadvapi32.c | 113 ++ apilibs/kexbases/Gdi32/FontResourceExA.c | 34 + apilibs/kexbases/Gdi32/GetGlyphOutlineA_fix.c | 39 + apilibs/kexbases/Gdi32/TextOut.c | 230 +++ apilibs/kexbases/Gdi32/_gdi32_apilist.c | 72 + apilibs/kexbases/Gdi32/_gdi32_apilist.h | 54 + apilibs/kexbases/Gdi32/_gdi32_stubs.c | 27 + apilibs/kexbases/Gdi32/unigdi32.c | 55 + apilibs/kexbases/Kernel32/CopyFileEx.c | 29 + apilibs/kexbases/Kernel32/CreateFileA_fix.c | 44 + apilibs/kexbases/Kernel32/CreateThread_fix.c | 37 + .../kexbases/Kernel32/DeleteCriticalSection.c | 30 + apilibs/kexbases/Kernel32/GetFileSizeEx.c | 38 + .../kexbases/Kernel32/GlobalMemoryStatusEx.c | 48 + apilibs/kexbases/Kernel32/HeapLocks.c | 51 + .../InitializeCriticalSectionAndSpinCount.c | 29 + apilibs/kexbases/Kernel32/Jobs.c | 81 + apilibs/kexbases/Kernel32/KEXVersion.c | 31 + apilibs/kexbases/Kernel32/LockFileEx.c | 36 + apilibs/kexbases/Kernel32/MapViewOfFile.c | 44 + apilibs/kexbases/Kernel32/MoveFileExA.c | 111 ++ .../kexbases/Kernel32/MoveFileWithProgressA.c | 28 + apilibs/kexbases/Kernel32/OpenThread.c | 60 + apilibs/kexbases/Kernel32/SetFilePointerEx.c | 40 + apilibs/kexbases/Kernel32/ThreadPool.c | 51 + .../Kernel32/TryEnterCriticalSection.c | 152 ++ apilibs/kexbases/Kernel32/VirtualAllocEx.c | 41 + apilibs/kexbases/Kernel32/_kernel32_apilist.c | 194 ++ apilibs/kexbases/Kernel32/_kernel32_apilist.h | 165 ++ apilibs/kexbases/Kernel32/_kernel32_stubs.c | 31 + apilibs/kexbases/Kernel32/uilang.c | 160 ++ apilibs/kexbases/Kernel32/unikernel32.c | 794 ++++++++ apilibs/kexbases/Kernel32/version.c | 584 ++++++ apilibs/kexbases/User32/CallWindowProcA_fix.c | 50 + .../User32/DisableProcessWindowsGhosting.c | 25 + apilibs/kexbases/User32/EnableWindow.c | 36 + apilibs/kexbases/User32/ForegroundWindow.c | 34 + apilibs/kexbases/User32/GetAncestor.c | 35 + .../kexbases/User32/GetMouseMovePointsEx.c | 31 + apilibs/kexbases/User32/IsHungAppWindow.c | 29 + apilibs/kexbases/User32/LockWorkStation.c | 28 + apilibs/kexbases/User32/MapVirtualKey_fix.c | 49 + apilibs/kexbases/User32/SendMessage_fix.c | 85 + apilibs/kexbases/User32/UberUSER.c | 134 ++ apilibs/kexbases/User32/UpdateLayeredWindow.c | 45 + apilibs/kexbases/User32/_user32_apilist.c | 97 + apilibs/kexbases/User32/_user32_apilist.h | 63 + apilibs/kexbases/User32/_user32_stubs.c | 24 + apilibs/kexbases/User32/uniuser32.c | 91 + apilibs/kexbases/auxdecl.h | 136 ++ apilibs/kexbases/comdlg32/PrintDlgEx.c | 31 + apilibs/kexbases/comdlg32/_comdlg32_apilist.c | 47 + apilibs/kexbases/comdlg32/_comdlg32_apilist.h | 35 + apilibs/kexbases/common.c | 52 + apilibs/kexbases/common.h | 113 ++ apilibs/kexbases/dirlist | 7 + apilibs/kexbases/kernel32ord.def | 14 + apilibs/kexbases/kexbases.def | 8 + apilibs/kexbases/kexbases.dsp | 467 +++++ apilibs/kexbases/kexbases.rc | 109 ++ apilibs/kexbases/main.c | 79 + apilibs/kexbases/resource.h | 15 + apilibs/kexbases/shell32/CommandLineToArgvW.c | 202 +++ apilibs/kexbases/shell32/IsUserAnAdmin.c | 28 + apilibs/kexbases/shell32/_shell32_apilist.c | 49 + apilibs/kexbases/shell32/_shell32_apilist.h | 38 + apilibs/kexbases/shell32/_shell32_stubs.c | 25 + apilibs/kexbases/version/_version_apilist.c | 51 + apilibs/kexbases/version/_version_apilist.h | 40 + apilibs/kexbases/version/universion.c | 161 ++ apilibs/settings.reg | 40 + auxiliary/auxiliary.dsp | 66 + auxiliary/makefile | 20 + auxiliary/makefile.msv | 36 + auxiliary/msimg32/makefile | 42 + auxiliary/msimg32/makefile.msv | 32 + auxiliary/msimg32/msimg32.c | 386 ++++ auxiliary/msimg32/msimg32.def | 8 + auxiliary/msimg32/msimgme.rc | 26 + auxiliary/pdh/kord.def | 5 + auxiliary/pdh/makefile | 43 + auxiliary/pdh/makefile.msv | 38 + auxiliary/pdh/pdh.c | 137 ++ auxiliary/pdh/pdh.def | 73 + auxiliary/psapi/makefile | 43 + auxiliary/psapi/makefile.msv | 32 + auxiliary/psapi/psapi.c | 348 ++++ auxiliary/psapi/psapi.def | 18 + auxiliary/uxtheme/kord.def | 5 + auxiliary/uxtheme/makefile | 43 + auxiliary/uxtheme/makefile.msv | 38 + auxiliary/uxtheme/uxtheme.c | 106 ++ auxiliary/uxtheme/uxtheme.def | 50 + auxiliary/wtsapi32/makefile | 43 + auxiliary/wtsapi32/makefile.msv | 33 + auxiliary/wtsapi32/wtsapi32.c | 343 ++++ auxiliary/wtsapi32/wtsapi32.def | 22 + auxiliary/wtsapi32/wtsapi32.h | 165 ++ common/is_sorted.hpp | 19 + common/kexcoresdk.h | 196 ++ common/pemanip.cpp | 435 +++++ common/pemanip.h | 70 + common/sstring.hpp | 78 + core/Core.rc | 131 ++ core/SettingsDB.cpp | 257 +++ core/SettingsDB.h | 66 + core/apiconf.cpp | 601 ++++++ core/apiconf.h | 106 ++ core/apiconfmgr.cpp | 537 ++++++ core/apiconfmgr.h | 67 + core/apilib.cpp | 704 +++++++ core/apilib.h | 69 + core/core.def | 8 + core/core.dsp | 289 +++ core/core.ini | 32 + core/debug.cpp | 56 + core/debug.h | 57 + core/debugproto.cpp | 41 + core/debugproto.h | 48 + core/internals.cpp | 505 ++++++ core/internals.h | 100 + core/k32ord.def | 14 + core/kexcoresdk.cpp | 87 + core/main.cpp | 217 +++ core/resolver.cpp | 676 +++++++ core/resolver.h | 61 + core/resource.h | 18 + core/sharedmem.cpp | 87 + core/sharedmem.h | 42 + core/structs.h | 315 ++++ core/thunks.cpp | 106 ++ core/thunks.h | 30 + core/version.h | 29 + core/wildcmp.cpp | 37 + core/wildcmp.h | 6 + kexcontrol/kexcontrol.cpp | 73 + kexcontrol/kexcontrol.dsp | 104 ++ kexcrt/LICENSE | 73 + kexcrt/README | 80 + kexcrt/_vsnprintf.c | 7 + kexcrt/atoi.c | 3 + kexcrt/atol.c | 3 + kexcrt/atoll.c | 3 + kexcrt/atox.c | 14 + kexcrt/ctype/ctypefunc.h | 13 + kexcrt/ctype/isalnum.c | 2 + kexcrt/ctype/isalpha.c | 2 + kexcrt/ctype/isascii.c | 2 + kexcrt/ctype/isblank.c | 2 + kexcrt/ctype/iscntrl.c | 2 + kexcrt/ctype/isdigit.c | 2 + kexcrt/ctype/isgraph.c | 2 + kexcrt/ctype/islower.c | 2 + kexcrt/ctype/isprint.c | 2 + kexcrt/ctype/ispunct.c | 2 + kexcrt/ctype/isspace.c | 2 + kexcrt/ctype/isupper.c | 2 + kexcrt/ctype/isxdigit.c | 2 + kexcrt/ctype/tolower.c | 2 + kexcrt/ctype/toupper.c | 2 + kexcrt/ctypes.c | 284 +++ kexcrt/ctypes.h | 134 ++ kexcrt/kexcrt.dsp | 341 ++++ kexcrt/makefile | 19 + kexcrt/makefile.msv | 21 + kexcrt/memccpy.c | 23 + kexcrt/memchr.c | 19 + kexcrt/memcmp.c | 19 + kexcrt/memcpy.c | 28 + kexcrt/memmem.c | 52 + kexcrt/memmove.c | 36 + kexcrt/memrchr.c | 19 + kexcrt/memset.c | 29 + kexcrt/memswap.c | 24 + kexcrt/msvc/STDINT.H | 184 ++ kexcrt/msvc/argcargv.c | 112 ++ kexcrt/msvc/argcargv.h | 3 + kexcrt/msvc/concrt0.c | 20 + kexcrt/msvc/dllcrt0.c | 27 + kexcrt/msvc/init.c | 85 + kexcrt/msvc/init.h | 7 + kexcrt/msvc/wincrt0.c | 53 + kexcrt/snprintf.c | 17 + kexcrt/sprintf.c | 18 + kexcrt/sscanf.c | 18 + kexcrt/strcat.c | 11 + kexcrt/strchr.c | 16 + kexcrt/strcmp.c | 21 + kexcrt/strcmpi.c | 24 + kexcrt/strcpy.c | 20 + kexcrt/strlen.c | 13 + kexcrt/strncat.c | 21 + kexcrt/strncmp.c | 21 + kexcrt/strncpy.c | 24 + kexcrt/strnicmp.c | 24 + kexcrt/strnlen.c | 18 + kexcrt/strntoimax.c | 13 + kexcrt/strntoumax.c | 80 + kexcrt/strpbrk.c | 12 + kexcrt/strrchr.c | 18 + kexcrt/strsep.c | 21 + kexcrt/strstr.c | 11 + kexcrt/strtok.c | 19 + kexcrt/strtol.c | 3 + kexcrt/strtoll.c | 3 + kexcrt/strtoul.c | 3 + kexcrt/strtoull.c | 3 + kexcrt/strtoumax.c | 3 + kexcrt/strtox.c | 13 + kexcrt/strupr.c | 18 + kexcrt/strxspn.c | 28 + kexcrt/strxspn.h | 12 + kexcrt/vsnprintf.c | 487 +++++ kexcrt/vsprintf.c | 11 + kexcrt/vsscanf.c | 411 +++++ setup/debug.h | 31 + setup/loadstub.h | 55 + setup/resource.h | 24 + setup/setup.cpp | 483 +++++ setup/setup.dsp | 132 ++ setup/setup.h | 68 + setup/setup.rc | 94 + setup/wininit.h | 154 ++ sheet/KexLinkage.cpp | 111 ++ sheet/KexLinkage.h | 67 + sheet/factory.cpp | 96 + sheet/factory.h | 42 + sheet/resource.h | 24 + sheet/server.cpp | 192 ++ sheet/server.def | 6 + sheet/server.h | 28 + sheet/sheet.cpp | 388 ++++ sheet/sheet.dsp | 149 ++ sheet/sheet.h | 65 + sheet/sheet.rc | 165 ++ util/dumpconf.c | 29 + util/dumpimte.c | 29 + util/dumpsett.c | 29 + util/funique.cpp | 140 ++ util/load.c | 42 + util/patterns.txt | 9 + util/prep/prep.cpp | 699 +++++++ util/prep/prep.dsp | 120 ++ util/prep/prep.h | 117 ++ util/prep/test/_te_apilist.c | 5 + util/prep/test/dirlist | 1 + util/prep/test/junk.c | 4 + util/prep/test/test.c | 38 + 295 files changed, 28034 insertions(+) create mode 100755 KernelEx.dsw create mode 100755 KernelEx.nsi create mode 100755 License.txt create mode 100755 UpdateDLL.nsh create mode 100644 apilibs/CORE.INI create mode 100644 apilibs/kexbasen/advapi32/_advapi32_apilist.c create mode 100644 apilibs/kexbasen/advapi32/_advapi32_apilist.h create mode 100644 apilibs/kexbasen/advapi32/uniadvapi32.c create mode 100644 apilibs/kexbasen/auxdecl.h create mode 100644 apilibs/kexbasen/comdlg32/_comdlg32_apilist.c create mode 100644 apilibs/kexbasen/comdlg32/_comdlg32_apilist.h create mode 100644 apilibs/kexbasen/comdlg32/unicomdlg32.c create mode 100644 apilibs/kexbasen/common.c create mode 100644 apilibs/kexbasen/common.h create mode 100644 apilibs/kexbasen/dirlist create mode 100644 apilibs/kexbasen/gdi32/UberGDI.c create mode 100644 apilibs/kexbasen/gdi32/_gdi32_apilist.c create mode 100644 apilibs/kexbasen/gdi32/_gdi32_apilist.h create mode 100644 apilibs/kexbasen/gdi32/unigdi32.c create mode 100644 apilibs/kexbasen/kernel32/_kernel32_apilist.c create mode 100644 apilibs/kexbasen/kernel32/_kernel32_apilist.h create mode 100644 apilibs/kexbasen/kernel32/unikernel32.c create mode 100644 apilibs/kexbasen/kexbasen.def create mode 100644 apilibs/kexbasen/kexbasen.dsp create mode 100644 apilibs/kexbasen/kexbasen.rc create mode 100644 apilibs/kexbasen/main.c create mode 100644 apilibs/kexbasen/resource.h create mode 100644 apilibs/kexbasen/shell32/SHGetFolderLocation.c create mode 100644 apilibs/kexbasen/shell32/SHGetFolderPath.c create mode 100644 apilibs/kexbasen/shell32/_shell32_apilist.c create mode 100644 apilibs/kexbasen/shell32/_shell32_apilist.h create mode 100644 apilibs/kexbasen/shell32/auxshlguid.h create mode 100644 apilibs/kexbasen/shell32/pidl.h create mode 100644 apilibs/kexbasen/shell32/unishell32.c create mode 100644 apilibs/kexbasen/shell32ord.def create mode 100644 apilibs/kexbasen/unifwd.c create mode 100644 apilibs/kexbasen/unifwd.h create mode 100644 apilibs/kexbasen/user32/_user32_apilist.c create mode 100644 apilibs/kexbasen/user32/_user32_apilist.h create mode 100644 apilibs/kexbasen/user32/uniuser32.c create mode 100644 apilibs/kexbases/Advapi32/RegDisablePredefinedCache.c create mode 100644 apilibs/kexbases/Advapi32/RegOpenCurrentUser.c create mode 100644 apilibs/kexbases/Advapi32/TraceMessage.c create mode 100644 apilibs/kexbases/Advapi32/_advapi32_apilist.c create mode 100644 apilibs/kexbases/Advapi32/_advapi32_apilist.h create mode 100644 apilibs/kexbases/Advapi32/_advapi32_stubs.c create mode 100644 apilibs/kexbases/Advapi32/security.c create mode 100644 apilibs/kexbases/Advapi32/uniadvapi32.c create mode 100644 apilibs/kexbases/Gdi32/FontResourceExA.c create mode 100644 apilibs/kexbases/Gdi32/GetGlyphOutlineA_fix.c create mode 100644 apilibs/kexbases/Gdi32/TextOut.c create mode 100644 apilibs/kexbases/Gdi32/_gdi32_apilist.c create mode 100644 apilibs/kexbases/Gdi32/_gdi32_apilist.h create mode 100644 apilibs/kexbases/Gdi32/_gdi32_stubs.c create mode 100644 apilibs/kexbases/Gdi32/unigdi32.c create mode 100644 apilibs/kexbases/Kernel32/CopyFileEx.c create mode 100644 apilibs/kexbases/Kernel32/CreateFileA_fix.c create mode 100644 apilibs/kexbases/Kernel32/CreateThread_fix.c create mode 100644 apilibs/kexbases/Kernel32/DeleteCriticalSection.c create mode 100644 apilibs/kexbases/Kernel32/GetFileSizeEx.c create mode 100644 apilibs/kexbases/Kernel32/GlobalMemoryStatusEx.c create mode 100644 apilibs/kexbases/Kernel32/HeapLocks.c create mode 100644 apilibs/kexbases/Kernel32/InitializeCriticalSectionAndSpinCount.c create mode 100644 apilibs/kexbases/Kernel32/Jobs.c create mode 100644 apilibs/kexbases/Kernel32/KEXVersion.c create mode 100644 apilibs/kexbases/Kernel32/LockFileEx.c create mode 100644 apilibs/kexbases/Kernel32/MapViewOfFile.c create mode 100644 apilibs/kexbases/Kernel32/MoveFileExA.c create mode 100644 apilibs/kexbases/Kernel32/MoveFileWithProgressA.c create mode 100644 apilibs/kexbases/Kernel32/OpenThread.c create mode 100644 apilibs/kexbases/Kernel32/SetFilePointerEx.c create mode 100644 apilibs/kexbases/Kernel32/ThreadPool.c create mode 100644 apilibs/kexbases/Kernel32/TryEnterCriticalSection.c create mode 100644 apilibs/kexbases/Kernel32/VirtualAllocEx.c create mode 100644 apilibs/kexbases/Kernel32/_kernel32_apilist.c create mode 100644 apilibs/kexbases/Kernel32/_kernel32_apilist.h create mode 100644 apilibs/kexbases/Kernel32/_kernel32_stubs.c create mode 100644 apilibs/kexbases/Kernel32/uilang.c create mode 100644 apilibs/kexbases/Kernel32/unikernel32.c create mode 100644 apilibs/kexbases/Kernel32/version.c create mode 100644 apilibs/kexbases/User32/CallWindowProcA_fix.c create mode 100644 apilibs/kexbases/User32/DisableProcessWindowsGhosting.c create mode 100644 apilibs/kexbases/User32/EnableWindow.c create mode 100644 apilibs/kexbases/User32/ForegroundWindow.c create mode 100644 apilibs/kexbases/User32/GetAncestor.c create mode 100644 apilibs/kexbases/User32/GetMouseMovePointsEx.c create mode 100644 apilibs/kexbases/User32/IsHungAppWindow.c create mode 100644 apilibs/kexbases/User32/LockWorkStation.c create mode 100644 apilibs/kexbases/User32/MapVirtualKey_fix.c create mode 100644 apilibs/kexbases/User32/SendMessage_fix.c create mode 100644 apilibs/kexbases/User32/UberUSER.c create mode 100644 apilibs/kexbases/User32/UpdateLayeredWindow.c create mode 100644 apilibs/kexbases/User32/_user32_apilist.c create mode 100644 apilibs/kexbases/User32/_user32_apilist.h create mode 100644 apilibs/kexbases/User32/_user32_stubs.c create mode 100644 apilibs/kexbases/User32/uniuser32.c create mode 100644 apilibs/kexbases/auxdecl.h create mode 100644 apilibs/kexbases/comdlg32/PrintDlgEx.c create mode 100644 apilibs/kexbases/comdlg32/_comdlg32_apilist.c create mode 100644 apilibs/kexbases/comdlg32/_comdlg32_apilist.h create mode 100644 apilibs/kexbases/common.c create mode 100644 apilibs/kexbases/common.h create mode 100644 apilibs/kexbases/dirlist create mode 100644 apilibs/kexbases/kernel32ord.def create mode 100644 apilibs/kexbases/kexbases.def create mode 100644 apilibs/kexbases/kexbases.dsp create mode 100644 apilibs/kexbases/kexbases.rc create mode 100644 apilibs/kexbases/main.c create mode 100644 apilibs/kexbases/resource.h create mode 100644 apilibs/kexbases/shell32/CommandLineToArgvW.c create mode 100644 apilibs/kexbases/shell32/IsUserAnAdmin.c create mode 100644 apilibs/kexbases/shell32/_shell32_apilist.c create mode 100644 apilibs/kexbases/shell32/_shell32_apilist.h create mode 100644 apilibs/kexbases/shell32/_shell32_stubs.c create mode 100644 apilibs/kexbases/version/_version_apilist.c create mode 100644 apilibs/kexbases/version/_version_apilist.h create mode 100644 apilibs/kexbases/version/universion.c create mode 100644 apilibs/settings.reg create mode 100644 auxiliary/auxiliary.dsp create mode 100644 auxiliary/makefile create mode 100644 auxiliary/makefile.msv create mode 100644 auxiliary/msimg32/makefile create mode 100644 auxiliary/msimg32/makefile.msv create mode 100644 auxiliary/msimg32/msimg32.c create mode 100644 auxiliary/msimg32/msimg32.def create mode 100644 auxiliary/msimg32/msimgme.rc create mode 100644 auxiliary/pdh/kord.def create mode 100644 auxiliary/pdh/makefile create mode 100644 auxiliary/pdh/makefile.msv create mode 100644 auxiliary/pdh/pdh.c create mode 100644 auxiliary/pdh/pdh.def create mode 100644 auxiliary/psapi/makefile create mode 100644 auxiliary/psapi/makefile.msv create mode 100644 auxiliary/psapi/psapi.c create mode 100644 auxiliary/psapi/psapi.def create mode 100644 auxiliary/uxtheme/kord.def create mode 100644 auxiliary/uxtheme/makefile create mode 100644 auxiliary/uxtheme/makefile.msv create mode 100644 auxiliary/uxtheme/uxtheme.c create mode 100644 auxiliary/uxtheme/uxtheme.def create mode 100644 auxiliary/wtsapi32/makefile create mode 100644 auxiliary/wtsapi32/makefile.msv create mode 100644 auxiliary/wtsapi32/wtsapi32.c create mode 100644 auxiliary/wtsapi32/wtsapi32.def create mode 100644 auxiliary/wtsapi32/wtsapi32.h create mode 100644 common/is_sorted.hpp create mode 100644 common/kexcoresdk.h create mode 100644 common/pemanip.cpp create mode 100644 common/pemanip.h create mode 100644 common/sstring.hpp create mode 100644 core/Core.rc create mode 100644 core/SettingsDB.cpp create mode 100644 core/SettingsDB.h create mode 100644 core/apiconf.cpp create mode 100644 core/apiconf.h create mode 100644 core/apiconfmgr.cpp create mode 100644 core/apiconfmgr.h create mode 100644 core/apilib.cpp create mode 100644 core/apilib.h create mode 100644 core/core.def create mode 100644 core/core.dsp create mode 100644 core/core.ini create mode 100644 core/debug.cpp create mode 100644 core/debug.h create mode 100644 core/debugproto.cpp create mode 100644 core/debugproto.h create mode 100644 core/internals.cpp create mode 100644 core/internals.h create mode 100644 core/k32ord.def create mode 100644 core/kexcoresdk.cpp create mode 100644 core/main.cpp create mode 100644 core/resolver.cpp create mode 100644 core/resolver.h create mode 100644 core/resource.h create mode 100644 core/sharedmem.cpp create mode 100644 core/sharedmem.h create mode 100644 core/structs.h create mode 100644 core/thunks.cpp create mode 100644 core/thunks.h create mode 100644 core/version.h create mode 100644 core/wildcmp.cpp create mode 100644 core/wildcmp.h create mode 100644 kexcontrol/kexcontrol.cpp create mode 100644 kexcontrol/kexcontrol.dsp create mode 100644 kexcrt/LICENSE create mode 100644 kexcrt/README create mode 100644 kexcrt/_vsnprintf.c create mode 100644 kexcrt/atoi.c create mode 100644 kexcrt/atol.c create mode 100644 kexcrt/atoll.c create mode 100644 kexcrt/atox.c create mode 100644 kexcrt/ctype/ctypefunc.h create mode 100644 kexcrt/ctype/isalnum.c create mode 100644 kexcrt/ctype/isalpha.c create mode 100644 kexcrt/ctype/isascii.c create mode 100644 kexcrt/ctype/isblank.c create mode 100644 kexcrt/ctype/iscntrl.c create mode 100644 kexcrt/ctype/isdigit.c create mode 100644 kexcrt/ctype/isgraph.c create mode 100644 kexcrt/ctype/islower.c create mode 100644 kexcrt/ctype/isprint.c create mode 100644 kexcrt/ctype/ispunct.c create mode 100644 kexcrt/ctype/isspace.c create mode 100644 kexcrt/ctype/isupper.c create mode 100644 kexcrt/ctype/isxdigit.c create mode 100644 kexcrt/ctype/tolower.c create mode 100644 kexcrt/ctype/toupper.c create mode 100644 kexcrt/ctypes.c create mode 100644 kexcrt/ctypes.h create mode 100644 kexcrt/kexcrt.dsp create mode 100644 kexcrt/makefile create mode 100644 kexcrt/makefile.msv create mode 100644 kexcrt/memccpy.c create mode 100644 kexcrt/memchr.c create mode 100644 kexcrt/memcmp.c create mode 100644 kexcrt/memcpy.c create mode 100644 kexcrt/memmem.c create mode 100644 kexcrt/memmove.c create mode 100644 kexcrt/memrchr.c create mode 100644 kexcrt/memset.c create mode 100644 kexcrt/memswap.c create mode 100644 kexcrt/msvc/STDINT.H create mode 100644 kexcrt/msvc/argcargv.c create mode 100644 kexcrt/msvc/argcargv.h create mode 100644 kexcrt/msvc/concrt0.c create mode 100644 kexcrt/msvc/dllcrt0.c create mode 100644 kexcrt/msvc/init.c create mode 100644 kexcrt/msvc/init.h create mode 100644 kexcrt/msvc/wincrt0.c create mode 100644 kexcrt/snprintf.c create mode 100644 kexcrt/sprintf.c create mode 100644 kexcrt/sscanf.c create mode 100644 kexcrt/strcat.c create mode 100644 kexcrt/strchr.c create mode 100644 kexcrt/strcmp.c create mode 100644 kexcrt/strcmpi.c create mode 100644 kexcrt/strcpy.c create mode 100644 kexcrt/strlen.c create mode 100644 kexcrt/strncat.c create mode 100644 kexcrt/strncmp.c create mode 100644 kexcrt/strncpy.c create mode 100644 kexcrt/strnicmp.c create mode 100644 kexcrt/strnlen.c create mode 100644 kexcrt/strntoimax.c create mode 100644 kexcrt/strntoumax.c create mode 100644 kexcrt/strpbrk.c create mode 100644 kexcrt/strrchr.c create mode 100644 kexcrt/strsep.c create mode 100644 kexcrt/strstr.c create mode 100644 kexcrt/strtok.c create mode 100644 kexcrt/strtol.c create mode 100644 kexcrt/strtoll.c create mode 100644 kexcrt/strtoul.c create mode 100644 kexcrt/strtoull.c create mode 100644 kexcrt/strtoumax.c create mode 100644 kexcrt/strtox.c create mode 100644 kexcrt/strupr.c create mode 100644 kexcrt/strxspn.c create mode 100644 kexcrt/strxspn.h create mode 100644 kexcrt/vsnprintf.c create mode 100644 kexcrt/vsprintf.c create mode 100644 kexcrt/vsscanf.c create mode 100644 setup/debug.h create mode 100644 setup/loadstub.h create mode 100644 setup/resource.h create mode 100644 setup/setup.cpp create mode 100644 setup/setup.dsp create mode 100644 setup/setup.h create mode 100644 setup/setup.rc create mode 100644 setup/wininit.h create mode 100644 sheet/KexLinkage.cpp create mode 100644 sheet/KexLinkage.h create mode 100644 sheet/factory.cpp create mode 100644 sheet/factory.h create mode 100644 sheet/resource.h create mode 100644 sheet/server.cpp create mode 100644 sheet/server.def create mode 100644 sheet/server.h create mode 100644 sheet/sheet.cpp create mode 100644 sheet/sheet.dsp create mode 100644 sheet/sheet.h create mode 100644 sheet/sheet.rc create mode 100644 util/dumpconf.c create mode 100644 util/dumpimte.c create mode 100644 util/dumpsett.c create mode 100644 util/funique.cpp create mode 100644 util/load.c create mode 100644 util/patterns.txt create mode 100644 util/prep/prep.cpp create mode 100644 util/prep/prep.dsp create mode 100644 util/prep/prep.h create mode 100644 util/prep/test/_te_apilist.c create mode 100644 util/prep/test/dirlist create mode 100644 util/prep/test/junk.c create mode 100644 util/prep/test/test.c diff --git a/KernelEx.dsw b/KernelEx.dsw new file mode 100755 index 0000000..ec319ae --- /dev/null +++ b/KernelEx.dsw @@ -0,0 +1,131 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "Core"=.\core\core.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "KernelEx Base NonShared"=.\apilibs\kexbasen\kexbasen.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name prep + End Project Dependency +}}} + +############################################################################### + +Project: "KernelEx Base Shared"=.\apilibs\kexbases\kexbases.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name prep + End Project Dependency +}}} + +############################################################################### + +Project: "auxiliary"=.\auxiliary\auxiliary.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "kexcontrol"=.\kexcontrol\kexcontrol.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "kexcrt"=.\kexcrt\kexcrt.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "prep"=.\util\prep\prep.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "setup"=.\setup\setup.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "sheet"=.\sheet\sheet.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/KernelEx.nsi b/KernelEx.nsi new file mode 100755 index 0000000..38a21ad --- /dev/null +++ b/KernelEx.nsi @@ -0,0 +1,313 @@ + !define VERSION '4.0 RC 1' + +;-------------------------------- +;Includes + + !include "MUI2.nsh" + !include "UpdateDLL.nsh" + !include "WinVer.nsh" + +;-------------------------------- +;General + + ;Name and file + Name "KernelEx" + Caption "KernelEx ${VERSION} Setup" + OutFile "..\KernelEx-${VERSION}.exe" + + ;Default installation folder + InstallDir "$WINDIR\KernelEx" + + ;Get installation folder from registry if available + InstallDirRegKey HKLM "Software\KernelEx" "InstallDir" + +;-------------------------------- +;Interface Settings + + !define MUI_ABORTWARNING +; !define MUI_FINISHPAGE_NOAUTOCLOSE +; !define MUI_UNFINISHPAGE_NOAUTOCLOSE + +;-------------------------------- +;Pages + + !insertmacro MUI_PAGE_WELCOME + !insertmacro MUI_PAGE_LICENSE "License.txt" + !insertmacro MUI_PAGE_INSTFILES + !insertmacro MUI_PAGE_FINISH + + !insertmacro MUI_UNPAGE_WELCOME + !insertmacro MUI_UNPAGE_CONFIRM + !insertmacro MUI_UNPAGE_INSTFILES + !insertmacro MUI_UNPAGE_FINISH + +;-------------------------------- +;Languages + + !insertmacro MUI_LANGUAGE "English" + + LangString DESC_SHORTPRODUCT ${LANG_ENGLISH} "Microsoft Layer for Unicode" + LangString DESC_LONGPRODUCT ${LANG_ENGLISH} "Microsoft Layer for Unicode on Windows 95, 98, and Me Systems, 1.1.3790.0" + LangString DESC_PRODUCT_DECISION ${LANG_ENGLISH} "$(DESC_SHORTPRODUCT) is required.$\nIt is strongly \ + advised that you install$\n$(DESC_SHORTPRODUCT) before continuing.$\nIf you choose to continue, \ + you will need to connect$\nto the internet before proceeding.$\nWould you like to continue with \ + the installation?" + LangString SEC_PRODUCT ${LANG_ENGLISH} "$(DESC_SHORTPRODUCT) " + LangString DESC_INSTALLING ${LANG_ENGLISH} "Installing" + LangString DESC_DOWNLOADING1 ${LANG_ENGLISH} "Downloading" + LangString DESC_DOWNLOADFAILED ${LANG_ENGLISH} "Download Failed:" + LangString DESC_PRODUCT_TIMEOUT ${LANG_ENGLISH} "The installation of the $(DESC_SHORTPRODUCT) \ + has timed out." + LangString ERROR_PRODUCT_INVALID_PATH ${LANG_ENGLISH} "The $(DESC_SHORTPRODUCT) Installation$\n\ + was not found in the following location:$\n" + LangString ERROR_PRODUCT_FATAL ${LANG_ENGLISH} "A fatal error occurred during the installation$\n\ + of the $(DESC_SHORTPRODUCT)." + LangString DESC_SETTINGS_PRESERVE ${LANG_ENGLISH} "Do you want to preserve custom settings?" + +;-------------------------------- +;Installer Section + +Section "MSLU" SECPRODUCT + + !define URL_PRODUCT "http://download.microsoft.com/download/b/7/5/b75eace3-00e2-4aa0-9a6f-0b6882c71642/unicows.exe" + + IfFileExists $SYSDIR\unicows.dll 0 lbl_download + + ;check version + GetDllVersion $SYSDIR\unicows.dll $R0 $R1 + IntOp $R2 $R0 / 0x00010000 + IntOp $R3 $R0 & 0x0000FFFF + IntOp $R4 $R1 / 0x00010000 + IntOp $R5 $R1 & 0x0000FFFF + StrCmp "1.1.3790.0" "$R2.$R3.$R4.$R5" lbl_Skip + + lbl_download: + DetailPrint "$(DESC_DOWNLOADING1) $(DESC_SHORTPRODUCT)..." + MessageBox MB_ICONEXCLAMATION|MB_YESNO|MB_DEFBUTTON2 "$(DESC_PRODUCT_DECISION)" /SD IDNO \ + IDYES +2 IDNO 0 + Abort + ; Download + AddSize 900 + nsisdl::download /TIMEOUT=30000 "${URL_PRODUCT}" "$TEMP\unicows.exe" + Pop $0 + StrCmp "$0" "success" lbl_continue + DetailPrint "$(DESC_DOWNLOADFAILED) $0" + Abort + + lbl_continue: + DetailPrint "$(DESC_INSTALLING) $(DESC_SHORTPRODUCT)..." + Banner::show /NOUNLOAD "$(DESC_INSTALLING) $(DESC_SHORTPRODUCT)..." + CreateDirectory "$INSTDIR\MSLU" + nsExec::Exec '"$TEMP\unicows.exe" /t:$INSTDIR\MSLU' + Pop $0 + Banner::destroy + Delete "$TEMP\unicows.exe" + + ; obtain any error code and inform the user ($0) + ; If nsExec is unable to execute the process, + ; it will return "error" + ; If the process timed out it will return "timeout" + ; else it will return the return code from the executed process. + StrCmp $0 "" lbl_NoError + StrCmp $0 "0" lbl_NoError + StrCmp $0 "error" lbl_Error + StrCmp $0 "timeout" lbl_TimeOut + ; all others are fatal + DetailPrint "$(ERROR_PRODUCT_FATAL)[$0]" + Goto lbl_commonError + + lbl_TimeOut: + DetailPrint "$(DESC_PRODUCT_TIMEOUT)" + Goto lbl_commonError + + lbl_Error: + DetailPrint "$(ERROR_PRODUCT_INVALID_PATH)" + Goto lbl_commonError + + lbl_commonError: + RMDir /r "$INSTDIR" + Abort + + lbl_NoError: + CopyFiles /SILENT "$INSTDIR\MSLU\unicows.dll" "$INSTDIR\mslu.tmp" + Rename /REBOOTOK "$INSTDIR\mslu.tmp" "$SYSDIR\unicows.dll" + + lbl_Skip: + +SectionEnd + +Section "Install" + + SetDetailsView show + SetOutPath "$INSTDIR" + + SetOverwrite on + File setup\Release\setupkex.exe + SetOverwrite lastused + + nsExec::ExecToLog '"$INSTDIR\setupkex.exe" "$INSTDIR\kernel32.bak"' + Pop $0 + DetailPrint " setup returned: $0" + Delete "$INSTDIR\setupkex.exe" + StrCmp $0 "0" +3 + RMDir "$INSTDIR" + Abort + + ;Files to install + + ;UpdateDLL_Func params: + ;$R4 - target; $R5 - tempdir; $R6 - register?; $R7 - source + GetTempFileName $0 "$INSTDIR" + File /oname=$0 "Core\Release\KernelEx.dll" + StrCpy $R4 "$INSTDIR\KernelEx.dll" + StrCpy $R6 "0" + StrCpy $R7 $0 + Call UpgradeDLL_Func + + GetTempFileName $0 "$INSTDIR" + File /oname=$0 "apilibs\kexbases\Release\kexbases.dll" + StrCpy $R4 "$INSTDIR\kexbases.dll" + StrCpy $R6 "0" + StrCpy $R7 $0 + Call UpgradeDLL_Func + + GetTempFileName $0 "$INSTDIR" + File /oname=$0 "apilibs\kexbasen\Release\kexbasen.dll" + StrCpy $R4 "$INSTDIR\kexbasen.dll" + StrCpy $R6 "0" + StrCpy $R7 $0 + Call UpgradeDLL_Func + + GetTempFileName $0 "$INSTDIR" + File /oname=$0 "sheet\Release\sheet.dll" + StrCpy $R4 "$INSTDIR\sheet.dll" + StrCpy $R6 "1" + StrCpy $R7 $0 + Call UpgradeDLL_Func + + SetOverwrite on + + File apilibs\core.ini + File apilibs\settings.reg + File license.txt + + GetTempFileName $0 "$INSTDIR" + File /oname=$0 auxiliary\msimg32.dll + Delete "$INSTDIR\msimg32.dll" + Rename /REBOOTOK $0 "$INSTDIR\msimg32.dll" + WriteRegStr HKLM "System\CurrentControlSet\Control\SessionManager\KnownDLLs" \ + "MSIMG32" "..\KernelEx\msimg32.dll" + + GetTempFileName $0 "$INSTDIR" + File /oname=$0 auxiliary\pdh.dll + Delete "$INSTDIR\pdh.dll" + Rename /REBOOTOK $0 "$INSTDIR\pdh.dll" + WriteRegStr HKLM "System\CurrentControlSet\Control\SessionManager\KnownDLLs" \ + "PDH" "..\KernelEx\pdh.dll" + + GetTempFileName $0 "$INSTDIR" + File /oname=$0 auxiliary\psapi.dll + Delete "$INSTDIR\psapi.dll" + Rename /REBOOTOK $0 "$INSTDIR\psapi.dll" + WriteRegStr HKLM "System\CurrentControlSet\Control\SessionManager\KnownDLLs" \ + "PSAPI" "..\KernelEx\psapi.dll" + + GetTempFileName $0 "$INSTDIR" + File /oname=$0 auxiliary\uxtheme.dll + Delete "$INSTDIR\uxtheme.dll" + Rename /REBOOTOK $0 "$INSTDIR\uxtheme.dll" + WriteRegStr HKLM "System\CurrentControlSet\Control\SessionManager\KnownDLLs" \ + "UXTHEME" "..\KernelEx\uxtheme.dll" + + GetTempFileName $0 "$INSTDIR" + File /oname=$0 auxiliary\wtsapi32.dll + Delete "$INSTDIR\wtsapi32.dll" + Rename /REBOOTOK $0 "$INSTDIR\wtsapi32.dll" + WriteRegStr HKLM "System\CurrentControlSet\Control\SessionManager\KnownDLLs" \ + "WTSAPI32" "..\KernelEx\wtsapi32.dll" + + SetOverwrite lastused + + ExecWait '"$WINDIR\regedit.exe" /s "$INSTDIR\settings.reg"' + Delete "$INSTDIR\settings.reg" + + ;Store installation folder + WriteRegStr HKLM "Software\KernelEx" "InstallDir" $INSTDIR + + ;Store run key + WriteRegStr HKLM "System\CurrentControlSet\Control\MPRServices\KernelEx" "DLLName" "$INSTDIR\KernelEx.dll" + WriteRegStr HKLM "System\CurrentControlSet\Control\MPRServices\KernelEx" "EntryPoint" "_MprStart@4" + WriteRegDWORD HKLM "System\CurrentControlSet\Control\MPRServices\KernelEx" "StackSize" 0x1000 + + ;Store uninstaller key + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\KernelEx" "DisplayName" "KernelEx ${VERSION}" + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\KernelEx" "UninstallString" '"$INSTDIR\uninstall.exe"' + + ;Create uninstaller + WriteUninstaller "$INSTDIR\Uninstall.exe" + + SetRebootFlag true + +SectionEnd + +;-------------------------------- +;Uninstaller Section + +Section "Uninstall" + + SetDetailsView show + + MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "$(DESC_SETTINGS_PRESERVE)" IDYES +2 IDNO 0 + DeleteRegKey HKLM "Software\KernelEx" + + DeleteRegKey HKLM "System\CurrentControlSet\Control\MPRServices\KernelEx" + DeleteRegKey /ifempty HKLM "System\CurrentControlSet\Control\MPRServices" + + ;Files to uninstall + Rename /REBOOTOK "$INSTDIR\kernel32.bak" "$SYSDIR\kernel32.dll" + Delete /REBOOTOK "$INSTDIR\KernelEx.dll" + Delete /REBOOTOK "$INSTDIR\kexbases.dll" + Delete /REBOOTOK "$INSTDIR\kexbasen.dll" + Delete "$INSTDIR\core.ini" + UnRegDLL "$INSTDIR\sheet.dll" + Delete /REBOOTOK "$INSTDIR\sheet.dll" + Delete "$INSTDIR\license.txt" + + Delete /REBOOTOK "$INSTDIR\msimg32.dll" + DeleteRegValue HKLM "System\CurrentControlSet\Control\SessionManager\KnownDLLs" "MSIMG32" + Delete /REBOOTOK "$INSTDIR\pdh.dll" + DeleteRegValue HKLM "System\CurrentControlSet\Control\SessionManager\KnownDLLs" "PDH" + Delete /REBOOTOK "$INSTDIR\psapi.dll" + DeleteRegValue HKLM "System\CurrentControlSet\Control\SessionManager\KnownDLLs" "PSAPI" + Delete /REBOOTOK "$INSTDIR\uxtheme.dll" + DeleteRegValue HKLM "System\CurrentControlSet\Control\SessionManager\KnownDLLs" "UXTHEME" + Delete /REBOOTOK "$INSTDIR\wtsapi32.dll" + DeleteRegValue HKLM "System\CurrentControlSet\Control\SessionManager\KnownDLLs" "WTSAPI32" + + Delete "$INSTDIR\Uninstall.exe" + + RMDir /r "$INSTDIR\MSLU" + WriteINIStr $WINDIR\wininit.ini Rename DIRNUL $INSTDIR + + DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\KernelEx" + + SetRebootFlag true + +SectionEnd + +;-------------------------------- +;.onInit + +Function .onInit + + ${If} ${IsWin98} + ${OrIf} ${IsWinME} + Goto lbl_Ok + ${EndIf} + + MessageBox MB_ICONSTOP|MB_OK "This program requires Windows 98 or Windows Millennium." + Abort + + lbl_Ok: + + FunctionEnd diff --git a/License.txt b/License.txt new file mode 100755 index 0000000..98443f3 --- /dev/null +++ b/License.txt @@ -0,0 +1,281 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + diff --git a/UpdateDLL.nsh b/UpdateDLL.nsh new file mode 100755 index 0000000..23c777c --- /dev/null +++ b/UpdateDLL.nsh @@ -0,0 +1,180 @@ +!ifndef UPGRADEDLL_FUNC_INCLUDED +!define UPGRADEDLL_FUNC_INCLUDED + +; Function - Upgrade DLL File +; Written by Opher Shachar on 2004/01/14 +; Revised on 2004/01/15: Supports registering *.TLB, *.OLB files with 'regtlib.exe' +; Needs 'GetFileExt' (http://nsis.sourceforge.net/wiki/Get_extention_of_file) +; Revised 2007/02/06: fix directory as source, skip '.' and '..' entries +; $R6 now is VOLATILE +; Revised 2009/02 by Xeno86: tempdir = localdir, no tlb register, erase source +; file if no upgrade +; Based on macro by Joost Verburg +; -------------------------------------- +; +; Parameters: +; $R4 = DESTFILE - Location of the DLL file that should be upgraded (on user's system) +; OR DESTDIR - Target directory for upgraded DLLs +; $R6 = REGISTER - if you want to upgrade a DLL that has to be registered. +; 0 = Don't register, anything else = Register -- note: VOLATILE +; $R7 = LOCALFILE - Location of the new DLL file (on the user's system) +; OR LOCALDIR - Source directory of newer DLLs +; Note: If you want to support Win9x, you can only use short filenames (8.3). +; +; Example of usage for single file: +; $R4 = "$SYSDIR\dllname.dll" +; $R6 = "1" (= Register DLL) +; $R7 = "Source_dir\dllname.dll" +; Call UpgradeDLL_Func +; +; Example of usage with File command: +; SetOutPath "$PLUGINSDIR\SysFiles" +; File /r "sys_files_to_be_installed\*.*" ... +; ... +; File "some_other_sys_file.dll" +; $R4 = "$SYSDIR" -- note no '\', MUST be an existing directory +; $R6 = "1" (= Register DLL) +; $R7 = "$PLUGINSDIR\SysFiles" -- note no '\' +; Call UpgradeDLL_Func +; RMDir /r "$PLUGINSDIR\SysFiles" +; +; Example of usage for whole bunch of external files: +; $R4 = "$SYSDIR" -- note no '\', MUST be an existing directory +; $R6 = "1" (= Register DLL) +; $R7 = "Source_dir" -- note no '\' +; Call UpgradeDLL_Func + +Function UpgradeDLL_Func + + Push $R0 + Push $R1 + Push $R2 + Push $R3 + + SetOverwrite try + + ;------------------------ + ;Check single file + + IfFileExists "$R7\*.*" +3 + Call :upgradedll.doit + Goto upgradedll.end + + ;------------------------ + ;Enumerate directory + + Push $0 + Push $1 + Push $2 + StrCpy $1 $R7 + StrCpy $2 $R4 + FindFirst $0 $R0 "$1\*.*" + + loop: + IfErrors upgradedll.nomore + StrCpy $R7 "$1\$R0" + StrCpy $R4 "$2\$R0" + StrCmp $R0 "." +3 + StrCmp $R0 ".." +2 + Call :upgradedll.doit + FindNext $0 $R0 + Goto loop + + upgradedll.nomore: + FindClose $0 + StrCpy $R7 $1 + StrCpy $R4 $2 + Pop $2 + Pop $1 + Pop $0 + Goto upgradedll.end + + ;------------------------ + ;Do we want to register file? + + upgradedll.doit: + IntCmp $R6 0 upgradedll.moveon + + ;------------------------ + ;File already installed? No. Just copy + + upgradedll.moveon: + IfFileExists $R4 0 upgradedll.copy + + ;------------------------ + ;Check file and version + + ClearErrors + GetDLLVersion $R7 $R0 $R1 + GetDLLVersion $R4 $R2 $R3 + IfErrors upgradedll.upgrade + + IntCmpU $R0 $R2 0 upgradedll.dontupgrade upgradedll.upgrade + IntCmpU $R1 $R3 upgradedll.upgrade upgradedll.dontupgrade upgradedll.upgrade + + ;------------------------ + ;Let's upgrade the DLL! + + upgradedll.upgrade: + IntCmp $R6 1 0 +2 +2 + UnRegDLL $R4 ;Unregister the DLL + + ;------------------------ + ;Try to copy the DLL directly + + upgradedll.copy: + ClearErrors + Rename $R7 $R4 + IfErrors 0 upgradedll.noreboot + + ;------------------------ + ;DLL is in use. Copy it to a temp file and Rename it on reboot. + + Rename /REBOOTOK $R7 $R4 + + ;------------------------ + ;Register the DLL on reboot + + IntCmp $R6 0 upgradedll.done + + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" \ + "Register $R4" '"$SYSDIR\regsvr32.exe" /s "$R4"' + Goto upgradedll.done + + ;------------------------ + ;Register the DLL + + upgradedll.noreboot: + IntCmp $R6 0 upgradedll.done + RegDLL $R4 + Goto upgradedll.done + + ;------------------------ + ;No upgrade required - delete file + + upgradedll.dontupgrade: + Delete $R7 + + ;------------------------ + ;Done + + upgradedll.done: + Return + + ;------------------------ + ;End + + upgradedll.end: + Pop $R3 + Pop $R2 + Pop $R1 + Pop $R0 + + ;------------------------ + ;Restore settings + + SetOverwrite lastused + +FunctionEnd + +!endif diff --git a/apilibs/CORE.INI b/apilibs/CORE.INI new file mode 100644 index 0000000..6207c9c --- /dev/null +++ b/apilibs/CORE.INI @@ -0,0 +1,136 @@ +[ApiConfigurations] +default=0 +0=DCFG1 +1=WIN95 +2=WIN98 +3=WINME +4=NT40 +5=NT2K +6=WINXP +7=WIN2K3 +8=VISTA +9=WIN2K8 + +[DCFG1] +contents=std,kexbases,kexbasen +noshow=1 + +[DCFG1.names.98] +KERNEL32.GetVersion=std +KERNEL32.GetVersionExA=std +KERNEL32.GetVersionExW=std +GDI32.SetWorldTransform=kexbases.0 +GDI32.GetRandomRgn=std +GDI32.SetGraphicsMode=std +KERNEL32.VerSetConditionMask=none +KERNEL32.VerifyVersionInfoA=none +KERNEL32.VerifyVersionInfoW=none + +[DCFG1.names.Me] +KERNEL32.GetVersion=std +KERNEL32.GetVersionExA=std +KERNEL32.GetVersionExW=std +GDI32.SetWorldTransform=kexbases.0 +GDI32.GetRandomRgn=std +GDI32.SetGraphicsMode=std +KERNEL32.VerSetConditionMask=none +KERNEL32.VerifyVersionInfoA=none +KERNEL32.VerifyVersionInfoW=none +USER32.AllowSetForegroundWindow=std +USER32.LockSetForegroundWindow=std +USER32.GetMouseMovePointsEx=std + +[WIN95] +inherit=DCFG1 +desc=Windows 95 + +[WIN95.names] +KERNEL32.GetVersion=kexbases.0 +KERNEL32.GetVersionExA=kexbases.0 +KERNEL32.GetVersionExW=kexbases.0 + +[WIN98] +inherit=WIN95 +desc=Windows 98 SE + +[WIN98.names] +KERNEL32.GetVersion=kexbases.1 +KERNEL32.GetVersionExA=kexbases.1 +KERNEL32.GetVersionExW=kexbases.1 + +[WINME] +inherit=WIN98 +desc=Windows Millennium + +[WINME.names] +KERNEL32.GetVersion=kexbases.2 +KERNEL32.GetVersionExA=kexbases.2 +KERNEL32.GetVersionExW=kexbases.2 + +[NT40] +inherit=WIN95 +desc=Windows NT 4.0 SP6 + +[NT40.names] +KERNEL32.GetVersion=kexbases.3 +KERNEL32.GetVersionExA=kexbases.3 +KERNEL32.GetVersionExW=kexbases.3 + +[NT2K] +inherit=NT40 +desc=Windows 2000 SP4 + +[NT2K.names] +KERNEL32.GetVersion=kexbases.4 +KERNEL32.GetVersionExA=kexbases.4 +KERNEL32.GetVersionExW=kexbases.4 +GDI32.SetWorldTransform=kexbases.1 +GDI32.GetRandomRgn=kexbases.0 +GDI32.SetGraphicsMode=kexbases.0 +KERNEL32.VerSetConditionMask=kexbases.0 +KERNEL32.VerifyVersionInfoA=kexbases.0 +KERNEL32.VerifyVersionInfoW=kexbases.0 + +[WINXP] +inherit=NT2K +desc=Windows XP SP2 + +[WINXP.names] +KERNEL32.GetVersion=kexbases.5 +KERNEL32.GetVersionExA=kexbases.5 +KERNEL32.GetVersionExW=kexbases.5 +KERNEL32.VerifyVersionInfoA=kexbases.1 +KERNEL32.VerifyVersionInfoW=kexbases.1 + +[WIN2K3] +inherit=WINXP +desc=Windows 2003 SP1 + +[WIN2K3.names] +KERNEL32.GetVersion=kexbases.6 +KERNEL32.GetVersionExA=kexbases.6 +KERNEL32.GetVersionExW=kexbases.6 +KERNEL32.VerifyVersionInfoA=kexbases.2 +KERNEL32.VerifyVersionInfoW=kexbases.2 + +[VISTA] +inherit=WIN2K3 +desc=Windows Vista + +[VISTA.names] +KERNEL32.GetVersion=kexbases.7 +KERNEL32.GetVersionExA=kexbases.7 +KERNEL32.GetVersionExW=kexbases.7 +KERNEL32.VerifyVersionInfoA=kexbases.3 +KERNEL32.VerifyVersionInfoW=kexbases.3 + +[WIN2K8] +inherit=VISTA +desc=Windows 2008 SP1 + +[WIN2K8.names] +KERNEL32.GetVersion=kexbases.8 +KERNEL32.GetVersionExA=kexbases.8 +KERNEL32.GetVersionExW=kexbases.8 +KERNEL32.VerifyVersionInfoA=kexbases.4 +KERNEL32.VerifyVersionInfoW=kexbases.4 diff --git a/apilibs/kexbasen/advapi32/_advapi32_apilist.c b/apilibs/kexbasen/advapi32/_advapi32_apilist.c new file mode 100644 index 0000000..2f4207a --- /dev/null +++ b/apilibs/kexbasen/advapi32/_advapi32_apilist.c @@ -0,0 +1,66 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" +#include "kexcoresdk.h" +#include "_advapi32_apilist.h" + +BOOL init_advapi32() +{ + return TRUE; +} + +static const apilib_named_api advapi32_named_apis[] = +{ +/*** AUTOGENERATED APILIST NAMED EXPORTS BEGIN ***/ + DECL_API("GetUserNameW", GetUserNameW_fwd), + DECL_API("IsTextUnicode", IsTextUnicode_fwd), + DECL_API("RegConnectRegistryW", RegConnectRegistryW_fwd), + DECL_API("RegCreateKeyExW", RegCreateKeyExW_fwd), + DECL_API("RegCreateKeyW", RegCreateKeyW_fwd), + DECL_API("RegDeleteKeyW", RegDeleteKeyW_fwd), + DECL_API("RegDeleteValueW", RegDeleteValueW_fwd), + DECL_API("RegEnumKeyExW", RegEnumKeyExW_fwd), + DECL_API("RegEnumKeyW", RegEnumKeyW_fwd), + DECL_API("RegEnumValueW", RegEnumValueW_fwd), + DECL_API("RegLoadKeyW", RegLoadKeyW_fwd), + DECL_API("RegOpenKeyExW", RegOpenKeyExW_fwd), + DECL_API("RegOpenKeyW", RegOpenKeyW_fwd), + DECL_API("RegQueryInfoKeyW", RegQueryInfoKeyW_fwd), + DECL_API("RegQueryMultipleValuesW", RegQueryMultipleValuesW_fwd), + DECL_API("RegQueryValueW", RegQueryValueW_fwd), + DECL_API("RegReplaceKeyW", RegReplaceKeyW_fwd), + DECL_API("RegSaveKeyW", RegSaveKeyW_fwd), + DECL_API("RegSetValueExW", RegSetValueExW_fwd), + DECL_API("RegSetValueW", RegSetValueW_fwd), + DECL_API("RegUnLoadKeyW", RegUnLoadKeyW_fwd), +/*** AUTOGENERATED APILIST NAMED EXPORTS END ***/ +}; + +#if 0 +static const apilib_unnamed_api advapi32_ordinal_apis[] = +{ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS BEGIN ***/ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS END ***/ +}; +#endif + +const apilib_api_table apitable_advapi32 = DECL_TAB("ADVAPI32.DLL", advapi32_named_apis, 0 /*advapi32_ordinal_apis*/); diff --git a/apilibs/kexbasen/advapi32/_advapi32_apilist.h b/apilibs/kexbasen/advapi32/_advapi32_apilist.h new file mode 100644 index 0000000..47fd1da --- /dev/null +++ b/apilibs/kexbasen/advapi32/_advapi32_apilist.h @@ -0,0 +1,55 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#ifndef _ADVAPI32_APILIST_H +#define _ADVAPI32_APILIST_H + +#include "auxdecl.h" +#include "kexcoresdk.h" + +BOOL init_advapi32(); +extern const apilib_api_table apitable_advapi32; + +/*** AUTOGENERATED APILIST DECLARATIONS BEGIN ***/ +FWDPROC GetUserNameW_fwd; +FWDPROC IsTextUnicode_fwd; +FWDPROC RegConnectRegistryW_fwd; +FWDPROC RegCreateKeyExW_fwd; +FWDPROC RegCreateKeyW_fwd; +FWDPROC RegDeleteKeyW_fwd; +FWDPROC RegDeleteValueW_fwd; +FWDPROC RegEnumKeyExW_fwd; +FWDPROC RegEnumKeyW_fwd; +FWDPROC RegEnumValueW_fwd; +FWDPROC RegLoadKeyW_fwd; +FWDPROC RegOpenKeyExW_fwd; +FWDPROC RegOpenKeyW_fwd; +FWDPROC RegQueryInfoKeyW_fwd; +FWDPROC RegQueryMultipleValuesW_fwd; +FWDPROC RegQueryValueW_fwd; +FWDPROC RegReplaceKeyW_fwd; +FWDPROC RegSaveKeyW_fwd; +FWDPROC RegSetValueExW_fwd; +FWDPROC RegSetValueW_fwd; +FWDPROC RegUnLoadKeyW_fwd; +/*** AUTOGENERATED APILIST DECLARATIONS END ***/ + +#endif diff --git a/apilibs/kexbasen/advapi32/uniadvapi32.c b/apilibs/kexbasen/advapi32/uniadvapi32.c new file mode 100644 index 0000000..5b0c37d --- /dev/null +++ b/apilibs/kexbasen/advapi32/uniadvapi32.c @@ -0,0 +1,44 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "unifwd.h" + +FORWARD_TO_UNICOWS(GetUserNameW); +FORWARD_TO_UNICOWS(IsTextUnicode); +FORWARD_TO_UNICOWS(RegConnectRegistryW); +FORWARD_TO_UNICOWS(RegCreateKeyExW); +FORWARD_TO_UNICOWS(RegCreateKeyW); +FORWARD_TO_UNICOWS(RegDeleteKeyW); +FORWARD_TO_UNICOWS(RegDeleteValueW); +FORWARD_TO_UNICOWS(RegEnumKeyExW); +FORWARD_TO_UNICOWS(RegEnumKeyW); +FORWARD_TO_UNICOWS(RegEnumValueW); +FORWARD_TO_UNICOWS(RegLoadKeyW); +FORWARD_TO_UNICOWS(RegOpenKeyExW); +FORWARD_TO_UNICOWS(RegOpenKeyW); +FORWARD_TO_UNICOWS(RegQueryInfoKeyW); +FORWARD_TO_UNICOWS(RegQueryMultipleValuesW); +FORWARD_TO_UNICOWS(RegQueryValueW); +FORWARD_TO_UNICOWS(RegReplaceKeyW); +FORWARD_TO_UNICOWS(RegSaveKeyW); +FORWARD_TO_UNICOWS(RegSetValueExW); +FORWARD_TO_UNICOWS(RegSetValueW); +FORWARD_TO_UNICOWS(RegUnLoadKeyW); diff --git a/apilibs/kexbasen/auxdecl.h b/apilibs/kexbasen/auxdecl.h new file mode 100644 index 0000000..506f6aa --- /dev/null +++ b/apilibs/kexbasen/auxdecl.h @@ -0,0 +1,132 @@ +/* This file contains required declarations missing from MINGW and MSVC6 without PSDK */ + +#ifndef __AUXDECL_H +#define __AUXDECL_H + + +#include + +/* declarations for MSVC6 without PSDK */ +#if defined (_MSC_VER) && (WINVER < 0x0500) + +#define VER_MINORVERSION 0x0000001 +#define VER_MAJORVERSION 0x0000002 +#define VER_BUILDNUMBER 0x0000004 +#define VER_PLATFORMID 0x0000008 +#define VER_SERVICEPACKMINOR 0x0000010 +#define VER_SERVICEPACKMAJOR 0x0000020 +#define VER_SUITENAME 0x0000040 +#define VER_PRODUCT_TYPE 0x0000080 +#define VER_EQUAL 1 +#define VER_GREATER 2 +#define VER_GREATER_EQUAL 3 +#define VER_LESS 4 +#define VER_LESS_EQUAL 5 +#define VER_AND 6 +#define VER_OR 7 + +#define VER_NT_WORKSTATION 1 +#define VER_NT_DOMAIN_CONTROLLER 2 +#define VER_NT_SERVER 3 +#define VER_SUITE_SMALLBUSINESS 1 +#define VER_SUITE_ENTERPRISE 2 +#define VER_SUITE_BACKOFFICE 4 +#define VER_SUITE_TERMINAL 16 +#define VER_SUITE_SMALLBUSINESS_RESTRICTED 32 +#define VER_SUITE_EMBEDDEDNT 64 +#define VER_SUITE_DATACENTER 128 +#define VER_SUITE_SINGLEUSERTS 256 +#define VER_SUITE_PERSONAL 512 +#define VER_SUITE_BLADE 1024 +#define VER_SUITE_STORAGE_SERVER 8192 +#define VER_SUITE_COMPUTE_SERVER 16384 + +#define OSVERSIONINFOEXA __OSVERSIONINFOEXA +#define POSVERSIONINFOEXA __POSVERSIONINFOEXA +#define LPOSVERSIONINFOEXA __LPOSVERSIONINFOEXA +#define OSVERSIONINFOEXW __OSVERSIONINFOEXW +#define POSVERSIONINFOEXW __POSVERSIONINFOEXW +#define LPOSVERSIONINFOEXW __LPOSVERSIONINFOEXW + +typedef struct { + DWORD dwOSVersionInfoSize; + DWORD dwMajorVersion; + DWORD dwMinorVersion; + DWORD dwBuildNumber; + DWORD dwPlatformId; + CHAR szCSDVersion[128]; + WORD wServicePackMajor; + WORD wServicePackMinor; + WORD wSuiteMask; + BYTE wProductType; + BYTE wReserved; +} __OSVERSIONINFOEXA, *__POSVERSIONINFOEXA, *__LPOSVERSIONINFOEXA; +typedef struct { + DWORD dwOSVersionInfoSize; + DWORD dwMajorVersion; + DWORD dwMinorVersion; + DWORD dwBuildNumber; + DWORD dwPlatformId; + WCHAR szCSDVersion[128]; + WORD wServicePackMajor; + WORD wServicePackMinor; + WORD wSuiteMask; + BYTE wProductType; + BYTE wReserved; +} __OSVERSIONINFOEXW, *__POSVERSIONINFOEXW, *__LPOSVERSIONINFOEXW; + +typedef long LONG_PTR; +typedef BOOL (CALLBACK *UILANGUAGE_ENUMPROCA)(LPSTR, LONG_PTR); +typedef BOOL (CALLBACK *UILANGUAGE_ENUMPROCW)(LPWSTR, LONG_PTR); + +#define MEMORYSTATUSEX __MEMORYSTATUSEX +#define PMEMORYSTATUSEX __PMEMORYSTATUSEX +#define LPMEMORYSTATUSEX __LPMEMORYSTATUSEX + +typedef struct +{ + DWORD dwLength; + DWORD dwMemoryLoad; + DWORDLONG ullTotalPhys; + DWORDLONG ullAvailPhys; + DWORDLONG ullTotalPageFile; + DWORDLONG ullAvailPageFile; + DWORDLONG ullTotalVirtual; + DWORDLONG ullAvailVirtual; + DWORDLONG ullAvailExtendedVirtual; +} __MEMORYSTATUSEX, *__PMEMORYSTATUSEX, *__LPMEMORYSTATUSEX; + +typedef enum { + SHGFP_TYPE_CURRENT = 0, + SHGFP_TYPE_DEFAULT = 1, +} SHGFP_TYPE; + +#define GA_ROOT 2 + +typedef void *LPPRINTDLGEX; + +EXTERN_C int WINAPI GetRandomRgn(HDC hdc, HRGN hrgn, INT iNum); +EXTERN_C HRESULT WINAPI SHGetFolderPathA(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPSTR pszPath); +EXTERN_C HWND WINAPI GetAncestor(HWND hwnd, UINT gaFlags); +EXTERN_C UINT WINAPI RealGetWindowClass(HWND hwnd, LPTSTR pszType, UINT cchType); + +#endif /* defined (_MSC_VER) && (WINVER < 0x0500) */ + + +/* declarations for MINGW32 */ +#ifdef __MINGW32_VERSION + +/* The security descriptor structure */ +typedef struct { + BYTE Revision; + BYTE Sbz1; + SECURITY_DESCRIPTOR_CONTROL Control; + DWORD Owner; + DWORD Group; + DWORD Sacl; + DWORD Dacl; +} SECURITY_DESCRIPTOR_RELATIVE, *PISECURITY_DESCRIPTOR_RELATIVE; + +#endif /* __MINGW32_VERSION */ + +#endif /* __AUXDECL_H */ diff --git a/apilibs/kexbasen/comdlg32/_comdlg32_apilist.c b/apilibs/kexbasen/comdlg32/_comdlg32_apilist.c new file mode 100644 index 0000000..1620c8c --- /dev/null +++ b/apilibs/kexbasen/comdlg32/_comdlg32_apilist.c @@ -0,0 +1,54 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" +#include "kexcoresdk.h" +#include "_comdlg32_apilist.h" + +BOOL init_comdlg32() +{ + return TRUE; +} + +static const apilib_named_api comdlg32_named_apis[] = +{ +/*** AUTOGENERATED APILIST NAMED EXPORTS BEGIN ***/ + DECL_API("ChooseColorW", ChooseColorW_fwd), + DECL_API("ChooseFontW", ChooseFontW_fwd), + DECL_API("FindTextW", FindTextW_fwd), + DECL_API("GetFileTitleW", GetFileTitleW_fwd), + DECL_API("GetOpenFileNameW", GetOpenFileNameW_fwd), + DECL_API("GetSaveFileNameW", GetSaveFileNameW_fwd), + DECL_API("PageSetupDlgW", PageSetupDlgW_fwd), + DECL_API("PrintDlgW", PrintDlgW_fwd), + DECL_API("ReplaceTextW", ReplaceTextW_fwd), +/*** AUTOGENERATED APILIST NAMED EXPORTS END ***/ +}; + +#if 0 +static const apilib_unnamed_api comdlg32_ordinal_apis[] = +{ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS BEGIN ***/ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS END ***/ +}; +#endif + +const apilib_api_table apitable_comdlg32 = DECL_TAB("COMDLG32.DLL", comdlg32_named_apis, 0 /*comdlg32_ordinal_apis*/); diff --git a/apilibs/kexbasen/comdlg32/_comdlg32_apilist.h b/apilibs/kexbasen/comdlg32/_comdlg32_apilist.h new file mode 100644 index 0000000..4b0b55b --- /dev/null +++ b/apilibs/kexbasen/comdlg32/_comdlg32_apilist.h @@ -0,0 +1,43 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#ifndef _COMDLG32_APILIST_H +#define _COMDLG32_APILIST_H + +#include "auxdecl.h" +#include "kexcoresdk.h" + +BOOL init_comdlg32(); +extern const apilib_api_table apitable_comdlg32; + +/*** AUTOGENERATED APILIST DECLARATIONS BEGIN ***/ +FWDPROC ChooseColorW_fwd; +FWDPROC ChooseFontW_fwd; +FWDPROC FindTextW_fwd; +FWDPROC GetFileTitleW_fwd; +FWDPROC GetOpenFileNameW_fwd; +FWDPROC GetSaveFileNameW_fwd; +FWDPROC PageSetupDlgW_fwd; +FWDPROC PrintDlgW_fwd; +FWDPROC ReplaceTextW_fwd; +/*** AUTOGENERATED APILIST DECLARATIONS END ***/ + +#endif diff --git a/apilibs/kexbasen/comdlg32/unicomdlg32.c b/apilibs/kexbasen/comdlg32/unicomdlg32.c new file mode 100644 index 0000000..220234b --- /dev/null +++ b/apilibs/kexbasen/comdlg32/unicomdlg32.c @@ -0,0 +1,32 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "unifwd.h" + +FORWARD_TO_UNICOWS(ChooseColorW); +FORWARD_TO_UNICOWS(ChooseFontW); +FORWARD_TO_UNICOWS(FindTextW); +FORWARD_TO_UNICOWS(GetFileTitleW); +FORWARD_TO_UNICOWS(GetOpenFileNameW); +FORWARD_TO_UNICOWS(GetSaveFileNameW); +FORWARD_TO_UNICOWS(PageSetupDlgW); +FORWARD_TO_UNICOWS(PrintDlgW); +FORWARD_TO_UNICOWS(ReplaceTextW); diff --git a/apilibs/kexbasen/common.c b/apilibs/kexbasen/common.c new file mode 100644 index 0000000..24270dd --- /dev/null +++ b/apilibs/kexbasen/common.c @@ -0,0 +1,59 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" + +int acp_mcs; + +static int GetMaxCharSize(UINT CodePage) +{ + CPINFO cpi; + if (!GetCPInfo(CodePage, &cpi)) + return 2; + return cpi.MaxCharSize; +} + +BOOL common_init(void) +{ + acp_mcs = GetMaxCharSize(CP_ACP); + return TRUE; +} + +char* file_fixWprefix(char* in) +{ + if (*(int *)in == 0x5c3f5c5c) //if (!strncmp(in, "\\?\", 4)) + { + in += 4; + if (*(int *)in == 0x5c434e55) //if (!strncmp(in, "UNC\", 4)) + { + in += 2; + *in = '\\'; + } + } + return in; +} + +void fatal_error(const char* msg) +{ + MessageBox(NULL, msg, "KernelEx error", MB_OK | MB_ICONERROR); +#pragma message("place DBGBREAK here!!!!") + ExitProcess(1); +} diff --git a/apilibs/kexbasen/common.h b/apilibs/kexbasen/common.h new file mode 100644 index 0000000..f06cc90 --- /dev/null +++ b/apilibs/kexbasen/common.h @@ -0,0 +1,107 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#ifndef __COMMON_H +#define __COMMON_H + +#include +#include + +typedef int __stdcall STUB(void); +typedef int __stdcall FWDPROC(void); + +extern int acp_mcs; +BOOL common_init(void); +int WINAPI CommonUnimpStub(void); +char* file_fixWprefix(char* in); +void fatal_error(const char* msg); + + +#ifdef __GNUC__ +#define UNIMPL_FUNC(name,params) \ + __asm__( ".text\n" \ + ".globl _" #name "_stub@0\n" \ + "_" #name "_new@0:\n\t" \ + "xor %eax, %eax\n\t" \ + "movb $" #params ", %cl\n\t" \ + "jmp _CommonUnimpStub@0\n\t" \ + ) +#else +#define UNIMPL_FUNC(name,params) \ + int __declspec(naked) __stdcall name##_stub() \ + { \ + __asm xor eax,eax \ + __asm mov cl, params \ + __asm jmp CommonUnimpStub \ + } +#endif + +#define AtoW(str, bsize) MultiByteToWideChar(CP_ACP, 0, str##A, -1, str##W, bsize) +#define WtoA(str, bsize) WideCharToMultiByte(CP_ACP, 0, str##W, -1, str##A, bsize, NULL, NULL) + +#define _ALLOC_WtoA(str) \ + const WCHAR* p; \ + int c; \ + for (p = str##W ; *p ; p++); \ + c = (int) p - (int) str##W; \ + c *= acp_mcs; \ + str##A = (char*) alloca(c); \ + WtoA(str, c) + + +#define ALLOC_WtoA(str) \ + char* str##A; \ + if (str##W) \ + { \ + _ALLOC_WtoA(str); \ + } \ + else str##A = NULL + +#define ALLOC_A(str, cnt) \ + char* str##A = str##W ? ((char*) alloca(cnt)) : NULL + +#define ABUFtoW(str, inbsize, outbsize) \ + MultiByteToWideChar(CP_ACP, 0, str##A, inbsize, str##W, outbsize) + +#define file_GetCP() \ + UINT file_CP = AreFileApisANSI() ? CP_ACP : CP_OEMCP +#define file_AtoW(str, bsize) MultiByteToWideChar(file_CP, 0, str##A, -1, str##W, bsize) +#define file_WtoA(str, bsize) WideCharToMultiByte(file_CP, 0, str##W, -1, str##A, bsize, "_", NULL); \ + str##A = file_fixWprefix(str##A) + +#define file_ALLOC_WtoA(str) \ + char* str##A; \ + if (str##W) \ + { \ + const WCHAR* p; \ + int c; \ + for (p = str##W ; *p ; p++); \ + c = (int) p - (int) str##W; \ + c *= acp_mcs; \ + str##A = (char*) alloca(c); \ + file_WtoA(str, c); \ + } \ + else str##A = NULL + +#define file_ABUFtoW(str, cntsrc, bsize) \ + MultiByteToWideChar(file_CP, 0, str##A, cntsrc, str##W, bsize) + +#endif diff --git a/apilibs/kexbasen/dirlist b/apilibs/kexbasen/dirlist new file mode 100644 index 0000000..085ec8e --- /dev/null +++ b/apilibs/kexbasen/dirlist @@ -0,0 +1,6 @@ +kernel32 +user32 +gdi32 +advapi32 +comdlg32 +shell32 diff --git a/apilibs/kexbasen/gdi32/UberGDI.c b/apilibs/kexbasen/gdi32/UberGDI.c new file mode 100644 index 0000000..08fb639 --- /dev/null +++ b/apilibs/kexbasen/gdi32/UberGDI.c @@ -0,0 +1,335 @@ +/* + * KernelEx + * + * Copyright 1993 Alexandre Julliard + * 1997 Alex Korobka + * Copyright 2002,2003 Shachar Shemesh + * Copyright 2003 CodeWeavers Inc. (Ulrich Czekalla) + * + * Copyright (C) 2008, Tihiy + * 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. + * + */ + +#include +#include +#include "common.h" +//#include + +typedef void *SCRIPT_CACHE; +typedef struct { + int cBytes; + WORD wgBlank; + WORD wgDefault; + WORD wgInvalid; + WORD wgKashida; + int iKashidaWidth; +} SCRIPT_FONTPROPERTIES; + + +typedef HRESULT (WINAPI *PFNSCRIPTGETCMAP) ( + HDC hdc, + SCRIPT_CACHE *psc, + const WCHAR *pwcInChars, + int cChars, + DWORD dwFlags, + WORD *pwOutGlyphs); +typedef HRESULT (WINAPI *PFNSFC) (SCRIPT_CACHE *psc); +typedef HRESULT (WINAPI *PFNCGH) ( HDC hdc, SCRIPT_CACHE *psc, long *tmHeight ); +typedef HRESULT (WINAPI *PFNGFP) ( HDC hdc, SCRIPT_CACHE *psc, SCRIPT_FONTPROPERTIES *sfp ); +typedef HRESULT (WINAPI *PFNGETGABCWIDTH) ( HDC hdc, SCRIPT_CACHE *psc, WORD wGlyph, ABC *pABC); + +static HRESULT WINAPI ScriptGetCMap_dld(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcInChars, int cChars, DWORD dwFlags, WORD *pwOutGlyphs); +static HRESULT WINAPI ScriptFreeCache_dld(SCRIPT_CACHE *psc); +static HRESULT WINAPI ScriptCacheGetHeight_dld(HDC hdc, SCRIPT_CACHE *psc, long *tmHeight); +static HRESULT WINAPI ScriptGetFontProperties_dld(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_FONTPROPERTIES *sfp); + +static PFNSCRIPTGETCMAP ScriptGetCMap_pfn = ScriptGetCMap_dld; +static PFNSFC ScriptFreeCache_pfn = ScriptFreeCache_dld; +static PFNCGH ScriptCacheGetHeight_pfn = ScriptCacheGetHeight_dld; +static PFNGFP ScriptGetFontProperties_pfn = ScriptGetFontProperties_dld; +static PFNGETGABCWIDTH ScriptGetGlyphABCWidth_pfn = NULL; + +/* delay-loaded Uniscribe start */ +static const char c_szUsp10[]="usp10.dll"; + +static FARPROC WINAPI LoadUniscribeProc(LPCSTR proc) +{ + static HMODULE usp10; + FARPROC ret; + DWORD lasterr = GetLastError(); + + if (!usp10) + { + usp10 = GetModuleHandleA(c_szUsp10); + if (!usp10) usp10 = LoadLibraryA(c_szUsp10); + if (!usp10) + fatal_error("kexbasen: Failed to load Uniscribe!"); + } + ret = GetProcAddress(usp10,proc); + SetLastError(lasterr); + return ret; +} + +static HRESULT WINAPI ScriptGetCMap_dld( + HDC hdc, + SCRIPT_CACHE *psc, + const WCHAR *pwcInChars, + int cChars, + DWORD dwFlags, + WORD *pwOutGlyphs +) +{ + PFNSCRIPTGETCMAP pfn; + pfn = (PFNSCRIPTGETCMAP)LoadUniscribeProc("ScriptGetCMap"); + if ( !pfn ) return E_FAIL; + ScriptGetCMap_pfn = pfn; + return pfn (hdc,psc,pwcInChars,cChars,dwFlags,pwOutGlyphs); +} + +static HRESULT WINAPI ScriptFreeCache_dld( + SCRIPT_CACHE *psc +) +{ + PFNSFC pfn; + pfn = (PFNSFC)LoadUniscribeProc("ScriptFreeCache"); + if ( !pfn ) return E_FAIL; + ScriptFreeCache_pfn = pfn; + return pfn (psc); +} + +static HRESULT WINAPI ScriptCacheGetHeight_dld( + HDC hdc, + SCRIPT_CACHE *psc, + long *tmHeight +) +{ + PFNCGH pfn; + pfn = (PFNCGH)LoadUniscribeProc("ScriptCacheGetHeight"); + if ( !pfn ) return E_FAIL; + ScriptCacheGetHeight_pfn = pfn; + return pfn (hdc,psc,tmHeight); +} + +static HRESULT WINAPI ScriptGetFontProperties_dld( + HDC hdc, + SCRIPT_CACHE *psc, + SCRIPT_FONTPROPERTIES *sfp +) +{ + PFNGFP pfn; + pfn = (PFNGFP)LoadUniscribeProc("ScriptGetFontProperties"); + if ( !pfn ) return E_FAIL; + ScriptGetFontProperties_pfn = pfn; + return pfn (hdc,psc,sfp); +} + +/* delay-loaded Uniscribe END */ + +/* MAKE_EXPORT GetGlyphIndicesW_new=GetGlyphIndicesW */ +int WINAPI GetGlyphIndicesW_new( + HDC hdc, // handle to DC + LPWSTR lpstr, // string to convert + int c, // number of characters in string + LPWORD pgi, // array of glyph indices + DWORD fl // glyph options +) +{ + HRESULT result; + SCRIPT_CACHE cache = 0; + if (!hdc || !pgi || (UINT)lpstr<0xFFFFu || !c) return GDI_ERROR; + result = ScriptGetCMap_pfn(hdc,&cache,lpstr,c,0,pgi); + if ( !( result == S_OK || result == S_FALSE ) ) return GDI_ERROR; + if ( fl && result == S_FALSE) + { + WORD* checkglyph = pgi; + int i; + SCRIPT_FONTPROPERTIES fpr; + fpr.cBytes = sizeof(SCRIPT_FONTPROPERTIES); + if (FAILED(ScriptGetFontProperties_pfn(hdc,&cache,&fpr))) return GDI_ERROR; + for (i = 0; i < c; i++) + { + if (*checkglyph == fpr.wgDefault) *checkglyph = 0xFFFF; + checkglyph++; + } + } + ScriptFreeCache_pfn(&cache); + return c; +} + +static int WINAPI GdiGetCodePage( HDC hdc ) +{ + UINT cp = CP_ACP; + CHARSETINFO csi; + int charset = GetTextCharset(hdc); + + /* Hmm, nicely designed api this one! */ + if(TranslateCharsetInfo((DWORD*)charset, &csi, TCI_SRCCHARSET)) + cp = csi.ciACP; + else + { + switch(charset) + { + case OEM_CHARSET: + cp = GetOEMCP(); + break; + case DEFAULT_CHARSET: + cp = GetACP(); + break; + } + } + return cp; +} + +/* MAKE_EXPORT GetGlyphIndicesA_new=GetGlyphIndicesA */ +int WINAPI GetGlyphIndicesA_new( + HDC hdc, // handle to DC + LPCSTR lpstr, // string to convert + int c, // number of characters in string + LPWORD pgi, // array of glyph indices + DWORD fl // glyph options +) +{ + int result; + LPWSTR lpstrwide; + if (!hdc || !pgi || (UINT)lpstr<0xFFFF || c<=0) return GDI_ERROR; + lpstrwide = (LPWSTR)alloca(c*sizeof(WCHAR)); + if (MultiByteToWideChar(GdiGetCodePage(hdc),0,lpstr,c,lpstrwide,c)) + result = GetGlyphIndicesW_new(hdc,lpstrwide,c,pgi,fl); + else + result = GDI_ERROR; + return result; +} + +/* MAKE_EXPORT GetTextExtentExPointI_new=GetTextExtentExPointI */ +BOOL WINAPI GetTextExtentExPointI_new( + HDC hdc, // handle to DC + LPWORD pgiIn, // array of glyph indices + int cgi, // number of glyphs in array + int nMaxExtent, // maximum width of formatted string + LPINT lpnFit, // maximum number of characters + LPINT alpDx, // array of partial string widths + LPSIZE lpSize // string dimensions +) +{ + SCRIPT_CACHE cache = 0; + ABC abc; + WORD* glyph = pgiIn; + int* dxs = alpDx; + int i; + int sum = 0; + int glyphwidth; + BOOL unfit = FALSE; + + if (!ScriptGetGlyphABCWidth_pfn) + ScriptGetGlyphABCWidth_pfn = (PFNGETGABCWIDTH)LoadUniscribeProc("ScriptGetGlyphABCWidth"); + if ( !hdc || !pgiIn || cgi<=0 || !lpSize || !ScriptGetGlyphABCWidth_pfn) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + //in UberKern, ScriptPlace was used. However, it's too costly... + //so let's compute the info ourselves + for (i = 0; i < cgi; i++) + { + if ( ScriptGetGlyphABCWidth_pfn(hdc,&cache,*glyph,&abc) != S_OK ) break; + glyphwidth = abc.abcA + abc.abcB + abc.abcC; + sum += glyphwidth; + if ( !unfit ) + { + unfit = ( sum > nMaxExtent ); + if (alpDx) {*dxs = sum; dxs++;} + if (unfit && lpnFit) *lpnFit = i+1; //test test! + } + glyph++; + } + lpSize->cx = sum; + ScriptCacheGetHeight_pfn(hdc,&cache,&lpSize->cy); + ScriptFreeCache_pfn(&cache); + return TRUE; +} + +/* MAKE_EXPORT GetTextExtentPointI_new=GetTextExtentPointI */ +BOOL WINAPI GetTextExtentPointI_new( + HDC hdc, // handle to DC + LPWORD pgiIn, // glyph indices + int cgi, // number of indices in array + LPSIZE lpSize // string size +) +{ + return GetTextExtentExPointI_new(hdc,pgiIn,cgi,32768,0,0,lpSize); +} + +/* MAKE_EXPORT GetCharWidthI_new=GetCharWidthI */ +BOOL WINAPI GetCharWidthI_new( + HDC hdc, // handle to DC + UINT giFirst, // first glyph index in range + UINT cgi, // number of glyph indices in range + WORD* pgi, // array of glyph indices + INT* lpBuffer // buffer for widths +) +{ + SCRIPT_CACHE cache = 0; + ABC abc; + WORD glyph; + + if (!ScriptGetGlyphABCWidth_pfn) + ScriptGetGlyphABCWidth_pfn = (PFNGETGABCWIDTH)LoadUniscribeProc("ScriptGetGlyphABCWidth"); + if ( !hdc || !lpBuffer || cgi<=0 || !ScriptGetGlyphABCWidth_pfn) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + if ( !pgi ) //cgi glyphs starting giFirst + { + for ( glyph = giFirst; glyph < giFirst+cgi; glyph++) + { + ScriptGetGlyphABCWidth_pfn(hdc,&cache,glyph,&abc); + *lpBuffer = abc.abcA + abc.abcB + abc.abcC; + lpBuffer++; + } + } + else + { + for ( glyph = 0; glyph < cgi; glyph++) + { + ScriptGetGlyphABCWidth_pfn(hdc,&cache,*pgi,&abc); + *lpBuffer = abc.abcA + abc.abcB + abc.abcC; + pgi++; + lpBuffer++; + } + } + ScriptFreeCache_pfn(&cache); + return TRUE; +} + +/* MAKE_EXPORT GetGlyphOutlineW_new=GetGlyphOutlineW */ +DWORD WINAPI GetGlyphOutlineW_new( + HDC hdc, // handle to DC + UINT uChar, // character to query + UINT uFormat, // data format + LPGLYPHMETRICS lpgm, // glyph metrics + DWORD cbBuffer, // size of data buffer + LPVOID lpvBuffer, // data buffer + CONST MAT2 *lpmat2 // transformation matrix +) +{ + UINT glyph = 0; + if (uFormat & GGO_GLYPH_INDEX) + return GetGlyphOutlineA( hdc, uChar, uFormat, lpgm, cbBuffer, lpvBuffer, lpmat2 ); + GetGlyphIndicesW_new( hdc, (LPWSTR)&uChar, 1, (LPWORD)&glyph, 0 ); + return GetGlyphOutlineA( hdc, glyph, uFormat | GGO_GLYPH_INDEX, lpgm, cbBuffer, lpvBuffer, lpmat2 ); +} diff --git a/apilibs/kexbasen/gdi32/_gdi32_apilist.c b/apilibs/kexbasen/gdi32/_gdi32_apilist.c new file mode 100644 index 0000000..3c43e6b --- /dev/null +++ b/apilibs/kexbasen/gdi32/_gdi32_apilist.c @@ -0,0 +1,82 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" +#include "kexcoresdk.h" +#include "_gdi32_apilist.h" + +BOOL init_gdi32() +{ + return TRUE; +} + +static const apilib_named_api gdi32_named_apis[] = +{ +/*** AUTOGENERATED APILIST NAMED EXPORTS BEGIN ***/ + DECL_API("CopyEnhMetaFileW", CopyEnhMetaFileW_fwd), + DECL_API("CopyMetaFileW", CopyMetaFileW_fwd), + DECL_API("CreateColorSpaceW", CreateColorSpaceW_fwd), + DECL_API("CreateDCW", CreateDCW_fwd), + DECL_API("CreateEnhMetaFileW", CreateEnhMetaFileW_fwd), + DECL_API("CreateFontIndirectW", CreateFontIndirectW_fwd), + DECL_API("CreateFontW", CreateFontW_fwd), + DECL_API("CreateICW", CreateICW_fwd), + DECL_API("CreateMetaFileW", CreateMetaFileW_fwd), + DECL_API("CreateScalableFontResourceW", CreateScalableFontResourceW_fwd), + DECL_API("EnumFontFamiliesExW", EnumFontFamiliesExW_fwd), + DECL_API("EnumFontFamiliesW", EnumFontFamiliesW_fwd), + DECL_API("EnumFontsW", EnumFontsW_fwd), + DECL_API("EnumICMProfilesW", EnumICMProfilesW_fwd), + DECL_API("GetCharABCWidthsW", GetCharABCWidthsW_fwd), + DECL_API("GetCharWidthI", GetCharWidthI_new), + DECL_API("GetCharacterPlacementW", GetCharacterPlacementW_fwd), + DECL_API("GetEnhMetaFileDescriptionW", GetEnhMetaFileDescriptionW_fwd), + DECL_API("GetEnhMetaFileW", GetEnhMetaFileW_fwd), + DECL_API("GetGlyphIndicesA", GetGlyphIndicesA_new), + DECL_API("GetGlyphIndicesW", GetGlyphIndicesW_new), + DECL_API("GetGlyphOutlineW", GetGlyphOutlineW_new), + DECL_API("GetICMProfileW", GetICMProfileW_fwd), + DECL_API("GetKerningPairsW", GetKerningPairsW_fwd), + DECL_API("GetLogColorSpaceW", GetLogColorSpaceW_fwd), + DECL_API("GetMetaFileW", GetMetaFileW_fwd), + DECL_API("GetObjectW", GetObjectW_fwd), + DECL_API("GetOutlineTextMetricsW", GetOutlineTextMetricsW_fwd), + DECL_API("GetTextExtentExPointI", GetTextExtentExPointI_new), + DECL_API("GetTextExtentExPointW", GetTextExtentExPointW_fwd), + DECL_API("GetTextExtentPointI", GetTextExtentPointI_new), + DECL_API("GetTextFaceW", GetTextFaceW_fwd), + DECL_API("GetTextMetricsW", GetTextMetricsW_fwd), + DECL_API("ResetDCW", ResetDCW_fwd), + DECL_API("SetICMProfileW", SetICMProfileW_fwd), + DECL_API("StartDocW", StartDocW_fwd), + DECL_API("UpdateICMRegKeyW", UpdateICMRegKeyW_fwd), +/*** AUTOGENERATED APILIST NAMED EXPORTS END ***/ +}; + +#if 0 +static const apilib_unnamed_api gdi32_ordinal_apis[] = +{ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS BEGIN ***/ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS END ***/ +}; +#endif + +const apilib_api_table apitable_gdi32 = DECL_TAB("GDI32.DLL", gdi32_named_apis, 0 /*gdi32_ordinal_apis*/); diff --git a/apilibs/kexbasen/gdi32/_gdi32_apilist.h b/apilibs/kexbasen/gdi32/_gdi32_apilist.h new file mode 100644 index 0000000..c0c439c --- /dev/null +++ b/apilibs/kexbasen/gdi32/_gdi32_apilist.h @@ -0,0 +1,71 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#ifndef _GDI32_APILIST_H +#define _GDI32_APILIST_H + +#include "auxdecl.h" +#include "kexcoresdk.h" + +BOOL init_gdi32(); +extern const apilib_api_table apitable_gdi32; + +/*** AUTOGENERATED APILIST DECLARATIONS BEGIN ***/ +int WINAPI GetGlyphIndicesW_new(HDC hdc, LPWSTR lpstr, int c, LPWORD pgi, DWORD fl); +int WINAPI GetGlyphIndicesA_new(HDC hdc, LPCSTR lpstr, int c, LPWORD pgi, DWORD fl); +BOOL WINAPI GetTextExtentExPointI_new(HDC hdc, LPWORD pgiIn, int cgi, int nMaxExtent, LPINT lpnFit, LPINT alpDx, LPSIZE lpSize); +BOOL WINAPI GetTextExtentPointI_new(HDC hdc, LPWORD pgiIn, int cgi, LPSIZE lpSize); +BOOL WINAPI GetCharWidthI_new(HDC hdc, UINT giFirst, UINT cgi, WORD* pgi, INT* lpBuffer); +DWORD WINAPI GetGlyphOutlineW_new(HDC hdc, UINT uChar, UINT uFormat, LPGLYPHMETRICS lpgm, DWORD cbBuffer, LPVOID lpvBuffer, CONST MAT2 *lpmat2); +FWDPROC CopyEnhMetaFileW_fwd; +FWDPROC CopyMetaFileW_fwd; +FWDPROC CreateColorSpaceW_fwd; +FWDPROC CreateDCW_fwd; +FWDPROC CreateEnhMetaFileW_fwd; +FWDPROC CreateFontIndirectW_fwd; +FWDPROC CreateFontW_fwd; +FWDPROC CreateICW_fwd; +FWDPROC CreateMetaFileW_fwd; +FWDPROC CreateScalableFontResourceW_fwd; +FWDPROC EnumFontFamiliesExW_fwd; +FWDPROC EnumFontFamiliesW_fwd; +FWDPROC EnumFontsW_fwd; +FWDPROC EnumICMProfilesW_fwd; +FWDPROC GetCharABCWidthsW_fwd; +FWDPROC GetCharacterPlacementW_fwd; +FWDPROC GetEnhMetaFileDescriptionW_fwd; +FWDPROC GetEnhMetaFileW_fwd; +FWDPROC GetICMProfileW_fwd; +FWDPROC GetKerningPairsW_fwd; +FWDPROC GetLogColorSpaceW_fwd; +FWDPROC GetMetaFileW_fwd; +FWDPROC GetObjectW_fwd; +FWDPROC GetOutlineTextMetricsW_fwd; +FWDPROC GetTextExtentExPointW_fwd; +FWDPROC GetTextFaceW_fwd; +FWDPROC GetTextMetricsW_fwd; +FWDPROC ResetDCW_fwd; +FWDPROC SetICMProfileW_fwd; +FWDPROC StartDocW_fwd; +FWDPROC UpdateICMRegKeyW_fwd; +/*** AUTOGENERATED APILIST DECLARATIONS END ***/ + +#endif diff --git a/apilibs/kexbasen/gdi32/unigdi32.c b/apilibs/kexbasen/gdi32/unigdi32.c new file mode 100644 index 0000000..514986f --- /dev/null +++ b/apilibs/kexbasen/gdi32/unigdi32.c @@ -0,0 +1,54 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "unifwd.h" + +FORWARD_TO_UNICOWS(CopyEnhMetaFileW); +FORWARD_TO_UNICOWS(CopyMetaFileW); +FORWARD_TO_UNICOWS(CreateColorSpaceW); +FORWARD_TO_UNICOWS(CreateDCW); +FORWARD_TO_UNICOWS(CreateEnhMetaFileW); +FORWARD_TO_UNICOWS(CreateFontIndirectW); +FORWARD_TO_UNICOWS(CreateFontW); +FORWARD_TO_UNICOWS(CreateICW); +FORWARD_TO_UNICOWS(CreateMetaFileW); +FORWARD_TO_UNICOWS(CreateScalableFontResourceW); +FORWARD_TO_UNICOWS(EnumFontFamiliesExW); +FORWARD_TO_UNICOWS(EnumFontFamiliesW); +FORWARD_TO_UNICOWS(EnumFontsW); +FORWARD_TO_UNICOWS(EnumICMProfilesW); +FORWARD_TO_UNICOWS(GetCharABCWidthsW); +FORWARD_TO_UNICOWS(GetCharacterPlacementW); +FORWARD_TO_UNICOWS(GetEnhMetaFileDescriptionW); +FORWARD_TO_UNICOWS(GetEnhMetaFileW); +FORWARD_TO_UNICOWS(GetICMProfileW); +FORWARD_TO_UNICOWS(GetKerningPairsW); +FORWARD_TO_UNICOWS(GetLogColorSpaceW); +FORWARD_TO_UNICOWS(GetMetaFileW); +FORWARD_TO_UNICOWS(GetObjectW); +FORWARD_TO_UNICOWS(GetOutlineTextMetricsW); +FORWARD_TO_UNICOWS(GetTextExtentExPointW); +FORWARD_TO_UNICOWS(GetTextFaceW); +FORWARD_TO_UNICOWS(GetTextMetricsW); +FORWARD_TO_UNICOWS(ResetDCW); +FORWARD_TO_UNICOWS(SetICMProfileW); +FORWARD_TO_UNICOWS(StartDocW); +FORWARD_TO_UNICOWS(UpdateICMRegKeyW); diff --git a/apilibs/kexbasen/kernel32/_kernel32_apilist.c b/apilibs/kexbasen/kernel32/_kernel32_apilist.c new file mode 100644 index 0000000..eca619c --- /dev/null +++ b/apilibs/kexbasen/kernel32/_kernel32_apilist.c @@ -0,0 +1,129 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" +#include "kexcoresdk.h" +#include "_kernel32_apilist.h" + +BOOL init_kernel32() +{ + return TRUE; +} + +static const apilib_named_api kernel32_named_apis[] = +{ +/*** AUTOGENERATED APILIST NAMED EXPORTS BEGIN ***/ + DECL_API("BuildCommDCBAndTimeoutsW", BuildCommDCBAndTimeoutsW_fwd), + DECL_API("BuildCommDCBW", BuildCommDCBW_fwd), + DECL_API("CallNamedPipeW", CallNamedPipeW_fwd), + DECL_API("CommConfigDialogW", CommConfigDialogW_fwd), + DECL_API("CompareStringW", CompareStringW_fwd), + DECL_API("CreateEventW", CreateEventW_fwd), + DECL_API("CreateFileMappingW", CreateFileMappingW_fwd), + DECL_API("CreateMailslotW", CreateMailslotW_fwd), + DECL_API("CreateMutexW", CreateMutexW_fwd), + DECL_API("CreateProcessW", CreateProcessW_fwd), + DECL_API("CreateSemaphoreW", CreateSemaphoreW_fwd), + DECL_API("CreateWaitableTimerW", CreateWaitableTimerW_fwd), + DECL_API("EnumCalendarInfoExW", EnumCalendarInfoExW_fwd), + DECL_API("EnumCalendarInfoW", EnumCalendarInfoW_fwd), + DECL_API("EnumDateFormatsExW", EnumDateFormatsExW_fwd), + DECL_API("EnumDateFormatsW", EnumDateFormatsW_fwd), + DECL_API("EnumSystemCodePagesW", EnumSystemCodePagesW_fwd), + DECL_API("EnumSystemLocalesW", EnumSystemLocalesW_fwd), + DECL_API("EnumTimeFormatsW", EnumTimeFormatsW_fwd), + DECL_API("ExpandEnvironmentStringsW", ExpandEnvironmentStringsW_fwd), + DECL_API("FatalAppExitW", FatalAppExitW_fwd), + DECL_API("FillConsoleOutputCharacterW", FillConsoleOutputCharacterW_fwd), + DECL_API("FormatMessageW", FormatMessageW_fwd), + DECL_API("GetAtomNameW", GetAtomNameW_fwd), + DECL_API("GetCPInfoExW", GetCPInfoExW_fwd), + DECL_API("GetCalendarInfoW", GetCalendarInfoW_fwd), + DECL_API("GetComputerNameW", GetComputerNameW_fwd), + DECL_API("GetConsoleTitleW", GetConsoleTitleW_fwd), + DECL_API("GetCurrencyFormatW", GetCurrencyFormatW_fwd), + DECL_API("GetDateFormatW", GetDateFormatW_fwd), + DECL_API("GetDriveTypeW", GetDriveTypeW_fwd), + DECL_API("GetEnvironmentVariableW", GetEnvironmentVariableW_fwd), + DECL_API("GetLocaleInfoW", GetLocaleInfoW_fwd), + DECL_API("GetLogicalDriveStringsW", GetLogicalDriveStringsW_fwd), + DECL_API("GetModuleFileNameW", GetModuleFileNameW_fwd), + DECL_API("GetModuleHandleW", GetModuleHandleW_fwd), + DECL_API("GetNamedPipeHandleStateW", GetNamedPipeHandleStateW_fwd), + DECL_API("GetNumberFormatW", GetNumberFormatW_fwd), + DECL_API("GetPrivateProfileIntW", GetPrivateProfileIntW_fwd), + DECL_API("GetPrivateProfileSectionNamesW", GetPrivateProfileSectionNamesW_fwd), + DECL_API("GetPrivateProfileSectionW", GetPrivateProfileSectionW_fwd), + DECL_API("GetPrivateProfileStringW", GetPrivateProfileStringW_fwd), + DECL_API("GetPrivateProfileStructW", GetPrivateProfileStructW_fwd), + DECL_API("GetProfileIntW", GetProfileIntW_fwd), + DECL_API("GetProfileSectionW", GetProfileSectionW_fwd), + DECL_API("GetProfileStringW", GetProfileStringW_fwd), + DECL_API("GetStringTypeExW", GetStringTypeExW_fwd), + DECL_API("GetStringTypeW", GetStringTypeW_fwd), + DECL_API("GetTimeFormatW", GetTimeFormatW_fwd), + DECL_API("GetVolumeInformationW", GetVolumeInformationW_fwd), + DECL_API("IsBadStringPtrW", IsBadStringPtrW_fwd), + DECL_API("LCMapStringW", LCMapStringW_fwd), + DECL_API("LoadLibraryExW", LoadLibraryExW_fwd), + DECL_API("LoadLibraryW", LoadLibraryW_fwd), + DECL_API("OpenEventW", OpenEventW_fwd), + DECL_API("OpenFileMappingW", OpenFileMappingW_fwd), + DECL_API("OpenMutexW", OpenMutexW_fwd), + DECL_API("OpenSemaphoreW", OpenSemaphoreW_fwd), + DECL_API("OpenWaitableTimerW", OpenWaitableTimerW_fwd), + DECL_API("PeekConsoleInputW", PeekConsoleInputW_fwd), + DECL_API("QueryDosDeviceW", QueryDosDeviceW_fwd), + DECL_API("ReadConsoleInputW", ReadConsoleInputW_fwd), + DECL_API("ReadConsoleOutputCharacterW", ReadConsoleOutputCharacterW_fwd), + DECL_API("ReadConsoleOutputW", ReadConsoleOutputW_fwd), + DECL_API("ReadConsoleW", ReadConsoleW_fwd), + DECL_API("ScrollConsoleScreenBufferW", ScrollConsoleScreenBufferW_fwd), + DECL_API("SetCalendarInfoW", SetCalendarInfoW_fwd), + DECL_API("SetComputerNameW", SetComputerNameW_fwd), + DECL_API("SetDefaultCommConfigW", SetDefaultCommConfigW_fwd), + DECL_API("SetEnvironmentVariableW", SetEnvironmentVariableW_fwd), + DECL_API("SetLocaleInfoW", SetLocaleInfoW_fwd), + DECL_API("SetVolumeLabelW", SetVolumeLabelW_fwd), + DECL_API("WaitNamedPipeW", WaitNamedPipeW_fwd), + DECL_API("WriteConsoleInputW", WriteConsoleInputW_fwd), + DECL_API("WriteConsoleOutputCharacterW", WriteConsoleOutputCharacterW_fwd), + DECL_API("WriteConsoleOutputW", WriteConsoleOutputW_fwd), + DECL_API("WriteConsoleW", WriteConsoleW_fwd), + DECL_API("WritePrivateProfileSectionW", WritePrivateProfileSectionW_fwd), + DECL_API("WritePrivateProfileStringW", WritePrivateProfileStringW_fwd), + DECL_API("WritePrivateProfileStructW", WritePrivateProfileStructW_fwd), + DECL_API("WriteProfileSectionW", WriteProfileSectionW_fwd), + DECL_API("WriteProfileStringW", WriteProfileStringW_fwd), + DECL_API("lstrcmpW", lstrcmpW_fwd), + DECL_API("lstrcmpiW", lstrcmpiW_fwd), +/*** AUTOGENERATED APILIST NAMED EXPORTS END ***/ +}; + +#if 0 +static const apilib_unnamed_api kernel32_ordinal_apis[] = +{ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS BEGIN ***/ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS END ***/ +}; +#endif + +const apilib_api_table apitable_kernel32 = DECL_TAB("KERNEL32.DLL", kernel32_named_apis, 0 /*kernel32_ordinal_apis*/); diff --git a/apilibs/kexbasen/kernel32/_kernel32_apilist.h b/apilibs/kexbasen/kernel32/_kernel32_apilist.h new file mode 100644 index 0000000..60cd8a1 --- /dev/null +++ b/apilibs/kexbasen/kernel32/_kernel32_apilist.h @@ -0,0 +1,118 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#ifndef _KERNEL32_APILIST_H +#define _KERNEL32_APILIST_H + +#include "auxdecl.h" +#include "kexcoresdk.h" + +BOOL init_kernel32(); +extern const apilib_api_table apitable_kernel32; + +/*** AUTOGENERATED APILIST DECLARATIONS BEGIN ***/ +FWDPROC BuildCommDCBAndTimeoutsW_fwd; +FWDPROC BuildCommDCBW_fwd; +FWDPROC CallNamedPipeW_fwd; +FWDPROC CommConfigDialogW_fwd; +FWDPROC CompareStringW_fwd; +FWDPROC CreateEventW_fwd; +FWDPROC CreateFileMappingW_fwd; +FWDPROC CreateMailslotW_fwd; +FWDPROC CreateMutexW_fwd; +FWDPROC CreateProcessW_fwd; +FWDPROC CreateSemaphoreW_fwd; +FWDPROC CreateWaitableTimerW_fwd; +FWDPROC EnumCalendarInfoExW_fwd; +FWDPROC EnumCalendarInfoW_fwd; +FWDPROC EnumDateFormatsExW_fwd; +FWDPROC EnumDateFormatsW_fwd; +FWDPROC EnumSystemCodePagesW_fwd; +FWDPROC EnumSystemLocalesW_fwd; +FWDPROC EnumTimeFormatsW_fwd; +FWDPROC ExpandEnvironmentStringsW_fwd; +FWDPROC FatalAppExitW_fwd; +FWDPROC FillConsoleOutputCharacterW_fwd; +FWDPROC FormatMessageW_fwd; +FWDPROC GetAtomNameW_fwd; +FWDPROC GetCPInfoExW_fwd; +FWDPROC GetCalendarInfoW_fwd; +FWDPROC GetComputerNameW_fwd; +FWDPROC GetConsoleTitleW_fwd; +FWDPROC GetCurrencyFormatW_fwd; +FWDPROC GetDateFormatW_fwd; +FWDPROC GetDriveTypeW_fwd; +FWDPROC GetEnvironmentVariableW_fwd; +FWDPROC GetLocaleInfoW_fwd; +FWDPROC GetLogicalDriveStringsW_fwd; +FWDPROC GetModuleFileNameW_fwd; +FWDPROC GetModuleHandleW_fwd; +FWDPROC GetNamedPipeHandleStateW_fwd; +FWDPROC GetNumberFormatW_fwd; +FWDPROC GetPrivateProfileIntW_fwd; +FWDPROC GetPrivateProfileSectionNamesW_fwd; +FWDPROC GetPrivateProfileSectionW_fwd; +FWDPROC GetPrivateProfileStringW_fwd; +FWDPROC GetPrivateProfileStructW_fwd; +FWDPROC GetProfileIntW_fwd; +FWDPROC GetProfileSectionW_fwd; +FWDPROC GetProfileStringW_fwd; +FWDPROC GetStringTypeExW_fwd; +FWDPROC GetStringTypeW_fwd; +FWDPROC GetTimeFormatW_fwd; +FWDPROC GetVolumeInformationW_fwd; +FWDPROC IsBadStringPtrW_fwd; +FWDPROC LCMapStringW_fwd; +FWDPROC LoadLibraryExW_fwd; +FWDPROC LoadLibraryW_fwd; +FWDPROC OpenEventW_fwd; +FWDPROC OpenFileMappingW_fwd; +FWDPROC OpenMutexW_fwd; +FWDPROC OpenSemaphoreW_fwd; +FWDPROC OpenWaitableTimerW_fwd; +FWDPROC PeekConsoleInputW_fwd; +FWDPROC QueryDosDeviceW_fwd; +FWDPROC ReadConsoleInputW_fwd; +FWDPROC ReadConsoleOutputCharacterW_fwd; +FWDPROC ReadConsoleOutputW_fwd; +FWDPROC ReadConsoleW_fwd; +FWDPROC ScrollConsoleScreenBufferW_fwd; +FWDPROC SetCalendarInfoW_fwd; +FWDPROC SetComputerNameW_fwd; +FWDPROC SetDefaultCommConfigW_fwd; +FWDPROC SetEnvironmentVariableW_fwd; +FWDPROC SetLocaleInfoW_fwd; +FWDPROC SetVolumeLabelW_fwd; +FWDPROC WaitNamedPipeW_fwd; +FWDPROC WriteConsoleInputW_fwd; +FWDPROC WriteConsoleOutputCharacterW_fwd; +FWDPROC WriteConsoleOutputW_fwd; +FWDPROC WriteConsoleW_fwd; +FWDPROC WritePrivateProfileSectionW_fwd; +FWDPROC WritePrivateProfileStringW_fwd; +FWDPROC WritePrivateProfileStructW_fwd; +FWDPROC WriteProfileSectionW_fwd; +FWDPROC WriteProfileStringW_fwd; +FWDPROC lstrcmpW_fwd; +FWDPROC lstrcmpiW_fwd; +/*** AUTOGENERATED APILIST DECLARATIONS END ***/ + +#endif diff --git a/apilibs/kexbasen/kernel32/unikernel32.c b/apilibs/kexbasen/kernel32/unikernel32.c new file mode 100644 index 0000000..8a4329b --- /dev/null +++ b/apilibs/kexbasen/kernel32/unikernel32.c @@ -0,0 +1,107 @@ +/* + * KernelEx + * Copyright (C) 2006-2008, 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. + * + */ + +#include "unifwd.h" + +FORWARD_TO_UNICOWS(BuildCommDCBAndTimeoutsW); +FORWARD_TO_UNICOWS(BuildCommDCBW); +FORWARD_TO_UNICOWS(CallNamedPipeW); +FORWARD_TO_UNICOWS(CommConfigDialogW); +FORWARD_TO_UNICOWS(CompareStringW); +FORWARD_TO_UNICOWS(CreateEventW); +FORWARD_TO_UNICOWS(CreateFileMappingW); +FORWARD_TO_UNICOWS(CreateMailslotW); +FORWARD_TO_UNICOWS(CreateMutexW); +FORWARD_TO_UNICOWS(CreateProcessW); +FORWARD_TO_UNICOWS(CreateSemaphoreW); +FORWARD_TO_UNICOWS(CreateWaitableTimerW); +FORWARD_TO_UNICOWS(EnumCalendarInfoExW); +FORWARD_TO_UNICOWS(EnumCalendarInfoW); +FORWARD_TO_UNICOWS(EnumDateFormatsExW); +FORWARD_TO_UNICOWS(EnumDateFormatsW); +FORWARD_TO_UNICOWS(EnumSystemCodePagesW); +FORWARD_TO_UNICOWS(EnumSystemLocalesW); +FORWARD_TO_UNICOWS(EnumTimeFormatsW); +FORWARD_TO_UNICOWS(ExpandEnvironmentStringsW); +FORWARD_TO_UNICOWS(FatalAppExitW); +FORWARD_TO_UNICOWS(FillConsoleOutputCharacterW); +FORWARD_TO_UNICOWS(FormatMessageW); +FORWARD_TO_UNICOWS(GetAtomNameW); +FORWARD_TO_UNICOWS(GetCPInfoExW); +FORWARD_TO_UNICOWS(GetCalendarInfoW); +FORWARD_TO_UNICOWS(GetComputerNameW); +FORWARD_TO_UNICOWS(GetConsoleTitleW); +FORWARD_TO_UNICOWS(GetCurrencyFormatW); +FORWARD_TO_UNICOWS(GetDateFormatW); +FORWARD_TO_UNICOWS(GetDriveTypeW); +FORWARD_TO_UNICOWS(GetEnvironmentVariableW); +FORWARD_TO_UNICOWS(GetLocaleInfoW); +FORWARD_TO_UNICOWS(GetLogicalDriveStringsW); +FORWARD_TO_UNICOWS(GetModuleFileNameW); +FORWARD_TO_UNICOWS(GetModuleHandleW); +FORWARD_TO_UNICOWS(GetNamedPipeHandleStateW); +FORWARD_TO_UNICOWS(GetNumberFormatW); +FORWARD_TO_UNICOWS(GetPrivateProfileIntW); +FORWARD_TO_UNICOWS(GetPrivateProfileSectionNamesW); +FORWARD_TO_UNICOWS(GetPrivateProfileSectionW); +FORWARD_TO_UNICOWS(GetPrivateProfileStringW); +FORWARD_TO_UNICOWS(GetPrivateProfileStructW); +FORWARD_TO_UNICOWS(GetProfileIntW); +FORWARD_TO_UNICOWS(GetProfileSectionW); +FORWARD_TO_UNICOWS(GetProfileStringW); +FORWARD_TO_UNICOWS(GetStringTypeExW); +FORWARD_TO_UNICOWS(GetStringTypeW); +FORWARD_TO_UNICOWS(GetTimeFormatW); +FORWARD_TO_UNICOWS(GetVolumeInformationW); +FORWARD_TO_UNICOWS(IsBadStringPtrW); +FORWARD_TO_UNICOWS(LCMapStringW); +FORWARD_TO_UNICOWS(LoadLibraryExW); +FORWARD_TO_UNICOWS(LoadLibraryW); +FORWARD_TO_UNICOWS(OpenEventW); +FORWARD_TO_UNICOWS(OpenFileMappingW); +FORWARD_TO_UNICOWS(OpenMutexW); +FORWARD_TO_UNICOWS(OpenSemaphoreW); +FORWARD_TO_UNICOWS(OpenWaitableTimerW); +FORWARD_TO_UNICOWS(PeekConsoleInputW); +FORWARD_TO_UNICOWS(QueryDosDeviceW); +FORWARD_TO_UNICOWS(ReadConsoleInputW); +FORWARD_TO_UNICOWS(ReadConsoleOutputCharacterW); +FORWARD_TO_UNICOWS(ReadConsoleOutputW); +FORWARD_TO_UNICOWS(ReadConsoleW); +FORWARD_TO_UNICOWS(ScrollConsoleScreenBufferW); +FORWARD_TO_UNICOWS(SetCalendarInfoW); +FORWARD_TO_UNICOWS(SetComputerNameW); +FORWARD_TO_UNICOWS(SetDefaultCommConfigW); +FORWARD_TO_UNICOWS(SetEnvironmentVariableW); +FORWARD_TO_UNICOWS(SetLocaleInfoW); +FORWARD_TO_UNICOWS(SetVolumeLabelW); +FORWARD_TO_UNICOWS(WaitNamedPipeW); +FORWARD_TO_UNICOWS(WriteConsoleInputW); +FORWARD_TO_UNICOWS(WriteConsoleOutputCharacterW); +FORWARD_TO_UNICOWS(WriteConsoleOutputW); +FORWARD_TO_UNICOWS(WriteConsoleW); +FORWARD_TO_UNICOWS(WritePrivateProfileSectionW); +FORWARD_TO_UNICOWS(WritePrivateProfileStringW); +FORWARD_TO_UNICOWS(WritePrivateProfileStructW); +FORWARD_TO_UNICOWS(WriteProfileSectionW); +FORWARD_TO_UNICOWS(WriteProfileStringW); +FORWARD_TO_UNICOWS(lstrcmpW); +FORWARD_TO_UNICOWS(lstrcmpiW); diff --git a/apilibs/kexbasen/kexbasen.def b/apilibs/kexbasen/kexbasen.def new file mode 100644 index 0000000..38e8bac --- /dev/null +++ b/apilibs/kexbasen/kexbasen.def @@ -0,0 +1 @@ +LIBRARY kexbasen.dll BASE=0x7D000000 \ No newline at end of file diff --git a/apilibs/kexbasen/kexbasen.dsp b/apilibs/kexbasen/kexbasen.dsp new file mode 100644 index 0000000..1b9dc49 --- /dev/null +++ b/apilibs/kexbasen/kexbasen.dsp @@ -0,0 +1,295 @@ +# Microsoft Developer Studio Project File - Name="KernelEx Base NonShared" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=KernelEx Base NonShared - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "kexbasen.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "kexbasen.mak" CFG="KernelEx Base NonShared - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "KernelEx Base NonShared - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "KernelEx Base NonShared - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "KernelEx Base NonShared - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "KEXBASEN_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /O2 /I "." /I "../../common" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D _WIN32_WINNT=0x0500 /YX /FD /TP /GF /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x415 /d "NDEBUG" +# ADD RSC /l 0x415 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shlwapi.lib shell32.lib ../../common/KernelEx.lib ../../kexcrt/kexcrt.lib libc.lib /nologo /dll /map /machine:I386 /nodefaultlib /OPT:NOWIN98 +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "KernelEx Base NonShared - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "KEXBASEN_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /Zi /Od /I "." /I "../../common" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D _WIN32_WINNT=0x0500 /YX /FD /TP /GZ /GF /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x415 /d "_DEBUG" +# ADD RSC /l 0x415 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shlwapi.lib shell32.lib ../../common/KernelEx.lib ../../kexcrt/kexcrt.lib libc.lib /nologo /dll /map /debug /machine:I386 /nodefaultlib /pdbtype:sept /OPT:NOWIN98 +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "KernelEx Base NonShared - Win32 Release" +# Name "KernelEx Base NonShared - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Group "kernel32" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\kernel32\_kernel32_apilist.c +# End Source File +# Begin Source File + +SOURCE=.\kernel32\_kernel32_apilist.h +# End Source File +# Begin Source File + +SOURCE=.\kernel32\unikernel32.c +# End Source File +# End Group +# Begin Group "user32" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\user32\_user32_apilist.c +# End Source File +# Begin Source File + +SOURCE=.\user32\_user32_apilist.h +# End Source File +# Begin Source File + +SOURCE=.\user32\uniuser32.c +# End Source File +# End Group +# Begin Group "gdi32" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\gdi32\_gdi32_apilist.c +# End Source File +# Begin Source File + +SOURCE=.\gdi32\_gdi32_apilist.h +# End Source File +# Begin Source File + +SOURCE=.\gdi32\UberGDI.c +# End Source File +# Begin Source File + +SOURCE=.\gdi32\unigdi32.c +# End Source File +# End Group +# Begin Group "advapi32" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\advapi32\_advapi32_apilist.c +# End Source File +# Begin Source File + +SOURCE=.\advapi32\_advapi32_apilist.h +# End Source File +# Begin Source File + +SOURCE=.\advapi32\uniadvapi32.c +# End Source File +# End Group +# Begin Group "comdlg32" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\comdlg32\_comdlg32_apilist.c +# End Source File +# Begin Source File + +SOURCE=.\comdlg32\_comdlg32_apilist.h +# End Source File +# Begin Source File + +SOURCE=.\comdlg32\unicomdlg32.c +# End Source File +# End Group +# Begin Group "shell32" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\shell32\_shell32_apilist.c +# End Source File +# Begin Source File + +SOURCE=.\shell32\_shell32_apilist.h +# End Source File +# Begin Source File + +SOURCE=.\shell32\auxshlguid.h +# End Source File +# Begin Source File + +SOURCE=.\shell32\pidl.h +# End Source File +# Begin Source File + +SOURCE=.\shell32\SHGetFolderLocation.c +# End Source File +# Begin Source File + +SOURCE=.\shell32\SHGetFolderPath.c +# End Source File +# Begin Source File + +SOURCE=.\shell32\unishell32.c +# End Source File +# End Group +# Begin Source File + +SOURCE=.\common.c +# End Source File +# Begin Source File + +SOURCE=.\kexbasen.def + +!IF "$(CFG)" == "KernelEx Base NonShared - Win32 Release" + +# Begin Custom Build +OutDir=.\Release +ProjDir=. +InputPath=.\kexbasen.def + +BuildCmds= \ + link /LIB /NOLOGO /MACHINE:IX86 /DEF:$(ProjDir)\shell32ord.def /OUT:$(OutDir)\shell32ord.lib + +"$(OutDir)\shell32ord.lib" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(OutDir)\shell32ord.exp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) +# End Custom Build + +!ELSEIF "$(CFG)" == "KernelEx Base NonShared - Win32 Debug" + +# Begin Custom Build +OutDir=.\Debug +ProjDir=. +InputPath=.\kexbasen.def + +BuildCmds= \ + link /LIB /NOLOGO /MACHINE:IX86 /DEF:$(ProjDir)\shell32ord.def /OUT:$(OutDir)\shell32ord.lib + +"$(OutDir)\shell32ord.lib" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(OutDir)\shell32ord.exp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) +# End Custom Build + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\main.c +# End Source File +# Begin Source File + +SOURCE=.\shell32ord.def +# PROP Exclude_From_Build 1 +# End Source File +# Begin Source File + +SOURCE=.\unifwd.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\auxdecl.h +# End Source File +# Begin Source File + +SOURCE=.\common.h +# End Source File +# Begin Source File + +SOURCE=.\unifwd.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# Begin Source File + +SOURCE=.\kexbasen.rc +# End Source File +# End Group +# End Target +# End Project diff --git a/apilibs/kexbasen/kexbasen.rc b/apilibs/kexbasen/kexbasen.rc new file mode 100644 index 0000000..1c374ea --- /dev/null +++ b/apilibs/kexbasen/kexbasen.rc @@ -0,0 +1,109 @@ +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// Polish resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_PLK) +#ifdef _WIN32 +LANGUAGE LANG_POLISH, SUBLANG_DEFAULT +#pragma code_page(1250) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +#ifndef _MAC +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 4,0,1,0 + PRODUCTVERSION 4,0,1,0 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004b0" + BEGIN + VALUE "Comments", "\0" + VALUE "CompanyName", "Xeno86\0" + VALUE "FileDescription", "KernelEx Base Non-shared Api Library\0" + VALUE "FileVersion", "4, 0, 1, 0\0" + VALUE "InternalName", "kexbasen\0" + VALUE "LegalCopyright", "Copyright © 2009, Xeno86\0" + VALUE "LegalTrademarks", "\0" + VALUE "OriginalFilename", "kexbasen.dll\0" + VALUE "PrivateBuild", "\0" + VALUE "ProductName", "KernelEx\0" + VALUE "ProductVersion", "4, 0, 1, 0\0" + VALUE "SpecialBuild", "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0, 1200 + END +END + +#endif // !_MAC + +#endif // Polish resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/apilibs/kexbasen/main.c b/apilibs/kexbasen/main.c new file mode 100644 index 0000000..4bf67a9 --- /dev/null +++ b/apilibs/kexbasen/main.c @@ -0,0 +1,77 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" +#include "unifwd.h" +#include "kexcoresdk.h" +#include "kernel32/_kernel32_apilist.h" +#include "gdi32/_gdi32_apilist.h" +#include "user32/_user32_apilist.h" +#include "advapi32/_advapi32_apilist.h" +#include "comdlg32/_comdlg32_apilist.h" +#include "shell32/_shell32_apilist.h" +//#include "/__apilist.h" + +static apilib_api_table api_table[7]; + +static void fill_apitable() +{ + api_table[0] = apitable_kernel32; + api_table[1] = apitable_gdi32; + api_table[2] = apitable_user32; + api_table[3] = apitable_advapi32; + api_table[4] = apitable_comdlg32; + api_table[5] = apitable_shell32; + //last entry is null terminator +} + +extern "C" +__declspec(dllexport) +const apilib_api_table* get_api_table() +{ + fill_apitable(); + //check if unicows is available + if (!unifwd_init()) + return NULL; + return api_table; +} + +BOOL init() +{ + return common_init() && init_kernel32() && init_gdi32() && init_user32() && init_advapi32() && init_comdlg32() && init_shell32(); +} + +BOOL APIENTRY DllMain(HINSTANCE instance, DWORD reason, BOOL load_static) +{ + switch (reason) + { + case DLL_PROCESS_ATTACH: +// kexDebugPrint("KernelEx Base Non-shared library reporting in action!\n"); + DisableThreadLibraryCalls(instance); + if (!init()) + return FALSE; + break; + case DLL_PROCESS_DETACH: +// kexDebugPrint("KernelEx Base Non-shared library signing off!\n"); + break; + } + return TRUE; +} diff --git a/apilibs/kexbasen/resource.h b/apilibs/kexbasen/resource.h new file mode 100644 index 0000000..d9175c8 --- /dev/null +++ b/apilibs/kexbasen/resource.h @@ -0,0 +1,15 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by kexbasen.rc +// + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1000 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/apilibs/kexbasen/shell32/SHGetFolderLocation.c b/apilibs/kexbasen/shell32/SHGetFolderLocation.c new file mode 100644 index 0000000..cf0cb02 --- /dev/null +++ b/apilibs/kexbasen/shell32/SHGetFolderLocation.c @@ -0,0 +1,307 @@ +/* + * Path Functions + * + * Copyright 1998, 1999, 2000 Juergen Schmied + * Copyright 2004 Juan Lang + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + */ + +#ifdef _MSC_VER +#pragma warning(disable:4002) +#define TRACE() ((void)0) +#define TRACE_() ((void)0) +#define WARN() ((void)0) +#else +#define TRACE(...) do {} while(0) +#define TRACE_(x) TRACE +#define WARN(...) do {} while(0) +#endif + +#define _WIN32_IE 0x0500 + +#include +#include +#include "auxshlguid.h" +#include "pidl.h" +#include +#include "common.h" +#include "_shell32_apilist.h" +#include "auxdecl.h" + +EXTERN_C HRESULT WINAPI SHILCreateFromPathA(LPCSTR path, LPITEMIDLIST *ppidl, DWORD *attributes); /* ORDINAL 28 */ +EXTERN_C LPVOID WINAPI SHAlloc(DWORD len); /* ORDINAL 196 */ +EXTERN_C void WINAPI SHFree(LPVOID pv); /* ORDINAL 195 */ +EXTERN_C LPITEMIDLIST WINAPI ILGetNext(LPCITEMIDLIST pidl); /* ORDINAL 153 */ +EXTERN_C LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2); /* ORDINAL 25 */ + +/************************************************************************** + * + * internal functions + * + * ### 1. section creating pidls ### + * + ************************************************************************* + */ +LPITEMIDLIST _ILAlloc(PIDLTYPE type, unsigned int size) +{ + LPITEMIDLIST pidlOut = NULL; + + pidlOut = (LPITEMIDLIST) SHAlloc(size + 5); + if(pidlOut) + { + LPPIDLDATA pData; + LPITEMIDLIST pidlNext; + + ZeroMemory(pidlOut, size + 5); + pidlOut->mkid.cb = size + 3; + + pData = _ILGetDataPointer(pidlOut); + if (pData) + pData->type = type; + + pidlNext = ILGetNext(pidlOut); + if (pidlNext) + pidlNext->mkid.cb = 0x00; + TRACE("-- (pidl=%p, size=%u)\n", pidlOut, size); + } + + return pidlOut; +} + +LPITEMIDLIST _ILCreateDesktop() +{ + LPITEMIDLIST ret; + + TRACE("()\n"); + ret = (LPITEMIDLIST) SHAlloc(2); + if (ret) + ret->mkid.cb = 0; + return ret; +} + +LPITEMIDLIST _ILCreateMyComputer() +{ + TRACE("()\n"); + return _ILCreateGuid(PT_GUID, &CLSID_MyComputer); +} + +LPITEMIDLIST _ILCreateMyDocuments() +{ + TRACE("()\n"); + return _ILCreateGuid(PT_GUID, &CLSID_MyDocuments); +} + +LPITEMIDLIST _ILCreateIExplore() +{ + TRACE("()\n"); + return _ILCreateGuid(PT_GUID, &CLSID_Internet); +} + +LPITEMIDLIST _ILCreateControlPanel() +{ + LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL; + + TRACE("()\n"); + if (parent) + { + LPITEMIDLIST cpl = _ILCreateGuid(PT_SHELLEXT, &CLSID_ControlPanel); + + if (cpl) + { + ret = ILCombine(parent, cpl); + SHFree(cpl); + } + SHFree(parent); + } + return ret; +} + +LPITEMIDLIST _ILCreatePrinters() +{ + LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL; + + TRACE("()\n"); + if (parent) + { + LPITEMIDLIST printers = _ILCreateGuid(PT_YAGUID, &CLSID_Printers); + + if (printers) + { + ret = ILCombine(parent, printers); + SHFree(printers); + } + SHFree(parent); + } + return ret; +} + +LPITEMIDLIST _ILCreateNetwork() +{ + TRACE("()\n"); + return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces); +} + +LPITEMIDLIST _ILCreateBitBucket() +{ + TRACE("()\n"); + return _ILCreateGuid(PT_GUID, &CLSID_RecycleBin); +} + +LPITEMIDLIST _ILCreateGuid(PIDLTYPE type, const IID *guid) +{ + LPITEMIDLIST pidlOut; + + if (type == PT_SHELLEXT || type == PT_GUID || type == PT_YAGUID) + { + pidlOut = _ILAlloc(type, sizeof(GUIDStruct)); + if (pidlOut) + { + LPPIDLDATA pData = _ILGetDataPointer(pidlOut); + + memcpy(&(pData->u.guid.guid), guid, sizeof(GUID)); + TRACE("-- create GUID-pidl %s\n", + debugstr_guid(&(pData->u.guid.guid))); + } + } + else + { + WARN("%d: invalid type for GUID\n", type); + pidlOut = NULL; + } + return pidlOut; +} + +/************************************************************************** + * + * ### 4. getting pointers to parts of pidls ### + * + ************************************************************************** + * _ILGetDataPointer() + */ +LPPIDLDATA _ILGetDataPointer(LPCITEMIDLIST pidl) +{ + if(pidl && pidl->mkid.cb != 0x00) + return (LPPIDLDATA) &(pidl->mkid.abID); + return NULL; +} + +/************************************************************************* + * SHGetFolderLocation [SHELL32.@] + * + * Gets the folder locations from the registry and creates a pidl. + * + * PARAMS + * hwndOwner [I] + * nFolder [I] CSIDL_xxxxx + * hToken [I] token representing user, or NULL for current user, or -1 for + * default user + * dwReserved [I] must be zero + * ppidl [O] PIDL of a special folder + * + * RETURNS + * Success: S_OK + * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG + * + * NOTES + * Creates missing reg keys and directories. + * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return + * virtual folders that are handled here. + */ +/* MAKE_EXPORT SHGetFolderLocation_new=SHGetFolderLocation */ +HRESULT WINAPI SHGetFolderLocation_new( + HWND hwndOwner, + int nFolder, + HANDLE hToken, + DWORD dwReserved, + LPVOID *_ppidl) +{ + LPITEMIDLIST *ppidl = (LPITEMIDLIST*) _ppidl; + HRESULT hr = E_INVALIDARG; + + TRACE("%p 0x%08x %p 0x%08lx %p\n", + hwndOwner, nFolder, hToken, dwReserved, ppidl); + + if (!ppidl) + return E_INVALIDARG; + if (dwReserved) + return E_INVALIDARG; + + /* The virtual folders' locations are not user-dependent */ + *ppidl = NULL; + switch (nFolder) + { + case CSIDL_DESKTOP: + *ppidl = _ILCreateDesktop(); + break; + + case CSIDL_PERSONAL: + *ppidl = _ILCreateMyDocuments(); + break; + + case CSIDL_INTERNET: + *ppidl = _ILCreateIExplore(); + break; + + case CSIDL_CONTROLS: + *ppidl = _ILCreateControlPanel(); + break; + + case CSIDL_PRINTERS: + *ppidl = _ILCreatePrinters(); + break; + + case CSIDL_BITBUCKET: + *ppidl = _ILCreateBitBucket(); + break; + + case CSIDL_DRIVES: + *ppidl = _ILCreateMyComputer(); + break; + + case CSIDL_NETWORK: + *ppidl = _ILCreateNetwork(); + break; + + default: + { + char szPath[MAX_PATH]; + + hr = SHGetFolderPathA_new(hwndOwner, nFolder, hToken, + SHGFP_TYPE_CURRENT, szPath); + if (SUCCEEDED(hr)) + { + DWORD attributes=0; + + TRACE("Value=%s\n", debugstr_w(szPath)); + hr = SHILCreateFromPathA(szPath, ppidl, &attributes); + } + else if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) + { + /* unlike SHGetFolderPath, SHGetFolderLocation in shell32 + * version 6.0 returns E_FAIL for nonexistent paths + */ + hr = E_FAIL; + } + } + } + if(*ppidl) + hr = NOERROR; + + TRACE("-- (new pidl %p)\n",*ppidl); + return hr; +} + diff --git a/apilibs/kexbasen/shell32/SHGetFolderPath.c b/apilibs/kexbasen/shell32/SHGetFolderPath.c new file mode 100644 index 0000000..520acfd --- /dev/null +++ b/apilibs/kexbasen/shell32/SHGetFolderPath.c @@ -0,0 +1,80 @@ +/* + * 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. + * + */ + +#include +#include "kexcoresdk.h" + +typedef HRESULT (WINAPI *SHGetFolderPathA_t)(HWND, int, HANDLE, DWORD, LPSTR); +typedef HRESULT (WINAPI *SHGetFolderPathW_t)(HWND, int, HANDLE, DWORD, LPWSTR); + +static SHGetFolderPathA_t SHGetFolderPathA_pfn = (SHGetFolderPathA_t)-1; +static SHGetFolderPathW_t SHGetFolderPathW_pfn = (SHGetFolderPathW_t)-1; + +BOOL init_shfolder(void) +{ + DWORD lasterr = GetLastError(); + HMODULE hShell32 = GetModuleHandle("SHELL32.DLL"); + PROC pfn = kexGetProcAddress(hShell32, "SHGetFolderPathA"); + if (pfn) + SHGetFolderPathA_pfn = (SHGetFolderPathA_t) pfn; + pfn = kexGetProcAddress(hShell32, "SHGetFolderPathW"); + if (pfn) + SHGetFolderPathW_pfn = (SHGetFolderPathW_t) pfn; + SetLastError(lasterr); + return TRUE; +} + +static PROC LoadShfolderProc(const char* proc) +{ + static const char ShfolderFn[] = "SHFOLDER.DLL"; + static HMODULE hShfolder; + PROC ret = NULL; + DWORD lasterr = GetLastError(); + + if (!hShfolder) + { + hShfolder = GetModuleHandle(ShfolderFn); + if (!hShfolder) hShfolder = LoadLibrary(ShfolderFn); + if (hShfolder) ret = kexGetProcAddress(hShfolder, proc); + } + SetLastError(lasterr); + return ret; +} + +/* MAKE_EXPORT SHGetFolderPathA_new=SHGetFolderPathA */ +HRESULT WINAPI SHGetFolderPathA_new(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPSTR pszPath) +{ + if (SHGetFolderPathA_pfn == (void*)-1) + SHGetFolderPathA_pfn = (SHGetFolderPathA_t) LoadShfolderProc("SHGetFolderPathA"); + if (SHGetFolderPathA_pfn == NULL) + return E_NOTIMPL; + return SHGetFolderPathA_pfn(hwndOwner, nFolder, hToken, dwFlags, pszPath); +} + +/* MAKE_EXPORT SHGetFolderPathW_new=SHGetFolderPathW */ +HRESULT WINAPI SHGetFolderPathW_new(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath) +{ + if (SHGetFolderPathW_pfn == (void*)-1) + SHGetFolderPathW_pfn = (SHGetFolderPathW_t) LoadShfolderProc("SHGetFolderPathW"); + if (SHGetFolderPathW_pfn == NULL) + return E_NOTIMPL; + return SHGetFolderPathW_pfn(hwndOwner, nFolder, hToken, dwFlags, pszPath); +} diff --git a/apilibs/kexbasen/shell32/_shell32_apilist.c b/apilibs/kexbasen/shell32/_shell32_apilist.c new file mode 100644 index 0000000..4f210fa --- /dev/null +++ b/apilibs/kexbasen/shell32/_shell32_apilist.c @@ -0,0 +1,62 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" +#include "kexcoresdk.h" +#include "_shell32_apilist.h" + +extern BOOL init_shfolder(void); + +BOOL init_shell32() +{ + return init_shfolder(); +} + +static const apilib_named_api shell32_named_apis[] = +{ +/*** AUTOGENERATED APILIST NAMED EXPORTS BEGIN ***/ + DECL_API("DragQueryFileW", DragQueryFileW_fwd), + DECL_API("ExtractIconExW", ExtractIconExW_fwd), + DECL_API("ExtractIconW", ExtractIconW_fwd), + DECL_API("FindExecutableW", FindExecutableW_fwd), + DECL_API("SHBrowseForFolderW", SHBrowseForFolderW_fwd), + DECL_API("SHFileOperationW", SHFileOperationW_fwd), + DECL_API("SHGetFileInfoW", SHGetFileInfoW_fwd), + DECL_API("SHGetFolderLocation", SHGetFolderLocation_new), + DECL_API("SHGetFolderPathA", SHGetFolderPathA_new), + DECL_API("SHGetFolderPathW", SHGetFolderPathW_new), + DECL_API("SHGetNewLinkInfoW", SHGetNewLinkInfoW_fwd), + DECL_API("ShellAboutW", ShellAboutW_fwd), + DECL_API("ShellExecuteExW", ShellExecuteExW_fwd), + DECL_API("ShellExecuteW", ShellExecuteW_fwd), + DECL_API("Shell_NotifyIconW", Shell_NotifyIconW_fwd), +/*** AUTOGENERATED APILIST NAMED EXPORTS END ***/ +}; + +#if 0 +static const apilib_unnamed_api shell32_ordinal_apis[] = +{ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS BEGIN ***/ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS END ***/ +}; +#endif + +const apilib_api_table apitable_shell32 = DECL_TAB("SHELL32.DLL", shell32_named_apis, 0 /*shell32_ordinal_apis*/); diff --git a/apilibs/kexbasen/shell32/_shell32_apilist.h b/apilibs/kexbasen/shell32/_shell32_apilist.h new file mode 100644 index 0000000..8bc4330 --- /dev/null +++ b/apilibs/kexbasen/shell32/_shell32_apilist.h @@ -0,0 +1,49 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#ifndef _SHELL32_APILIST_H +#define _SHELL32_APILIST_H + +#include "auxdecl.h" +#include "kexcoresdk.h" + +BOOL init_shell32(); +extern const apilib_api_table apitable_shell32; + +/*** AUTOGENERATED APILIST DECLARATIONS BEGIN ***/ +HRESULT WINAPI SHGetFolderLocation_new(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwReserved, LPVOID *_ppidl); +HRESULT WINAPI SHGetFolderPathA_new(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPSTR pszPath); +HRESULT WINAPI SHGetFolderPathW_new(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath); +FWDPROC DragQueryFileW_fwd; +FWDPROC ExtractIconExW_fwd; +FWDPROC ExtractIconW_fwd; +FWDPROC FindExecutableW_fwd; +FWDPROC SHBrowseForFolderW_fwd; +FWDPROC Shell_NotifyIconW_fwd; +FWDPROC ShellAboutW_fwd; +FWDPROC ShellExecuteExW_fwd; +FWDPROC ShellExecuteW_fwd; +FWDPROC SHFileOperationW_fwd; +FWDPROC SHGetFileInfoW_fwd; +FWDPROC SHGetNewLinkInfoW_fwd; +/*** AUTOGENERATED APILIST DECLARATIONS END ***/ + +#endif diff --git a/apilibs/kexbasen/shell32/auxshlguid.h b/apilibs/kexbasen/shell32/auxshlguid.h new file mode 100644 index 0000000..02839bc --- /dev/null +++ b/apilibs/kexbasen/shell32/auxshlguid.h @@ -0,0 +1,24 @@ +#ifndef __AUX_SHLGUID_H +#define __AUX_SHLGUID_H + +#ifdef DEFINE_GUID +#undef DEFINE_GUID +#endif + +#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ + const GUID name \ + = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } + +DEFINE_GUID(CLSID_NetworkPlaces, 0x208D2C60, 0x3AEA, 0x1069, 0xA2, 0xD7, 0x08, 0x00, 0x2B, 0x30, 0x30, 0x9D); +DEFINE_GUID(CLSID_NetworkDomain, 0x46e06680, 0x4bf0, 0x11d1, 0x83, 0xee, 0x00, 0xa0, 0xc9, 0x0d, 0xc8, 0x49); +DEFINE_GUID(CLSID_NetworkServer, 0xc0542a90, 0x4bf0, 0x11d1, 0x83, 0xee, 0x00, 0xa0, 0xc9, 0x0d, 0xc8, 0x49); +DEFINE_GUID(CLSID_NetworkShare, 0x54a754c0, 0x4bf0, 0x11d1, 0x83, 0xee, 0x00, 0xa0, 0xc9, 0x0d, 0xc8, 0x49); +DEFINE_GUID(CLSID_MyComputer, 0x20D04FE0, 0x3AEA, 0x1069, 0xA2, 0xD8, 0x08, 0x00, 0x2B, 0x30, 0x30, 0x9D); +DEFINE_GUID(CLSID_Internet, 0x871C5380, 0x42A0, 0x1069, 0xA2, 0xEA, 0x08, 0x00, 0x2B, 0x30, 0x30, 0x9D); +DEFINE_GUID(CLSID_ShellFSFolder, 0xF3364BA0, 0x65B9, 0x11CE, 0xA9, 0xBA, 0x00, 0xAA, 0x00, 0x4A, 0xE8, 0x37); +DEFINE_GUID(CLSID_RecycleBin, 0x645FF040, 0x5081, 0x101B, 0x9F, 0x08, 0x00, 0xAA, 0x00, 0x2F, 0x95, 0x4E); +DEFINE_GUID(CLSID_ControlPanel, 0x21EC2020, 0x3AEA, 0x1069, 0xA2, 0xDD, 0x08, 0x00, 0x2B, 0x30, 0x30, 0x9D); +DEFINE_GUID(CLSID_Printers, 0x2227A280, 0x3AEA, 0x1069, 0xA2, 0xDE, 0x08, 0x00, 0x2B, 0x30, 0x30, 0x9D); +DEFINE_GUID(CLSID_MyDocuments, 0x450d8fba, 0xad25, 0x11d0, 0x98, 0xa8, 0x08, 0x00, 0x36, 0x1b, 0x11, 0x03); + +#endif diff --git a/apilibs/kexbasen/shell32/pidl.h b/apilibs/kexbasen/shell32/pidl.h new file mode 100644 index 0000000..6ef2138 --- /dev/null +++ b/apilibs/kexbasen/shell32/pidl.h @@ -0,0 +1,286 @@ +/* + * internal pidl functions + * + * Copyright 1998 Juergen Schmied + * Copyright 2004 Juan Lang + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + * NOTES: + * + * DO NOT use this definitions outside the shell32.dll ! + * + * The contents of a pidl should never used from a application + * directly. + * + * Undocumented: + * MS says: the abID of SHITEMID should be treated as binary data and not + * be interpreted by applications. Applies to everyone but MS itself. + * Word95 interprets the contents of abID (Filesize/Date) so we have to go + * for binary compatibility here. + */ + +#ifndef __WINE_PIDL_H +#define __WINE_PIDL_H + +#include + +#include "windef.h" +#include "winbase.h" +#include "winuser.h" +#include "shlobj.h" + +/* +* the pidl does cache fileattributes to speed up SHGetAttributes when +* displaying a big number of files. +* +* a pidl of NULL means the desktop +* +* The structure of the pidl seems to be a union. The first byte of the +* PIDLDATA desribes the type of pidl. +* +* object ! first byte / ! format ! living space +* ! size +* ---------------------------------------------------------------- +* my computer 0x1F/20 guid (2) (usual) +* network 0x1F guid +* bitbucket 0x1F guid +* drive 0x23/25 drive (usual) +* drive 0x25/25 drive (lnk/persistent) +* drive 0x29/25 drive +* shell extension 0x2E guid +* drive 0x2F drive (lnk/persistent) +* folder/file 0x30 folder/file (1) (lnk/persistent) +* folder 0x31 folder (usual) +* valueA 0x32 file (ANSI file name) +* valueW 0x34 file (Unicode file name) +* workgroup 0x41 network (3) +* computer 0x42 network (4) +* net provider 0x46 network +* whole network 0x47 network (5) +* MSITStore 0x61 htmlhlp (7) +* printers/ras connections 0x70 guid +* history/favorites 0xb1 file +* share 0xc3 network (6) +* +* guess: the persistent elements are non tracking +* +* (1) dummy byte is used, attributes are empty +* (2) IID_MyComputer = 20D04FE0L-3AEA-1069-A2D8-08002B30309D +* (3) two strings "workgroup" "Microsoft Network" +* (4) two strings "\\sirius" "Microsoft Network" +* (5) one string "Entire Network" +* (6) two strings "\\sirius\c" "Microsoft Network" +* (7) contains string "mk:@MSITStore:C:\path\file.chm::/path/filename.htm" +* GUID 871C5380-42A0-1069-A2EA-08002B30309D +*/ + +#define PT_CPLAPPLET 0x00 +#define PT_GUID 0x1F +#define PT_DRIVE 0x23 +#define PT_DRIVE2 0x25 +#define PT_DRIVE3 0x29 +#define PT_SHELLEXT 0x2E +#define PT_DRIVE1 0x2F +#define PT_FOLDER1 0x30 +#define PT_FOLDER 0x31 +#define PT_VALUE 0x32 +#define PT_VALUEW 0x34 +#define PT_WORKGRP 0x41 +#define PT_COMP 0x42 +#define PT_NETPROVIDER 0x46 +#define PT_NETWORK 0x47 +#define PT_IESPECIAL1 0x61 +#define PT_YAGUID 0x70 /* yet another guid.. */ +#define PT_IESPECIAL2 0xb1 +#define PT_SHARE 0xc3 + +#include "pshpack1.h" +typedef BYTE PIDLTYPE; + +typedef struct tagPIDLCPanelStruct +{ + BYTE dummy; /*01 is 0x00 */ + DWORD iconIdx; /*02 negative icon ID */ + WORD offsDispName; /*06*/ + WORD offsComment; /*08*/ + CHAR szName[1]; /*10*/ /* terminated by 0x00, followed by display name and comment string */ +} PIDLCPanelStruct; + +typedef struct tagGUIDStruct +{ + BYTE dummy; /* offset 01 is unknown */ + GUID guid; /* offset 02 */ +} GUIDStruct; + +typedef struct tagDriveStruct +{ + CHAR szDriveName[20]; /*01*/ + WORD unknown; /*21*/ +} DriveStruct; + +typedef struct tagFileStruct +{ + BYTE dummy; /*01 is 0x00 for files or dirs */ + DWORD dwFileSize; /*02*/ + WORD uFileDate; /*06*/ + WORD uFileTime; /*08*/ + WORD uFileAttribs; /*10*/ + CHAR szNames[1]; /*12*/ + /* Here are coming two strings. The first is the long name. + The second the dos name when needed or just 0x00 */ +} FileStruct; + +/* At least on WinXP, this struct is appended with 2-byte-alignment to FileStruct. There follows + * a WORD member after the wszName string, which gives the offset from the beginning of the PIDL + * to the FileStructW member. */ +typedef struct tagFileStructW { + WORD cbLen; + BYTE dummy1[6]; + WORD uCreationDate; + WORD uCreationTime; + WORD uLastAccessDate; + WORD uLastAccessTime; + BYTE dummy2[4]; + WCHAR wszName[1]; +} FileStructW; + +typedef struct tagValueW +{ + WCHAR name[1]; +} ValueWStruct; + +typedef struct tagPIDLDATA +{ PIDLTYPE type; /*00*/ + union + { + struct tagGUIDStruct guid; + struct tagDriveStruct drive; + struct tagFileStruct file; + struct + { WORD dummy; /*01*/ + CHAR szNames[1]; /*03*/ + } network; + struct + { WORD dummy; /*01*/ + DWORD dummy1; /*02*/ + CHAR szName[1]; /*06*/ /* terminated by 0x00 0x00 */ + } htmlhelp; + struct tagPIDLCPanelStruct cpanel; + struct tagValueW valueW; + }u; +} PIDLDATA, *LPPIDLDATA; +#include "poppack.h" + +/* + * getting special values from simple pidls + */ +DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize); +DWORD _ILSimpleGetTextW (LPCITEMIDLIST pidl, LPWSTR pOut, UINT uOutSize); +BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize); +DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize); +BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize); +void _ILGetFileType (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize); +DWORD _ILGetFileAttributes (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize); + +BOOL _ILGetFileDateTime (LPCITEMIDLIST pidl, FILETIME *ft); +DWORD _ILGetDrive (LPCITEMIDLIST, LPSTR, UINT); + +/* + * testing simple pidls + */ +BOOL _ILIsDesktop (LPCITEMIDLIST pidl); +BOOL _ILIsMyComputer (LPCITEMIDLIST pidl); +BOOL _ILIsDrive (LPCITEMIDLIST pidl); +BOOL _ILIsFolder (LPCITEMIDLIST pidl); +BOOL _ILIsValue (LPCITEMIDLIST pidl); +BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl); +BOOL _ILIsPidlSimple (LPCITEMIDLIST pidl); +BOOL _ILIsCPanelStruct (LPCITEMIDLIST pidl); +/* +static inline +BOOL _ILIsEqualSimple (LPCITEMIDLIST pidlA, LPCITEMIDLIST pidlB) +{ + return (pidlA->mkid.cb > 0 && !memcmp(pidlA, pidlB, pidlA->mkid.cb)) || + (!pidlA->mkid.cb && !pidlB->mkid.cb); +} +static inline +BOOL _ILIsEmpty (LPCITEMIDLIST pidl) { return _ILIsDesktop(pidl); } +*/ + +/* + * simple pidls + */ + +/* Basic PIDL constructor. Allocates size + 5 bytes, where: + * - two bytes are SHITEMID.cb + * - one byte is PIDLDATA.type + * - two bytes are the NULL PIDL terminator + * Sets type of the returned PIDL to type. + */ +LPITEMIDLIST _ILAlloc(PIDLTYPE type, unsigned int size); + +/* Creates a PIDL with guid format and type type, which must be one of PT_GUID, + * PT_SHELLEXT, or PT_YAGUID. + */ +LPITEMIDLIST _ILCreateGuid(PIDLTYPE type, const IID *guid); + +/* Like _ILCreateGuid, but using the string szGUID. */ +LPITEMIDLIST _ILCreateGuidFromStrA(LPCSTR szGUID); +LPITEMIDLIST _ILCreateGuidFromStrW(LPCWSTR szGUID); + +/* Commonly used PIDLs representing file system objects. */ +LPITEMIDLIST _ILCreateDesktop (void); +LPITEMIDLIST _ILCreateFromFindDataA(WIN32_FIND_DATAA *stffile); +LPITEMIDLIST _ILCreateFromFindDataW(WIN32_FIND_DATAW *stffile); +HRESULT _ILCreateFromPathA (LPCSTR szPath, LPITEMIDLIST* ppidl); +HRESULT _ILCreateFromPathW (LPCWSTR szPath, LPITEMIDLIST* ppidl); + +/* Other helpers */ +LPITEMIDLIST _ILCreateMyComputer (void); +LPITEMIDLIST _ILCreateMyDocuments (void); +LPITEMIDLIST _ILCreateIExplore (void); +LPITEMIDLIST _ILCreateControlPanel (void); +LPITEMIDLIST _ILCreatePrinters (void); +LPITEMIDLIST _ILCreateNetwork (void); +LPITEMIDLIST _ILCreateBitBucket (void); +LPITEMIDLIST _ILCreateDrive (LPCWSTR); + +/* + * helper functions (getting struct-pointer) + */ +LPPIDLDATA _ILGetDataPointer (LPCITEMIDLIST); +LPSTR _ILGetTextPointer (LPCITEMIDLIST); +LPSTR _ILGetSTextPointer (LPCITEMIDLIST); +IID *_ILGetGUIDPointer (LPCITEMIDLIST pidl); +FileStructW *_ILGetFileStructW (LPCITEMIDLIST pidl); + +/* + * debug helper + */ +void pdump (LPCITEMIDLIST pidl); +BOOL pcheck (LPCITEMIDLIST pidl); + +/* + * aPidl helper + */ +void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl); +LPITEMIDLIST * _ILCopyaPidl(LPCITEMIDLIST * apidlsrc, UINT cidl); +LPITEMIDLIST * _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, LPIDA cida); + +BOOL WINAPI ILGetDisplayNameExA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPSTR path, DWORD type); +BOOL WINAPI ILGetDisplayNameExW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPWSTR path, DWORD type); + +#endif diff --git a/apilibs/kexbasen/shell32/unishell32.c b/apilibs/kexbasen/shell32/unishell32.c new file mode 100644 index 0000000..ee2da41 --- /dev/null +++ b/apilibs/kexbasen/shell32/unishell32.c @@ -0,0 +1,35 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "unifwd.h" + +FORWARD_TO_UNICOWS(DragQueryFileW); +FORWARD_TO_UNICOWS(ExtractIconExW); +FORWARD_TO_UNICOWS(ExtractIconW); +FORWARD_TO_UNICOWS(FindExecutableW); +FORWARD_TO_UNICOWS(SHBrowseForFolderW); +FORWARD_TO_UNICOWS(Shell_NotifyIconW); +FORWARD_TO_UNICOWS(ShellAboutW); +FORWARD_TO_UNICOWS(ShellExecuteExW); +FORWARD_TO_UNICOWS(ShellExecuteW); +FORWARD_TO_UNICOWS(SHFileOperationW); +FORWARD_TO_UNICOWS(SHGetFileInfoW); +FORWARD_TO_UNICOWS(SHGetNewLinkInfoW); diff --git a/apilibs/kexbasen/shell32ord.def b/apilibs/kexbasen/shell32ord.def new file mode 100644 index 0000000..2810a25 --- /dev/null +++ b/apilibs/kexbasen/shell32ord.def @@ -0,0 +1,8 @@ +LIBRARY SHELL32.dll + +EXPORTS + SHILCreateFromPathA@12 @28 NONAME + SHAlloc@4 @196 NONAME + SHFree@4 @195 NONAME + ILGetNext@4 @153 NONAME + ILCombine@8 @25 NONAME diff --git a/apilibs/kexbasen/unifwd.c b/apilibs/kexbasen/unifwd.c new file mode 100644 index 0000000..46851b6 --- /dev/null +++ b/apilibs/kexbasen/unifwd.c @@ -0,0 +1,53 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include +#include "unifwd.h" +#include "kexcoresdk.h" +#include "common.h" + +static HMODULE hUnicows; + +int unifwd_init(void) +{ + hUnicows = GetModuleHandle("UNICOWS.DLL"); + if (!hUnicows) + hUnicows = LoadLibrary("UNICOWS.DLL"); + return (hUnicows != NULL); +} + +void unicows_fatal_error(const char* func) +{ + char msg[256]; + strcpy(msg, "kexbasen: Failed to get unicows proc addr: "); + strcat(msg, func); + fatal_error(msg); +} + +unsigned long __stdcall GetUnicowsAddress(const char* name) +{ + if (!hUnicows) + unifwd_init(); + PROC addr = GetProcAddress(hUnicows, name); + if (!addr) + unicows_fatal_error(name); + return (unsigned long) addr; +} diff --git a/apilibs/kexbasen/unifwd.h b/apilibs/kexbasen/unifwd.h new file mode 100644 index 0000000..0f37e62 --- /dev/null +++ b/apilibs/kexbasen/unifwd.h @@ -0,0 +1,88 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#ifndef __UNIFWD_H +#define __UNIFWD_H + +#pragma warning(disable:4409) + +int unifwd_init(void); +unsigned long __stdcall GetUnicowsAddress(const char* name); + + +/* Q: Why FORWARD_TO_UNICOWS macro is in asm? + * A: We don't know the parameters of called function + * so we can't call the function in C + * + * Note that the code below would be correct if all compilers translated + * the 'return' line to JMP instruction but it is not always the case + * and we can't rely on that so we workaround this writing the macro in asm. + * + * int __stdcall fun_fwd() + * { + * static const char* n = "fun"; + * static unsigned long ref = 0; + * if (!ref) + * ref = GetUnicowsAddress("fun"); + * return ((int (__stdcall *)())ref)(); + * } + */ + +#ifdef __GNUC__ + +/* How to make it less messy? */ +#define FORWARD_TO_UNICOWS(name) \ + __asm__( \ + ".section .rdata,\"dr\"\n" \ + "LC_" #name ":\n\t" \ + ".ascii \"" #name "\\0\"\n\t" \ + ".text\n" \ + ".globl _" #name "_fwd@0\n\t" \ + ".def _" #name "fwd@0; .scl 2; .type 32; .endef\n" \ + "_" #name "_fwd@0:\n\t" \ + "cmpl $0, _ref_" #name "\n\t" \ + "jnz LOC_" #name "\n\t" \ + "pushl $LC_" #name "\n\t" \ + "call _GetUnicowsAddress@4\n\t" \ + "movl %eax, _ref_" #name "\n" \ + "LOC_" #name ":\n\t" \ + "movl _ref_" #name ", %eax\n\t" \ + "jmp *%eax\n" \ + ".lcomm _ref_" #name ",4\n\t" + +#else + +#define FORWARD_TO_UNICOWS(name) \ + int __declspec(naked) __stdcall name##_fwd(void) \ + { \ + static const char n[] = #name; \ + static unsigned long ref = 0; \ + __asm { cmp dword ptr [ref], 0} \ + __asm { jnz L1 } \ + __asm { push offset n } \ + __asm { call GetUnicowsAddress } \ + __asm { mov dword ptr [ref], eax } \ + __asm { L1: jmp [ref] } \ + } + +#endif /* #ifdef __GNUC__ */ + +#endif diff --git a/apilibs/kexbasen/user32/_user32_apilist.c b/apilibs/kexbasen/user32/_user32_apilist.c new file mode 100644 index 0000000..dd76168 --- /dev/null +++ b/apilibs/kexbasen/user32/_user32_apilist.c @@ -0,0 +1,163 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" +#include "kexcoresdk.h" +#include "_user32_apilist.h" + +BOOL init_user32() +{ + return TRUE; +} + +static const apilib_named_api user32_named_apis[] = +{ +/*** AUTOGENERATED APILIST NAMED EXPORTS BEGIN ***/ + DECL_API("AppendMenuW", AppendMenuW_fwd), + DECL_API("BroadcastSystemMessageW", BroadcastSystemMessageW_fwd), + DECL_API("CallMsgFilterW", CallMsgFilterW_fwd), + DECL_API("CallWindowProcW", CallWindowProcW_fwd), + DECL_API("ChangeDisplaySettingsExW", ChangeDisplaySettingsExW_fwd), + DECL_API("ChangeDisplaySettingsW", ChangeDisplaySettingsW_fwd), + DECL_API("ChangeMenuW", ChangeMenuW_fwd), + DECL_API("CharLowerBuffW", CharLowerBuffW_fwd), + DECL_API("CharLowerW", CharLowerW_fwd), + DECL_API("CharNextW", CharNextW_fwd), + DECL_API("CharPrevW", CharPrevW_fwd), + DECL_API("CharToOemBuffW", CharToOemBuffW_fwd), + DECL_API("CharToOemW", CharToOemW_fwd), + DECL_API("CharUpperBuffW", CharUpperBuffW_fwd), + DECL_API("CharUpperW", CharUpperW_fwd), + DECL_API("CopyAcceleratorTableW", CopyAcceleratorTableW_fwd), + DECL_API("CreateAcceleratorTableW", CreateAcceleratorTableW_fwd), + DECL_API("CreateDialogIndirectParamW", CreateDialogIndirectParamW_fwd), + DECL_API("CreateDialogParamW", CreateDialogParamW_new), + DECL_API("CreateMDIWindowW", CreateMDIWindowW_fwd), + DECL_API("CreateWindowExW", CreateWindowExW_fwd), + DECL_API("DdeCreateStringHandleW", DdeCreateStringHandleW_fwd), + DECL_API("DdeInitializeW", DdeInitializeW_fwd), + DECL_API("DdeQueryStringW", DdeQueryStringW_fwd), + DECL_API("DefDlgProcW", DefDlgProcW_fwd), + DECL_API("DefFrameProcW", DefFrameProcW_fwd), + DECL_API("DefMDIChildProcW", DefMDIChildProcW_fwd), + DECL_API("DefWindowProcW", DefWindowProcW_new), + DECL_API("DialogBoxIndirectParamW", DialogBoxIndirectParamW_fwd), + DECL_API("DialogBoxParamW", DialogBoxParamW_fwd), + DECL_API("DispatchMessageW", DispatchMessageW_fwd), + DECL_API("DlgDirListComboBoxW", DlgDirListComboBoxW_fwd), + DECL_API("DlgDirListW", DlgDirListW_fwd), + DECL_API("DlgDirSelectComboBoxExW", DlgDirSelectComboBoxExW_fwd), + DECL_API("DlgDirSelectExW", DlgDirSelectExW_fwd), + DECL_API("DrawStateW", DrawStateW_fwd), + DECL_API("DrawTextExW", DrawTextExW_fwd), + DECL_API("DrawTextW", DrawTextW_fwd), + DECL_API("EnumDisplayDevicesW", EnumDisplayDevicesW_fwd), + DECL_API("EnumDisplaySettingsExW", EnumDisplaySettingsExW_fwd), + DECL_API("EnumDisplaySettingsW", EnumDisplaySettingsW_fwd), + DECL_API("EnumPropsExW", EnumPropsExW_fwd), + DECL_API("EnumPropsW", EnumPropsW_fwd), + DECL_API("FindWindowExW", FindWindowExW_fwd), + DECL_API("FindWindowW", FindWindowW_fwd), + DECL_API("GetAltTabInfoW", GetAltTabInfoW_fwd), + DECL_API("GetClassInfoExW", GetClassInfoExW_fwd), + DECL_API("GetClassInfoW", GetClassInfoW_fwd), + DECL_API("GetClassLongW", GetClassLongW_fwd), + DECL_API("GetClassNameW", GetClassNameW_fwd), + DECL_API("GetClipboardFormatNameW", GetClipboardFormatNameW_fwd), + DECL_API("GetDlgItemTextW", GetDlgItemTextW_fwd), + DECL_API("GetKeyNameTextW", GetKeyNameTextW_fwd), + DECL_API("GetKeyboardLayoutNameW", GetKeyboardLayoutNameW_fwd), + DECL_API("GetMenuItemInfoW", GetMenuItemInfoW_fwd), + DECL_API("GetMenuStringW", GetMenuStringW_fwd), + DECL_API("GetMessageW", GetMessageW_fwd), + DECL_API("GetMonitorInfoW", GetMonitorInfoW_fwd), + DECL_API("GetPropW", GetPropW_fwd), + DECL_API("GetTabbedTextExtentW", GetTabbedTextExtentW_fwd), + DECL_API("GetWindowLongW", GetWindowLongW_fwd), + DECL_API("GetWindowTextLengthW", GetWindowTextLengthW_fwd), + DECL_API("GetWindowTextW", GetWindowTextW_fwd), + DECL_API("GrayStringW", GrayStringW_fwd), + DECL_API("InsertMenuItemW", InsertMenuItemW_fwd), + DECL_API("InsertMenuW", InsertMenuW_fwd), + DECL_API("IsCharAlphaNumericW", IsCharAlphaNumericW_fwd), + DECL_API("IsCharAlphaW", IsCharAlphaW_fwd), + DECL_API("IsCharLowerW", IsCharLowerW_fwd), + DECL_API("IsCharUpperW", IsCharUpperW_fwd), + DECL_API("IsDialogMessageW", IsDialogMessageW_fwd), + DECL_API("IsWindowUnicode", IsWindowUnicode_fwd), + DECL_API("LoadAcceleratorsW", LoadAcceleratorsW_fwd), + DECL_API("LoadBitmapW", LoadBitmapW_fwd), + DECL_API("LoadCursorFromFileW", LoadCursorFromFileW_fwd), + DECL_API("LoadCursorW", LoadCursorW_fwd), + DECL_API("LoadIconW", LoadIconW_fwd), + DECL_API("LoadImageW", LoadImageW_fwd), + DECL_API("LoadKeyboardLayoutW", LoadKeyboardLayoutW_fwd), + DECL_API("LoadMenuIndirectW", LoadMenuIndirectW_fwd), + DECL_API("LoadMenuW", LoadMenuW_fwd), + DECL_API("MapVirtualKeyExW", MapVirtualKeyExW_fwd), + DECL_API("MapVirtualKeyW", MapVirtualKeyW_fwd), + DECL_API("MessageBoxIndirectW", MessageBoxIndirectW_fwd), + DECL_API("ModifyMenuW", ModifyMenuW_fwd), + DECL_API("OemToCharBuffW", OemToCharBuffW_fwd), + DECL_API("OemToCharW", OemToCharW_fwd), + DECL_API("PeekMessageW", PeekMessageW_fwd), + DECL_API("PostMessageW", PostMessageW_fwd), + DECL_API("PostThreadMessageW", PostThreadMessageW_fwd), + DECL_API("RegisterClassExW", RegisterClassExW_fwd), + DECL_API("RegisterClassW", RegisterClassW_fwd), + DECL_API("RegisterClipboardFormatW", RegisterClipboardFormatW_fwd), + DECL_API("RegisterDeviceNotificationW", RegisterDeviceNotificationW_fwd), + DECL_API("RegisterWindowMessageW", RegisterWindowMessageW_fwd), + DECL_API("RemovePropW", RemovePropW_fwd), + DECL_API("SendDlgItemMessageW", SendDlgItemMessageW_fwd), + DECL_API("SendMessageCallbackW", SendMessageCallbackW_fwd), + DECL_API("SendMessageTimeoutW", SendMessageTimeoutW_fwd), + DECL_API("SendMessageW", SendMessageW_fwd), + DECL_API("SendNotifyMessageW", SendNotifyMessageW_fwd), + DECL_API("SetClassLongW", SetClassLongW_fwd), + DECL_API("SetDlgItemTextW", SetDlgItemTextW_fwd), + DECL_API("SetMenuItemInfoW", SetMenuItemInfoW_fwd), + DECL_API("SetPropW", SetPropW_fwd), + DECL_API("SetWindowLongW", SetWindowLongW_fwd), + DECL_API("SetWindowTextW", SetWindowTextW_fwd), + DECL_API("SetWindowsHookExW", SetWindowsHookExW_fwd), + DECL_API("SetWindowsHookW", SetWindowsHookW_fwd), + DECL_API("SystemParametersInfoW", SystemParametersInfoW_fwd), + DECL_API("TabbedTextOutW", TabbedTextOutW_fwd), + DECL_API("TranslateAcceleratorW", TranslateAcceleratorW_fwd), + DECL_API("UnregisterClassW", UnregisterClassW_fwd), + DECL_API("VkKeyScanExW", VkKeyScanExW_fwd), + DECL_API("VkKeyScanW", VkKeyScanW_fwd), + DECL_API("WinHelpW", WinHelpW_fwd), + DECL_API("wsprintfW", wsprintfW_fwd), + DECL_API("wvsprintfW", wvsprintfW_fwd), +/*** AUTOGENERATED APILIST NAMED EXPORTS END ***/ +}; + +#if 0 +static const apilib_unnamed_api user32_ordinal_apis[] = +{ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS BEGIN ***/ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS END ***/ +}; +#endif + +const apilib_api_table apitable_user32 = DECL_TAB("USER32.DLL", user32_named_apis, 0 /*user32_ordinal_apis*/); diff --git a/apilibs/kexbasen/user32/_user32_apilist.h b/apilibs/kexbasen/user32/_user32_apilist.h new file mode 100644 index 0000000..923d2e4 --- /dev/null +++ b/apilibs/kexbasen/user32/_user32_apilist.h @@ -0,0 +1,152 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#ifndef _USER32_APILIST_H +#define _USER32_APILIST_H + +#include "auxdecl.h" +#include "kexcoresdk.h" + +BOOL init_user32(); +extern const apilib_api_table apitable_user32; + +/*** AUTOGENERATED APILIST DECLARATIONS BEGIN ***/ +FWDPROC AppendMenuW_fwd; +FWDPROC BroadcastSystemMessageW_fwd; +FWDPROC CallMsgFilterW_fwd; +FWDPROC CallWindowProcW_fwd; +FWDPROC ChangeDisplaySettingsExW_fwd; +FWDPROC ChangeDisplaySettingsW_fwd; +FWDPROC ChangeMenuW_fwd; +FWDPROC CharLowerBuffW_fwd; +FWDPROC CharLowerW_fwd; +FWDPROC CharNextW_fwd; +FWDPROC CharPrevW_fwd; +FWDPROC CharToOemBuffW_fwd; +FWDPROC CharToOemW_fwd; +FWDPROC CharUpperBuffW_fwd; +FWDPROC CharUpperW_fwd; +FWDPROC CopyAcceleratorTableW_fwd; +FWDPROC CreateAcceleratorTableW_fwd; +FWDPROC CreateDialogIndirectParamW_fwd; +FWDPROC CreateMDIWindowW_fwd; +FWDPROC CreateWindowExW_fwd; +FWDPROC DdeCreateStringHandleW_fwd; +FWDPROC DdeInitializeW_fwd; +FWDPROC DdeQueryStringW_fwd; +FWDPROC DefDlgProcW_fwd; +FWDPROC DefFrameProcW_fwd; +FWDPROC DefMDIChildProcW_fwd; +FWDPROC DialogBoxIndirectParamW_fwd; +FWDPROC DialogBoxParamW_fwd; +FWDPROC DispatchMessageW_fwd; +FWDPROC DlgDirListComboBoxW_fwd; +FWDPROC DlgDirListW_fwd; +FWDPROC DlgDirSelectComboBoxExW_fwd; +FWDPROC DlgDirSelectExW_fwd; +FWDPROC DrawStateW_fwd; +FWDPROC DrawTextExW_fwd; +FWDPROC DrawTextW_fwd; +FWDPROC EnumDisplayDevicesW_fwd; +FWDPROC EnumDisplaySettingsExW_fwd; +FWDPROC EnumDisplaySettingsW_fwd; +FWDPROC EnumPropsExW_fwd; +FWDPROC EnumPropsW_fwd; +FWDPROC FindWindowExW_fwd; +FWDPROC FindWindowW_fwd; +FWDPROC GetAltTabInfoW_fwd; +FWDPROC GetClassInfoExW_fwd; +FWDPROC GetClassInfoW_fwd; +FWDPROC GetClassLongW_fwd; +FWDPROC GetClassNameW_fwd; +FWDPROC GetClipboardFormatNameW_fwd; +FWDPROC GetDlgItemTextW_fwd; +FWDPROC GetKeyboardLayoutNameW_fwd; +FWDPROC GetKeyNameTextW_fwd; +FWDPROC GetMenuItemInfoW_fwd; +FWDPROC GetMenuStringW_fwd; +FWDPROC GetMessageW_fwd; +FWDPROC GetMonitorInfoW_fwd; +FWDPROC GetPropW_fwd; +FWDPROC GetTabbedTextExtentW_fwd; +FWDPROC GetWindowLongW_fwd; +FWDPROC GetWindowTextLengthW_fwd; +FWDPROC GetWindowTextW_fwd; +FWDPROC GrayStringW_fwd; +FWDPROC InsertMenuItemW_fwd; +FWDPROC InsertMenuW_fwd; +FWDPROC IsCharAlphaNumericW_fwd; +FWDPROC IsCharAlphaW_fwd; +FWDPROC IsCharLowerW_fwd; +FWDPROC IsCharUpperW_fwd; +FWDPROC IsDialogMessageW_fwd; +FWDPROC IsWindowUnicode_fwd; +FWDPROC LoadAcceleratorsW_fwd; +FWDPROC LoadBitmapW_fwd; +FWDPROC LoadCursorFromFileW_fwd; +FWDPROC LoadCursorW_fwd; +FWDPROC LoadIconW_fwd; +FWDPROC LoadImageW_fwd; +FWDPROC LoadKeyboardLayoutW_fwd; +FWDPROC LoadMenuIndirectW_fwd; +FWDPROC LoadMenuW_fwd; +FWDPROC MapVirtualKeyExW_fwd; +FWDPROC MapVirtualKeyW_fwd; +FWDPROC MessageBoxIndirectW_fwd; +FWDPROC ModifyMenuW_fwd; +FWDPROC OemToCharBuffW_fwd; +FWDPROC OemToCharW_fwd; +FWDPROC PeekMessageW_fwd; +FWDPROC PostMessageW_fwd; +FWDPROC PostThreadMessageW_fwd; +FWDPROC RegisterClassExW_fwd; +FWDPROC RegisterClassW_fwd; +FWDPROC RegisterClipboardFormatW_fwd; +FWDPROC RegisterDeviceNotificationW_fwd; +FWDPROC RegisterWindowMessageW_fwd; +FWDPROC RemovePropW_fwd; +FWDPROC SendDlgItemMessageW_fwd; +FWDPROC SendMessageCallbackW_fwd; +FWDPROC SendMessageTimeoutW_fwd; +FWDPROC SendMessageW_fwd; +FWDPROC SendNotifyMessageW_fwd; +FWDPROC SetClassLongW_fwd; +FWDPROC SetDlgItemTextW_fwd; +FWDPROC SetMenuItemInfoW_fwd; +FWDPROC SetPropW_fwd; +FWDPROC SetWindowLongW_fwd; +FWDPROC SetWindowsHookExW_fwd; +FWDPROC SetWindowsHookW_fwd; +FWDPROC SetWindowTextW_fwd; +FWDPROC SystemParametersInfoW_fwd; +FWDPROC TabbedTextOutW_fwd; +FWDPROC TranslateAcceleratorW_fwd; +FWDPROC UnregisterClassW_fwd; +FWDPROC VkKeyScanExW_fwd; +FWDPROC VkKeyScanW_fwd; +FWDPROC WinHelpW_fwd; +FWDPROC wsprintfW_fwd; +FWDPROC wvsprintfW_fwd; +HWND WINAPI CreateDialogParamW_new(HINSTANCE hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam); +LRESULT WINAPI DefWindowProcW_new(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); +/*** AUTOGENERATED APILIST DECLARATIONS END ***/ + +#endif diff --git a/apilibs/kexbasen/user32/uniuser32.c b/apilibs/kexbasen/user32/uniuser32.c new file mode 100644 index 0000000..8357a78 --- /dev/null +++ b/apilibs/kexbasen/user32/uniuser32.c @@ -0,0 +1,170 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include +#include +#include "unifwd.h" + +FORWARD_TO_UNICOWS(AppendMenuW); +FORWARD_TO_UNICOWS(BroadcastSystemMessageW); +FORWARD_TO_UNICOWS(CallMsgFilterW); +FORWARD_TO_UNICOWS(CallWindowProcW); +FORWARD_TO_UNICOWS(ChangeDisplaySettingsExW); +FORWARD_TO_UNICOWS(ChangeDisplaySettingsW); +FORWARD_TO_UNICOWS(ChangeMenuW); +FORWARD_TO_UNICOWS(CharLowerBuffW); +FORWARD_TO_UNICOWS(CharLowerW); +FORWARD_TO_UNICOWS(CharNextW); +FORWARD_TO_UNICOWS(CharPrevW); +FORWARD_TO_UNICOWS(CharToOemBuffW); +FORWARD_TO_UNICOWS(CharToOemW); +FORWARD_TO_UNICOWS(CharUpperBuffW); +FORWARD_TO_UNICOWS(CharUpperW); +FORWARD_TO_UNICOWS(CopyAcceleratorTableW); +FORWARD_TO_UNICOWS(CreateAcceleratorTableW); +FORWARD_TO_UNICOWS(CreateDialogIndirectParamW); + +static BOOL CALLBACK SetUnicode(HWND hwnd, LPARAM lParam) +{ + return SendMessage(hwnd, CCM_SETUNICODEFORMAT, TRUE, 0); +} + +/* MAKE_EXPORT CreateDialogParamW_new=CreateDialogParamW */ +HWND WINAPI CreateDialogParamW_new(HINSTANCE hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam) +{ + typedef HWND (WINAPI *CreateDialogParamW_t)(HINSTANCE, LPCSTR, HWND, DLGPROC, LPARAM); + static CreateDialogParamW_t g_DialogParamW; + HWND hDlg; + if (!g_DialogParamW) g_DialogParamW = (CreateDialogParamW_t) GetUnicowsAddress("CreateDialogParamW"); + hDlg = g_DialogParamW(hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam); + if (hDlg) EnumChildWindows(hDlg, SetUnicode, 0); + return hDlg; +} + +FORWARD_TO_UNICOWS(CreateMDIWindowW); +FORWARD_TO_UNICOWS(CreateWindowExW); +FORWARD_TO_UNICOWS(DdeCreateStringHandleW); +FORWARD_TO_UNICOWS(DdeInitializeW); +FORWARD_TO_UNICOWS(DdeQueryStringW); +FORWARD_TO_UNICOWS(DefDlgProcW); +FORWARD_TO_UNICOWS(DefFrameProcW); +FORWARD_TO_UNICOWS(DefMDIChildProcW); + +/* MAKE_EXPORT DefWindowProcW_new=DefWindowProcW */ +LRESULT WINAPI DefWindowProcW_new(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) +{ + typedef LRESULT (WINAPI *DefWindowProcW_t)(HWND, UINT, WPARAM, LPARAM); + static DefWindowProcW_t g_DefProcW; + if (!g_DefProcW) g_DefProcW = (DefWindowProcW_t) GetUnicowsAddress("DefWindowProcW"); + if (Msg == WM_NOTIFYFORMAT && lParam == NF_QUERY && IsWindowUnicode(hWnd)) return NFR_UNICODE; + return g_DefProcW(hWnd, Msg, wParam, lParam); +} + +FORWARD_TO_UNICOWS(DialogBoxIndirectParamW); +FORWARD_TO_UNICOWS(DialogBoxParamW); +FORWARD_TO_UNICOWS(DispatchMessageW); +FORWARD_TO_UNICOWS(DlgDirListComboBoxW); +FORWARD_TO_UNICOWS(DlgDirListW); +FORWARD_TO_UNICOWS(DlgDirSelectComboBoxExW); +FORWARD_TO_UNICOWS(DlgDirSelectExW); +FORWARD_TO_UNICOWS(DrawStateW); +FORWARD_TO_UNICOWS(DrawTextExW); +FORWARD_TO_UNICOWS(DrawTextW); +FORWARD_TO_UNICOWS(EnumDisplayDevicesW); +FORWARD_TO_UNICOWS(EnumDisplaySettingsExW); +FORWARD_TO_UNICOWS(EnumDisplaySettingsW); +FORWARD_TO_UNICOWS(EnumPropsExW); +FORWARD_TO_UNICOWS(EnumPropsW); +FORWARD_TO_UNICOWS(FindWindowExW); +FORWARD_TO_UNICOWS(FindWindowW); +FORWARD_TO_UNICOWS(GetAltTabInfoW); +FORWARD_TO_UNICOWS(GetClassInfoExW); +FORWARD_TO_UNICOWS(GetClassInfoW); +FORWARD_TO_UNICOWS(GetClassLongW); +FORWARD_TO_UNICOWS(GetClassNameW); +FORWARD_TO_UNICOWS(GetClipboardFormatNameW); +FORWARD_TO_UNICOWS(GetDlgItemTextW); +FORWARD_TO_UNICOWS(GetKeyboardLayoutNameW); +FORWARD_TO_UNICOWS(GetKeyNameTextW); +FORWARD_TO_UNICOWS(GetMenuItemInfoW); +FORWARD_TO_UNICOWS(GetMenuStringW); +FORWARD_TO_UNICOWS(GetMessageW); +FORWARD_TO_UNICOWS(GetMonitorInfoW); +FORWARD_TO_UNICOWS(GetPropW); +FORWARD_TO_UNICOWS(GetTabbedTextExtentW); +FORWARD_TO_UNICOWS(GetWindowLongW); +FORWARD_TO_UNICOWS(GetWindowTextLengthW); +FORWARD_TO_UNICOWS(GetWindowTextW); +FORWARD_TO_UNICOWS(GrayStringW); +FORWARD_TO_UNICOWS(InsertMenuItemW); +FORWARD_TO_UNICOWS(InsertMenuW); +FORWARD_TO_UNICOWS(IsCharAlphaNumericW); +FORWARD_TO_UNICOWS(IsCharAlphaW); +FORWARD_TO_UNICOWS(IsCharLowerW); +FORWARD_TO_UNICOWS(IsCharUpperW); +FORWARD_TO_UNICOWS(IsDialogMessageW); +FORWARD_TO_UNICOWS(IsWindowUnicode); +FORWARD_TO_UNICOWS(LoadAcceleratorsW); +FORWARD_TO_UNICOWS(LoadBitmapW); +FORWARD_TO_UNICOWS(LoadCursorFromFileW); +FORWARD_TO_UNICOWS(LoadCursorW); +FORWARD_TO_UNICOWS(LoadIconW); +FORWARD_TO_UNICOWS(LoadImageW); +FORWARD_TO_UNICOWS(LoadKeyboardLayoutW); +FORWARD_TO_UNICOWS(LoadMenuIndirectW); +FORWARD_TO_UNICOWS(LoadMenuW); +FORWARD_TO_UNICOWS(MapVirtualKeyExW); +FORWARD_TO_UNICOWS(MapVirtualKeyW); +FORWARD_TO_UNICOWS(MessageBoxIndirectW); +FORWARD_TO_UNICOWS(ModifyMenuW); +FORWARD_TO_UNICOWS(OemToCharBuffW); +FORWARD_TO_UNICOWS(OemToCharW); +FORWARD_TO_UNICOWS(PeekMessageW); +FORWARD_TO_UNICOWS(PostMessageW); +FORWARD_TO_UNICOWS(PostThreadMessageW); +FORWARD_TO_UNICOWS(RegisterClassExW); +FORWARD_TO_UNICOWS(RegisterClassW); +FORWARD_TO_UNICOWS(RegisterClipboardFormatW); +FORWARD_TO_UNICOWS(RegisterDeviceNotificationW); +FORWARD_TO_UNICOWS(RegisterWindowMessageW); +FORWARD_TO_UNICOWS(RemovePropW); +FORWARD_TO_UNICOWS(SendDlgItemMessageW); +FORWARD_TO_UNICOWS(SendMessageCallbackW); +FORWARD_TO_UNICOWS(SendMessageTimeoutW); +FORWARD_TO_UNICOWS(SendMessageW); +FORWARD_TO_UNICOWS(SendNotifyMessageW); +FORWARD_TO_UNICOWS(SetClassLongW); +FORWARD_TO_UNICOWS(SetDlgItemTextW); +FORWARD_TO_UNICOWS(SetMenuItemInfoW); +FORWARD_TO_UNICOWS(SetPropW); +FORWARD_TO_UNICOWS(SetWindowLongW); +FORWARD_TO_UNICOWS(SetWindowsHookExW); +FORWARD_TO_UNICOWS(SetWindowsHookW); +FORWARD_TO_UNICOWS(SetWindowTextW); +FORWARD_TO_UNICOWS(SystemParametersInfoW); +FORWARD_TO_UNICOWS(TabbedTextOutW); +FORWARD_TO_UNICOWS(TranslateAcceleratorW); +FORWARD_TO_UNICOWS(UnregisterClassW); +FORWARD_TO_UNICOWS(VkKeyScanExW); +FORWARD_TO_UNICOWS(VkKeyScanW); +FORWARD_TO_UNICOWS(WinHelpW); +FORWARD_TO_UNICOWS(wsprintfW); +FORWARD_TO_UNICOWS(wvsprintfW); diff --git a/apilibs/kexbases/Advapi32/RegDisablePredefinedCache.c b/apilibs/kexbases/Advapi32/RegDisablePredefinedCache.c new file mode 100644 index 0000000..e720f81 --- /dev/null +++ b/apilibs/kexbases/Advapi32/RegDisablePredefinedCache.c @@ -0,0 +1,28 @@ +/* + * KernelEx + * Copyright (C) 2008, Tihiy + * + * 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. + * + */ + +#include + +/* MAKE_EXPORT RegDisablePredefinedCache_new=RegDisablePredefinedCache */ +BOOL WINAPI RegDisablePredefinedCache_new() +{ + return ERROR_SUCCESS; +} diff --git a/apilibs/kexbases/Advapi32/RegOpenCurrentUser.c b/apilibs/kexbases/Advapi32/RegOpenCurrentUser.c new file mode 100644 index 0000000..8e3ac41 --- /dev/null +++ b/apilibs/kexbases/Advapi32/RegOpenCurrentUser.c @@ -0,0 +1,28 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include + +/* MAKE_EXPORT RegOpenCurrentUser_new=RegOpenCurrentUser */ +LONG WINAPI RegOpenCurrentUser_new(REGSAM access, PHKEY retkey) +{ + return RegOpenKeyExA(HKEY_CURRENT_USER, NULL, 0, access, retkey); +} diff --git a/apilibs/kexbases/Advapi32/TraceMessage.c b/apilibs/kexbases/Advapi32/TraceMessage.c new file mode 100644 index 0000000..4b1a0eb --- /dev/null +++ b/apilibs/kexbases/Advapi32/TraceMessage.c @@ -0,0 +1,34 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include + +/* MAKE_EXPORT TraceMessage_new=TraceMessage */ +ULONG CDECL TraceMessage_new( + ULONG64 LoggerHandle, + ULONG MessageFlags, + LPGUID MessageGuid, + USHORT MessageNumber, + ... +) +{ + return ERROR_SUCCESS; +} diff --git a/apilibs/kexbases/Advapi32/_advapi32_apilist.c b/apilibs/kexbases/Advapi32/_advapi32_apilist.c new file mode 100644 index 0000000..cca4c64 --- /dev/null +++ b/apilibs/kexbases/Advapi32/_advapi32_apilist.c @@ -0,0 +1,120 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" +#include "kexcoresdk.h" +#include "_advapi32_apilist.h" + +BOOL init_advapi32() +{ + return TRUE; +} + +static const apilib_named_api advapi32_named_apis[] = +{ +/*** AUTOGENERATED APILIST NAMED EXPORTS BEGIN ***/ + DECL_API("AccessCheck", AccessCheck_new), + DECL_API("AddAccessAllowedAce", AddAccessAllowedAce_new), + DECL_API("AdjustTokenPrivileges", AdjustTokenPrivileges_new), + DECL_API("AllocateAndInitializeSid", AllocateAndInitializeSid_new), + DECL_API("CheckTokenMembership", CheckTokenMembership_new), + DECL_API("ConvertSecurityDescriptorToStringSecurityDescriptorA", ConvertSecurityDescriptorToStringSecurityDescriptorA_stub), + DECL_API("ConvertSecurityDescriptorToStringSecurityDescriptorW", ConvertSecurityDescriptorToStringSecurityDescriptorW_stub), + DECL_API("ConvertSidToStringSidA", ConvertSidToStringSidA_stub), + DECL_API("ConvertSidToStringSidW", ConvertSidToStringSidW_stub), + DECL_API("ConvertStringSecurityDescriptorToSecurityDescriptorA", ConvertStringSecurityDescriptorToSecurityDescriptorA_stub), + DECL_API("ConvertStringSecurityDescriptorToSecurityDescriptorW", ConvertStringSecurityDescriptorToSecurityDescriptorW_stub), + DECL_API("ConvertStringSidToSidA", ConvertStringSidToSidA_stub), + DECL_API("ConvertStringSidToSidW", ConvertStringSidToSidW_stub), + DECL_API("CopySid", CopySid_new), + DECL_API("CreateRestrictedToken", CreateRestrictedToken_new), + DECL_API("CreateWellKnownSid", CreateWellKnownSid_new), + DECL_API("CryptAcquireContextW", CryptAcquireContextW_stub), + DECL_API("CryptEnumProviderTypesW", CryptEnumProviderTypesW_stub), + DECL_API("CryptEnumProvidersW", CryptEnumProvidersW_stub), + DECL_API("CryptGetDefaultProviderW", CryptGetDefaultProviderW_stub), + DECL_API("CryptSetProviderExW", CryptSetProviderExW_stub), + DECL_API("CryptSetProviderW", CryptSetProviderW_stub), + DECL_API("CryptSignHashW", CryptSignHashW_stub), + DECL_API("CryptVerifySignatureW", CryptVerifySignatureW_stub), + DECL_API("DuplicateToken", DuplicateToken_new), + DECL_API("DuplicateTokenEx", DuplicateTokenEx_new), + DECL_API("EqualPrefixSid", EqualPrefixSid_new), + DECL_API("EqualSid", EqualSid_new), + DECL_API("FreeSid", FreeSid_new), + DECL_API("GetAce", GetAce_new), + DECL_API("GetFileSecurityA", GetFileSecurityA_new), + DECL_API("GetFileSecurityW", GetFileSecurityW_new), + DECL_API("GetLengthSid", GetLengthSid_new), + DECL_API("GetSecurityDescriptorControl", GetSecurityDescriptorControl_new), + DECL_API("GetSecurityDescriptorDacl", GetSecurityDescriptorDacl_new), + DECL_API("GetSecurityDescriptorGroup", GetSecurityDescriptorGroup_new), + DECL_API("GetSecurityDescriptorLength", GetSecurityDescriptorLength_new), + DECL_API("GetSecurityDescriptorOwner", GetSecurityDescriptorOwner_new), + DECL_API("GetSecurityDescriptorSacl", GetSecurityDescriptorSacl_new), + DECL_API("GetSidIdentifierAuthority", GetSidIdentifierAuthority_new), + DECL_API("GetSidLengthRequired", GetSidLengthRequired_new), + DECL_API("GetSidSubAuthority", GetSidSubAuthority_new), + DECL_API("GetSidSubAuthorityCount", GetSidSubAuthorityCount_new), + DECL_API("GetTokenInformation", GetTokenInformation_new), + DECL_API("ImpersonateSelf", ImpersonateSelf_new), + DECL_API("InitializeAcl", InitializeAcl_new), + DECL_API("InitializeSecurityDescriptor", InitializeSecurityDescriptor_new), + DECL_API("InitializeSid", InitializeSid_new), + DECL_API("IsValidSecurityDescriptor", IsValidSecurityDescriptor_new), + DECL_API("IsValidSid", IsValidSid_new), + DECL_API("IsWellKnownSid", IsWellKnownSid_stub), + DECL_API("LookupAccountSidA", LookupAccountSidA_new), + DECL_API("LookupAccountSidW", LookupAccountSidW_new), + DECL_API("LookupPrivilegeValueA", LookupPrivilegeValueA_new), + DECL_API("LookupPrivilegeValueW", LookupPrivilegeValueW_new), + DECL_API("MakeSelfRelativeSD", MakeSelfRelativeSD_new), + DECL_API("NotifyBootConfigStatus", NotifyBootConfigStatus_new), + DECL_API("OpenProcessToken", OpenProcessToken_new), + DECL_API("OpenThreadToken", OpenThreadToken_new), + DECL_API("PrivilegeCheck", PrivilegeCheck_new), + DECL_API("QueryServiceStatusEx", QueryServiceStatusEx_stub), + DECL_API("RegDisablePredefinedCache", RegDisablePredefinedCache_new), + DECL_API("RegOpenCurrentUser", RegOpenCurrentUser_new), + DECL_API("RegOverridePredefKey", RegOverridePredefKey_stub), + DECL_API("RegQueryValueExW", RegQueryValueExW_new), + DECL_API("RevertToSelf", RevertToSelf_new), + DECL_API("SetFileSecurityA", SetFileSecurityA_new), + DECL_API("SetFileSecurityW", SetFileSecurityW_new), + DECL_API("SetKernelObjectSecurity", SetKernelObjectSecurity_new), + DECL_API("SetSecurityDescriptorDacl", SetSecurityDescriptorDacl_new), + DECL_API("SetSecurityDescriptorGroup", SetSecurityDescriptorGroup_new), + DECL_API("SetSecurityDescriptorOwner", SetSecurityDescriptorOwner_new), + DECL_API("SetSecurityDescriptorSacl", SetSecurityDescriptorSacl_new), + DECL_API("SetThreadToken", SetThreadToken_new), + DECL_API("TraceMessage", TraceMessage_new), +/*** AUTOGENERATED APILIST NAMED EXPORTS END ***/ +}; + +#if 0 +static const apilib_unnamed_api advapi32_ordinal_apis[] = +{ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS BEGIN ***/ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS END ***/ +}; +#endif + +const apilib_api_table apitable_advapi32 = DECL_TAB("ADVAPI32.DLL", advapi32_named_apis, 0 /*advapi32_ordinal_apis*/); diff --git a/apilibs/kexbases/Advapi32/_advapi32_apilist.h b/apilibs/kexbases/Advapi32/_advapi32_apilist.h new file mode 100644 index 0000000..279899b --- /dev/null +++ b/apilibs/kexbases/Advapi32/_advapi32_apilist.h @@ -0,0 +1,109 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#ifndef _ADVAPI32_APILIST_H +#define _ADVAPI32_APILIST_H + +#include "auxdecl.h" +#include "kexcoresdk.h" + +BOOL init_advapi32(); +extern const apilib_api_table apitable_advapi32; + +/*** AUTOGENERATED APILIST DECLARATIONS BEGIN ***/ +BOOL WINAPI RegDisablePredefinedCache_new(); +LONG WINAPI RegOpenCurrentUser_new(REGSAM access, PHKEY retkey); +ULONG CDECL TraceMessage_new(ULONG64 LoggerHandle, ULONG MessageFlags, LPGUID MessageGuid, USHORT MessageNumber, ...); +STUB CryptAcquireContextW_stub; +STUB CryptEnumProvidersW_stub; +STUB CryptEnumProviderTypesW_stub; +STUB CryptGetDefaultProviderW_stub; +STUB CryptSetProviderExW_stub; +STUB CryptSetProviderW_stub; +STUB CryptSignHashW_stub; +STUB CryptVerifySignatureW_stub; +STUB ConvertSidToStringSidA_stub; +STUB ConvertStringSidToSidA_stub; +STUB ConvertSidToStringSidW_stub; +STUB ConvertStringSidToSidW_stub; +STUB RegOverridePredefKey_stub; +STUB IsWellKnownSid_stub; +STUB ConvertStringSecurityDescriptorToSecurityDescriptorA_stub; +STUB ConvertStringSecurityDescriptorToSecurityDescriptorW_stub; +STUB ConvertSecurityDescriptorToStringSecurityDescriptorA_stub; +STUB ConvertSecurityDescriptorToStringSecurityDescriptorW_stub; +STUB QueryServiceStatusEx_stub; +BOOL WINAPI OpenProcessToken_new(HANDLE ProcessHandle, DWORD DesiredAccess, HANDLE *TokenHandle); +BOOL WINAPI OpenThreadToken_new(HANDLE ThreadHandle, DWORD DesiredAccess, BOOL OpenAsSelf, HANDLE *TokenHandle); +BOOL WINAPI DuplicateTokenEx_new(HANDLE ExistingTokenHandle, DWORD dwDesiredAccess, LPSECURITY_ATTRIBUTES lpTokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType, PHANDLE DuplicateTokenHandle); +BOOL WINAPI DuplicateToken_new(HANDLE ExistingTokenHandle, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, PHANDLE DuplicateTokenHandle); +BOOL WINAPI AdjustTokenPrivileges_new(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, LPDWORD ReturnLength); +BOOL WINAPI CheckTokenMembership_new(HANDLE TokenHandle, PSID SidToCheck, PBOOL IsMember); +BOOL WINAPI GetTokenInformation_new(HANDLE token, TOKEN_INFORMATION_CLASS tokeninfoclass, LPVOID tokeninfo, DWORD tokeninfolength, LPDWORD retlen); +BOOL WINAPI SetThreadToken_new(PHANDLE thread, HANDLE token); +BOOL WINAPI AllocateAndInitializeSid_new(PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, BYTE nSubAuthorityCount, DWORD nSubAuthority0, DWORD nSubAuthority1, DWORD nSubAuthority2, DWORD nSubAuthority3, DWORD nSubAuthority4, DWORD nSubAuthority5, DWORD nSubAuthority6, DWORD nSubAuthority7, PSID *pSid); +PVOID WINAPI FreeSid_new(PSID pSid); +BOOL WINAPI CopySid_new(DWORD nDestinationSidLength, PSID pDestinationSid, PSID pSourceSid); +BOOL WINAPI IsValidSid_new(PSID pSid); +BOOL WINAPI EqualSid_new(PSID pSid1, PSID pSid2); +BOOL WINAPI EqualPrefixSid_new (PSID pSid1, PSID pSid2); +DWORD WINAPI GetSidLengthRequired_new(BYTE nSubAuthorityCount); +BOOL WINAPI InitializeSid_new (PSID pSid, PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, BYTE nSubAuthorityCount); +PSID_IDENTIFIER_AUTHORITY WINAPI GetSidIdentifierAuthority_new(PSID pSid); +PDWORD WINAPI GetSidSubAuthority_new(PSID pSid, DWORD nSubAuthority); +PUCHAR WINAPI GetSidSubAuthorityCount_new (PSID pSid); +DWORD WINAPI GetLengthSid_new (PSID pSid); +BOOL WINAPI InitializeSecurityDescriptor_new(SECURITY_DESCRIPTOR *pDescr, DWORD revision); +DWORD WINAPI GetSecurityDescriptorLength_new(SECURITY_DESCRIPTOR *pDescr); +BOOL WINAPI GetSecurityDescriptorOwner_new(SECURITY_DESCRIPTOR *pDescr, PSID *Owner, LPBOOL OwnerDefaulted); +BOOL WINAPI SetSecurityDescriptorOwner_new(PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID owner, BOOL ownerdefaulted); +BOOL WINAPI GetSecurityDescriptorGroup_new(PSECURITY_DESCRIPTOR SecurityDescriptor, PSID *Group, LPBOOL GroupDefaulted); +BOOL WINAPI SetSecurityDescriptorGroup_new (PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID group, BOOL groupdefaulted); +BOOL WINAPI IsValidSecurityDescriptor_new(PSECURITY_DESCRIPTOR pSecurityDescriptor); +BOOL WINAPI GetSecurityDescriptorDacl_new(IN PSECURITY_DESCRIPTOR pSecurityDescriptor, OUT LPBOOL lpbDaclPresent, OUT PACL *pDacl, OUT LPBOOL lpbDaclDefaulted); +BOOL WINAPI SetSecurityDescriptorDacl_new (PSECURITY_DESCRIPTOR pSecurityDescriptor, BOOL daclpresent, PACL dacl, BOOL dacldefaulted); +BOOL WINAPI GetSecurityDescriptorSacl_new(IN PSECURITY_DESCRIPTOR pSecurityDescriptor, OUT LPBOOL lpbSaclPresent, OUT PACL *pSacl, OUT LPBOOL lpbSaclDefaulted); +BOOL WINAPI SetSecurityDescriptorSacl_new (PSECURITY_DESCRIPTOR pSecurityDescriptor, BOOL saclpresent, PACL sacl, BOOL sacldefaulted); +BOOL WINAPI MakeSelfRelativeSD_new(IN PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor, IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor, IN OUT LPDWORD lpdwBufferLength); +BOOL WINAPI GetSecurityDescriptorControl_new (PSECURITY_DESCRIPTOR pSecurityDescriptor, PSECURITY_DESCRIPTOR_CONTROL pControl, LPDWORD lpdwRevision); +BOOL WINAPI InitializeAcl_new(PACL acl, DWORD size, DWORD rev); +BOOL WINAPI LookupPrivilegeValueW_new(LPCWSTR lpSystemName, LPCWSTR lpName, PLUID lpLuid); +BOOL WINAPI LookupPrivilegeValueA_new(LPCSTR lpSystemName, LPCSTR lpName, PLUID lpLuid); +BOOL WINAPI GetFileSecurityW_new(LPCWSTR lpFileName, SECURITY_INFORMATION RequestedInformation, SECURITY_DESCRIPTOR* pSecurityDescriptor, DWORD nLength, LPDWORD lpnLengthNeeded); +BOOL WINAPI GetFileSecurityA_new(LPCSTR lpFileName, SECURITY_INFORMATION RequestedInformation, SECURITY_DESCRIPTOR* pSecurityDescriptor, DWORD nLength, LPDWORD lpnLengthNeeded); +BOOL WINAPI LookupAccountSidA_new(IN LPCSTR system, IN PSID sid, OUT LPSTR account, IN OUT LPDWORD accountSize, OUT LPSTR domain, IN OUT LPDWORD domainSize, OUT PSID_NAME_USE name_use); +BOOL WINAPI LookupAccountSidW_new(IN LPCWSTR system, IN PSID sid, OUT LPWSTR account, IN OUT LPDWORD accountSize, OUT LPWSTR domain, IN OUT LPDWORD domainSize, OUT PSID_NAME_USE name_use); +BOOL WINAPI SetFileSecurityA_new(LPCSTR lpFileName, SECURITY_INFORMATION RequestedInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor); +BOOL WINAPI SetFileSecurityW_new(LPCWSTR lpFileName, SECURITY_INFORMATION RequestedInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor); +BOOL WINAPI NotifyBootConfigStatus_new(BOOL x1); +BOOL WINAPI RevertToSelf_new(void); +BOOL WINAPI ImpersonateSelf_new(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel); +BOOL WINAPI AccessCheck_new(PSECURITY_DESCRIPTOR SecurityDescriptor, HANDLE ClientToken, DWORD DesiredAccess, PGENERIC_MAPPING GenericMapping, PPRIVILEGE_SET PrivilegeSet, LPDWORD PrivilegeSetLength, LPDWORD GrantedAccess, LPBOOL AccessStatus); +BOOL WINAPI SetKernelObjectSecurity_new (IN HANDLE Handle, IN SECURITY_INFORMATION SecurityInformation, IN PSECURITY_DESCRIPTOR SecurityDescriptor); +BOOL WINAPI PrivilegeCheck_new(HANDLE ClientToken, PPRIVILEGE_SET RequiredPrivileges, LPBOOL pfResult); +BOOL WINAPI AddAccessAllowedAce_new(IN OUT PACL pAcl, IN DWORD dwAceRevision, IN DWORD AccessMask, IN PSID pSid); +BOOL WINAPI GetAce_new(PACL pAcl,DWORD dwAceIndex,LPVOID *pAce); +BOOL WINAPI CreateRestrictedToken_new(HANDLE baseToken, DWORD flags, DWORD nDisableSids, PSID_AND_ATTRIBUTES disableSids, DWORD nDeletePrivs, PLUID_AND_ATTRIBUTES deletePrivs, DWORD nRestrictSids, PSID_AND_ATTRIBUTES restrictSids, PHANDLE newToken); +BOOL WINAPI CreateWellKnownSid_new(DWORD WellKnownSidType, PSID DomainSid, PSID pSid, DWORD* cbSid); +LONG WINAPI RegQueryValueExW_new(HKEY hKey, LPCWSTR lpValueNameW, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData); +/*** AUTOGENERATED APILIST DECLARATIONS END ***/ + +#endif diff --git a/apilibs/kexbases/Advapi32/_advapi32_stubs.c b/apilibs/kexbases/Advapi32/_advapi32_stubs.c new file mode 100644 index 0000000..93b74d1 --- /dev/null +++ b/apilibs/kexbases/Advapi32/_advapi32_stubs.c @@ -0,0 +1,46 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" + +UNIMPL_FUNC(CryptAcquireContextW, 5); //all MSLU does is to load this function from advapi32 so it loops... +UNIMPL_FUNC(CryptEnumProvidersW, 6); //so it loops... +UNIMPL_FUNC(CryptEnumProviderTypesW, 6); //so it loops... +UNIMPL_FUNC(CryptGetDefaultProviderW, 5); //so it loops... +UNIMPL_FUNC(CryptSetProviderExW, 4); //... +UNIMPL_FUNC(CryptSetProviderW, 2); //... +UNIMPL_FUNC(CryptSignHashW, 6); //... +UNIMPL_FUNC(CryptVerifySignatureW, 6); //... + +UNIMPL_FUNC(ConvertSidToStringSidA, 2); +UNIMPL_FUNC(ConvertStringSidToSidA, 2); +UNIMPL_FUNC(ConvertSidToStringSidW, 2); +UNIMPL_FUNC(ConvertStringSidToSidW, 2); +UNIMPL_FUNC(RegOverridePredefKey, 2); +UNIMPL_FUNC(IsWellKnownSid, 2); + +UNIMPL_FUNC(ConvertStringSecurityDescriptorToSecurityDescriptorA, 4); +UNIMPL_FUNC(ConvertStringSecurityDescriptorToSecurityDescriptorW, 4); + +UNIMPL_FUNC(ConvertSecurityDescriptorToStringSecurityDescriptorA, 5); +UNIMPL_FUNC(ConvertSecurityDescriptorToStringSecurityDescriptorW, 5); + +UNIMPL_FUNC(QueryServiceStatusEx, 5); diff --git a/apilibs/kexbases/Advapi32/security.c b/apilibs/kexbases/Advapi32/security.c new file mode 100644 index 0000000..08bbb05 --- /dev/null +++ b/apilibs/kexbases/Advapi32/security.c @@ -0,0 +1,1613 @@ +/* + * Copyright 1996-1998 Marcus Meissner + * Copyright 1999, 2000 Juergen Schmied + * Copyright 2003 CodeWeavers Inc. (Ulrich Czekalla) + * Copyright 2007 Xeno86 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * The purpose of this code is NOT to add additional security + * and access rights but to satisfy some of the installers which + * check those APIs and fail with "You must have administrator rights" + * messages when those APIs are not implemented. + * The code has been borrowed from Wine project. + */ + +#include +#include +#include "common.h" +#include "_advapi32_apilist.h" + +#ifdef _MSC_VER +#pragma warning(disable:4002) +#define FIXME() ((void)0) +#define FIXMEW() ((void)0) +#else +#define FIXME(args...) +#define FIXMEW(args...) +#endif + +#define TRACE FIXME + +#ifndef SID_MAX_SUB_AUTHORITIES +#define SID_MAX_SUB_AUTHORITIES (15) /* current max subauths */ +#endif + +static void dumpLsaAttributes( PLSA_OBJECT_ATTRIBUTES oa ) +{ + if (oa) + { + TRACE("\n\tlength=%lu, rootdir=0x%08x, objectname=%s\n\tattr=0x%08lx, sid=%p qos=%p\n", + oa->Length, oa->RootDirectory, + oa->ObjectName?debugstr_w(oa->ObjectName->Buffer):"null", + oa->Attributes, oa->SecurityDescriptor, oa->SecurityQualityOfService); + } +} + +static SID const sidWorld = { SID_REVISION, 1, { SECURITY_WORLD_SID_AUTHORITY} , { SECURITY_WORLD_RID } }; + +#define WINE_SIZE_OF_WORLD_ACCESS_ACL (sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + sizeof(sidWorld) - sizeof(DWORD)) + +static void GetWorldAccessACL(PACL pACL) +{ + PACCESS_ALLOWED_ACE pACE = (PACCESS_ALLOWED_ACE) (pACL + 1); + + pACL->AclRevision = ACL_REVISION; + pACL->Sbz1 = 0; + pACL->AclSize = WINE_SIZE_OF_WORLD_ACCESS_ACL; + pACL->AceCount = 1; + pACL->Sbz2 = 0; + + pACE->Header.AceType = ACCESS_ALLOWED_ACE_TYPE; + pACE->Header.AceFlags = CONTAINER_INHERIT_ACE; + pACE->Header.AceSize = sizeof(ACCESS_ALLOWED_ACE) + sizeof(sidWorld) - sizeof(DWORD); + pACE->Mask = 0xf3ffffff; /* Everything except reserved bits */ + memcpy(&pACE->SidStart, &sidWorld, sizeof(sidWorld)); +} + +/* ############################## + ###### TOKEN FUNCTIONS ###### + ############################## +*/ + +/****************************************************************************** + * OpenProcessToken [ADVAPI32.@] + * Opens the access token associated with a process + * + * PARAMS + * ProcessHandle [I] Handle to process + * DesiredAccess [I] Desired access to process + * TokenHandle [O] Pointer to handle of open access token + * + * RETURNS STD + */ +/* MAKE_EXPORT OpenProcessToken_new=OpenProcessToken */ +BOOL WINAPI +OpenProcessToken_new( HANDLE ProcessHandle, DWORD DesiredAccess, + HANDLE *TokenHandle ) +{ + FIXME("OpenProcessToken(0x%08x,0x%08lx,%p): stub\n", + ProcessHandle,DesiredAccess, TokenHandle); + *(int*)TokenHandle = 0xcafe; + return TRUE; +} + +/****************************************************************************** + * OpenThreadToken [ADVAPI32.@] + * + * PARAMS + * thread [] + * desiredaccess [] + * openasself [] + * thandle [] + */ +/* MAKE_EXPORT OpenThreadToken_new=OpenThreadToken */ +BOOL WINAPI +OpenThreadToken_new( HANDLE ThreadHandle, DWORD DesiredAccess, + BOOL OpenAsSelf, HANDLE *TokenHandle) +{ + FIXME("OpenThreadToken(0x%08x,0x08lx,0x%08x,%p): stub\n", + ThreadHandle,DesiredAccess, OpenAsSelf, TokenHandle); + if (OpenAsSelf) return FALSE; //shlwapi hack + *(int*)TokenHandle = 0xcafe; + return TRUE; +} + +/****************************************************************************** + * DuplicateTokenEx [ADVAPI32.@] + */ +/* MAKE_EXPORT DuplicateTokenEx_new=DuplicateTokenEx */ +BOOL WINAPI DuplicateTokenEx_new( + HANDLE ExistingTokenHandle, DWORD dwDesiredAccess, + LPSECURITY_ATTRIBUTES lpTokenAttributes, + SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, + TOKEN_TYPE TokenType, + PHANDLE DuplicateTokenHandle ) +{ + FIXME("DuplicateTokenEx(0x%08x,0x%08lx,0x%08x,0x%08x,%p): stub\n", ExistingTokenHandle, dwDesiredAccess, + ImpersonationLevel, TokenType, DuplicateTokenHandle); + *DuplicateTokenHandle = ExistingTokenHandle; + + return TRUE; +} + +/****************************************************************************** + * DuplicateToken [ADVAPI32.@] + */ +/* MAKE_EXPORT DuplicateToken_new=DuplicateToken */ +BOOL WINAPI DuplicateToken_new( + HANDLE ExistingTokenHandle, + SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, + PHANDLE DuplicateTokenHandle ) +{ + return DuplicateTokenEx_new( ExistingTokenHandle, 0, NULL, ImpersonationLevel, + TokenImpersonation, DuplicateTokenHandle ); +} + +/****************************************************************************** + * AdjustTokenPrivileges [ADVAPI32.@] + * + * PARAMS + * TokenHandle [] + * DisableAllPrivileges [] + * NewState [] + * BufferLength [] + * PreviousState [] + * ReturnLength [] + */ +/* MAKE_EXPORT AdjustTokenPrivileges_new=AdjustTokenPrivileges */ +BOOL WINAPI +AdjustTokenPrivileges_new( HANDLE TokenHandle, BOOL DisableAllPrivileges, + PTOKEN_PRIVILEGES NewState, DWORD BufferLength, + PTOKEN_PRIVILEGES PreviousState, LPDWORD ReturnLength ) +{ + FIXME("AdjustTokenPrivileges(0x%08x,0x%08x,%p,0x%08lx,%p,%p),stub!\n", + TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength); + return TRUE; +} + +/****************************************************************************** + * CheckTokenMembership [ADVAPI32.@] + * + * PARAMS + * TokenHandle [] + * SidToCheck [] + * IsMember [] + */ +/* MAKE_EXPORT CheckTokenMembership_new=CheckTokenMembership */ +BOOL WINAPI +CheckTokenMembership_new( HANDLE TokenHandle, PSID SidToCheck, + PBOOL IsMember ) +{ + FIXME("CheckTokenMembership(0x%08x %p %p) stub!\n", TokenHandle, SidToCheck, IsMember); + + *IsMember = TRUE; + return TRUE; +} + +/****************************************************************************** + * GetTokenInformation [ADVAPI32.@] + * + * PARAMS + * token [] + * tokeninfoclass [] + * tokeninfo [] + * tokeninfolength [] + * retlen [] + * + */ +/* MAKE_EXPORT GetTokenInformation_new=GetTokenInformation */ +BOOL WINAPI +GetTokenInformation_new( HANDLE token, TOKEN_INFORMATION_CLASS tokeninfoclass, + LPVOID tokeninfo, DWORD tokeninfolength, LPDWORD retlen ) +{ + unsigned int len = 0; + + FIXME("GetTokenInformation(%08x,%ld,%p,%ld,%p): stub\n", + token,tokeninfoclass,tokeninfo,tokeninfolength,retlen); + + switch (tokeninfoclass) + { + case TokenUser: + len = sizeof(TOKEN_USER) + sizeof(SID); + break; + case TokenGroups: + len = sizeof(TOKEN_GROUPS); + break; + case TokenOwner: + len = sizeof(TOKEN_OWNER) + sizeof(SID); + break; + case TokenPrimaryGroup: + len = sizeof(TOKEN_PRIMARY_GROUP); + break; + case TokenDefaultDacl: + len = sizeof(TOKEN_DEFAULT_DACL); + break; + case TokenSource: + len = sizeof(TOKEN_SOURCE); + break; + case TokenType: + len = sizeof (TOKEN_TYPE); + break; +#if 0 + case TokenImpersonationLevel: + case TokenStatistics: +#endif /* 0 */ + } + + if (retlen) *retlen = len; + + if (tokeninfolength < len) + { + SetLastError(ERROR_INSUFFICIENT_BUFFER); + return FALSE; + } + + switch (tokeninfoclass) + { + case TokenUser: + if( tokeninfo ) + { + TOKEN_USER * tuser = (TOKEN_USER*) tokeninfo; + PSID sid = (PSID) (tuser + 1); + SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY}; + InitializeSid_new(sid, &localSidAuthority, 1); + *(GetSidSubAuthority_new(sid, 0)) = SECURITY_INTERACTIVE_RID; + tuser->User.Sid = sid; + } + break; + case TokenGroups: + if (tokeninfo) + { + TOKEN_GROUPS *tgroups = (TOKEN_GROUPS*) tokeninfo; + SID_IDENTIFIER_AUTHORITY sid = {SECURITY_NT_AUTHORITY}; + + /* we need to show admin privileges ! */ + tgroups->GroupCount = 1; + tgroups->Groups->Attributes = SE_GROUP_ENABLED; + AllocateAndInitializeSid_new(&sid, + 2, + SECURITY_BUILTIN_DOMAIN_RID, + DOMAIN_ALIAS_RID_ADMINS, + 0, 0, 0, 0, 0, 0, + &(tgroups->Groups->Sid)); + } + break; + case TokenPrimaryGroup: + if (tokeninfo) + { + TOKEN_PRIMARY_GROUP *tgroup = (TOKEN_PRIMARY_GROUP*) tokeninfo; + SID_IDENTIFIER_AUTHORITY sid = {SECURITY_NT_AUTHORITY}; + AllocateAndInitializeSid_new( &sid, + 2, + SECURITY_BUILTIN_DOMAIN_RID, + DOMAIN_ALIAS_RID_ADMINS, + 0, 0, 0, 0, 0, 0, + &(tgroup->PrimaryGroup)); + } + break; + case TokenPrivileges: + { + TOKEN_PRIVILEGES *tpriv = (TOKEN_PRIVILEGES*) tokeninfo; + + len = FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges) + 0 * sizeof(LUID_AND_ATTRIBUTES); + if (retlen) *retlen = len; + if (tokeninfolength < len) + { + SetLastError(ERROR_INSUFFICIENT_BUFFER); + return FALSE; + } + if (tpriv) tpriv->PrivilegeCount = 0; + } + break; + case TokenOwner: + if (tokeninfo) + { + TOKEN_OWNER *owner = (TOKEN_OWNER*) tokeninfo; + PSID sid = (PSID) (owner + 1); + SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY}; + InitializeSid_new(sid, &localSidAuthority, 1); + *(GetSidSubAuthority_new(sid, 0)) = SECURITY_INTERACTIVE_RID; + owner->Owner = sid; + } + break; + default: + { + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; + } + } + return TRUE; +} + +/************************************************************************* + * SetThreadToken [ADVAPI32.@] + * + * Assigns an "impersonation token" to a thread so it can assume the + * security privledges of another thread or process. Can also remove + * a previously assigned token. Only supported on NT - it's a stub + * exactly like this one on Win9X. + * + */ +/* MAKE_EXPORT SetThreadToken_new=SetThreadToken */ +BOOL WINAPI SetThreadToken_new(PHANDLE thread, HANDLE token) +{ + FIXME("SetThreadToken(%p,%08x): stub\n", thread, token); + return TRUE; +} + +/* ############################## + ###### SID FUNCTIONS ###### + ############################## +*/ + +/****************************************************************************** + * AllocateAndInitializeSid [ADVAPI32.@] + * + * PARAMS + * pIdentifierAuthority [] + * nSubAuthorityCount [] + * nSubAuthority0 [] + * nSubAuthority1 [] + * nSubAuthority2 [] + * nSubAuthority3 [] + * nSubAuthority4 [] + * nSubAuthority5 [] + * nSubAuthority6 [] + * nSubAuthority7 [] + * pSid [] + */ +/* MAKE_EXPORT AllocateAndInitializeSid_new=AllocateAndInitializeSid */ +BOOL WINAPI +AllocateAndInitializeSid_new( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, + BYTE nSubAuthorityCount, + DWORD nSubAuthority0, DWORD nSubAuthority1, + DWORD nSubAuthority2, DWORD nSubAuthority3, + DWORD nSubAuthority4, DWORD nSubAuthority5, + DWORD nSubAuthority6, DWORD nSubAuthority7, + PSID *pSid ) +{ + SID *tmp_sid; + + TRACE("AllocateAndInitializeSid(%p, 0x%04x,0x%08x,0x%08x,0x%08x,0x%08x,0x%08x,0x%08x,0x%08x,0x%08x,%p)\n", + pIdentifierAuthority,nSubAuthorityCount, + nSubAuthority0, nSubAuthority1, nSubAuthority2, nSubAuthority3, + nSubAuthority4, nSubAuthority5, nSubAuthority6, nSubAuthority7, pSid); + + if (nSubAuthorityCount > 8) + { + SetLastError(ERROR_INVALID_SID); + return FALSE; + } + + if (!(tmp_sid= (SID*) HeapAlloc( GetProcessHeap(), 0, + GetSidLengthRequired_new(nSubAuthorityCount)))) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; + } + + tmp_sid->Revision = SID_REVISION; + + if (pIdentifierAuthority) + memcpy(&tmp_sid->IdentifierAuthority, pIdentifierAuthority, sizeof(SID_IDENTIFIER_AUTHORITY)); + tmp_sid->SubAuthorityCount = nSubAuthorityCount; + + switch( nSubAuthorityCount ) + { + case 8: tmp_sid->SubAuthority[7]= nSubAuthority7; + case 7: tmp_sid->SubAuthority[6]= nSubAuthority6; + case 6: tmp_sid->SubAuthority[5]= nSubAuthority5; + case 5: tmp_sid->SubAuthority[4]= nSubAuthority4; + case 4: tmp_sid->SubAuthority[3]= nSubAuthority3; + case 3: tmp_sid->SubAuthority[2]= nSubAuthority2; + case 2: tmp_sid->SubAuthority[1]= nSubAuthority1; + case 1: tmp_sid->SubAuthority[0]= nSubAuthority0; + break; + } + *pSid = tmp_sid; + return TRUE; +} + +/****************************************************************************** + * FreeSid [ADVAPI32.@] + * + * PARAMS + * pSid [] + */ +/* MAKE_EXPORT FreeSid_new=FreeSid */ +PVOID WINAPI +FreeSid_new( PSID pSid ) +{ + TRACE("FreeSid(%p)\n", pSid); + HeapFree( GetProcessHeap(), 0, pSid ); + return NULL; /* is documented like this */ +} + +/****************************************************************************** + * CopySid [ADVAPI32.@] + * + * PARAMS + * nDestinationSidLength [] + * pDestinationSid [] + * pSourceSid [] + */ +/* MAKE_EXPORT CopySid_new=CopySid */ +BOOL WINAPI +CopySid_new( DWORD nDestinationSidLength, PSID pDestinationSid, PSID pSourceSid ) +{ + if (!IsValidSid_new(pSourceSid) || + (nDestinationSidLength < GetLengthSid_new(pSourceSid))) + return FALSE; + + if (nDestinationSidLength < (((SID*)pSourceSid)->SubAuthorityCount*4+8)) + return FALSE; + + memmove(pDestinationSid, pSourceSid, ((SID*)pSourceSid)->SubAuthorityCount*4+8); + return TRUE; +} + +/****************************************************************************** + * IsValidSid [ADVAPI32.@] + * + * PARAMS + * pSid [] + */ +/* MAKE_EXPORT IsValidSid_new=IsValidSid */ +BOOL WINAPI +IsValidSid_new( PSID pSid ) +{ + if (!pSid || IsBadWritePtr(pSid, sizeof(SID)) || ((SID*)pSid)->Revision != SID_REVISION || + ((SID*)pSid)->SubAuthorityCount > SID_MAX_SUB_AUTHORITIES) + { + return FALSE; + } + return TRUE; +} + +/****************************************************************************** + * EqualSid [ADVAPI32.@] + * + * PARAMS + * pSid1 [] + * pSid2 [] + */ +/* MAKE_EXPORT EqualSid_new=EqualSid */ +BOOL WINAPI +EqualSid_new( PSID pSid1, PSID pSid2 ) +{ + if (!IsValidSid_new(pSid1) || !IsValidSid_new(pSid2)) + return FALSE; + + if (*GetSidSubAuthorityCount_new(pSid1) != *GetSidSubAuthorityCount_new(pSid2)) + return FALSE; + + if (memcmp(pSid1, pSid2, GetLengthSid_new(pSid1)) != 0) + return FALSE; + + return TRUE; +} + +/****************************************************************************** + * EqualPrefixSid [ADVAPI32.@] + */ +/* MAKE_EXPORT EqualPrefixSid_new=EqualPrefixSid */ +BOOL WINAPI EqualPrefixSid_new (PSID pSid1, PSID pSid2) +{ + if (!IsValidSid_new(pSid1) || !IsValidSid_new(pSid2)) + return FALSE; + + if (*GetSidSubAuthorityCount_new(pSid1) != *GetSidSubAuthorityCount_new(pSid2)) + return FALSE; + + if (memcmp(pSid1, pSid2, GetSidLengthRequired_new(((SID*)pSid1)->SubAuthorityCount - 1)) != 0) + return FALSE; + + return TRUE; +} + +/****************************************************************************** + * GetSidLengthRequired [ADVAPI32.@] + * + * PARAMS + * nSubAuthorityCount [] + */ +/* MAKE_EXPORT GetSidLengthRequired_new=GetSidLengthRequired */ +DWORD WINAPI +GetSidLengthRequired_new( BYTE nSubAuthorityCount ) +{ + return (nSubAuthorityCount-1)*sizeof(DWORD) + sizeof(SID); +} + +/****************************************************************************** + * InitializeSid [ADVAPI32.@] + * + * PARAMS + * pIdentifierAuthority [] + */ +/* MAKE_EXPORT InitializeSid_new=InitializeSid */ +BOOL WINAPI +InitializeSid_new ( + PSID pSid, + PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, + BYTE nSubAuthorityCount) +{ + int i; + SID* pisid=(SID*)pSid; + + if (nSubAuthorityCount >= SID_MAX_SUB_AUTHORITIES) + return FALSE; + + pisid->Revision = SID_REVISION; + pisid->SubAuthorityCount = nSubAuthorityCount; + if (pIdentifierAuthority) + memcpy(&pisid->IdentifierAuthority, pIdentifierAuthority, sizeof (SID_IDENTIFIER_AUTHORITY)); + + for (i = 0; i < nSubAuthorityCount; i++) + *GetSidSubAuthority_new(pSid, i) = 0; + + return TRUE; +} + +/****************************************************************************** + * GetSidIdentifierAuthority [ADVAPI32.@] + * + * PARAMS + * pSid [] + */ +/* MAKE_EXPORT GetSidIdentifierAuthority_new=GetSidIdentifierAuthority */ +PSID_IDENTIFIER_AUTHORITY WINAPI +GetSidIdentifierAuthority_new( PSID pSid ) +{ + return &(((SID*)pSid)->IdentifierAuthority); +} + +/****************************************************************************** + * GetSidSubAuthority [ADVAPI32.@] + * + * PARAMS + * pSid [] + * nSubAuthority [] + */ +/* MAKE_EXPORT GetSidSubAuthority_new=GetSidSubAuthority */ +PDWORD WINAPI +GetSidSubAuthority_new( PSID pSid, DWORD nSubAuthority ) +{ + return &(((SID*)pSid)->SubAuthority[nSubAuthority]); +} + +/****************************************************************************** + * GetSidSubAuthorityCount [ADVAPI32.@] + * + * PARAMS + * pSid [] + */ +/* MAKE_EXPORT GetSidSubAuthorityCount_new=GetSidSubAuthorityCount */ +PUCHAR WINAPI +GetSidSubAuthorityCount_new (PSID pSid) +{ + return &(((SID*)pSid)->SubAuthorityCount); +} + +/****************************************************************************** + * GetLengthSid [ADVAPI32.@] + * + * PARAMS + * pSid [] + */ +/* MAKE_EXPORT GetLengthSid_new=GetLengthSid */ +DWORD WINAPI +GetLengthSid_new (PSID pSid) +{ + TRACE("sid=%p\n",pSid); + if (!pSid) return 0; + return GetSidLengthRequired_new(*GetSidSubAuthorityCount_new(pSid)); +} + +/* ############################################## + ###### SECURITY DESCRIPTOR FUNCTIONS ###### + ############################################## +*/ + +/****************************************************************************** + * InitializeSecurityDescriptor [ADVAPI32.@] + * + * PARAMS + * pDescr [] + * revision [] + */ +/* MAKE_EXPORT InitializeSecurityDescriptor_new=InitializeSecurityDescriptor */ +BOOL WINAPI +InitializeSecurityDescriptor_new( SECURITY_DESCRIPTOR *pDescr, DWORD revision ) +{ + if (revision!=SECURITY_DESCRIPTOR_REVISION) + { + SetLastError(ERROR_UNKNOWN_REVISION); + return FALSE; + } + memset(pDescr,'\0',sizeof(*pDescr)); + pDescr->Revision = SECURITY_DESCRIPTOR_REVISION; + return TRUE; +} + +/****************************************************************************** + * GetSecurityDescriptorLength [ADVAPI32.@] + */ +/* MAKE_EXPORT GetSecurityDescriptorLength_new=GetSecurityDescriptorLength */ +DWORD WINAPI GetSecurityDescriptorLength_new( SECURITY_DESCRIPTOR *pDescr) +{ + SECURITY_DESCRIPTOR* lpsd=pDescr; + ULONG offset = 0; + ULONG Size = SECURITY_DESCRIPTOR_MIN_LENGTH; + + if ( lpsd == NULL ) + return 0; + + if ( lpsd->Control & SE_SELF_RELATIVE) + offset = (ULONG) lpsd; + + if ( lpsd->Owner != NULL ) + Size += GetLengthSid_new((PSID)((LPBYTE)lpsd->Owner + offset)); + + if ( lpsd->Group != NULL ) + Size += GetLengthSid_new((PSID)((LPBYTE)lpsd->Group + offset)); + + if ( (lpsd->Control & SE_SACL_PRESENT) && + lpsd->Sacl != NULL ) + Size += ((PACL)((LPBYTE)lpsd->Sacl + offset))->AclSize; + + if ( (lpsd->Control & SE_DACL_PRESENT) && + lpsd->Dacl != NULL ) + Size += ((PACL)((LPBYTE)lpsd->Dacl + offset))->AclSize; + + return Size; +} + +/****************************************************************************** + * GetSecurityDescriptorOwner [ADVAPI32.@] + * + * PARAMS + * pOwner [] + * lpbOwnerDefaulted [] + */ +/* MAKE_EXPORT GetSecurityDescriptorOwner_new=GetSecurityDescriptorOwner */ +BOOL WINAPI +GetSecurityDescriptorOwner_new( SECURITY_DESCRIPTOR *pDescr, PSID *Owner, + LPBOOL OwnerDefaulted ) +{ + SECURITY_DESCRIPTOR* lpsd=pDescr; + + TRACE("GetSecurityDescriptorOwner(%p,%p,%p)\n"); + + if ( !lpsd || !Owner || !OwnerDefaulted ) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + if (lpsd->Owner != NULL) + { + if (lpsd->Control & SE_SELF_RELATIVE) + *Owner = (PSID)((LPBYTE)lpsd + + (ULONG)lpsd->Owner); + else + *Owner = lpsd->Owner; + + if ( lpsd->Control & SE_OWNER_DEFAULTED ) + *OwnerDefaulted = TRUE; + else + *OwnerDefaulted = FALSE; + } + else + *Owner = NULL; + + return TRUE; +} + +/****************************************************************************** + * SetSecurityDescriptorOwner [ADVAPI32.@] + * + * PARAMS + */ +/* MAKE_EXPORT SetSecurityDescriptorOwner_new=SetSecurityDescriptorOwner */ +BOOL WINAPI SetSecurityDescriptorOwner_new( PSECURITY_DESCRIPTOR pSecurityDescriptor, + PSID owner, BOOL ownerdefaulted) +{ + SECURITY_DESCRIPTOR* lpsd=(SECURITY_DESCRIPTOR*)pSecurityDescriptor; + + if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION) + { + SetLastError(ERROR_UNKNOWN_REVISION); + return FALSE; + } + if (lpsd->Control & SE_SELF_RELATIVE) + { + SetLastError(ERROR_INVALID_SECURITY_DESCR); + return FALSE; + } + + lpsd->Owner = owner; + if (ownerdefaulted) + lpsd->Control |= SE_OWNER_DEFAULTED; + else + lpsd->Control &= ~SE_OWNER_DEFAULTED; + return TRUE; +} +/****************************************************************************** + * GetSecurityDescriptorGroup [ADVAPI32.@] + */ +/* MAKE_EXPORT GetSecurityDescriptorGroup_new=GetSecurityDescriptorGroup */ +BOOL WINAPI GetSecurityDescriptorGroup_new( + PSECURITY_DESCRIPTOR SecurityDescriptor, + PSID *Group, + LPBOOL GroupDefaulted) +{ + SECURITY_DESCRIPTOR* lpsd=(SECURITY_DESCRIPTOR*)SecurityDescriptor; + + TRACE("GetSecurityDescriptorGroup(%p,%p,%p)\n"); + + if ( !lpsd || !Group || !GroupDefaulted ) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + if (lpsd->Group != NULL) + { + if (lpsd->Control & SE_SELF_RELATIVE) + *Group = (PSID)((LPBYTE)lpsd + + (ULONG)lpsd->Group); + else + *Group = lpsd->Group; + + if ( lpsd->Control & SE_GROUP_DEFAULTED ) + *GroupDefaulted = TRUE; + else + *GroupDefaulted = FALSE; + } + else + *Group = NULL; + + return TRUE; +} +/****************************************************************************** + * SetSecurityDescriptorGroup [ADVAPI32.@] + */ +/* MAKE_EXPORT SetSecurityDescriptorGroup_new=SetSecurityDescriptorGroup */ +BOOL WINAPI SetSecurityDescriptorGroup_new ( PSECURITY_DESCRIPTOR pSecurityDescriptor, + PSID group, BOOL groupdefaulted) +{ + SECURITY_DESCRIPTOR* lpsd=(SECURITY_DESCRIPTOR*)pSecurityDescriptor; + + if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION) + { + SetLastError(ERROR_UNKNOWN_REVISION); + return FALSE; + } + if (lpsd->Control & SE_SELF_RELATIVE) + { + SetLastError(ERROR_INVALID_SECURITY_DESCR); + return FALSE; + } + + lpsd->Group = group; + if (groupdefaulted) + lpsd->Control |= SE_GROUP_DEFAULTED; + else + lpsd->Control &= ~SE_GROUP_DEFAULTED; + return TRUE; +} + +/****************************************************************************** + * IsValidSecurityDescriptor [ADVAPI32.@] + * + * PARAMS + * lpsecdesc [] + */ +/* MAKE_EXPORT IsValidSecurityDescriptor_new=IsValidSecurityDescriptor */ +BOOL WINAPI +IsValidSecurityDescriptor_new( PSECURITY_DESCRIPTOR pSecurityDescriptor ) +{ + SECURITY_DESCRIPTOR* lpsd=(SECURITY_DESCRIPTOR*)pSecurityDescriptor; + + if ( ! pSecurityDescriptor ) + { + SetLastError(ERROR_INVALID_SECURITY_DESCR); + return FALSE; + } + if ( lpsd->Revision != SECURITY_DESCRIPTOR_REVISION ) + { + SetLastError(ERROR_UNKNOWN_REVISION); + return FALSE; + } + + return TRUE; +} + +/***************************************************************************** + * GetSecurityDescriptorDacl [ADVAPI32.@] + */ +/* MAKE_EXPORT GetSecurityDescriptorDacl_new=GetSecurityDescriptorDacl */ +BOOL WINAPI GetSecurityDescriptorDacl_new( + IN PSECURITY_DESCRIPTOR pSecurityDescriptor, + OUT LPBOOL lpbDaclPresent, + OUT PACL *pDacl, + OUT LPBOOL lpbDaclDefaulted) +{ + SECURITY_DESCRIPTOR* lpsd=(SECURITY_DESCRIPTOR*)pSecurityDescriptor; + + TRACE("GetSecurityDescriptorDacl(%p,%p,%p,%p)\n", + pSecurityDescriptor, lpbDaclPresent, pDacl, lpbDaclDefaulted); + + if (lpsd->Revision != SECURITY_DESCRIPTOR_REVISION) + { + SetLastError(ERROR_UNKNOWN_REVISION); + return FALSE; + } + + if ( (*lpbDaclPresent = (SE_DACL_PRESENT & lpsd->Control) ? 1 : 0) ) + { + if ( SE_SELF_RELATIVE & lpsd->Control) + *pDacl = (PACL) ((LPBYTE)lpsd + (DWORD)lpsd->Dacl); + else + *pDacl = lpsd->Dacl; + + *lpbDaclDefaulted = (( SE_DACL_DEFAULTED & lpsd->Control ) ? 1 : 0); + } + + return TRUE; +} + +/****************************************************************************** + * SetSecurityDescriptorDacl [ADVAPI32.@] + */ +/* MAKE_EXPORT SetSecurityDescriptorDacl_new=SetSecurityDescriptorDacl */ +BOOL WINAPI +SetSecurityDescriptorDacl_new ( + PSECURITY_DESCRIPTOR pSecurityDescriptor, + BOOL daclpresent, + PACL dacl, + BOOL dacldefaulted ) +{ + SECURITY_DESCRIPTOR* lpsd=(SECURITY_DESCRIPTOR*)pSecurityDescriptor; + + if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION) + { + SetLastError(ERROR_UNKNOWN_REVISION); + return FALSE; + } + if (lpsd->Control & SE_SELF_RELATIVE) + { + SetLastError(ERROR_INVALID_SECURITY_DESCR); + return FALSE; + } + + if (!daclpresent) + { lpsd->Control &= ~SE_DACL_PRESENT; + return TRUE; + } + + lpsd->Control |= SE_DACL_PRESENT; + lpsd->Dacl = dacl; + + if (dacldefaulted) + lpsd->Control |= SE_DACL_DEFAULTED; + else + lpsd->Control &= ~SE_DACL_DEFAULTED; + + return TRUE; +} +/****************************************************************************** + * GetSecurityDescriptorSacl [ADVAPI32.@] + */ +/* MAKE_EXPORT GetSecurityDescriptorSacl_new=GetSecurityDescriptorSacl */ +BOOL WINAPI GetSecurityDescriptorSacl_new( + IN PSECURITY_DESCRIPTOR pSecurityDescriptor, + OUT LPBOOL lpbSaclPresent, + OUT PACL *pSacl, + OUT LPBOOL lpbSaclDefaulted) +{ + SECURITY_DESCRIPTOR* lpsd=(SECURITY_DESCRIPTOR*)pSecurityDescriptor; + + TRACE("GetSecurityDescriptorSacl(%p,%p,%p,%p)\n", + lpsd, lpbSaclPresent, *pSacl, lpbSaclDefaulted); + + if (lpsd->Revision != SECURITY_DESCRIPTOR_REVISION) + { + SetLastError(ERROR_UNKNOWN_REVISION); + return FALSE; + } + + if ( (*lpbSaclPresent = (SE_SACL_PRESENT & lpsd->Control) ? 1 : 0) ) + { + if (SE_SELF_RELATIVE & lpsd->Control) + *pSacl = (PACL) ((LPBYTE)lpsd + (DWORD)lpsd->Sacl); + else + *pSacl = lpsd->Sacl; + + *lpbSaclDefaulted = (( SE_SACL_DEFAULTED & lpsd->Control ) ? 1 : 0); + } + + return TRUE; +} + +/************************************************************************** + * SetSecurityDescriptorSacl [ADVAPI32.@] + */ +/* MAKE_EXPORT SetSecurityDescriptorSacl_new=SetSecurityDescriptorSacl */ +BOOL WINAPI SetSecurityDescriptorSacl_new ( + PSECURITY_DESCRIPTOR pSecurityDescriptor, + BOOL saclpresent, + PACL sacl, + BOOL sacldefaulted) +{ + SECURITY_DESCRIPTOR* lpsd=(SECURITY_DESCRIPTOR*)pSecurityDescriptor; + + if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION) + { + SetLastError(ERROR_UNKNOWN_REVISION); + return FALSE; + } + if (lpsd->Control & SE_SELF_RELATIVE) + { + SetLastError(ERROR_INVALID_SECURITY_DESCR); + return FALSE; + } + if (!saclpresent) { + lpsd->Control &= ~SE_SACL_PRESENT; + return TRUE; + } + lpsd->Control |= SE_SACL_PRESENT; + lpsd->Sacl = sacl; + if (sacldefaulted) + lpsd->Control |= SE_SACL_DEFAULTED; + else + lpsd->Control &= ~SE_SACL_DEFAULTED; + return TRUE; +} +/****************************************************************************** + * MakeSelfRelativeSD [ADVAPI32.@] + * + * PARAMS + * lpabssecdesc [] + * lpselfsecdesc [] + * lpbuflen [] + */ +/* MAKE_EXPORT MakeSelfRelativeSD_new=MakeSelfRelativeSD */ +BOOL WINAPI +MakeSelfRelativeSD_new( + IN PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor, + IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor, + IN OUT LPDWORD lpdwBufferLength) +{ + FIXME("MakeSelfRelativeSD(%p,%p,%p(%lu))\n", pAbsoluteSecurityDescriptor, + pSelfRelativeSecurityDescriptor, lpdwBufferLength,*lpdwBufferLength); + return TRUE; +} + +/****************************************************************************** + * GetSecurityDescriptorControl [ADVAPI32.@] + */ +/* MAKE_EXPORT GetSecurityDescriptorControl_new=GetSecurityDescriptorControl */ +BOOL WINAPI GetSecurityDescriptorControl_new ( PSECURITY_DESCRIPTOR pSecurityDescriptor, + PSECURITY_DESCRIPTOR_CONTROL pControl, LPDWORD lpdwRevision) +{ + SECURITY_DESCRIPTOR *lpsd = (SECURITY_DESCRIPTOR*) pSecurityDescriptor; + + TRACE("GetSecurityDescriptorControl(%p,%p,%p)\n",pSecurityDescriptor,pControl,lpdwRevision); + + *lpdwRevision = lpsd->Revision; + + if (*lpdwRevision != SECURITY_DESCRIPTOR_REVISION) + { + SetLastError(ERROR_UNKNOWN_REVISION); + return FALSE; + } + + *pControl = lpsd->Control; + + return TRUE; +} + +/* ############################## + ###### ACL FUNCTIONS ###### + ############################## +*/ + +/************************************************************************* + * InitializeAcl [ADVAPI32.@] + */ +/* MAKE_EXPORT InitializeAcl_new=InitializeAcl */ +BOOL WINAPI InitializeAcl_new(PACL acl, DWORD size, DWORD rev) +{ + TRACE("InitializeAcl(%p 0x%08x 0x%08x)\n", acl, size, rev); + + if (rev!=ACL_REVISION) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + if (size0xFFFF) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + memset(acl,'\0',sizeof(ACL)); + acl->AclRevision = rev; + acl->AclSize = size; + acl->AceCount = 0; + return TRUE; +} + +/* ############################## + ###### MISC FUNCTIONS ###### + ############################## +*/ + +/****************************************************************************** + * LookupPrivilegeValueW [ADVAPI32.@] !!20040505 + * Retrieves LUID used on a system to represent the privilege name. + * + * NOTES + * lpLuid should be PLUID + * + * PARAMS + * lpSystemName [I] Address of string specifying the system + * lpName [I] Address of string specifying the privilege + * lpLuid [I] Address of locally unique identifier + * + * RETURNS STD + */ +/* MAKE_EXPORT LookupPrivilegeValueW_new=LookupPrivilegeValueW */ +BOOL WINAPI +LookupPrivilegeValueW_new( LPCWSTR lpSystemName, LPCWSTR lpName, PLUID lpLuid ) +{ + FIXMEW("LookupPrivilegeValueW(%s,%s,%p): stub\n", lpSystemName, + lpName, lpLuid); + return TRUE; +} + +/****************************************************************************** + * LookupPrivilegeValueA [ADVAPI32.@] + */ +/* MAKE_EXPORT LookupPrivilegeValueA_new=LookupPrivilegeValueA */ +BOOL WINAPI +LookupPrivilegeValueA_new( LPCSTR lpSystemName, LPCSTR lpName, PLUID lpLuid ) +{ + FIXME("LookupPrivilegeValueA(%s,%s,%p): stub\n", lpSystemName, + lpName, lpLuid); + return TRUE; +} + +/****************************************************************************** + * GetFileSecurityW [ADVAPI32.@] + * + * Obtains Specified information about the security of a file or directory + * The information obtained is constrained by the callers access rights and + * privileges + * + * PARAMS + * lpFileName [] + * RequestedInformation [] + * pSecurityDescriptor [] + * nLength [] + * lpnLengthNeeded [] + */ +/* MAKE_EXPORT GetFileSecurityW_new=GetFileSecurityW */ +BOOL WINAPI +GetFileSecurityW_new( LPCWSTR lpFileName, + SECURITY_INFORMATION RequestedInformation, + SECURITY_DESCRIPTOR* pSecurityDescriptor, + DWORD nLength, LPDWORD lpnLengthNeeded ) +{ + DWORD nNeeded; + LPBYTE pBuffer; + DWORD iLocNow; + SECURITY_DESCRIPTOR_RELATIVE *pSDRelative; + + FIXMEW("GetFileSecurityW(%s) : returns fake SECURITY_DESCRIPTOR\n", lpFileName); + + nNeeded = sizeof(SECURITY_DESCRIPTOR_RELATIVE); + if (RequestedInformation & OWNER_SECURITY_INFORMATION) + nNeeded += sizeof(sidWorld); + if (RequestedInformation & GROUP_SECURITY_INFORMATION) + nNeeded += sizeof(sidWorld); + if (RequestedInformation & DACL_SECURITY_INFORMATION) + nNeeded += WINE_SIZE_OF_WORLD_ACCESS_ACL; + if (RequestedInformation & SACL_SECURITY_INFORMATION) + nNeeded += WINE_SIZE_OF_WORLD_ACCESS_ACL; + + *lpnLengthNeeded = nNeeded; + + if (nNeeded > nLength) + return TRUE; + + if (!InitializeSecurityDescriptor_new(pSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION)) + return FALSE; + + pSDRelative = (PISECURITY_DESCRIPTOR_RELATIVE) pSecurityDescriptor; + pSDRelative->Control |= SE_SELF_RELATIVE; + pBuffer = (LPBYTE) pSDRelative; + iLocNow = sizeof(SECURITY_DESCRIPTOR_RELATIVE); + + if (RequestedInformation & OWNER_SECURITY_INFORMATION) + { + memcpy(pBuffer + iLocNow, &sidWorld, sizeof(sidWorld)); + pSDRelative->Owner = iLocNow; + iLocNow += sizeof(sidWorld); + } + if (RequestedInformation & GROUP_SECURITY_INFORMATION) + { + memcpy(pBuffer + iLocNow, &sidWorld, sizeof(sidWorld)); + pSDRelative->Group = iLocNow; + iLocNow += sizeof(sidWorld); + } + if (RequestedInformation & DACL_SECURITY_INFORMATION) + { + GetWorldAccessACL((PACL) (pBuffer + iLocNow)); + pSDRelative->Dacl = iLocNow; + iLocNow += WINE_SIZE_OF_WORLD_ACCESS_ACL; + } + if (RequestedInformation & SACL_SECURITY_INFORMATION) + { + GetWorldAccessACL((PACL) (pBuffer + iLocNow)); + pSDRelative->Sacl = iLocNow; + /* iLocNow += WINE_SIZE_OF_WORLD_ACCESS_ACL; */ + } + return TRUE; +} + +/****************************************************************************** + * GetFileSecurityA [ADVAPI32.@] + * + * Obtains Specified information about the security of a file or directory + * The information obtained is constrained by the callers access rights and + * privileges + */ +/* MAKE_EXPORT GetFileSecurityA_new=GetFileSecurityA */ +BOOL WINAPI +GetFileSecurityA_new( LPCSTR lpFileName, + SECURITY_INFORMATION RequestedInformation, + SECURITY_DESCRIPTOR* pSecurityDescriptor, + DWORD nLength, LPDWORD lpnLengthNeeded ) +{ + BOOL r; + LPWSTR name = NULL; + + /*if( lpFileName ) + { + len = MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, NULL, 0 ); + name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) ); + MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, name, len ); + }*/ + + r = GetFileSecurityW_new( name, RequestedInformation, pSecurityDescriptor, + nLength, lpnLengthNeeded ); + /*HeapFree( GetProcessHeap(), 0, name );*/ + + return r; +} + +/****************************************************************************** + * LookupAccountSidA [ADVAPI32.@] + */ +/* MAKE_EXPORT LookupAccountSidA_new=LookupAccountSidA */ +BOOL WINAPI +LookupAccountSidA_new( + IN LPCSTR system, + IN PSID sid, + OUT LPSTR account, + IN OUT LPDWORD accountSize, + OUT LPSTR domain, + IN OUT LPDWORD domainSize, + OUT PSID_NAME_USE name_use ) +{ + static const char ac[] = "Administrator"; + static const char dm[] = "DOMAIN"; + FIXME("LookupAccountSidA(%s,sid=%p,%p,%p(%lu),%p,%7p(%lu),%p): semi-stub\n", + system,sid, + account,accountSize,accountSize?*accountSize:0, + domain,domainSize,domainSize?*domainSize:0, + name_use); + + if (accountSize) *accountSize = strlen(ac)+1; + if (account && (*accountSize > strlen(ac))) + strcpy(account, ac); + + if (domainSize) *domainSize = strlen(dm)+1; + if (domain && (*domainSize > strlen(dm))) + strcpy(domain,dm); + + if (name_use) *name_use = SidTypeUser; + return TRUE; +} + +/****************************************************************************** + * LookupAccountSidW [ADVAPI32.@] + * + * PARAMS + * system [] + * sid [] + * account [] + * accountSize [] + * domain [] + * domainSize [] + * name_use [] + */ +/* MAKE_EXPORT LookupAccountSidW_new=LookupAccountSidW */ +BOOL WINAPI +LookupAccountSidW_new( + IN LPCWSTR system, + IN PSID sid, + OUT LPWSTR account, + IN OUT LPDWORD accountSize, + OUT LPWSTR domain, + IN OUT LPDWORD domainSize, + OUT PSID_NAME_USE name_use ) +{ + static const WCHAR ac[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r',0}; + static const WCHAR dm[] = {'D','O','M','A','I','N',0}; + FIXMEW("LookupAccountSidW(%s,sid=%p,%p,%p(%lu),%p,%p(%lu),%p): semi-stub\n", + system,sid, + account,accountSize,accountSize?*accountSize:0, + domain,domainSize,domainSize?*domainSize:0, + name_use); + + if (accountSize) *accountSize = lstrlenW(ac)+1; + if (account && (*accountSize > lstrlenW(ac))) + lstrcpyW(account, ac); + + if (domainSize) *domainSize = lstrlenW(dm)+1; + if (domain && (*domainSize > lstrlenW(dm))) + lstrcpyW(domain,dm); + + if (name_use) *name_use = SidTypeUser; + return TRUE; +} + +/****************************************************************************** + * SetFileSecurityA [ADVAPI32.@] + * Sets the security of a file or directory + */ +/* MAKE_EXPORT SetFileSecurityA_new=SetFileSecurityA */ +BOOL WINAPI +SetFileSecurityA_new( LPCSTR lpFileName, + SECURITY_INFORMATION RequestedInformation, + PSECURITY_DESCRIPTOR pSecurityDescriptor) +{ + FIXME("SetFileSecurityA(%s) : stub\n", lpFileName); + return TRUE; +} + +/****************************************************************************** + * SetFileSecurityW [ADVAPI32.@] + * Sets the security of a file or directory + * + * PARAMS + * lpFileName [] + * RequestedInformation [] + * pSecurityDescriptor [] + */ +/* MAKE_EXPORT SetFileSecurityW_new=SetFileSecurityW */ +BOOL WINAPI +SetFileSecurityW_new( LPCWSTR lpFileName, + SECURITY_INFORMATION RequestedInformation, + PSECURITY_DESCRIPTOR pSecurityDescriptor ) +{ + FIXMEW("SetFileSecurityW(%s) : stub\n", lpFileName); + return TRUE; +} + +#if 0 /* unneeded ?? */ +/****************************************************************************** + * QueryWindows31FilesMigration [ADVAPI32.@] + * + * PARAMS + * x1 [] + */ +BOOL WINAPI +QueryWindows31FilesMigration( DWORD x1 ) +{ + FIXME("(%ld):stub\n",x1); + return TRUE; +} + +/****************************************************************************** + * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.@] + * + * PARAMS + * x1 [] + * x2 [] + * x3 [] + * x4 [] + */ +BOOL WINAPI +SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1, DWORD x2, DWORD x3, + DWORD x4 ) +{ + FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx):stub\n",x1,x2,x3,x4); + return TRUE; +} +#endif + +#if 0 /* LSA disabled */ +/****************************************************************************** + * LsaOpenPolicy [ADVAPI32.@] + * + * PARAMS + * x1 [] + * x2 [] + * x3 [] + * x4 [] + */ +NTSTATUS WINAPI +LsaOpenPolicy( + IN PLSA_UNICODE_STRING SystemName, + IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes, + IN ACCESS_MASK DesiredAccess, + IN OUT PLSA_HANDLE PolicyHandle) +{ + FIXME("(%s,%p,0x%08lx,%p):stub\n", + SystemName?debugstr_w(SystemName->Buffer):"null", + ObjectAttributes, DesiredAccess, PolicyHandle); + dumpLsaAttributes(ObjectAttributes); + if(PolicyHandle) *PolicyHandle = (LSA_HANDLE)0xcafe; + return TRUE; +} + +/****************************************************************************** + * LsaQueryInformationPolicy [ADVAPI32.@] + */ +NTSTATUS WINAPI +LsaQueryInformationPolicy( + IN LSA_HANDLE PolicyHandle, + IN POLICY_INFORMATION_CLASS InformationClass, + OUT PVOID *Buffer) +{ + FIXME("(%p,0x%08x,%p):stub\n", + PolicyHandle, InformationClass, Buffer); + + if(!Buffer) return FALSE; + switch (InformationClass) + { + case PolicyAuditEventsInformation: /* 2 */ + { + PPOLICY_AUDIT_EVENTS_INFO p = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(POLICY_AUDIT_EVENTS_INFO)); + p->AuditingMode = FALSE; /* no auditing */ + *Buffer = p; + } + break; + case PolicyPrimaryDomainInformation: /* 3 */ + case PolicyAccountDomainInformation: /* 5 */ + { + struct di + { POLICY_PRIMARY_DOMAIN_INFO ppdi; + SID sid; + }; + SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY}; + + struct di * xdi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(xdi)); + RtlInitUnicodeString(&(xdi->ppdi.Name), HEAP_strdupAtoW(GetProcessHeap(),0,"DOMAIN")); + xdi->ppdi.Sid = &(xdi->sid); + xdi->sid.Revision = SID_REVISION; + xdi->sid.SubAuthorityCount = 1; + xdi->sid.IdentifierAuthority = localSidAuthority; + xdi->sid.SubAuthority[0] = SECURITY_LOCAL_SYSTEM_RID; + *Buffer = xdi; + } + break; + case PolicyAuditLogInformation: + case PolicyPdAccountInformation: + case PolicyLsaServerRoleInformation: + case PolicyReplicaSourceInformation: + case PolicyDefaultQuotaInformation: + case PolicyModificationInformation: + case PolicyAuditFullSetInformation: + case PolicyAuditFullQueryInformation: + case PolicyDnsDomainInformation: + { + FIXME("category not implemented\n"); + return FALSE; + } + } + return TRUE; +} + +/****************************************************************************** + * LsaLookupSids [ADVAPI32.@] + */ +NTSTATUS WINAPI +LsaLookupSids( + IN LSA_HANDLE PolicyHandle, + IN ULONG Count, + IN PSID *Sids, + OUT PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains, + OUT PLSA_TRANSLATED_NAME *Names ) +{ + FIXME("%p %lu %p %p %p\n", + PolicyHandle, Count, Sids, ReferencedDomains, Names); + return FALSE; +} + +/****************************************************************************** + * LsaFreeMemory [ADVAPI32.@] + */ +NTSTATUS WINAPI +LsaFreeMemory(IN PVOID Buffer) +{ + TRACE("(%p)\n",Buffer); + return HeapFree(GetProcessHeap(), 0, Buffer); +} +/****************************************************************************** + * LsaClose [ADVAPI32.@] + */ +NTSTATUS WINAPI +LsaClose(IN LSA_HANDLE ObjectHandle) +{ + FIXME("(%p):stub\n",ObjectHandle); + return 0xc0000000; +} +#endif +/****************************************************************************** + * NotifyBootConfigStatus [ADVAPI32.@] + * + * PARAMS + * x1 [] + */ +/* MAKE_EXPORT NotifyBootConfigStatus_new=NotifyBootConfigStatus */ +BOOL WINAPI +NotifyBootConfigStatus_new( BOOL x1 ) +{ + FIXME("NotifyBootConfigStatus(0x%08x):stub\n",x1); + return TRUE; +} + +/****************************************************************************** + * RevertToSelf [ADVAPI32.@] + * + * PARAMS + * void [] + */ +/* MAKE_EXPORT RevertToSelf_new=RevertToSelf */ +BOOL WINAPI +RevertToSelf_new( void ) +{ + FIXME("RevertToSelf(), stub\n"); + return TRUE; +} + +/****************************************************************************** + * ImpersonateSelf [ADVAPI32.@] + */ +/* MAKE_EXPORT ImpersonateSelf_new=ImpersonateSelf */ +BOOL WINAPI +ImpersonateSelf_new(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel) +{ + FIXME("ImpersonateSelf(%08x), stub\n", ImpersonationLevel); + return TRUE; +} + +/****************************************************************************** + * AccessCheck [ADVAPI32.@] + * + * FIXME check cast LPBOOL to PBOOLEAN + */ +/* MAKE_EXPORT AccessCheck_new=AccessCheck */ +BOOL WINAPI +AccessCheck_new( + PSECURITY_DESCRIPTOR SecurityDescriptor, + HANDLE ClientToken, + DWORD DesiredAccess, + PGENERIC_MAPPING GenericMapping, + PPRIVILEGE_SET PrivilegeSet, + LPDWORD PrivilegeSetLength, + LPDWORD GrantedAccess, + LPBOOL AccessStatus) +{ + FIXME("AccessCheck(%p, %04x, %08lx, %p, %p, %p, %p, %p), stub\n", + SecurityDescriptor, ClientToken, DesiredAccess, GenericMapping, + PrivilegeSet, PrivilegeSetLength, GrantedAccess, AccessStatus); + *AccessStatus = TRUE; + return TRUE; +} + +/************************************************************************* + * SetKernelObjectSecurity [ADVAPI32.@] + */ +/* MAKE_EXPORT SetKernelObjectSecurity_new=SetKernelObjectSecurity */ +BOOL WINAPI +SetKernelObjectSecurity_new ( + IN HANDLE Handle, + IN SECURITY_INFORMATION SecurityInformation, + IN PSECURITY_DESCRIPTOR SecurityDescriptor ) +{ + FIXME("SetKernelObjectSecurity(0x%08x 0x%08lx %p): stub\n", Handle, SecurityInformation, SecurityDescriptor); + return TRUE; +} + +/****************************************************************************** + * PrivilegeCheck [ADVAPI32.@] + */ +/* MAKE_EXPORT PrivilegeCheck_new=PrivilegeCheck */ +BOOL WINAPI PrivilegeCheck_new( HANDLE ClientToken, PPRIVILEGE_SET RequiredPrivileges, LPBOOL pfResult) +{ + FIXME("PrivilegeCheck(%p %p %p): stub\n", ClientToken, RequiredPrivileges, pfResult); + if (pfResult) + *pfResult=TRUE; + return TRUE; +} + +/****************************************************************************** + * AddAccessAllowedAce [ADVAPI32.@] + */ +/* MAKE_EXPORT AddAccessAllowedAce_new=AddAccessAllowedAce */ +BOOL WINAPI AddAccessAllowedAce_new( + IN OUT PACL pAcl, + IN DWORD dwAceRevision, + IN DWORD AccessMask, + IN PSID pSid) +{ + FIXME("AddAccessAllowedAce(%p,0x%08lx,0x%08lx,%p),stub!\n", + pAcl, dwAceRevision, AccessMask, pSid); + return TRUE; +} + +/****************************************************************************** + * GetAce [ADVAPI32.@] + */ +/* MAKE_EXPORT GetAce_new=GetAce */ +BOOL WINAPI GetAce_new(PACL pAcl,DWORD dwAceIndex,LPVOID *pAce ) +{ + FIXME("GetAce(%p,%ld,%p),stub!\n",pAcl,dwAceIndex,pAce); + return TRUE; +} + +/************************************************************************* + * CreateRestrictedToken [ADVAPI32.@] + */ +/* MAKE_EXPORT CreateRestrictedToken_new=CreateRestrictedToken */ +BOOL WINAPI CreateRestrictedToken_new( + HANDLE baseToken, + DWORD flags, + DWORD nDisableSids, + PSID_AND_ATTRIBUTES disableSids, + DWORD nDeletePrivs, + PLUID_AND_ATTRIBUTES deletePrivs, + DWORD nRestrictSids, + PSID_AND_ATTRIBUTES restrictSids, + PHANDLE newToken) +{ + //bullshit + if (newToken) *newToken = baseToken; + return ( newToken ? TRUE : FALSE ); +} + +/****************************************************************************** + * CreateWellKnownSid [ADVAPI32.@] + */ +/* MAKE_EXPORT CreateWellKnownSid_new=CreateWellKnownSid */ +BOOL WINAPI CreateWellKnownSid_new( DWORD WellKnownSidType, PSID DomainSid, PSID pSid, DWORD* cbSid) +{ + FIXME("CreateWellKnownSid(%ld,%p,%p,%p,%p),stub!\n",WellKnownSidType,DomainSid,pSid,cbSid); + return TRUE; +} diff --git a/apilibs/kexbases/Advapi32/uniadvapi32.c b/apilibs/kexbases/Advapi32/uniadvapi32.c new file mode 100644 index 0000000..44d12fb --- /dev/null +++ b/apilibs/kexbases/Advapi32/uniadvapi32.c @@ -0,0 +1,113 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" + +//MAKE_EXPORT RegQueryValueExW_new=RegQueryValueExW +LONG WINAPI RegQueryValueExW_new(HKEY hKey, LPCWSTR lpValueNameW, LPDWORD lpReserved, + LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData) +{ + LONG ret; + DWORD type; + BYTE stackbuf[256]; + BYTE* ptr = stackbuf; + BYTE* heapbuf = NULL; + DWORD bufsize = sizeof(stackbuf); + + if ((lpData && !lpcbData) || lpReserved) return ERROR_INVALID_PARAMETER; + if (!lpData && lpcbData) *lpcbData = 0; + + //try with stack buffer first + if (lpValueNameW) + { + ALLOC_WtoA(lpValueName); + ret = RegQueryValueExA(hKey, lpValueNameA, lpReserved, &type, ptr, &bufsize); + if (lpType) *lpType = type; + if (lpcbData && type != REG_SZ && bufsize > *lpcbData) + { + *lpcbData = bufsize; + return ERROR_MORE_DATA; + } + //retry with dynamic buffer + if (ret == ERROR_MORE_DATA) + { + ptr = heapbuf = (BYTE*) HeapAlloc(GetProcessHeap(), 0, bufsize); + if (!heapbuf) + { + return ERROR_NOT_ENOUGH_MEMORY; + } + ret = RegQueryValueExA(hKey, lpValueNameA, lpReserved, &type, ptr, &bufsize); + } + } + else + { + ret = RegQueryValueExA(hKey, 0, lpReserved, &type, ptr, &bufsize); + if (lpType) *lpType = type; + if (lpcbData && type != REG_SZ && bufsize > *lpcbData) + { + *lpcbData = bufsize; + return ERROR_MORE_DATA; + } + //retry with dynamic buffer + if (ret == ERROR_MORE_DATA) + { + ptr = heapbuf = (BYTE*) HeapAlloc(GetProcessHeap(), 0, bufsize); + if (!heapbuf) + { + return ERROR_NOT_ENOUGH_MEMORY; + } + ret = RegQueryValueExA(hKey, 0, lpReserved, &type, ptr, &bufsize); + } + } + if (ret != ERROR_SUCCESS) goto _end; + + if (type == REG_SZ) + { + if (lpcbData) + { + DWORD gle = GetLastError(); + int written = MultiByteToWideChar(CP_ACP, 0, (LPSTR) ptr, -1, + (LPWSTR)lpData, lpData ? (*lpcbData >> 1) : 0); + if (!written) + { + ret = GetLastError(); + if (ret == ERROR_INSUFFICIENT_BUFFER) + { + *lpcbData = MultiByteToWideChar(CP_ACP, 0, (LPSTR) ptr, + -1, NULL, 0) << 1; + ret = ERROR_MORE_DATA; + } + SetLastError(gle); + goto _end; + } + *lpcbData = written << 1; + } + } + else + { + if (lpData) memcpy(lpData, ptr, bufsize); + if (lpcbData) *lpcbData = bufsize; + } + +_end: + if (heapbuf) HeapFree(GetProcessHeap(), 0, heapbuf); + return ret; +} diff --git a/apilibs/kexbases/Gdi32/FontResourceExA.c b/apilibs/kexbases/Gdi32/FontResourceExA.c new file mode 100644 index 0000000..c091240 --- /dev/null +++ b/apilibs/kexbases/Gdi32/FontResourceExA.c @@ -0,0 +1,34 @@ +/* + * 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. + * + */ + +#include + +/* MAKE_EXPORT AddFontResourceExA_new=AddFontResourceExA */ +INT WINAPI AddFontResourceExA_new(LPCSTR str, DWORD fl, PVOID pdv) +{ + return AddFontResourceA(str); +} + +/* MAKE_EXPORT RemoveFontResourceExA_new=RemoveFontResourceExA */ +BOOL WINAPI RemoveFontResourceExA_new(LPCSTR str, DWORD fl, PVOID pdv) +{ + return RemoveFontResourceA(str); +} diff --git a/apilibs/kexbases/Gdi32/GetGlyphOutlineA_fix.c b/apilibs/kexbases/Gdi32/GetGlyphOutlineA_fix.c new file mode 100644 index 0000000..03ad160 --- /dev/null +++ b/apilibs/kexbases/Gdi32/GetGlyphOutlineA_fix.c @@ -0,0 +1,39 @@ +/* + * KernelEx + * + * Copyright (C) 2008, Tihiy + * 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. + * + */ + +#include + +/* MAKE_EXPORT GetGlyphOutlineA_fix=GetGlyphOutlineA */ +DWORD WINAPI GetGlyphOutlineA_fix( + HDC hdc, // handle to DC + UINT uChar, // character to query + UINT uFormat, // data format + LPGLYPHMETRICS lpgm, // glyph metrics + DWORD cbBuffer, // size of data buffer + LPVOID lpvBuffer, // data buffer + CONST MAT2 *lpmat2 // transformation matrix +) +{ + //last parameter must point to writeable memory + MAT2 matr; + memcpy( &matr, lpmat2, sizeof(MAT2) ); + return GetGlyphOutlineA( hdc, uChar, uFormat, lpgm, cbBuffer, lpvBuffer, &matr ); +} diff --git a/apilibs/kexbases/Gdi32/TextOut.c b/apilibs/kexbases/Gdi32/TextOut.c new file mode 100644 index 0000000..bc2b769 --- /dev/null +++ b/apilibs/kexbases/Gdi32/TextOut.c @@ -0,0 +1,230 @@ +/* + * KernelEx + * + * Copyright 1993 Alexandre Julliard + * 1997 Alex Korobka + * Copyright 2002,2003 Shachar Shemesh + * Copyright 2003 CodeWeavers Inc. (Ulrich Czekalla) + * + * Copyright (C) 2008, Tihiy + * + * 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. + * + */ + +#include +#include "auxdecl.h" + +#ifndef ETO_PDY +#define ETO_PDY 0x2000 +#endif + +static void WINAPI MakeDxFromDxDy(const int* lpDx, int* newlpDx, UINT cbCount) +{ + UINT oneDx; + for (oneDx = 0; oneDx < cbCount; oneDx++) + { + *newlpDx = *lpDx; + newlpDx++; + lpDx++; + lpDx++; + } + newlpDx--; + if (*newlpDx == 0) *newlpDx = 16; //TERRIBLE HACK but needed on some fonts/glyphs/etc! +} + +/* MAKE_EXPORT ExtTextOutA_new=ExtTextOutA */ +BOOL WINAPI ExtTextOutA_new( + HDC hdc, // handle to DC + int X, // x-coordinate of reference point + int Y, // y-coordinate of reference point + UINT fuOptions, // text-output options + CONST RECT* lprc, // optional dimensions + LPCSTR lpString, // string + UINT cbCount, // number of characters in string + CONST INT* lpDx // array of spacing values +) +{ + BOOL result; + int* buffer = 0; + + if ((UINT)lpString>0xFFFFu) + { + if (cbCount>8192) cbCount = 8192; + if (fuOptions & ETO_PDY) //win9x can't understand it and messes up other flags + { + fuOptions = fuOptions & ~ETO_PDY; + if (lpDx) //we have to make array which contains dx values only + { + buffer = (int*)HeapAlloc(GetProcessHeap(),0,cbCount*sizeof(int)); + if (!buffer) //you've managed to ruin everything + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; + } + MakeDxFromDxDy(lpDx,buffer, cbCount); + lpDx = buffer; + } + } + } + result = ExtTextOutA(hdc,X,Y,fuOptions,lprc,lpString,cbCount,lpDx); + if (buffer) HeapFree (GetProcessHeap(),0,buffer); + return result; +} + + +/* MAKE_EXPORT ExtTextOutW_new=ExtTextOutW */ +BOOL WINAPI ExtTextOutW_new( + HDC hdc, // handle to DC + int X, // x-coordinate of reference point + int Y, // y-coordinate of reference point + UINT fuOptions, // text-output options + CONST RECT* lprc, // optional dimensions + LPCWSTR lpString, // string + UINT cbCount, // number of characters in string + CONST INT* lpDx // array of spacing values +) +{ + BOOL result; + BOOL optimized = FALSE; + int* buffer = 0; + char english[128]; + + if ((UINT)lpString>0xFFFFu) + { + if (cbCount>8192) cbCount = 8192; + if (fuOptions & ETO_PDY) + { + fuOptions = fuOptions & ~ETO_PDY; + if (lpDx) + { + buffer = (int*)HeapAlloc(GetProcessHeap(),0,cbCount*sizeof(int)); + if (!buffer) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; + } + MakeDxFromDxDy(lpDx,buffer,cbCount); + lpDx = buffer; + } + } + //now, common case optimization (English short string) + if (!(fuOptions & ETO_GLYPH_INDEX || cbCount>128 || *lpString>0x7Fu)) + { + UINT i; + LPCWSTR uString = lpString; + for (i = 0; i< cbCount; i++) + { + if (*uString>0x7Fu) break; else english[i]=(char)*uString; + uString++; + } + optimized = (i == cbCount); + } + else + optimized = FALSE; + } + + if (optimized) + result = ExtTextOutA(hdc,X,Y,fuOptions,lprc,english,cbCount,lpDx); + else + result = ExtTextOutW(hdc,X,Y,fuOptions,lprc,lpString,cbCount,lpDx); + + if (buffer) HeapFree (GetProcessHeap(),0,buffer); + return result; +} + +/* MAKE_EXPORT PolyTextOutA_new=PolyTextOutA */ +BOOL WINAPI PolyTextOutA_new( HDC hdc, const POLYTEXTA *pptxt, INT cStrings ) +{ + if (!hdc || !cStrings || !pptxt) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + for (; cStrings>0; cStrings--, pptxt++) + if (!ExtTextOutA_new (hdc, pptxt->x, pptxt->y, pptxt->uiFlags, &pptxt->rcl, pptxt->lpstr, pptxt->n, pptxt->pdx )) + return FALSE; + return TRUE; +} + +/* MAKE_EXPORT PolyTextOutW_new=PolyTextOutW */ +BOOL WINAPI PolyTextOutW_new( HDC hdc, const POLYTEXTW *pptxt, INT cStrings ) +{ + if (!hdc || !cStrings || !pptxt) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + for (; cStrings>0; cStrings--, pptxt++) + if (!ExtTextOutW_new (hdc, pptxt->x, pptxt->y, pptxt->uiFlags, &pptxt->rcl, pptxt->lpstr, pptxt->n, pptxt->pdx )) + return FALSE; + return TRUE; +} + +/* MAKE_EXPORT GetFontUnicodeRanges_new=GetFontUnicodeRanges */ +DWORD WINAPI GetFontUnicodeRanges_new( + HDC hdc, + LPGLYPHSET lpgs +) +{ + SetLastError(ERROR_NOT_SUPPORTED); + return 0; +} + +/* On 9x fallback to system function */ +/* MAKE_EXPORT SetGraphicsMode_NT=SetGraphicsMode */ +int WINAPI SetGraphicsMode_NT( + HDC hdc, // handle to device context + int iMode // graphics mode +) +{ + return GM_COMPATIBLE; +} + +/* MAKE_EXPORT SetWorldTransform_9x=SetWorldTransform */ +BOOL WINAPI SetWorldTransform_9x( + HDC hdc, // handle to device context + CONST XFORM *lpXform // transformation data +) +{ + return FALSE; +} + +/* MAKE_EXPORT SetWorldTransform_NT=SetWorldTransform */ +BOOL WINAPI SetWorldTransform_NT( + HDC hdc, // handle to device context + CONST XFORM *lpXform // transformation data +) +{ + return TRUE; +} + +/* MAKE_EXPORT GetRandomRgn_NT=GetRandomRgn */ +int WINAPI GetRandomRgn_NT( + HDC hdc, // handle to DC + HRGN hrgn, // handle to region + INT iNum // must be SYSRGN +) +{ + int result = GetRandomRgn(hdc,hrgn,iNum); + if (result) + { + POINT pt; + GetDCOrgEx(hdc,&pt); + OffsetRgn(hrgn,pt.x,pt.y); + } + return result; +} diff --git a/apilibs/kexbases/Gdi32/_gdi32_apilist.c b/apilibs/kexbases/Gdi32/_gdi32_apilist.c new file mode 100644 index 0000000..bd569e4 --- /dev/null +++ b/apilibs/kexbases/Gdi32/_gdi32_apilist.c @@ -0,0 +1,72 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" +#include "kexcoresdk.h" +#include "_gdi32_apilist.h" + +BOOL init_gdi32() +{ + return TRUE; +} + +/* + * MAKE_EXPORT GetCharWidthA=GetCharWidth32A + * MAKE_EXPORT GetCharWidthW=GetCharWidth32W + */ + +static const apilib_named_api gdi32_named_apis[] = +{ +/*** AUTOGENERATED APILIST NAMED EXPORTS BEGIN ***/ + DECL_API("AddFontMemResourceEx", AddFontMemResourceEx_stub), + DECL_API("AddFontResourceExA", AddFontResourceExA_new), + DECL_API("AddFontResourceExW", AddFontResourceExW_new), + DECL_API("AddFontResourceW", AddFontResourceW_new), + DECL_API("ExtTextOutA", ExtTextOutA_new), + DECL_API("ExtTextOutW", ExtTextOutW_new), + DECL_API("GetCharWidth32A", GetCharWidthA), + DECL_API("GetCharWidth32W", GetCharWidthW), + DECL_API("GetFontUnicodeRanges", GetFontUnicodeRanges_new), + DECL_API("GetGlyphOutlineA", GetGlyphOutlineA_fix), + DECL_API("GetRandomRgn", GetRandomRgn_NT), + DECL_API("PolyTextOutA", PolyTextOutA_new), + DECL_API("PolyTextOutW", PolyTextOutW_new), + DECL_API("RemoveFontMemResourceEx", RemoveFontMemResourceEx_stub), + DECL_API("RemoveFontResourceExA", RemoveFontResourceExA_new), + DECL_API("RemoveFontResourceExW", RemoveFontResourceExW_new), + DECL_API("RemoveFontResourceW", RemoveFontResourceW_new), + DECL_API("SetDCBrushColor", SetDCBrushColor_stub), + DECL_API("SetDCPenColor", SetDCPenColor_stub), + DECL_API("SetGraphicsMode", SetGraphicsMode_NT), + DECL_API("SetWorldTransform", SetWorldTransform_9x), + DECL_API("SetWorldTransform", SetWorldTransform_NT), +/*** AUTOGENERATED APILIST NAMED EXPORTS END ***/ +}; + +#if 0 +static const apilib_unnamed_api gdi32_ordinal_apis[] = +{ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS BEGIN ***/ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS END ***/ +}; +#endif + +const apilib_api_table apitable_gdi32 = DECL_TAB("GDI32.DLL", gdi32_named_apis, 0 /*gdi32_ordinal_apis*/); diff --git a/apilibs/kexbases/Gdi32/_gdi32_apilist.h b/apilibs/kexbases/Gdi32/_gdi32_apilist.h new file mode 100644 index 0000000..6d79272 --- /dev/null +++ b/apilibs/kexbases/Gdi32/_gdi32_apilist.h @@ -0,0 +1,54 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#ifndef _GDI32_APILIST_H +#define _GDI32_APILIST_H + +#include "auxdecl.h" +#include "kexcoresdk.h" + +BOOL init_gdi32(); +extern const apilib_api_table apitable_gdi32; + +/*** AUTOGENERATED APILIST DECLARATIONS BEGIN ***/ +INT WINAPI AddFontResourceExA_new(LPCSTR str, DWORD fl, PVOID pdv); +BOOL WINAPI RemoveFontResourceExA_new(LPCSTR str, DWORD fl, PVOID pdv); +DWORD WINAPI GetGlyphOutlineA_fix(HDC hdc, UINT uChar, UINT uFormat, LPGLYPHMETRICS lpgm, DWORD cbBuffer, LPVOID lpvBuffer, CONST MAT2 *lpmat2); +BOOL WINAPI ExtTextOutA_new(HDC hdc, int X, int Y, UINT fuOptions, CONST RECT* lprc, LPCSTR lpString, UINT cbCount, CONST INT* lpDx); +BOOL WINAPI ExtTextOutW_new(HDC hdc, int X, int Y, UINT fuOptions, CONST RECT* lprc, LPCWSTR lpString, UINT cbCount, CONST INT* lpDx); +BOOL WINAPI PolyTextOutA_new(HDC hdc, const POLYTEXTA *pptxt, INT cStrings); +BOOL WINAPI PolyTextOutW_new(HDC hdc, const POLYTEXTW *pptxt, INT cStrings); +DWORD WINAPI GetFontUnicodeRanges_new(HDC hdc, LPGLYPHSET lpgs); +int WINAPI SetGraphicsMode_NT(HDC hdc, int iMode); +BOOL WINAPI SetWorldTransform_9x(HDC hdc, CONST XFORM *lpXform); +BOOL WINAPI SetWorldTransform_NT(HDC hdc, CONST XFORM *lpXform); +int WINAPI GetRandomRgn_NT(HDC hdc, HRGN hrgn, INT iNum); +STUB SetDCBrushColor_stub; +STUB SetDCPenColor_stub; +STUB AddFontMemResourceEx_stub; +STUB RemoveFontMemResourceEx_stub; +INT WINAPI AddFontResourceExW_new(LPCWSTR strW, DWORD fl, PVOID pdv); +INT WINAPI AddFontResourceW_new(LPCWSTR strW); +BOOL WINAPI RemoveFontResourceExW_new(LPCWSTR strW, DWORD fl, PVOID pdv); +BOOL WINAPI RemoveFontResourceW_new(LPCWSTR strW); +/*** AUTOGENERATED APILIST DECLARATIONS END ***/ + +#endif diff --git a/apilibs/kexbases/Gdi32/_gdi32_stubs.c b/apilibs/kexbases/Gdi32/_gdi32_stubs.c new file mode 100644 index 0000000..be8d11b --- /dev/null +++ b/apilibs/kexbases/Gdi32/_gdi32_stubs.c @@ -0,0 +1,27 @@ +/* + * 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. + * + */ + +#include "common.h" + +UNIMPL_FUNC(SetDCBrushColor, 2); +UNIMPL_FUNC(SetDCPenColor, 2); +UNIMPL_FUNC(AddFontMemResourceEx, 4); +UNIMPL_FUNC(RemoveFontMemResourceEx, 1); diff --git a/apilibs/kexbases/Gdi32/unigdi32.c b/apilibs/kexbases/Gdi32/unigdi32.c new file mode 100644 index 0000000..dda1b8b --- /dev/null +++ b/apilibs/kexbases/Gdi32/unigdi32.c @@ -0,0 +1,55 @@ +/* + * 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. + * + */ + +#include "common.h" +#include "_gdi32_apilist.h" + +//MAKE_EXPORT AddFontResourceExW_new=AddFontResourceExW +INT WINAPI AddFontResourceExW_new(LPCWSTR strW, DWORD fl, PVOID pdv) +{ + file_GetCP(); + file_ALLOC_WtoA(str); + return AddFontResourceExA_new(strA, fl, pdv); +} + +//MAKE_EXPORT AddFontResourceW_new=AddFontResourceW +INT WINAPI AddFontResourceW_new(LPCWSTR strW) +{ + file_GetCP(); + file_ALLOC_WtoA(str); + return AddFontResourceA(strA); +} + +//MAKE_EXPORT RemoveFontResourceExW_new=RemoveFontResourceExW +BOOL WINAPI RemoveFontResourceExW_new(LPCWSTR strW, DWORD fl, PVOID pdv) +{ + file_GetCP(); + file_ALLOC_WtoA(str); + return RemoveFontResourceExA_new(strA, fl, pdv); +} + +//MAKE_EXPORT RemoveFontResourceW_new=RemoveFontResourceW +BOOL WINAPI RemoveFontResourceW_new(LPCWSTR strW) +{ + file_GetCP(); + file_ALLOC_WtoA(str); + return RemoveFontResourceA(strA); +} diff --git a/apilibs/kexbases/Kernel32/CopyFileEx.c b/apilibs/kexbases/Kernel32/CopyFileEx.c new file mode 100644 index 0000000..2f58206 --- /dev/null +++ b/apilibs/kexbases/Kernel32/CopyFileEx.c @@ -0,0 +1,29 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include + +/* MAKE_EXPORT CopyFileExA_new=CopyFileExA */ +BOOL WINAPI CopyFileExA_new(LPCSTR lpExistingFileNameA, LPCSTR lpNewFileNameA, LPPROGRESS_ROUTINE lpProgressRoutine, LPVOID lpData, LPBOOL pbCancel, DWORD dwCopyFlags) +{ + return CopyFileA(lpExistingFileNameA, lpNewFileNameA, + (dwCopyFlags & COPY_FILE_FAIL_IF_EXISTS) != 0); +} diff --git a/apilibs/kexbases/Kernel32/CreateFileA_fix.c b/apilibs/kexbases/Kernel32/CreateFileA_fix.c new file mode 100644 index 0000000..6f178fa --- /dev/null +++ b/apilibs/kexbases/Kernel32/CreateFileA_fix.c @@ -0,0 +1,44 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#include + +/* MAKE_EXPORT CreateFileA_fix=CreateFileA */ +HANDLE WINAPI CreateFileA_fix(LPCSTR lpFileName, DWORD dwDesiredAccess, + DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, + DWORD dwCreationDistribution, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) +{ + /* translate NT-specific access rights to generic ones */ + if (dwDesiredAccess & ~0xf0010100) + { + DWORD oldaccess = dwDesiredAccess; + dwDesiredAccess &= 0xf0010100; + if (oldaccess & FILE_READ_DATA) + dwDesiredAccess |= GENERIC_READ; + if (oldaccess & FILE_WRITE_DATA) + dwDesiredAccess |= GENERIC_WRITE; + if (oldaccess & FILE_EXECUTE) + dwDesiredAccess |= GENERIC_EXECUTE; + } + // hTemplate has to be NULL on 9x + return CreateFileA(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, + dwCreationDistribution, dwFlagsAndAttributes, NULL); +} diff --git a/apilibs/kexbases/Kernel32/CreateThread_fix.c b/apilibs/kexbases/Kernel32/CreateThread_fix.c new file mode 100644 index 0000000..9606f57 --- /dev/null +++ b/apilibs/kexbases/Kernel32/CreateThread_fix.c @@ -0,0 +1,37 @@ +/* + * KernelEx + * Copyright (C) 2008, Tihiy + * + * 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. + * + */ + +#include + +/* MAKE_EXPORT CreateThread_fix=CreateThread */ +HANDLE WINAPI CreateThread_fix( + LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD + SIZE_T dwStackSize, // initial stack size + LPTHREAD_START_ROUTINE lpStartAddress, // thread function + LPVOID lpParameter, // thread argument + DWORD dwCreationFlags, // creation option + LPDWORD lpThreadId // thread identifier +) +{ + DWORD dummy; + if ( !lpThreadId ) lpThreadId = &dummy; + return CreateThread( lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId ); +} diff --git a/apilibs/kexbases/Kernel32/DeleteCriticalSection.c b/apilibs/kexbases/Kernel32/DeleteCriticalSection.c new file mode 100644 index 0000000..442c72c --- /dev/null +++ b/apilibs/kexbases/Kernel32/DeleteCriticalSection.c @@ -0,0 +1,30 @@ +/* + * KernelEx + * + * Copyright (C) 2008, Tihiy + * 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. + * + */ + +#include + +/* MAKE_EXPORT DeleteCriticalSection_new=DeleteCriticalSection */ +void WINAPI DeleteCriticalSection_new(PCRITICAL_SECTION lpCriticalSection) +{ + //make DeleteCriticalSection not fail on deleted section + byte* deleted = (byte*) lpCriticalSection; + if (*deleted != 0) DeleteCriticalSection(lpCriticalSection); +} diff --git a/apilibs/kexbases/Kernel32/GetFileSizeEx.c b/apilibs/kexbases/Kernel32/GetFileSizeEx.c new file mode 100644 index 0000000..cb29c7d --- /dev/null +++ b/apilibs/kexbases/Kernel32/GetFileSizeEx.c @@ -0,0 +1,38 @@ +/* + * KernelEx + * Copyright (C) 2006, 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. + * + */ + +#include + +/* MAKE_EXPORT GetFileSizeEx_new=GetFileSizeEx */ +BOOL WINAPI GetFileSizeEx_new(HANDLE hFile, PLARGE_INTEGER lpFileSize) +{ + DWORD h, l, lasterr; + lasterr = GetLastError(); + l = GetFileSize(hFile, &h); + if (l == INVALID_FILE_SIZE && GetLastError() != NO_ERROR) return FALSE; + else + { + lpFileSize->HighPart = h; + lpFileSize->LowPart = l; + } + SetLastError(lasterr); + return TRUE; +} diff --git a/apilibs/kexbases/Kernel32/GlobalMemoryStatusEx.c b/apilibs/kexbases/Kernel32/GlobalMemoryStatusEx.c new file mode 100644 index 0000000..0ff84a3 --- /dev/null +++ b/apilibs/kexbases/Kernel32/GlobalMemoryStatusEx.c @@ -0,0 +1,48 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include +#include "auxdecl.h" + +/* MAKE_EXPORT GlobalMemoryStatusEx_new=GlobalMemoryStatusEx */ +BOOL WINAPI GlobalMemoryStatusEx_new(LPMEMORYSTATUSEX lpmemex) +{ + MEMORYSTATUS mem; + + if (lpmemex->dwLength != sizeof(*lpmemex)) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + mem.dwLength = sizeof(mem); + GlobalMemoryStatus(&mem); + lpmemex->dwMemoryLoad = mem.dwMemoryLoad; + lpmemex->ullTotalPhys = mem.dwTotalPhys; + lpmemex->ullAvailPhys = mem.dwAvailPhys; + lpmemex->ullTotalPageFile = mem.dwTotalPageFile; + lpmemex->ullAvailPageFile = mem.dwAvailPageFile; + lpmemex->ullTotalVirtual = mem.dwTotalVirtual; + lpmemex->ullAvailVirtual = mem.dwAvailVirtual; + lpmemex->ullAvailExtendedVirtual = 0; + + return TRUE; +} diff --git a/apilibs/kexbases/Kernel32/HeapLocks.c b/apilibs/kexbases/Kernel32/HeapLocks.c new file mode 100644 index 0000000..79dda98 --- /dev/null +++ b/apilibs/kexbases/Kernel32/HeapLocks.c @@ -0,0 +1,51 @@ +/* + * KernelEx + * + * Copyright (C) 2008, Tihiy + * 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. + * + */ + +#include + +static BOOL IsValidHeap(HANDLE hHeap) +{ + WORD *sig; + if ( IsBadReadPtr(hHeap,0x74) ) return FALSE; + sig = (WORD*)((DWORD)hHeap+0x72); + if ( *sig != 0x4948 ) return FALSE; + return TRUE; +} + +/* MAKE_EXPORT HeapLock_new=HeapLock */ +BOOL WINAPI HeapLock_new( + HANDLE hHeap +) +{ + if ( !IsValidHeap(hHeap) ) return FALSE; + EnterCriticalSection((CRITICAL_SECTION*)((DWORD)hHeap+0x50)); + return TRUE; +} + +/* MAKE_EXPORT HeapUnlock_new=HeapUnlock */ +BOOL WINAPI HeapUnlock_new( + HANDLE hHeap +) +{ + if ( !IsValidHeap(hHeap) ) return FALSE; + LeaveCriticalSection((CRITICAL_SECTION*)((DWORD)hHeap+0x50)); + return TRUE; +} diff --git a/apilibs/kexbases/Kernel32/InitializeCriticalSectionAndSpinCount.c b/apilibs/kexbases/Kernel32/InitializeCriticalSectionAndSpinCount.c new file mode 100644 index 0000000..230f12b --- /dev/null +++ b/apilibs/kexbases/Kernel32/InitializeCriticalSectionAndSpinCount.c @@ -0,0 +1,29 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include + +/* MAKE_EXPORT InitializeCriticalSectionAndSpinCount_new=InitializeCriticalSectionAndSpinCount */ +BOOL WINAPI InitializeCriticalSectionAndSpinCount_new(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount) +{ + InitializeCriticalSection(lpCriticalSection); + return TRUE; +} diff --git a/apilibs/kexbases/Kernel32/Jobs.c b/apilibs/kexbases/Kernel32/Jobs.c new file mode 100644 index 0000000..6045565 --- /dev/null +++ b/apilibs/kexbases/Kernel32/Jobs.c @@ -0,0 +1,81 @@ +/* + * KernelEx + * Copyright (C) 2008, Xeno86 + * Copyright (C) 2008, Tihiy + * + * 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. + * + */ + +#include + +/* MAKE_EXPORT CreateJobObjectA_new=CreateJobObjectA */ +HANDLE WINAPI CreateJobObjectA_new(LPSECURITY_ATTRIBUTES sa, LPCSTR name) +{ + return (HANDLE) 0x1ee7; +} + +/* MAKE_EXPORT CreateJobObjectW_new=CreateJobObjectW */ +HANDLE WINAPI CreateJobObjectW_new(LPSECURITY_ATTRIBUTES sa, LPCWSTR name) +{ + return (HANDLE) 0x1ee7; +} + +/* MAKE_EXPORT TerminateJobObject_new=TerminateJobObject */ +BOOL WINAPI TerminateJobObject_new(HANDLE job, UINT exit_code) +{ + return TRUE; +} + +/* MAKE_EXPORT OpenJobObjectA_new=OpenJobObjectA */ +HANDLE WINAPI OpenJobObjectA_new(DWORD access, BOOL inherit, LPCSTR name) +{ + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return 0; +} + +/* MAKE_EXPORT OpenJobObjectW_new=OpenJobObjectW */ +HANDLE WINAPI OpenJobObjectW_new(DWORD access, BOOL inherit, LPCWSTR name) +{ + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return 0; +} + +/* MAKE_EXPORT QueryInformationJobObject_new=QueryInformationJobObject */ +BOOL WINAPI QueryInformationJobObject_new(HANDLE job, PVOID classs, LPVOID info, DWORD len, DWORD *ret_len) +{ + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} + +/* MAKE_EXPORT SetInformationJobObject_new=SetInformationJobObject */ +BOOL WINAPI SetInformationJobObject_new(HANDLE job, PVOID classs, LPVOID info, DWORD len) +{ + return TRUE; +} + +/* MAKE_EXPORT AssignProcessToJobObject_new=AssignProcessToJobObject */ +BOOL WINAPI AssignProcessToJobObject_new(HANDLE job, HANDLE process) +{ + return TRUE; +} + +/* MAKE_EXPORT IsProcessInJob_new=IsProcessInJob */ +BOOL WINAPI IsProcessInJob_new(HANDLE process, HANDLE job, PBOOL result) +{ + *result = FALSE; + return TRUE; +} diff --git a/apilibs/kexbases/Kernel32/KEXVersion.c b/apilibs/kexbases/Kernel32/KEXVersion.c new file mode 100644 index 0000000..e0cbf74 --- /dev/null +++ b/apilibs/kexbases/Kernel32/KEXVersion.c @@ -0,0 +1,31 @@ +/* + * 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. + * + */ + +#include +#include +#include "kexcoresdk.h" + +/* MAKE_EXPORT KEXVersion=KEXVersion */ +void WINAPI KEXVersion(char* out) +{ + unsigned long ver = kexGetKEXVersion(); + sprintf(out, "%d.%d.%d", (ver>>24) & 0xff, (ver>>16) & 0xff, ver & 0xffff); +} diff --git a/apilibs/kexbases/Kernel32/LockFileEx.c b/apilibs/kexbases/Kernel32/LockFileEx.c new file mode 100644 index 0000000..01d5c85 --- /dev/null +++ b/apilibs/kexbases/Kernel32/LockFileEx.c @@ -0,0 +1,36 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include + +/* MAKE_EXPORT LockFileEx_new=LockFileEx */ +BOOL WINAPI LockFileEx_new(HANDLE hFile, DWORD dwFlags, DWORD dwReserved, DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh, LPOVERLAPPED lpOverlapped) +{ + /* FIXME: flags LOCKFILE_FAIL_IMMEDIATELY and LOCKFILE_EXCLUSIVE_LOCK not supported (always set), + Event signalling not supported + */ + if (dwReserved) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + return LockFile(hFile, lpOverlapped->Offset, lpOverlapped->OffsetHigh, nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh); +} diff --git a/apilibs/kexbases/Kernel32/MapViewOfFile.c b/apilibs/kexbases/Kernel32/MapViewOfFile.c new file mode 100644 index 0000000..34d7590 --- /dev/null +++ b/apilibs/kexbases/Kernel32/MapViewOfFile.c @@ -0,0 +1,44 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include + +/* MAKE_EXPORT MapViewOfFileEx_new=MapViewOfFileEx */ +LPVOID WINAPI MapViewOfFileEx_new( + HANDLE hFileMappingObject, + DWORD dwDesiredAccess, + DWORD dwFileOffsetHigh, + DWORD dwFileOffsetLow, + SIZE_T dwNumberOfBytesToMap, + LPVOID lpBaseAddress +) +{ + /* + * With this modification MapViewOfFileEx won't fail if lpBaseAddress + * doesn't point to Shared Arena - it will ignore suggested starting address + */ + if ((DWORD)lpBaseAddress < 0x80000000 || (DWORD)lpBaseAddress >= 0xc0000000) + { + lpBaseAddress = 0; + } + return MapViewOfFileEx(hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh, + dwFileOffsetLow, dwNumberOfBytesToMap, lpBaseAddress); +} diff --git a/apilibs/kexbases/Kernel32/MoveFileExA.c b/apilibs/kexbases/Kernel32/MoveFileExA.c new file mode 100644 index 0000000..155adc7 --- /dev/null +++ b/apilibs/kexbases/Kernel32/MoveFileExA.c @@ -0,0 +1,111 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: MoveFileExA.cpp,v $ + * + * $Revision: 1.4 $ + * + * last change: $Author: rt $ $Date: 2005/09/08 16:21:23 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +//#include "macros.h" +#include + +#define WININIT_FILENAME "wininit.ini" +#define RENAME_SECTION "rename" +#define BUFSIZE 32767 + +/* MAKE_EXPORT MoveFileExA_new=MoveFileExA */ +BOOL WINAPI MoveFileExA_new( LPCSTR lpExistingFileNameA, LPCSTR lpNewFileNameA, DWORD dwFlags ) +{ + BOOL fSuccess = FALSE; // assume failure + + // Windows 9x has a special mechanism to move files after reboot + + if ( dwFlags & MOVEFILE_DELAY_UNTIL_REBOOT ) + { + CHAR szExistingFileNameA[MAX_PATH]; + CHAR szNewFileNameA[MAX_PATH]; + lstrcpyA( szNewFileNameA, "NUL" ); + + // Path names in WININIT.INI must be in short path name form + + if ( + GetShortPathNameA( lpExistingFileNameA, szExistingFileNameA, MAX_PATH ) && + (!lpNewFileNameA || GetShortPathNameA( lpNewFileNameA, szNewFileNameA, MAX_PATH )) + ) + { + CHAR* szBuffer = (CHAR*) HeapAlloc( GetProcessHeap(), 0, BUFSIZE ); // The buffer size must not exceed 32K + DWORD dwBufLen = GetPrivateProfileSectionA( RENAME_SECTION, szBuffer, BUFSIZE, WININIT_FILENAME ); + + CHAR szRename[MAX_PATH]; // This is enough for at most to times 67 chracters + size_t lnRename; + lstrcpyA( szRename, szNewFileNameA ); + lstrcatA( szRename, "=" ); + lstrcatA( szRename, szExistingFileNameA ); + lnRename = lstrlenA(szRename); + + if ( dwBufLen + lnRename + 2 <= BUFSIZE ) + { + lstrcpyA( &szBuffer[dwBufLen], szRename ); + szBuffer[ dwBufLen + lnRename + 1 ] = 0; + + fSuccess = WritePrivateProfileSectionA( RENAME_SECTION, szBuffer, WININIT_FILENAME ); + } + else + SetLastError( ERROR_BUFFER_OVERFLOW ); + + HeapFree( GetProcessHeap(), 0, szBuffer ); + } + } + else + { + + fSuccess = MoveFileA( lpExistingFileNameA, lpNewFileNameA ); + + if ( !fSuccess && 0 != (dwFlags & (MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING)) ) + { + BOOL bFailIfExist = 0 == (dwFlags & MOVEFILE_REPLACE_EXISTING); + + fSuccess = CopyFileA( lpExistingFileNameA, lpNewFileNameA, bFailIfExist ); + + // In case of successfull copy do not return FALSE if delete fails. + // Error detection is done by GetLastError() + + if ( fSuccess ) + { + SetLastError( NO_ERROR ); + DeleteFileA( lpExistingFileNameA ); + } + } + + } + + return fSuccess; +} + diff --git a/apilibs/kexbases/Kernel32/MoveFileWithProgressA.c b/apilibs/kexbases/Kernel32/MoveFileWithProgressA.c new file mode 100644 index 0000000..8b21ec0 --- /dev/null +++ b/apilibs/kexbases/Kernel32/MoveFileWithProgressA.c @@ -0,0 +1,28 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include + +/* MAKE_EXPORT MoveFileWithProgressA_new=MoveFileWithProgressA */ +BOOL WINAPI MoveFileWithProgressA_new(LPCSTR lpExistingFileName, LPCSTR lpNewFileName, LPPROGRESS_ROUTINE lpProgressRoutine, LPVOID lpData, DWORD dwFlags) +{ + return MoveFileExA(lpExistingFileName, lpNewFileName, dwFlags); +} diff --git a/apilibs/kexbases/Kernel32/OpenThread.c b/apilibs/kexbases/Kernel32/OpenThread.c new file mode 100644 index 0000000..027435a --- /dev/null +++ b/apilibs/kexbases/Kernel32/OpenThread.c @@ -0,0 +1,60 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include +#include "kexcoresdk.h" + +typedef HANDLE (__stdcall *AllocHandle_t)(void* current_pdb, void* tdb, DWORD access); +AllocHandle_t AllocHandle = NULL; + +BOOL init_openthread() +{ + int i; + DWORD addr = (DWORD) kexGetProcAddress(GetModuleHandle("kernel32"), "OpenProcess"); + for (i = 0 ; i < 100 ; i++, addr++) + if (*(DWORD*) addr == 0xe832ff50) + { + addr += 4; + AllocHandle = (AllocHandle_t)(addr + 4 + *(DWORD*)addr); + return TRUE; + } + return FALSE; +} + +/* MAKE_EXPORT OpenThread_new=OpenThread */ +HANDLE WINAPI OpenThread_new(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwThreadId) +{ + HANDLE ret; + BYTE* tdb = (BYTE*) kexTIDtoTDB(dwThreadId); + if (!tdb || *tdb != 7) + { + SetLastError(ERROR_INVALID_PARAMETER); + return NULL; + } + + dwDesiredAccess &= THREAD_ALL_ACCESS; + if (bInheritHandle) + dwDesiredAccess |= 0x80000000; + ret = AllocHandle(kexPIDtoPDB(GetCurrentProcessId()), tdb, dwDesiredAccess); + if (ret == INVALID_HANDLE_VALUE) + return NULL; + return ret; +} diff --git a/apilibs/kexbases/Kernel32/SetFilePointerEx.c b/apilibs/kexbases/Kernel32/SetFilePointerEx.c new file mode 100644 index 0000000..bf426a7 --- /dev/null +++ b/apilibs/kexbases/Kernel32/SetFilePointerEx.c @@ -0,0 +1,40 @@ +/* + * KernelEx + * Copyright (C) 2006, 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. + * + */ + +#include + +#ifndef INVALID_SET_FILE_POINTER +#define INVALID_SET_FILE_POINTER ((DWORD)-1) +#endif + +/* MAKE_EXPORT SetFilePointerEx_new=SetFilePointerEx */ +BOOL WINAPI SetFilePointerEx_new(HANDLE hFile, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod) +{ + DWORD lasterr = GetLastError(); + if ((liDistanceToMove.LowPart = SetFilePointer(hFile, liDistanceToMove.LowPart, &liDistanceToMove.HighPart, dwMoveMethod)) == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + if (lpNewFilePointer) *lpNewFilePointer = liDistanceToMove; + SetLastError(lasterr); + return TRUE; +} diff --git a/apilibs/kexbases/Kernel32/ThreadPool.c b/apilibs/kexbases/Kernel32/ThreadPool.c new file mode 100644 index 0000000..e9ab60d --- /dev/null +++ b/apilibs/kexbases/Kernel32/ThreadPool.c @@ -0,0 +1,51 @@ +/* + * KernelEx + * Copyright (C) 2008, Tihiy + * + * 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. + * + */ + +#include + +/* COMPLETE SHIT. PORT WINE HERE */ + +/* MAKE_EXPORT RegisterWaitForSingleObject_new=RegisterWaitForSingleObject */ +BOOL WINAPI RegisterWaitForSingleObject_new(PHANDLE phNewWaitObject, HANDLE hObject, PVOID Callback, PVOID Context, ULONG dwMilliseconds, ULONG dwFlags) +{ + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} + +/* MAKE_EXPORT RegisterWaitForSingleObjectEx_new=RegisterWaitForSingleObjectEx */ +HANDLE WINAPI RegisterWaitForSingleObjectEx_new(HANDLE hObject, + PVOID Callback, PVOID Context, + ULONG dwMilliseconds, ULONG dwFlags) +{ + return 0; +} + +/* MAKE_EXPORT UnregisterWait_new=UnregisterWait */ +BOOL WINAPI UnregisterWait_new(HANDLE WaitHandle) +{ + return WaitHandle != 0; +} + +/* MAKE_EXPORT UnregisterWaitEx_new=UnregisterWaitEx */ +BOOL WINAPI UnregisterWaitEx_new(HANDLE WaitHandle, HANDLE CompletionEvent) +{ + return WaitHandle != 0; +} diff --git a/apilibs/kexbases/Kernel32/TryEnterCriticalSection.c b/apilibs/kexbases/Kernel32/TryEnterCriticalSection.c new file mode 100644 index 0000000..f8287f5 --- /dev/null +++ b/apilibs/kexbases/Kernel32/TryEnterCriticalSection.c @@ -0,0 +1,152 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include +#include "kexcoresdk.h" + +#define K32OBJ_CRITICAL_SECTION 4 + +typedef struct _CRIT_SECT // Size = 0x20 +{ + BYTE Type; // 00 = 4: K32_OBJECT_CRITICAL_SECTION + int RecursionCount; // 04 initially 0, incremented on lock + void* OwningThread; // 08 pointer to TDBX + DWORD un3; // 0C + int LockCount; // 10 initially 1, decremented on lock + struct _CRIT_SECT* Next; // 14 + void* PLst; // 18 list of processes using it? + struct _WIN_CRITICAL_SECTION* UserCS; // 1C pointer to user defined CRITICAL_SECTION +} CRIT_SECT, *PCRIT_SECT; + +typedef struct _WIN_CRITICAL_SECTION +{ + BYTE Type; //= 4: K32_OBJECT_CRITICAL_SECTION + PCRIT_SECT crit; + DWORD un1; + DWORD un2; + DWORD un3; + DWORD un4; +} WIN_CRITICAL_SECTION, *PWIN_CRITICAL_SECTION; + +static DWORD _offset; + +BOOL init_tryentercritsec() +{ + DWORD GV = kexGetVersion(); + + if (GV == 0xc0000a04) //98 + { + _offset = 0x58 - 0x8; + return TRUE; + } + if (GV == 0xc0005a04) //Me + { + _offset = 0x88 - 0x8; + return TRUE; + } + return FALSE; +} + +#ifdef __GNUC__ + +BOOL WINAPI TryEnterCrst(CRIT_SECT* crit); + +__asm__(".text\n\t" + ".align 4\n\t" + ".globl _TryEnterCrst@4\n\t" + ".def _TryEnterCrst@4; .scl 2; .type 32; .endef\n" + "_TryEnterCrst@4:\n\t" + "movl 4(%esp),%edx\n\t" + "xorl %eax,%eax\n\t" + "incl %eax\n\t" + "xorl %ecx,%ecx\n\t" + "cmpxchgl %ecx,0x10(%edx)\n\t" /* if (OP1==eax) { OP1=OP2; ZF=1; } else { eax=OP1; ZF=0 } */ + "movl %fs:0x18, %ecx\n\t" + "addl _offset,%ecx\n\t" + "movl (%ecx),%ecx\n\t" /* ecx will contain TDBX now */ + "cmpl $1,%eax\n\t" + "jnz .L1\n\t" + /* critical section was unowned => successful lock */ + "movl %ecx,8(%edx)\n\t" + "incl 4(%edx)\n\t" + "ret $4\n\t" +".L1: \n\t" + "cmpl %ecx,8(%edx)\n\t" + "jnz .L2\n\t" + /* critical section owned by this thread */ + "decl 0x10(%edx)\n\t" + "incl 4(%edx)\n\t" + "xorl %eax,%eax\n\t" + "incl %eax\n\t" + "ret $4\n\t" +".L2: \n\t" + /* critical section owned by other thread - do nothing */ + "xorl %eax,%eax\n\t" + "ret $4\n\t" + ); + +#else + +__declspec(naked) BOOL WINAPI TryEnterCrst(CRIT_SECT* crit) +{ +__asm { + mov edx, [esp+4] + xor eax, eax + inc eax + xor ecx, ecx + cmpxchg [edx+10h], ecx ;if (OP1==eax) { OP1=OP2; ZF=1; } else { eax=OP1; ZF=0 } + ;mov ecx, ppTDBXCur + mov ecx, fs:[18h] + add ecx, [_offset] + mov ecx, [ecx] ;ecx will contain TDBX now + cmp eax, 1 + jnz L1 + ;critical section was unowned => successful lock + mov [edx+8], ecx + inc dword ptr [edx+4] + ret 4 +L1: + cmp [edx+8], ecx + jnz L2 + ;critical section owned by this thread + dec dword ptr [edx+10h] + inc dword ptr [edx+4] + xor eax, eax + inc eax + ret 4 +L2: + ;critical section owned by other thread - do nothing + xor eax, eax + ret 4 + } +} + +#endif + +/* MAKE_EXPORT TryEnterCriticalSection_new=TryEnterCriticalSection */ +BOOL WINAPI TryEnterCriticalSection_new(CRITICAL_SECTION* cs) +{ + WIN_CRITICAL_SECTION* mycs = (WIN_CRITICAL_SECTION*) cs; + if (mycs->Type != K32OBJ_CRITICAL_SECTION) + RaiseException(STATUS_ACCESS_VIOLATION, 0, 0, NULL); + + return TryEnterCrst(mycs->crit); +} diff --git a/apilibs/kexbases/Kernel32/VirtualAllocEx.c b/apilibs/kexbases/Kernel32/VirtualAllocEx.c new file mode 100644 index 0000000..7284b6c --- /dev/null +++ b/apilibs/kexbases/Kernel32/VirtualAllocEx.c @@ -0,0 +1,41 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include + +#ifndef VA_SHARED +#define VA_SHARED 0x8000000 +#endif + +/* MAKE_EXPORT VirtualAllocEx_new=VirtualAllocEx */ +LPVOID WINAPI VirtualAllocEx_new(HANDLE hProcess, LPVOID lpAddress, DWORD dwSize, DWORD flAllocationType, DWORD flProtect) +{ + if (hProcess != GetCurrentProcess()) + //if (GetProcessID(hProcess) != GetCurrentProcessId()) + flAllocationType |= VA_SHARED; + return VirtualAlloc(lpAddress, dwSize, flAllocationType, flProtect); +} + +/* MAKE_EXPORT VirtualFreeEx_new=VirtualFreeEx */ +BOOL WINAPI VirtualFreeEx_new(HANDLE hProcess, LPVOID lpAddress, DWORD dwSize, DWORD dwFreeType) +{ + return VirtualFree(lpAddress, dwSize, dwFreeType); +} diff --git a/apilibs/kexbases/Kernel32/_kernel32_apilist.c b/apilibs/kexbases/Kernel32/_kernel32_apilist.c new file mode 100644 index 0000000..a878c22 --- /dev/null +++ b/apilibs/kexbases/Kernel32/_kernel32_apilist.c @@ -0,0 +1,194 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +/*TODOS: +CreateRemoteThread +http://17slon.com/blogs/gabr/2007/02/four-ways-to-detect-vista.html +*/ + +#include "common.h" +#include "kexcoresdk.h" +#include "_kernel32_apilist.h" + +BOOL init_tryentercritsec(); +BOOL init_openthread(); + +BOOL init_kernel32() +{ + return init_tryentercritsec() && init_openthread(); +} + +/* + * MAKE_EXPORT GetWindowsDirectoryA=GetSystemWindowsDirectoryA + * MAKE_EXPORT GetWindowsDirectoryW=GetSystemWindowsDirectoryW + * MAKE_EXPORT GetSystemInfo=GetNativeSystemInfo + * MAKE_EXPORT SetLastError=RestoreLastError + */ + +static const apilib_named_api kernel32_named_apis[] = +{ +/*** AUTOGENERATED APILIST NAMED EXPORTS BEGIN ***/ + DECL_API("AddAtomW", AddAtomW_new), + DECL_API("AssignProcessToJobObject", AssignProcessToJobObject_new), + DECL_API("CopyFileExA", CopyFileExA_new), + DECL_API("CopyFileExW", CopyFileExW_new), + DECL_API("CopyFileW", CopyFileW_new), + DECL_API("CreateDirectoryExW", CreateDirectoryExW_new), + DECL_API("CreateDirectoryW", CreateDirectoryW_new), + DECL_API("CreateFileA", CreateFileA_fix), + DECL_API("CreateFileW", CreateFileW_new), + DECL_API("CreateHardLinkA", CreateHardLinkA_stub), + DECL_API("CreateHardLinkW", CreateHardLinkW_stub), + DECL_API("CreateJobObjectA", CreateJobObjectA_new), + DECL_API("CreateJobObjectW", CreateJobObjectW_new), + DECL_API("CreateThread", CreateThread_fix), + DECL_API("DefineDosDeviceW", DefineDosDeviceW_new), + DECL_API("DeleteCriticalSection", DeleteCriticalSection_new), + DECL_API("DeleteFileW", DeleteFileW_new), + DECL_API("EnumUILanguagesA", EnumUILanguagesA_new), + DECL_API("EnumUILanguagesW", EnumUILanguagesW_new), + DECL_API("FindAtomW", FindAtomW_new), + DECL_API("FindFirstChangeNotificationW", FindFirstChangeNotificationW_new), + DECL_API("FindFirstFileExW", FindFirstFileExW_stub), + DECL_API("FindFirstFileW", FindFirstFileW_new), + DECL_API("FindNextFileW", FindNextFileW_new), + DECL_API("FindResourceExW", FindResourceExW_new), + DECL_API("FindResourceW", FindResourceW_new), + DECL_API("FreeEnvironmentStringsW", FreeEnvironmentStringsW_new), + DECL_API("GetConsoleWindow", GetConsoleWindow_stub), + DECL_API("GetCurrentDirectoryW", GetCurrentDirectoryW_new), + DECL_API("GetDefaultCommConfigW", GetDefaultCommConfigW_new), + DECL_API("GetDiskFreeSpaceExW", GetDiskFreeSpaceExW_new), + DECL_API("GetDiskFreeSpaceW", GetDiskFreeSpaceW_new), + DECL_API("GetEnvironmentStringsW", GetEnvironmentStringsW_new), + DECL_API("GetFileAttributesExW", GetFileAttributesExW_new), + DECL_API("GetFileAttributesW", GetFileAttributesW_new), + DECL_API("GetFileSizeEx", GetFileSizeEx_new), + DECL_API("GetFullPathNameW", GetFullPathNameW_new), + DECL_API("GetLongPathNameW", GetLongPathNameW_new), + DECL_API("GetNativeSystemInfo", GetSystemInfo), + DECL_API("GetShortPathNameW", GetShortPathNameW_new), + DECL_API("GetStartupInfoW", GetStartupInfoW_new), + DECL_API("GetSystemDefaultUILanguage", GetSystemDefaultUILanguage_new), + DECL_API("GetSystemDirectoryW", GetSystemDirectoryW_new), + DECL_API("GetSystemWindowsDirectoryA", GetWindowsDirectoryA), + DECL_API("GetSystemWindowsDirectoryW", GetWindowsDirectoryW), + DECL_API("GetTempFileNameW", GetTempFileNameW_new), + DECL_API("GetTempPathW", GetTempPathW_new), + DECL_API("GetUserDefaultUILanguage", GetUserDefaultUILanguage_new), + DECL_API("GetVersion", GetVersion_WIN95), + DECL_API("GetVersion", GetVersion_WIN98), + DECL_API("GetVersion", GetVersion_WINME), + DECL_API("GetVersion", GetVersion_NT40), + DECL_API("GetVersion", GetVersion_NT2K), + DECL_API("GetVersion", GetVersion_WINXP), + DECL_API("GetVersion", GetVersion_WIN2K3), + DECL_API("GetVersion", GetVersion_VISTA), + DECL_API("GetVersion", GetVersion_WIN2K8), + DECL_API("GetVersionExA", GetVersionExA_WIN95), + DECL_API("GetVersionExA", GetVersionExA_WIN98), + DECL_API("GetVersionExA", GetVersionExA_WINME), + DECL_API("GetVersionExA", GetVersionExA_NT40), + DECL_API("GetVersionExA", GetVersionExA_NT2K), + DECL_API("GetVersionExA", GetVersionExA_WINXP), + DECL_API("GetVersionExA", GetVersionExA_WIN2K3), + DECL_API("GetVersionExA", GetVersionExA_VISTA), + DECL_API("GetVersionExA", GetVersionExA_WIN2K8), + DECL_API("GetVersionExW", GetVersionExW_WIN95), + DECL_API("GetVersionExW", GetVersionExW_WIN98), + DECL_API("GetVersionExW", GetVersionExW_WINME), + DECL_API("GetVersionExW", GetVersionExW_NT40), + DECL_API("GetVersionExW", GetVersionExW_NT2K), + DECL_API("GetVersionExW", GetVersionExW_WINXP), + DECL_API("GetVersionExW", GetVersionExW_WIN2K3), + DECL_API("GetVersionExW", GetVersionExW_VISTA), + DECL_API("GetVersionExW", GetVersionExW_WIN2K8), + DECL_API("GetWindowsDirectoryW", GetWindowsDirectoryW_new), + DECL_API("GlobalAddAtomW", GlobalAddAtomW_new), + DECL_API("GlobalFindAtomW", GlobalFindAtomW_new), + DECL_API("GlobalGetAtomNameW", GlobalGetAtomNameW_new), + DECL_API("GlobalMemoryStatusEx", GlobalMemoryStatusEx_new), + DECL_API("HeapLock", HeapLock_new), + DECL_API("HeapUnlock", HeapUnlock_new), + DECL_API("InitializeCriticalSectionAndSpinCount", InitializeCriticalSectionAndSpinCount_new), + DECL_API("IsProcessInJob", IsProcessInJob_new), + DECL_API("IsValidLanguageGroup", IsValidLanguageGroup_stub), + DECL_API("KEXVersion", KEXVersion), + DECL_API("LockFileEx", LockFileEx_new), + DECL_API("MapViewOfFileEx", MapViewOfFileEx_new), + DECL_API("Module32FirstW", Module32FirstW_new), + DECL_API("Module32NextW", Module32NextW_new), + DECL_API("MoveFileExA", MoveFileExA_new), + DECL_API("MoveFileExW", MoveFileExW_new), + DECL_API("MoveFileW", MoveFileW_new), + DECL_API("MoveFileWithProgressA", MoveFileWithProgressA_new), + DECL_API("MoveFileWithProgressW", MoveFileWithProgressW_new), + DECL_API("OpenJobObjectA", OpenJobObjectA_new), + DECL_API("OpenJobObjectW", OpenJobObjectW_new), + DECL_API("OpenThread", OpenThread_new), + DECL_API("OutputDebugStringW", OutputDebugStringW_new), + DECL_API("Process32FirstW", Process32FirstW_new), + DECL_API("Process32NextW", Process32NextW_new), + DECL_API("QueryInformationJobObject", QueryInformationJobObject_new), + DECL_API("QueueUserWorkItem", QueueUserWorkItem_stub), + DECL_API("RegisterWaitForSingleObject", RegisterWaitForSingleObject_new), + DECL_API("RegisterWaitForSingleObjectEx", RegisterWaitForSingleObjectEx_new), + DECL_API("RemoveDirectoryW", RemoveDirectoryW_new), + DECL_API("ReplaceFileA", ReplaceFileA_stub), + DECL_API("ReplaceFileW", ReplaceFileW_stub), + DECL_API("RestoreLastError", SetLastError), + DECL_API("SearchPathW", SearchPathW_new), + DECL_API("SetConsoleTitleW", SetConsoleTitleW_new), + DECL_API("SetCurrentDirectoryW", SetCurrentDirectoryW_new), + DECL_API("SetFileAttributesW", SetFileAttributesW_new), + DECL_API("SetFilePointerEx", SetFilePointerEx_new), + DECL_API("SetInformationJobObject", SetInformationJobObject_new), + DECL_API("TerminateJobObject", TerminateJobObject_new), + DECL_API("TryEnterCriticalSection", TryEnterCriticalSection_new), + DECL_API("UnregisterWait", UnregisterWait_new), + DECL_API("UnregisterWaitEx", UnregisterWaitEx_new), + DECL_API("VerLanguageNameW", VerLanguageNameW_new), + DECL_API("VerSetConditionMask", VerSetConditionMask_new), + DECL_API("VerifyVersionInfoA", VerifyVersionInfoA_NT2K), + DECL_API("VerifyVersionInfoA", VerifyVersionInfoA_WINXP), + DECL_API("VerifyVersionInfoA", VerifyVersionInfoA_WIN2K3), + DECL_API("VerifyVersionInfoA", VerifyVersionInfoA_VISTA), + DECL_API("VerifyVersionInfoA", VerifyVersionInfoA_WIN2K8), + DECL_API("VerifyVersionInfoW", VerifyVersionInfoW_NT2K), + DECL_API("VerifyVersionInfoW", VerifyVersionInfoW_WINXP), + DECL_API("VerifyVersionInfoW", VerifyVersionInfoW_WIN2K3), + DECL_API("VerifyVersionInfoW", VerifyVersionInfoW_VISTA), + DECL_API("VerifyVersionInfoW", VerifyVersionInfoW_WIN2K8), + DECL_API("VirtualAllocEx", VirtualAllocEx_new), + DECL_API("VirtualFreeEx", VirtualFreeEx_new), + DECL_API("lstrcpynW", lstrcpynW_new), +/*** AUTOGENERATED APILIST NAMED EXPORTS END ***/ +}; + +#if 0 +static const apilib_unnamed_api kernel32_ordinal_apis[] = +{ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS BEGIN ***/ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS END ***/ +}; +#endif + +const apilib_api_table apitable_kernel32 = DECL_TAB("KERNEL32.DLL", kernel32_named_apis, 0 /*kernel32_ordinal_apis*/); diff --git a/apilibs/kexbases/Kernel32/_kernel32_apilist.h b/apilibs/kexbases/Kernel32/_kernel32_apilist.h new file mode 100644 index 0000000..2c24e1c --- /dev/null +++ b/apilibs/kexbases/Kernel32/_kernel32_apilist.h @@ -0,0 +1,165 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#ifndef _KERNEL32_APILIST_H +#define _KERNEL32_APILIST_H + +#include "auxdecl.h" +#include "kexcoresdk.h" +#include + +BOOL init_kernel32(); +extern const apilib_api_table apitable_kernel32; + +/*** AUTOGENERATED APILIST DECLARATIONS BEGIN ***/ +BOOL WINAPI CopyFileExA_new(LPCSTR lpExistingFileNameA, LPCSTR lpNewFileNameA, LPPROGRESS_ROUTINE lpProgressRoutine, LPVOID lpData, LPBOOL pbCancel, DWORD dwCopyFlags); +HANDLE WINAPI CreateFileA_fix(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDistribution, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile); +HANDLE WINAPI CreateThread_fix(LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId); +void WINAPI DeleteCriticalSection_new(PCRITICAL_SECTION lpCriticalSection); +BOOL WINAPI GetFileSizeEx_new(HANDLE hFile, PLARGE_INTEGER lpFileSize); +BOOL WINAPI GlobalMemoryStatusEx_new(LPMEMORYSTATUSEX lpmemex); +BOOL WINAPI HeapLock_new(HANDLE hHeap); +BOOL WINAPI HeapUnlock_new(HANDLE hHeap); +BOOL WINAPI InitializeCriticalSectionAndSpinCount_new(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount); +HANDLE WINAPI CreateJobObjectA_new(LPSECURITY_ATTRIBUTES sa, LPCSTR name); +HANDLE WINAPI CreateJobObjectW_new(LPSECURITY_ATTRIBUTES sa, LPCWSTR name); +BOOL WINAPI TerminateJobObject_new(HANDLE job, UINT exit_code); +HANDLE WINAPI OpenJobObjectA_new(DWORD access, BOOL inherit, LPCSTR name); +HANDLE WINAPI OpenJobObjectW_new(DWORD access, BOOL inherit, LPCWSTR name); +BOOL WINAPI QueryInformationJobObject_new(HANDLE job, PVOID classs, LPVOID info, DWORD len, DWORD *ret_len); +BOOL WINAPI SetInformationJobObject_new(HANDLE job, PVOID classs, LPVOID info, DWORD len); +BOOL WINAPI AssignProcessToJobObject_new(HANDLE job, HANDLE process); +BOOL WINAPI IsProcessInJob_new(HANDLE process, HANDLE job, PBOOL result); +void WINAPI KEXVersion(char* out); +BOOL WINAPI LockFileEx_new(HANDLE hFile, DWORD dwFlags, DWORD dwReserved, DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh, LPOVERLAPPED lpOverlapped); +LPVOID WINAPI MapViewOfFileEx_new(HANDLE hFileMappingObject, DWORD dwDesiredAccess, DWORD dwFileOffsetHigh, DWORD dwFileOffsetLow, SIZE_T dwNumberOfBytesToMap, LPVOID lpBaseAddress); +BOOL WINAPI MoveFileExA_new(LPCSTR lpExistingFileNameA, LPCSTR lpNewFileNameA, DWORD dwFlags); +BOOL WINAPI MoveFileWithProgressA_new(LPCSTR lpExistingFileName, LPCSTR lpNewFileName, LPPROGRESS_ROUTINE lpProgressRoutine, LPVOID lpData, DWORD dwFlags); +HANDLE WINAPI OpenThread_new(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwThreadId); +BOOL WINAPI SetFilePointerEx_new(HANDLE hFile, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod); +BOOL WINAPI RegisterWaitForSingleObject_new(PHANDLE phNewWaitObject, HANDLE hObject, PVOID Callback, PVOID Context, ULONG dwMilliseconds, ULONG dwFlags); +HANDLE WINAPI RegisterWaitForSingleObjectEx_new(HANDLE hObject, PVOID Callback, PVOID Context, ULONG dwMilliseconds, ULONG dwFlags); +BOOL WINAPI UnregisterWait_new(HANDLE WaitHandle); +BOOL WINAPI UnregisterWaitEx_new(HANDLE WaitHandle, HANDLE CompletionEvent); +BOOL WINAPI TryEnterCriticalSection_new(CRITICAL_SECTION* cs); +LPVOID WINAPI VirtualAllocEx_new(HANDLE hProcess, LPVOID lpAddress, DWORD dwSize, DWORD flAllocationType, DWORD flProtect); +BOOL WINAPI VirtualFreeEx_new(HANDLE hProcess, LPVOID lpAddress, DWORD dwSize, DWORD dwFreeType); +STUB CreateHardLinkA_stub; +STUB CreateHardLinkW_stub; +STUB GetConsoleWindow_stub; +STUB IsValidLanguageGroup_stub; +STUB QueueUserWorkItem_stub; +STUB ReplaceFileA_stub; +STUB ReplaceFileW_stub; +STUB FindFirstFileExW_stub; +LANGID WINAPI GetUserDefaultUILanguage_new(void); +LANGID WINAPI GetSystemDefaultUILanguage_new(void); +BOOL WINAPI EnumUILanguagesA_new(UILANGUAGE_ENUMPROCA pUILangEnumProc, DWORD dwFlags, LONG_PTR lParam); +BOOL WINAPI EnumUILanguagesW_new(UILANGUAGE_ENUMPROCW pUILangEnumProc, DWORD dwFlags, LONG_PTR lParam); +ATOM WINAPI AddAtomW_new(LPCWSTR strW); +BOOL WINAPI CopyFileExW_new(LPCWSTR lpExistingFileNameW, LPCWSTR lpNewFileNameW, LPPROGRESS_ROUTINE lpProgressRoutine, LPVOID lpData, LPBOOL pbCancel, DWORD dwCopyFlags); +BOOL WINAPI CopyFileW_new(LPCWSTR lpExistingFileNameW, LPCWSTR lpNewFileNameW, BOOL bFailIfExists); +BOOL WINAPI CreateDirectoryExW_new(LPCWSTR templatedirW, LPCWSTR newdirW, LPSECURITY_ATTRIBUTES secattr); +BOOL WINAPI CreateDirectoryW_new(LPCWSTR PathW, LPSECURITY_ATTRIBUTES SecAttr); +HANDLE WINAPI CreateFileW_new(LPCWSTR strW, DWORD access, DWORD sharemode, LPSECURITY_ATTRIBUTES secattr, DWORD creatdistr, DWORD flags, HANDLE temp); +BOOL WINAPI DefineDosDeviceW_new(DWORD dwFlags, LPCWSTR lpDeviceNameW, LPCWSTR lpTargetPathW); +BOOL WINAPI DeleteFileW_new(LPCWSTR lpFileNameW); +ATOM WINAPI FindAtomW_new(LPCWSTR strW); +HANDLE WINAPI FindFirstChangeNotificationW_new(LPCWSTR pathW, BOOL watchsubtree, DWORD filter); +HANDLE WINAPI FindFirstFileW_new(LPCWSTR strW, LPWIN32_FIND_DATAW dataW); +BOOL WINAPI FindNextFileW_new(HANDLE handle, LPWIN32_FIND_DATAW dataW); +HRSRC WINAPI FindResourceExW_new(HMODULE hModule, LPCWSTR typeW, LPCWSTR nameW, WORD lang); +HRSRC WINAPI FindResourceW_new(HINSTANCE hModule, LPCWSTR name, LPCWSTR type); +BOOL WINAPI FreeEnvironmentStringsW_new(void* env); +DWORD WINAPI GetCurrentDirectoryW_new(DWORD nBufferLength, LPWSTR lpBufferW); +BOOL WINAPI GetDefaultCommConfigW_new(LPCWSTR lpszNameW, LPCOMMCONFIG lpCC, LPDWORD lpdwSize); +BOOL WINAPI GetDiskFreeSpaceExW_new(LPCWSTR lpDirectoryNameW, PULARGE_INTEGER lpFreeBytesAvailableToCaller, PULARGE_INTEGER lpTotalNumberOfBytes, PULARGE_INTEGER lpTotalNumberOfFreeBytes); +BOOL WINAPI GetDiskFreeSpaceW_new(LPCWSTR lpRootPathNameW, LPDWORD lpSectorsPerCluster, LPDWORD lpBytesPerSector, LPDWORD lpNumberOfFreeClusters, LPDWORD lpTotalNumberOfClusters); +void* WINAPI GetEnvironmentStringsW_new(void); +BOOL WINAPI GetFileAttributesExW_new(LPCWSTR lpFileNameW, GET_FILEEX_INFO_LEVELS fInfoLevelId, LPVOID lpFileInformation); +DWORD WINAPI GetFileAttributesW_new(LPCWSTR lpFileNameW); +DWORD WINAPI GetFullPathNameW_new(LPCWSTR lpFileNameW, DWORD nBufferLength, LPWSTR lpBufferW, LPWSTR *lpFilePartW); +DWORD WINAPI GetLongPathNameW_new(LPCWSTR lpszShortPathW, LPWSTR lpszLongPathW, DWORD cchBuffer); +DWORD WINAPI GetShortPathNameW_new(LPCWSTR lpszLongPathW, LPWSTR lpszShortPathW, DWORD cchBuffer); +VOID WINAPI GetStartupInfoW_new(LPSTARTUPINFOW lpStartupInfo); +UINT WINAPI GetSystemDirectoryW_new(LPWSTR lpBufferW, UINT uSize); +UINT WINAPI GetTempFileNameW_new(LPCWSTR lpPathNameW, LPCWSTR lpPrefixStringW, UINT uUnique, LPWSTR lpTempFileNameW); +DWORD WINAPI GetTempPathW_new(DWORD nBufferLength, LPWSTR lpBufferW); +UINT WINAPI GetWindowsDirectoryW_new(LPWSTR lpBufferW, UINT uSize); +ATOM WINAPI GlobalAddAtomW_new(LPCWSTR strW); +ATOM WINAPI GlobalFindAtomW_new(LPCWSTR strW); +UINT WINAPI GlobalGetAtomNameW_new(ATOM atom, LPWSTR bufferW, int size); +BOOL WINAPI Module32FirstW_new(HANDLE hSnapshot, LPMODULEENTRY32W lpmeW); +BOOL WINAPI Module32NextW_new(HANDLE hSnapshot, LPMODULEENTRY32W lpmeW); +BOOL WINAPI MoveFileExW_new(LPCWSTR existingfileW, LPCWSTR newfileW, DWORD flags); +BOOL WINAPI MoveFileW_new(LPCWSTR existingfileW, LPCWSTR newfileW); +BOOL WINAPI MoveFileWithProgressW_new(LPCWSTR existingfileW, LPCWSTR newfileW, LPPROGRESS_ROUTINE lpProgressRoutine, LPVOID lpData, DWORD dwFlags); +void WINAPI OutputDebugStringW_new(LPCWSTR strW); +BOOL WINAPI Process32FirstW_new(HANDLE hSnapshot, LPPROCESSENTRY32W lppeW); +BOOL WINAPI Process32NextW_new(HANDLE hSnapshot, LPPROCESSENTRY32W lppeW); +BOOL WINAPI RemoveDirectoryW_new(LPCWSTR lpPathNameW); +DWORD WINAPI SearchPathW_new(LPCWSTR lpPathW, LPCWSTR lpFileNameW, LPCWSTR lpExtensionW, DWORD nBufferLength, LPWSTR lpBufferW, LPWSTR *lpFilePartW); +BOOL WINAPI SetConsoleTitleW_new(LPCWSTR strW); +BOOL WINAPI SetCurrentDirectoryW_new(LPCWSTR lpPathNameW); +BOOL WINAPI SetFileAttributesW_new(LPCWSTR lpFileNameW, DWORD dwFileAttributes); +DWORD WINAPI VerLanguageNameW_new(DWORD wLang, LPWSTR szLangW, DWORD nSize); +LPWSTR WINAPI lstrcpynW_new(LPWSTR dst, LPCWSTR src, INT n); +ULONGLONG WINAPI VerSetConditionMask_new(ULONGLONG dwlConditionMask, DWORD dwTypeBitMask, BYTE dwConditionMask); +DWORD WINAPI GetVersion_WIN95(void); +DWORD WINAPI GetVersion_WIN98(void); +DWORD WINAPI GetVersion_WINME(void); +DWORD WINAPI GetVersion_NT40(void); +DWORD WINAPI GetVersion_NT2K(void); +DWORD WINAPI GetVersion_WINXP(void); +DWORD WINAPI GetVersion_WIN2K3(void); +DWORD WINAPI GetVersion_VISTA(void); +DWORD WINAPI GetVersion_WIN2K8(void); +BOOL WINAPI GetVersionExA_WIN95(LPOSVERSIONINFOA lpVersionInfo); +BOOL WINAPI GetVersionExW_WIN95(LPOSVERSIONINFOW lpVersionInfo); +BOOL WINAPI GetVersionExA_WIN98(LPOSVERSIONINFOA lpVersionInfo); +BOOL WINAPI GetVersionExW_WIN98(LPOSVERSIONINFOW lpVersionInfo); +BOOL WINAPI GetVersionExA_WINME(LPOSVERSIONINFOA lpVersionInfo); +BOOL WINAPI GetVersionExW_WINME(LPOSVERSIONINFOW lpVersionInfo); +BOOL WINAPI GetVersionExA_NT40(LPOSVERSIONINFOA lpVersionInfo); +BOOL WINAPI GetVersionExW_NT40(LPOSVERSIONINFOW lpVersionInfo); +BOOL WINAPI GetVersionExA_NT2K(LPOSVERSIONINFOA lpVersionInfo); +BOOL WINAPI GetVersionExW_NT2K(LPOSVERSIONINFOW lpVersionInfo); +BOOL WINAPI GetVersionExA_WINXP(LPOSVERSIONINFOA lpVersionInfo); +BOOL WINAPI GetVersionExW_WINXP(LPOSVERSIONINFOW lpVersionInfo); +BOOL WINAPI GetVersionExA_WIN2K3(LPOSVERSIONINFOA lpVersionInfo); +BOOL WINAPI GetVersionExW_WIN2K3(LPOSVERSIONINFOW lpVersionInfo); +BOOL WINAPI GetVersionExA_VISTA(LPOSVERSIONINFOA lpVersionInfo); +BOOL WINAPI GetVersionExW_VISTA(LPOSVERSIONINFOW lpVersionInfo); +BOOL WINAPI GetVersionExA_WIN2K8(LPOSVERSIONINFOA lpVersionInfo); +BOOL WINAPI GetVersionExW_WIN2K8(LPOSVERSIONINFOW lpVersionInfo); +BOOL WINAPI VerifyVersionInfoA_NT2K(LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask, DWORDLONG dwlConditionMask); +BOOL WINAPI VerifyVersionInfoW_NT2K(LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask, DWORDLONG dwlConditionMask); +BOOL WINAPI VerifyVersionInfoA_WINXP(LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask, DWORDLONG dwlConditionMask); +BOOL WINAPI VerifyVersionInfoW_WINXP(LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask, DWORDLONG dwlConditionMask); +BOOL WINAPI VerifyVersionInfoA_WIN2K3(LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask, DWORDLONG dwlConditionMask); +BOOL WINAPI VerifyVersionInfoW_WIN2K3(LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask, DWORDLONG dwlConditionMask); +BOOL WINAPI VerifyVersionInfoA_VISTA(LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask, DWORDLONG dwlConditionMask); +BOOL WINAPI VerifyVersionInfoW_VISTA(LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask, DWORDLONG dwlConditionMask); +BOOL WINAPI VerifyVersionInfoA_WIN2K8(LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask, DWORDLONG dwlConditionMask); +BOOL WINAPI VerifyVersionInfoW_WIN2K8(LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask, DWORDLONG dwlConditionMask); +/*** AUTOGENERATED APILIST DECLARATIONS END ***/ + +#endif diff --git a/apilibs/kexbases/Kernel32/_kernel32_stubs.c b/apilibs/kexbases/Kernel32/_kernel32_stubs.c new file mode 100644 index 0000000..5972330 --- /dev/null +++ b/apilibs/kexbases/Kernel32/_kernel32_stubs.c @@ -0,0 +1,31 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" + +UNIMPL_FUNC(CreateHardLinkA, 3); +UNIMPL_FUNC(CreateHardLinkW, 3); +UNIMPL_FUNC(GetConsoleWindow, 0); +UNIMPL_FUNC(IsValidLanguageGroup, 2); +UNIMPL_FUNC(QueueUserWorkItem, 3); +UNIMPL_FUNC(ReplaceFileA, 6); +UNIMPL_FUNC(ReplaceFileW, 6); +UNIMPL_FUNC(FindFirstFileExW, 6); diff --git a/apilibs/kexbases/Kernel32/uilang.c b/apilibs/kexbases/Kernel32/uilang.c new file mode 100644 index 0000000..77702d0 --- /dev/null +++ b/apilibs/kexbases/Kernel32/uilang.c @@ -0,0 +1,160 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include + +static DWORD hexstr_to_dword(const char* hexstr) +{ + int i; + DWORD res = 0; + + for (i = 0 ; i < 8 ; i++) + { + res <<= 4; + if (hexstr[i] >= '0' && hexstr[i] <= '9') + res += hexstr[i] - '0'; + else if (hexstr[i] >= 'a' && hexstr[i] <= 'f') + res += hexstr[i] - 'a' + 0xa; + else if (hexstr[i] >= 'A' && hexstr[i] <= 'F') + res += hexstr[i] - 'A' + 0xA; + else + return (DWORD)-1; + } + return res; +} + +static void dword_to_hexstr(DWORD val, void* _out, BOOL unicode) +{ + int i; + char* out = (char*) _out; + + for (i = 0 ; i < 8 ; i++) + { + int v = (val & 0xf0000000) >> 28; + val <<= 4; + if (v <= 9) + *out++ = v + '0'; + else + *out++ = v - 0xa + 'A'; + if (unicode) + *out++ = 0; + } + *out++ = 0; + if (unicode) + *out++ = 0; +} + +static LANGID UILanguage_readreg() +{ + HKEY key; + DWORD type; + char data[10]; + LONG res; + DWORD count = sizeof(data); + + if (RegOpenKey(HKEY_CURRENT_USER, "Control Panel\\desktop\\ResourceLocale", &key)) + return (LANGID) -1; + + res = RegQueryValueEx(key, NULL, NULL, &type, (BYTE*)data, &count); + RegCloseKey(key); + + if (!res && type == REG_SZ && count == 9) + { + DWORD res = hexstr_to_dword(data); + if (res < 0x10000) + return (LANGID) res; + } + return (LANGID) -1; +} + +/* MAKE_EXPORT GetUserDefaultUILanguage_new=GetUserDefaultUILanguage */ +LANGID WINAPI GetUserDefaultUILanguage_new(void) +{ + LANGID res = UILanguage_readreg(); + if (res != (LANGID) -1) + return res; + return (LANGID) 0x409; /* default to English US */ +} + +/* MAKE_EXPORT GetSystemDefaultUILanguage_new=GetSystemDefaultUILanguage */ +LANGID WINAPI GetSystemDefaultUILanguage_new(void) +{ + LANGID res = UILanguage_readreg(); + if (res != (LANGID) -1) + return res; + return (LANGID) 0x409; /* default to English US */ +} + +typedef long LONG_PTR; +typedef BOOL (CALLBACK *UILANGUAGE_ENUMPROCA)(LPSTR, LONG_PTR); +typedef BOOL (CALLBACK *UILANGUAGE_ENUMPROCW)(LPWSTR, LONG_PTR); + +/* MAKE_EXPORT EnumUILanguagesA_new=EnumUILanguagesA */ +BOOL WINAPI EnumUILanguagesA_new(UILANGUAGE_ENUMPROCA pUILangEnumProc, DWORD dwFlags, LONG_PTR lParam) +{ + char buf[10]; + LANGID lid; + + if (!pUILangEnumProc) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + if (dwFlags) + { + SetLastError(ERROR_INVALID_FLAGS); + return FALSE; + } + + lid = GetSystemDefaultUILanguage_new(); + + dword_to_hexstr(lid, buf, FALSE); + + pUILangEnumProc(buf, lParam); + return TRUE; +} + +/* MAKE_EXPORT EnumUILanguagesW_new=EnumUILanguagesW */ +BOOL WINAPI EnumUILanguagesW_new(UILANGUAGE_ENUMPROCW pUILangEnumProc, DWORD dwFlags, LONG_PTR lParam) +{ + WCHAR buf[10]; + LANGID lid; + + if (!pUILangEnumProc) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + if (dwFlags) + { + SetLastError(ERROR_INVALID_FLAGS); + return FALSE; + } + + lid = GetSystemDefaultUILanguage_new(); + + dword_to_hexstr(lid, buf, TRUE); + + pUILangEnumProc(buf, lParam); + return TRUE; +} diff --git a/apilibs/kexbases/Kernel32/unikernel32.c b/apilibs/kexbases/Kernel32/unikernel32.c new file mode 100644 index 0000000..eeccb42 --- /dev/null +++ b/apilibs/kexbases/Kernel32/unikernel32.c @@ -0,0 +1,794 @@ +/* + * KernelEx + * Copyright (C) 2006-2008, 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. + * + */ + +#define _WIN32_WINDOWS 0x0410 +#define ENABLE_FILEAPIS +#include "common.h" +#include +#include "_kernel32_apilist.h" + +//MAKE_EXPORT AddAtomW_new=AddAtomW +ATOM WINAPI AddAtomW_new(LPCWSTR strW) +{ + ALLOC_WtoA(str); + return AddAtomA(strA); +} + +/* something seems to be wrong with this and I don't know what +INT WINAPI CompareStringW_new(LCID lcid, DWORD style, + LPCWSTR str1, INT len1, LPCWSTR str2, INT len2) +{ + CHAR buf1A[BUFSIZE]; + CHAR buf2A[BUFSIZE]; + LPSTR str1A, str2A; + INT len1A, len2A, ret; + UINT locale_cp = CP_ACP; + int lasterr; + + DBGMSGW((L"CompareStringW(0x%1!x!,0x%2!x!,%3!s!,%4!d!,%5!s!,%6!d!)\n",lcid,style,str1,len1,str2,len2)); + + lasterr = GetLastError(); + if (lcid == LANG_INVARIANT) lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT); + + if (!str1 || !str2) + { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + if (!(style & LOCALE_USE_CP_ACP)) + if (!GetLocaleInfoA(lcid, LOCALE_IDEFAULTANSICODEPAGE|LOCALE_RETURN_NUMBER, + (CHAR *)&locale_cp, sizeof(locale_cp)/sizeof(CHAR))) locale_cp = 0; + + str1A = buf1A; + if (len1 != 0) + { + len1A = WideCharToMultiByte(locale_cp, 0, str1, len1, buf1A, BUFSIZE, NULL, NULL); + if (!len1A) + { + len1A = WideCharToMultiByte(locale_cp, 0, str1, len1, NULL, 0, NULL, NULL); + str1A = HeapAlloc(GetProcessHeap(), 0, len1A); + if (!str1A) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return 0; + } + WideCharToMultiByte(locale_cp, 0, str1, len1, str1A, len1A, NULL, NULL); + } + } + str2A = buf2A; + if (len2 != 0) + { + len2A = WideCharToMultiByte(locale_cp, 0, str2, len2, buf2A, BUFSIZE, NULL, NULL); + if (!len2A) + { + len2A = WideCharToMultiByte(locale_cp, 0, str2, len2, NULL, 0, NULL, NULL); + str2A = HeapAlloc(GetProcessHeap(), 0, len2A); + if (!str2A) + { + if (str1A != buf1A) HeapFree(GetProcessHeap(), 0, str1A); + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return 0; + } + WideCharToMultiByte(locale_cp, 0, str2, len2, str2A, len2A, NULL, NULL); + } + } + SetLastError(lasterr); + + ret = CompareStringA(lcid, style, str1A, len1A, str2A, len2A); + + if (str1A != buf1A) HeapFree(GetProcessHeap(), 0, str1A); + if (str2A != buf2A) HeapFree(GetProcessHeap(), 0, str2A); + return ret; +} +*/ + +//MAKE_EXPORT CopyFileExW_new=CopyFileExW +BOOL WINAPI CopyFileExW_new(LPCWSTR lpExistingFileNameW, LPCWSTR lpNewFileNameW, LPPROGRESS_ROUTINE lpProgressRoutine, LPVOID lpData, LPBOOL pbCancel, DWORD dwCopyFlags) +{ + file_GetCP(); + file_ALLOC_WtoA(lpExistingFileName); + file_ALLOC_WtoA(lpNewFileName); + return CopyFileExA_new(lpExistingFileNameA, lpNewFileNameA, + lpProgressRoutine, lpData, pbCancel, dwCopyFlags); +} + +//MAKE_EXPORT CopyFileW_new=CopyFileW +BOOL WINAPI CopyFileW_new(LPCWSTR lpExistingFileNameW, LPCWSTR lpNewFileNameW, BOOL bFailIfExists) +{ + file_GetCP(); + file_ALLOC_WtoA(lpExistingFileName); + file_ALLOC_WtoA(lpNewFileName); + return CopyFileA(lpExistingFileNameA, lpNewFileNameA, bFailIfExists); +} + +//MAKE_EXPORT CreateDirectoryExW_new=CreateDirectoryExW +BOOL WINAPI CreateDirectoryExW_new(LPCWSTR templatedirW, LPCWSTR newdirW, LPSECURITY_ATTRIBUTES secattr) +{ + file_GetCP(); + file_ALLOC_WtoA(templatedir); + file_ALLOC_WtoA(newdir); + return CreateDirectoryExA(templatedirA, newdirA, secattr); +} + +//MAKE_EXPORT CreateDirectoryW_new=CreateDirectoryW +BOOL WINAPI CreateDirectoryW_new(LPCWSTR PathW, LPSECURITY_ATTRIBUTES SecAttr) +{ + file_GetCP(); + file_ALLOC_WtoA(Path); + return CreateDirectoryA(PathA, SecAttr); +} + +//MAKE_EXPORT CreateFileW_new=CreateFileW +HANDLE WINAPI CreateFileW_new(LPCWSTR strW, DWORD access, DWORD sharemode, + LPSECURITY_ATTRIBUTES secattr, DWORD creatdistr, DWORD flags, HANDLE temp) +{ + file_GetCP(); + file_ALLOC_WtoA(str); + return CreateFileA_fix(strA, access, sharemode, secattr, creatdistr, flags, temp); +} + +//MAKE_EXPORT DefineDosDeviceW_new=DefineDosDeviceW +BOOL WINAPI DefineDosDeviceW_new(DWORD dwFlags, LPCWSTR lpDeviceNameW, + LPCWSTR lpTargetPathW) +{ + file_GetCP(); + file_ALLOC_WtoA(lpDeviceName); + file_ALLOC_WtoA(lpTargetPath); + return DefineDosDeviceA(dwFlags, lpDeviceNameA, lpTargetPathA); +} + +//MAKE_EXPORT DeleteFileW_new=DeleteFileW +BOOL WINAPI DeleteFileW_new(LPCWSTR lpFileNameW) +{ + file_GetCP(); + file_ALLOC_WtoA(lpFileName); + return DeleteFileA(lpFileNameA); +} + +//MAKE_EXPORT FindAtomW_new=FindAtomW +ATOM WINAPI FindAtomW_new(LPCWSTR strW) +{ + ALLOC_WtoA(str); + return FindAtomA(strA); +} + +//MAKE_EXPORT FindFirstChangeNotificationW_new=FindFirstChangeNotificationW +HANDLE WINAPI FindFirstChangeNotificationW_new(LPCWSTR pathW, BOOL watchsubtree, DWORD filter) +{ + file_GetCP(); + file_ALLOC_WtoA(path); + return FindFirstChangeNotificationA(pathA, watchsubtree, filter); +} + +//MAKE_EXPORT FindFirstFileW_new=FindFirstFileW +HANDLE WINAPI FindFirstFileW_new(LPCWSTR strW, LPWIN32_FIND_DATAW dataW) +{ + HANDLE ret; + char cFileNameA[MAX_PATH]; + char cAlternateFileNameA[14]; + WCHAR* cFileNameW = dataW->cFileName; + WCHAR* cAlternateFileNameW = dataW->cAlternateFileName; + file_GetCP(); + file_ALLOC_WtoA(str); + ret = FindFirstFileA(strA, (LPWIN32_FIND_DATAA)dataW); + if (ret != INVALID_HANDLE_VALUE) + { + strcpy(cFileNameA, ((LPWIN32_FIND_DATAA)dataW)->cFileName); + strcpy(cAlternateFileNameA, ((LPWIN32_FIND_DATAA)dataW)->cAlternateFileName); + file_AtoW(cFileName, sizeof(dataW->cFileName) / sizeof(WCHAR)); + file_AtoW(cAlternateFileName, sizeof(dataW->cAlternateFileName) / sizeof(WCHAR)); + } + return ret; +} + +//MAKE_EXPORT FindNextFileW_new=FindNextFileW +BOOL WINAPI FindNextFileW_new(HANDLE handle, LPWIN32_FIND_DATAW dataW) +{ + BOOL ret; + char cFileNameA[MAX_PATH]; + char cAlternateFileNameA[14]; + WCHAR* cFileNameW = dataW->cFileName; + WCHAR* cAlternateFileNameW = dataW->cAlternateFileName; + ret = FindNextFileA(handle, (LPWIN32_FIND_DATAA)dataW); + if (ret) + { + file_GetCP(); + strcpy(cFileNameA, ((LPWIN32_FIND_DATAA)dataW)->cFileName); + strcpy(cAlternateFileNameA, ((LPWIN32_FIND_DATAA)dataW)->cAlternateFileName); + file_AtoW(cFileName, sizeof(dataW->cFileName) / sizeof(WCHAR)); + file_AtoW(cAlternateFileName, sizeof(dataW->cAlternateFileName) / sizeof(WCHAR)); + } + return ret; +} + +//MAKE_EXPORT FindResourceExW_new=FindResourceExW +HRSRC WINAPI FindResourceExW_new(HMODULE hModule, LPCWSTR typeW, LPCWSTR nameW, WORD lang) +{ + LPSTR nameA, typeA; + + if (HIWORD(nameW)) + { + _ALLOC_WtoA(name); + } + else + nameA = (LPSTR) nameW; + + if (HIWORD(typeW)) + { + _ALLOC_WtoA(type); + } + else + typeA = (LPSTR) typeW; + + return FindResourceExA(hModule, typeA, nameA, lang); +} + +//MAKE_EXPORT FindResourceW_new=FindResourceW +HRSRC WINAPI FindResourceW_new(HINSTANCE hModule, LPCWSTR name, LPCWSTR type) +{ + return FindResourceExW_new(hModule, type, name, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)); +} + +//MAKE_EXPORT FreeEnvironmentStringsW_new=FreeEnvironmentStringsW +BOOL WINAPI FreeEnvironmentStringsW_new(void* env) +{ + return HeapFree(GetProcessHeap(), 0, env); +} + +//MAKE_EXPORT GetCurrentDirectoryW_new=GetCurrentDirectoryW +DWORD WINAPI GetCurrentDirectoryW_new(DWORD nBufferLength, LPWSTR lpBufferW) +{ + DWORD ret; + char lpBufferA[MAX_PATH]; + ret = GetCurrentDirectoryA(MAX_PATH, lpBufferA); + if (ret) + { + file_GetCP(); + if (ret > MAX_PATH) + { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + return 0; + } + ret = file_AtoW(lpBuffer, 0); + if (ret <= nBufferLength) + { + ret = file_AtoW(lpBuffer, nBufferLength); + if (ret) ret--; + } + } + return ret; +} + +//MAKE_EXPORT GetDefaultCommConfigW_new=GetDefaultCommConfigW +BOOL WINAPI GetDefaultCommConfigW_new(LPCWSTR lpszNameW, LPCOMMCONFIG lpCC, LPDWORD lpdwSize) +{ + ALLOC_WtoA(lpszName); + return GetDefaultCommConfigA(lpszNameA, lpCC, lpdwSize); +} + +//MAKE_EXPORT GetDiskFreeSpaceExW_new=GetDiskFreeSpaceExW +BOOL WINAPI GetDiskFreeSpaceExW_new(LPCWSTR lpDirectoryNameW, PULARGE_INTEGER lpFreeBytesAvailableToCaller, PULARGE_INTEGER lpTotalNumberOfBytes, PULARGE_INTEGER lpTotalNumberOfFreeBytes) +{ + file_GetCP(); + file_ALLOC_WtoA(lpDirectoryName); + return GetDiskFreeSpaceExA(lpDirectoryNameA, lpFreeBytesAvailableToCaller, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes); +} + +//MAKE_EXPORT GetDiskFreeSpaceW_new=GetDiskFreeSpaceW +BOOL WINAPI GetDiskFreeSpaceW_new(LPCWSTR lpRootPathNameW, LPDWORD lpSectorsPerCluster, LPDWORD lpBytesPerSector, LPDWORD lpNumberOfFreeClusters, LPDWORD lpTotalNumberOfClusters) +{ + file_GetCP(); + file_ALLOC_WtoA(lpRootPathName); + return GetDiskFreeSpaceA(lpRootPathNameA, lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters); +} + +//MAKE_EXPORT GetEnvironmentStringsW_new=GetEnvironmentStringsW +void* WINAPI GetEnvironmentStringsW_new(void) +{ + int len; + WCHAR* envW; + char* envA = GetEnvironmentStringsA(); + char* ptrA = (char*) envA; + if (!envA) return envA; + + do while (*ptrA++); while (*++ptrA); + len = (int) ptrA - (int) envA; + + envW = (WCHAR*) HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); + if (envW) + ABUFtoW(env, len, len); + FreeEnvironmentStringsA(envA); + return envW; +} + +//MAKE_EXPORT GetFileAttributesExW_new=GetFileAttributesExW +BOOL WINAPI GetFileAttributesExW_new(LPCWSTR lpFileNameW, GET_FILEEX_INFO_LEVELS fInfoLevelId, + LPVOID lpFileInformation) +{ + file_GetCP(); + file_ALLOC_WtoA(lpFileName); + return GetFileAttributesExA(lpFileNameA, fInfoLevelId, lpFileInformation); +} + +//MAKE_EXPORT GetFileAttributesW_new=GetFileAttributesW +DWORD WINAPI GetFileAttributesW_new(LPCWSTR lpFileNameW) +{ + file_GetCP(); + file_ALLOC_WtoA(lpFileName); + return GetFileAttributesA(lpFileNameA); +} + +//MAKE_EXPORT GetFullPathNameW_new=GetFullPathNameW +DWORD WINAPI GetFullPathNameW_new(LPCWSTR lpFileNameW, DWORD nBufferLength, LPWSTR lpBufferW, LPWSTR *lpFilePartW) +{ + DWORD ret; + char lpBufferA[MAX_PATH]; + file_GetCP(); + file_ALLOC_WtoA(lpFileName); + ret = GetFullPathNameA(lpFileNameA, MAX_PATH, lpBufferA, NULL); + if (ret) + { + if (ret > MAX_PATH) + { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + return 0; + } + ret = file_AtoW(lpBuffer, 0); + if (ret <= nBufferLength) + { + ret = file_AtoW(lpBuffer, nBufferLength); + if (ret && lpFilePartW) + { + if (lpBufferW[ret - 1] == '\\') *lpFilePartW = 0; + else + { + LPWSTR p = lpBufferW + ret - 1; + while ((p > lpBufferW + 2) && (*p != '\\')) p--; + *lpFilePartW = p + 1; + } + } + if (ret) ret--; + } + } + return ret; +} + +//MAKE_EXPORT GetLongPathNameW_new=GetLongPathNameW +DWORD WINAPI GetLongPathNameW_new(LPCWSTR lpszShortPathW, LPWSTR lpszLongPathW, DWORD cchBuffer) +{ + DWORD ret; + char lpszLongPathA[MAX_PATH]; + file_GetCP(); + file_ALLOC_WtoA(lpszShortPath); + ret = GetLongPathNameA(lpszShortPathA, lpszLongPathA, MAX_PATH); + if (ret) + { + if (ret > MAX_PATH) + { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + return 0; + } + ret = file_AtoW(lpszLongPath, 0); + if (ret <= cchBuffer) + { + ret = file_AtoW(lpszLongPath, cchBuffer); + if (ret) ret--; + } + } + return ret; +} + +//MAKE_EXPORT GetShortPathNameW_new=GetShortPathNameW +DWORD WINAPI GetShortPathNameW_new(LPCWSTR lpszLongPathW, LPWSTR lpszShortPathW, DWORD cchBuffer) +{ + DWORD ret; + char lpszShortPathA[MAX_PATH]; + file_GetCP(); + file_ALLOC_WtoA(lpszLongPath); + ret = GetShortPathNameA(lpszLongPathA, lpszShortPathA, MAX_PATH); + if (ret) + { + if (ret > MAX_PATH) + { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + return 0; + } + ret = file_AtoW(lpszShortPath, 0); + if (ret <= cchBuffer) + { + ret = file_AtoW(lpszShortPath, cchBuffer); + if (ret) ret--; + } + } + return ret; +} + +//MAKE_EXPORT GetStartupInfoW_new=GetStartupInfoW +VOID WINAPI GetStartupInfoW_new(LPSTARTUPINFOW lpStartupInfo) +{ + // since lpDesktop and lpTitle and lpReserved are + // always zero we can just execute ansi version + GetStartupInfoA((LPSTARTUPINFOA)lpStartupInfo); +} + +//MAKE_EXPORT GetSystemDirectoryW_new=GetSystemDirectoryW +UINT WINAPI GetSystemDirectoryW_new(LPWSTR lpBufferW, UINT uSize) +{ + UINT ret; + char lpBufferA[MAX_PATH]; + ret = GetSystemDirectoryA(lpBufferA, MAX_PATH); + if (ret) + { + if (ret > MAX_PATH) + { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + return 0; + } + file_GetCP(); + ret = file_AtoW(lpBuffer, 0); + if (ret <= uSize) + { + ret = file_AtoW(lpBuffer, uSize); + if (ret) ret--; + } + } + return ret; +} + +//MAKE_EXPORT GetTempFileNameW_new=GetTempFileNameW +UINT WINAPI GetTempFileNameW_new(LPCWSTR lpPathNameW, LPCWSTR lpPrefixStringW, UINT uUnique, LPWSTR lpTempFileNameW) +{ + UINT ret; + char lpTempFileNameA[MAX_PATH]; + file_GetCP(); + file_ALLOC_WtoA(lpPathName); + file_ALLOC_WtoA(lpPrefixString); + ret = GetTempFileNameA(lpPathNameA, lpPrefixStringA, uUnique, lpTempFileNameA); + if (ret) + { + file_AtoW(lpTempFileName, MAX_PATH); + } + return ret; +} + +//MAKE_EXPORT GetTempPathW_new=GetTempPathW +DWORD WINAPI GetTempPathW_new(DWORD nBufferLength, LPWSTR lpBufferW) +{ + DWORD ret; + char lpBufferA[MAX_PATH]; + ret = GetTempPathA(MAX_PATH, lpBufferA); + if (ret) + { + if (ret > MAX_PATH) + { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + return 0; + } + file_GetCP(); + ret = file_AtoW(lpBuffer, 0); + if (ret <= nBufferLength) + { + ret = file_AtoW(lpBuffer, nBufferLength); + if (ret) ret--; + } + } + return ret; +} + +//MAKE_EXPORT GetWindowsDirectoryW_new=GetWindowsDirectoryW +UINT WINAPI GetWindowsDirectoryW_new(LPWSTR lpBufferW, UINT uSize) +{ + UINT ret; + char lpBufferA[MAX_PATH]; + ret = GetWindowsDirectoryA(lpBufferA, MAX_PATH); + if (ret) + { + if (ret > MAX_PATH) + { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + return 0; + } + file_GetCP(); + ret = file_AtoW(lpBuffer, 0); + if (ret <= uSize) + { + ret = file_AtoW(lpBuffer, uSize); + if (ret) ret--; + } + } + return ret; +} + +//MAKE_EXPORT GlobalAddAtomW_new=GlobalAddAtomW +ATOM WINAPI GlobalAddAtomW_new(LPCWSTR strW) +{ + ALLOC_WtoA(str); + return GlobalAddAtomA(strA); +} + +//MAKE_EXPORT GlobalFindAtomW_new=GlobalFindAtomW +ATOM WINAPI GlobalFindAtomW_new(LPCWSTR strW) +{ + ALLOC_WtoA(str); + return GlobalFindAtomA(strA); +} + +//MAKE_EXPORT GlobalGetAtomNameW_new=GlobalGetAtomNameW +UINT WINAPI GlobalGetAtomNameW_new(ATOM atom, LPWSTR bufferW, int size) +{ + UINT ret; + ALLOC_A(buffer, size * acp_mcs); + ret = GlobalGetAtomNameA(atom, bufferA, size * acp_mcs); + if (ret) + ret = ABUFtoW(buffer, ret + 1, size); + if (ret) ret--; + return ret; +} + +//MAKE_EXPORT Module32FirstW_new=Module32FirstW +BOOL WINAPI Module32FirstW_new(HANDLE hSnapshot, LPMODULEENTRY32W lpmeW) +{ + BOOL ret; + char szModuleA[MAX_MODULE_NAME32 + 1]; + char szExePathA[MAX_PATH]; + WCHAR* szModuleW = lpmeW->szModule; + WCHAR* szExePathW = lpmeW->szExePath; + + if (lpmeW->dwSize < sizeof(MODULEENTRY32W)) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + lpmeW->dwSize = sizeof(MODULEENTRY32); + + if ((ret = Module32First(hSnapshot, (LPMODULEENTRY32)lpmeW)) != FALSE) + { + strcpy(szModuleA, ((LPMODULEENTRY32)lpmeW)->szModule); + strcpy(szExePathA, ((LPMODULEENTRY32)lpmeW)->szExePath); + AtoW(szModule, sizeof(lpmeW->szModule) / sizeof(WCHAR)); + AtoW(szExePath, sizeof(lpmeW->szExePath) / sizeof(WCHAR)); + } + lpmeW->dwSize = sizeof(MODULEENTRY32W); + return ret; +} + +//MAKE_EXPORT Module32NextW_new=Module32NextW +BOOL WINAPI Module32NextW_new(HANDLE hSnapshot, LPMODULEENTRY32W lpmeW) +{ + BOOL ret; + char szModuleA[MAX_MODULE_NAME32 + 1]; + char szExePathA[MAX_PATH]; + WCHAR* szModuleW = lpmeW->szModule; + WCHAR* szExePathW = lpmeW->szExePath; + + if (lpmeW->dwSize < sizeof(MODULEENTRY32W)) + { + SetLastError(ERROR_INVALID_DATA); + return FALSE; + } + + lpmeW->dwSize = sizeof(MODULEENTRY32); + + if ((ret = Module32Next(hSnapshot, (LPMODULEENTRY32)lpmeW)) != FALSE) + { + strcpy(szModuleA, ((LPMODULEENTRY32)lpmeW)->szModule); + strcpy(szExePathA, ((LPMODULEENTRY32)lpmeW)->szExePath); + AtoW(szModule, sizeof(lpmeW->szModule) / sizeof(WCHAR)); + AtoW(szExePath, sizeof(lpmeW->szExePath) / sizeof(WCHAR)); + } + lpmeW->dwSize = sizeof(MODULEENTRY32W); + return ret; +} + +//MAKE_EXPORT MoveFileExW_new=MoveFileExW +BOOL WINAPI MoveFileExW_new(LPCWSTR existingfileW, LPCWSTR newfileW, DWORD flags) +{ + file_GetCP(); + file_ALLOC_WtoA(existingfile); + file_ALLOC_WtoA(newfile); + return MoveFileExA_new(existingfileA, newfileA, flags); +} + +//MAKE_EXPORT MoveFileW_new=MoveFileW +BOOL WINAPI MoveFileW_new(LPCWSTR existingfileW, LPCWSTR newfileW) +{ + file_GetCP(); + file_ALLOC_WtoA(existingfile); + file_ALLOC_WtoA(newfile); + return MoveFileA(existingfileA, newfileA); +} + +//MAKE_EXPORT MoveFileWithProgressW_new=MoveFileWithProgressW +BOOL WINAPI MoveFileWithProgressW_new(LPCWSTR existingfileW, LPCWSTR newfileW, LPPROGRESS_ROUTINE lpProgressRoutine, LPVOID lpData, DWORD dwFlags) +{ + file_GetCP(); + file_ALLOC_WtoA(existingfile); + file_ALLOC_WtoA(newfile); + return MoveFileWithProgressA_new(existingfileA, newfileA, lpProgressRoutine, lpData, dwFlags); +} + +//MAKE_EXPORT OutputDebugStringW_new=OutputDebugStringW +void WINAPI OutputDebugStringW_new(LPCWSTR strW) +{ + ALLOC_WtoA(str); + OutputDebugStringA(strA); +} + +//MAKE_EXPORT Process32FirstW_new=Process32FirstW +BOOL WINAPI Process32FirstW_new(HANDLE hSnapshot, LPPROCESSENTRY32W lppeW) +{ + BOOL ret; + char szExeFileA[MAX_PATH]; + WCHAR* szExeFileW = lppeW->szExeFile; + + if (lppeW->dwSize < sizeof(PROCESSENTRY32W)) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + lppeW->dwSize = sizeof(PROCESSENTRY32); + + if ((ret = Process32First(hSnapshot, (LPPROCESSENTRY32)lppeW)) != FALSE) + { + strcpy(szExeFileA, ((LPPROCESSENTRY32)lppeW)->szExeFile); + AtoW(szExeFile, sizeof(lppeW->szExeFile) / sizeof(WCHAR)); + } + lppeW->dwSize = sizeof(PROCESSENTRY32W); + return ret; +} + +//MAKE_EXPORT Process32NextW_new=Process32NextW +BOOL WINAPI Process32NextW_new(HANDLE hSnapshot, LPPROCESSENTRY32W lppeW) +{ + BOOL ret; + char szExeFileA[MAX_PATH]; + WCHAR* szExeFileW = lppeW->szExeFile; + + if (lppeW->dwSize < sizeof(PROCESSENTRY32W)) + { + SetLastError(ERROR_INVALID_DATA); + return FALSE; + } + + lppeW->dwSize = sizeof(PROCESSENTRY32); + + if ((ret = Process32Next(hSnapshot, (LPPROCESSENTRY32)lppeW)) != FALSE) + { + strcpy(szExeFileA, ((LPPROCESSENTRY32)lppeW)->szExeFile); + AtoW(szExeFile, sizeof(lppeW->szExeFile) / sizeof(WCHAR)); + } + lppeW->dwSize = sizeof(PROCESSENTRY32W); + return ret; +} + +//MAKE_EXPORT RemoveDirectoryW_new=RemoveDirectoryW +BOOL WINAPI RemoveDirectoryW_new(LPCWSTR lpPathNameW) +{ + file_GetCP(); + file_ALLOC_WtoA(lpPathName); + return RemoveDirectoryA(lpPathNameA); +} + +//MAKE_EXPORT SearchPathW_new=SearchPathW +DWORD WINAPI SearchPathW_new(LPCWSTR lpPathW, LPCWSTR lpFileNameW, LPCWSTR lpExtensionW, DWORD nBufferLength, LPWSTR lpBufferW, LPWSTR *lpFilePartW) +{ + DWORD ret; + char lpBufferA[MAX_PATH]; + file_GetCP(); + file_ALLOC_WtoA(lpPath); + file_ALLOC_WtoA(lpFileName); + file_ALLOC_WtoA(lpExtension); + ret = SearchPathA(lpPathA, lpFileNameA, lpExtensionA, MAX_PATH, lpBufferA, NULL); + if (ret) + { + ret = file_AtoW(lpBuffer, 0); + if (ret <= nBufferLength) + { + ret = file_AtoW(lpBuffer, nBufferLength); + if (lpFilePartW) + { + DWORD i; + for (i = ret ; i >= 0 ; i--) + { + if (lpBufferW[i] == '\\') + { + *lpFilePartW = &lpBufferW[i + 1]; + break; + } + } + } + } + } + return ret; +} + +//MAKE_EXPORT SetConsoleTitleW_new=SetConsoleTitleW +BOOL WINAPI SetConsoleTitleW_new(LPCWSTR strW) +{ + ALLOC_WtoA(str); + return SetConsoleTitleA(strA); +} + +//MAKE_EXPORT SetCurrentDirectoryW_new=SetCurrentDirectoryW +BOOL WINAPI SetCurrentDirectoryW_new(LPCWSTR lpPathNameW) +{ + file_GetCP(); + file_ALLOC_WtoA(lpPathName); + return SetCurrentDirectoryA(lpPathNameA); +} + +//MAKE_EXPORT SetFileAttributesW_new=SetFileAttributesW +BOOL WINAPI SetFileAttributesW_new(LPCWSTR lpFileNameW, DWORD dwFileAttributes) +{ + file_GetCP(); + file_ALLOC_WtoA(lpFileName); + return SetFileAttributesA(lpFileNameA, dwFileAttributes); +} + +//MAKE_EXPORT VerLanguageNameW_new=VerLanguageNameW +DWORD WINAPI VerLanguageNameW_new(DWORD wLang, LPWSTR szLangW, DWORD nSize) +{ + DWORD ret; + DWORD buf_size = VerLanguageNameA(wLang, NULL, 1); //GPF if nSize==0 + + if (!buf_size) return 0; + buf_size++; + + ALLOC_A(szLang, buf_size); + + ret = VerLanguageNameA(wLang, szLangA, buf_size); + if (ret) + { + DWORD last_err = GetLastError(); + ret = AtoW(szLang, nSize); + if (!ret) + { + szLangW[nSize - 1] = 0; + ret = AtoW(szLang, 0); + } + if (ret) ret--; + SetLastError(last_err); + } + return ret; +} + +//MAKE_EXPORT lstrcpynW_new=lstrcpynW +LPWSTR WINAPI lstrcpynW_new(LPWSTR dst, LPCWSTR src, INT n) +{ + LPWSTR ret = dst; + + if (IsBadReadPtr(src, n) || IsBadWritePtr(dst, n)) + { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + while ((n > 1) && *src) + { + *dst++ = *src++; + n--; + } + *dst = 0; + return ret; +} diff --git a/apilibs/kexbases/Kernel32/version.c b/apilibs/kexbases/Kernel32/version.c new file mode 100644 index 0000000..312a138 --- /dev/null +++ b/apilibs/kexbases/Kernel32/version.c @@ -0,0 +1,584 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include +#include "auxdecl.h" + +/* special structure used internally to save some space */ +typedef struct +{ + DWORD dwMajorVersion; + DWORD dwMinorVersion; + DWORD dwBuildNumber; + DWORD dwPlatformId; + CHAR* lpszCSDVersion; + WORD wServicePackMajor; + WORD wServicePackMinor; + WORD wSuiteMask; + BYTE wProductType; + BYTE wReserved; +} OSVERSIONINFOEXA_PRIV; + +typedef enum +{ + WIN95, /* Windows 95 */ + WIN98, /* Windows 98 */ + WINME, /* Windows Me */ + NT40, /* Windows NT 4.0 */ + NT2K, /* Windows 2000 */ + WINXP, /* Windows XP */ + WIN2K3, /* Windows 2003 */ + VISTA, /* Windows Vista */ + WIN2K8, /* Windows 2008 */ + NB_WINDOWS_VERSIONS +} WINDOWS_VERSION; + +static const OSVERSIONINFOEXA_PRIV VersionData[NB_WINDOWS_VERSIONS] = +{ + /* WIN95 */ + { + 4, 0, 0x40003B6, VER_PLATFORM_WIN32_WINDOWS, + "", + 0, 0, 0, 0, 0 + }, + /* WIN98 (second edition) */ + { + 4, 10, 0x40A08AE, VER_PLATFORM_WIN32_WINDOWS, + " A ", + 0, 0, 0, 0, 0 + }, + /* WINME */ + { + 4, 90, 0x45A0BB8, VER_PLATFORM_WIN32_WINDOWS, + " ", + 0, 0, 0, 0, 0 + }, + /* NT40 */ + { + 4, 0, 0x565, VER_PLATFORM_WIN32_NT, + "Service Pack 6a", + 6, 0, 0, VER_NT_WORKSTATION, 0 + }, + /* NT2K */ + { + 5, 0, 0x893, VER_PLATFORM_WIN32_NT, + "Service Pack 4", + 4, 0, 0, VER_NT_WORKSTATION, 30 + }, + /* WINXP */ + { + 5, 1, 0xA28, VER_PLATFORM_WIN32_NT, + "Service Pack 2", + 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 30 + }, + /* WIN2K3 */ + { + 5, 2, 0xECE, VER_PLATFORM_WIN32_NT, + "Service Pack 1", + 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0 + }, + /* WINVISTA */ + { + 6, 0, 0x1770, VER_PLATFORM_WIN32_NT, + " ", + 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0 + }, + /* WIN2K8 */ + { + 6, 0, 0x1771, VER_PLATFORM_WIN32_NT, + "Service Pack 1", + 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0 + } +}; + +static DWORD common_GetVersion(WINDOWS_VERSION version) +{ + const OSVERSIONINFOEXA_PRIV* osv = &VersionData[version]; + DWORD result; + + result = MAKELONG(MAKEWORD(osv->dwMajorVersion, osv->dwMinorVersion), + (osv->dwPlatformId ^ 2) << 14); + if (osv->dwPlatformId == VER_PLATFORM_WIN32_NT) + result |= LOWORD(osv->dwBuildNumber) << 16; + return result; +} + +static BOOL common_GetVersionEx(WINDOWS_VERSION version, void* buf, BOOL unicode) +{ + const OSVERSIONINFOEXA_PRIV* osv = &VersionData[version]; + + if (!unicode) + { + OSVERSIONINFOEXA* osa = (OSVERSIONINFOEXA*) buf; + if (osa->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA) + && osa->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXA)) + { + SetLastError(ERROR_INSUFFICIENT_BUFFER); + return FALSE; + } + osa->dwMajorVersion = osv->dwMajorVersion; + osa->dwMinorVersion = osv->dwMinorVersion; + osa->dwBuildNumber = osv->dwBuildNumber; + osa->dwPlatformId = osv->dwPlatformId; + strcpy(osa->szCSDVersion, osv->lpszCSDVersion); + if (osa->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA)) + { + osa->wServicePackMajor = osv->wServicePackMajor; + osa->wServicePackMinor = osv->wServicePackMinor; + osa->wSuiteMask = osv->wSuiteMask; + osa->wProductType = osv->wProductType; + osa->wReserved = osv->wReserved; + } + } + else //if (unicode) + { + OSVERSIONINFOEXW* osw = (OSVERSIONINFOEXW*) buf; + if (osw->dwOSVersionInfoSize != sizeof(OSVERSIONINFOW) + && osw->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW)) + { + SetLastError(ERROR_INSUFFICIENT_BUFFER); + return FALSE; + } + osw->dwMajorVersion = osv->dwMajorVersion; + osw->dwMinorVersion = osv->dwMinorVersion; + osw->dwBuildNumber = osv->dwBuildNumber; + osw->dwPlatformId = osv->dwPlatformId; + MultiByteToWideChar(CP_ACP, 0, osv->lpszCSDVersion, -1, + osw->szCSDVersion, sizeof(osw->szCSDVersion) / sizeof(WCHAR)); + if (osw->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW)) + { + osw->wServicePackMajor = osv->wServicePackMajor; + osw->wServicePackMinor = osv->wServicePackMinor; + osw->wSuiteMask = osv->wSuiteMask; + osw->wProductType = osv->wProductType; + osw->wReserved = osv->wReserved; + } + } + return TRUE; +} + +static DWORD version_compare_values(ULONG left, ULONG right, UCHAR condition) +{ + switch (condition) { + case VER_EQUAL: + if (left != right) return ERROR_OLD_WIN_VERSION; + break; + case VER_GREATER: + if (left <= right) return ERROR_OLD_WIN_VERSION; + break; + case VER_GREATER_EQUAL: + if (left < right) return ERROR_OLD_WIN_VERSION; + break; + case VER_LESS: + if (left >= right) return ERROR_OLD_WIN_VERSION; + break; + case VER_LESS_EQUAL: + if (left > right) return ERROR_OLD_WIN_VERSION; + break; + default: + return ERROR_OLD_WIN_VERSION; + } + return ERROR_SUCCESS; +} + +static DWORD common_VerifyVersionInfo(WINDOWS_VERSION version, + const OSVERSIONINFOEXA* info, DWORD dwTypeMask, DWORDLONG dwlConditionMask) +{ + const OSVERSIONINFOEXA_PRIV* osv = &VersionData[version]; + DWORD status; + + if (!(dwTypeMask && dwlConditionMask)) return ERROR_BAD_ARGUMENTS; + + if (dwTypeMask & VER_PRODUCT_TYPE) + { + status = version_compare_values(osv->wProductType, info->wProductType, (UCHAR)(dwlConditionMask >> 7*3 & 0x07)); + if (status != ERROR_SUCCESS) + return status; + } + if (dwTypeMask & VER_SUITENAME) + switch(dwlConditionMask >> 6*3 & 0x07) + { + case VER_AND: + if ((info->wSuiteMask & osv->wSuiteMask) != info->wSuiteMask) + return ERROR_OLD_WIN_VERSION; + break; + case VER_OR: + if (!(info->wSuiteMask & osv->wSuiteMask) && info->wSuiteMask) + return ERROR_OLD_WIN_VERSION; + break; + default: + return ERROR_BAD_ARGUMENTS; + } + if (dwTypeMask & VER_PLATFORMID) + { + status = version_compare_values(osv->dwPlatformId, info->dwPlatformId, (UCHAR)(dwlConditionMask >> 3*3 & 0x07)); + if (status != ERROR_SUCCESS) + return status; + } + if (dwTypeMask & VER_BUILDNUMBER) + { + status = version_compare_values(osv->dwBuildNumber, info->dwBuildNumber, (UCHAR)(dwlConditionMask >> 2*3 & 0x07)); + if (status != ERROR_SUCCESS) + return status; + } + + if (dwTypeMask & (VER_MAJORVERSION|VER_MINORVERSION|VER_SERVICEPACKMAJOR|VER_SERVICEPACKMINOR)) + { + UCHAR condition = 0; + BOOL do_next_check = TRUE; + + if (dwTypeMask & VER_MAJORVERSION) + condition = (UCHAR)(dwlConditionMask >> 1*3 & 0x07); + else if (dwTypeMask & VER_MINORVERSION) + condition = (UCHAR)(dwlConditionMask >> 0*3 & 0x07); + else if (dwTypeMask & VER_SERVICEPACKMAJOR) + condition = (UCHAR)(dwlConditionMask >> 5*3 & 0x07); + else if (dwTypeMask & VER_SERVICEPACKMINOR) + condition = (UCHAR)(dwlConditionMask >> 4*3 & 0x07); + + if (dwTypeMask & VER_MAJORVERSION) + { + status = version_compare_values(osv->dwMajorVersion, info->dwMajorVersion, condition); + do_next_check = (osv->dwMajorVersion == info->dwMajorVersion) && + ((condition != VER_EQUAL) || (status == ERROR_SUCCESS)); + } + if ((dwTypeMask & VER_MINORVERSION) && do_next_check) + { + status = version_compare_values(osv->dwMinorVersion, info->dwMinorVersion, condition); + do_next_check = (osv->dwMinorVersion == info->dwMinorVersion) && + ((condition != VER_EQUAL) || (status == ERROR_SUCCESS)); + } + if ((dwTypeMask & VER_SERVICEPACKMAJOR) && do_next_check) + { + status = version_compare_values(osv->wServicePackMajor, info->wServicePackMajor, condition); + do_next_check = (osv->wServicePackMajor == info->wServicePackMajor) && + ((condition != VER_EQUAL) || (status == ERROR_SUCCESS)); + } + if ((dwTypeMask & VER_SERVICEPACKMINOR) && do_next_check) + { + status = version_compare_values(osv->wServicePackMinor, info->wServicePackMinor, condition); + } + + if (status != ERROR_SUCCESS) + return status; + } + + return ERROR_SUCCESS; +} + +static BOOL WINAPI common_VerifyVersionInfoA(WINDOWS_VERSION version, + LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask, + DWORDLONG dwlConditionMask) +{ + DWORD ret = common_VerifyVersionInfo(version, lpVersionInfo, dwTypeMask, dwlConditionMask); + if (ret) + { + SetLastError(ret); + return FALSE; + } + return TRUE; +} + +static BOOL WINAPI common_VerifyVersionInfoW(WINDOWS_VERSION version, + LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask, + DWORDLONG dwlConditionMask) +{ + DWORD ret; + OSVERSIONINFOEXA VersionInfoA; + VersionInfoA.dwMajorVersion = lpVersionInfo->dwMajorVersion; + VersionInfoA.dwMinorVersion = lpVersionInfo->dwMinorVersion; + VersionInfoA.dwBuildNumber = lpVersionInfo->dwBuildNumber; + VersionInfoA.dwPlatformId = lpVersionInfo->dwPlatformId; + VersionInfoA.wServicePackMajor = lpVersionInfo->wServicePackMajor; + VersionInfoA.wServicePackMinor = lpVersionInfo->wServicePackMinor; + VersionInfoA.wSuiteMask = lpVersionInfo->wSuiteMask; + VersionInfoA.wProductType = lpVersionInfo->wProductType; + + ret = common_VerifyVersionInfo(version, &VersionInfoA, dwTypeMask, dwlConditionMask); + if (ret) + { + SetLastError(ret); + return FALSE; + } + return TRUE; +} + +/* MAKE_EXPORT VerSetConditionMask_new=VerSetConditionMask */ +ULONGLONG WINAPI VerSetConditionMask_new(ULONGLONG dwlConditionMask, + DWORD dwTypeBitMask, BYTE dwConditionMask) +{ + if (dwTypeBitMask == 0) + return dwlConditionMask; + dwConditionMask &= 0x07; + if (dwConditionMask == 0) + return dwlConditionMask; + + if (dwTypeBitMask & VER_PRODUCT_TYPE) + dwlConditionMask |= dwConditionMask << 7*3; + else if (dwTypeBitMask & VER_SUITENAME) + dwlConditionMask |= dwConditionMask << 6*3; + else if (dwTypeBitMask & VER_SERVICEPACKMAJOR) + dwlConditionMask |= dwConditionMask << 5*3; + else if (dwTypeBitMask & VER_SERVICEPACKMINOR) + dwlConditionMask |= dwConditionMask << 4*3; + else if (dwTypeBitMask & VER_PLATFORMID) + dwlConditionMask |= dwConditionMask << 3*3; + else if (dwTypeBitMask & VER_BUILDNUMBER) + dwlConditionMask |= dwConditionMask << 2*3; + else if (dwTypeBitMask & VER_MAJORVERSION) + dwlConditionMask |= dwConditionMask << 1*3; + else if (dwTypeBitMask & VER_MINORVERSION) + dwlConditionMask |= dwConditionMask << 0*3; + return dwlConditionMask; +} + +/* MAKE_EXPORT GetVersion_WIN95=GetVersion */ +DWORD WINAPI GetVersion_WIN95(void) +{ + return common_GetVersion(WIN95); +} + +/* MAKE_EXPORT GetVersion_WIN98=GetVersion */ +DWORD WINAPI GetVersion_WIN98(void) +{ + return common_GetVersion(WIN98); +} + +/* MAKE_EXPORT GetVersion_WINME=GetVersion */ +DWORD WINAPI GetVersion_WINME(void) +{ + return common_GetVersion(WINME); +} + +/* MAKE_EXPORT GetVersion_NT40=GetVersion */ +DWORD WINAPI GetVersion_NT40(void) +{ + return common_GetVersion(NT40); +} + +/* MAKE_EXPORT GetVersion_NT2K=GetVersion */ +DWORD WINAPI GetVersion_NT2K(void) +{ + return common_GetVersion(NT2K); +} + +/* MAKE_EXPORT GetVersion_WINXP=GetVersion */ +DWORD WINAPI GetVersion_WINXP(void) +{ + return common_GetVersion(WINXP); +} + +/* MAKE_EXPORT GetVersion_WIN2K3=GetVersion */ +DWORD WINAPI GetVersion_WIN2K3(void) +{ + return common_GetVersion(WIN2K3); +} + +/* MAKE_EXPORT GetVersion_VISTA=GetVersion */ +DWORD WINAPI GetVersion_VISTA(void) +{ + return common_GetVersion(VISTA); +} + +/* MAKE_EXPORT GetVersion_WIN2K8=GetVersion */ +DWORD WINAPI GetVersion_WIN2K8(void) +{ + return common_GetVersion(WIN2K8); +} + +/* MAKE_EXPORT GetVersionExA_WIN95=GetVersionExA */ +BOOL WINAPI GetVersionExA_WIN95(LPOSVERSIONINFOA lpVersionInfo) +{ + return common_GetVersionEx(WIN95, lpVersionInfo, FALSE); +} + +/* MAKE_EXPORT GetVersionExW_WIN95=GetVersionExW */ +BOOL WINAPI GetVersionExW_WIN95(LPOSVERSIONINFOW lpVersionInfo) +{ + return common_GetVersionEx(WIN95, lpVersionInfo, TRUE); +} + +/* MAKE_EXPORT GetVersionExA_WIN98=GetVersionExA */ +BOOL WINAPI GetVersionExA_WIN98(LPOSVERSIONINFOA lpVersionInfo) +{ + return common_GetVersionEx(WIN98, lpVersionInfo, FALSE); +} + +/* MAKE_EXPORT GetVersionExW_WIN98=GetVersionExW */ +BOOL WINAPI GetVersionExW_WIN98(LPOSVERSIONINFOW lpVersionInfo) +{ + return common_GetVersionEx(WIN98, lpVersionInfo, TRUE); +} + +/* MAKE_EXPORT GetVersionExA_WINME=GetVersionExA */ +BOOL WINAPI GetVersionExA_WINME(LPOSVERSIONINFOA lpVersionInfo) +{ + return common_GetVersionEx(WINME, lpVersionInfo, FALSE); +} + +/* MAKE_EXPORT GetVersionExW_WINME=GetVersionExW */ +BOOL WINAPI GetVersionExW_WINME(LPOSVERSIONINFOW lpVersionInfo) +{ + return common_GetVersionEx(WINME, lpVersionInfo, TRUE); +} + +/* MAKE_EXPORT GetVersionExA_NT40=GetVersionExA */ +BOOL WINAPI GetVersionExA_NT40(LPOSVERSIONINFOA lpVersionInfo) +{ + return common_GetVersionEx(NT40, lpVersionInfo, FALSE); +} + +/* MAKE_EXPORT GetVersionExW_NT40=GetVersionExW */ +BOOL WINAPI GetVersionExW_NT40(LPOSVERSIONINFOW lpVersionInfo) +{ + return common_GetVersionEx(NT40, lpVersionInfo, TRUE); +} + +/* MAKE_EXPORT GetVersionExA_NT2K=GetVersionExA */ +BOOL WINAPI GetVersionExA_NT2K(LPOSVERSIONINFOA lpVersionInfo) +{ + return common_GetVersionEx(NT2K, lpVersionInfo, FALSE); +} + +/* MAKE_EXPORT GetVersionExW_NT2K=GetVersionExW */ +BOOL WINAPI GetVersionExW_NT2K(LPOSVERSIONINFOW lpVersionInfo) +{ + return common_GetVersionEx(NT2K, lpVersionInfo, TRUE); +} + +/* MAKE_EXPORT GetVersionExA_WINXP=GetVersionExA */ +BOOL WINAPI GetVersionExA_WINXP(LPOSVERSIONINFOA lpVersionInfo) +{ + return common_GetVersionEx(WINXP, lpVersionInfo, FALSE); +} + +/* MAKE_EXPORT GetVersionExW_WINXP=GetVersionExW */ +BOOL WINAPI GetVersionExW_WINXP(LPOSVERSIONINFOW lpVersionInfo) +{ + return common_GetVersionEx(WINXP, lpVersionInfo, TRUE); +} + +/* MAKE_EXPORT GetVersionExA_WIN2K3=GetVersionExA */ +BOOL WINAPI GetVersionExA_WIN2K3(LPOSVERSIONINFOA lpVersionInfo) +{ + return common_GetVersionEx(WIN2K3, lpVersionInfo, FALSE); +} + +/* MAKE_EXPORT GetVersionExW_WIN2K3=GetVersionExW */ +BOOL WINAPI GetVersionExW_WIN2K3(LPOSVERSIONINFOW lpVersionInfo) +{ + return common_GetVersionEx(WIN2K3, lpVersionInfo, TRUE); +} + +/* MAKE_EXPORT GetVersionExA_VISTA=GetVersionExA */ +BOOL WINAPI GetVersionExA_VISTA(LPOSVERSIONINFOA lpVersionInfo) +{ + return common_GetVersionEx(VISTA, lpVersionInfo, FALSE); +} + +/* MAKE_EXPORT GetVersionExW_VISTA=GetVersionExW */ +BOOL WINAPI GetVersionExW_VISTA(LPOSVERSIONINFOW lpVersionInfo) +{ + return common_GetVersionEx(VISTA, lpVersionInfo, TRUE); +} + +/* MAKE_EXPORT GetVersionExA_WIN2K8=GetVersionExA */ +BOOL WINAPI GetVersionExA_WIN2K8(LPOSVERSIONINFOA lpVersionInfo) +{ + return common_GetVersionEx(WIN2K8, lpVersionInfo, FALSE); +} + +/* MAKE_EXPORT GetVersionExW_WIN2K8=GetVersionExW */ +BOOL WINAPI GetVersionExW_WIN2K8(LPOSVERSIONINFOW lpVersionInfo) +{ + return common_GetVersionEx(WIN2K8, lpVersionInfo, TRUE); +} + +/* MAKE_EXPORT VerifyVersionInfoA_NT2K=VerifyVersionInfoA */ +BOOL WINAPI VerifyVersionInfoA_NT2K(LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask, + DWORDLONG dwlConditionMask) +{ + return common_VerifyVersionInfoA(NT2K, lpVersionInfo, dwTypeMask, dwlConditionMask); +} + +/* MAKE_EXPORT VerifyVersionInfoW_NT2K=VerifyVersionInfoW */ +BOOL WINAPI VerifyVersionInfoW_NT2K(LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask, + DWORDLONG dwlConditionMask) +{ + return common_VerifyVersionInfoW(NT2K, lpVersionInfo, dwTypeMask, dwlConditionMask); +} + +/* MAKE_EXPORT VerifyVersionInfoA_WINXP=VerifyVersionInfoA */ +BOOL WINAPI VerifyVersionInfoA_WINXP(LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask, + DWORDLONG dwlConditionMask) +{ + return common_VerifyVersionInfoA(WINXP, lpVersionInfo, dwTypeMask, dwlConditionMask); +} + +/* MAKE_EXPORT VerifyVersionInfoW_WINXP=VerifyVersionInfoW */ +BOOL WINAPI VerifyVersionInfoW_WINXP(LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask, + DWORDLONG dwlConditionMask) +{ + return common_VerifyVersionInfoW(WINXP, lpVersionInfo, dwTypeMask, dwlConditionMask); +} + +/* MAKE_EXPORT VerifyVersionInfoA_WIN2K3=VerifyVersionInfoA */ +BOOL WINAPI VerifyVersionInfoA_WIN2K3(LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask, + DWORDLONG dwlConditionMask) +{ + return common_VerifyVersionInfoA(WIN2K3, lpVersionInfo, dwTypeMask, dwlConditionMask); +} + +/* MAKE_EXPORT VerifyVersionInfoW_WIN2K3=VerifyVersionInfoW */ +BOOL WINAPI VerifyVersionInfoW_WIN2K3(LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask, + DWORDLONG dwlConditionMask) +{ + return common_VerifyVersionInfoW(WIN2K3, lpVersionInfo, dwTypeMask, dwlConditionMask); +} + +/* MAKE_EXPORT VerifyVersionInfoA_VISTA=VerifyVersionInfoA */ +BOOL WINAPI VerifyVersionInfoA_VISTA(LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask, + DWORDLONG dwlConditionMask) +{ + return common_VerifyVersionInfoA(VISTA, lpVersionInfo, dwTypeMask, dwlConditionMask); +} + +/* MAKE_EXPORT VerifyVersionInfoW_VISTA=VerifyVersionInfoW */ +BOOL WINAPI VerifyVersionInfoW_VISTA(LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask, + DWORDLONG dwlConditionMask) +{ + return common_VerifyVersionInfoW(VISTA, lpVersionInfo, dwTypeMask, dwlConditionMask); +} + +/* MAKE_EXPORT VerifyVersionInfoA_WIN2K8=VerifyVersionInfoA */ +BOOL WINAPI VerifyVersionInfoA_WIN2K8(LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask, + DWORDLONG dwlConditionMask) +{ + return common_VerifyVersionInfoA(WIN2K8, lpVersionInfo, dwTypeMask, dwlConditionMask); +} + +/* MAKE_EXPORT VerifyVersionInfoW_WIN2K8=VerifyVersionInfoW */ +BOOL WINAPI VerifyVersionInfoW_WIN2K8(LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask, + DWORDLONG dwlConditionMask) +{ + return common_VerifyVersionInfoW(WIN2K8, lpVersionInfo, dwTypeMask, dwlConditionMask); +} + diff --git a/apilibs/kexbases/User32/CallWindowProcA_fix.c b/apilibs/kexbases/User32/CallWindowProcA_fix.c new file mode 100644 index 0000000..e22e230 --- /dev/null +++ b/apilibs/kexbases/User32/CallWindowProcA_fix.c @@ -0,0 +1,50 @@ +/* + * KernelEx + * Copyright (C) 2008, Xeno86 + * Copyright (C) 2008, Tihiy + * + * 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. + * + */ + +#include + +__declspec(naked) +/* MAKE_EXPORT CallWindowProcA_fix=CallWindowProcA */ +LRESULT WINAPI CallWindowProcA_fix(WNDPROC lpPrevWndFunc, HWND hWnd, + UINT Msg, WPARAM wParam, LPARAM lParam) +{ + static const char unicows_str[] = "unicows.dll"; + static const char callwindowproca_str[] = "CallWindowProcA"; + + /* We shouldn't write it in C because some weird programs depend + * on CallWindowProc calling function directly! + */ +__asm { + mov eax, [esp+4] ;lpPrevWndFunc + and eax, 0x7FFFFFF0 + cmp eax, 0x7FFFFFF0 + je UNI + jmp dword ptr [CallWindowProcA] +UNI: + push offset unicows_str + call dword ptr [GetModuleHandleA] + push offset callwindowproca_str + push eax + call dword ptr [GetProcAddress] + jmp eax + } +} diff --git a/apilibs/kexbases/User32/DisableProcessWindowsGhosting.c b/apilibs/kexbases/User32/DisableProcessWindowsGhosting.c new file mode 100644 index 0000000..40b252b --- /dev/null +++ b/apilibs/kexbases/User32/DisableProcessWindowsGhosting.c @@ -0,0 +1,25 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +/* MAKE_EXPORT DisableProcessWindowsGhosting_new=DisableProcessWindowsGhosting */ +void __stdcall DisableProcessWindowsGhosting_new(void) +{ +} diff --git a/apilibs/kexbases/User32/EnableWindow.c b/apilibs/kexbases/User32/EnableWindow.c new file mode 100644 index 0000000..8c03a5f --- /dev/null +++ b/apilibs/kexbases/User32/EnableWindow.c @@ -0,0 +1,36 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include + +/* + * Win9x seems to look at only the low 16 bits of bEnable. + * This causes a problem, for example, if the caller passes + * a count of items with the intent to enable a window when + * the count is >0. That will fail when the count is + * a multiple of 64K + */ + +/* MAKE_EXPORT EnableWindow_new=EnableWindow */ +BOOL WINAPI EnableWindow_new(HWND hWnd, BOOL bEnable) +{ + return EnableWindow(hWnd, bEnable ? TRUE : FALSE); +} diff --git a/apilibs/kexbases/User32/ForegroundWindow.c b/apilibs/kexbases/User32/ForegroundWindow.c new file mode 100644 index 0000000..776662d --- /dev/null +++ b/apilibs/kexbases/User32/ForegroundWindow.c @@ -0,0 +1,34 @@ +/* + * 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. + * + */ + +#include + +/* MAKE_EXPORT AllowSetForegroundWindow_98=AllowSetForegroundWindow */ +BOOL WINAPI AllowSetForegroundWindow_98(DWORD procid) +{ + return TRUE; +} + +/* MAKE_EXPORT LockSetForegroundWindow_98=LockSetForegroundWindow */ +BOOL WINAPI LockSetForegroundWindow_98(UINT lockcode) +{ + return TRUE; +} diff --git a/apilibs/kexbases/User32/GetAncestor.c b/apilibs/kexbases/User32/GetAncestor.c new file mode 100644 index 0000000..8041e52 --- /dev/null +++ b/apilibs/kexbases/User32/GetAncestor.c @@ -0,0 +1,35 @@ +/* + * KernelEx + * Copyright (C) 2008, Xeno86 + * Copyright (C) 1998-2001 Avery Lee + * + * 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. + * + */ + +#include +#include "auxdecl.h" + +//MAKE_EXPORT GetAncestor_fix=GetAncestor +HWND APIENTRY GetAncestor_fix(HWND hwnd, UINT gaFlags) +{ + // Believe it or not, HWND_MESSAGE works under Windows 98 -- and if you call GetAncestor() + // on such a window, user32 crashes in 16-bit code. :( + if (gaFlags == GA_ROOT && GetParent(hwnd) == NULL) + return hwnd; + + return GetAncestor(hwnd, gaFlags); +} diff --git a/apilibs/kexbases/User32/GetMouseMovePointsEx.c b/apilibs/kexbases/User32/GetMouseMovePointsEx.c new file mode 100644 index 0000000..278eb15 --- /dev/null +++ b/apilibs/kexbases/User32/GetMouseMovePointsEx.c @@ -0,0 +1,31 @@ +/* + * 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. + * + */ + +#include "common.h" +#include "_user32_apilist.h" + +GetMouseMovePoints_t GetMouseMovePoints_pfn; + +/* MAKE_EXPORT GetMouseMovePointsEx_98=GetMouseMovePointsEx */ +int WINAPI GetMouseMovePointsEx_98(UINT size, LPMOUSEMOVEPOINT ptin, LPMOUSEMOVEPOINT ptout, int count, DWORD res) +{ + return GetMouseMovePoints_pfn(size, ptin, ptout, count, res); +} diff --git a/apilibs/kexbases/User32/IsHungAppWindow.c b/apilibs/kexbases/User32/IsHungAppWindow.c new file mode 100644 index 0000000..6b37a8f --- /dev/null +++ b/apilibs/kexbases/User32/IsHungAppWindow.c @@ -0,0 +1,29 @@ +/* + * KernelEx + * Copyright (C) 2008, Tihiy + * 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. + * + */ + +#include +#include "common.h" +#include "_user32_apilist.h" + +/* MAKE_EXPORT IsHungAppWindow_new=IsHungAppWindow */ +BOOL WINAPI IsHungAppWindow_new(HWND hWnd) +{ + return IsHungThread_pfn(GetWindowThreadProcessId(hWnd, NULL)); +} diff --git a/apilibs/kexbases/User32/LockWorkStation.c b/apilibs/kexbases/User32/LockWorkStation.c new file mode 100644 index 0000000..fb14d94 --- /dev/null +++ b/apilibs/kexbases/User32/LockWorkStation.c @@ -0,0 +1,28 @@ +/* + * KernelEx + * Copyright (C) 2008, Tihiy + * 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. + * + */ + +#include + +/* MAKE_EXPORT LockWorkStation_new=LockWorkStation */ +BOOL WINAPI LockWorkStation_new(void) +{ + //FIXME: rundll32 likes to call it and crashes because stack would be incorrect + return WinExec("conlock.mod -uSeR",SW_SHOWDEFAULT) > 31 ? TRUE : FALSE; +} diff --git a/apilibs/kexbases/User32/MapVirtualKey_fix.c b/apilibs/kexbases/User32/MapVirtualKey_fix.c new file mode 100644 index 0000000..69e34a5 --- /dev/null +++ b/apilibs/kexbases/User32/MapVirtualKey_fix.c @@ -0,0 +1,49 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include + +/* MapVirtualKey translation types */ +#define MAPVK_VK_TO_VSC 0 +#define MAPVK_VSC_TO_VK 1 +#define MAPVK_VK_TO_CHAR 2 +#define MAPVK_VSC_TO_VK_EX 3 +#define MAPVK_VK_TO_VSC_EX 4 + +/* MAKE_EXPORT MapVirtualKeyA_new=MapVirtualKeyA */ +UINT WINAPI MapVirtualKeyA_new(UINT uCode, UINT uMapType) +{ + if (uMapType == MAPVK_VK_TO_VSC_EX) + uMapType = MAPVK_VK_TO_VSC; + else if (uMapType == MAPVK_VSC_TO_VK_EX) + uMapType = MAPVK_VSC_TO_VK; + return MapVirtualKeyA(uCode, uMapType); +} + +/* MAKE_EXPORT MapVirtualKeyExA_new=MapVirtualKeyExA */ +UINT WINAPI MapVirtualKeyExA_new(UINT uCode, UINT uMapType, HKL dwhkl) +{ + if (uMapType == MAPVK_VK_TO_VSC_EX) + uMapType = MAPVK_VK_TO_VSC; + else if (uMapType == MAPVK_VSC_TO_VK_EX) + uMapType = MAPVK_VSC_TO_VK; + return MapVirtualKeyExA(uCode, uMapType, dwhkl); +} diff --git a/apilibs/kexbases/User32/SendMessage_fix.c b/apilibs/kexbases/User32/SendMessage_fix.c new file mode 100644 index 0000000..9072c53 --- /dev/null +++ b/apilibs/kexbases/User32/SendMessage_fix.c @@ -0,0 +1,85 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include + +/* MAKE_EXPORT SendMessageA_fix=SendMessageA */ +__declspec(naked) +LRESULT WINAPI SendMessageA_fix(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) +{ +__asm { + mov eax, [esp+8] ;Msg + cmp eax, 402 ;LB_SETTABSTOPS + jz fix_settabstops + cmp eax, 203 ;EM_SETTABSTOPS + jz fix_settabstops +orig_func: + jmp dword ptr [SendMessageA] +fix_settabstops: + mov eax, [esp+12] ;wParam + cmp eax, 0 + jbe orig_func ;sanity check: wParam > 0 ? + shl eax, 2 ;wParam * sizeof(DWORD) + push eax ;HeapAlloc.dwBytes + push eax ;cb + push dword ptr [esp+16+8] + call dword ptr [IsBadReadPtr] ;sanity check: ok to read ? + test eax, eax + jz L2 + add esp, 4 ;can't read => return failure + xor eax, eax + ret 16 +L2: + push 0 + call dword ptr [GetProcessHeap] + push eax + call dword ptr [HeapAlloc] + test eax, eax + jnz L3 ;alloc successful? + ret 16 +L3: + mov ecx, [esp+12] + push esi + push edi + mov esi, [esp+16+8] + mov edi, eax + cld + rep movsd + pop edi + pop esi + push ebx + mov ebx, eax ;alloc'd mem ptr + push eax + push dword ptr [esp+12+8] + push dword ptr [esp+8+12] + push dword ptr [esp+4+16] + call dword ptr [SendMessageA] + push eax ;remember result + push ebx + push 0 + call dword ptr [GetProcessHeap] + push eax + call dword ptr [HeapFree] + pop eax ;remembered result + pop ebx + ret 16 + } +} diff --git a/apilibs/kexbases/User32/UberUSER.c b/apilibs/kexbases/User32/UberUSER.c new file mode 100644 index 0000000..9f99e9c --- /dev/null +++ b/apilibs/kexbases/User32/UberUSER.c @@ -0,0 +1,134 @@ +/* + * KernelEx + * + * Copyright 1993 Alexandre Julliard + * 1997 Alex Korobka + * Copyright 2002,2003 Shachar Shemesh + * Copyright 2003 CodeWeavers Inc. (Ulrich Czekalla) + * + * Copyright (C) 2008, Tihiy + * 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. + * + */ + +#include + +static const char c_szUnicows[]="unicows.dll"; +static const char c_szUnicowsProp[]="GodotMemoryBlock"; + +static int WINAPI GetCPFromLocale(LCID Locale) +{ + int cp; + Locale = Locale & 0xFFFF; //we can assume that HKL == LCID in 9x... i hope :) + if (GetLocaleInfoA(Locale,LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,(LPSTR)&cp,sizeof(int))) + return cp; + else + return CP_ACP; +} + +/* MAKE_EXPORT ToUnicodeEx_new=ToUnicodeEx */ +int WINAPI ToUnicodeEx_new( + UINT wVirtKey, + UINT wScanCode, + const PBYTE lpKeyState, + LPWSTR pwszBuff, + int cchBuff, + UINT wFlags, + HKL dwhkl +) +{ + int result; + WORD asciibuf[4]; + char ansibuf[4]; + if (!lpKeyState || !pwszBuff) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + result = ToAsciiEx(wVirtKey,wScanCode,lpKeyState,asciibuf,wFlags,dwhkl); + if (result && cchBuff) + { + int i; + for (i = 0; i < result; i++) ansibuf[i]=(char)asciibuf[i]; + MultiByteToWideChar(GetCPFromLocale((LCID)dwhkl),0,ansibuf,result,pwszBuff,cchBuff); + } + return result; +} + +/* MAKE_EXPORT ToUnicode_new=ToUnicode */ +int WINAPI ToUnicode_new( + UINT wVirtKey, + UINT wScanCode, + const PBYTE lpKeyState, + LPWSTR pwszBuff, + int cchBuff, + UINT wFlags +) +{ + return ToUnicodeEx_new(wVirtKey,wScanCode,lpKeyState,pwszBuff,cchBuff,wFlags,GetKeyboardLayout(GetCurrentThreadId())); +} + +/* MAKE_EXPORT GetLastInputInfo_new=GetLastInputInfo */ +BOOL WINAPI GetLastInputInfo_new( + PLASTINPUTINFO plii // last input event +) +{ + if ( !plii ) return FALSE; + plii->dwTime = GetTickCount() - 123; + return TRUE; +} + +/* MAKE_EXPORT GetMessageW_new=GetMessageW */ +BOOL WINAPI GetMessageW_new( + LPMSG lpMsg, // message information + HWND hWnd, // handle to window + UINT wMsgFilterMin, // first message + UINT wMsgFilterMax // last message +) +{ + BOOL result; + /* HACKHACK ALERT: don't bother calling MSLU. We know how it works already. Win speed instead! */ + result = GetMessageA(lpMsg,hWnd,wMsgFilterMin,wMsgFilterMax); + if (lpMsg && lpMsg->message == WM_CHAR && lpMsg->wParam > 0x7Fu && lpMsg->wParam <= 0xFFu && IsWindow(lpMsg->hwnd) && GetPropA(lpMsg->hwnd,c_szUnicowsProp)) + { + WORD unichar; + char ansichar = lpMsg->wParam; + MultiByteToWideChar(GetCPFromLocale((LCID)GetKeyboardLayout(GetCurrentThreadId())),0,&ansichar,1,&unichar,1); + lpMsg->wParam = unichar; + } + return result; +} + +/* This fix is mainly for Winamp. Proper fix would be to hook SetWindowLongA too, but it's too hard and still, + MSLU would fail to deliver right ANSI functions. Forget it! +*/ + +/* MAKE_EXPORT GetWindowLongA_new=GetWindowLongA */ +LONG WINAPI GetWindowLongA_new(HWND hWnd, int nIndex) +{ + LONG ret = GetWindowLongA( hWnd, nIndex ); + if ( nIndex == GWL_WNDPROC && ret & 0x80000000 && GetPropA(hWnd, c_szUnicowsProp) ) + { + typedef HRESULT (WINAPI *GWLU) (HWND hWnd, int nIndex); + GWLU GetWindowLongAU = (GWLU)GetProcAddress( GetModuleHandleA(c_szUnicows), "GetWindowLongA" ); + if ( GetWindowLongAU ) + { + LONG retU = GetWindowLongAU( hWnd, nIndex ); + if ( retU ) return retU; + } + } + return ret; +} diff --git a/apilibs/kexbases/User32/UpdateLayeredWindow.c b/apilibs/kexbases/User32/UpdateLayeredWindow.c new file mode 100644 index 0000000..b3560bc --- /dev/null +++ b/apilibs/kexbases/User32/UpdateLayeredWindow.c @@ -0,0 +1,45 @@ +/* + * KernelEx + * Copyright (C) 2008, Tihiy + * 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. + * + */ + +#include + +/* MAKE_EXPORT UpdateLayeredWindow_new=UpdateLayeredWindow */ +BOOL WINAPI UpdateLayeredWindow_new( + HWND hwnd, // handle to layered window + HDC hdcDst, // handle to screen DC + POINT *pptDst, // new screen position + SIZE *psize, // new size of the layered window + HDC hdcSrc, // handle to surface DC + POINT *pptSrc, // layer position + COLORREF crKey, // color key + BLENDFUNCTION *pblend, // blend function + DWORD dwFlags // options +) +{ + //pretty dumb stub for Firefox + if ( hdcSrc && psize && pptSrc ) + { + HDC hdc = GetDC( hwnd ); + BitBlt( hdc, 0, 0, psize->cx, psize->cy, hdcSrc, pptSrc->x, pptSrc->y, SRCCOPY ); + ReleaseDC( hwnd, hdc ); + } + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} diff --git a/apilibs/kexbases/User32/_user32_apilist.c b/apilibs/kexbases/User32/_user32_apilist.c new file mode 100644 index 0000000..d0713e3 --- /dev/null +++ b/apilibs/kexbases/User32/_user32_apilist.c @@ -0,0 +1,97 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" +#include "kexcoresdk.h" +#include "_user32_apilist.h" + +IsHungThread_t IsHungThread_pfn; +DrawCaptionTempA_t DrawCaptionTempA_pfn; + +BOOL init_user32() +{ + HMODULE hUser32 = GetModuleHandle("USER32.DLL"); + + IsHungThread_pfn = (IsHungThread_t)GetProcAddress(hUser32, "IsHungThread"); + DrawCaptionTempA_pfn = (DrawCaptionTempA_t)GetProcAddress(hUser32, "DrawCaptionTempA"); + GetMouseMovePoints_pfn = (GetMouseMovePoints_t)GetProcAddress(hUser32, "GetMouseMovePoints"); + + return IsHungThread_pfn && DrawCaptionTempA_pfn && GetMouseMovePoints_pfn; +} + +/* + * MAKE_EXPORT RealGetWindowClass=RealGetWindowClassA + * MAKE_EXPORT GetAltTabInfo=GetAltTabInfoA + * MAKE_EXPORT PeekMessageA=PeekMessageW + * MAKE_EXPORT DispatchMessageA=DispatchMessageW + * MAKE_EXPORT IsDialogMessageA=IsDialogMessageW + * MAKE_EXPORT TranslateAcceleratorA=TranslateAcceleratorW + * MAKE_EXPORT CopyAcceleratorTableA=CopyAcceleratorTableW + * MAKE_EXPORT CreateAcceleratorTableA=CreateAcceleratorTableW + * MAKE_EXPORT CallMsgFilterA=CallMsgFilterW + */ + +static const apilib_named_api user32_named_apis[] = +{ +/*** AUTOGENERATED APILIST NAMED EXPORTS BEGIN ***/ + DECL_API("AllowSetForegroundWindow", AllowSetForegroundWindow_98), + DECL_API("CallMsgFilterW", CallMsgFilterA), + DECL_API("CallWindowProcA", CallWindowProcA_fix), + DECL_API("CopyAcceleratorTableW", CopyAcceleratorTableA), + DECL_API("CreateAcceleratorTableW", CreateAcceleratorTableA), + DECL_API("DisableProcessWindowsGhosting", DisableProcessWindowsGhosting_new), + DECL_API("DispatchMessageW", DispatchMessageA), + DECL_API("DrawCaptionTempW", DrawCaptionTempW_new), + DECL_API("EnableWindow", EnableWindow_new), + DECL_API("GetAltTabInfoA", GetAltTabInfo), + DECL_API("GetAncestor", GetAncestor_fix), + DECL_API("GetLastInputInfo", GetLastInputInfo_new), + DECL_API("GetMessageW", GetMessageW_new), + DECL_API("GetMouseMovePointsEx", GetMouseMovePointsEx_98), + DECL_API("GetWindowLongA", GetWindowLongA_new), + DECL_API("IsDialogMessageW", IsDialogMessageA), + DECL_API("IsHungAppWindow", IsHungAppWindow_new), + DECL_API("LoadStringW", LoadStringW_new), + DECL_API("LockSetForegroundWindow", LockSetForegroundWindow_98), + DECL_API("LockWorkStation", LockWorkStation_new), + DECL_API("MapVirtualKeyA", MapVirtualKeyA_new), + DECL_API("MapVirtualKeyExA", MapVirtualKeyExA_new), + DECL_API("PeekMessageW", PeekMessageA), + DECL_API("RealGetWindowClassA", RealGetWindowClass), + DECL_API("RealGetWindowClassW", RealGetWindowClassW_new), + DECL_API("SendMessageA", SendMessageA_fix), + DECL_API("SetLayeredWindowAttributes", SetLayeredWindowAttributes_stub), + DECL_API("ToUnicode", ToUnicode_new), + DECL_API("ToUnicodeEx", ToUnicodeEx_new), + DECL_API("TranslateAcceleratorW", TranslateAcceleratorA), + DECL_API("UpdateLayeredWindow", UpdateLayeredWindow_new), +/*** AUTOGENERATED APILIST NAMED EXPORTS END ***/ +}; + +#if 0 +static const apilib_unnamed_api user32_ordinal_apis[] = +{ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS BEGIN ***/ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS END ***/ +}; +#endif + +const apilib_api_table apitable_user32 = DECL_TAB("USER32.DLL", user32_named_apis, 0 /*user32_ordinal_apis*/); diff --git a/apilibs/kexbases/User32/_user32_apilist.h b/apilibs/kexbases/User32/_user32_apilist.h new file mode 100644 index 0000000..f8101fc --- /dev/null +++ b/apilibs/kexbases/User32/_user32_apilist.h @@ -0,0 +1,63 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#ifndef _USER32_APILIST_H +#define _USER32_APILIST_H + +#include "auxdecl.h" +#include "kexcoresdk.h" + +typedef BOOL (WINAPI *IsHungThread_t)(DWORD ThreadID); +extern IsHungThread_t IsHungThread_pfn; +typedef BOOL (WINAPI *DrawCaptionTempA_t)(HWND, HDC, const RECT*, HFONT, HICON, LPCSTR, UINT); +extern DrawCaptionTempA_t DrawCaptionTempA_pfn; +typedef int (WINAPI *GetMouseMovePoints_t)(UINT,LPMOUSEMOVEPOINT,LPMOUSEMOVEPOINT,int,DWORD); +extern GetMouseMovePoints_t GetMouseMovePoints_pfn; + +BOOL init_user32(); +extern const apilib_api_table apitable_user32; + +/*** AUTOGENERATED APILIST DECLARATIONS BEGIN ***/ +LRESULT WINAPI CallWindowProcA_fix(WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); +void __stdcall DisableProcessWindowsGhosting_new(void); +BOOL WINAPI EnableWindow_new(HWND hWnd, BOOL bEnable); +BOOL WINAPI AllowSetForegroundWindow_98(DWORD procid); +BOOL WINAPI LockSetForegroundWindow_98(UINT lockcode); +HWND APIENTRY GetAncestor_fix(HWND hwnd, UINT gaFlags); +int WINAPI GetMouseMovePointsEx_98(UINT size, LPMOUSEMOVEPOINT ptin, LPMOUSEMOVEPOINT ptout, int count, DWORD res); +BOOL WINAPI IsHungAppWindow_new(HWND hWnd); +BOOL WINAPI LockWorkStation_new(void); +UINT WINAPI MapVirtualKeyA_new(UINT uCode, UINT uMapType); +UINT WINAPI MapVirtualKeyExA_new(UINT uCode, UINT uMapType, HKL dwhkl); +LRESULT WINAPI SendMessageA_fix(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); +int WINAPI ToUnicodeEx_new(UINT wVirtKey, UINT wScanCode, const PBYTE lpKeyState, LPWSTR pwszBuff, int cchBuff, UINT wFlags, HKL dwhkl); +int WINAPI ToUnicode_new(UINT wVirtKey, UINT wScanCode, const PBYTE lpKeyState, LPWSTR pwszBuff, int cchBuff, UINT wFlags); +BOOL WINAPI GetLastInputInfo_new(PLASTINPUTINFO plii); +BOOL WINAPI GetMessageW_new(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax); +LONG WINAPI GetWindowLongA_new(HWND hWnd, int nIndex); +BOOL WINAPI UpdateLayeredWindow_new(HWND hwnd, HDC hdcDst, POINT *pptDst, SIZE *psize, HDC hdcSrc, POINT *pptSrc, COLORREF crKey, BLENDFUNCTION *pblend, DWORD dwFlags); +STUB SetLayeredWindowAttributes_stub; +BOOL WINAPI DrawCaptionTempW_new(HWND hwnd, HDC hdc, const RECT *rect, HFONT hFont, HICON hIcon, LPCWSTR strW, UINT uFlags); +int WINAPI LoadStringW_new(HINSTANCE hInstance, UINT uID, LPWSTR lpBuffer, int nBufferMax); +UINT WINAPI RealGetWindowClassW_new(HWND hwnd, LPWSTR pszTypeW, UINT cchType); +/*** AUTOGENERATED APILIST DECLARATIONS END ***/ + +#endif diff --git a/apilibs/kexbases/User32/_user32_stubs.c b/apilibs/kexbases/User32/_user32_stubs.c new file mode 100644 index 0000000..f1cff14 --- /dev/null +++ b/apilibs/kexbases/User32/_user32_stubs.c @@ -0,0 +1,24 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" + +UNIMPL_FUNC(SetLayeredWindowAttributes, 4); diff --git a/apilibs/kexbases/User32/uniuser32.c b/apilibs/kexbases/User32/uniuser32.c new file mode 100644 index 0000000..26b2d46 --- /dev/null +++ b/apilibs/kexbases/User32/uniuser32.c @@ -0,0 +1,91 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" +#include "_user32_apilist.h" +#include + +/* MAKE_EXPORT DrawCaptionTempW_new=DrawCaptionTempW */ +BOOL WINAPI DrawCaptionTempW_new(HWND hwnd, HDC hdc, const RECT *rect, HFONT hFont, HICON hIcon, LPCWSTR strW, UINT uFlags) +{ + if (!(uFlags & DC_TEXT) || !strW) + return DrawCaptionTempA_pfn(hwnd, hdc, rect, hFont, hIcon, (LPCSTR)strW, uFlags); + else + { + ALLOC_WtoA(str); + return DrawCaptionTempA_pfn(hwnd, hdc, rect, hFont, hIcon, strA, uFlags); + } +} + +/* MAKE_EXPORT LoadStringW_new=LoadStringW */ +int WINAPI LoadStringW_new(HINSTANCE hInstance, UINT uID, LPWSTR lpBuffer, int nBufferMax) +{ + int len; + LPWSTR wstr; + + len = 0; + if (lpBuffer) + { + // find stringtable resource + HRSRC res = FindResourceA(hInstance, MAKEINTRESOURCE((uID >> 4) + 1), RT_STRING); + if (res) + { + // load stringtable resource + HGLOBAL data = LoadResource(hInstance, res); + if (data) + { + // find string in stringtable + uID &= 0xf; + do + { + len = *(WORD*)data; + wstr = (LPWSTR)data + 1; + data = (HGLOBAL)(wstr + len); + } + while (uID--); + // if nBufferMax is zero, then lpBuffer receives pointer to the resource itself + if (!nBufferMax) + { + *(LPWSTR*)lpBuffer = wstr; + return len; + } + if (len > nBufferMax - 1) + { + len = nBufferMax - 1; + } + memcpy(lpBuffer, wstr, len * sizeof(WCHAR)); + } + } + lpBuffer[len] = 0; + } + return len; +} + +/* MAKE_EXPORT RealGetWindowClassW_new=RealGetWindowClassW */ +UINT WINAPI RealGetWindowClassW_new(HWND hwnd, LPWSTR pszTypeW, UINT cchType) +{ + UINT ret; + ALLOC_A(pszType, cchType * acp_mcs); + ret = RealGetWindowClass(hwnd, pszTypeA, cchType * acp_mcs); + if (ret) + ret = ABUFtoW(pszType, ret, cchType); + return ret; +} diff --git a/apilibs/kexbases/auxdecl.h b/apilibs/kexbases/auxdecl.h new file mode 100644 index 0000000..5f0e8eb --- /dev/null +++ b/apilibs/kexbases/auxdecl.h @@ -0,0 +1,136 @@ +/* This file contains required declarations missing from MINGW and MSVC6 without PSDK */ + +#ifndef __AUXDECL_H +#define __AUXDECL_H + + +#include + +/* declarations for MSVC6 without PSDK */ +#if defined (_MSC_VER) && (WINVER < 0x0500) + +#define VER_MINORVERSION 0x0000001 +#define VER_MAJORVERSION 0x0000002 +#define VER_BUILDNUMBER 0x0000004 +#define VER_PLATFORMID 0x0000008 +#define VER_SERVICEPACKMINOR 0x0000010 +#define VER_SERVICEPACKMAJOR 0x0000020 +#define VER_SUITENAME 0x0000040 +#define VER_PRODUCT_TYPE 0x0000080 +#define VER_EQUAL 1 +#define VER_GREATER 2 +#define VER_GREATER_EQUAL 3 +#define VER_LESS 4 +#define VER_LESS_EQUAL 5 +#define VER_AND 6 +#define VER_OR 7 + +#define VER_NT_WORKSTATION 1 +#define VER_NT_DOMAIN_CONTROLLER 2 +#define VER_NT_SERVER 3 +#define VER_SUITE_SMALLBUSINESS 1 +#define VER_SUITE_ENTERPRISE 2 +#define VER_SUITE_BACKOFFICE 4 +#define VER_SUITE_TERMINAL 16 +#define VER_SUITE_SMALLBUSINESS_RESTRICTED 32 +#define VER_SUITE_EMBEDDEDNT 64 +#define VER_SUITE_DATACENTER 128 +#define VER_SUITE_SINGLEUSERTS 256 +#define VER_SUITE_PERSONAL 512 +#define VER_SUITE_BLADE 1024 +#define VER_SUITE_STORAGE_SERVER 8192 +#define VER_SUITE_COMPUTE_SERVER 16384 + +#define OSVERSIONINFOEXA __OSVERSIONINFOEXA +#define POSVERSIONINFOEXA __POSVERSIONINFOEXA +#define LPOSVERSIONINFOEXA __LPOSVERSIONINFOEXA +#define OSVERSIONINFOEXW __OSVERSIONINFOEXW +#define POSVERSIONINFOEXW __POSVERSIONINFOEXW +#define LPOSVERSIONINFOEXW __LPOSVERSIONINFOEXW + +typedef struct { + DWORD dwOSVersionInfoSize; + DWORD dwMajorVersion; + DWORD dwMinorVersion; + DWORD dwBuildNumber; + DWORD dwPlatformId; + CHAR szCSDVersion[128]; + WORD wServicePackMajor; + WORD wServicePackMinor; + WORD wSuiteMask; + BYTE wProductType; + BYTE wReserved; +} __OSVERSIONINFOEXA, *__POSVERSIONINFOEXA, *__LPOSVERSIONINFOEXA; +typedef struct { + DWORD dwOSVersionInfoSize; + DWORD dwMajorVersion; + DWORD dwMinorVersion; + DWORD dwBuildNumber; + DWORD dwPlatformId; + WCHAR szCSDVersion[128]; + WORD wServicePackMajor; + WORD wServicePackMinor; + WORD wSuiteMask; + BYTE wProductType; + BYTE wReserved; +} __OSVERSIONINFOEXW, *__POSVERSIONINFOEXW, *__LPOSVERSIONINFOEXW; + +typedef long LONG_PTR; +typedef BOOL (CALLBACK *UILANGUAGE_ENUMPROCA)(LPSTR, LONG_PTR); +typedef BOOL (CALLBACK *UILANGUAGE_ENUMPROCW)(LPWSTR, LONG_PTR); + +#define MEMORYSTATUSEX __MEMORYSTATUSEX +#define PMEMORYSTATUSEX __PMEMORYSTATUSEX +#define LPMEMORYSTATUSEX __LPMEMORYSTATUSEX + +typedef struct +{ + DWORD dwLength; + DWORD dwMemoryLoad; + DWORDLONG ullTotalPhys; + DWORDLONG ullAvailPhys; + DWORDLONG ullTotalPageFile; + DWORDLONG ullAvailPageFile; + DWORDLONG ullTotalVirtual; + DWORDLONG ullAvailVirtual; + DWORDLONG ullAvailExtendedVirtual; +} __MEMORYSTATUSEX, *__PMEMORYSTATUSEX, *__LPMEMORYSTATUSEX; + +typedef enum { + SHGFP_TYPE_CURRENT = 0, + SHGFP_TYPE_DEFAULT = 1, +} SHGFP_TYPE; + +#define GA_ROOT 2 + +typedef void *LPPRINTDLGEX; +typedef void *LPMOUSEMOVEPOINT; + +EXTERN_C int WINAPI GetRandomRgn(HDC hdc, HRGN hrgn, INT iNum); +EXTERN_C HRESULT WINAPI SHGetFolderPathA(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPSTR pszPath); +EXTERN_C HWND WINAPI GetAncestor(HWND hwnd, UINT gaFlags); +EXTERN_C UINT WINAPI RealGetWindowClass(HWND hwnd, LPTSTR pszType, UINT cchType); + +#endif /* defined (_MSC_VER) && (WINVER < 0x0500) */ + + +/* declarations for MINGW32 */ +#ifdef __MINGW32_VERSION + +/* The security descriptor structure */ +typedef struct { + BYTE Revision; + BYTE Sbz1; + SECURITY_DESCRIPTOR_CONTROL Control; + DWORD Owner; + DWORD Group; + DWORD Sacl; + DWORD Dacl; +} SECURITY_DESCRIPTOR_RELATIVE, *PISECURITY_DESCRIPTOR_RELATIVE; + +#endif /* __MINGW32_VERSION */ + +/* declarations for everyone */ +EXTERN_C BOOL WINAPI GetAltTabInfo(HWND,int,PVOID,LPSTR,UINT); + +#endif /* __AUXDECL_H */ diff --git a/apilibs/kexbases/comdlg32/PrintDlgEx.c b/apilibs/kexbases/comdlg32/PrintDlgEx.c new file mode 100644 index 0000000..dd9a8d1 --- /dev/null +++ b/apilibs/kexbases/comdlg32/PrintDlgEx.c @@ -0,0 +1,31 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "auxdecl.h" + +/* MAKE_EXPORT PrintDlgEx_new=PrintDlgExA + * MAKE_EXPORT PrintDlgEx_new=PrintDlgExW + */ +HRESULT WINAPI PrintDlgEx_new(LPPRINTDLGEX lppd) +{ + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return E_NOTIMPL; +} diff --git a/apilibs/kexbases/comdlg32/_comdlg32_apilist.c b/apilibs/kexbases/comdlg32/_comdlg32_apilist.c new file mode 100644 index 0000000..57f80a3 --- /dev/null +++ b/apilibs/kexbases/comdlg32/_comdlg32_apilist.c @@ -0,0 +1,47 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" +#include "kexcoresdk.h" +#include "_comdlg32_apilist.h" + +BOOL init_comdlg32() +{ + return TRUE; +} + +static const apilib_named_api comdlg32_named_apis[] = +{ +/*** AUTOGENERATED APILIST NAMED EXPORTS BEGIN ***/ + DECL_API("PrintDlgExA", PrintDlgEx_new), + DECL_API("PrintDlgExW", PrintDlgEx_new), +/*** AUTOGENERATED APILIST NAMED EXPORTS END ***/ +}; + +#if 0 +static const apilib_unnamed_api comdlg32_ordinal_apis[] = +{ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS BEGIN ***/ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS END ***/ +}; +#endif + +const apilib_api_table apitable_comdlg32 = DECL_TAB("COMDLG32.DLL", comdlg32_named_apis, 0 /*comdlg32_ordinal_apis*/); diff --git a/apilibs/kexbases/comdlg32/_comdlg32_apilist.h b/apilibs/kexbases/comdlg32/_comdlg32_apilist.h new file mode 100644 index 0000000..d84caaf --- /dev/null +++ b/apilibs/kexbases/comdlg32/_comdlg32_apilist.h @@ -0,0 +1,35 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#ifndef _COMDLG32_APILIST_H +#define _COMDLG32_APILIST_H + +#include "auxdecl.h" +#include "kexcoresdk.h" + +BOOL init_comdlg32(); +extern const apilib_api_table apitable_comdlg32; + +/*** AUTOGENERATED APILIST DECLARATIONS BEGIN ***/ +HRESULT WINAPI PrintDlgEx_new(LPPRINTDLGEX lppd); +/*** AUTOGENERATED APILIST DECLARATIONS END ***/ + +#endif diff --git a/apilibs/kexbases/common.c b/apilibs/kexbases/common.c new file mode 100644 index 0000000..346e7ff --- /dev/null +++ b/apilibs/kexbases/common.c @@ -0,0 +1,52 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" + +int acp_mcs; + +static int GetMaxCharSize(UINT CodePage) +{ + CPINFO cpi; + if (!GetCPInfo(CodePage, &cpi)) + return 2; + return cpi.MaxCharSize; +} + +BOOL common_init(void) +{ + acp_mcs = GetMaxCharSize(CP_ACP); + return TRUE; +} + +char* file_fixWprefix(char* in) +{ + if (*(int *)in == 0x5c3f5c5c) //if (!strncmp(in, "\\?\", 4)) + { + in += 4; + if (*(int *)in == 0x5c434e55) //if (!strncmp(in, "UNC\", 4)) + { + in += 2; + *in = '\\'; + } + } + return in; +} diff --git a/apilibs/kexbases/common.h b/apilibs/kexbases/common.h new file mode 100644 index 0000000..04cc26c --- /dev/null +++ b/apilibs/kexbases/common.h @@ -0,0 +1,113 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#ifndef __COMMON_H +#define __COMMON_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef int __stdcall STUB(void); +typedef int __stdcall FWDPROC(void); + +extern int acp_mcs; +BOOL common_init(void); +int WINAPI CommonUnimpStub(void); +char* file_fixWprefix(char* in); + +#ifdef __cplusplus +}; +#endif + +#ifdef __GNUC__ +#define UNIMPL_FUNC(name,params) \ + __asm__( ".text\n" \ + ".globl _" #name "_stub@0\n" \ + "_" #name "_new@0:\n\t" \ + "xor %eax, %eax\n\t" \ + "movb $" #params ", %cl\n\t" \ + "jmp _CommonUnimpStub@0\n\t" \ + ) +#else +#define UNIMPL_FUNC(name,params) \ + int __declspec(naked) __stdcall name##_stub() \ + { \ + __asm xor eax,eax \ + __asm mov cl, params \ + __asm jmp CommonUnimpStub \ + } +#endif + +#define AtoW(str, bsize) MultiByteToWideChar(CP_ACP, 0, str##A, -1, str##W, bsize) +#define WtoA(str, bsize) WideCharToMultiByte(CP_ACP, 0, str##W, -1, str##A, bsize, NULL, NULL) + +#define _ALLOC_WtoA(str) \ + const WCHAR* p; \ + int c; \ + for (p = str##W ; *p ; p++); \ + c = (int) p - (int) str##W; \ + c *= acp_mcs; \ + str##A = (char*) alloca(c); \ + WtoA(str, c) + + +#define ALLOC_WtoA(str) \ + char* str##A; \ + if (str##W) \ + { \ + _ALLOC_WtoA(str); \ + } \ + else str##A = NULL + +#define ALLOC_A(str, cnt) \ + char* str##A = str##W ? ((char*) alloca(cnt)) : NULL + +#define ABUFtoW(str, inbsize, outbsize) \ + MultiByteToWideChar(CP_ACP, 0, str##A, inbsize, str##W, outbsize) + +#define file_GetCP() \ + UINT file_CP = AreFileApisANSI() ? CP_ACP : CP_OEMCP +#define file_AtoW(str, bsize) MultiByteToWideChar(file_CP, 0, str##A, -1, str##W, bsize) +#define file_WtoA(str, bsize) WideCharToMultiByte(file_CP, 0, str##W, -1, str##A, bsize, "_", NULL); \ + str##A = file_fixWprefix(str##A) + +#define file_ALLOC_WtoA(str) \ + char* str##A; \ + if (str##W) \ + { \ + const WCHAR* p; \ + int c; \ + for (p = str##W ; *p ; p++); \ + c = (int) p - (int) str##W; \ + c *= acp_mcs; \ + str##A = (char*) alloca(c); \ + file_WtoA(str, c); \ + } \ + else str##A = NULL + +#define file_ABUFtoW(str, cntsrc, bsize) \ + MultiByteToWideChar(file_CP, 0, str##A, cntsrc, str##W, bsize) + +#endif diff --git a/apilibs/kexbases/dirlist b/apilibs/kexbases/dirlist new file mode 100644 index 0000000..fe65ef2 --- /dev/null +++ b/apilibs/kexbases/dirlist @@ -0,0 +1,7 @@ +kernel32 +user32 +gdi32 +advapi32 +comdlg32 +shell32 +version diff --git a/apilibs/kexbases/kernel32ord.def b/apilibs/kexbases/kernel32ord.def new file mode 100644 index 0000000..a21814b --- /dev/null +++ b/apilibs/kexbases/kernel32ord.def @@ -0,0 +1,14 @@ +LIBRARY KERNEL32.dll + +EXPORTS + CommonUnimpStub@0 @17 NONAME + VxDCall1@4 @1 NONAME + VxDCall2@8 @2 NONAME + VxDCall3@12 @3 NONAME + VxDCall4@16 @4 NONAME + VxDCall5@20 @5 NONAME + VxDCall6@24 @6 NONAME + VxDCall7@28 @7 NONAME + VxDCall8@32 @8 NONAME + _EnterSysLevel@4 @97 NONAME + _LeaveSysLevel@4 @98 NONAME diff --git a/apilibs/kexbases/kexbases.def b/apilibs/kexbases/kexbases.def new file mode 100644 index 0000000..ab58640 --- /dev/null +++ b/apilibs/kexbases/kexbases.def @@ -0,0 +1,8 @@ +LIBRARY kexbases.dll BASE=0xBFA40000 +SECTIONS + .text SHARED + .bss SHARED + .data SHARED + .edata SHARED + .rdata SHARED + .idata SHARED diff --git a/apilibs/kexbases/kexbases.dsp b/apilibs/kexbases/kexbases.dsp new file mode 100644 index 0000000..f684c1a --- /dev/null +++ b/apilibs/kexbases/kexbases.dsp @@ -0,0 +1,467 @@ +# Microsoft Developer Studio Project File - Name="KernelEx Base Shared" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=KernelEx Base Shared - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "kexbases.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "kexbases.mak" CFG="KernelEx Base Shared - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "KernelEx Base Shared - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "KernelEx Base Shared - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "KernelEx Base Shared - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "KERNELEXBASESHARED_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /O2 /I "." /I "../../common" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D _WIN32_WINNT=0x0500 /YX /FD /TP /GF /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x415 /d "NDEBUG" +# ADD RSC /l 0x415 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib version.lib ../../common/KernelEx.lib ../../kexcrt/kexcrt.lib libc.lib /nologo /dll /map /machine:I386 /nodefaultlib /ignore:4092 /OPT:NOWIN98 +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "KernelEx Base Shared - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "KERNELEXBASESHARED_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /Zi /Od /I "." /I "../../common" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D _WIN32_WINNT=0x0500 /YX /FD /TP /GZ /GF /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x415 /d "_DEBUG" +# ADD RSC /l 0x415 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib version.lib ../../common/KernelEx.lib ../../kexcrt/kexcrt.lib libc.lib /nologo /dll /map /debug /machine:I386 /nodefaultlib /pdbtype:sept /ignore:4092 /OPT:NOWIN98 +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "KernelEx Base Shared - Win32 Release" +# Name "KernelEx Base Shared - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Group "kernel32" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\Kernel32\_kernel32_apilist.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\_kernel32_apilist.h +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\_kernel32_stubs.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\CopyFileEx.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\CreateFileA_fix.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\CreateThread_fix.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\DeleteCriticalSection.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\GetFileSizeEx.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\GlobalMemoryStatusEx.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\HeapLocks.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\InitializeCriticalSectionAndSpinCount.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\Jobs.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\KEXVersion.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\LockFileEx.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\MapViewOfFile.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\MoveFileExA.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\MoveFileWithProgressA.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\OpenThread.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\SetFilePointerEx.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\ThreadPool.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\TryEnterCriticalSection.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\uilang.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\unikernel32.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\version.c +# End Source File +# Begin Source File + +SOURCE=.\Kernel32\VirtualAllocEx.c +# End Source File +# End Group +# Begin Group "user32" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\User32\_user32_apilist.c +# End Source File +# Begin Source File + +SOURCE=.\User32\_user32_apilist.h +# End Source File +# Begin Source File + +SOURCE=.\User32\_user32_stubs.c +# End Source File +# Begin Source File + +SOURCE=.\User32\CallWindowProcA_fix.c +# End Source File +# Begin Source File + +SOURCE=.\User32\DisableProcessWindowsGhosting.c +# End Source File +# Begin Source File + +SOURCE=.\User32\EnableWindow.c +# End Source File +# Begin Source File + +SOURCE=.\User32\ForegroundWindow.c +# End Source File +# Begin Source File + +SOURCE=.\User32\GetAncestor.c +# End Source File +# Begin Source File + +SOURCE=.\User32\GetMouseMovePointsEx.c +# End Source File +# Begin Source File + +SOURCE=.\User32\IsHungAppWindow.c +# End Source File +# Begin Source File + +SOURCE=.\User32\LockWorkStation.c +# End Source File +# Begin Source File + +SOURCE=.\User32\MapVirtualKey_fix.c +# End Source File +# Begin Source File + +SOURCE=.\User32\SendMessage_fix.c +# End Source File +# Begin Source File + +SOURCE=.\User32\UberUSER.c +# End Source File +# Begin Source File + +SOURCE=.\User32\uniuser32.c +# End Source File +# Begin Source File + +SOURCE=.\User32\UpdateLayeredWindow.c +# End Source File +# End Group +# Begin Group "gdi32" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\Gdi32\_gdi32_apilist.c +# End Source File +# Begin Source File + +SOURCE=.\Gdi32\_gdi32_apilist.h +# End Source File +# Begin Source File + +SOURCE=.\Gdi32\_gdi32_stubs.c +# End Source File +# Begin Source File + +SOURCE=.\Gdi32\FontResourceExA.c +# End Source File +# Begin Source File + +SOURCE=.\Gdi32\GetGlyphOutlineA_fix.c +# End Source File +# Begin Source File + +SOURCE=.\Gdi32\TextOut.c +# End Source File +# Begin Source File + +SOURCE=.\Gdi32\unigdi32.c +# End Source File +# End Group +# Begin Group "advapi32" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\Advapi32\_advapi32_apilist.c +# End Source File +# Begin Source File + +SOURCE=.\Advapi32\_advapi32_apilist.h +# End Source File +# Begin Source File + +SOURCE=.\Advapi32\_advapi32_stubs.c +# End Source File +# Begin Source File + +SOURCE=.\Advapi32\RegDisablePredefinedCache.c +# End Source File +# Begin Source File + +SOURCE=.\Advapi32\RegOpenCurrentUser.c +# End Source File +# Begin Source File + +SOURCE=.\Advapi32\security.c +# End Source File +# Begin Source File + +SOURCE=.\Advapi32\TraceMessage.c +# End Source File +# Begin Source File + +SOURCE=.\Advapi32\uniadvapi32.c +# End Source File +# End Group +# Begin Group "comdlg32" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\comdlg32\_comdlg32_apilist.c +# End Source File +# Begin Source File + +SOURCE=.\comdlg32\_comdlg32_apilist.h +# End Source File +# Begin Source File + +SOURCE=.\comdlg32\PrintDlgEx.c +# End Source File +# End Group +# Begin Group "version" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\version\_version_apilist.c +# End Source File +# Begin Source File + +SOURCE=.\version\_version_apilist.h +# End Source File +# Begin Source File + +SOURCE=.\version\universion.c +# End Source File +# End Group +# Begin Group "shell32" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\shell32\_shell32_apilist.c +# End Source File +# Begin Source File + +SOURCE=.\shell32\_shell32_apilist.h +# End Source File +# Begin Source File + +SOURCE=.\shell32\_shell32_stubs.c +# End Source File +# Begin Source File + +SOURCE=.\shell32\CommandLineToArgvW.c +# End Source File +# Begin Source File + +SOURCE=.\shell32\IsUserAnAdmin.c +# End Source File +# End Group +# Begin Source File + +SOURCE=.\common.c +# End Source File +# Begin Source File + +SOURCE=.\kernel32ord.def +# PROP Exclude_From_Build 1 +# End Source File +# Begin Source File + +SOURCE=.\kexbases.def + +!IF "$(CFG)" == "KernelEx Base Shared - Win32 Release" + +# Begin Custom Build +OutDir=.\Release +ProjDir=. +InputPath=.\kexbases.def + +BuildCmds= \ + link /LIB /NOLOGO /MACHINE:IX86 /DEF:$(ProjDir)\kernel32ord.def /OUT:$(OutDir)\kernel32ord.lib + +"$(OutDir)\kernel32ord.lib" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(OutDir)\kernel32ord.exp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) +# End Custom Build + +!ELSEIF "$(CFG)" == "KernelEx Base Shared - Win32 Debug" + +# Begin Custom Build +OutDir=.\Debug +ProjDir=. +InputPath=.\kexbases.def + +BuildCmds= \ + link /LIB /NOLOGO /MACHINE:IX86 /DEF:$(ProjDir)\kernel32ord.def /OUT:$(OutDir)\kernel32ord.lib + +"$(OutDir)\kernel32ord.lib" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(OutDir)\kernel32ord.exp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) +# End Custom Build + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\main.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\auxdecl.h +# End Source File +# Begin Source File + +SOURCE=.\common.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# Begin Source File + +SOURCE=.\kexbases.rc +# End Source File +# End Group +# End Target +# End Project diff --git a/apilibs/kexbases/kexbases.rc b/apilibs/kexbases/kexbases.rc new file mode 100644 index 0000000..91a409e --- /dev/null +++ b/apilibs/kexbases/kexbases.rc @@ -0,0 +1,109 @@ +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// Polish resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_PLK) +#ifdef _WIN32 +LANGUAGE LANG_POLISH, SUBLANG_DEFAULT +#pragma code_page(1250) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +#ifndef _MAC +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 4,0,1,0 + PRODUCTVERSION 4,0,1,0 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004b0" + BEGIN + VALUE "Comments", "\0" + VALUE "CompanyName", "Xeno86\0" + VALUE "FileDescription", "KernelEx Base Shared Api Library\0" + VALUE "FileVersion", "4, 0, 1, 0\0" + VALUE "InternalName", "kexbases\0" + VALUE "LegalCopyright", "Copyright © 2009, Xeno86\0" + VALUE "LegalTrademarks", "\0" + VALUE "OriginalFilename", "kexbases.dll\0" + VALUE "PrivateBuild", "\0" + VALUE "ProductName", "KernelEx\0" + VALUE "ProductVersion", "4, 0, 1, 0\0" + VALUE "SpecialBuild", "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0, 1200 + END +END + +#endif // !_MAC + +#endif // Polish resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/apilibs/kexbases/main.c b/apilibs/kexbases/main.c new file mode 100644 index 0000000..376f057 --- /dev/null +++ b/apilibs/kexbases/main.c @@ -0,0 +1,79 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" +#include "kexcoresdk.h" +#include "kernel32/_kernel32_apilist.h" +#include "gdi32/_gdi32_apilist.h" +#include "user32/_user32_apilist.h" +#include "advapi32/_advapi32_apilist.h" +#include "comdlg32/_comdlg32_apilist.h" +#include "shell32/_shell32_apilist.h" +#include "version/_version_apilist.h" +//#include "/__apilist.h" + +static LONG inited = 0; +static apilib_api_table api_table[8]; + +static void fill_apitable() +{ + api_table[0] = apitable_kernel32; + api_table[1] = apitable_gdi32; + api_table[2] = apitable_user32; + api_table[3] = apitable_advapi32; + api_table[4] = apitable_comdlg32; + api_table[5] = apitable_shell32; + api_table[6] = apitable_version; + //last entry is null terminator +} + +extern "C" +__declspec(dllexport) +const apilib_api_table* get_api_table() +{ + fill_apitable(); + return api_table; +} + +BOOL init_once() +{ + return common_init() && init_kernel32() && init_gdi32() && init_user32() && init_advapi32() && init_comdlg32() && init_shell32() && init_version(); +} + +BOOL APIENTRY DllMain(HINSTANCE instance, DWORD reason, BOOL load_static) +{ + switch (reason) + { + case DLL_PROCESS_ATTACH: +// kexDebugPrint("KernelEx Base Shared library reporting in action!\n"); + DisableThreadLibraryCalls(instance); + if (InterlockedExchange(&inited, 1) == 0) + { + if (!init_once()) + return FALSE; + } + break; + case DLL_PROCESS_DETACH: +// kexDebugPrint("KernelEx Base Shared library signing off!\n"); + break; + } + return TRUE; +} diff --git a/apilibs/kexbases/resource.h b/apilibs/kexbases/resource.h new file mode 100644 index 0000000..a0cc924 --- /dev/null +++ b/apilibs/kexbases/resource.h @@ -0,0 +1,15 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by kexbases.rc +// + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1000 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/apilibs/kexbases/shell32/CommandLineToArgvW.c b/apilibs/kexbases/shell32/CommandLineToArgvW.c new file mode 100644 index 0000000..9d852e7 --- /dev/null +++ b/apilibs/kexbases/shell32/CommandLineToArgvW.c @@ -0,0 +1,202 @@ +/* + * Shell basics + * + * Copyright 1998 Marcus Meissner + * Copyright 1998 Juergen Schmied (jsch) * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include + +/************************************************************************* + * CommandLineToArgvW [SHELL32.@] + * + * We must interpret the quotes in the command line to rebuild the argv + * array correctly: + * - arguments are separated by spaces or tabs + * - quotes serve as optional argument delimiters + * '"a b"' -> 'a b' + * - escaped quotes must be converted back to '"' + * '\"' -> '"' + * - an odd number of '\'s followed by '"' correspond to half that number + * of '\' followed by a '"' (extension of the above) + * '\\\"' -> '\"' + * '\\\\\"' -> '\\"' + * - an even number of '\'s followed by a '"' correspond to half that number + * of '\', plus a regular quote serving as an argument delimiter (which + * means it does not appear in the result) + * 'a\\"b c"' -> 'a\b c' + * 'a\\\\"b c"' -> 'a\\b c' + * - '\' that are not followed by a '"' are copied literally + * 'a\b' -> 'a\b' + * 'a\\b' -> 'a\\b' + * + * Note: + * '\t' == 0x0009 + * ' ' == 0x0020 + * '"' == 0x0022 + * '\\' == 0x005c + */ + +/* MAKE_EXPORT CommandLineToArgvW_new=CommandLineToArgvW */ +LPWSTR* WINAPI CommandLineToArgvW_new(LPCWSTR lpCmdline, int* numargs) +{ + DWORD argc; + LPWSTR *argv; + LPCWSTR cs; + LPWSTR arg,s,d; + LPWSTR cmdline; + int in_quotes,bcount; + + if (*lpCmdline==0) + { + /* Return the path to the executable */ + DWORD len, size=16; + + argv=(LPWSTR*)LocalAlloc(LMEM_FIXED, size); + for (;;) + { + len = GetModuleFileNameW(0, (LPWSTR)(argv+1), (size-sizeof(LPWSTR))/sizeof(WCHAR)); + if (!len) + { + LocalFree(argv); + return NULL; + } + if (len < size) break; + size*=2; + argv=(LPWSTR*)LocalReAlloc(argv, size, 0); + } + argv[0]=(LPWSTR)(argv+1); + if (numargs) + *numargs=2; + + return argv; + } + + /* to get a writable copy */ + argc=0; + bcount=0; + in_quotes=0; + cs=lpCmdline; + while (1) + { + if (*cs==0 || ((*cs==0x0009 || *cs==0x0020) && !in_quotes)) + { + /* space */ + argc++; + /* skip the remaining spaces */ + while (*cs==0x0009 || *cs==0x0020) { + cs++; + } + if (*cs==0) + break; + bcount=0; + continue; + } + else if (*cs==0x005c) + { + /* '\', count them */ + bcount++; + } + else if ((*cs==0x0022) && ((bcount & 1)==0)) + { + /* unescaped '"' */ + in_quotes=!in_quotes; + bcount=0; + } + else + { + /* a regular character */ + bcount=0; + } + cs++; + } + /* Allocate in a single lump, the string array, and the strings that go with it. + * This way the caller can make a single GlobalFree call to free both, as per MSDN. + */ + argv=(LPWSTR*)LocalAlloc(LMEM_FIXED, argc*sizeof(LPWSTR)+(lstrlenW(lpCmdline)+1)*sizeof(WCHAR)); + if (!argv) + return NULL; + cmdline=(LPWSTR)(argv+argc); + lstrcpyW(cmdline, lpCmdline); + + argc=0; + bcount=0; + in_quotes=0; + arg=d=s=cmdline; + while (*s) + { + if ((*s==0x0009 || *s==0x0020) && !in_quotes) + { + /* Close the argument and copy it */ + *d=0; + argv[argc++]=arg; + + /* skip the remaining spaces */ + do { + s++; + } while (*s==0x0009 || *s==0x0020); + + /* Start with a new argument */ + arg=d=s; + bcount=0; + } + else if (*s==0x005c) + { + /* '\\' */ + *d++=*s++; + bcount++; + } + else if (*s==0x0022) + { + /* '"' */ + if ((bcount & 1)==0) + { + /* Preceded by an even number of '\', this is half that + * number of '\', plus a quote which we erase. + */ + d-=bcount/2; + in_quotes=!in_quotes; + s++; + } + else + { + /* Preceded by an odd number of '\', this is half that + * number of '\' followed by a '"' + */ + d=d-bcount/2-1; + *d++='"'; + s++; + } + bcount=0; + } + else + { + /* a regular character */ + *d++=*s++; + bcount=0; + } + } + if (*arg) + { + *d='\0'; + argv[argc++]=arg; + } + if (numargs) + *numargs=argc; + + return argv; +} diff --git a/apilibs/kexbases/shell32/IsUserAnAdmin.c b/apilibs/kexbases/shell32/IsUserAnAdmin.c new file mode 100644 index 0000000..b804f34 --- /dev/null +++ b/apilibs/kexbases/shell32/IsUserAnAdmin.c @@ -0,0 +1,28 @@ +/* + * KernelEx + * Copyright (C) 2007, 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. + * + */ + +#include + +/* MAKE_EXPORT IsUserAnAdmin_new=IsUserAnAdmin */ +BOOL WINAPI IsUserAnAdmin_new(void) +{ + return TRUE; +} diff --git a/apilibs/kexbases/shell32/_shell32_apilist.c b/apilibs/kexbases/shell32/_shell32_apilist.c new file mode 100644 index 0000000..4f3c02d --- /dev/null +++ b/apilibs/kexbases/shell32/_shell32_apilist.c @@ -0,0 +1,49 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" +#include "kexcoresdk.h" +#include "_shell32_apilist.h" + +BOOL init_shell32() +{ + return TRUE; +} + +static const apilib_named_api shell32_named_apis[] = +{ +/*** AUTOGENERATED APILIST NAMED EXPORTS BEGIN ***/ + DECL_API("CommandLineToArgvW", CommandLineToArgvW_new), + DECL_API("IsUserAnAdmin", IsUserAnAdmin_new), + DECL_API("SHCreateShellItem", SHCreateShellItem_stub), + DECL_API("SHParseDisplayName", SHParseDisplayName_stub), +/*** AUTOGENERATED APILIST NAMED EXPORTS END ***/ +}; + +#if 0 +static const apilib_unnamed_api shell32_ordinal_apis[] = +{ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS BEGIN ***/ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS END ***/ +}; +#endif + +const apilib_api_table apitable_shell32 = DECL_TAB("SHELL32.DLL", shell32_named_apis, 0 /*shell32_ordinal_apis*/); diff --git a/apilibs/kexbases/shell32/_shell32_apilist.h b/apilibs/kexbases/shell32/_shell32_apilist.h new file mode 100644 index 0000000..7498426 --- /dev/null +++ b/apilibs/kexbases/shell32/_shell32_apilist.h @@ -0,0 +1,38 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#ifndef _SHELL32_APILIST_H +#define _SHELL32_APILIST_H + +#include "auxdecl.h" +#include "kexcoresdk.h" + +BOOL init_shell32(); +extern const apilib_api_table apitable_shell32; + +/*** AUTOGENERATED APILIST DECLARATIONS BEGIN ***/ +LPWSTR* WINAPI CommandLineToArgvW_new(LPCWSTR lpCmdline, int* numargs); +BOOL WINAPI IsUserAnAdmin_new(void); +STUB SHParseDisplayName_stub; +STUB SHCreateShellItem_stub; +/*** AUTOGENERATED APILIST DECLARATIONS END ***/ + +#endif diff --git a/apilibs/kexbases/shell32/_shell32_stubs.c b/apilibs/kexbases/shell32/_shell32_stubs.c new file mode 100644 index 0000000..f4dda04 --- /dev/null +++ b/apilibs/kexbases/shell32/_shell32_stubs.c @@ -0,0 +1,25 @@ +/* + * 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. + * + */ + +#include "common.h" + +UNIMPL_FUNC(SHParseDisplayName, 5); +UNIMPL_FUNC(SHCreateShellItem, 4); diff --git a/apilibs/kexbases/version/_version_apilist.c b/apilibs/kexbases/version/_version_apilist.c new file mode 100644 index 0000000..eea8293 --- /dev/null +++ b/apilibs/kexbases/version/_version_apilist.c @@ -0,0 +1,51 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" +#include "kexcoresdk.h" +#include "_version_apilist.h" + +BOOL init_version() +{ + return TRUE; +} + +static const apilib_named_api version_named_apis[] = +{ +/*** AUTOGENERATED APILIST NAMED EXPORTS BEGIN ***/ + DECL_API("GetFileVersionInfoSizeW", GetFileVersionInfoSizeW_new), + DECL_API("GetFileVersionInfoW", GetFileVersionInfoW_new), + DECL_API("VerFindFileW", VerFindFileW_new), + DECL_API("VerInstallFileW", VerInstallFileW_new), + DECL_API("VerLanguageNameW", VerLanguageNameW_new), + DECL_API("VerQueryValueW", VerQueryValueW_new), +/*** AUTOGENERATED APILIST NAMED EXPORTS END ***/ +}; + +#if 0 +static const apilib_unnamed_api version_ordinal_apis[] = +{ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS BEGIN ***/ +/*** AUTOGENERATED APILIST ORDINAL EXPORTS END ***/ +}; +#endif + +const apilib_api_table apitable_version = DECL_TAB("VERSION.DLL", version_named_apis, 0 /*version_ordinal_apis*/); diff --git a/apilibs/kexbases/version/_version_apilist.h b/apilibs/kexbases/version/_version_apilist.h new file mode 100644 index 0000000..45a0560 --- /dev/null +++ b/apilibs/kexbases/version/_version_apilist.h @@ -0,0 +1,40 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#ifndef _VERSION_APILIST_H +#define _VERSION_APILIST_H + +#include "auxdecl.h" +#include "kexcoresdk.h" + +BOOL init_version(); +extern const apilib_api_table apitable_version; + +/*** AUTOGENERATED APILIST DECLARATIONS BEGIN ***/ +DWORD WINAPI GetFileVersionInfoSizeW_new(LPWSTR filenameW, LPDWORD handle); +BOOL WINAPI GetFileVersionInfoW_new(LPWSTR filenameW, DWORD handle, DWORD len, LPVOID data); +DWORD WINAPI VerFindFileW_new(DWORD dwFlags, LPWSTR szFileNameW, LPWSTR szWinDirW, LPWSTR szAppDirW, LPWSTR szCurDirW, PUINT lpuCurDirLenW, LPWSTR szDestDirW, PUINT lpuDestDirLenW); +DWORD WINAPI VerInstallFileW_new(DWORD uFlags, LPWSTR szSrcFileNameW, LPWSTR szDestFileNameW, LPWSTR szSrcDirW, LPWSTR szDestDirW, LPWSTR szCurDirW, LPWSTR szTmpFileW, PUINT lpuTmpFileLenW); +DWORD WINAPI VerLanguageNameW_new(DWORD wLang, LPWSTR szLangW, DWORD nSize); +BOOL WINAPI VerQueryValueW_new(const LPVOID pBlock, LPWSTR lpSubBlockW, LPVOID *lplpBuffer, PUINT puLen); +/*** AUTOGENERATED APILIST DECLARATIONS END ***/ + +#endif diff --git a/apilibs/kexbases/version/universion.c b/apilibs/kexbases/version/universion.c new file mode 100644 index 0000000..47c0fcd --- /dev/null +++ b/apilibs/kexbases/version/universion.c @@ -0,0 +1,161 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include "common.h" + +static const char signature[] = "KxRC"; + +/* MAKE_EXPORT GetFileVersionInfoSizeW_new=GetFileVersionInfoSizeW */ +DWORD WINAPI GetFileVersionInfoSizeW_new(LPWSTR filenameW, LPDWORD handle) +{ + DWORD size; + + file_GetCP(); + file_ALLOC_WtoA(filename); + size = GetFileVersionInfoSizeA(filenameA, handle); + return size * (1 + sizeof(WCHAR)) + 4; +} + +/* MAKE_EXPORT GetFileVersionInfoW_new=GetFileVersionInfoW */ +BOOL WINAPI GetFileVersionInfoW_new(LPWSTR filenameW, DWORD handle, DWORD len, LPVOID data) +{ + DWORD ret; + + file_GetCP(); + file_ALLOC_WtoA(filename); + ret = GetFileVersionInfoA(filenameA, handle, len, data); + if (ret) + { + if (len < (DWORD)(*(WORD*)data * (1 + sizeof(WCHAR)) + 4)) + { + SetLastError(ERROR_INSUFFICIENT_BUFFER); + return FALSE; + } + + memcpy(((char*)data) + *(WORD*)data, signature, 4); + memset(((char*)data) + *(WORD*)data + 4, 0, *(WORD*)data * sizeof(WCHAR)); + } + return ret; +} + +/* MAKE_EXPORT VerFindFileW_new=VerFindFileW */ +DWORD WINAPI VerFindFileW_new(DWORD dwFlags, LPWSTR szFileNameW, LPWSTR szWinDirW, LPWSTR szAppDirW, LPWSTR szCurDirW, PUINT lpuCurDirLenW, LPWSTR szDestDirW, PUINT lpuDestDirLenW) +{ + DWORD ret; + DWORD last_error = GetLastError(); + DWORD result; + UINT CurDirLenA = MAX_PATH; + UINT DestDirLenA = MAX_PATH; + char szCurDirA[MAX_PATH]; + char szDestDirA[MAX_PATH]; + + file_GetCP(); + file_ALLOC_WtoA(szFileName); + file_ALLOC_WtoA(szWinDir); + file_ALLOC_WtoA(szAppDir); + + *szCurDirA = '\0'; + *szDestDirA = '\0'; + + ret = VerFindFileA(dwFlags, szFileNameA, szWinDirA, szAppDirA, szCurDirA, &CurDirLenA, szDestDirA, &DestDirLenA); + + result = file_AtoW(szCurDir, *lpuCurDirLenW); + if (!result) + { + szCurDirW[*lpuCurDirLenW - 1] = 0; + result = file_AtoW(szCurDir, 0); + ret |= VFF_BUFFTOOSMALL; + } + *lpuCurDirLenW = result; + result = file_AtoW(szDestDir, *lpuDestDirLenW); + if (!result) + { + szDestDirW[*lpuDestDirLenW - 1] = 0; + result = file_AtoW(szDestDir, 0); + ret |= VFF_BUFFTOOSMALL; + } + *lpuDestDirLenW = result; + + SetLastError(last_error); + return ret; +} + +/* MAKE_EXPORT VerInstallFileW_new=VerInstallFileW */ +DWORD WINAPI VerInstallFileW_new(DWORD uFlags, LPWSTR szSrcFileNameW, LPWSTR szDestFileNameW, LPWSTR szSrcDirW, LPWSTR szDestDirW, LPWSTR szCurDirW, LPWSTR szTmpFileW, PUINT lpuTmpFileLenW) +{ + DWORD ret; + DWORD last_error = GetLastError(); + DWORD result; + UINT TmpFileLenA = MAX_PATH; + char szTmpFileA[MAX_PATH]; + + file_GetCP(); + file_ALLOC_WtoA(szSrcFileName); + file_ALLOC_WtoA(szDestFileName); + file_ALLOC_WtoA(szSrcDir); + file_ALLOC_WtoA(szDestDir); + file_ALLOC_WtoA(szCurDir); + + *szTmpFileA = '\0'; + + ret = VerInstallFileA(uFlags, szSrcFileNameA, szDestFileNameA, szSrcDirA, szDestDirA, szCurDirA, szTmpFileA, &TmpFileLenA); + + result = file_AtoW(szTmpFile, *lpuTmpFileLenW); + if (!result) + { + szTmpFileW[*lpuTmpFileLenW - 1] = 0; + result = file_AtoW(szTmpFile, 0); + ret |= VIF_BUFFTOOSMALL; + } + *lpuTmpFileLenW = result; + + SetLastError(last_error); + return ret; +} + +/* MAKE_EXPORT VerLanguageNameW_new=VerLanguageNameW */ +DWORD WINAPI VerLanguageNameW_new(DWORD wLang, LPWSTR szLangW, DWORD nSize); /* -> implementation is in kernel32 folder */ + +/* MAKE_EXPORT VerQueryValueW_new=VerQueryValueW */ +BOOL WINAPI VerQueryValueW_new(const LPVOID pBlock, LPWSTR lpSubBlockW, LPVOID *lplpBuffer, PUINT puLen) +{ + BOOL ret; + + if (!pBlock || memcmp((char*)pBlock + *(WORD*)pBlock, signature, 4)) + return FALSE; + + ALLOC_WtoA(lpSubBlock); + ret = VerQueryValueA(pBlock, lpSubBlockA, lplpBuffer, puLen); + if (ret && strcmpi(lpSubBlockA, "\\") && strcmpi(lpSubBlockA, "\\VarFileInfo\\Translation")) + { + WCHAR* lpBlockW = (WCHAR*)((char*)pBlock + *(WORD*)pBlock + 4); + DWORD pos = (char*)*lplpBuffer - (char*)pBlock; + WCHAR* p = lpBlockW + pos; + UINT len = 0; + if (!*p) + len = MultiByteToWideChar(CP_ACP, 0, (char*)*lplpBuffer, -1, p, *(WORD*)pBlock - pos); + else + do len++; while (*p++); + *lplpBuffer = lpBlockW + pos; + *puLen = len; + } + return ret; +} diff --git a/apilibs/settings.reg b/apilibs/settings.reg new file mode 100644 index 0000000..6d79823 --- /dev/null +++ b/apilibs/settings.reg @@ -0,0 +1,40 @@ +REGEDIT4 + +[HKEY_LOCAL_MACHINE\Software\KernelEx\AppSettings] + +[HKEY_LOCAL_MACHINE\Software\KernelEx\AppSettings\Configs] +"*\\UNICOWS.DLL"="DCFG1" +"*\\FIREFOX SETUP 3*.EXE"="WINXP" +"*\\FIREFOX*PRE*.INSTALLER.EXE"="WINXP" +"*\\XUL.DLL"="WINXP" +"*\\INSTALL_FLASH_PLAYER.EXE"="WINXP" +"*\\MFC*U.DLL"="WINXP" +;-Java +"*\\JAVA.EXE"="DCFG1" +"*\\JAVAW.EXE"="DCFG1" + +[HKEY_LOCAL_MACHINE\Software\KernelEx\AppSettings\Flags] +;DISABLE KERNELEX FOR: +;-system files +"*\\KERNEL32.DLL"=dword:00000001 +"*\\SHFOLDER.DLL"=dword:00000001 +"*\\ICMP.DLL"=dword:00000001 +"*\\IPHLPAPI.DLL"=dword:00000001 +"*\\WININET.DLL"=dword:00000001 +"*\\MSHTML.DLL"=dword:00000001 +"*\\SHDOCVW.DLL"=dword:00000001 +"*\\BROWSEUI.DLL"=dword:00000001 +"*\\SHLWAPI.DLL"=dword:00000001 +"*\\MSVCRT.DLL"=dword:00000001 +;-OpenGL drivers +"*\\OPENGL32.DLL"=dword:00000001 +"*\\ATIO9XXX.DLL"=dword:00000001 +"*\\NVOPENGL.DLL"=dword:00000001 +;-PunkBuster +"*\\PBCL.DLL"=dword:00000001 +"*\\PBCLS.DLL"=dword:00000001 +"*\\PBAG.DLL"=dword:00000001 +"*\\PBAGS.DLL"=dword:00000001 +"*\\PBSV.DLL"=dword:00000001 +"*\\PBSVS.DLL"=dword:00000001 + diff --git a/auxiliary/auxiliary.dsp b/auxiliary/auxiliary.dsp new file mode 100644 index 0000000..4892161 --- /dev/null +++ b/auxiliary/auxiliary.dsp @@ -0,0 +1,66 @@ +# Microsoft Developer Studio Project File - Name="auxiliary" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) External Target" 0x0106 + +CFG=auxiliary - Win32 Release +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "auxiliary.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "auxiliary.mak" CFG="auxiliary - Win32 Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "auxiliary - Win32 Release" (based on "Win32 (x86) External Target") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +# PROP BASE Use_MFC +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Cmd_Line "NMAKE /f auxiliary.mak" +# PROP BASE Rebuild_Opt "/a" +# PROP BASE Target_File "auxiliary.exe" +# PROP BASE Bsc_Name "auxiliary.bsc" +# PROP BASE Target_Dir "" +# PROP Use_MFC +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Cmd_Line "nmake /nologo /f makefile.msv ide" +# PROP Rebuild_Opt "/a" +# PROP Target_File "auxiliary" +# PROP Bsc_Name "" +# PROP Target_Dir "" +# Begin Target + +# Name "auxiliary - Win32 Release" + +!IF "$(CFG)" == "auxiliary - Win32 Release" + +!ENDIF + +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/auxiliary/makefile b/auxiliary/makefile new file mode 100644 index 0000000..7354c5c --- /dev/null +++ b/auxiliary/makefile @@ -0,0 +1,20 @@ +all : + @$(MAKE) -C msimg32 $@ + @$(MAKE) -C pdh $@ + @$(MAKE) -C wtsapi32 $@ + @$(MAKE) -C uxtheme $@ + @$(MAKE) -C psapi $@ + +clean : + @$(MAKE) -C msimg32 $@ + @$(MAKE) -C pdh $@ + @$(MAKE) -C wtsapi32 $@ + @$(MAKE) -C uxtheme $@ + @$(MAKE) -C psapi $@ + +realclean : + @$(MAKE) -C msimg32 $@ + @$(MAKE) -C pdh $@ + @$(MAKE) -C wtsapi32 $@ + @$(MAKE) -C uxtheme $@ + @$(MAKE) -C psapi $@ diff --git a/auxiliary/makefile.msv b/auxiliary/makefile.msv new file mode 100644 index 0000000..00ff187 --- /dev/null +++ b/auxiliary/makefile.msv @@ -0,0 +1,36 @@ +all : + cd msimg32 + @$(MAKE) /nologo /f makefile.msv $@ + cd .. + cd pdh + @$(MAKE) /nologo /f makefile.msv $@ + cd .. + cd wtsapi32 + @$(MAKE) /nologo /f makefile.msv $@ + cd .. + cd uxtheme + @$(MAKE) /nologo /f makefile.msv $@ + cd .. + cd psapi + @$(MAKE) /nologo /f makefile.msv $@ + cd .. + +clean : + cd msimg32 + @$(MAKE) /nologo /f makefile.msv $@ + cd .. + cd pdh + @$(MAKE) /nologo /f makefile.msv $@ + cd .. + cd wtsapi32 + @$(MAKE) /nologo /f makefile.msv $@ + cd .. + cd uxtheme + @$(MAKE) /nologo /f makefile.msv $@ + cd .. + cd psapi + @$(MAKE) /nologo /f makefile.msv $@ + cd .. + +ide : all clean + -@if exist Release\NUL rd Release diff --git a/auxiliary/msimg32/makefile b/auxiliary/msimg32/makefile new file mode 100644 index 0000000..e1cb1c2 --- /dev/null +++ b/auxiliary/msimg32/makefile @@ -0,0 +1,42 @@ +# Makefile for GNU C Compiler (GCC) + +CC = gcc +CXX = g++ +RCC = windres +OBJ = msimg32.o +RES = msimgme.o +LIBS = -nostdlib -lkernel32 -lgdi32 +LDFLAGS = -s -shared -Wl,--kill-at -e _DllMain@12 -Wl,--enable-stdcall-fixup +BIN = ..\msimg32.dll +CFLAGS = -O2 -Wall +CXXFLAGS = $(CFLAGS) + +.SUFFIXES: .rc + +all : $(BIN) + +.PHONY : clean +clean : + -@if exist *.o del *.o + -@if exist *.po del *.po + -@if exist *.a del *.a + +realclean : clean + -@if exist $(BIN) del $(BIN) + +$(BIN) : $(OBJ) $(RES) + $(CXX) $(LDFLAGS) -o $(BIN) msimg32.def $(OBJ) $(RES) $(LIBS) + +.c.o : + $(CC) $(CFLAGS) -c -MMD -MF $*.po -o $@ $< + +.cpp.o : + $(CXX) $(CXXFLAGS) -c -MMD -MF $*.po -o $@ $< + +.rc.o : + $(RCC) $< $@ + +.def.a : + dlltool --def $< -l $@ + +-include $(OBJ:.o=.po) diff --git a/auxiliary/msimg32/makefile.msv b/auxiliary/msimg32/makefile.msv new file mode 100644 index 0000000..fe0fdae --- /dev/null +++ b/auxiliary/msimg32/makefile.msv @@ -0,0 +1,32 @@ +# Makefile for Microsoft Visual C++ Compiler (MSVC) + +OBJ = msimg32.obj +RES = msimgme.res +DEF = /DEF:msimg32.def +BIN = ..\msimg32.dll +LIBS = -nodefaultlib kernel32.lib gdi32.lib +LDFLAGS = /DLL /OPT:NOWIN98 /ENTRY:DllMain@12 +CFLAGS = /W3 /O2 /Oi /FD +CXXFLAGS = $(CFLAGS) + +all : $(BIN) + -@if exist $(BIN:.dll=.exp) del $(BIN:.dll=.exp) + -@if exist $(BIN:.dll=.lib) del $(BIN:.dll=.lib) + +.PHONY : clean +clean : + -@if exist *.obj del *.obj + -@if exist *.idb del *.idb + -@if exist *.res del *.res + +realclean : clean + -@if exist $(BIN) del $(BIN) + +$(BIN) : $(OBJ) $(RES) + link /nologo $(LDFLAGS) $(DEF) /OUT:$(BIN) $(LIBS) $(OBJ) $(RES) + +.c.obj : + cl /nologo $(CFLAGS) /c /Fo$@ $< + +.cpp.obj : + cl /nologo $(CXXFLAGS) /c /Fo$@ $< diff --git a/auxiliary/msimg32/msimg32.c b/auxiliary/msimg32/msimg32.c new file mode 100644 index 0000000..ee3e54b --- /dev/null +++ b/auxiliary/msimg32/msimg32.c @@ -0,0 +1,386 @@ +/* + * KernelEx + * Copyright (C) 2008, Tihiy + * Copyright 1993, 1994 Alexandre Julliard + * Copyright 1997 Bertho A. Stultiens + * 1999 Huw D M Davies + * + * 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. + * + */ + +#include +#define INITBITMAPINFO(bInfo,cx,cy) \ + ZeroMemory(&bInfo,sizeof(BITMAPINFO)); \ + bInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); \ + bInfo.bmiHeader.biWidth = cx; \ + bInfo.bmiHeader.biHeight = cy; \ + bInfo.bmiHeader.biPlanes = 1; \ + bInfo.bmiHeader.biBitCount = 32; + +typedef struct tagRGBALPHA { + byte rgbRed; + byte rgbGreen; + byte rgbBlue; + byte rgbReserved; +} RGBALPHA,*PRGBALPHA; + +#ifndef GRADIENT_FILL_RECT_H +#define GRADIENT_FILL_RECT_H 0x00 +#define GRADIENT_FILL_RECT_V 0x01 +#define GRADIENT_FILL_TRIANGLE 0x02 +#define GRADIENT_FILL_OP_FLAG 0xff +#endif + +BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + if (fdwReason == DLL_PROCESS_ATTACH) + DisableThreadLibraryCalls(hinstDLL); + return TRUE; +} + + +BOOL WINAPI AlphaBlend_NEW( HDC hdcDest, // handle to destination DC + int nXOriginDest, // x-coord of upper-left corner + int nYOriginDest, // y-coord of upper-left corner + int nWidthDest, // destination width + int nHeightDest, // destination height + HDC hdcSrc, // handle to source DC + int nXOriginSrc, // x-coord of upper-left corner + int nYOriginSrc, // y-coord of upper-left corner + int nWidthSrc, // source width + int nHeightSrc, // source height + BLENDFUNCTION blendFunction // alpha-blending function +) +{ + unsigned int i, srcalpha, dstalpha; + BITMAPINFO bmi; + HBITMAP srcBM, dstBM, dcBM; + HDC srcDC, dstDC; + PRGBALPHA srcPixel, dstPixel; + INITBITMAPINFO(bmi,nWidthDest,nHeightDest); + + if ( !hdcDest || !hdcSrc || blendFunction.BlendOp != AC_SRC_OVER ) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + if ( !blendFunction.SourceConstantAlpha ) return TRUE; //nothing to do + if ( !blendFunction.AlphaFormat && blendFunction.SourceConstantAlpha == 0xFF ) //no alpha work + return StretchBlt(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc, SRCCOPY ); + + srcBM = CreateDIBSection(hdcSrc, &bmi, DIB_RGB_COLORS, (void*)&srcPixel, NULL, 0); + dstBM = CreateDIBSection(hdcDest, &bmi, DIB_RGB_COLORS, (void*)&dstPixel, NULL, 0); + + if ( !srcBM || !dstBM ) + { + DeleteObject(srcBM); + DeleteObject(dstBM); + return FALSE; + } + //create a copy of source image + srcDC = CreateCompatibleDC(hdcSrc); + dcBM = SelectObject(srcDC, srcBM); + StretchBlt(srcDC, 0, 0, nWidthDest, nHeightDest, hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc, SRCCOPY); + SelectObject(srcDC, dcBM); + DeleteDC(srcDC); //don't need no more + //create a copy of dest image + dstDC = CreateCompatibleDC(hdcDest); + dcBM = SelectObject(dstDC, dstBM); + BitBlt(dstDC, 0, 0, nWidthDest, nHeightDest, hdcDest, nXOriginDest, nYOriginDest, SRCCOPY); + //workwork + if ( !blendFunction.AlphaFormat ) //no alpha channel + { + srcalpha = blendFunction.SourceConstantAlpha; + dstalpha = 255 - srcalpha; + for (i = 0; i < (nWidthDest*nHeightDest); i++) + { + dstPixel->rgbBlue = ( (srcPixel->rgbBlue * srcalpha) + (dstPixel->rgbBlue * dstalpha) ) / 255; + dstPixel->rgbGreen = ( (srcPixel->rgbGreen * srcalpha) + (dstPixel->rgbGreen * dstalpha) ) / 255; + dstPixel->rgbRed = ( (srcPixel->rgbRed * srcalpha) + (dstPixel->rgbRed * dstalpha) ) / 255; + dstPixel->rgbReserved = ( (srcPixel->rgbReserved * srcalpha) + (dstPixel->rgbReserved * dstalpha) ) / 255; + srcPixel++; + dstPixel++; + } + } + else + { + unsigned int tmp; + srcalpha = blendFunction.SourceConstantAlpha; + for (i = 0; i < (nWidthDest*nHeightDest); i++) + { + + dstalpha = 255 - srcPixel->rgbReserved; + tmp = ((srcPixel->rgbRed * srcalpha) + (dstPixel->rgbRed * dstalpha)) / 255; + if (tmp > 255) tmp = 255; + dstPixel->rgbRed = tmp; + tmp = ((srcPixel->rgbGreen * srcalpha) + (dstPixel->rgbGreen * dstalpha)) / 255; + if (tmp > 255) tmp = 255; + dstPixel->rgbGreen = tmp; + tmp = ((srcPixel->rgbBlue * srcalpha) + (dstPixel->rgbBlue * dstalpha)) / 255; + if (tmp > 255) tmp = 255; + dstPixel->rgbBlue = tmp; + tmp = ((srcPixel->rgbReserved * srcalpha) + (dstPixel->rgbReserved * dstalpha)) / 255; + if (tmp > 255) tmp = 255; + dstPixel->rgbReserved = tmp; + srcPixel++; + dstPixel++; + } + } + BitBlt(hdcDest,nXOriginDest,nYOriginDest,nWidthDest,nHeightDest,dstDC,0,0,SRCCOPY); + //destroy stuff we used + SelectObject(dstDC, dcBM); + DeleteDC(dstDC); + DeleteObject(srcBM); + DeleteObject(dstBM); + + return TRUE; +} + +/****************************************************************************** + * GdiGradientFill (GDI32.@) + * + * FIXME: we don't support the Alpha channel properly + */ +BOOL WINAPI GradientFill_NEW( HDC hdc, TRIVERTEX *vert_array, ULONG nvert, + void * grad_array, ULONG ngrad, ULONG mode ) +{ + unsigned int i; + + if ( !hdc || !vert_array || ! grad_array ) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + switch(mode) + { + case GRADIENT_FILL_RECT_H: + for(i = 0; i < ngrad; i++) + { + GRADIENT_RECT *rect = ((GRADIENT_RECT *)grad_array) + i; + TRIVERTEX *v1 = vert_array + rect->UpperLeft; + TRIVERTEX *v2 = vert_array + rect->LowerRight; + int y1 = v1->y < v2->y ? v1->y : v2->y; + int y2 = v2->y > v1->y ? v2->y : v1->y; + int x, dx; + if (v1->x > v2->x) + { + TRIVERTEX *t = v2; + v2 = v1; + v1 = t; + } + dx = v2->x - v1->x; + for (x = 0; x < dx; x++) + { + POINT pts[2]; + HPEN hPen, hOldPen; + + hPen = CreatePen( PS_SOLID, 1, RGB( + (v1->Red * (dx - x) + v2->Red * x) / dx >> 8, + (v1->Green * (dx - x) + v2->Green * x) / dx >> 8, + (v1->Blue * (dx - x) + v2->Blue * x) / dx >> 8)); + hOldPen = SelectObject( hdc, hPen ); + pts[0].x = v1->x + x; + pts[0].y = y1; + pts[1].x = v1->x + x; + pts[1].y = y2; + Polyline( hdc, &pts[0], 2 ); + DeleteObject( SelectObject(hdc, hOldPen ) ); + } + } + break; + case GRADIENT_FILL_RECT_V: + for(i = 0; i < ngrad; i++) + { + GRADIENT_RECT *rect = ((GRADIENT_RECT *)grad_array) + i; + TRIVERTEX *v1 = vert_array + rect->UpperLeft; + TRIVERTEX *v2 = vert_array + rect->LowerRight; + int x1 = v1->x < v2->x ? v1->x : v2->x; + int x2 = v2->x > v1->x ? v2->x : v1->x; + int y, dy; + if (v1->y > v2->y) + { + TRIVERTEX *t = v2; + v2 = v1; + v1 = t; + } + dy = v2->y - v1->y; + for (y = 0; y < dy; y++) + { + POINT pts[2]; + HPEN hPen, hOldPen; + + hPen = CreatePen( PS_SOLID, 1, RGB( + (v1->Red * (dy - y) + v2->Red * y) / dy >> 8, + (v1->Green * (dy - y) + v2->Green * y) / dy >> 8, + (v1->Blue * (dy - y) + v2->Blue * y) / dy >> 8)); + hOldPen = SelectObject( hdc, hPen ); + pts[0].x = x1; + pts[0].y = v1->y + y; + pts[1].x = x2; + pts[1].y = v1->y + y; + Polyline( hdc, &pts[0], 2 ); + DeleteObject( SelectObject(hdc, hOldPen ) ); + } + } + break; + case GRADIENT_FILL_TRIANGLE: + for (i = 0; i < ngrad; i++) + { + GRADIENT_TRIANGLE *tri = ((GRADIENT_TRIANGLE *)grad_array) + i; + TRIVERTEX *v1 = vert_array + tri->Vertex1; + TRIVERTEX *v2 = vert_array + tri->Vertex2; + TRIVERTEX *v3 = vert_array + tri->Vertex3; + int y, dy; + + if (v1->y > v2->y) + { TRIVERTEX *t = v1; v1 = v2; v2 = t; } + if (v2->y > v3->y) + { + TRIVERTEX *t = v2; v2 = v3; v3 = t; + if (v1->y > v2->y) + { t = v1; v1 = v2; v2 = t; } + } + /* v1->y <= v2->y <= v3->y */ + + dy = v3->y - v1->y; + for (y = 0; y < dy; y++) + { + /* v1->y <= y < v3->y */ + TRIVERTEX *v = y < (v2->y - v1->y) ? v1 : v3; + /* (v->y <= y < v2->y) || (v2->y <= y < v->y) */ + int dy2 = v2->y - v->y; + int y2 = y + v1->y - v->y; + + int x1 = (v3->x * y + v1->x * (dy - y )) / dy; + int x2 = (v2->x * y2 + v-> x * (dy2 - y2)) / dy2; + int r1 = (v3->Red * y + v1->Red * (dy - y )) / dy; + int r2 = (v2->Red * y2 + v-> Red * (dy2 - y2)) / dy2; + int g1 = (v3->Green * y + v1->Green * (dy - y )) / dy; + int g2 = (v2->Green * y2 + v-> Green * (dy2 - y2)) / dy2; + int b1 = (v3->Blue * y + v1->Blue * (dy - y )) / dy; + int b2 = (v2->Blue * y2 + v-> Blue * (dy2 - y2)) / dy2; + + int x; + if (x1 < x2) + { + int dx = x2 - x1; + for (x = 0; x < dx; x++) + SetPixel (hdc, x + x1, y + v1->y, RGB( + (r1 * (dx - x) + r2 * x) / dx >> 8, + (g1 * (dx - x) + g2 * x) / dx >> 8, + (b1 * (dx - x) + b2 * x) / dx >> 8)); + } + else + { + int dx = x1 - x2; + for (x = 0; x < dx; x++) + SetPixel (hdc, x + x2, y + v1->y, RGB( + (r2 * (dx - x) + r1 * x) / dx >> 8, + (g2 * (dx - x) + g1 * x) / dx >> 8, + (b2 * (dx - x) + b1 * x) / dx >> 8)); + } + } + } + break; + default: + return FALSE; + } + + return TRUE; +} + +/****************************************************************************** + * GdiTransparentBlt [GDI32.@] + */ +BOOL WINAPI TransparentBlt_NEW( HDC hdcDest, int xDest, int yDest, int widthDest, int heightDest, + HDC hdcSrc, int xSrc, int ySrc, int widthSrc, int heightSrc, + UINT crTransparent ) +{ + BOOL ret = FALSE; + HDC hdcWork; + HBITMAP bmpWork; + HGDIOBJ oldWork; + HDC hdcMask = NULL; + HBITMAP bmpMask = NULL; + HBITMAP oldMask = NULL; + COLORREF oldBackground; + COLORREF oldForeground; + int oldStretchMode; + + if ( !hdcDest || !hdcSrc ) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + if(widthDest < 0 || heightDest < 0 || widthSrc < 0 || heightSrc < 0) { + return FALSE; + } + + oldBackground = SetBkColor(hdcDest, RGB(255,255,255)); + oldForeground = SetTextColor(hdcDest, RGB(0,0,0)); + + /* Stretch bitmap */ + oldStretchMode = GetStretchBltMode(hdcSrc); + if(oldStretchMode == BLACKONWHITE || oldStretchMode == WHITEONBLACK) + SetStretchBltMode(hdcSrc, COLORONCOLOR); + hdcWork = CreateCompatibleDC(hdcDest); + bmpWork = CreateCompatibleBitmap(hdcDest, widthDest, heightDest); + oldWork = SelectObject(hdcWork, bmpWork); + if(!StretchBlt(hdcWork, 0, 0, widthDest, heightDest, hdcSrc, xSrc, ySrc, widthSrc, heightSrc, SRCCOPY)) goto error; + SetBkColor(hdcWork, crTransparent); + + /* Create mask */ + hdcMask = CreateCompatibleDC(hdcDest); + bmpMask = CreateCompatibleBitmap(hdcMask, widthDest, heightDest); + oldMask = SelectObject(hdcMask, bmpMask); + if(!BitBlt(hdcMask, 0, 0, widthDest, heightDest, hdcWork, 0, 0, SRCCOPY)) goto error; + + /* Replace transparent color with black */ + SetBkColor(hdcWork, RGB(0,0,0)); + SetTextColor(hdcWork, RGB(255,255,255)); + if(!BitBlt(hdcWork, 0, 0, widthDest, heightDest, hdcMask, 0, 0, SRCAND)) goto error; + + /* Replace non-transparent area on destination with black */ + if(!BitBlt(hdcDest, xDest, yDest, widthDest, heightDest, hdcMask, 0, 0, SRCAND)) goto error; + + /* Draw the image */ + if(!BitBlt(hdcDest, xDest, yDest, widthDest, heightDest, hdcWork, 0, 0, SRCPAINT)) goto error; + + ret = TRUE; +error: + SetStretchBltMode(hdcSrc, oldStretchMode); + SetBkColor(hdcDest, oldBackground); + SetTextColor(hdcDest, oldForeground); + if(hdcWork) { + SelectObject(hdcWork, oldWork); + DeleteDC(hdcWork); + } + if(bmpWork) DeleteObject(bmpWork); + if(hdcMask) { + SelectObject(hdcMask, oldMask); + DeleteDC(hdcMask); + } + if(bmpMask) DeleteObject(bmpMask); + return ret; +} + +void WINAPI vSetDdrawflag() +{ + return; +} diff --git a/auxiliary/msimg32/msimg32.def b/auxiliary/msimg32/msimg32.def new file mode 100644 index 0000000..8c2399f --- /dev/null +++ b/auxiliary/msimg32/msimg32.def @@ -0,0 +1,8 @@ +LIBRARY msimg32.dll BASE=0x79790000 +EXPORTS + +vSetDdrawflag @1 +AlphaBlend = AlphaBlend_NEW @2 +DllInitialize = DllMain @3 PRIVATE +GradientFill = GradientFill_NEW @4 +TransparentBlt = TransparentBlt_NEW @5 diff --git a/auxiliary/msimg32/msimgme.rc b/auxiliary/msimg32/msimgme.rc new file mode 100644 index 0000000..20125b3 --- /dev/null +++ b/auxiliary/msimg32/msimgme.rc @@ -0,0 +1,26 @@ +1 VERSIONINFO +FILEVERSION 5,0,2218,1 +PRODUCTVERSION 5,0,2218,1 +FILEOS 0x40004 +FILETYPE 0x2 +{ +BLOCK "StringFileInfo" +{ + BLOCK "040904B0" + { + VALUE "CompanyName", "KernelEx" + VALUE "FileDescription", "GDIEXT Client DLL" + VALUE "FileVersion", "5.00.2218.1 (KernelEx special version)" + VALUE "InternalName", "gdiext" + VALUE "LegalCopyright", "Tihiy" + VALUE "OriginalFilename", "gdiext" + VALUE "ProductName", "KernelEx supplementary libraries" + VALUE "ProductVersion", "5.00.2218.1" + } +} + +BLOCK "VarFileInfo" +{ + VALUE "Translation", 0x0409, 0x04B0 +} +} diff --git a/auxiliary/pdh/kord.def b/auxiliary/pdh/kord.def new file mode 100644 index 0000000..d1f1443 --- /dev/null +++ b/auxiliary/pdh/kord.def @@ -0,0 +1,5 @@ +LIBRARY KERNEL32.dll + +EXPORTS + CommonUnimpStub@0 @17 NONAME + diff --git a/auxiliary/pdh/makefile b/auxiliary/pdh/makefile new file mode 100644 index 0000000..b8a807c --- /dev/null +++ b/auxiliary/pdh/makefile @@ -0,0 +1,43 @@ +# Makefile for GNU C Compiler (GCC) + +CC = gcc +CXX = g++ +RCC = windres +OBJ = pdh.o +RES = +DEF = pdh.def +LIBS = kord.a -nostdlib -lkernel32 +LDFLAGS = -s -shared -e _DllMain@12 -Wl,--enable-stdcall-fixup +BIN = ..\pdh.dll +CFLAGS = -Os -Wall +CXXFLAGS = $(CFLAGS) + +.SUFFIXES: .rc + +all : $(BIN) + +.PHONY : clean +clean : + -@if exist *.o del *.o + -@if exist *.po del *.po + -@if exist *.a del *.a + +realclean : clean + -@if exist $(BIN) del $(BIN) + +$(BIN) : $(OBJ) $(RES) kord.a + $(CXX) $(LDFLAGS) -o $(BIN) $(OBJ) $(RES) $(LIBS) $(DEF) + +.c.o : + $(CC) $(CFLAGS) -c -MMD -MF $*.po -o $@ $< + +.cpp.o : + $(CXX) $(CXXFLAGS) -c -MMD -MF $*.po -o $@ $< + +.rc.o : + $(RCC) $< $@ + +.def.a : + dlltool --def $< -l $@ + +-include $(OBJ:.o=.po) diff --git a/auxiliary/pdh/makefile.msv b/auxiliary/pdh/makefile.msv new file mode 100644 index 0000000..8aee83a --- /dev/null +++ b/auxiliary/pdh/makefile.msv @@ -0,0 +1,38 @@ +# Makefile for Microsoft Visual C++ Compiler (MSVC) + +OBJ = kord.lib pdh.obj +RES = +DEF = /DEF:pdh.def +BIN = ..\pdh.dll +LIBS = -nodefaultlib kernel32.lib gdi32.lib +LDFLAGS = /DLL /OPT:NOWIN98 /ENTRY:DllMain@12 +CFLAGS = /W3 /O2 /Oi /FD +CXXFLAGS = $(CFLAGS) + +all : $(BIN) + -@if exist $(BIN:.dll=.exp) del $(BIN:.dll=.exp) + -@if exist $(BIN:.dll=.lib) del $(BIN:.dll=.lib) + +.PHONY : clean +clean : + -@if exist *.obj del *.obj + -@if exist *.idb del *.idb + -@if exist *.res del *.res + -@if exist *.exp del *.exp + -@if exist *.lib del *.lib + +realclean : clean + -@if exist $(BIN) del $(BIN) + +$(BIN) : $(OBJ) $(RES) + link /nologo $(LDFLAGS) $(DEF) /OUT:$(BIN) $(LIBS) $(OBJ) $(RES) + +.c.obj : + cl /nologo $(CFLAGS) /c /Fo$@ $< + +.cpp.obj : + cl /nologo $(CXXFLAGS) /c /Fo$@ $< + +kord.lib : kord.def + link /LIB /NOLOGO /MACHINE:IX86 /DEF:$? /OUT:$@ + diff --git a/auxiliary/pdh/pdh.c b/auxiliary/pdh/pdh.c new file mode 100644 index 0000000..51449a9 --- /dev/null +++ b/auxiliary/pdh/pdh.c @@ -0,0 +1,137 @@ +/* + * KernelEx + * Copyright (C) 2007, 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. + * + */ + +#include + +int WINAPI CommonUnimpStub(void); + +#ifdef __GNUC__ +#define UNIMPL_FUNC(name,params) \ + __asm__( ".text\n" \ + ".globl _" #name "@0\n" \ + "_" #name "_new@0:\n\t" \ + "xor %eax, %eax\n\t" \ + "movb $" #params ", %cl\n\t" \ + "jmp _CommonUnimpStub@0\n\t" \ + ) +#else +#define UNIMPL_FUNC(name,params) \ + int __declspec(naked) __stdcall name() \ + { \ + __asm xor eax,eax \ + __asm mov cl, params \ + __asm jmp CommonUnimpStub \ + } +#endif + +BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + switch (fdwReason) { + case DLL_PROCESS_ATTACH: + { + OSVERSIONINFO osv; + osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&osv); + if (osv.dwMajorVersion < 5) + return FALSE; + DisableThreadLibraryCalls(hinstDLL); + break; + } + case DLL_PROCESS_DETACH: + { + break; + } + } + + return TRUE; +} + +UNIMPL_FUNC(PdhGetDllVersion, 1); +UNIMPL_FUNC(PdhOpenQueryA, 3); +UNIMPL_FUNC(PdhOpenQueryW, 3); +UNIMPL_FUNC(PdhAddCounterA, 4); +UNIMPL_FUNC(PdhAddCounterW, 4); +UNIMPL_FUNC(PdhRemoveCounter, 1); +UNIMPL_FUNC(PdhCollectQueryData, 1); +UNIMPL_FUNC(PdhCloseQuery, 1); +UNIMPL_FUNC(PdhGetFormattedCounterValue, 4); +UNIMPL_FUNC(PdhGetFormattedCounterArrayA, 5); +UNIMPL_FUNC(PdhGetFormattedCounterArrayW, 5); +UNIMPL_FUNC(PdhGetRawCounterValue, 3); +UNIMPL_FUNC(PdhGetRawCounterArrayA, 4); +UNIMPL_FUNC(PdhGetRawCounterArrayW, 4); +UNIMPL_FUNC(PdhCalculateCounterFromRawValue, 5); +UNIMPL_FUNC(PdhComputeCounterStatistics, 6); +UNIMPL_FUNC(PdhGetCounterInfoA, 4); +UNIMPL_FUNC(PdhGetCounterInfoW, 4); +UNIMPL_FUNC(PdhSetCounterScaleFactor, 2); +UNIMPL_FUNC(PdhConnectMachineA, 1); +UNIMPL_FUNC(PdhConnectMachineW, 1); +UNIMPL_FUNC(PdhEnumMachinesA, 3); +UNIMPL_FUNC(PdhEnumMachinesW, 3); +UNIMPL_FUNC(PdhEnumObjectsA, 6); +UNIMPL_FUNC(PdhEnumObjectsW, 6); +UNIMPL_FUNC(PdhEnumObjectItemsA, 9); +UNIMPL_FUNC(PdhEnumObjectItemsW, 9); +UNIMPL_FUNC(PdhMakeCounterPathA, 4); +UNIMPL_FUNC(PdhMakeCounterPathW, 4); +UNIMPL_FUNC(PdhParseCounterPathA, 4); +UNIMPL_FUNC(PdhParseCounterPathW, 4); +UNIMPL_FUNC(PdhParseInstanceNameA, 6); +UNIMPL_FUNC(PdhParseInstanceNameW, 6); +UNIMPL_FUNC(PdhValidatePathA, 1); +UNIMPL_FUNC(PdhValidatePathW, 1); +UNIMPL_FUNC(PdhGetDefaultPerfObjectA, 4); +UNIMPL_FUNC(PdhGetDefaultPerfObjectW, 4); +UNIMPL_FUNC(PdhGetDefaultPerfCounterA, 5); +UNIMPL_FUNC(PdhGetDefaultPerfCounterW, 5); +UNIMPL_FUNC(PdhBrowseCountersA, 1); +UNIMPL_FUNC(PdhBrowseCountersW, 1); +UNIMPL_FUNC(PdhExpandCounterPathA, 3); +UNIMPL_FUNC(PdhExpandCounterPathW, 3); +UNIMPL_FUNC(PdhLookupPerfNameByIndexA, 4); +UNIMPL_FUNC(PdhLookupPerfNameByIndexW, 4); +UNIMPL_FUNC(PdhLookupPerfIndexByNameA, 3); +UNIMPL_FUNC(PdhLookupPerfIndexByNameW, 3); +UNIMPL_FUNC(PdhOpenLogA, 7); +UNIMPL_FUNC(PdhOpenLogW, 7); +UNIMPL_FUNC(PdhUpdateLogA, 2); +UNIMPL_FUNC(PdhUpdateLogW, 2); +UNIMPL_FUNC(PdhGetLogFileSize, 2); +UNIMPL_FUNC(PdhCloseLog, 2); +UNIMPL_FUNC(PdhSelectDataSourceA, 4); +UNIMPL_FUNC(PdhSelectDataSourceW, 4); +UNIMPL_FUNC(PdhIsRealTimeQuery, 1); +UNIMPL_FUNC(PdhSetQueryTimeRange, 2); +UNIMPL_FUNC(PdhGetDataSourceTimeRangeA, 4); +UNIMPL_FUNC(PdhGetDataSourceTimeRangeW, 4); +UNIMPL_FUNC(PdhCollectQueryDataEx, 3); +UNIMPL_FUNC(PdhFormatFromRawValue, 6); +UNIMPL_FUNC(PdhGetCounterTimeBase, 2); +UNIMPL_FUNC(PdhEncodeWmiPathA, 5); +UNIMPL_FUNC(PdhEncodeWmiPathW, 5); +UNIMPL_FUNC(PdhDecodeWmiPathA, 5); +UNIMPL_FUNC(PdhDecodeWmiPathW, 5); +UNIMPL_FUNC(PdhReadRawLogRecord, 4); +UNIMPL_FUNC(PdhLogServiceCommandA, 4); +UNIMPL_FUNC(PdhLogServiceCommandW, 4); +UNIMPL_FUNC(PdhLogServiceControlA, 5); +UNIMPL_FUNC(PdhLogServiceControlW, 5); diff --git a/auxiliary/pdh/pdh.def b/auxiliary/pdh/pdh.def new file mode 100644 index 0000000..6c822f6 --- /dev/null +++ b/auxiliary/pdh/pdh.def @@ -0,0 +1,73 @@ +LIBRARY pdh.dll BASE=0x7D050000 +EXPORTS + PdhGetDllVersion + PdhOpenQueryA + PdhOpenQueryW + PdhAddCounterA + PdhAddCounterW + PdhRemoveCounter + PdhCollectQueryData + PdhCloseQuery + PdhGetFormattedCounterValue + PdhGetFormattedCounterArrayA + PdhGetFormattedCounterArrayW + PdhGetRawCounterValue + PdhGetRawCounterArrayA + PdhGetRawCounterArrayW + PdhCalculateCounterFromRawValue + PdhComputeCounterStatistics + PdhGetCounterInfoA + PdhGetCounterInfoW + PdhSetCounterScaleFactor + PdhConnectMachineA + PdhConnectMachineW + PdhEnumMachinesA + PdhEnumMachinesW + PdhEnumObjectsA + PdhEnumObjectsW + PdhEnumObjectItemsA + PdhEnumObjectItemsW + PdhMakeCounterPathA + PdhMakeCounterPathW + PdhParseCounterPathA + PdhParseCounterPathW + PdhParseInstanceNameA + PdhParseInstanceNameW + PdhValidatePathA + PdhValidatePathW + PdhGetDefaultPerfObjectA + PdhGetDefaultPerfObjectW + PdhGetDefaultPerfCounterA + PdhGetDefaultPerfCounterW + PdhBrowseCountersA + PdhBrowseCountersW + PdhExpandCounterPathA + PdhExpandCounterPathW + PdhLookupPerfNameByIndexA + PdhLookupPerfNameByIndexW + PdhLookupPerfIndexByNameA + PdhLookupPerfIndexByNameW + PdhOpenLogA + PdhOpenLogW + PdhUpdateLogA + PdhUpdateLogW + PdhGetLogFileSize + PdhCloseLog + PdhSelectDataSourceA + PdhSelectDataSourceW + PdhIsRealTimeQuery + PdhSetQueryTimeRange + PdhGetDataSourceTimeRangeA + PdhGetDataSourceTimeRangeW + PdhCollectQueryDataEx + PdhFormatFromRawValue + PdhGetCounterTimeBase + PdhEncodeWmiPathA + PdhEncodeWmiPathW + PdhDecodeWmiPathA + PdhDecodeWmiPathW + PdhReadRawLogRecord + PdhLogServiceCommandA + PdhLogServiceCommandW + PdhLogServiceControlA + PdhLogServiceControlW diff --git a/auxiliary/psapi/makefile b/auxiliary/psapi/makefile new file mode 100644 index 0000000..0d78dd6 --- /dev/null +++ b/auxiliary/psapi/makefile @@ -0,0 +1,43 @@ +# Makefile for GNU C Compiler (GCC) + +CC = gcc +CXX = g++ +RCC = windres +OBJ = psapi.o +RES = +DEF = psapi.def +LIBS = -nostdlib -lkernel32 +LDFLAGS = -s -shared -Wl,--enable-stdcall-fixup -e _DllMain@12 +BIN = ..\psapi.dll +CFLAGS = -Os -Wall +CXXFLAGS = $(CFLAGS) + +.SUFFIXES: .rc + +all : $(BIN) + +.PHONY : clean +clean : + -@if exist *.o del *.o + -@if exist *.po del *.po + -@if exist *.a del *.a + +realclean : clean + -@if exist $(BIN) del $(BIN) + +$(BIN) : $(OBJ) $(RES) + $(CXX) $(LDFLAGS) -o $(BIN) $(OBJ) $(RES) $(DEF) $(LIBS) + +.c.o : + $(CC) $(CFLAGS) -c -MMD -MF $*.po -o $@ $< + +.cpp.o : + $(CXX) $(CXXFLAGS) -c -MMD -MF $*.po -o $@ $< + +.rc.o : + $(RCC) $< $@ + +.def.a : + dlltool --def $< -l $@ + +-include $(OBJ:.o=.po) diff --git a/auxiliary/psapi/makefile.msv b/auxiliary/psapi/makefile.msv new file mode 100644 index 0000000..cf28de3 --- /dev/null +++ b/auxiliary/psapi/makefile.msv @@ -0,0 +1,32 @@ +# Makefile for Microsoft Visual C++ Compiler (MSVC) + +OBJ = psapi.obj +RES = +DEF = /DEF:psapi.def +BIN = ..\psapi.dll +LIBS = -nodefaultlib kernel32.lib +LDFLAGS = /DLL /OPT:NOWIN98 /ENTRY:DllMain@12 +CFLAGS = /W3 /O2 /Oi /FD +CXXFLAGS = $(CFLAGS) + +all : $(BIN) + -@if exist $(BIN:.dll=.exp) del $(BIN:.dll=.exp) + -@if exist $(BIN:.dll=.lib) del $(BIN:.dll=.lib) + +.PHONY : clean +clean : + -@if exist *.obj del *.obj + -@if exist *.idb del *.idb + -@if exist *.res del *.res + +realclean : clean + -@if exist $(BIN) del $(BIN) + +$(BIN) : $(OBJ) $(RES) + link /nologo $(LDFLAGS) $(DEF) /OUT:$(BIN) $(LIBS) $(OBJ) $(RES) + +.c.obj : + cl /nologo $(CFLAGS) /c /Fo$@ $< + +.cpp.obj : + cl /nologo $(CXXFLAGS) /c /Fo$@ $< diff --git a/auxiliary/psapi/psapi.c b/auxiliary/psapi/psapi.c new file mode 100644 index 0000000..4113941 --- /dev/null +++ b/auxiliary/psapi/psapi.c @@ -0,0 +1,348 @@ +/* + * KernelEx + * Copyright (C) 2008, Tihiy + * + * 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. + * + */ + +#include +#include + +BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + if (fdwReason == DLL_PROCESS_ATTACH) + DisableThreadLibraryCalls(hinstDLL); + return TRUE; +} + + +DWORD WINAPI GetProcessFlags( + HANDLE ProcessID +) +{ + typedef DWORD (WINAPI *GPF) (HANDLE ProcessID); + static GPF g_GetProcessFlags = 0; + + if ( !g_GetProcessFlags ) g_GetProcessFlags = (GPF) GetProcAddress(GetModuleHandle("kernel32.dll"),"GetProcessFlags"); + return g_GetProcessFlags(ProcessID); +} + +/* Retrieves the process identifier of the specified process. +dumb facts: +- most reliable relative code ever +- yes, kernel32 on XP+ does export this function. we make 98 too :p */ + +DWORD WINAPI GetProcessId( + HANDLE hProcess +) +{ + typedef DWORD (WINAPI *MPH) (HANDLE hProcess); + static MPH MapProcessHandle = 0; + + if (!MapProcessHandle) + { + DWORD *faddr; + DWORD addr; + + faddr = (DWORD *) ( (DWORD)GetProcAddress(GetModuleHandle("kernel32.dll"),"SetFilePointer") + 0x1D ); //there is jmp _SetFilePointer + addr = (DWORD) faddr + *faddr + 4 - 0x16; //0x16 bytes before _SetFilePointer there is MapProcessHandle, just what we need + faddr = (DWORD *) addr; + if (*faddr != 0x206A006A) return FALSE; //push 0; push 0x20 + MapProcessHandle = (MPH) addr; + } + return MapProcessHandle(hProcess); +} + +/* Enumerate processes in the system into array. +dumb facts: +- uses byte size instead of dword +- checks output buffers for access */ + +BOOL WINAPI EnumProcesses( + DWORD *pProcessIds, + DWORD cb, + DWORD *pBytesReturned +) +{ + PROCESSENTRY32 oneprocess; + HANDLE hSnap; + if ( cb < sizeof(DWORD) ) return FALSE; + cb = cb & ~sizeof(DWORD); //you don't want to get a quarter of a process + if ( IsBadWritePtr(pProcessIds,sizeof(DWORD)) || IsBadWritePtr(pBytesReturned,sizeof(DWORD)) ) + { + SetLastError(ERROR_NOACCESS); + return FALSE; + } + hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); + if (hSnap == INVALID_HANDLE_VALUE) return FALSE; + oneprocess.dwSize = sizeof(PROCESSENTRY32); + if ( Process32First(hSnap, &oneprocess) ) + { + *pProcessIds = oneprocess.th32ProcessID; + pProcessIds++; + *pBytesReturned = sizeof(DWORD); + while ( Process32Next(hSnap, &oneprocess) && *pBytesReturned*lpcbNeeded) + { + if ( onemodule.th32ModuleID == ProcessModuleID ) + { + //current element gets first value, first gets current + *lphModule = *lphModuleStart; + *lphModuleStart = onemodule.hModule; + } + else + *lphModule = onemodule.hModule; + + lphModule++; + } + else + if ( onemodule.th32ModuleID == ProcessModuleID ) *lphModuleStart = onemodule.hModule; + + *lpcbNeeded += sizeof(DWORD); + lRet = Module32Next(hSnap, &onemodule); + } + CloseHandle(hSnap); + return TRUE; +} + +/* find module/process full/short path in ansi/unicode */ +static DWORD WINAPI GetModuleSuperName( + HANDLE hProcess, + HMODULE hModule, + LPTSTR lpFilename, + DWORD nSize, + BOOL fUnicode, + BOOL fFullName +) +{ + MODULEENTRY32 onemodule; + DWORD pid; + DWORD ProcessModuleID = 0; + HANDLE hSnap; + LPCSTR ModuleName; + + if ( !lpFilename || !nSize ) return FALSE; + pid = GetProcessId(hProcess); + onemodule.dwSize = sizeof(MODULEENTRY32); + if ( !hModule ) + { + hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPPROCESS,pid); + if ( hSnap == INVALID_HANDLE_VALUE ) return FALSE; + ProcessModuleID = FindProcessMID(hSnap,pid); + if ( !ProcessModuleID ) + { + CloseHandle(hSnap); + SetLastError(ERROR_INVALID_HANDLE); + return FALSE; + } + } + else + { + hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,pid); + } + if ( hSnap == INVALID_HANDLE_VALUE ) return FALSE; + + Module32First(hSnap,&onemodule); + while ( onemodule.hModule != hModule && onemodule.th32ModuleID != ProcessModuleID ) + { + if ( !Module32Next(hSnap, &onemodule) ) //not found + { + CloseHandle(hSnap); + return FALSE; + } + } + CloseHandle(hSnap); + ModuleName = fFullName ? onemodule.szExePath : onemodule.szModule; + if ( fUnicode ) + return MultiByteToWideChar(CP_ACP,0,ModuleName,MAX_MODULE_NAME32,(LPWSTR)lpFilename,nSize); + else + { + int maxLen = ( nSize > MAX_MODULE_NAME32 ) ? MAX_MODULE_NAME32 : nSize; + lstrcpynA(lpFilename,ModuleName,maxLen); + return maxLen; + } +} + +DWORD WINAPI GetModuleBaseNameA( + HANDLE hProcess, + HMODULE hModule, + LPCSTR lpBaseName, + DWORD nSize +) +{ + return GetModuleSuperName(hProcess,hModule,(LPTSTR)lpBaseName,nSize,FALSE,FALSE); +} + +DWORD WINAPI GetModuleBaseNameW( + HANDLE hProcess, + HMODULE hModule, + LPWSTR lpBaseName, + DWORD nSize +) +{ + return GetModuleSuperName(hProcess,hModule,(LPTSTR)lpBaseName,nSize,TRUE,FALSE); +} + +DWORD WINAPI GetModuleFileNameExA( + HANDLE hProcess, + HMODULE hModule, + LPCSTR lpBaseName, + DWORD nSize +) +{ + return GetModuleSuperName(hProcess,hModule,(LPTSTR)lpBaseName,nSize,FALSE,TRUE); +} + +DWORD WINAPI GetModuleFileNameExW( + HANDLE hProcess, + HMODULE hModule, + LPWSTR lpBaseName, + DWORD nSize +) +{ + return GetModuleSuperName(hProcess,hModule,(LPTSTR)lpBaseName,nSize,TRUE,TRUE); +} + +/* BUGBUG those should return NT device path */ +DWORD WINAPI GetProcessImageFileNameA( + HANDLE hProcess, + LPCSTR lpImageFileName, + DWORD nSize +) +{ + return GetModuleSuperName(hProcess,NULL,(LPTSTR)lpImageFileName,nSize,FALSE,TRUE); +} + +DWORD WINAPI GetProcessImageFileNameW( + HANDLE hProcess, + LPWSTR lpImageFileName, + DWORD nSize +) +{ + return GetModuleSuperName(hProcess,NULL,(LPTSTR)lpImageFileName,nSize,TRUE,TRUE); +} + + +//rewrite those somehow, please... +BOOL WINAPI GetProcessMemoryInfo( + HANDLE Process, + DWORD ppsmemCounters, + DWORD cb +) +{ + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} + +BOOL WINAPI QueryWorkingSet( HANDLE process, LPVOID buffer, DWORD size ) +{ + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} + +BOOL WINAPI QueryWorkingSetEx( HANDLE process, LPVOID buffer, DWORD size ) +{ + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} + +BOOL WINAPI InitializeProcessForWsWatch( HANDLE hProcess ) +{ + return TRUE; +} + +BOOL WINAPI EnumPageFilesA( PVOID callback, LPVOID context ) +{ + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} + +BOOL WINAPI EnumPageFilesW( PVOID callback, LPVOID context ) +{ + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} diff --git a/auxiliary/psapi/psapi.def b/auxiliary/psapi/psapi.def new file mode 100644 index 0000000..6bd8490 --- /dev/null +++ b/auxiliary/psapi/psapi.def @@ -0,0 +1,18 @@ +LIBRARY psapi.dll BASE=0x7D020000 +EXPORTS + GetProcessFlags + GetProcessId + EnumProcesses + EnumProcessModules + GetModuleBaseNameA + GetModuleBaseNameW + GetModuleFileNameExA + GetModuleFileNameExW + GetProcessImageFileNameA + GetProcessImageFileNameW + GetProcessMemoryInfo + QueryWorkingSet + QueryWorkingSetEx + InitializeProcessForWsWatch + EnumPageFilesA + EnumPageFilesW diff --git a/auxiliary/uxtheme/kord.def b/auxiliary/uxtheme/kord.def new file mode 100644 index 0000000..d1f1443 --- /dev/null +++ b/auxiliary/uxtheme/kord.def @@ -0,0 +1,5 @@ +LIBRARY KERNEL32.dll + +EXPORTS + CommonUnimpStub@0 @17 NONAME + diff --git a/auxiliary/uxtheme/makefile b/auxiliary/uxtheme/makefile new file mode 100644 index 0000000..85c9e36 --- /dev/null +++ b/auxiliary/uxtheme/makefile @@ -0,0 +1,43 @@ +# Makefile for GNU C Compiler (GCC) + +CC = gcc +CXX = g++ +RCC = windres +OBJ = uxtheme.o +RES = +DEF = uxtheme.def +LIBS = kord.a -nostdlib -lkernel32 +LDFLAGS = -s -shared -Wl,--enable-stdcall-fixup -e _DllMain@12 +BIN = ..\uxtheme.dll +CFLAGS = -Os -Wall +CXXFLAGS = $(CFLAGS) + +.SUFFIXES: .rc + +all : $(BIN) + +.PHONY : clean +clean : + -@if exist *.o del *.o + -@if exist *.po del *.po + -@if exist *.a del *.a + +realclean : clean + -@if exist $(BIN) del $(BIN) + +$(BIN) : $(OBJ) $(RES) kord.a + $(CXX) $(LDFLAGS) -o $(BIN) $(OBJ) $(RES) $(LIBS) $(DEF) + +.c.o : + $(CC) $(CFLAGS) -c -MMD -MF $*.po -o $@ $< + +.cpp.o : + $(CXX) $(CXXFLAGS) -c -MMD -MF $*.po -o $@ $< + +.rc.o : + $(RCC) $< $@ + +.def.a : + dlltool --def $< -l $@ + +-include $(OBJ:.o=.po) diff --git a/auxiliary/uxtheme/makefile.msv b/auxiliary/uxtheme/makefile.msv new file mode 100644 index 0000000..1c17c6b --- /dev/null +++ b/auxiliary/uxtheme/makefile.msv @@ -0,0 +1,38 @@ +# Makefile for Microsoft Visual C++ Compiler (MSVC) + +OBJ = kord.lib uxtheme.obj +RES = +DEF = /DEF:uxtheme.def +BIN = ..\uxtheme.dll +LIBS = -nodefaultlib kernel32.lib gdi32.lib +LDFLAGS = /DLL /OPT:NOWIN98 /ENTRY:DllMain@12 +CFLAGS = /W3 /O2 /Oi /FD +CXXFLAGS = $(CFLAGS) + +all : $(BIN) + -@if exist $(BIN:.dll=.exp) del $(BIN:.dll=.exp) + -@if exist $(BIN:.dll=.lib) del $(BIN:.dll=.lib) + +.PHONY : clean +clean : + -@if exist *.obj del *.obj + -@if exist *.idb del *.idb + -@if exist *.res del *.res + -@if exist *.exp del *.exp + -@if exist *.lib del *.lib + +realclean : clean + -@if exist $(BIN) del $(BIN) + +$(BIN) : $(OBJ) $(RES) + link /nologo $(LDFLAGS) $(DEF) /OUT:$(BIN) $(LIBS) $(OBJ) $(RES) + +.c.obj : + cl /nologo $(CFLAGS) /c /Fo$@ $< + +.cpp.obj : + cl /nologo $(CXXFLAGS) /c /Fo$@ $< + +kord.lib : kord.def + link /LIB /NOLOGO /MACHINE:IX86 /DEF:$? /OUT:$@ + diff --git a/auxiliary/uxtheme/uxtheme.c b/auxiliary/uxtheme/uxtheme.c new file mode 100644 index 0000000..0423a62 --- /dev/null +++ b/auxiliary/uxtheme/uxtheme.c @@ -0,0 +1,106 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#include + +int WINAPI CommonUnimpStub(void); + +#ifdef __GNUC__ +#define UNIMPL_FUNC(name,params) \ + __asm__( ".text\n" \ + ".globl _" #name "@0\n" \ + "_" #name "_new@0:\n\t" \ + "xor %eax, %eax\n\t" \ + "movb $" #params ", %cl\n\t" \ + "jmp _CommonUnimpStub@0\n\t" \ + ) +#else +#define UNIMPL_FUNC(name,params) \ + int __declspec(naked) __stdcall name() \ + { \ + __asm xor eax,eax \ + __asm mov cl, params \ + __asm jmp CommonUnimpStub \ + } +#endif + +BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + if (fdwReason == DLL_PROCESS_ATTACH) + { + OSVERSIONINFO osv; + osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&osv); + if (osv.dwMajorVersion < 5 || osv.dwMinorVersion < 1) + return FALSE; + DisableThreadLibraryCalls(hinstDLL); + } + return TRUE; +} + +UNIMPL_FUNC(CloseThemeData, 1); +UNIMPL_FUNC(DrawThemeBackground, 6); +UNIMPL_FUNC(DrawThemeBackgroundEx, 6); +UNIMPL_FUNC(DrawThemeEdge, 8); +UNIMPL_FUNC(DrawThemeIcon, 7); +UNIMPL_FUNC(DrawThemeParentBackground, 3); +UNIMPL_FUNC(DrawThemeText, 9); +UNIMPL_FUNC(EnableThemeDialogTexture, 2); +UNIMPL_FUNC(EnableTheming, 1); +UNIMPL_FUNC(GetCurrentThemeName, 6); +UNIMPL_FUNC(GetThemeAppProperties, 0); +UNIMPL_FUNC(GetThemeBackgroundContentRect, 6); +UNIMPL_FUNC(GetThemeBackgroundExtent, 6); +UNIMPL_FUNC(GetThemeBackgroundRegion, 6); +UNIMPL_FUNC(GetThemeBool, 5); +UNIMPL_FUNC(GetThemeColor, 5); +UNIMPL_FUNC(GetThemeDocumentationProperty, 4); +UNIMPL_FUNC(GetThemeEnumValue, 5); +UNIMPL_FUNC(GetThemeFilename, 6); +UNIMPL_FUNC(GetThemeFont, 6); +UNIMPL_FUNC(GetThemeInt, 5); +UNIMPL_FUNC(GetThemeIntList, 5); +UNIMPL_FUNC(GetThemeMargins, 7); +UNIMPL_FUNC(GetThemeMetric, 6); +UNIMPL_FUNC(GetThemePartSize, 7); +UNIMPL_FUNC(GetThemePosition, 5); +UNIMPL_FUNC(GetThemePropertyOrigin, 5); +UNIMPL_FUNC(GetThemeRect, 5); +UNIMPL_FUNC(GetThemeString, 6); +UNIMPL_FUNC(GetThemeSysBool, 2); +UNIMPL_FUNC(GetThemeSysColor, 2); +UNIMPL_FUNC(GetThemeSysColorBrush, 2); +UNIMPL_FUNC(GetThemeSysFont, 3); +UNIMPL_FUNC(GetThemeSysInt, 3); +UNIMPL_FUNC(GetThemeSysSize, 2); +UNIMPL_FUNC(GetThemeSysString, 4); +UNIMPL_FUNC(GetThemeTextExtent, 9); +UNIMPL_FUNC(GetThemeTextMetrics, 5); +UNIMPL_FUNC(GetWindowTheme, 1); +UNIMPL_FUNC(HitTestThemeBackground, 10); +UNIMPL_FUNC(IsAppThemed, 0); +UNIMPL_FUNC(IsThemeActive, 0); +UNIMPL_FUNC(IsThemeBackgroundPartiallyTransparent, 3); +UNIMPL_FUNC(IsThemeDialogTextureEnabled, 1); +UNIMPL_FUNC(IsThemePartDefined, 3); +UNIMPL_FUNC(OpenThemeData, 2); +UNIMPL_FUNC(SetThemeAppProperties, 1); +UNIMPL_FUNC(SetWindowTheme, 3); diff --git a/auxiliary/uxtheme/uxtheme.def b/auxiliary/uxtheme/uxtheme.def new file mode 100644 index 0000000..9228913 --- /dev/null +++ b/auxiliary/uxtheme/uxtheme.def @@ -0,0 +1,50 @@ +LIBRARY uxtheme.dll BASE=0x7D030000 +EXPORTS + CloseThemeData + DrawThemeBackground + DrawThemeBackgroundEx + DrawThemeEdge + DrawThemeIcon + DrawThemeParentBackground + DrawThemeText + EnableThemeDialogTexture + EnableTheming + GetCurrentThemeName + GetThemeAppProperties + GetThemeBackgroundContentRect + GetThemeBackgroundExtent + GetThemeBackgroundRegion + GetThemeBool + GetThemeColor + GetThemeDocumentationProperty + GetThemeEnumValue + GetThemeFilename + GetThemeFont + GetThemeInt + GetThemeIntList + GetThemeMargins + GetThemeMetric + GetThemePartSize + GetThemePosition + GetThemePropertyOrigin + GetThemeRect + GetThemeString + GetThemeSysBool + GetThemeSysColor + GetThemeSysColorBrush + GetThemeSysFont + GetThemeSysInt + GetThemeSysSize + GetThemeSysString + GetThemeTextExtent + GetThemeTextMetrics + GetWindowTheme + HitTestThemeBackground + IsAppThemed + IsThemeActive + IsThemeBackgroundPartiallyTransparent + IsThemeDialogTextureEnabled + IsThemePartDefined + OpenThemeData + SetThemeAppProperties + SetWindowTheme diff --git a/auxiliary/wtsapi32/makefile b/auxiliary/wtsapi32/makefile new file mode 100644 index 0000000..e979123 --- /dev/null +++ b/auxiliary/wtsapi32/makefile @@ -0,0 +1,43 @@ +# Makefile for GNU C Compiler (GCC) + +CC = gcc +CXX = g++ +RCC = windres +OBJ = wtsapi32.o +RES = +LIBS = +DEF = wtsapi32.def +LDFLAGS = -s -shared -Wl,--kill-at +BIN = ..\wtsapi32.dll +CFLAGS = -Os -Wall +CXXFLAGS = $(CFLAGS) + +.SUFFIXES: .rc + +all : $(BIN) + +.PHONY : clean +clean : + -@if exist *.o del *.o + -@if exist *.po del *.po + -@if exist *.a del *.a + +realclean : clean + -@if exist $(BIN) del $(BIN) + +$(BIN) : $(OBJ) $(RES) + $(CXX) $(LDFLAGS) -o $(BIN) $(OBJ) $(RES) $(LIBS) $(DEF) + +.c.o : + $(CC) $(CFLAGS) -c -MMD -MF $*.po -o $@ $< + +.cpp.o : + $(CXX) $(CXXFLAGS) -c -MMD -MF $*.po -o $@ $< + +.rc.o : + $(RCC) $< $@ + +.def.a : + dlltool --def $< -l $@ + +-include $(OBJ:.o=.po) diff --git a/auxiliary/wtsapi32/makefile.msv b/auxiliary/wtsapi32/makefile.msv new file mode 100644 index 0000000..17a302a --- /dev/null +++ b/auxiliary/wtsapi32/makefile.msv @@ -0,0 +1,33 @@ +# Makefile for Microsoft Visual C++ Compiler (MSVC) + +OBJ = wtsapi32.obj +RES = +DEF = /DEF:wtsapi32.def +BIN = ..\wtsapi32.dll +LIBS = -nodefaultlib kernel32.lib gdi32.lib +LDFLAGS = /DLL /OPT:NOWIN98 /ENTRY:DllMain@12 +CFLAGS = /W3 /O2 /Oi /FD +CXXFLAGS = $(CFLAGS) + +all : $(BIN) + -@if exist $(BIN:.dll=.exp) del $(BIN:.dll=.exp) + -@if exist $(BIN:.dll=.lib) del $(BIN:.dll=.lib) + +.PHONY : clean +clean : + -@if exist *.obj del *.obj + -@if exist *.idb del *.idb + -@if exist *.res del *.res + +realclean : clean + -@if exist $(BIN) del $(BIN) + +$(BIN) : $(OBJ) $(RES) + link /nologo $(LDFLAGS) $(DEF) /OUT:$(BIN) $(LIBS) $(OBJ) $(RES) + +.c.obj : + cl /nologo $(CFLAGS) /c /Fo$@ $< + +.cpp.obj : + cl /nologo $(CXXFLAGS) /c /Fo$@ $< + diff --git a/auxiliary/wtsapi32/wtsapi32.c b/auxiliary/wtsapi32/wtsapi32.c new file mode 100644 index 0000000..f4e2db3 --- /dev/null +++ b/auxiliary/wtsapi32/wtsapi32.c @@ -0,0 +1,343 @@ +/* Copyright 2007 Xeno86 + * Copyright 2005 Ulrich Czekalla + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +//#include "config.h" +#include +#include +#include +/*#include "windef.h" +#include "winbase.h"*/ +#include "wtsapi32.h" +//#include "wine/debug.h" +#include + +#ifdef _MSC_VER + +#define TRACE() +#define FIXME() + +#else + +#define TRACE(x,args...) debug_output(__func__,x,args) +#define FIXME(x,args...) TRACE("FIXME: "x,args) + +#endif + +//WINE_DEFAULT_DEBUG_CHANNEL(wtsapi); +static const char* debugstr_a(const char* a) +{ + return a; +} + +static const char* debugstr_w(const wchar_t* w) +{ + static char a[256]; + WideCharToMultiByte(CP_ACP, 0, w, -1, a, sizeof(a), NULL, NULL); + return a; +} + +static void debug_output(const char* func, const char* fmt, ...) +{ + va_list args; + char buf[200]; + + va_start(args, fmt); + strcpy(buf, func); + strcat(buf, ": "); + vsprintf(buf + strlen(buf), fmt, args); + va_end(args); + OutputDebugStringA(buf); +} + +static HMODULE WTSAPI32_hModule = 0; + +BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + TRACE("%p,%lx,%p\n", hinstDLL, fdwReason, lpvReserved); + + switch (fdwReason) { + case DLL_PROCESS_ATTACH: + { + OSVERSIONINFO osv; + osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&osv); + if (osv.dwMajorVersion < 5) + return FALSE; + DisableThreadLibraryCalls(hinstDLL); + WTSAPI32_hModule = hinstDLL; + break; + } + case DLL_PROCESS_DETACH: + { + break; + } + } + + return TRUE; +} + +/************************************************************ + * WTSCloseServer (WTSAPI32.@) + */ +void WINAPI WTSCloseServer(HANDLE hServer) +{ + FIXME("Stub %p\n", hServer); +} + +/************************************************************ + * WTSDisconnectSession (WTSAPI32.@) + */ +BOOL WINAPI WTSDisconnectSession(HANDLE hServer, DWORD SessionId, BOOL bWait) +{ + FIXME("Stub %p 0x%08lx %d\n", hServer, SessionId, bWait); + return TRUE; +} + +/************************************************************ + * WTSEnumerateProcessesA (WTSAPI32.@) + */ +BOOL WINAPI WTSEnumerateProcessesA(HANDLE hServer, DWORD Reserved, DWORD Version, + PWTS_PROCESS_INFOA* ppProcessInfo, DWORD* pCount) +{ + FIXME("Stub %p 0x%08lx 0x%08lx %p %p\n", hServer, Reserved, Version, + ppProcessInfo, pCount); + + if (!ppProcessInfo || !pCount) return FALSE; + + *pCount = 0; + *ppProcessInfo = NULL; + + return TRUE; +} + +/************************************************************ + * WTSEnumerateProcessesW (WTSAPI32.@) + */ +BOOL WINAPI WTSEnumerateProcessesW(HANDLE hServer, DWORD Reserved, DWORD Version, + PWTS_PROCESS_INFOW* ppProcessInfo, DWORD* pCount) +{ + FIXME("Stub %p 0x%08lx 0x%08lx %p %p\n", hServer, Reserved, Version, + ppProcessInfo, pCount); + + if (!ppProcessInfo || !pCount) return FALSE; + + *pCount = 0; + *ppProcessInfo = NULL; + + return TRUE; +} + +/************************************************************ + * WTSEnumerateServersA (WTSAPI32.@) + */ +BOOL WINAPI WTSEnumerateServersA(LPSTR pDomainName, DWORD Reserved, DWORD Version, + PWTS_SERVER_INFOA* ppServerInfo, DWORD* pCount) +{ + FIXME("Stub %s 0x%08lx 0x%08lx %p %p\n", debugstr_a(pDomainName), Reserved, Version, + ppServerInfo, pCount); + + if (!ppServerInfo || !pCount) return FALSE; + + *pCount = 0; + *ppServerInfo = NULL; + + return TRUE; +} + +/************************************************************ + * WTSEnumerateServersW (WTSAPI32.@) + */ +BOOL WINAPI WTSEnumerateServersW(LPWSTR pDomainName, DWORD Reserved, DWORD Version, + PWTS_SERVER_INFOW* ppServerInfo, DWORD* pCount) +{ + FIXME("Stub %s 0x%08lx 0x%08lx %p %p\n", debugstr_w(pDomainName), Reserved, Version, + ppServerInfo, pCount); + + if (!ppServerInfo || !pCount) return FALSE; + + *pCount = 0; + *ppServerInfo = NULL; + + return TRUE; +} + +/************************************************************ + * WTSEnumerateEnumerateSessionsA (WTSAPI32.@) + */ +BOOL WINAPI WTSEnumerateSessionsA(HANDLE hServer, DWORD Reserved, DWORD Version, + PWTS_SESSION_INFOA* ppSessionInfo, DWORD* pCount) +{ + FIXME("Stub %p 0x%08lx 0x%08lx %p %p\n", hServer, Reserved, Version, + ppSessionInfo, pCount); + + if (!ppSessionInfo || !pCount) return FALSE; + + *pCount = 0; + *ppSessionInfo = NULL; + + return TRUE; +} + +/************************************************************ + * WTSEnumerateEnumerateSessionsW (WTSAPI32.@) + */ +BOOL WINAPI WTSEnumerateSessionsW(HANDLE hServer, DWORD Reserved, DWORD Version, + PWTS_SESSION_INFOW* ppSessionInfo, DWORD* pCount) +{ + FIXME("Stub %p 0x%08lx 0x%08lx %p %p\n", hServer, Reserved, Version, + ppSessionInfo, pCount); + + if (!ppSessionInfo || !pCount) return FALSE; + + *pCount = 0; + *ppSessionInfo = NULL; + + return TRUE; +} + +/************************************************************ + * WTSFreeMemory (WTSAPI32.@) + */ +void WINAPI WTSFreeMemory(PVOID pMemory) +{ + FIXME("Stub %p\n", pMemory); + return; +} + +/************************************************************ + * WTSOpenServerA (WTSAPI32.@) + */ +HANDLE WINAPI WTSOpenServerA(LPSTR pServerName) +{ + FIXME("(%s) stub\n", debugstr_a(pServerName)); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return NULL; +} + +/************************************************************ + * WTSOpenServerW (WTSAPI32.@) + */ +HANDLE WINAPI WTSOpenServerW(LPWSTR pServerName) +{ + FIXME("(%s) stub\n", debugstr_w(pServerName)); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return NULL; +} + +/************************************************************ + * WTSQuerySessionInformationA (WTSAPI32.@) + */ +BOOL WINAPI WTSQuerySessionInformationA( + HANDLE hServer, + DWORD SessionId, + WTS_INFO_CLASS WTSInfoClass, + LPSTR* Buffer, + DWORD* BytesReturned) +{ + /* FIXME: Forward request to winsta.dll::WinStationQueryInformationA */ + FIXME("Stub %p 0x%08lx %d %p %p\n", hServer, SessionId, WTSInfoClass, + Buffer, BytesReturned); + + return FALSE; +} + +/************************************************************ + * WTSQuerySessionInformationW (WTSAPI32.@) + */ +BOOL WINAPI WTSQuerySessionInformationW( + HANDLE hServer, + DWORD SessionId, + WTS_INFO_CLASS WTSInfoClass, + LPWSTR* Buffer, + DWORD* BytesReturned) +{ + /* FIXME: Forward request to winsta.dll::WinStationQueryInformationW */ + FIXME("Stub %p 0x%08lx %d %p %p\n", hServer, SessionId, WTSInfoClass, + Buffer, BytesReturned); + + return FALSE; +} + +/************************************************************ + * WTSQueryUserConfigA (WTSAPI32.@) + */ +BOOL WINAPI WTSQueryUserConfigA(LPSTR pServerName, LPSTR pUserName, + WTS_CONFIG_CLASS WTSConfigClass, LPSTR* ppBuffer, DWORD* pBytesReturned) +{ + FIXME("Stub %s %s 0x%08lx %p %p\n", debugstr_a(pServerName), debugstr_a(pUserName), + WTSConfigClass, ppBuffer, pBytesReturned); + return FALSE; +} + +/************************************************************ + * WTSQueryUserConfigW (WTSAPI32.@) + */ +BOOL WINAPI WTSQueryUserConfigW(LPWSTR pServerName, LPWSTR pUserName, + WTS_CONFIG_CLASS WTSConfigClass, LPWSTR* ppBuffer, DWORD* pBytesReturned) +{ + FIXME("Stub %s %s 0x%08lx %p %p\n", debugstr_w(pServerName), debugstr_w(pUserName), + WTSConfigClass, ppBuffer, pBytesReturned); + return FALSE; +} + +/************************************************************ + * WTSQueryUserToken (WTSAPI32.@) + */ +BOOL WINAPI WTSQueryUserToken(ULONG SessionId, PHANDLE phToken) +{ + SetLastError(ERROR_NO_TOKEN); + return FALSE; +} + +/************************************************************ + * WTSRegisterSessionNotification (WTSAPI32.@) + */ +BOOL WINAPI WTSRegisterSessionNotification(HWND hWnd, DWORD dwFlags) +{ + FIXME("Stub %p 0x%08x\n", hWnd, dwFlags); + return TRUE; +} + +/************************************************************ + * WTSTerminateProcess (WTSAPI32.@) + */ +BOOL WINAPI WTSTerminateProcess(HANDLE hServer, DWORD ProcessId, DWORD ExitCode) +{ + FIXME("Stub %p 0x%08x 0x%08x\n", hServer, ProcessId, ExitCode); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} + +/************************************************************ + * WTSUnRegisterSessionNotification (WTSAPI32.@) + */ +BOOL WINAPI WTSUnRegisterSessionNotification(HWND hWnd) +{ + FIXME("Stub %p\n", hWnd); + return TRUE; +} + +/************************************************************ + * WTSWaitSystemEvent (WTSAPI32.@) + */ +BOOL WINAPI WTSWaitSystemEvent(HANDLE hServer, DWORD Mask, DWORD* Flags) +{ + /* FIXME: Forward request to winsta.dll::WinStationWaitSystemEvent */ + FIXME("Stub %p 0x%08lx %p\n", hServer, Mask, Flags); + return FALSE; +} diff --git a/auxiliary/wtsapi32/wtsapi32.def b/auxiliary/wtsapi32/wtsapi32.def new file mode 100644 index 0000000..6f50264 --- /dev/null +++ b/auxiliary/wtsapi32/wtsapi32.def @@ -0,0 +1,22 @@ +LIBRARY wtsapi32.dll BASE=0x7D040000 +EXPORTS + WTSCloseServer + WTSDisconnectSession + WTSEnumerateProcessesA + WTSEnumerateProcessesW + WTSEnumerateServersA + WTSEnumerateServersW + WTSEnumerateSessionsA + WTSEnumerateSessionsW + WTSFreeMemory + WTSOpenServerA + WTSOpenServerW + WTSQuerySessionInformationA + WTSQuerySessionInformationW + WTSQueryUserConfigA + WTSQueryUserConfigW + WTSQueryUserToken + WTSRegisterSessionNotification + WTSTerminateProcess + WTSUnRegisterSessionNotification + WTSWaitSystemEvent diff --git a/auxiliary/wtsapi32/wtsapi32.h b/auxiliary/wtsapi32/wtsapi32.h new file mode 100644 index 0000000..b0f5d71 --- /dev/null +++ b/auxiliary/wtsapi32/wtsapi32.h @@ -0,0 +1,165 @@ +/* + * Copyright 2005 Ulrich Czekalla (For CodeWeavers) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __WINE_WTSAPI32_H +#define __WINE_WTSAPI32_H + +#define DECL_WINELIB_TYPE_AW(x) + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef enum tagWTS_INFO_CLASS +{ + WTSInitialProgram, + WTSApplicationName, + WTSWorkingDirectory, + WTSOEMId, + WTSSessionId, + WTSUserName, + WTSWinStationName, + WTSDomainName, + WTSConnectState, + WTSClientBuildNumber, + WTSClientName, + WTSClientDirectory, + WTSClientProductId, + WTSClientHardwareId, + WTSClientAddress, + WTSClientDisplay, + WTSClientProtocolType, +} WTS_INFO_CLASS; + +typedef enum _WTS_CONNECTSTATE_CLASS +{ + WTSActive, + WTSConnected, + WTSConnectQuery, + WTSShadow, + WTSDisconnected, + WTSIdle, + WTSListen, + WTSReset, + WTSDown, + WTSInit +} WTS_CONNECTSTATE_CLASS; + +typedef enum _WTS_CONFIG_CLASS +{ + WTSUserConfigInitialProgram, + WTSUserConfigWorkingDirectory, + WTSUserConfigInheritInitialProgram, + WTSUserConfigAllowLogonTerminalServer, + WTSUserConfigTimeoutSettingsConnections, + WTSUserConfigTimeoutSettingsDisconnections, + WTSUserConfigTimeoutSettingsIdle, + WTSUserConfigDeviceClientDrives, + WTSUserConfigDeviceClientPrinters, + WTSUserConfigDeviceClientDefaultPrinter, + WTSUserConfigBrokenTimeoutSettings, + WTSUserConfigModemCallbackSettings, + WTSUserConfigModemCallbackPhoneNumber, + WTSUserConfigShadowSettings, + WTSUserConfigTerminalServerProfilePath, + WTSUserConfigTerminalServerHomeDirectory, + WTSUserConfigfTerminalServerRemoteHomeDir +} WTS_CONFIG_CLASS; + +typedef struct _WTS_PROCESS_INFOA +{ + DWORD SessionId; + DWORD ProcessId; + LPSTR pProcessName; + PSID pUserSid; +} WTS_PROCESS_INFOA, *PWTS_PROCESS_INFOA; + +typedef struct _WTS_PROCESS_INFOW +{ + DWORD SessionId; + DWORD ProcessId; + LPWSTR pProcessName; + PSID pUserSid; +} WTS_PROCESS_INFOW, *PWTS_PROCESS_INFOW; + +DECL_WINELIB_TYPE_AW(WTS_PROCESS_INFO) +DECL_WINELIB_TYPE_AW(PWTS_PROCESS_INFO) + +typedef struct _WTS_SESSION_INFOA +{ + DWORD SessionId; + LPSTR pWinStationName; + WTS_CONNECTSTATE_CLASS State; +} WTS_SESSION_INFOA, *PWTS_SESSION_INFOA; + +typedef struct _WTS_SESSION_INFOW +{ + DWORD SessionId; + LPWSTR pWinStationName; + WTS_CONNECTSTATE_CLASS State; +} WTS_SESSION_INFOW, *PWTS_SESSION_INFOW; + +DECL_WINELIB_TYPE_AW(WTS_SESSION_INFO) +DECL_WINELIB_TYPE_AW(PWTS_SESSION_INFO) + +typedef struct _WTS_SERVER_INFOA +{ + LPSTR pServerName; +} WTS_SERVER_INFOA, *PWTS_SERVER_INFOA; + +typedef struct _WTS_SERVER_INFOW +{ + LPWSTR pServerName; +} WTS_SERVER_INFOW, *PWTS_SERVER_INFOW; + +DECL_WINELIB_TYPE_AW(WTS_SERVER_INFO) +DECL_WINELIB_TYPE_AW(PWTS_SERVER_INFO) + +void WINAPI WTSCloseServer(HANDLE); +BOOL WINAPI WTSDisconnectSession(HANDLE, DWORD, BOOL); +BOOL WINAPI WTSEnumerateProcessesA(HANDLE, DWORD, DWORD, PWTS_PROCESS_INFOA *, DWORD *); +BOOL WINAPI WTSEnumerateProcessesW(HANDLE, DWORD, DWORD, PWTS_PROCESS_INFOW *, DWORD *); +#define WTSEnumerateProcesses WINELIB_NAME_AW(WTSEnumerateProcesses) +BOOL WINAPI WTSEnumerateServersA( LPSTR, DWORD, DWORD, PWTS_SERVER_INFOA*, DWORD*); +BOOL WINAPI WTSEnumerateServersW( LPWSTR, DWORD, DWORD, PWTS_SERVER_INFOW*, DWORD*); +#define WTSEnumerateServers WINELIB_NAME_AW(WTSEnumerateServers) +BOOL WINAPI WTSEnumerateSessionsA(HANDLE, DWORD, DWORD, PWTS_SESSION_INFOA *, DWORD *); +BOOL WINAPI WTSEnumerateSessionsW(HANDLE, DWORD, DWORD, PWTS_SESSION_INFOW *, DWORD *); +#define WTSEnumerateSessions WINELIB_NAME_AW(WTSEnumerateSessions) +void WINAPI WTSFreeMemory(PVOID); +HANDLE WINAPI WTSOpenServerA(LPSTR); +HANDLE WINAPI WTSOpenServerW(LPWSTR); +#define WTSOpenServer WINELIB_NAME_AW(WTSOpenServer) +BOOL WINAPI WTSQuerySessionInformationA(HANDLE, DWORD, WTS_INFO_CLASS, LPSTR *, DWORD *); +BOOL WINAPI WTSQuerySessionInformationW(HANDLE, DWORD, WTS_INFO_CLASS, LPWSTR *, DWORD *); +#define WTSQuerySessionInformation WINELIB_NAME_AW(WTSQuerySessionInformation) +BOOL WINAPI WTSQueryUserConfigA(LPSTR,LPSTR,WTS_CONFIG_CLASS,LPSTR*,DWORD*); +BOOL WINAPI WTSQueryUserConfigW(LPWSTR,LPWSTR,WTS_CONFIG_CLASS,LPWSTR*,DWORD*); +#define WTSQueryUserConfig WINELIB_NAME_AW(WTSQueryUserConfig) +BOOL WINAPI WTSQueryUserToken(ULONG, PHANDLE); +BOOL WINAPI WTSRegisterSessionNotification(HWND, DWORD); +BOOL WINAPI WTSTerminateProcess(HANDLE, DWORD, DWORD); +BOOL WINAPI WTSUnRegisterSessionNotification(HWND); +BOOL WINAPI WTSWaitSystemEvent(HANDLE, DWORD, DWORD*); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/common/is_sorted.hpp b/common/is_sorted.hpp new file mode 100644 index 0000000..3cd43df --- /dev/null +++ b/common/is_sorted.hpp @@ -0,0 +1,19 @@ +template +inline bool is_sorted(FI begin, FI end) +{ + return is_sorted_until(begin, end) == end; +} + +template +FI is_sorted_until(FI begin, FI end) +{ + if (begin == end) + return end; + + FI next = begin; + for (++next ; next != end ; begin = next, ++next) + if (*next < *begin) + return next; + + return end; +} diff --git a/common/kexcoresdk.h b/common/kexcoresdk.h new file mode 100644 index 0000000..785c727 --- /dev/null +++ b/common/kexcoresdk.h @@ -0,0 +1,196 @@ +/* + * 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. + * + */ + +/** KernelEx Core SDK. */ + + +#ifndef __KEXCORESDK_H +#define __KEXCORESDK_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef KEXCORE_EXPORTS +#define _KEXCOREIMP __declspec(dllexport) +#else +#define _KEXCOREIMP __declspec(dllimport) +#endif + + +/***************************************************************************** + * + * Every api library has to export the following functions: + * + * + * const apilib_api_table* get_api_table() + * + * Function should return pointer to api tables provided by the library. + * Function will be called when KernelEx Core builds new api + * configuration table, but only if the library hasn't been loaded yet. + * Named api and ordinal api tables have to be sorted in ascending order, + * according to operator< rules below. + * After the last api table there has to be a closing NULL entry + * (all fields set to zeros). + * Multiple apis with same names and ordinal numbers are allowed in single + * api library. However only one api with given name or ordinal will be + * included in single api configuration. It is possible to specify which + * api should be used in core.ini configuration file. + * + *****************************************************************************/ + + +/** Convenience macro for defining apis. */ +#define DECL_API(name_ord,func) { name_ord, (unsigned long) func } +/** Convenience macro for defining tables. */ +#define DECL_TAB(lib,named,unnamed) { lib, named, sizeof(named) / sizeof(apilib_named_api), unnamed, sizeof(unnamed) / sizeof(apilib_unnamed_api) } + + +/** apilib_named_api - named api structure. */ +typedef struct _apilib_named_api +{ + const char* name; /**< Api name. */ + unsigned long addr; /**< Api address. */ +} apilib_named_api; + + +/** apilib_unnamed_api - unnamed api structure. */ +typedef struct _apilib_unnamed_api +{ + unsigned short ord; /**< Api ordinal number. */ + unsigned long addr; /**< Api address. */ +} apilib_unnamed_api; + + +/** apilib_api_table - api table structure. */ +typedef struct _apilib_api_table +{ + const char* target_library; /**< DLL library for which the apis are defined. */ + const apilib_named_api* named_apis; /**< Pointer to table of named apis. */ + int named_apis_count; /**< Number of named apis in the table. */ + const apilib_unnamed_api* ordinal_apis; /**< Pointer to table of unnamed apis. */ + int ordinal_apis_count; /**< Number of unnamed apis in the table. */ +} apilib_api_table; + + +/** Type definition for get_api_table() function. */ +typedef const apilib_api_table* (* fgat_t)(); + + +/** kexGetKEXVersion - obtain KernelEx Core version + * + * Returned value is KernelEx version number encoded as follows: + * 0xHHLLRRRR, where: + * HH - major version number + * LL - minor version number + * RRRR - revision number + */ +_KEXCOREIMP unsigned long kexGetKEXVersion(); + + +/** kexDebugPrint - output debug information + * + * Parameters are compatible with printf command, + * maximum output length is limited to 256 bytes. + */ +_KEXCOREIMP void kexDebugPrint(const char* format, ...); + + +/** kexGetVersion - obtain original Windows version number. + * + * Refer to GetVersion API documentation for parameters and output. + */ +_KEXCOREIMP DWORD kexGetVersion(); + + +/** kexGetProcAddress - obtain original address of DLL library function. + * + * Refer to GetProcAddress API documentation for parameters and output. + */ +_KEXCOREIMP PROC kexGetProcAddress(HMODULE hModule, PCSTR lpProcName); + + +/** kexPIDtoPDB - obtain pointer to process database entry, given process identifier. + * + * @param pid Process identifier. + * @return Pointer to process database entry on success, NULL on failure. + */ +_KEXCOREIMP void* kexPIDtoPDB(DWORD pid); + + +/** kexTIDtoTDB - obtain pointer to thread database entry, given thread identifier. + * + * @param tid Thread identifier. + * @return Pointer to thread database entry on success, NULL on failure. + */ +_KEXCOREIMP void* kexTIDtoTDB(DWORD tid); + + +/** 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. + */ +_KEXCOREIMP void kexGetModuleSettings(const char* module, + char* conf_name, BYTE* ldr_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. + */ +_KEXCOREIMP void kexSetModuleSettings(const char* module, + const char* conf_name, BYTE ldr_flags); + + +/** kexFlushAppSettings - Reloads all module settings from registy. */ +_KEXCOREIMP void kexFlushAppSettings(void); + + +#ifdef __cplusplus +}; /* extern "C" */ +#endif + + +#ifdef __cplusplus + + +/** Comparison operator used to order named api entries. */ +inline bool operator<(const apilib_named_api& a, const apilib_named_api& b) +{ + return strcmp(a.name, b.name) < 0; +} + + +/** Comparison operator used to order unnamed api entries. */ +inline bool operator<(const apilib_unnamed_api& a, const apilib_unnamed_api& b) +{ + return a.ord < b.ord; +} + + +#endif + + +#endif diff --git a/common/pemanip.cpp b/common/pemanip.cpp new file mode 100644 index 0000000..763b95a --- /dev/null +++ b/common/pemanip.cpp @@ -0,0 +1,435 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#include "pemanip.h" +#include "debug.h" +#include + +PEmanip::PEmanip() +{ + ZeroInit(); +} + +PEmanip::PEmanip(const char* file_path, int add_size) +{ + ZeroInit(); + OpenFile(file_path, add_size); +} + +PEmanip::PEmanip(void* memory) +{ + ZeroInit(); + OpenMemory(memory); +} + +PEmanip::~PEmanip() +{ + if (file_buf) + HeapFree(GetProcessHeap(), 0, file_buf); + if (file_path) + HeapFree(GetProcessHeap(), 0, file_path); +} + +void PEmanip::ZeroInit() +{ + file_buf = NULL; + file_path = NULL; + MZh = NULL; + PEh = NULL; + section_hdrs = NULL; + target_len = 0; + max_target_len = 0; + image_base = 0; + has_target = false; +} + +bool PEmanip::HasTarget() +{ + return has_target; +} + +IMAGE_NT_HEADERS* PEmanip::GetPEHeader() +{ + return PEh; +} + +int PEmanip::GetFileSize(const char* file_path) +{ + HANDLE file = CreateFile(file_path, GENERIC_READ, FILE_SHARE_READ, + NULL, OPEN_EXISTING, 0, NULL); + int file_size = -1; + if (file != INVALID_HANDLE_VALUE) + { + file_size = ::GetFileSize(file, NULL); + CloseHandle(file); + } + return file_size; +} + +bool PEmanip::LoadFile(const char* file_path, int add_size) +{ + void* buf = NULL; + int buf_len; + HANDLE file; + int bytes_read; + bool ret = false; + + if (!file_path || add_size < 0) + return false; + + buf_len = GetFileSize(file_path); + if (buf_len > 0) + { + buf = HeapAlloc(GetProcessHeap(), 0, buf_len + add_size); + if (buf) + { + file = CreateFile(file_path, GENERIC_READ, FILE_SHARE_READ, + NULL, OPEN_EXISTING, 0, NULL); + if (file != INVALID_HANDLE_VALUE) + { + if (ReadFile(file, buf, buf_len, (DWORD*) &bytes_read, NULL) + && bytes_read == buf_len) + { + this->file_path = (char*) HeapAlloc(GetProcessHeap(), + 0, strlen(file_path) + 1); + this->target_len = buf_len; + this->file_buf = buf; + this->max_target_len = buf_len + add_size; + if (this->file_path) + { + strcpy(this->file_path, file_path); + ret = true; + } + } + CloseHandle(file); + } + } + } + + if (!ret && buf) + HeapFree(GetProcessHeap(), 0, buf); + + return ret; +} + +bool PEmanip::SaveFile(const char* file_path) +{ + HANDLE file; + int bytes_written; + bool ret = false; + + if (!file_path || !file_buf) + return false; + + file = CreateFile(file_path, GENERIC_WRITE, 0, NULL, + CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (file != INVALID_HANDLE_VALUE) + { + if (WriteFile(file, file_buf, target_len, (DWORD*) &bytes_written, NULL) + && bytes_written == target_len) + { + ret = true; + } + CloseHandle(file); + } + + return ret; +} + +void PEmanip::Close() +{ + if (file_buf) + HeapFree(GetProcessHeap(), 0, file_buf); + if (file_path) + HeapFree(GetProcessHeap(), 0, file_path); + + ZeroInit(); +} + +int PEmanip::GetBufferLen() +{ + return target_len; +} + +bool PEmanip::SetBufferLen(int new_size) +{ + if (new_size >= max_target_len) + return false; + + if (new_size < target_len) + return false; + + target_len = new_size; + return true; +} + +unsigned long PEmanip::ALIGN(unsigned long x, unsigned long y) +{ + return (x + y - 1) & (~(y - 1)); +} + +bool PEmanip::OpenFile(const char* file_path, int add_size) +{ + if (has_target) + return false; + + if (LoadFile(file_path, add_size)) + { + MZh = (IMAGE_DOS_HEADER*) file_buf; + + if (MZh->e_magic == IMAGE_DOS_SIGNATURE) + { + PEh = (IMAGE_NT_HEADERS*) ((DWORD) MZh + MZh->e_lfanew); + if ((PEh->Signature == IMAGE_NT_SIGNATURE) + && (PEh->FileHeader.Machine == IMAGE_FILE_MACHINE_I386) + && (PEh->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR_MAGIC)) + { + section_hdrs = (IMAGE_SECTION_HEADER*) + ((DWORD) PEh + + PEh->FileHeader.SizeOfOptionalHeader + + sizeof(IMAGE_FILE_HEADER) + + sizeof(DWORD)); + image_base = PEh->OptionalHeader.ImageBase; + has_target = true; + return true; + } + } + } + return false; +} + +bool PEmanip::OpenMemory(void* memory) +{ + if (has_target) + return false; + + MZh = (IMAGE_DOS_HEADER*) memory; + + if (MZh->e_magic == IMAGE_DOS_SIGNATURE) + { + PEh = (IMAGE_NT_HEADERS*) ((DWORD) MZh + MZh->e_lfanew); + if ((PEh->Signature == IMAGE_NT_SIGNATURE) + && (PEh->FileHeader.Machine == IMAGE_FILE_MACHINE_I386) + && (PEh->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR_MAGIC)) + { + section_hdrs = (IMAGE_SECTION_HEADER*) + ((DWORD) PEh + + PEh->FileHeader.SizeOfOptionalHeader + + sizeof(IMAGE_FILE_HEADER) + + sizeof(DWORD)); + image_base = (DWORD)memory; + has_target = true; + target_len = PEh->OptionalHeader.SizeOfImage; + max_target_len = target_len; + return true; + } + } + return false; +} + +IMAGE_SECTION_HEADER* PEmanip::RvaToSection(DWORD Rva) +{ + IMAGE_SECTION_HEADER* section = section_hdrs; + + for (int i = 0 ; i < PEh->FileHeader.NumberOfSections ; i++) + { + if ((Rva >= section->VirtualAddress) + && (Rva < (section->VirtualAddress + section->Misc.VirtualSize))) + { + return section; + } + section++; + } + return NULL; +} + +void* PEmanip::RvaToPointer(DWORD Rva) +{ + if (!file_buf) + return (void*)(Rva + image_base); + + IMAGE_SECTION_HEADER* section = section_hdrs; + + for (int i = 0 ; i < PEh->FileHeader.NumberOfSections ; i++) + { + if ((Rva >= section->VirtualAddress) + && (Rva < (section->VirtualAddress + section->Misc.VirtualSize))) + { + return (void*) (Rva - section->VirtualAddress + + section->PointerToRawData + (DWORD) MZh); + } + section++; + } + return 0; +} + +DWORD PEmanip::PointerToRva(void* pointer) +{ + if (!file_buf) + return (DWORD) pointer - image_base; + + IMAGE_SECTION_HEADER* section = section_hdrs; + DWORD offset; + + if (pointer < MZh) + return 0; + + offset = (DWORD) pointer - (DWORD) MZh; + + for (int i = 0 ; i < PEh->FileHeader.NumberOfSections ; i++) + { + if ((offset >= section->PointerToRawData) + && (offset < (section->PointerToRawData + section->SizeOfRawData))) + { + return offset - section->PointerToRawData + + section->VirtualAddress; + } + section++; + } + return 0; +} + +IMAGE_SECTION_HEADER* PEmanip::FindSectionByName(const char* name) +{ + IMAGE_SECTION_HEADER* section = section_hdrs; + + for (int i = 0 ; i < PEh->FileHeader.NumberOfSections ; i++) + { + if (!strnicmp((char*) section->Name, name, sizeof(section->Name))) + return section; + section++; + } + return NULL; +} + +void* PEmanip::GetSectionByName(const char* name) +{ + IMAGE_SECTION_HEADER* section = FindSectionByName(name); + + if (section) + return RvaToPointer(section->VirtualAddress); + return NULL; +} + +int PEmanip::GetSectionSize(const char* name) +{ + IMAGE_SECTION_HEADER* section = FindSectionByName(name); + + if (section) + if (file_buf) + return section->SizeOfRawData; + else + return section->Misc.VirtualSize; + return 0; +} + +bool PEmanip::AllocSectionSpace(const char* name, int needed_space, void** ptr, int align) +{ + IMAGE_SECTION_HEADER* Section = FindSectionByName(name); + + if (!Section || align < 1 || needed_space < 0) + return false; + + if (!needed_space) + return true; + + DWORD current_size = ALIGN(Section->Misc.VirtualSize, align); + DWORD new_size = current_size + needed_space; + + DWORD max_size = (Section + 1)->VirtualAddress - Section->VirtualAddress; + int available_space = max_size - current_size; + + DBGPRINTF(("Bytes available: %d, ", available_space)); + DBGPRINTF(("Bytes needed: %d\n", needed_space)); + + if (available_space < needed_space) + { + DBGPRINTF(("Not enough space in section!\n")); + return false; + } + + if (new_size > Section->SizeOfRawData) + { + int offset = ALIGN(new_size - Section->SizeOfRawData, + PEh->OptionalHeader.FileAlignment); + + DBGPRINTF(("Applying offset of %d\n", offset)); + + void* block_start = RvaToPointer((Section + 1)->VirtualAddress); + int block_size = GetBufferLen() - (Section + 1)->PointerToRawData; + + char* tmp = (char*)HeapAlloc(GetProcessHeap(), 0, block_size); + memcpy(tmp, block_start, block_size); + memcpy((void*)((int)block_start + offset), tmp, block_size); + HeapFree(GetProcessHeap(), 0, tmp); + memset(block_start, 0, offset); + + // update offsets + for (int i = 0 ; i < PEh->FileHeader.NumberOfSections ; i++) + { + if (§ion_hdrs[i] <= Section) + continue; + section_hdrs[i].PointerToRawData += offset; + } + Section->SizeOfRawData += offset; + if (!SetBufferLen(GetBufferLen() + offset)) + return false; + } + + Section->Misc.VirtualSize = new_size; + + if (ptr) + *ptr = RvaToPointer(Section->VirtualAddress + current_size); + + return true; +} + +DWORD PEmanip::GetExportedAPI(const char* func) +{ + IMAGE_EXPORT_DIRECTORY* Exports = (IMAGE_EXPORT_DIRECTORY*) + RvaToPointer(PEh->OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress); + + if (Exports) + { + DWORD* Names = (DWORD*) RvaToPointer(Exports->AddressOfNames); + + for (DWORD i = 0 ; i < Exports->NumberOfNames ; i++) + { + if (!strcmp(func, (char*) RvaToPointer(*Names))) + { + WORD* OrdinalTable = (WORD*) RvaToPointer(Exports->AddressOfNameOrdinals); + WORD Index = OrdinalTable[i]; + DWORD* FunctionTable = (DWORD*) RvaToPointer(Exports->AddressOfFunctions); + DWORD Address = (DWORD) FunctionTable[Index]; + return Address; + } + Names++; + } + } + + return 0; +} + +DWORD PEmanip::GetImageBase() +{ + return image_base; +} diff --git a/common/pemanip.h b/common/pemanip.h new file mode 100644 index 0000000..dcce032 --- /dev/null +++ b/common/pemanip.h @@ -0,0 +1,70 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#ifndef _SETUP_PEMANIP_H +#define _SETUP_PEMANIP_H + +#include +#include + +class PEmanip +{ +private: + bool has_target; + char* file_path; + void* file_buf; + int target_len; + int max_target_len; + IMAGE_DOS_HEADER* MZh; + IMAGE_NT_HEADERS* PEh; + IMAGE_SECTION_HEADER* section_hdrs; + DWORD image_base; + + void ZeroInit(); + int GetFileSize(const char* file_path); + bool LoadFile(const char* file_path, int add_size); + int GetBufferLen(); + bool SetBufferLen(int new_size); + static unsigned long ALIGN(unsigned long x, unsigned long y); + IMAGE_SECTION_HEADER* FindSectionByName(const char* name); + +public: + PEmanip(); + PEmanip(const char* file_path, int add_size = 0); + PEmanip(void* memory); + ~PEmanip(); + bool HasTarget(); + bool OpenFile(const char* file_path, int add_size = 0); + bool OpenMemory(void* memory); + bool SaveFile(const char* file_path); + void Close(); + IMAGE_NT_HEADERS* GetPEHeader(); + IMAGE_SECTION_HEADER* RvaToSection(DWORD Rva); + void* RvaToPointer(DWORD Rva); + DWORD PointerToRva(void* pointer); + void* GetSectionByName(const char* name); + int GetSectionSize(const char* name); + bool AllocSectionSpace(const char* name, int needed_space, void** ptr, int align = 1); + DWORD GetExportedAPI(const char* func); + DWORD GetImageBase(); +}; + +#endif diff --git a/common/sstring.hpp b/common/sstring.hpp new file mode 100644 index 0000000..1e48854 --- /dev/null +++ b/common/sstring.hpp @@ -0,0 +1,78 @@ +/* + * 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. + * + */ + +#ifndef __SSTRING_HPP +#define __SSTRING_HPP + +#include + +class sstring +{ +public: + sstring(const char* src) + { + len = strlen(src); + storage = new char[len + 1]; + strcpy(storage, src); + } + + sstring(const sstring& src) + { + len = src.len; + storage = new char[len + 1]; + strcpy(storage, src.storage); + } + + ~sstring() + { + delete [] storage; + } + + sstring& operator=(const sstring& src) + { + len = src.len; + delete [] storage; + storage = new char[len + 1]; + strcpy(storage, src.storage); + return *this; + } + + bool operator<(const sstring& a) const + { + return strcmp(storage, a.storage) < 0; + } + + const char* get() const + { + return storage; + } + + int length() const + { + return len; + } + +private: + int len; + char* storage; +}; + +#endif diff --git a/core/Core.rc b/core/Core.rc new file mode 100644 index 0000000..3882db7 --- /dev/null +++ b/core/Core.rc @@ -0,0 +1,131 @@ +#include "resource.h" +#include "version.h" +#define _QUOTEME(x) #x +#define QUOTEME(x) _QUOTEME(x) + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// Neutral resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU) +#ifdef _WIN32 +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL +#pragma code_page(1250) +#endif //_WIN32 + +///////////////////////////////////////////////////////////////////////////// +// +// String Table +// + +STRINGTABLE DISCARDABLE +BEGIN + IDS_NOTREADY "System is not KernelEx-ready.\nPlease reinstall KernelEx." + IDS_STUBMISMATCH "Stub version mismatch (expected: %d, got: %d).\nPlease reinstall KernelEx." + IDS_OLDVER "Another KernelEx version has been detected: %s.\nPlease uninstall all other versions and reinstall latest version." +END + +#endif // Neutral resources +///////////////////////////////////////////////////////////////////////////// + + +///////////////////////////////////////////////////////////////////////////// +// Polish resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_PLK) +#ifdef _WIN32 +LANGUAGE LANG_POLISH, SUBLANG_DEFAULT +#pragma code_page(1250) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +#ifndef _MAC +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION RCVERSION + PRODUCTVERSION RCVERSION + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004b0" + BEGIN + VALUE "CompanyName", "Xeno86\0" + VALUE "FileDescription", "KernelEx Core\0" + VALUE "FileVersion", QUOTEME(RCVERSION) "\0" + VALUE "InternalName", "KernelEx\0" + VALUE "LegalCopyright", "Copyright © 2009, Xeno86\0" + VALUE "OriginalFilename", "KernelEx.dll\0" + VALUE "ProductName", "KernelEx\0" + VALUE "ProductVersion", VERSION_STR "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0, 1200 + END +END + +#endif // !_MAC + +#endif // Polish resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/core/SettingsDB.cpp b/core/SettingsDB.cpp new file mode 100644 index 0000000..7272258 --- /dev/null +++ b/core/SettingsDB.cpp @@ -0,0 +1,257 @@ +/* + * 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. + * + */ + +#include +#include "SettingsDB.h" +#include "apiconfmgr.h" +#include "internals.h" +#include "resolver.h" +#include "debug.h" +#include "wildcmp.h" + +SettingsDB SettingsDB::instance; + +SettingsDB::SettingsDB() +{ + InitializeCriticalSection(&cs); +} + +SettingsDB::~SettingsDB() +{ + DeleteCriticalSection(&cs); +} + +void SettingsDB::clear() +{ + EnterCriticalSection(&cs); + db.clear(); + appsetting as; + as.flags = LDR_KEX_DISABLE; + db.insert(pair(own_path, as)); + LeaveCriticalSection(&cs); +} + +void SettingsDB::flush_all() +{ + EnterCriticalSection(&cs); + clear(); + parse_configs(); + parse_flags(); + LeaveCriticalSection(&cs); +} + +void SettingsDB::parse_configs() +{ + LONG result; + HKEY key; + DWORD index = 0; + char path[MAX_PATH]; + DWORD path_len; + char name[256]; + DWORD name_len; + DWORD type; + + result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\KernelEx\\AppSettings\\Configs", + 0, KEY_QUERY_VALUE, &key); + if (result != ERROR_SUCCESS) + { + DBGPRINTF(("AppSettings\\Configs key missing\n")); + return; + } + while (true) + { + appsetting as; + map* pdb; + + path_len = sizeof(path); + name_len = sizeof(name); + result = RegEnumValue(key, index, path, &path_len, NULL, &type, (LPBYTE)name, &name_len); + index++; + if (result == ERROR_NO_MORE_ITEMS) + break; + if (result != ERROR_SUCCESS) + break; + if (type != REG_SZ) + continue; + name[sizeof(name) - 1] = '\0'; + as.conf = ApiConfigurationManager::get_api_configuration(name); + if (!as.conf) + continue; + + strupr(path); + if (strchr(path, '*') || strchr(path, '?')) + pdb = &db_wild; + else + pdb = &db; + + pdb->insert(pair(path, as)); + } + RegCloseKey(key); +} + +//note: call it after parse_configs() +void SettingsDB::parse_flags() +{ + LONG result; + HKEY key; + DWORD index = 0; + char path[MAX_PATH]; + DWORD path_len; + unsigned long flags; + DWORD flags_len; + DWORD type; + + result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\KernelEx\\AppSettings\\Flags", + 0, KEY_QUERY_VALUE, &key); + if (result != ERROR_SUCCESS) + { + DBGPRINTF(("AppSettings\\Flags key missing\n")); + return; + } + while (true) + { + map* pdb; + path_len = sizeof(path); + flags_len = sizeof(flags); + result = RegEnumValue(key, index, path, &path_len, NULL, &type, (LPBYTE)&flags, &flags_len); + index++; + if (result == ERROR_NO_MORE_ITEMS) + break; + if (result != ERROR_SUCCESS) + break; + if (type != REG_DWORD) + continue; + + strupr(path); + if (strchr(path, '*') || strchr(path, '?')) + pdb = &db_wild; + else + pdb = &db; + + map::iterator it = pdb->find(path); + if (it == pdb->end()) + { + appsetting as; + as.flags = flags; + pdb->insert(pair(path, as)); + } + else + { + it->second.flags = flags; + } + } + RegCloseKey(key); +} + +appsetting SettingsDB::get_appsetting(const char* path) +{ + map::const_iterator it; + + EnterCriticalSection(&cs); + //try full path first + it = db.find(path); + if (it == db.end()) + { + //then try wildcard matching + for (it = db_wild.begin() ; it != db_wild.end() ; it++) + { + if (wildcmp(it->first.get(), path)) + break; + } + } + + bool atend = it == db.end() || it == db_wild.end(); + LeaveCriticalSection(&cs); + if (!atend) + return it->second; + else + return appsetting(); +} + +void SettingsDB::write_single(const char* path, const char* conf_name, BYTE flags) +{ + LONG result; + HKEY key; + appsetting as; + + //convert path to uppercase + char path2[MAX_PATH]; + strncpy(path2, path, sizeof(path2)); + strupr(path2); + + //check if configuration name is valid + as.conf = ApiConfigurationManager::get_api_configuration(conf_name); + as.flags = flags; + + //write config + result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, + "Software\\KernelEx\\AppSettings\\Configs", 0, KEY_WRITE, &key); + if (result == ERROR_SUCCESS) + { + if (!as.conf || as.conf == ApiConfigurationManager::get_default_configuration()) + RegSetValueEx(key, path, 0, REG_SZ, (const BYTE*) "default", + sizeof("default")); + else + RegSetValueEx(key, path, 0, REG_SZ, (const BYTE*) conf_name, + strlen(conf_name) + 1); + RegCloseKey(key); + } + + //write flags + result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, + "Software\\KernelEx\\AppSettings\\Flags", 0, KEY_WRITE, &key); + if (result == ERROR_SUCCESS) + { + RegSetValueEx(key, path, 0, REG_DWORD, (BYTE*) &as.flags, sizeof(as.flags)); + RegCloseKey(key); + } + + //add to DB + EnterCriticalSection(&cs); + db.erase(path2); + db.insert(pair(path2, as)); + LeaveCriticalSection(&cs); +} + +#ifdef _DEBUG + +void SettingsDB::dump_db() +{ + map::const_iterator it; + + dbgprintf("User settings:\n"); + for (it = db.begin() ; it != db.end() ; it++) + { + ApiConfiguration* conf = it->second.conf; + dbgprintf("%-40s %-10s %02x\n", it->first.get(), + conf ? conf->get_name() : "unknown", it->second.flags); + } + + dbgprintf("\nPredefined settings:\n"); + for (it = db_wild.begin() ; it != db_wild.end() ; it++) + { + ApiConfiguration* conf = it->second.conf; + dbgprintf("%-40s %-10s %02x\n", it->first.get(), + conf ? conf->get_name() : "unknown", it->second.flags); + } +} + +#endif diff --git a/core/SettingsDB.h b/core/SettingsDB.h new file mode 100644 index 0000000..27ff114 --- /dev/null +++ b/core/SettingsDB.h @@ -0,0 +1,66 @@ +/* + * 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. + * + */ + +#ifndef __SETTINGSDB_H +#define __SETTINGSDB_H + +#ifdef _MSC_VER +#pragma warning(disable:4786) +#endif + +#include "sstring.hpp" +#include +#include "apiconf.h" + +using namespace std; + +struct appsetting +{ + appsetting() : conf(NULL), flags(0) {} + ApiConfiguration* conf; + unsigned long flags; +}; + +class SettingsDB +{ +public: + static SettingsDB instance; + + ~SettingsDB(); + void clear(); + void flush_all(); + appsetting get_appsetting(const char* path); + void write_single(const char* path, const char* conf_name, BYTE flags); +#ifdef _DEBUG + void dump_db(); +#endif + +private: + map db; + map db_wild; + CRITICAL_SECTION cs; + + SettingsDB(); + void parse_configs(); + void parse_flags(); +}; + +#endif diff --git a/core/apiconf.cpp b/core/apiconf.cpp new file mode 100644 index 0000000..71ce427 --- /dev/null +++ b/core/apiconf.cpp @@ -0,0 +1,601 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#include +#include +#include "apilib.h" +#include "apiconf.h" +#include "resolver.h" +#include "internals.h" +#include "debug.h" + +using namespace std; + +ApiConfiguration::ApiConfiguration(const char* name) +{ + initialized = prepare(name); + if (!initialized) + DBGPRINTF(("Failed to allocate memory\n")); +} + +ApiConfiguration::ApiConfiguration(const char* new_name, const ApiConfiguration& src) +{ + if (!prepare(new_name)) + goto __error; + + if (src.used_apilibs) + { + void* mem = malloc(src.used_apilibs_count * sizeof(ApiLibrary*)); + if (!mem) + goto __error; + + used_apilibs = (const ApiLibrary**) mem; + copy(src.used_apilibs, src.used_apilibs + src.used_apilibs_count, used_apilibs); + used_apilibs_count = src.used_apilibs_count; + } + + for (int i = 0 ; i < src.api_tables_count ; i++) + { + void* mem; + const ModuleApi& stab = src.api_tables[i]; + ModuleApi& dtab = api_tables[i]; + + mem = malloc(stab.named_apis_count * sizeof(NamedApi)); + if (!mem) + goto __error; + + dtab.named_apis = (NamedApi*) mem; + dtab.named_apis_count = stab.named_apis_count; + copy(stab.named_apis, stab.named_apis + stab.named_apis_count, + dtab.named_apis); + + mem = malloc(stab.unnamed_apis_count * sizeof(PROC)); + if (!mem) + goto __error; + + dtab.unnamed_apis = (PDWORD) mem; + dtab.unnamed_apis_count = stab.unnamed_apis_count; + copy(stab.unnamed_apis, stab.unnamed_apis + stab.unnamed_apis_count, + dtab.unnamed_apis); + } + + initialized = true; + return; + +__error: + DBGPRINTF(("Failed to allocate memory\n")); + initialized = false; +} + +ApiConfiguration::~ApiConfiguration() +{ + for (int i = 0 ; i < api_tables_count ; i++) + { + free(api_tables[i].named_apis); + free(api_tables[i].unnamed_apis); + } + free(conf_name); + free(api_tables); + free(used_apilibs); +} + +bool ApiConfiguration::prepare(const char* name) +{ + int size = strlen(name) + 1; + conf_name = (char*) malloc(size); + if (!conf_name) + return false; + + strcpy(conf_name, name); + + api_tables = (ModuleApi*) calloc(new_overridden_mod_cnt, sizeof(ModuleApi)); + if (!api_tables) + return false; + + api_tables_count = new_overridden_mod_cnt; + used_apilibs = NULL; + used_apilibs_count = 0; + return true; +} + +bool ApiConfiguration::add_to_used_apilibs(const ApiLibrary* apilib) +{ + for (int i = 0 ; i < used_apilibs_count ; i++) + { + if (used_apilibs[i] == apilib) + return true; + } + + //not found => add to list + void* mem = realloc(used_apilibs, (used_apilibs_count + 1) * sizeof(ApiLibrary*)); + if (!mem) + return false; + + used_apilibs = (const ApiLibrary**) mem; + used_apilibs[used_apilibs_count++] = apilib; + return true; +} + +bool ApiConfiguration::merge(const ApiLibrary* apilib) +{ + if (!apilib) + return false; + + if (!add_to_used_apilibs(apilib)) + return false; + + for (int i = 0 ; i < new_overridden_mod_cnt ; i++) + { + const apilib_api_table* psrc = apilib->api_tables; + while (psrc->target_library) + { + if (!strcmpi(psrc->target_library, new_overridden_mod_nms[i])) + { + if (i >= api_tables_count) + { + void* mem = recalloc(api_tables, new_overridden_mod_cnt * sizeof(ModuleApi)); + if (!mem) + return false; + api_tables = (ModuleApi*) mem; + api_tables_count = new_overridden_mod_cnt; + } + ModuleApi* pdst = api_tables + i; + + //join ordinal apis + + unsigned short max_ord; + if (psrc->ordinal_apis_count) + max_ord = psrc->ordinal_apis[psrc->ordinal_apis_count - 1].ord; + else + max_ord = 0; + + if (pdst->unnamed_apis_count < max_ord) + { + void* mem = recalloc(pdst->unnamed_apis, max_ord * sizeof(PROC)); + if (!mem) + return false; + pdst->unnamed_apis = (PDWORD) mem; + pdst->unnamed_apis_count = max_ord; + } + + //join tables + for (int i = psrc->ordinal_apis_count - 1 ; i >= 0 ; i--) + { + const apilib_unnamed_api& pua = psrc->ordinal_apis[i]; + pdst->unnamed_apis[pua.ord - 1] = encode_address(pua.addr, apilib); + } + + //join named apis + + const apilib_named_api* sfirst = psrc->named_apis; + const apilib_named_api* slast = sfirst + psrc->named_apis_count; + NamedApi* dfirst = pdst->named_apis; + NamedApi* dlast = dfirst + pdst->named_apis_count; + + //check how much space is needed first + int space = 0; + while (sfirst != slast && dfirst != dlast) + { + int cmp_result = strcmp(dfirst->api_name, sfirst->name); + if (cmp_result < 0) + { + dfirst++; + } + else if (cmp_result == 0) + { + dfirst++; + sfirst++; + while (sfirst != slast && !strcmp(sfirst->name, (sfirst - 1)->name)) + sfirst++; + } + else + { + space++; + sfirst++; + while (sfirst != slast && !strcmp(sfirst->name, (sfirst - 1)->name)) + sfirst++; + } + } + + //entries after end of dest + while (sfirst != slast) + { + sfirst++; + space++; + } + + //allocate new mem + if (space) + { + void* mem = realloc(pdst->named_apis, + (pdst->named_apis_count + space) * sizeof(NamedApi)); + if (!mem) + return false; + + pdst->named_apis = (NamedApi*) mem; + } + + sfirst = psrc->named_apis; + dfirst = pdst->named_apis; + dlast = dfirst + pdst->named_apis_count; + pdst->named_apis_count += space; + + //join tables + while (sfirst != slast && dfirst != dlast) + { + int cmp_result = strcmp(dfirst->api_name, sfirst->name); + if (cmp_result < 0) + dfirst++; + else if (cmp_result == 0) + { + //same apis => update address + (dfirst++)->address = encode_address((sfirst++)->addr, apilib); + while (sfirst != slast && !strcmp(sfirst->name, (sfirst - 1)->name)) + sfirst++; + } + else //cmp_result > 0 + { + //insert new api + copy_backward(dfirst, dlast, dlast + 1); + dlast++; + dfirst->api_name = sfirst->name; + dfirst->address = encode_address(sfirst->addr, apilib); + dfirst++; + sfirst++; + while (sfirst != slast && !strcmp(sfirst->name, (sfirst - 1)->name)) + sfirst++; + } + } + + //entries after end of dest + while (sfirst != slast) + { + dfirst->api_name = sfirst->name; + dfirst->address = encode_address(sfirst->addr, apilib); + dfirst++; + sfirst++; + } + + break; + } + psrc++; + } + } + + return true; +} + +bool ApiConfiguration::merge(const char* module, unsigned short ordinal, + const ApiLibrary* apilib, int id) +{ + if (!apilib) + return false; + + const apilib_api_table* psrc = apilib->api_tables; + + while (psrc->target_library) + { + if (!strcmpi(module, psrc->target_library)) + break; + psrc++; + } + + if (!psrc->target_library) + return false; + + apilib_unnamed_api to_find; + to_find.ord = ordinal; + + const apilib_unnamed_api* first = psrc->ordinal_apis; + const apilib_unnamed_api* last = first + psrc->ordinal_apis_count; + + const apilib_unnamed_api* low = lower_bound(first, last, to_find); + + if (low == last || to_find < *low) + return false; + + low += id; + + if (low >= last || to_find < *low) + return false; + + int i; + for (i = 0 ; i < new_overridden_mod_cnt ; i++) + if (!strcmpi(module, new_overridden_mod_nms[i])) + break; + + if (i == new_overridden_mod_cnt) + return false; + + if (!add_to_used_apilibs(apilib)) + return false; + + if (api_tables_count <= i) + { + void* mem = recalloc(api_tables, new_overridden_mod_cnt * sizeof(ModuleApi)); + if (!mem) + return false; + api_tables = (ModuleApi*) mem; + api_tables_count = new_overridden_mod_cnt; + } + + ModuleApi* pdst = api_tables + i; + if (pdst->unnamed_apis_count < ordinal) + { + void* mem = recalloc(pdst->unnamed_apis, ordinal * sizeof(PROC)); + if (!mem) + return false; + pdst->unnamed_apis = (PDWORD) mem; + pdst->unnamed_apis_count = ordinal; + } + + pdst->unnamed_apis[ordinal - 1] = encode_address(low->addr, apilib); + + return true; +} + +bool ApiConfiguration::merge(const char* module, const char* api_name, + const ApiLibrary* apilib, int id) +{ + if (!apilib) + return false; + + const apilib_api_table* psrc = apilib->api_tables; + + while (psrc->target_library) + { + if (!strcmpi(module, psrc->target_library)) + break; + psrc++; + } + + if (!psrc->target_library) + return false; + + apilib_named_api to_find; + to_find.name = api_name; + + const apilib_named_api* first = psrc->named_apis; + const apilib_named_api* last = first + psrc->named_apis_count; + + const apilib_named_api* low = lower_bound(first, last, to_find); + + if (low == last || to_find < *low) + return false; + + low += id; + + if (low >= last || to_find < *low) + return false; + + int i; + for (i = 0 ; i < new_overridden_mod_cnt ; i++) + if (!strcmpi(module, new_overridden_mod_nms[i])) + break; + + if (i == new_overridden_mod_cnt) + return false; + + if (!add_to_used_apilibs(apilib)) + return false; + + if (api_tables_count <= i) + { + void* mem = recalloc(api_tables, new_overridden_mod_cnt * sizeof(ModuleApi)); + if (!mem) + return false; + api_tables = (ModuleApi*) mem; + api_tables_count = new_overridden_mod_cnt; + } + + ModuleApi* pdst = api_tables + i; + NamedApi* dfirst = pdst->named_apis; + NamedApi* dlast = dfirst + pdst->named_apis_count; + + NamedApi dto_find; + dto_find.api_name = api_name; + + NamedApi* dlow = lower_bound(dfirst, dlast, dto_find); + + //scenario 1: existing entry + if (dlow < dlast && !(dto_find < *dlow)) + { + dlow->address = encode_address(low->addr, apilib); + } + //scenario 2: no matching entry + else + { + void* mem = realloc(pdst->named_apis, + (pdst->named_apis_count + 1) * sizeof(NamedApi)); + if (!mem) + return false; + + pdst->named_apis = (NamedApi*) mem; + pdst->named_apis_count++; + + dlow = (NamedApi*)((DWORD) dlow - (DWORD) dfirst + (DWORD) pdst->named_apis); + dfirst = pdst->named_apis; + dlast = dfirst + pdst->named_apis_count; + copy_backward(dlow, dlast - 1, dlast); + dlow->api_name = low->name; + dlow->address = encode_address(low->addr, apilib); + } + + return true; +} + +bool ApiConfiguration::erase(const char* module, unsigned short ordinal) +{ + int i; + for (i = 0 ; i < new_overridden_mod_cnt ; i++) + if (!strcmpi(module, new_overridden_mod_nms[i])) + break; + + if (i == new_overridden_mod_cnt || i >= api_tables_count) + return false; + + ModuleApi* pdst = api_tables + i; + if (pdst->unnamed_apis_count < ordinal) + { + return false; + } + + pdst->unnamed_apis[ordinal - 1] = 0; + + return true; +} + +bool ApiConfiguration::erase(const char* module, const char* api_name) +{ + int i; + for (i = 0 ; i < new_overridden_mod_cnt ; i++) + if (!strcmpi(module, new_overridden_mod_nms[i])) + break; + + if (i == new_overridden_mod_cnt || i >= api_tables_count) + return false; + + ModuleApi* pdst = api_tables + i; + NamedApi* dfirst = pdst->named_apis; + NamedApi* dlast = dfirst + pdst->named_apis_count; + + NamedApi dto_find; + dto_find.api_name = api_name; + + NamedApi* dlow = lower_bound(dfirst, dlast, dto_find); + + if (dlow >= dlast || dto_find < *dlow) + return false; + + copy(dlow + 1, dlast, dlow); + pdst->named_apis_count--; + //should I realloc memory after deleting entry? + + return true; +} + +/** Get api address given api table number and api name. + * @param table_id Valid api table number. + * @param hint Loader hint. + * @param api_name Api name. + * @return Api address or 0 if api address not found. + */ +unsigned long ApiConfiguration::get(unsigned short table_id, + unsigned short hint, const char* api_name) +{ + NamedApi* named_apis; + unsigned short named_apis_count; + int lo, hi, curr; + + named_apis = api_tables[table_id].named_apis; + named_apis_count = api_tables[table_id].named_apis_count; + + if (hint < named_apis_count) + { + int res = strcmp(api_name, named_apis[hint].api_name); + if (res > 0) + { + lo = hint + 1; + hi = named_apis_count - 1; + } + else if (res < 0) + { + lo = 0; + hi = hint - 1; + } + else + { + return named_apis[hint].address; + } + } + else + { + lo = 0; + hi = named_apis_count - 1; + } + curr = (hi + lo) >> 1; + + while (lo <= hi) + { + int res = strcmp(api_name, named_apis[curr].api_name); + if (res > 0) + { + lo = curr + 1; + } + else if (res < 0) + { + hi = curr - 1; + } + else + { + return named_apis[curr].address; + } + curr = (hi + lo) >> 1; + } + return 0; +} + +/** Get api address given api table number and api ordinal. + * @param table_id Valid api table number. + * @param api_ordinal Api ordinal number. + * @return Api address or 0 if api address not found. + */ +unsigned long ApiConfiguration::get(unsigned short table_id, + unsigned short api_ordinal) +{ + unsigned long* unnamed_apis; + unsigned short unnamed_apis_count; + + unnamed_apis = api_tables[table_id].unnamed_apis; + unnamed_apis_count = api_tables[table_id].unnamed_apis_count; + + if (api_ordinal > unnamed_apis_count) + return 0; + + return unnamed_apis[api_ordinal - 1]; +} + +bool ApiConfiguration::is_initialized() +{ + return initialized; +} + +#ifdef _DEBUG + +void ApiConfiguration::dump() +{ + dbgprintf("ApiConfiguration %s\n", get_name()); + for (int i = 0 ; i < api_tables_count ; i++) + { + dbgprintf("Covered module #%d: %s\n", i, overridden_module_names[i]); + dbgprintf("Named apis (count = %d)\n", api_tables[i].named_apis_count); + for (int j = 0 ; j < api_tables[i].named_apis_count ; j++) + dbgprintf("\t%-32s %08x\n", api_tables[i].named_apis[j].api_name, + api_tables[i].named_apis[j].address); + dbgprintf("Unnamed apis (count = %d)\n", api_tables[i].unnamed_apis_count); + for (int j = 0 ; j < api_tables[i].unnamed_apis_count ; j++) + dbgprintf("\t%-5d %08x\n", j, api_tables[i].unnamed_apis[j]); + dbgprintf("\n"); + } + dbgprintf("\n"); +} + +#endif diff --git a/core/apiconf.h b/core/apiconf.h new file mode 100644 index 0000000..66a796a --- /dev/null +++ b/core/apiconf.h @@ -0,0 +1,106 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#ifndef __APICONF_H +#define __APICONF_H + +#include "apilib.h" + +class ApiConfiguration +{ + struct NamedApi + { + const char* api_name; /* function name */ + unsigned long address; /* function address */ + bool operator<(const NamedApi& a) const; + }; + + struct ModuleApi + { + unsigned short named_apis_count; + unsigned short unnamed_apis_count; + NamedApi* named_apis; + unsigned long* unnamed_apis; /* function addresses */ + }; + +public: + ApiConfiguration(const char* name); + ApiConfiguration(const char* new_name, const ApiConfiguration& src); + ~ApiConfiguration(); + + bool is_table_empty(unsigned short table_id); + const char* get_name(); + + bool merge(const ApiLibrary* apilib); + bool merge(const char* module, unsigned short ordinal, + const ApiLibrary* apilib, int id); + bool merge(const char* module, const char* api_name, + const ApiLibrary* apilib, int id); + bool erase(const char* module, unsigned short ordinal); + bool erase(const char* module, const char* api_name); + unsigned long get(unsigned short table_id, unsigned short hint, const char* api_name); + unsigned long get(unsigned short table_id, unsigned short api_ordinal); + bool is_initialized(); + +#ifdef _DEBUG + void dump(); +#endif + + friend class ApiConfigurationManager; + +protected: + +private: + ModuleApi* api_tables; + unsigned short api_tables_count; + char* conf_name; + const ApiLibrary** used_apilibs; + int used_apilibs_count; + bool initialized; + + bool prepare(const char* name); + bool add_to_used_apilibs(const ApiLibrary* apilib); +}; + +inline bool ApiConfiguration::NamedApi::operator<(const NamedApi& a) const +{ + return strcmp(this->api_name, a.api_name) < 0; +} + +/** Returns true if selected api table is empty or invalid. + * @return True if selected api table is empty or invalid, false otherwise. + */ +inline bool ApiConfiguration::is_table_empty(unsigned short table_id) +{ + if (table_id >= api_tables_count) + return true; + return api_tables[table_id].unnamed_apis_count ? false : true; +} + +/** Retrieves api configuration name. + * @return Api configuration name. + */ +inline const char* ApiConfiguration::get_name() +{ + return conf_name; +} + +#endif diff --git a/core/apiconfmgr.cpp b/core/apiconfmgr.cpp new file mode 100644 index 0000000..8af169d --- /dev/null +++ b/core/apiconfmgr.cpp @@ -0,0 +1,537 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#include +#include +#include +#include "debug.h" +#include "internals.h" +#include "resolver.h" +#include "apiconfmgr.h" + +#define ALLOC_CAPACITY 10 + +ApiConfiguration** ApiConfigurationManager::curr_apiconf_ptrs = NULL; +int ApiConfigurationManager::curr_apiconf_cnt = 0; +ApiConfiguration** ApiConfigurationManager::prev_apiconf_ptrs = NULL; +int ApiConfigurationManager::prev_apiconf_cnt = 0; +ApiConfiguration* ApiConfigurationManager::default_apiconf = NULL; + +//TODO: I should check if new ApiConfiguration is identical to existing one +//and deallocate it if this is true + +ApiConfigurationManager::ApiConfigurationManager() +{ + new_apiconf_ptrs = NULL; + new_apiconf_cnt = 0; + strcpy(core_conf_file, kernelex_dir.get()); + strcat(core_conf_file, "core.ini"); +} + +ApiConfigurationManager::~ApiConfigurationManager() +{ + for (int i = 0 ; i < new_apiconf_cnt ; i++) + delete new_apiconf_ptrs[i]; + if (new_apiconf_ptrs) + free(new_apiconf_ptrs); +} + +bool ApiConfigurationManager::add_apiconf(ApiConfiguration* ac) +{ + //allocate space for new ApiConfigurations + if (new_apiconf_cnt % ALLOC_CAPACITY == 0) + { + void* new_block = realloc(new_apiconf_ptrs, + (new_apiconf_cnt + ALLOC_CAPACITY) * sizeof(ApiConfiguration*)); + + if (!new_block) + { + DBGPRINTF(("Failed to add api configuration to list of new ACs\n")); + return false; + } + + new_apiconf_ptrs = (ApiConfiguration**) new_block; + } + + //add to table of new ApiConfigurations + new_apiconf_ptrs[new_apiconf_cnt++] = ac; + return true; +} + +ApiConfiguration* ApiConfigurationManager::get_new_apiconf(const char* conf_name) +{ + for (int i = 0 ; i < new_apiconf_cnt ; i++) + if (!strcmp(new_apiconf_ptrs[i]->conf_name, conf_name)) + return new_apiconf_ptrs[i]; + return NULL; +} + +ApiConfiguration* ApiConfigurationManager::get_api_configuration(const char* conf_name) +{ + if (!strcmp("default", conf_name)) + return get_default_configuration(); + + for (int i = 0 ; i < curr_apiconf_cnt ; i++) + if (!strcmp(curr_apiconf_ptrs[i]->conf_name, conf_name)) + return curr_apiconf_ptrs[i]; + return NULL; +} + +void ApiConfigurationManager::reload_api_configurations() +{ + DBGPRINTF(("Reloading api configurations\n")); + + default_apiconf_index = GetPrivateProfileInt( + "ApiConfigurations", "default", 0, core_conf_file); + + for (int i = 0 ; i < 65536 ; i++) + { + char num[6]; + char apiconf_name[256]; + ApiConfiguration* apiconf = NULL; + + sprintf(num, "%d", i); + if (!GetPrivateProfileString("ApiConfigurations", num, "", + apiconf_name, sizeof(apiconf_name), core_conf_file)) + { + //no more entries + if (i <= default_apiconf_index) + { + DBGPRINTF(("Failed to load default api configuration - aborting\n")); + return; + } + break; + } + DBGPRINTF(("Processing api configuration #%s: %s\n", num, apiconf_name)); + + char buf[256]; + + if (!GetPrivateProfileString(apiconf_name, "inherit", "", buf, + sizeof(buf), core_conf_file) || !strcmpi(buf, "none")) + { + //no inherit + apiconf = new ApiConfiguration(apiconf_name); + } + else + { + ApiConfiguration* src_conf = get_new_apiconf(buf); + if (!src_conf) + { + DBGPRINTF(("Cannot inherit: %s. Configuration not found\n", buf)); + goto __error; + } + + apiconf = new ApiConfiguration(apiconf_name, *src_conf); + } + + if (!apiconf || !apiconf->is_initialized()) + { + DBGPRINTF(("Failed to create new api configuration object\n")); + goto __error; + } + + if (!join_apilibs(apiconf) || !parse_overrides(apiconf) || !add_apiconf(apiconf)) + goto __error; + + continue; + +__error: + if (apiconf) + delete apiconf; + if (i == default_apiconf_index) + { + DBGPRINTF(("Failed to load default api configuration - aborting\n")); + return; + } + } //for loop + + DBGPRINTF(("No more api configurations\n")); + + FullCritLock(); + + if (commit_changes()) + { + DBGPRINTF(("Re-add api libraries for previous api configurations\n")); + for (int i = 0 ; i < prev_apiconf_cnt ; i++) + for (int j = 0 ; j < prev_apiconf_ptrs[i]->used_apilibs_count ; j++) + if (!libmgr.load_apilib(prev_apiconf_ptrs[i]->used_apilibs[j]->apilib_name)) + DBGPRINTF(("Error\n")); + + libmgr.commit_changes(); + } + else + DBGPRINTF(("Bailing out\n")); + + FullCritUnlock(); +} + +bool ApiConfigurationManager::join_apilibs(ApiConfiguration* apiconf) +{ + char buf[256]; + + if (!GetPrivateProfileString(apiconf->get_name(), "contents", "", + buf, sizeof(buf), core_conf_file) || !strcmpi(buf, "none")) + { + DBGPRINTF(("No contents found\n")); + } + else + { + char buf2[256]; + + strupr(buf); + strcpy(buf2, buf); + char* lib = strtok(buf, ","); + while (lib) + { + if (!libmgr.load_apilib(lib)) + { + DBGPRINTF(("Failed to load api library: %s\n", lib)); + return false; + } + lib = strtok(NULL, ","); + } + + //merge has to be done in a separate loop because STD + //api library is based on other loaded api libraries + lib = strtok(buf2, ","); + while (lib) + { + if (!apiconf->merge(libmgr.get_new_apilib(lib))) + { + DBGPRINTF(("Failed to merge api library: %s\n", lib)); + return false; + } + lib = strtok(NULL, ","); + } + } + return true; +} + +bool ApiConfigurationManager::parse_overrides(ApiConfiguration* apiconf) +{ + //parse names and ordinal overrides + char buf[MAX_PATH]; + char section_data[32767]; + DWORD res; + + //first try [conf.names.xx] + strcpy(buf, apiconf->get_name()); + strcat(buf, ".names"); + if (isWinMe()) + strcat(buf, ".me"); + else + strcat(buf, ".98"); + + res = GetPrivateProfileSection(buf, section_data, sizeof(section_data), + core_conf_file); + + //else try [conf.names] + if (!res) + { + strcpy(buf, apiconf->get_name()); + strcat(buf, ".names"); + res = GetPrivateProfileSection(buf, section_data, sizeof(section_data), + core_conf_file); + } + + if (res) + { + DBGPRINTF(("Parsing named api overrides\n")); + + char* line = section_data; + while (*line) + { + char* module; + char* api_name; + char* apilib_name; + int id; + + char* p = line; + char* oldline = line; + line += strlen(line) + 1; + + module = p; + p = strchr(p, '.'); + if (!p) + { + DBGPRINTF(("Error parsing line: %s\n", oldline)); + continue; + } + *p++ = '\0'; + strcpy(buf, module); + strcat(buf, ".DLL"); + module = buf; + api_name = p; + p = strchr(p, '='); + if (!p) + { + DBGPRINTF(("Error parsing line: %s\n", oldline)); + continue; + } + *p++ = '\0'; + apilib_name = p; + p = strchr(p, '.'); + if (!p) + id = 0; + else + { + *p++ = '\0'; + id = atoi(p); + if (id < 0) + { + DBGPRINTF(("Error parsing line: %s\n", oldline)); + continue; + } + } + strupr(apilib_name); + if (!strcmp(apilib_name, "NONE")) + { + if (!apiconf->erase(module, api_name)) + { + DBGPRINTF(("Failed to merge named api overrides\n")); + return false; + } + } + else + { + if (!apiconf->merge(module, api_name, + libmgr.get_new_apilib(apilib_name), id)) + { + DBGPRINTF(("Failed to merge named api overrides\n")); + return false; + } + } + } + } + + //first try [conf.ordinals.xx] + strcpy(buf, apiconf->get_name()); + strcat(buf, ".ordinals"); + + if (isWinMe()) + strcat(buf, ".me"); + else + strcat(buf, ".98"); + + //else try [conf.ordinals] + res = GetPrivateProfileSection(buf, section_data, sizeof(section_data), + core_conf_file); + + if (!res) + { + strcpy(buf, apiconf->get_name()); + strcat(buf, ".ordinals"); + res = GetPrivateProfileSection(buf, section_data, sizeof(section_data), + core_conf_file); + } + + if (res) + { + DBGPRINTF(("Parsing ordinal api overrides\n")); + + char* line = section_data; + while (*line) + { + char* module; + char* ordinal_s; + int ordinal; + char* apilib_name; + int id; + + char* p = line; + char* oldline = line; + line += strlen(line) + 1; + + module = p; + p = strchr(p, '.'); + if (!p) + { + DBGPRINTF(("Error parsing line: %s\n", oldline)); + continue; + } + *p++ = '\0'; + strcpy(buf, module); + strcat(buf, ".DLL"); + module = buf; + ordinal_s = p; + p = strchr(p, '='); + if (!p) + { + DBGPRINTF(("Error parsing line: %s\n", oldline)); + continue; + } + *p++ = '\0'; + ordinal = atoi(ordinal_s); + if (ordinal < 1 || ordinal > 65535) + { + DBGPRINTF(("Error parsing line: %s\n", oldline)); + continue; + } + apilib_name = p; + p = strchr(p, '.'); + if (!p) + id = 0; + else + { + *p++ = '\0'; + id = atoi(p); + if (id < 0) + { + DBGPRINTF(("Error parsing line: %s\n", oldline)); + continue; + } + } + strupr(apilib_name); + if (!strcmp(apilib_name, "NONE")) + { + if (!apiconf->erase(module, (WORD) ordinal)) + { + DBGPRINTF(("Failed to merge ordinal api overrides\n")); + return false; + } + } + else + { + if (!apiconf->merge(module, (WORD) ordinal, + libmgr.get_new_apilib(apilib_name), id)) + { + DBGPRINTF(("Failed to merge ordinal api overrides\n")); + return false; + } + } + } + } + return true; +} + +bool ApiConfigurationManager::commit_changes() +{ + DBGPRINTF(("Updating api configuration list\n")); + + //calculate number of apiconf in use + WORD imteMax = *pimteMax; + IMTE** pmteModTable = *ppmteModTable; + int used = 0; + for (int j = 0 ; j < curr_apiconf_cnt ; j++) + { + for (WORD i = 0 ; i < imteMax ; i++) + { + IMTE_KEX* imte = (IMTE_KEX*) pmteModTable[i]; + if (imte && imte->config == curr_apiconf_ptrs[j]) + { + used++; + break; + } + } + } + for (int j = 0 ; j < prev_apiconf_cnt ; j++) + { + for (WORD i = 0 ; i < imteMax ; i++) + { + IMTE_KEX* imte = (IMTE_KEX*) pmteModTable[i]; + if (imte && imte->config == prev_apiconf_ptrs[j]) + { + used++; + break; + } + } + } + + //alloc space for new_prev + ApiConfiguration** new_prev; + new_prev = (ApiConfiguration**) malloc(used * sizeof(ApiConfiguration*)); + if (!new_prev) + { + DBGPRINTF(("Failed to allocate memory\n")); + return false; + } + + int cnt = 0; + + //move used entries from curr and prev to new_prev, free unused + for (int j = 0 ; j < curr_apiconf_cnt ; j++) + { + WORD i; + for (i = 0 ; i < imteMax ; i++) + { + IMTE_KEX* imte = (IMTE_KEX*) pmteModTable[i]; + if (imte && imte->config == curr_apiconf_ptrs[j]) + { + new_prev[cnt++] = curr_apiconf_ptrs[j]; + break; + } + } + if (i == imteMax) + delete curr_apiconf_ptrs[j]; + } + for (int j = 0 ; j < prev_apiconf_cnt ; j++) + { + WORD i; + for (i = 0 ; i < imteMax ; i++) + { + IMTE_KEX* imte = (IMTE_KEX*) pmteModTable[i]; + if (imte && imte->config == prev_apiconf_ptrs[j]) + { + new_prev[cnt++] = prev_apiconf_ptrs[j]; + break; + } + } + if (i == imteMax) + delete curr_apiconf_ptrs[j]; + } + + //replace prev with new_prev + free(prev_apiconf_ptrs); + prev_apiconf_ptrs = new_prev; + prev_apiconf_cnt = cnt; + + //replace curr with new + free(curr_apiconf_ptrs); + curr_apiconf_ptrs = new_apiconf_ptrs; + curr_apiconf_cnt = new_apiconf_cnt; + new_apiconf_ptrs = NULL; + new_apiconf_cnt = 0; + + //set default apiconf + if (default_apiconf_index >= 0) + default_apiconf = curr_apiconf_ptrs[default_apiconf_index]; + else + default_apiconf = NULL; + + DBGPRINTF(("Default api configuration is: %s\n", + default_apiconf ? default_apiconf->get_name() : "system")); + + return true; +} + +#ifdef _DEBUG + +void ApiConfigurationManager::dump_configurations() +{ + dbgprintf("Dumping all api configurations (count = %d) ...\n\n", curr_apiconf_cnt); + for (int i = 0 ; i < curr_apiconf_cnt ; i++) + { + curr_apiconf_ptrs[i]->dump(); + } + dbgprintf("End dump\n\n"); +} + +#endif diff --git a/core/apiconfmgr.h b/core/apiconfmgr.h new file mode 100644 index 0000000..45ebfc4 --- /dev/null +++ b/core/apiconfmgr.h @@ -0,0 +1,67 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#ifndef __APICONFMGR_H +#define __APICONFMGR_H + +#include "apiconf.h" + +class ApiConfigurationManager +{ +public: + ApiConfigurationManager(); + ~ApiConfigurationManager(); + void reload_api_configurations(); + static ApiConfiguration* get_api_configuration(const char* conf_name); + static ApiConfiguration* get_default_configuration(); + +#ifdef _DEBUG + static void dump_configurations(); +#endif + +protected: + +private: + char core_conf_file[MAX_PATH]; + ApiConfiguration** new_apiconf_ptrs; + int new_apiconf_cnt; + int default_apiconf_index; + ApiLibraryManager libmgr; + + static ApiConfiguration** curr_apiconf_ptrs; + static int curr_apiconf_cnt; + static ApiConfiguration** prev_apiconf_ptrs; + static int prev_apiconf_cnt; + static ApiConfiguration* default_apiconf; + + bool join_apilibs(ApiConfiguration* apiconf); + bool parse_overrides(ApiConfiguration* apiconf); + bool add_apiconf(ApiConfiguration* ac); + ApiConfiguration* get_new_apiconf(const char* conf_name); + bool commit_changes(); +}; + +inline ApiConfiguration* ApiConfigurationManager::get_default_configuration() +{ + return default_apiconf; +} + +#endif diff --git a/core/apilib.cpp b/core/apilib.cpp new file mode 100644 index 0000000..b4176db --- /dev/null +++ b/core/apilib.cpp @@ -0,0 +1,704 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#include +#include "apilib.h" +#include +#include "resolver.h" +#include "internals.h" +#include "debug.h" +#include "is_sorted.hpp" +#include "pemanip.h" + +using namespace std; + +#define ALLOC_CAPACITY 10 + +ApiLibrary** ApiLibraryManager::apilib_ptrs = NULL; +int ApiLibraryManager::apilib_cnt = 0; + +int overridden_module_count; +const char** overridden_module_names; +const char** new_overridden_mod_nms; +int new_overridden_mod_cnt; + +ApiLibraryManager::ApiLibraryManager() +{ + new_apilib_ptrs = NULL; + new_apilib_cnt = 0; + new_overridden_mod_nms = NULL; + new_overridden_mod_cnt = 0; + initialized = false; +} + +ApiLibraryManager::~ApiLibraryManager() +{ + rollback_changes(); +} + +bool ApiLibraryManager::initialize() +{ + ApiLibrary* std_apilib; + + new_apilib_cnt = 0; + new_apilib_ptrs = (ApiLibrary**) malloc(ALLOC_CAPACITY * sizeof(ApiLibrary*)); + + if (!new_apilib_ptrs) + goto __error; + + std_apilib = (ApiLibrary*) malloc(sizeof(ApiLibrary) + strlen("STD")); + + if (!std_apilib) + goto __error; + + strcpy(std_apilib->apilib_name, "STD"); + std_apilib->mod_handle = NULL; + std_apilib->api_tables = NULL; + std_apilib->index = 0; + + //copy previous STD api library tables and overridden module names + if (overridden_module_count) + { + int size = (overridden_module_count / ALLOC_CAPACITY + 1) * ALLOC_CAPACITY; + + std_apilib->api_tables = (apilib_api_table*) + malloc((size + 1) * sizeof(apilib_api_table)); + + if (!std_apilib->api_tables) + goto __error; + + apilib_api_table* prev_std_tab = apilib_ptrs[0]->api_tables; + copy(prev_std_tab, prev_std_tab + size + 1, std_apilib->api_tables); + + new_overridden_mod_nms = (const char**) malloc(size * sizeof(char*)); + + if (!new_overridden_mod_nms) + goto __error; + + copy(overridden_module_names, overridden_module_names + size, + new_overridden_mod_nms); + + new_overridden_mod_cnt = overridden_module_count; + } + + new_apilib_ptrs[new_apilib_cnt++] = std_apilib; + + initialized = true; + return true; + +__error: + free(new_overridden_mod_nms); + if (std_apilib) + free(std_apilib->api_tables); + free(std_apilib); + free(new_apilib_ptrs); + return false; +} + +bool ApiLibraryManager::load_apilib(const char* apilib_name) +{ + if (!initialized && !initialize()) + { + DBGPRINTF(("Failed to initialize api library manager\n")); + return false; + } + + if (new_apilib_cnt >= 0xff) + { + DBGPRINTF(("Too many api libraries loaded\n")); + return false; + } + + //STD is a special api library name + if (!strcmp(apilib_name, "STD")) + return true; + + //check if library wasn't loaded in this instance + for (int i = 0 ; i < new_apilib_cnt ; i++) + if (!strcmp(new_apilib_ptrs[i]->apilib_name, apilib_name)) + return true; + + ApiLibrary* apilib; + bool already_loaded = false; + + DBGPRINTF(("Loading api library: %s... ", apilib_name)); + + //check if library wasn't previously loaded + for (int i = 0 ; i < apilib_cnt ; i++) + { + if (!strcmp(apilib_ptrs[i]->apilib_name, apilib_name)) + { + DBGPRINTF(("already loaded... ")); + apilib = apilib_ptrs[i]; + already_loaded = true; + } + } + + //if it wasn't loaded + if (!already_loaded) + { + char dllpath[MAX_PATH]; + int size = sizeof(ApiLibrary) + strlen(apilib_name); + + apilib = (ApiLibrary*) malloc(size); + + if (!apilib) + { + DBGPRINTF(("Failed to allocate memory\n")); + goto __error; + } + + strcpy(apilib->apilib_name, apilib_name); + + strcpy(dllpath, kernelex_dir.get()); + strcat(dllpath, apilib_name); + apilib->mod_handle = LoadLibrary(dllpath); + + if (!apilib->mod_handle) + { + DBGPRINTF(("Failed to load api library\n")); + goto __error; + } + + fgat_t get_api_table; + get_api_table = (fgat_t) GetProcAddress( + apilib->mod_handle, "get_api_table"); + + if (!get_api_table) + { + DBGPRINTF(("Failed to get api library entry point\n")); + goto __error; + } + + const apilib_api_table* file_api_tables; + file_api_tables = get_api_table(); + + if (!file_api_tables) + { + DBGPRINTF(("Failed to get api tables\n")); + goto __error; + } + + apilib->api_tables = make_shared_api_tables(file_api_tables); + + if (!apilib->api_tables) + { + DBGPRINTF(("Failed to create shared api tables\n")); + goto __error; + } + + DBGPRINTF(("loaded @ 0x%08x... ", (DWORD) apilib->mod_handle)); + } + + //allocate space for new ApiLibraries + if (new_apilib_cnt % ALLOC_CAPACITY == 0) + { + void* new_block = realloc(new_apilib_ptrs, + (new_apilib_cnt + ALLOC_CAPACITY) * sizeof(ApiLibrary*)); + + if (!new_block) + { + DBGPRINTF(("Failed to allocate memory\n")); + goto __error; + } + + new_apilib_ptrs = (ApiLibrary**) new_block; + } + +// DBGPRINTF(("Listing modules overridden by api library:\n")); + for (apilib_api_table* p = apilib->api_tables ; p->target_library ; p++) + { +// DBGPRINTF((" * %s\n", p->target_library)); + add_overridden_module(p->target_library); + } + + //set or update index value which is used by encode_address() + //and to update mod_index in commit_changes() + apilib->index = new_apilib_cnt; + + //add to table of new ApiLibraries + new_apilib_ptrs[new_apilib_cnt++] = apilib; + + DBGPRINTF(("ok\n")); + return true; + +__error: + if (!already_loaded && apilib) + { + if (apilib->mod_handle) + FreeLibrary(apilib->mod_handle); + if (apilib->api_tables) + free(apilib->api_tables); + free(apilib); + } + return false; +} + +ApiLibrary* ApiLibraryManager::get_new_apilib(const char* apilib_name) +{ + for (int i = 0 ; i < new_apilib_cnt ; i++) + if (!strcmp(new_apilib_ptrs[i]->apilib_name, apilib_name)) + return new_apilib_ptrs[i]; + DBGPRINTF(("Api library %s not found\n", apilib_name)); + return NULL; +} + +ApiLibrary* ApiLibraryManager::get_apilib(int index) +{ + if (index < 0 || index >= apilib_cnt) + return NULL; + + DBGASSERT(apilib_ptrs[index]); + DBGASSERT(apilib_ptrs[index]->index == index); + return apilib_ptrs[index]; +} + +bool ApiLibraryManager::are_api_tables_sorted(const apilib_api_table* tab) +{ + for (const apilib_api_table* p = tab ; p->target_library ; p++) + { + if (!::is_sorted(p->named_apis, p->named_apis + p->named_apis_count)) + return false; + + if (!::is_sorted(p->ordinal_apis, p->ordinal_apis + p->ordinal_apis_count)) + return false; + } + return true; +} + +apilib_api_table* ApiLibraryManager::make_shared_api_tables(const apilib_api_table* in) +{ + bool copy_strings = (size_t) in < 0x80000000 ? true : false; + bool sorted = are_api_tables_sorted(in); + + if (!sorted) + { + DBGPRINTF(("Error: api tables are not sorted\n")); + return NULL; + } + + if (!copy_strings && sorted) + { + //nothing bad will happen if I call HeapFree + //on non-HeapAlloc'ed mem later right? + return const_cast(in); + } + + int size = required_api_table_space(in, copy_strings); + apilib_api_table* out = (apilib_api_table*) malloc(size); + + if (!out) + return NULL; + + int i; + char* pstr = (char*) out + size; + + //copy apilib_api_tables + const apilib_api_table* pin; + apilib_api_table* pout; + + for (pin = in, pout = out ; pin->target_library ; pin++, pout++) + { + if (copy_strings) + { + pstr -= strlen(pin->target_library) + 1; + strcpy(pstr, pin->target_library); + pout->target_library = pstr; + } + else + { + pout->target_library = pin->target_library; + } + } + *pout++ = *pin++; //terminating NULL entry + + //copy apilib_named_apis + const apilib_named_api* pina; + apilib_named_api* pona; + pona = (apilib_named_api*) pout; + + for (pin = in, pout = out ; pin->target_library ; pin++, pout++) + { + pout->named_apis = pona; + pout->named_apis_count = pin->named_apis_count; + + for (i = 0, pina = pin->named_apis ; i < pin->named_apis_count ; i++, pina++, pona++) + { + if (copy_strings) + { + pstr -= strlen(pina->name) + 1; + strcpy(pstr, pina->name); + pona->name = pstr; + } + else + { + pona->name = pina->name; + } + pona->addr = pina->addr; + } + } + + //copy apilib_unnamed_apis + const apilib_unnamed_api* piua; + apilib_unnamed_api* poua; + poua = (apilib_unnamed_api*) pona; + + for (pin = in, pout = out ; pin->target_library ; pin++, pout++) + { + pout->ordinal_apis = poua; + pout->ordinal_apis_count = pin->ordinal_apis_count; + + for (i = 0, piua = pin->ordinal_apis ; i < pin->ordinal_apis_count ; i++, piua++, poua++) + { + *poua = *piua; + } + } + +// //sort the tables +// if (!sorted) +// { +// while (pout-- != out) +// { +// stable_sort(pout->named_apis, pout->named_apis + pout->named_apis_count); +// stable_sort(pout->ordinal_apis, pout->ordinal_apis + pout->ordinal_apis_count); +// } +// } + + //finish line + return out; +} + +int ApiLibraryManager::required_api_table_space(const apilib_api_table* tab, bool copy_strings) +{ + int space = 0; + + for (const apilib_api_table* p = tab ; p->target_library ; p++) + { + space += sizeof(apilib_api_table); + space += p->named_apis_count * sizeof(apilib_named_api); + space += p->ordinal_apis_count * sizeof(apilib_unnamed_api); + + if (copy_strings) + { + space += strlen(p->target_library) + 1; + for (int i = 0 ; i < p->named_apis_count ; i++) + space += strlen(p->named_apis[i].name) + 1; + } + } + space += sizeof(apilib_api_table); + + return space; +} + +bool ApiLibraryManager::add_overridden_module(const char* mod) +{ + apilib_api_table*& std_api_table = new_apilib_ptrs[0]->api_tables; + + //ensure that module isn't already on list + for (int i = 0 ; i < new_overridden_mod_cnt ; i++) + { + if (!strcmpi(new_overridden_mod_nms[i], mod)) + return true; + } + + //allocate space for new overridden modules + if (new_overridden_mod_cnt % ALLOC_CAPACITY == 0) + { + void* new_block = realloc(new_overridden_mod_nms, + (new_overridden_mod_cnt + ALLOC_CAPACITY) * sizeof(char*)); + + if (!new_block) + { + DBGPRINTF(("Failed to allocate memory\n")); + return false; + } + + new_overridden_mod_nms = (const char**) new_block; + + new_block = realloc(std_api_table, + (new_overridden_mod_cnt + 1 + ALLOC_CAPACITY) * sizeof(apilib_api_table)); + //+ 1 because api_tables are NULL terminated + + if (!new_block) + { + DBGPRINTF(("Failed to allocate memory\n")); + return false; + } + + std_api_table = (apilib_api_table*) new_block; + } + + if (!parse_system_dll(mod, &std_api_table[new_overridden_mod_cnt])) + return false; + + //add to table of overridden modules + new_overridden_mod_nms[new_overridden_mod_cnt] + = std_api_table[new_overridden_mod_cnt].target_library; + new_overridden_mod_cnt++; + + memset(&std_api_table[new_overridden_mod_cnt], 0, sizeof(apilib_api_table)); + + return true; +} + +bool ApiLibraryManager::parse_system_dll(const char* dll_name, apilib_api_table* api_tab) +{ + PEmanip pemod; + HMODULE mem_dll = GetModuleHandle(dll_name); + + if (mem_dll) + { + if (!pemod.OpenMemory(mem_dll)) + return false; + } + else + { + char path[MAX_PATH]; + GetSystemDirectory(path, sizeof(path)); + strcat(path, "\\"); + strcat(path, dll_name); + + if (!pemod.OpenFile(path)) + return false; + } + + IMAGE_NT_HEADERS* PEh = pemod.GetPEHeader(); + DWORD ExportsRva = PEh->OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress; + + IMAGE_EXPORT_DIRECTORY* Exports = (IMAGE_EXPORT_DIRECTORY*) + pemod.RvaToPointer(ExportsRva); + + DWORD ExportsSize = PEh->OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size; + + if (!Exports || !ExportsSize) + return false; + + DWORD* Names = (DWORD*) pemod.RvaToPointer(Exports->AddressOfNames); + WORD* OrdinalTable = (WORD*) pemod.RvaToPointer(Exports->AddressOfNameOrdinals); + DWORD* FunctionTable = (DWORD*) pemod.RvaToPointer(Exports->AddressOfFunctions); + + unsigned long offset = PEh->OptionalHeader.ImageBase >= 0x80000000 + ? PEh->OptionalHeader.ImageBase : 0; + + //calculate required space + int space = 0; + + space += sizeof(apilib_unnamed_api) * (Exports->NumberOfFunctions + 1); + space += sizeof(apilib_named_api) * (Exports->NumberOfNames + 1); + + DWORD* pname = Names; + for (DWORD i = 0 ; i < Exports->NumberOfNames ; i++) + space += strlen((char*) pemod.RvaToPointer(*pname++)) + 1; + + void* mem = malloc(space); + + if (!mem) + return false; + + char* pstr = (char*) mem + space; + + // read exports by name + apilib_named_api* pna = (apilib_named_api*) mem; + api_tab->named_apis = pna; + api_tab->named_apis_count = Exports->NumberOfNames; + pname = Names; + for (DWORD i = 0 ; i < Exports->NumberOfNames ; i++, pna++) + { + WORD ord = OrdinalTable[i]; + DWORD addr = FunctionTable[ord]; + char* api_name = (char*) pemod.RvaToPointer(*pname++); + + pstr -= strlen(api_name) + 1; + strcpy(pstr, api_name); + pna->name = pstr; + + //export forwarding case + if (addr >= ExportsRva && addr < ExportsRva + ExportsSize) + addr = 0xffff0000 | ord + Exports->Base; + else + addr += offset; + + pna->addr = addr; + } + + // read exports by ordinals + apilib_unnamed_api* pua = (apilib_unnamed_api*) pna; + api_tab->ordinal_apis = pua; + api_tab->ordinal_apis_count = Exports->NumberOfFunctions; + DBGASSERT(Exports->NumberOfFunctions < 0x10000); + + for (DWORD i = 0 ; i < Exports->NumberOfFunctions ; i++, pua++) + { + DWORD addr = FunctionTable[i]; + + pua->ord = (WORD)(Exports->Base + i); + + //export forwarding case + if (addr >= ExportsRva && addr < ExportsRva + ExportsSize) + addr = 0xffff0000 | i + Exports->Base; + else + addr += offset; + + pua->addr = addr; + } + + char* new_mod = (char*) malloc(strlen(dll_name) + 1); + if (!new_mod) + { + DBGPRINTF(("Failed to allocate memory\n")); + return false; + } + strcpy(new_mod, dll_name); + strupr(new_mod); + api_tab->target_library = new_mod; + + return true; +} + +void ApiLibraryManager::rollback_changes() +{ + if (!initialized) + return; + + //STD api library case + //unload new system module override tables api_tables + [overridden_module_count] ; p->target_library ; p++) + free((void*) p->named_apis); //consistent with parse_system_dll + free(new_apilib_ptrs[0]->api_tables); + free(new_apilib_ptrs[0]); + + //other api libraries + for (int i = 1 ; i < new_apilib_cnt ; i++) + { + if (apilib_ptrs) + { + int j; + + for (j = 1 ; j < apilib_cnt ; j++) + if (new_apilib_ptrs[i] == apilib_ptrs[j]) + break; + + if (j != apilib_cnt) + continue; + } + FreeLibrary(new_apilib_ptrs[i]->mod_handle); + free(new_apilib_ptrs[i]->api_tables); + free(new_apilib_ptrs[i]); + } + + free(new_apilib_ptrs); + new_apilib_ptrs = NULL; + new_apilib_cnt = 0; + + for (int i = overridden_module_count ; i < new_overridden_mod_cnt ; i++) + free((void*) new_overridden_mod_nms[i]); + + free(new_overridden_mod_nms); + new_overridden_mod_nms = NULL; + new_overridden_mod_cnt = 0; + + initialized = false; +} + +void ApiLibraryManager::commit_changes() +{ + if (!initialized) + return; + + ApiLibrary** old_apilib_ptrs = apilib_ptrs; + int old_apilib_cnt = apilib_cnt; + + //LOCK ALL CRITICAL SECTIONS! + apilib_ptrs = new_apilib_ptrs; + apilib_cnt = new_apilib_cnt; + free(overridden_module_names); + overridden_module_names = new_overridden_mod_nms; + overridden_module_count = new_overridden_mod_cnt; + + //update old api library mod_index values to new + //set all non-overridden modules to 'not checked' + WORD imteMax = *pimteMax; + IMTE** pmteModTable = *ppmteModTable; + for (WORD i = 0 ; i < imteMax ; i++) + { + IMTE_KEX* imte = (IMTE_KEX*) pmteModTable[i]; + if (imte) + { + WORD index = imte->mod_index; + if (index >= 0xff00 && index < 0xffff) + { + int api_lib_num = index & 0xff; + DBGASSERT(api_lib_num != 0); //reserved for STD apilib + DBGASSERT(api_lib_num >= old_apilib_cnt); + imte->mod_index = old_apilib_ptrs[api_lib_num]->index + 0xff00; + } + else if (index == 0xffff) + imte->mod_index = 0; + } + } + + //set mod_index for newly loaded api libraries + for (int i = 1 ; i < apilib_cnt ; i++) + { + ApiLibrary* apilib = apilib_ptrs[i]; + MODREF* mr = MRFromHLib(apilib->mod_handle); + DBGASSERT(mr); + ((IMTE_KEX*) pmteModTable[mr->mteIndex])->mod_index = 0xff00 + i; + } + //UNLOCK ALL CRITICAL SECTIONS! + + new_overridden_mod_nms = NULL; + new_overridden_mod_cnt = 0; + new_apilib_ptrs = NULL; + new_apilib_cnt = 0; + + //STD api library case + if (old_apilib_cnt > 0) + { + free(old_apilib_ptrs[0]->api_tables); + free(old_apilib_ptrs[0]); + } + + //other api libraries + for (int i = 1 ; i < old_apilib_cnt ; i++) + { + int j; + + for (j = 1 ; j < apilib_cnt ; j++) + if (old_apilib_ptrs[i] == apilib_ptrs[j]) + break; + + if (j != apilib_cnt) + continue; + + FreeLibrary(old_apilib_ptrs[i]->mod_handle); + free(old_apilib_ptrs[i]->api_tables); + free(old_apilib_ptrs[i]); + } + + free(old_apilib_ptrs); + + initialized = false; +} + diff --git a/core/apilib.h b/core/apilib.h new file mode 100644 index 0000000..9e64533 --- /dev/null +++ b/core/apilib.h @@ -0,0 +1,69 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#ifndef __APILIB_H +#define __APILIB_H + +#include "kexcoresdk.h" + +struct ApiLibrary +{ + apilib_api_table* api_tables; + HMODULE mod_handle; + int index; + char apilib_name[1]; // variable size array +}; + +class ApiLibraryManager +{ +public: + ApiLibraryManager(); + ~ApiLibraryManager(); + bool load_apilib(const char* apilib_name); + ApiLibrary* get_new_apilib(const char* apilib_name); + static ApiLibrary* get_apilib(int index); + void commit_changes(); + void rollback_changes(); + +protected: + +private: + bool initialized; + ApiLibrary** new_apilib_ptrs; + int new_apilib_cnt; + + static ApiLibrary** apilib_ptrs; + static int apilib_cnt; + + bool initialize(); + bool are_api_tables_sorted(const apilib_api_table* tab); + apilib_api_table* make_shared_api_tables(const apilib_api_table* in); + int required_api_table_space(const apilib_api_table* tab, bool copy_strings); + bool add_overridden_module(const char* mod); + bool parse_system_dll(const char* dll_name, apilib_api_table* api_tab); +}; + +extern int overridden_module_count; +extern const char** overridden_module_names; +extern const char** new_overridden_mod_nms; +extern int new_overridden_mod_cnt; + +#endif diff --git a/core/core.def b/core/core.def new file mode 100644 index 0000000..05c888a --- /dev/null +++ b/core/core.def @@ -0,0 +1,8 @@ +LIBRARY KernelEx.dll BASE=0xBFA00000 +SECTIONS + .text SHARED + .bss SHARED + .data SHARED + .edata SHARED + .rdata SHARED + .idata SHARED diff --git a/core/core.dsp b/core/core.dsp new file mode 100644 index 0000000..8b34cfd --- /dev/null +++ b/core/core.dsp @@ -0,0 +1,289 @@ +# Microsoft Developer Studio Project File - Name="Core" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=Core - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "core.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "core.mak" CFG="Core - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "Core - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "Core - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "Core - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "KERNELEX_EXPORTS" /YX /FD /c +# ADD CPP /nologo /W3 /O2 /I "." /I "../common" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "KEXCORE_EXPORTS" /YX /FD /GF /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x415 /d "NDEBUG" +# ADD RSC /l 0x415 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib advapi32.lib ..\kexcrt\kexcrt.lib libc.lib /nologo /entry:"PreDllMain@12" /dll /map /machine:I386 /nodefaultlib /out:"Release/KernelEx.dll" /implib:"../common/KernelEx.lib" /ignore:4092 /OPT:NOWIN98 +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "Core - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "KERNELEX_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /ML /W3 /Gm /Zi /Od /I "." /I "../common" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "KEXCORE_EXPORTS" /YX /FD /GZ /GF /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x415 /d "_DEBUG" +# ADD RSC /l 0x415 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib advapi32.lib ..\kexcrt\kexcrt.lib libc.lib /nologo /entry:"PreDllMain@12" /dll /incremental:no /map /debug /machine:I386 /nodefaultlib /out:"Debug/KernelEx.dll" /implib:"../common/KernelEx.lib" /ignore:4092 /OPT:NOWIN98 +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "Core - Win32 Release" +# Name "Core - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\apiconf.cpp +# End Source File +# Begin Source File + +SOURCE=.\apiconfmgr.cpp +# End Source File +# Begin Source File + +SOURCE=.\apilib.cpp +# End Source File +# Begin Source File + +SOURCE=.\core.def + +!IF "$(CFG)" == "Core - Win32 Release" + +# Begin Custom Build +OutDir=.\Release +ProjDir=. +InputPath=.\core.def + +BuildCmds= \ + link /LIB /NOLOGO /MACHINE:IX86 /DEF:$(ProjDir)\k32ord.def /OUT:$(OutDir)\k32ord.lib + +"$(OutDir)\k32ord.lib" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(OutDir)\k32ord.exp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) +# End Custom Build + +!ELSEIF "$(CFG)" == "Core - Win32 Debug" + +# Begin Custom Build +OutDir=.\Debug +ProjDir=. +InputPath=.\core.def + +BuildCmds= \ + link /LIB /NOLOGO /MACHINE:IX86 /DEF:$(ProjDir)\k32ord.def /OUT:$(OutDir)\k32ord.lib + +"$(OutDir)\k32ord.lib" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(OutDir)\k32ord.exp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) +# End Custom Build + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\debug.cpp + +!IF "$(CFG)" == "Core - Win32 Release" + +# PROP Exclude_From_Build 1 + +!ELSEIF "$(CFG)" == "Core - Win32 Debug" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\debugproto.cpp + +!IF "$(CFG)" == "Core - Win32 Release" + +# PROP Exclude_From_Build 1 + +!ELSEIF "$(CFG)" == "Core - Win32 Debug" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\internals.cpp +# End Source File +# Begin Source File + +SOURCE=.\k32ord.def +# PROP Exclude_From_Build 1 +# End Source File +# Begin Source File + +SOURCE=.\kexcoresdk.cpp +# End Source File +# Begin Source File + +SOURCE=.\main.cpp +# End Source File +# Begin Source File + +SOURCE=..\common\pemanip.cpp +# End Source File +# Begin Source File + +SOURCE=.\resolver.cpp +# End Source File +# Begin Source File + +SOURCE=.\SettingsDB.cpp +# End Source File +# Begin Source File + +SOURCE=.\sharedmem.cpp +# End Source File +# Begin Source File + +SOURCE=.\thunks.cpp +# End Source File +# Begin Source File + +SOURCE=.\wildcmp.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\apiconf.h +# End Source File +# Begin Source File + +SOURCE=.\apiconfmgr.h +# End Source File +# Begin Source File + +SOURCE=.\apilib.h +# End Source File +# Begin Source File + +SOURCE=.\debug.h +# End Source File +# Begin Source File + +SOURCE=.\debugproto.h +# End Source File +# Begin Source File + +SOURCE=.\internals.h +# End Source File +# Begin Source File + +SOURCE=..\common\kexcoresdk.h +# End Source File +# Begin Source File + +SOURCE=..\common\pemanip.h +# End Source File +# Begin Source File + +SOURCE=.\resolver.h +# End Source File +# Begin Source File + +SOURCE=.\SettingsDB.h +# End Source File +# Begin Source File + +SOURCE=.\sharedmem.h +# End Source File +# Begin Source File + +SOURCE=.\structs.h +# End Source File +# Begin Source File + +SOURCE=.\thunks.h +# End Source File +# Begin Source File + +SOURCE=.\version.h +# End Source File +# Begin Source File + +SOURCE=.\wildcmp.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# Begin Source File + +SOURCE=.\core.rc +# End Source File +# End Group +# End Target +# End Project diff --git a/core/core.ini b/core/core.ini new file mode 100644 index 0000000..bdaddfa --- /dev/null +++ b/core/core.ini @@ -0,0 +1,32 @@ +[ApiConfigurations] +;configuration 0 is default configuration +default=0 +0=BASE +1=conf1 +2=conf2 + +[BASE] +inherit=none +contents=std,kexbases,kexbasen + +[BASE.names] +KERNEL32.GetVersion=std +KERNEL32.GetAtomNameA=kexbases.1 +KERNEL32.GetComputerNameW=none + +[BASE.ordinals] +KERNEL32.1=none + +[conf1] +inherit=base +contents=none + +[conf1.names] +KERNEL32.GetVersion=kexbases.2 + +[conf2] +inherit=conf1 +contents=none + +[conf2.ordinals] +KERNEL32.1=std diff --git a/core/debug.cpp b/core/debug.cpp new file mode 100644 index 0000000..78c9d97 --- /dev/null +++ b/core/debug.cpp @@ -0,0 +1,56 @@ +/* + * 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. + * + */ + +#include "debug.h" +#include +#include +#include + +#define BUFLEN 256 + +extern "C" +int vsnprintf(char *buffer, size_t n, const char *format, va_list ap); + +void dbgvprintf(const char* format, void* _argp) +{ + char msg[BUFLEN]; + va_list argp = (va_list) _argp; + HANDLE console_out = GetStdHandle(STD_OUTPUT_HANDLE); + int cnt = vsnprintf(msg, sizeof(msg), format, argp); + + if (console_out == INVALID_HANDLE_VALUE) + { + OutputDebugString(msg); + } + else + { + DWORD dummy; + WriteFile(console_out, msg, cnt < 0 ? BUFLEN - 1 : cnt, &dummy, NULL); + } +} + +void dbgprintf(const char* format, ...) +{ + va_list argp; + va_start(argp, format); + dbgvprintf(format, argp); + va_end(argp); +} diff --git a/core/debug.h b/core/debug.h new file mode 100644 index 0000000..91bb831 --- /dev/null +++ b/core/debug.h @@ -0,0 +1,57 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#ifndef __DEBUG_H +#define __DEBUG_H + +#ifndef _DEBUG + +#define DBGPRINTF(x) do { } while (0) +#define DBGASSERT(x) do { } while (0) + +#else + +#define DBGPRINTF(x) dbgprintf x +#define DBGASSERT(x) \ + if (!(x)) \ + do \ + { \ + dbgprintf("ASSERTION FAILED: file: %s, line: %d\n", __FILE__, __LINE__); \ + DebugBreak(); \ + } \ + while (0) + +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + +void dbgvprintf(const char* format, void* _argp); +void dbgprintf(const char* format, ...); + +#ifdef __cplusplus +}; /* extern "C" */ +#endif + + +#endif diff --git a/core/debugproto.cpp b/core/debugproto.cpp new file mode 100644 index 0000000..a7a7936 --- /dev/null +++ b/core/debugproto.cpp @@ -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. + * + */ + +#include "debugproto.h" +#include +#include "apiconfmgr.h" +#include "resolver.h" +#include "SettingsDB.h" + +void kexDbgDumpConfigurations(void) +{ + ApiConfigurationManager::dump_configurations(); +} + +void kexDbgDumpImtes(void) +{ + dump_imtes(); +} + +void kexDbgDumpAppSettings(void) +{ + SettingsDB::instance.dump_db(); +} diff --git a/core/debugproto.h b/core/debugproto.h new file mode 100644 index 0000000..802c09a --- /dev/null +++ b/core/debugproto.h @@ -0,0 +1,48 @@ +/* + * 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. + * + */ + +#ifndef __DEBUGPROTO_H +#define __DEBUGPROTO_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef KEXCORE_EXPORTS +#define _KEXCOREIMP __declspec(dllexport) +#else +#define _KEXCOREIMP __declspec(dllimport) +#endif + + +_KEXCOREIMP int kexInit(void); +_KEXCOREIMP int kexUninit(void); +_KEXCOREIMP void kexDbgDumpConfigurations(void); +_KEXCOREIMP void kexDbgDumpImtes(void); +_KEXCOREIMP void kexDbgDumpAppSettings(void); + + +#ifdef __cplusplus +}; /* extern "C" */ +#endif + + +#endif diff --git a/core/internals.cpp b/core/internals.cpp new file mode 100644 index 0000000..0d6c7db --- /dev/null +++ b/core/internals.cpp @@ -0,0 +1,505 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#include +#include +#include "internals.h" +#include +#include "resolver.h" +#include "debug.h" +#include "pemanip.h" + +static bool is_winme; + +IMTE*** ppmteModTable = NULL; +HMODULE h_kernel32; +CRITICAL_SECTION* krnl32lock = NULL; +PDB98** pppdbCur = NULL; +WORD* pimteMax = NULL; + +MRFromHLib_t MRFromHLib = NULL; +TIDtoTDB_t TIDtoTDB = NULL; +PIDtoPDB_t PIDtoPDB = NULL; +MRLoadTree_t MRLoadTree = NULL; +FreeLibTree_t FreeLibTree = NULL; +FLoadTreeNotify_t FLoadTreeNotify = NULL; +FreeLibRemove_t FreeLibRemove = NULL; + +sstring kernelex_dir(""); +sstring own_path(""); + +HANDLE fullcritlock_hndl = NULL; + +//FIXME: CreateToolhelp32Snapshot + Process32First/Next should be replaced by +// plstPdb + PnodGetLstElem() + SetLstCurElem() (see DumpProcesses()) +void FullCritLock() +{ + PROCESSENTRY32 pe; + BOOL result; + + DBGPRINTF(("FullCritLock\n")); + if (fullcritlock_hndl) + { + DBGPRINTF(("Error: lock already acquired\n")); + return; + } + + _EnterSysLevel(krnl32lock); + fullcritlock_hndl = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + DBGASSERT(fullcritlock_hndl != INVALID_HANDLE_VALUE); + + pe.dwSize = sizeof(pe); + result = Process32First(fullcritlock_hndl, &pe); + DBGASSERT(result != FALSE); + do + { + PDB98* pdb; + pdb = PIDtoPDB(pe.th32ProcessID); + _EnterSysLevel(&pdb->CriticalSection); + } + while (Process32Next(fullcritlock_hndl, &pe)); +} + +void FullCritUnlock() +{ + PROCESSENTRY32 pe; + BOOL result; + + if (!fullcritlock_hndl) + { + DBGPRINTF(("Error: not locked\n")); + return; + } + + pe.dwSize = sizeof(pe); + result = Process32First(fullcritlock_hndl, &pe); + DBGASSERT(result != FALSE); + do + { + PDB98* pdb; + pdb = PIDtoPDB(pe.th32ProcessID); + _LeaveSysLevel(&pdb->CriticalSection); + } + while (Process32Next(fullcritlock_hndl, &pe)); + + CloseHandle(fullcritlock_hndl); + fullcritlock_hndl = NULL; + + _LeaveSysLevel(krnl32lock); + DBGPRINTF(("FullCritUnlock\n")); +} + +bool isWinMe() +{ + return is_winme; +} + +void ShowError(UINT id, ...) +{ + char format[512]; + char out[512]; + va_list vargs; + + va_start(vargs, id); + if (!LoadString(GetModuleHandle(NULL), id, format, sizeof(format))) + sprintf(out, "ERROR: Missing string resource %d", id); + else + _vsnprintf(out, sizeof(out), format, vargs); + va_end(vargs); + MessageBox(NULL, out, "KernelEx Core", MB_OK | MB_ICONERROR); +} + +DWORD* find_unique_pattern(void* start, int size, const short* pattern, int pat_len, const char* pat_name) +{ + unsigned char* pos = (unsigned char*) start; + unsigned char* end_pos = pos + size - pat_len; + unsigned char* found_loc = NULL; + int found = 0; + + while (pos <= end_pos) + { + if (pattern[0] < 0 || *pos == pattern[0]) + { + int j; + for (j = 1 ; j < pat_len ; j++) + { + if (pattern[j] >= 0 && pos[j] != pattern[j]) + break; + } + if (j == pat_len) //pattern found + { + found++; + if (!found_loc) + found_loc = pos; + } + } + pos++; + } + + if (found != 1) + { + if (!found) + DBGPRINTF(("%s: pattern not found\n", pat_name)); + else + DBGPRINTF(("%s: pattern not unique, found occurrences: %d\n", pat_name, found)); + return NULL; + } + + for (int i = 0 ; i < pat_len ; i++) + if (pattern[i] == -2) + return (DWORD*) &found_loc[i]; + + DBGPRINTF(("%s: invalid pattern\n", pat_name)); + return NULL; +} + +static DWORD decode_calljmp(DWORD* addr) +{ + unsigned char* code = (unsigned char*)addr; + + if (code[-1] == 0xe8 || code[-1] == 0xe9) /* call/jmp rel32 */ + { + return (DWORD)(code + 4 + *(DWORD*)code); + } + else if (code[-2] == 0xff + && (code[-1] == 0x15 || code[-1] == 0x25)) /* call/jmp m32 */ + { + return *(DWORD*)code; + } + else if (code[-1] == 0xeb) /* jmp rel8 */ + { + return (DWORD)(code + 1 + *(char*)code); + } + else return 0; +} + +MODREF* MRfromCallerAddr(DWORD addr) +{ + MODREF* mr; + PDB98* ppdbCur = *pppdbCur; + IMTE** pmteModTable = *ppmteModTable; + + mr = ppdbCur->pExeMODREF; + if (mr) + { + IMTE* imte = pmteModTable[mr->mteIndex]; + IMAGE_NT_HEADERS* nthdr = imte->pNTHdr; + DWORD img_base = nthdr->OptionalHeader.ImageBase; + if (addr >= img_base && addr < img_base + nthdr->OptionalHeader.SizeOfImage) + return mr; + } + mr = ppdbCur->MODREFList; + if (mr) + { + do + { + IMTE* imte = pmteModTable[mr->mteIndex]; + IMAGE_NT_HEADERS* nthdr = imte->pNTHdr; + DWORD img_base = nthdr->OptionalHeader.ImageBase; + if (addr >= img_base && addr < img_base + nthdr->OptionalHeader.SizeOfImage) + return mr; + mr = mr->pNextModRef; + } + while (mr); + } + return NULL; +} + +/* find win32 mutex */ +static CRITICAL_SECTION* find_krnl32lock() +{ + CRITICAL_SECTION* ret; + + const char* pat_name = "Win32 lock"; + short pat[] = {0x55,0xA1,-2,-2,-2,-2,0x8B,0xEC,0x56,0x57,0x33,0xF6,0x50,0xE8}; + int pat_len = sizeof(pat) / sizeof(short); + + DWORD* res = find_unique_pattern(iGetProcAddress(h_kernel32, "VirtualQueryEx"), pat_len, pat, pat_len, pat_name); + if (!res) + return NULL; + + ret = *(CRITICAL_SECTION**)*res; + DBGPRINTF(("%s @ 0x%08x\n", pat_name, ret)); + return ret; +} + +/* find current process PDB */ +static PDB98** find_curPDB() +{ + PDB98** ret; + + const char* pat_name = "pppdbCur"; + short pat[] = {0xA1,-2,-2,-2,-2,0xFF,0x30,0xE8,-1,-1,-1,-1,0xC3}; + int pat_len = sizeof(pat) / sizeof(short); + + DWORD* res = find_unique_pattern(iGetProcAddress(h_kernel32, "GetCurrentProcessId"), pat_len, pat, pat_len, pat_name); + if (!res) + return NULL; + + ret = *(PDB98***)*res; + DBGPRINTF(("%s @ 0x%08x\n", pat_name, ret)); + return ret; +} + +/* find global module tables */ +static IMTE*** find_mod_table() +{ + IMTE*** ret; + + const char* pat_name = "Module table"; + short pat[] = {0x8B,0x0D,-2,-2,-2,-2}; + int pat_len = sizeof(pat) / sizeof(short); + + DWORD* res = find_unique_pattern(iGetProcAddress(h_kernel32, (LPSTR)23), 0x20, pat, pat_len, pat_name); + + ret = (IMTE***)*res; + DBGPRINTF(("%s @ 0x%08x\n", pat_name, ret)); + return ret; +} + +static MRFromHLib_t find_MRFromHLib() +{ + MRFromHLib_t ret; + + const char* pat_name = "MRFromHLib"; + short pat[] = {0xE8,-2,-2,-2,-2}; + int pat_len = sizeof(pat) / sizeof(short); + + DWORD* res = find_unique_pattern(iGetProcAddress(h_kernel32, (LPSTR)23), 0x20, pat, pat_len, pat_name); + if (!res) + return NULL; + + ret = (MRFromHLib_t)decode_calljmp(res); + DBGPRINTF(("%s @ 0x%08x\n", pat_name, ret)); + return ret; +} + +static WORD* find_pimteMax() +{ + WORD* ret; + PEmanip pe(h_kernel32); + if (!pe.HasTarget()) + return NULL; + + const char* pat_name = "pimteMax"; + short pat[] = {0x66,0x8B,0x44,0x24,0x04,0x66,-1,0x05,-2,-2,-2,-2,-1,0x17,0x8B,0x0D,-1,-1,-1,-1,0x0F,0xBF,0xC0,0x8B,0x04,0x81,0x85,0xC0,0x74,0x07,0x8B,0x40,0x04,0x85,0xC0,0x75,0x09}; + int pat_len = sizeof(pat) / sizeof(short); + const char* sec_name = ".text"; + + DWORD* res = find_unique_pattern(pe.GetSectionByName(sec_name), pe.GetSectionSize(sec_name), pat, pat_len, pat_name); + if (!res) + return NULL; + + ret = (WORD*) *res; + DBGPRINTF(("%s @ 0x%08x\n", pat_name, ret)); + return ret; +} + +static TIDtoTDB_t find_TIDtoTDB() +{ + TIDtoTDB_t ret; + PEmanip pe(h_kernel32); + if (!pe.HasTarget()) + return NULL; + + const char* pat_name = "TIDtoTDB"; + short pat[] = {0x89,-1,0xFF,0x75,0xFC,0xFF,0x77,0x14,0xE8,-2,-2,-2,-2,0x50}; + int pat_len = sizeof(pat) / sizeof(short); + const char* sec_name = ".text"; + + DWORD* res = find_unique_pattern(pe.GetSectionByName(sec_name), pe.GetSectionSize(sec_name), pat, pat_len, pat_name); + if (!res) + return NULL; + + ret = (TIDtoTDB_t)decode_calljmp(res); + DBGPRINTF(("%s @ 0x%08x\n", pat_name, ret)); + return ret; +} + +static PIDtoPDB_t find_PIDtoPDB() +{ + PIDtoPDB_t ret; + + const char* pat_name = "PIDtoPDB"; + short pat[] = {0xFF,0x74,0x24,0x0C,0xE8,-2,-2,-2,-2}; + int pat_len = sizeof(pat) / sizeof(short); + + DWORD* res = find_unique_pattern(iGetProcAddress(h_kernel32, "OpenProcess"), pat_len, pat, pat_len, pat_name); + if (!res) + return NULL; + + ret = (PIDtoPDB_t)decode_calljmp(res); + DBGPRINTF(("%s @ 0x%08x\n", pat_name, ret)); + return ret; +} + +static MRLoadTree_t find_MRLoadTree() +{ + MRLoadTree_t ret; + PEmanip pe(h_kernel32); + if (!pe.HasTarget()) + return NULL; + + const char* pat_name = "MRLoadTree"; + short pat[] = {0x33,0xF6,0xE8,-1,-1,-1,-1,0x39,0x35,-1,-1,-1,-1,0x74,0x11,0xA1,-1,-1,-1,-1,0x50,0xE8,-1,-1,-1,-1,0x89,0x35,-1,-1,-1,-1,0xFF,0x74,0x24,0x14,0xE8,-2,-2,-2,-2,0x8B,0xF0,0x85,0xF6}; + int pat_len = sizeof(pat) / sizeof(short); + const char* sec_name = ".text"; + + DWORD* res = find_unique_pattern(pe.GetSectionByName(sec_name), pe.GetSectionSize(sec_name), pat, pat_len, pat_name); + if (!res) + return NULL; + + ret = (MRLoadTree_t)decode_calljmp(res); + DBGPRINTF(("%s @ 0x%08x\n", pat_name, ret)); + return ret; +} + +static FreeLibTree_t find_FreeLibTree() +{ + FreeLibTree_t ret; + + const char* pat_name = "FreeLibTree"; + short pat[] = {0x75,0x09,0x6A,0x06,0xE8,-1,-1,-1,-1,0xEB,0x08,0x50,0xE8,-2,-2,-2,-2,0x8B,0xF0}; + int pat_len = sizeof(pat) / sizeof(short); + + DWORD* res = find_unique_pattern(iGetProcAddress(h_kernel32, "FreeLibrary"), 0x80, pat, pat_len, pat_name); + if (!res) + return NULL; + + ret = (FreeLibTree_t)decode_calljmp(res); + DBGPRINTF(("%s @ 0x%08x\n", pat_name, ret)); + return ret; +} + +static FLoadTreeNotify_t find_FLoadTreeNotify() +{ + FLoadTreeNotify_t ret; + PEmanip pe(h_kernel32); + if (!pe.HasTarget()) + return NULL; + + const char* pat_name = "FLoadTreeNotify"; + short pat[] = {0x56,0xA1,-1,-1,-1,-1,0x6A,0x01,0x8B,0x08,0xFF,0xB1,0x98,0x00,0x00,0x00,0xE8,-2,-2,-2,-2,0x83,0xF8,0x01,0x1B,0xF6,0xF7,0xDE,0x85,0xF6}; + int pat_len = sizeof(pat) / sizeof(short); + const char* sec_name = ".text"; + + DWORD* res = find_unique_pattern(pe.GetSectionByName(sec_name), pe.GetSectionSize(sec_name), pat, pat_len, pat_name); + if (!res) + return NULL; + + ret = (FLoadTreeNotify_t)decode_calljmp(res); + DBGPRINTF(("%s @ 0x%08x\n", pat_name, ret)); + return ret; +} + +static FreeLibRemove_t find_FreeLibRemove() +{ + FreeLibRemove_t ret; + PEmanip pe(h_kernel32); + if (!pe.HasTarget()) + return NULL; + + const char* pat_name = "FreeLibRemove"; + short pat[] = {0x8B,0xF0,0x85,0xF6,0x75,0x05,0xE8,-2,-2,-2,-2,0xA1,-1,-1,-1,-1,0x50}; + int pat_len = sizeof(pat) / sizeof(short); + const char* sec_name = ".text"; + + DWORD* res = find_unique_pattern(pe.GetSectionByName(sec_name), pe.GetSectionSize(sec_name), pat, pat_len, pat_name); + if (!res) + return NULL; + + ret = (FreeLibRemove_t)decode_calljmp(res); + DBGPRINTF(("%s @ 0x%08x\n", pat_name, ret)); + return ret; +} + +static bool find_kernelex_install_dir() +{ + //registry value InstallDir is written by the installer + HKEY key; + DWORD type; + char path[MAX_PATH]; + DWORD len = sizeof(path); + DWORD attr; + long result; + + result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\KernelEx", + 0, KEY_QUERY_VALUE, &key); + if (result != ERROR_SUCCESS) + { + DBGPRINTF(("Failed to open KernelEx registry key\n")); + return false; + } + + result = RegQueryValueEx(key, "InstallDir", NULL, &type, + (BYTE*)path, &len); + RegCloseKey(key); + if (result != ERROR_SUCCESS || type != REG_SZ || len == 0) + { + DBGPRINTF(("Failed to read InstallDir registry value\n")); + return false; + } + + if (path[strlen(path) - 1] == '\\') + path[strlen(path) - 1] = '\0'; + + attr = GetFileAttributes(path); + if (attr == 0xffffffff || !(attr & FILE_ATTRIBUTE_DIRECTORY)) + { + DBGPRINTF(("KernelEx directory [%s] doesn't exist\n", path)); + return false; + } + + DBGPRINTF(("KernelEx directory: %s\n", path)); + strcat(path, "\\"); + kernelex_dir = path; + return true; +} + +int internals_init() +{ + DBGPRINTF(("internals_init()\n")); + h_kernel32 = GetModuleHandle("kernel32"); + ppmteModTable = find_mod_table(); + krnl32lock = find_krnl32lock(); + pppdbCur = find_curPDB(); + MRFromHLib = find_MRFromHLib(); + pimteMax = find_pimteMax(); + TIDtoTDB = find_TIDtoTDB(); + PIDtoPDB = find_PIDtoPDB(); + MRLoadTree = find_MRLoadTree(); + FreeLibTree = find_FreeLibTree(); + FLoadTreeNotify = find_FLoadTreeNotify(); + FreeLibRemove = find_FreeLibRemove(); + bool instdir_rslt = find_kernelex_install_dir(); + is_winme = (GetVersion() == 0xc0005a04); + + if (!h_kernel32 || !ppmteModTable || !krnl32lock || !pppdbCur || !MRFromHLib + || !pimteMax || !TIDtoTDB || !PIDtoPDB || !MRLoadTree || !FreeLibTree + || !FLoadTreeNotify || !FreeLibRemove || !instdir_rslt) + return 0; + return 1; +} + +void internals_uninit() +{ + DBGPRINTF(("internals_uninit()\n")); +} diff --git a/core/internals.h b/core/internals.h new file mode 100644 index 0000000..d651e86 --- /dev/null +++ b/core/internals.h @@ -0,0 +1,100 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#ifndef __INTERNALS_H +#define __INTERNALS_H + +#include "structs.h" +#include "sharedmem.h" +#include "sstring.hpp" +#include "resource.h" + +/** MSVC for-loop workaround. */ +#ifdef _MSC_VER +#if _MSC_VER < 1201 +#define for if (0); else for +#endif +#endif + +extern IMTE*** ppmteModTable; +extern HMODULE h_kernel32; +extern CRITICAL_SECTION* krnl32lock; +extern PDB98** pppdbCur; +extern WORD* pimteMax; + +extern sstring kernelex_dir; +extern sstring own_path; + +void FullCritLock(); +void FullCritUnlock(); +void ShowError(UINT id, ...); +bool isWinMe(); + +typedef MODREF* (__stdcall *MRFromHLib_t)(HMODULE); +typedef TDB98* (__stdcall *TIDtoTDB_t)(DWORD); +typedef PDB98* (__stdcall *PIDtoPDB_t)(DWORD); +typedef MODREF* (__stdcall * MRLoadTree_t)(LPCSTR); +typedef BOOL (__stdcall * FreeLibTree_t)(MODREF*); +typedef BOOL (__stdcall * FLoadTreeNotify_t)(MODREF*, BOOL); +typedef VOID (__stdcall * FreeLibRemove_t)(VOID); + +extern MRFromHLib_t MRFromHLib; + +/** Convert Thread ID into pointer to Thread Database. + * @param tid Thread ID. + * @return Pointer to Thread Database. + */ +extern TIDtoTDB_t TIDtoTDB; + +/** Convert Process ID into pointer to Process Database. + * @param pid Process ID. + * @return Pointer to Process Database. + */ +extern PIDtoPDB_t PIDtoPDB; + +extern MRLoadTree_t MRLoadTree; +extern FreeLibTree_t FreeLibTree; +extern FLoadTreeNotify_t FLoadTreeNotify; +extern FreeLibRemove_t FreeLibRemove; + +MODREF* MRfromCallerAddr(DWORD addr); + +#ifdef __cplusplus +extern "C" { +#endif + +void __stdcall _EnterSysLevel(CRITICAL_SECTION*); +void __stdcall _LeaveSysLevel(CRITICAL_SECTION*); + +ULONG __stdcall VxDCall1(ULONG); +ULONG __stdcall VxDCall2(ULONG, ULONG); +ULONG __stdcall VxDCall3(ULONG, ULONG, ULONG); +ULONG __stdcall VxDCall4(ULONG, ULONG, ULONG, ULONG); +ULONG __stdcall VxDCall5(ULONG, ULONG, ULONG, ULONG, ULONG); +ULONG __stdcall VxDCall6(ULONG, ULONG, ULONG, ULONG, ULONG, ULONG); +ULONG __stdcall VxDCall7(ULONG, ULONG, ULONG, ULONG, ULONG, ULONG, ULONG); +ULONG __stdcall VxDCall8(ULONG, ULONG, ULONG, ULONG, ULONG, ULONG, ULONG, ULONG); + +#ifdef __cplusplus +}; +#endif + +#endif diff --git a/core/k32ord.def b/core/k32ord.def new file mode 100644 index 0000000..a21814b --- /dev/null +++ b/core/k32ord.def @@ -0,0 +1,14 @@ +LIBRARY KERNEL32.dll + +EXPORTS + CommonUnimpStub@0 @17 NONAME + VxDCall1@4 @1 NONAME + VxDCall2@8 @2 NONAME + VxDCall3@12 @3 NONAME + VxDCall4@16 @4 NONAME + VxDCall5@20 @5 NONAME + VxDCall6@24 @6 NONAME + VxDCall7@28 @7 NONAME + VxDCall8@32 @8 NONAME + _EnterSysLevel@4 @97 NONAME + _LeaveSysLevel@4 @98 NONAME diff --git a/core/kexcoresdk.cpp b/core/kexcoresdk.cpp new file mode 100644 index 0000000..0cb578a --- /dev/null +++ b/core/kexcoresdk.cpp @@ -0,0 +1,87 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#include +#include "version.h" +#include +#include "kexcoresdk.h" +#include "resolver.h" +#include "internals.h" +#include "SettingsDB.h" +#include "debug.h" + +unsigned long kexGetKEXVersion() +{ + return VERSION_CODE; +} + +void kexDebugPrint(const char* format, ...) +{ +#ifdef _DEBUG + va_list argp; + va_start(argp, format); + dbgvprintf(format, argp); + va_end(argp); +#endif +} + +DWORD kexGetVersion() +{ + return GetVersion(); +} + +PROC kexGetProcAddress(HMODULE hModule, PCSTR lpProcName) +{ + return iGetProcAddress(hModule, lpProcName); +} + +void* kexPIDtoPDB(DWORD pid) +{ + return PIDtoPDB(pid); +} + +void* kexTIDtoTDB(DWORD tid) +{ + return TIDtoTDB(tid); +} + +void kexGetModuleSettings(const char* module, + char* conf_name, BYTE* ldr_flags) +{ + appsetting as = SettingsDB::instance.get_appsetting(module); + if (!as.conf) + strcpy(conf_name, "default"); + else + strncpy(conf_name, as.conf->get_name(), 256); + *ldr_flags = as.flags; + conf_name[255] = '\0'; +} + +void kexSetModuleSettings(const char* module, + const char* conf_name, BYTE ldr_flags) +{ + SettingsDB::instance.write_single(module, conf_name, ldr_flags); +} + +void kexFlushAppSettings(void) +{ + SettingsDB::instance.flush_all(); +} diff --git a/core/main.cpp b/core/main.cpp new file mode 100644 index 0000000..89485e9 --- /dev/null +++ b/core/main.cpp @@ -0,0 +1,217 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#include +#include "version.h" +#include "kexcoresdk.h" +#include "debug.h" +#include "apiconfmgr.h" +#include "internals.h" + +extern int internals_init(); +extern void internals_uninit(); +extern int resolver_init(); +extern void resolver_uninit(); +extern void resolver_hook(); +extern void resolver_unhook(); + +static int init_count = 0; + +static void prepare() +{ + ApiConfigurationManager acm; + acm.reload_api_configurations(); +} + +//these should be visible only in debug builds +#ifdef _DEBUG +extern "C" _KEXCOREIMP +#endif +int kexInit() +{ + if (init_count > 0) + return ++init_count; + + DBGPRINTF(("KernelEx Core v%s by Xeno86\n", VERSION_STR)); + DBGPRINTF(("Initializing...\n")); + + if (!internals_init()) + goto __error1; + + prepare(); + + if (!resolver_init()) + goto __error2; + + resolver_hook(); + + DBGPRINTF(("Initialized successfully\n")); + return ++init_count; + +__error2: + internals_uninit(); +__error1: + DBGPRINTF(("Initialization failure\n")); + return 0; +} + +//these should be visible only in debug builds +#ifdef _DEBUG +extern "C" _KEXCOREIMP +#endif +int kexUninit() +{ + if (init_count == 0) + return 0; + if (init_count > 1) + return --init_count; + + DBGPRINTF(("Uninitializing\n")); + resolver_unhook(); + resolver_uninit(); + internals_uninit(); + return --init_count; +} + +extern "C" _KEXCOREIMP +DWORD WINAPI MprStart(LPVOID) +{ + return 0; +} + +/** Check if loaded into shared memory area. + * @param addr Address to which loaded. + * @return TRUE if loaded to shared memory, FALSE otherwise. + */ +static bool ensure_shared_memory(DWORD addr) +{ + if (addr < 0x80000000) + { + MessageBox(NULL, "KernelEx not loaded into shared memory!", + "Critical Error", MB_ICONERROR | MB_OK); + return false; + } + return true; +} + +static bool is_failsafe_mode() +{ + return GetSystemMetrics(SM_CLEANBOOT) != 0; +} + +static int load_count(DWORD addr) +{ + if (!ppmteModTable) + return 1; + IMTE** pmteModTable = *ppmteModTable; + return pmteModTable[MRfromCallerAddr(addr)->mteIndex]->cUsage; +} + +static void get_own_path(HMODULE base) +{ + char path[MAX_PATH]; + GetModuleFileName(base, path, sizeof(path)); + own_path = path; +} + +static bool detect_old_version() +{ + typedef void (WINAPI *KV_t)(char *); + KV_t h_KVersion; + char buf[32]; + + h_KVersion = (KV_t)GetProcAddress(GetModuleHandle("kernel32"), "KUPVersion"); + if (!h_KVersion) + h_KVersion = (KV_t)GetProcAddress(GetModuleHandle("kernel32"), "KEXVersion"); + if (!h_KVersion) + return false; + h_KVersion(buf); + ShowError(IDS_OLDVER, buf); + return true; +} + +/** CRT startup routine declaration. */ +extern "C" +BOOL WINAPI _DllMainCRTStartup(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved); + +/** Pre-init code executed before CRT startup code. */ +extern "C" +BOOL APIENTRY PreDllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) +{ + BOOL ret = TRUE; + + if (reason == DLL_PROCESS_ATTACH) + { + if (!ensure_shared_memory((DWORD)instance)) + return FALSE; + + if (is_failsafe_mode()) + return FALSE; + + DisableThreadLibraryCalls(instance); + + if (load_count((DWORD) instance) == 1) + { + if (detect_old_version()) + return FALSE; + + //very important - without this memory allocation won't work + if (!create_shared_heap()) + return FALSE; + + //we are in shared memory so CRT init code should be called only once + //globally (by default it would be called on every process attach) + ret = _DllMainCRTStartup(instance, reason, reserved); + + get_own_path(instance); + } + } + else if (reason == DLL_PROCESS_DETACH) + { + if (load_count((DWORD) instance) == 1) + { + ret = _DllMainCRTStartup(instance, reason, reserved); + destroy_shared_heap(); + } + } + + return ret; +} + +/** Entry point. Called by CRT startup code. */ +extern "C" +BOOL APIENTRY DllMain(HINSTANCE instance, DWORD reason, BOOL load_static) +{ + if (reason == DLL_PROCESS_ATTACH && GetModuleHandle("MPREXE.EXE")) + { + return kexInit(); + } + + //for additional safety - auto uninit on core unload + if (reason == DLL_PROCESS_DETACH + && load_count((DWORD) instance) == 1 && init_count > 0) + { + init_count = 1; + kexUninit(); + } + return TRUE; +} + diff --git a/core/resolver.cpp b/core/resolver.cpp new file mode 100644 index 0000000..fd415a7 --- /dev/null +++ b/core/resolver.cpp @@ -0,0 +1,676 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#include +#include +#include "debug.h" +#include "resolver.h" +#include "apiconf.h" +#include "apiconfmgr.h" +#include "internals.h" +#include "../setup/loadstub.h" +#include "thunks.h" +#include "SettingsDB.h" + +using namespace std; + +char system_path[MAX_PATH]; +int system_path_len; + +static PLONG jtab; +static LONG old_jtab[4]; + + +/** Get API configuration for selected module. + * @param module Target module. + * @return Pointer to API configuration or NULL to not use extended API. + */ +static ApiConfiguration* get_config(MODREF* moduleMR) +{ + IMTE** pmteModTable = *ppmteModTable; + PDB98* ppdbCur = *pppdbCur; + IMTE_KEX* module = (IMTE_KEX*) pmteModTable[moduleMR->mteIndex]; + IMTE_KEX* process = (IMTE_KEX*) pmteModTable[ppdbCur->pExeMODREF->mteIndex]; + ApiConfiguration* conf; + BYTE flags; + + //unless override flag is set try to get module configuration first + if (!(process->flags & LDR_OVERRIDE_PROC_MOD)) + { + if (!(module->flags & LDR_VALID_FLAG)) + { + appsetting as = SettingsDB::instance.get_appsetting(module->pszFileName); + module->config = as.conf; + module->flags = as.flags | LDR_VALID_FLAG; + } + conf = module->config; + flags = module->flags; + + if (flags & LDR_KEX_DISABLE) + return NULL; + } + else + conf = NULL; + + //if above failed or override flag was set try to get process configuration + if (!conf) + { + if (!(process->flags & LDR_VALID_FLAG)) + { + appsetting as = SettingsDB::instance.get_appsetting(process->pszFileName); + process->config = as.conf; + process->flags = as.flags | LDR_VALID_FLAG; + } + conf = process->config; + flags = process->flags; + + if (flags & LDR_KEX_DISABLE) + return NULL; + } + + //if no process configuration then get parent configuration + if (!conf) + { + PDB98* ppdbParent = ppdbCur->ParentPDB; + + if (ppdbParent && !(ppdbParent->Flags & (fTerminated | fTerminating | + fNearlyTerminating | fDosProcess | fWin16Process))) + { + IMTE_KEX* parent = (IMTE_KEX*) pmteModTable[ppdbParent->pExeMODREF->mteIndex]; + conf = parent->config; + flags = parent->flags; + + if (flags & LDR_KEX_DISABLE) + return NULL; + } + } + + if (flags & LDR_LOG_APIS) + { + //TODO: not implemented yet + DBGPRINTF(("Resolver flag LDR_LOG_APIS not implemented\n")); + } + + if (flags & LDR_FILTER_APIS) + { + //TODO: not implemented yet + DBGPRINTF(("Resolver flag LDR_FILTER_APIS not implemented\n")); + } + + //finally if everything else fails take default configuration + if (!conf) + conf = ApiConfigurationManager::get_default_configuration(); + + return conf; +} + +/** Finds overridden module index for target module. + * @param target Module from which functions are imported. + * @return Index or 0xffff if module doesn't have entry in API configuration tables. + */ +static WORD resolve_mod_index(IMTE_KEX* target) +{ + const char* file_name; + + /* Skip non-system modules */ + if (target->cbFileName - target->cbModName - 1 != system_path_len + || strncmp(system_path, target->pszFileName, system_path_len)) + return target->mod_index = 0xffff; + + file_name = target->pszModName; + + for (int i = 0 ; i < overridden_module_count ; i++) + if (strcmp(file_name, overridden_module_names[i]) == 0) + return target->mod_index = i + 1; + + /* No override API list for target module available. */ + return target->mod_index = 0xffff; +} + +static PROC resolve_nonshared_addr(DWORD addr, MODREF* caller, PMODREF** refmod) +{ + MODREF* mr; + WORD idx; + DWORD img_base; + int api_lib_num; + char dllpath[MAX_PATH]; + ApiLibrary* apilib; + IMTE** pmteModTable = *ppmteModTable; + static MODREF* buffer[1024]; + + DBGASSERT(addr >= 0xc0000000); + api_lib_num = (addr >> 24) - 0xc0; + DBGASSERT(api_lib_num > 0); //ensure apilib ID isn't STD's + apilib = ApiLibraryManager::get_apilib(api_lib_num); + DBGASSERT(apilib != NULL); + DBGASSERT((DWORD) apilib->mod_handle < 0x80000000); + idx = 0xff00 + api_lib_num; + + //first check if api library has already been loaded + mr = (*pppdbCur)->MODREFList; + do + { + IMTE_KEX* imte = (IMTE_KEX*) pmteModTable[mr->mteIndex]; + if (imte->mod_index == idx) + { + IMAGE_NT_HEADERS* nthdr = imte->pNTHdr; + img_base = nthdr->OptionalHeader.ImageBase; + return (PROC)(img_base + (addr & 0x00ffffff)); + } + mr = mr->pNextModRef; + } + while (mr); + + //if not - load it + + strcpy(dllpath, kernelex_dir.get()); + strcat(dllpath, apilib->apilib_name); + + _EnterSysLevel(krnl32lock); + mr = MRLoadTree(dllpath); + if (!mr) + { + FreeLibRemove(); + _LeaveSysLevel(krnl32lock); + return 0; + } + _LeaveSysLevel(krnl32lock); + + if (refmod) //static resolve (implicit) + { + for (int i = 0 ; i < caller->cImportedModules ; i++) + buffer[i] = caller->ImplicitImports[i].pMR; + + //FIXME: this will cause problems if apilib references another non-shared apilib!! + //it is okay to use global buffer because static resolve code is protected by k32 lock + **refmod = mr; + *refmod += buffer - &caller->ImplicitImports[0].pMR; + } + else //dynamic resolve (GetProcAddress) + { + if (FLoadTreeNotify(mr, 0)) + { + FreeLibTree(mr); + return 0; + } + } + + IMTE_KEX* imte = (IMTE_KEX*) pmteModTable[mr->mteIndex]; + + img_base = imte->pNTHdr->OptionalHeader.ImageBase; + + if (img_base == (DWORD) apilib->mod_handle) + DBGASSERT(imte->mod_index == apilib->index + 0xff00); + + imte->mod_index = idx; + + return (PROC)(img_base + (addr & 0x00ffffff)); +} + +static PROC WINAPI OriExportFromOrdinal(IMAGE_NT_HEADERS* PEh, WORD ordinal) +{ + DWORD img_base; + IMAGE_EXPORT_DIRECTORY* Exports; + DWORD export_table_size; + DWORD export_no; + DWORD export_cnt; + DWORD* function_table; + DWORD addr; + + export_table_size = PEh->OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size; + + if (!export_table_size) + return NULL; + + img_base = PEh->OptionalHeader.ImageBase; + Exports = (IMAGE_EXPORT_DIRECTORY *)(img_base + PEh->OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress); + + export_no = ordinal - Exports->Base; + export_cnt = Exports->NumberOfFunctions; + + if (!export_cnt || export_no > export_cnt) + return NULL; + + function_table = (DWORD*)(Exports->AddressOfFunctions + img_base); + addr = function_table[export_no]; + + if (!addr) + return NULL; + + addr += img_base; + + //handle export forwarding case + if (addr >= (DWORD)Exports && addr < (DWORD)Exports + export_table_size) + { + char module_name[MAX_PATH]; + char* p; + char c; + HMODULE hmod; + + p = module_name; + do + { + c = *(char*) addr; + addr++; + if (c == '.') break; + *p = c; + p++; + } + while (c); + *p = '\0'; + + hmod = GetModuleHandle(module_name); //should be IGetModuleHandle + if (!hmod) + return NULL; + + return GetProcAddress(hmod, (char*) addr); //should be IGetProcAddress + } + + return (PROC) addr; +} + +static PROC WINAPI OriExportFromName(IMAGE_NT_HEADERS* PEh, WORD hint, LPCSTR name) +{ + DWORD img_base; + IMAGE_EXPORT_DIRECTORY* Exports; + DWORD* names; + WORD* ordinals; + int lo; + int hi; + int curr; + int res; + + if (!PEh->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size) + return NULL; + + img_base = PEh->OptionalHeader.ImageBase; + Exports = (IMAGE_EXPORT_DIRECTORY *)(img_base + PEh->OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress); + + hi = Exports->NumberOfNames; + + if (!hi) + return NULL; + + ordinals = (WORD*)(Exports->AddressOfNameOrdinals + img_base); + names = (DWORD*)(img_base + Exports->AddressOfNames); + + if (hint < hi) + { + res = strcmp(name, (char*)(names[hint] + img_base)); + if (!res) + { + return OriExportFromOrdinal(PEh, (WORD)(Exports->Base + ordinals[hint])); + } + else if (res > 0) + { + lo = hint + 1; + hi--; + } + else + { + lo = 0; + hi = hint - 1; + } + curr = (hi + lo) >> 1; + } + else + { + lo = 0; + hi--; + curr = hi >> 1; + } + + while (lo <= hi) + { + res = strcmp(name, (char*)(names[curr] + img_base)); + if (!res) + { + return OriExportFromOrdinal(PEh, (WORD)(Exports->Base + ordinals[curr])); + } + else if (res > 0) + { + lo = curr + 1; + } + else + { + hi = curr - 1; + } + curr = (hi + lo) >> 1; + } + return 0; +} + +DWORD encode_address(DWORD addr, const ApiLibrary* apilib) +{ + //note: rules have to be the same as in decode_address + int index = apilib->index; + + //ensure that we haven't run out of indexes + DBGASSERT(index + 0xc0 < 0xff); + + //STD apilib + if (index == 0) + return addr; + + //non-shared apilib + if ((DWORD) apilib->mod_handle < 0x80000000) + { + //max non-shared apilib size 16MB + DBGASSERT(addr - (DWORD) apilib->mod_handle < 0x01000000); + + return ((0xc0 + index) << 24) + addr - (DWORD) apilib->mod_handle; + } + //shared apilib + return addr; +} + +inline PROC decode_address(DWORD p, IMAGE_NT_HEADERS* target_NThdr, MODREF* caller, PMODREF** refmod) +{ + //note: rules have to be the same as in encode_address + //zero address + if (!p) + return (PROC) p; + //export forwarding - ordinal number + if ((p & 0xffff0000) == 0xffff0000) + return OriExportFromOrdinal(target_NThdr, LOWORD(p)); + //non-shared system library + if (p < 0x80000000) + return (PROC)(p + target_NThdr->OptionalHeader.ImageBase); + //non-shared api library + if (p >= 0xc0000000) + return resolve_nonshared_addr(p, caller, refmod); + //shared system or api library + return (PROC) p; +} + +PROC WINAPI ExportFromOrdinal(IMTE_KEX* target, MODREF* caller, PMODREF** refmod, WORD ordinal) +{ + PROC ret; + + //if caller is unknown - assume it is process's exe + if (!caller) + caller = (*pppdbCur)->pExeMODREF; + + ApiConfiguration* apiconf = get_config(caller); + if (apiconf) + { + WORD mod_index = target->mod_index; + + if (!mod_index) + mod_index = resolve_mod_index(target); + + DBGASSERT(mod_index); + mod_index--; + + if (!apiconf->is_table_empty(mod_index)) + ret = decode_address(apiconf->get(mod_index, ordinal), + target->pNTHdr, caller, refmod); + else + ret = OriExportFromOrdinal(target->pNTHdr, ordinal); + } + else + ret = OriExportFromOrdinal(target->pNTHdr, ordinal); + + if (!ret && refmod) + DBGPRINTF(("%s: unresolved export %s:%d\n", + ((*ppmteModTable)[caller->mteIndex])->pszModName, + target->pszModName, ordinal)); + + return ret; +} + +PROC WINAPI ExportFromName(IMTE_KEX* target, MODREF* caller, PMODREF** refmod, WORD hint, LPCSTR name) +{ + PROC ret; + + //if caller is unknown - assume it is process's exe + if (!caller) + caller = (*pppdbCur)->pExeMODREF; + + ApiConfiguration* apiconf = get_config(caller); + if (apiconf) + { + WORD mod_index = target->mod_index; + + if (!mod_index) + mod_index = resolve_mod_index(target); + + DBGASSERT(mod_index); + mod_index--; + + if (!apiconf->is_table_empty(mod_index)) + ret = decode_address(apiconf->get(mod_index, hint, name), + target->pNTHdr, caller, refmod); + else + ret = OriExportFromName(target->pNTHdr, hint, name); + } + else + ret = OriExportFromName(target->pNTHdr, hint, name); + + if (!ret && refmod) + DBGPRINTF(("%s: unresolved export %s:%s\n", + ((*ppmteModTable)[caller->mteIndex])->pszModName, + target->pszModName, name)); + + return ret; +} + +#if 0 + +//todo: vGetProcAddress_new +PROC WINAPI GetProcAddress_new(HMODULE hModule, LPCSTR lpProcName) +{ + DWORD caller = *((DWORD*)&hModule - 1); + PDB98* ppdbCur = *pppdbCur; + MODREF* mod_mr; + IMAGE_NT_HEADERS* peh; + PROC ret; + + _EnterSysLevel(&ppdbCur->CriticalSection); + mod_mr = MRFromHLib(hModule); + if (!mod_mr) + { + _SetError(ERROR_INVALID_HANDLE); + ret = NULL; + } + else + { + IMTE_KEX* target = (IMTE_KEX*) pmteModTable[mod_mr->mteIndex]; + + if (HIWORD(lpProcName)) + { + ret = ExportFromName(target, (IMTE_KEX*) IMTEfromCallerAddr(caller), 0, lpProcName); + } + else + { + ret = ExportFromOrdinal(target, (IMTE_KEX*) IMTEfromCallerAddr(caller), (WORD) lpProcName); + } + if (!ppdbCur->DebuggeeCB || _CheckMustComplete()) + { + if (!ret) + _SetError(ERROR_PROC_NOT_FOUND); + } + else + { + ret = _DEBCreateDIT(*((DWORD*)ppdbCur->DebuggeeCB + 5), ret); + } + + } + _LeaveSysLevel(&ppdbCur->CriticalSection); + return ret; +} +#endif + +PROC WINAPI iGetProcAddress(HMODULE hModule, LPCSTR lpProcName) +{ + IMAGE_DOS_HEADER* dos_hdr; + IMAGE_NT_HEADERS* nt_hdr; + + dos_hdr = (IMAGE_DOS_HEADER*) hModule; + nt_hdr = (IMAGE_NT_HEADERS*)((int)dos_hdr + dos_hdr->e_lfanew); + + if ((DWORD)lpProcName < 0x10000) + return OriExportFromOrdinal(nt_hdr, (WORD)lpProcName); + return OriExportFromName(nt_hdr, 0, lpProcName); +} + +static IMAGE_SECTION_HEADER* get_data_section() +{ + int i; + IMAGE_DOS_HEADER* MZh = (IMAGE_DOS_HEADER*) GetModuleHandle("kernel32"); + IMAGE_NT_HEADERS* PEh = (IMAGE_NT_HEADERS*) ((int)MZh + MZh->e_lfanew); + IMAGE_SECTION_HEADER* section = (IMAGE_SECTION_HEADER*) + ((int)PEh + + PEh->FileHeader.SizeOfOptionalHeader + + sizeof(IMAGE_FILE_HEADER) + + sizeof(DWORD)); + for (i = 0 ; i < PEh->FileHeader.NumberOfSections ; i++) + { + if (!strcmpi((char*) section->Name, ".data")) + return section; + section++; + } + return NULL; +} + +static void reset_imtes() +{ + DBGPRINTF(("Reseting IMTEs\n")); + _EnterSysLevel(krnl32lock); + + WORD imteMax = *pimteMax; + IMTE** pmteModTable = *ppmteModTable; + for (WORD i = 0 ; i < imteMax ; i++) + { + IMTE_KEX* imte = (IMTE_KEX*) pmteModTable[i]; + if (imte) + { + imte->config = NULL; + imte->flags = 0; + imte->mod_index = 0; + } + } + + _LeaveSysLevel(krnl32lock); +} + +#ifdef _DEBUG + +void dump_imtes(void) +{ + WORD imteMax = *pimteMax; + IMTE** pmteModTable = *ppmteModTable; + int total = 0; + + dbgprintf("Dumping IMTEs...\n"); + dbgprintf("%-6s %-12s %s %s %s\n", "No.", "Process", "Module", "Config", "Flags"); + for (WORD i = 0 ; i < imteMax ; i++) + { + IMTE_KEX* imte = (IMTE_KEX*) pmteModTable[i]; + if (imte) + { + dbgprintf("#%-5d %-12s %s %s %02x\n", i, + pmteModTable[imte->pMR->ppdb->pExeMODREF->mteIndex]->pszSModName, + imte->pszFileName, + imte->config ? imte->config->get_name() : "unknown", + imte->flags); + total++; + } + } + dbgprintf("\nEnd dump total %d IMTEs\n\n", total); +} + +#endif + +int resolver_init() +{ + DBGPRINTF(("resolver_init()\n")); + DWORD ptr; + KernelEx_dataseg* dseg = NULL; + IMAGE_SECTION_HEADER* section = get_data_section(); + DWORD sign_len = sizeof(KEX_SIGNATURE) - 1; + + if (!section) + return 0; + + ptr = (DWORD) h_kernel32 + section->VirtualAddress + section->Misc.VirtualSize - sign_len; + while (ptr >= (DWORD) h_kernel32 + section->VirtualAddress) + { + if (!memcmp((void*)ptr, KEX_SIGNATURE, sign_len)) + { + dseg = (KernelEx_dataseg*) ptr; + break; + } + ptr--; + } + + if (!dseg) + { + DBGPRINTF(("Signature not found\n")); + ShowError(IDS_NOTREADY); + return 0; + } + else + DBGPRINTF(("Signature found @ 0x%08x\n", ptr)); + + if (dseg->version != KEX_STUB_VER) + { + DBGPRINTF(("Wrong stub version, expected: %d, got: %d\n", + KEX_STUB_VER, dseg->version)); + ShowError(IDS_STUBMISMATCH, KEX_STUB_VER, dseg->version); + return 0; + } + + jtab = (PLONG) dseg->jtab; + + system_path_len = GetSystemDirectory(system_path, sizeof(system_path)); + + SettingsDB::instance.flush_all(); + + return 1; +} + +void resolver_uninit() +{ + SettingsDB::instance.clear(); + reset_imtes(); +} + +void resolver_hook() +{ + DBGPRINTF(("resolver_hook()\n")); + old_jtab[0] = InterlockedExchange(jtab + JTAB_EFO_DYN, (LONG) ExportFromOrdinalDynamic_thunk); + old_jtab[1] = InterlockedExchange(jtab + JTAB_EFO_STA, (LONG) ExportFromOrdinalStatic_thunk); + old_jtab[2] = InterlockedExchange(jtab + JTAB_EFN_DYN, (LONG) ExportFromNameDynamic_thunk); + old_jtab[3] = InterlockedExchange(jtab + JTAB_EFN_STA, (LONG) ExportFromNameStatic_thunk); +} + +void resolver_unhook() +{ + DBGPRINTF(("resolver_unhook()\n")); + InterlockedExchange(jtab + JTAB_EFO_DYN, old_jtab[0]); + InterlockedExchange(jtab + JTAB_EFO_STA, old_jtab[1]); + InterlockedExchange(jtab + JTAB_EFN_DYN, old_jtab[2]); + InterlockedExchange(jtab + JTAB_EFN_STA, old_jtab[3]); +} diff --git a/core/resolver.h b/core/resolver.h new file mode 100644 index 0000000..7a18746 --- /dev/null +++ b/core/resolver.h @@ -0,0 +1,61 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#ifndef __RESOLVER_H +#define __RESOLVER_H + +#include "structs.h" +#include "apilib.h" + +/***** loader flags *****/ +#define LDR_KEX_DISABLE 1 /* disable KernelEx API extensions for this module */ +#define LDR_OVERRIDE_PROC_MOD 2 /* use same configuration and flags for all modules in a process */ +#define LDR_LOG_APIS 4 /* enable API tracing */ +#define LDR_FILTER_APIS 8 /* allow to control single APIs - enable, disable, switch */ +#define LDR_VALID_FLAG 128 /* denotes that flags field is valid */ + +#pragma pack(push,1) + +class ApiConfiguration; + +struct IMTE_KEX : public IMTE +{ + ApiConfiguration* config; /* pointer to API configuration required by the module + * 0 - not checked */ + BYTE flags; /* loader flags */ + BYTE unused; /* unused */ + WORD mod_index; /* this value minus 1 is index into MODAPI table in API configurations + * 0xff00-0xfffe - api libraries + * 0 - not checked, 0xffff - not an overridden module */ +}; + +#pragma pack(pop) + +DWORD encode_address(DWORD addr, const ApiLibrary* apilib); +PROC WINAPI iGetProcAddress(HMODULE hModule, LPCSTR lpProcName); +PROC WINAPI ExportFromOrdinal(IMTE_KEX* target, MODREF* caller, PMODREF** refmod, WORD ordinal); +PROC WINAPI ExportFromName(IMTE_KEX* target, MODREF* caller, PMODREF** refmod, WORD hint, LPCSTR name); + +#ifdef _DEBUG +void dump_imtes(void); +#endif + +#endif diff --git a/core/resource.h b/core/resource.h new file mode 100644 index 0000000..513a90f --- /dev/null +++ b/core/resource.h @@ -0,0 +1,18 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by Core.rc +// +#define IDS_NOTREADY 1 +#define IDS_STUBMISMATCH 2 +#define IDS_OLDVER 3 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1000 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/core/sharedmem.cpp b/core/sharedmem.cpp new file mode 100644 index 0000000..137dd34 --- /dev/null +++ b/core/sharedmem.cpp @@ -0,0 +1,87 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#include +#include "sharedmem.h" +#include "debug.h" + +#define HEAP_SHARED 0x04000000 + +HANDLE shared_heap; + +int create_shared_heap() +{ + shared_heap = HeapCreate(HEAP_SHARED, 0, 0x100000); + return shared_heap ? 1 : 0; +} + +void destroy_shared_heap() +{ + HeapDestroy(shared_heap); +} + +void* malloc(size_t size) +{ + return HeapAlloc(shared_heap, 0, size); +} + +void* calloc(size_t count, size_t size) +{ + return HeapAlloc(shared_heap, HEAP_ZERO_MEMORY, count * size); +} + +void free(void* ptr) +{ + DBGASSERT(ptr == NULL || (DWORD)ptr >= 0x80000000); + if (ptr) + HeapFree(shared_heap, 0, ptr); +} + +void* realloc(void* ptr, size_t size) +{ + DBGASSERT(ptr == NULL || (DWORD)ptr >= 0x80000000); + if (ptr) + return HeapReAlloc(shared_heap, 0, ptr, size); + else + return HeapAlloc(shared_heap, 0, size); +} + +void* recalloc(void* ptr, size_t size) +{ + DBGASSERT(ptr == NULL || (DWORD)ptr >= 0x80000000); + if (ptr) + return HeapReAlloc(shared_heap, HEAP_ZERO_MEMORY, ptr, size); + else + return HeapAlloc(shared_heap, HEAP_ZERO_MEMORY, size); +} + +void* operator new(size_t size) +{ + void* mem = malloc(size); + DBGASSERT(mem); + return mem; +} + +void operator delete(void* ptr) +{ + DBGASSERT((DWORD)ptr >= 0x80000000); + free(ptr); +} diff --git a/core/sharedmem.h b/core/sharedmem.h new file mode 100644 index 0000000..04a0388 --- /dev/null +++ b/core/sharedmem.h @@ -0,0 +1,42 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#ifndef __SHAREDMEM_H +#define __SHAREDMEM_H + +#ifdef __cplusplus +extern "C" { +#endif + +int create_shared_heap(); +void destroy_shared_heap(); + +void* malloc(size_t size); +void* calloc(size_t count, size_t size); +void free(void* ptr); +void* realloc(void* ptr, size_t size); +void* recalloc(void* ptr, size_t size); + +#ifdef __cplusplus +}; +#endif + +#endif diff --git a/core/structs.h b/core/structs.h new file mode 100644 index 0000000..e40b482 --- /dev/null +++ b/core/structs.h @@ -0,0 +1,315 @@ +#ifndef __STRUCTS_H +#define __STRUCTS_H + +#define WIN98_K32OBJ_SEMAPHORE 0x1 +#define WIN98_K32OBJ_EVENT 0x2 +#define WIN98_K32OBJ_MUTEX 0x3 +#define WIN98_K32OBJ_CRITICAL_SECTION 0x4 +#define WIN98_K32OBJ_CHANGE 0x5 +#define WIN98_K32OBJ_PROCESS 0x6 +#define WIN98_K32OBJ_THREAD 0x7 +#define WIN98_K32OBJ_FILE 0x8 +#define WIN98_K32OBJ_CONSOLE 0x9 +#define WIN98_K32OBJ_SCREEN_BUFFER 0xA +#define WIN98_K32OBJ_MAILSLOT 0xB +#define WIN98_K32OBJ_SERIAL 0xC +#define WIN98_K32OBJ_MEM_MAPPED_FILE 0xD +#define WIN98_K32OBJ_PIPE 0xE +#define WIN98_K32OBJ_DEVICE_IOCTL 0xF +#define WIN98_K32OBJ_TOOLHELP_SNAPSHOT 0x10 +#define WIN98_K32OBJ_SOCKET 0x11 + +// Process Database flags (WIN95) +#define fDebugSingle 0x00000001 // Set if process is being debugged +#define fCreateProcessEvent 0x00000002 // Set in debugged process after starting +#define fExitProcessEvent 0x00000004 // Might be set in debugged process at exit time +#define fWin16Process 0x00000008 // 16-bit process +#define fDosProcess 0x00000010 // DOS process +#define fConsoleProcess 0x00000020 // 32-bit console process +#define fFileApisAreOem 0x00000040 // SetFileAPIsToOEM +#define fNukeProcess 0x00000080 +#define fServiceProcess 0x00000100 // RegisterServiceProcess +#define fLoginScriptHack 0x00000800 // Might be a Novell network login process +#define fSendDllNotifications 0x00200000 +#define fDebugEventPending 0x00400000 // e.g. stopped in debugger +#define fNearlyTerminating 0x00800000 +#define fFaulted 0x08000000 +#define fTerminating 0x10000000 +#define fTerminated 0x20000000 +#define fInitError 0x40000000 +#define fSignaled 0x80000000 + +#pragma pack(push,1) + +// Structured Exception Handler +typedef struct _SEH { + struct _SEH *pNext; + FARPROC pfnHandler; +} SEH, *PSEH; + +typedef struct _HANDLE_TABLE_ENTRY { + DWORD flags; // Valid flags depend on what type of object this is + PVOID pObject; // Pointer to the object that the handle refers to +} HANDLE_TABLE_ENTRY, *PHANDLE_TABLE_ENTRY; + +// Handle Table +typedef struct _HANDLE_TABLE { + DWORD cEntries; // Max number of handles in table + HANDLE_TABLE_ENTRY array[1]; // An array (number is given by cEntries) +} HANDLE_TABLE, *PHANDLE_TABLE; + +struct _PDB98; + +// MODREF +typedef struct _MODREF { // Size = 0x1C + 4*cImportedModules + struct _MODREF* pNextModRef; // 00 Pointer to next process's MODREF in list + struct _MODREF* pPrevModRef; // 04 Pointer to previous process's MODREF in list + struct _MODREF* pNextMteMR; // 08 Next MODREF in IMTE list ?? + struct _MODREF* pPrevMteMR; // 0C Prev MODREF in IMTE list ?? + WORD mteIndex; // 10 Index to global array of pointers to IMTEs + WORD cUsage; // 12 ref count + WORD flags; // 14 flags + WORD cImportedModules; // 16 Number of modules imported implicitly + struct _PDB98* ppdb; // 18 Pointer to process database + union { // 1C + PSTR pszModuleName; + struct _MODREF* pMR; + } ImplicitImports[1]; // * cImportedModules +} MODREF, *PMODREF; + +// IMTE +typedef struct _IMTE { // Size = 0x3C + DWORD unknown1; // 00 + IMAGE_NT_HEADERS* pNTHdr; // 04 pointer to shared PE header for module + DWORD unknown2; // 08 + PSTR pszFileName; // 0C long path name + PSTR pszModName; // 10 long module name + WORD cbFileName; // 14 long path name length + WORD cbModName; // 16 long module name length + DWORD unknown3; // 18 + DWORD cSections; // 1C number of sections in the module + DWORD unknown4; // 20 + DWORD baseAddress; // 24 module base address before relocation + WORD hModule16; // 28 16-bit selector to NE header + WORD cUsage; // 2A usage count + PMODREF pMR; // 2C pointer to MODREF structure + PSTR pszSFileName; // 30 short path name + WORD cbSFileName; // 34 short path name length + PSTR pszSModName; // 36 short module name + WORD cbSModName; // 3A short module name length +} IMTE, *PIMTE; + +// Environment Database +typedef struct _ENVIRONMENT_DATABASE { + PSTR pszEnvironment; //00 Pointer to Process Environment + DWORD un1; //04 (always 0) + PSTR pszCmdLine; //08 Pointer to command line + PSTR pszCurrDirectory; //0C Pointer to current directory + LPSTARTUPINFOA pStartupInfo; //10 Pointer to STARTUPINFOA struct + HANDLE hStdIn; //14 Standard Input handle + HANDLE hStdOut; //18 Standard Output handle + HANDLE hStdErr; //1C Standard Error handle + DWORD un2; //20 (always 1) + DWORD InheritConsole; //24 Inherit console from parent + DWORD BreakType; //28 Handle console events (like CTRL+C) + DWORD BreakSem; //2C Pointer to K32OBJ_SEMAPHORE + DWORD BreakEvent; //30 Pointer to K32OBJ_EVENT + DWORD BreakThreadID; //34 Pointer to K32OBJ_THREAD + DWORD BreakHandlers; //38 Pointer to list of installed console control handlers +} EDB, *PEDB; + +// Process Database +typedef struct _PDB98 { // Size = 0xC4 (from Kernel32) + BYTE Type; // 00 Kernel object type = K32OBJ_PROCESS (6) + BYTE Unknown_A; // 01 (align ?) + WORD cReference; // 02 Number of references to process + DWORD Unknown_B; // 04 Pointer to ??? + DWORD Unknown1; // 08 (zero) + DWORD pEvent; // 0C Event for process waiting + DWORD TerminationStatus; // 10 GetExitCodeProcess + DWORD Unknown2; // 14 May be used for private purposes + HANDLE DefaultHeap; // 18 GetProcessHeap + PCONTEXT MemoryContext; // 1C Pointer to process context + DWORD Flags; // 20 Flags + DWORD pPSP; // 24 Linear address of DOS PSP + WORD PSPSelector; // 28 Selector to DOS PSP + WORD MTEIndex; // 2A Index into global module table + WORD cThreads; // 2C Threads.ItemCount + WORD cNotTermThreads; // 2E Threads.ItemCount + WORD Unknown3; // 30 (zero) + WORD cRing0Threads; // 32 Normally Threads.ItemCount (except kernel32) + HANDLE HeapHandle; // 34 Kernel32 shared heap + DWORD w16TDB; // 38 Win16 task database selector + DWORD MemMappedFiles; // 3C List of memory mapped files + PEDB pEDB; // 40 Pointer to Environment Database + PHANDLE_TABLE pHandleTable; // 44 Pointer to Handle Table + struct _PDB98* ParentPDB; // 48 Pointer to parent process (PDB) + PMODREF MODREFList; // 4C Pointer to list of modules + DWORD ThreadList; // 50 Pointer to list of threads + DWORD DebuggeeCB; // 54 Debuggee context block + DWORD LocalHeapFreeHead; // 58 Free list for process default heap + DWORD InitialRing0ID; // 5C Meaning unknown + CRITICAL_SECTION CriticalSection; // 60 For synchronizing threads + DWORD Unknown4[3]; // 78 + DWORD pConsole; // 84 Output console + DWORD tlsInUseBits1; // 88 Status of TLS indexes 0 - 31 + DWORD tlsInUseBits2; // 8C Status of TLS indexes 32 - 63 + DWORD ProcessDWORD; // 90 Undocumented API GetProcessDword, meaning unknown + struct _PDB98* ProcessGroup; // 94 Master process PDB (in debugging) + PMODREF pExeMODREF; // 98 Points to exe's module structure + DWORD TopExcFilter; // 9C SetUnhandledExceptionFilter + DWORD PriorityClass; // A0 PriorityClass (8 = NORMAL) + DWORD HeapList; // A4 List of heaps + DWORD HeapHandleList; // A8 List of moveable memory blocks + DWORD HeapPointer; // AC Pointer to one moveable memory block, meaning unknown + DWORD pConsoleProvider; // B0 Console for DOS apps + WORD EnvironSelector; // B4 Environment database selector + WORD ErrorMode; // B6 SetErrorMode + DWORD pEventLoadFinished; // B8 Signaled when the process has finished loading + WORD UTState; // BC Universal thunking, meaning unknown + WORD Unknown5; // BE (zero) + DWORD Unknown6; // C0 +} PDB98, *PPDB98; + +// Process Database +typedef struct _PDBME { // Size = 0xC4 (from Kernel32) + BYTE Type; // 00 Kernel object type = K32OBJ_PROCESS (6) + BYTE Unknown_A; // 01 (align ?) + WORD cReference; // 02 Number of references to process + DWORD Unknown_B; // 04 Pointer to ??? + DWORD Unknown1; // 08 (zero) + DWORD pEvent; // 0C Event for process waiting + DWORD TerminationStatus; // 10 GetExitCodeProcess + DWORD Unknown2; // 14 May be used for private purposes + DWORD DefaultHeap; // 18 GetProcessHeap + DWORD MemoryContext; // 1C Pointer to process context + DWORD Flags; // 20 Flags + DWORD pPSP; // 24 Linear address of DOS PSP + WORD PSPSelector; // 28 Selector to DOS PSP + WORD MTEIndex; // 2A Index into global module table + WORD cThreads; // 2C Threads.ItemCount + WORD cNotTermThreads; // 2E Threads.ItemCount + WORD Unknown3; // 30 (zero) + WORD cRing0Threads; // 32 Normally Threads.ItemCount (except kernel32) + HANDLE HeapHandle; // 34 Kernel32 shared heap + DWORD w16TDB; // 38 Win16 task database selector + DWORD MemMappedFiles; // 3C List of memory mapped files + PEDB pEDB; // 40 Pointer to Environment Database + PHANDLE_TABLE pHandleTable; // 44 Pointer to Handle Table + struct _PDBME* ParentPDB; // 48 Pointer to parent process (PDB) + PMODREF MODREFList; // 4C Pointer to list of modules + DWORD ThreadList; // 50 Pointer to list of threads + DWORD DebuggeeCB; // 54 Debuggee context block + DWORD LocalHeapFreeHead; // 58 Free list for process default heap + DWORD InitialRing0ID; // 5C Meaning unknown + CRITICAL_SECTION CriticalSection; // 60 For synchronizing threads + DWORD Unknown4[2]; // 78 + DWORD pConsole; // 80 Output console + DWORD tlsInUseBits1; // 84 Status of TLS indexes 0 - 31 + DWORD tlsInUseBits2; // 88 Status of TLS indexes 32 - 63 + DWORD ProcessDWORD; // 8C Undocumented API GetProcessDword, meaning unknown + DWORD Unknown_C; // 90 Unknown + struct _PDBME* ProcessGroup; // 94 Master process PDB (in debugging) + PMODREF pExeMODREF; // 98 Points to exe's module structure + DWORD TopExcFilter; // 9C SetUnhandledExceptionFilter + DWORD PriorityClass; // A0 PriorityClass (8 = NORMAL) + DWORD HeapList; // A4 List of heaps + DWORD HeapHandleList; // A8 List of moveable memory blocks + DWORD HeapPointer; // AC Pointer to one moveable memory block, meaning unknown + DWORD pConsoleProvider; // B0 Console for DOS apps + WORD EnvironSelector; // B4 Environment database selector + WORD ErrorMode; // B6 SetErrorMode + DWORD pEventLoadFinished; // B8 Signaled when the process has finished loading + WORD UTState; // BC Universal thunking, meaning unknown + WORD Unknown5; // BE (zero) + DWORD Unknown6; // C0 +} PDBME, *PPDBME; + +// Thread Information Block (FS:[0x18]) +typedef struct _TIB98 { // Size = 0x38 + PSEH pvExcept; // 00 Head of exception record list + PVOID pvStackUserTop; // 04 Top of user stack + PVOID pvStackUserBase; // 08 Base of user stack + WORD pvTDB; // 0C Ptr to win-16 task database + WORD pvThunksSS; // 0E SS selector used for thunking to 16 bits + DWORD SelmanList; // 10 Pointer to selector manager list + PVOID pvArbitrary; // 14 Available for application use + struct _TIB98 *pTIBSelf; // 18 Linear address of TIB structure + WORD TIBFlags; // 1C TIBF_WIN32 = 1, TIBF_TRAP = 2 + WORD Win16MutexCount; // 1E Win16Lock + DWORD DebugContext; // 20 Pointer to debug context structure + DWORD pCurrentPriority; // 24 Pointer to DWORD containing current priority level + DWORD pvQueue; // 28 Message Queue selector + PVOID *pvTLSArray; // 2C Thread Local Storage (TLS) array + PVOID *pProcess; // 30 Pointer to owning process database (PDB) + DWORD Unknown; // 34 Pointer to ??? +} TIB98, *PTIB98; + +typedef struct _TDBX98 TDBX98; + +// Thread database (FS:[0x18] - 0x8) +typedef struct _TDB98 { // Size = 0x228 (from Kernel32) + WORD Type; // 00 K32 object type + WORD cReference; // 02 Reference count + DWORD pSomeEvent; // 04 K32 event object used when someone waits on the thread object + TIB98 tib; // 08 Thread information block (TIB) + DWORD Unknown; // 40 + DWORD Flags; // 44 Flags + DWORD TerminationStatus; // 48 Exit code + WORD TIBSelector; // 4C Selector used in FS to point to TIB + WORD EmulatorSelector; // 4E Memory block for saving x87 state + DWORD cHandles; // 50 Handle count + DWORD Ring0Thread; // 54 R0 thread control block (TCB) + TDBX98 *pTDBX; // 58 R0 thread database extension (TDBX) + DWORD un1[109]; // 5C + DWORD APISuspendCount; // 210 Count of SuspendThread's minus ResumeThread's +} TDB98, *PTDB98; + +typedef struct _TDBME { // Size = 0x228 (from Kernel32) + WORD Type; // 00 K32 object type + WORD cReference; // 02 Reference count + DWORD pSomeEvent; // 04 K32 event object used when someone waits on the thread object + TIB98 tib; // 08 Thread information block (TIB) + DWORD Unknown; // 40 + DWORD Unknown2; // 44 + WORD TIBSelector; // 46 Selector used in FS to point to TIB + DWORD TerminationStatus; // 48 Exit code + DWORD Flags; // 4C Flags + DWORD cHandles; // 50 Handle count + DWORD Ring0Thread; // 54 R0 thread control block (TCB) + DWORD Unknown3; // 58 Selector for ??? + DWORD un1[11]; // 5C + TDBX98 *pTDBX; // 88 + DWORD un2[97]; // 8C + DWORD APISuspendCount; // 210 Count of SuspendThread's minus ResumeThread's +} TDBME, *PTDBME; + +// Thread database extension +typedef struct _TDBX98 { + DWORD un0; // 00 + TDB98 *ptdb; // 04 R3 thread database + PDB98 *ppdb; // 08 R3 process database + DWORD ContextHandle; // 0C R0 memory context + DWORD Ring0Thread; // 10 R0 thread control block [TCB *] + DWORD WaitNodeList; // 14 Anchor of things we're waiting on [WAITNODE *] + DWORD WaitFlags; // 18 Blocking flags + DWORD un1; // 1C + DWORD TimeOutHandle; // 20 + DWORD WakeParam; // 24 + DWORD BlockHandle; // 28 R0 semaphore on which thread will wait inside VWIN32 + DWORD BlockState; // 2C + DWORD SuspendCount; // 30 + DWORD SuspendHandle; // 34 + DWORD MustCompleteCount; // 38 Count of EnterMustComplete's minus LeaveMustComplete's + DWORD WaitExFlags; // 3C Flags + DWORD SyncWaitCount; // 40 + DWORD QueuedSyncFuncs; // 44 + DWORD UserAPCList; // 48 + DWORD KernAPCList; // 4C + DWORD pPMPSPSelector; // 50 + DWORD BlockedOnID; // 54 +} TDBX98, *PTDBX98; + +#pragma pack(pop) + +#endif diff --git a/core/thunks.cpp b/core/thunks.cpp new file mode 100644 index 0000000..2d7057b --- /dev/null +++ b/core/thunks.cpp @@ -0,0 +1,106 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#include +#include "thunks.h" +#include "internals.h" +#include "resolver.h" + +__declspec(naked) +PROC ExportFromOrdinalStatic_thunk(IMAGE_NT_HEADERS* PEh, WORD ordinal) +{ +__asm { + mov eax, [ebp-4Ch] //tested w98fe 1998, w98se 2222, w98se 2226, wme 3000 + mov ecx, [eax] + mov ax, [ecx+10h] + movzx eax, ax + mov edx, ppmteModTable + mov edx, [edx] + mov eax, [edx+4*eax] + push eax //target IMTE + push dword ptr [esp+4] //return address + mov eax, [ebp+8] + mov [esp+8], eax //caller MODREF + lea eax, [ebp-4Ch] + mov dword ptr [esp+12], eax + jmp ExportFromOrdinal + } +} + +__declspec(naked) +PROC ExportFromNameStatic_thunk(IMAGE_NT_HEADERS* PEh, WORD hint, LPCSTR name) +{ +__asm { + mov eax, [ebp-4Ch] //tested w98fe 1998, w98se 2222, w98se 2226, wme 3000 + mov ecx, [eax] + mov ax, [ecx+10h] + movzx eax, ax + mov edx, ppmteModTable + mov edx, [edx] + mov eax, [edx+4*eax] + push eax //target IMTE + push dword ptr [esp+4] //return address + mov eax, [ebp+8] + mov [esp+8], eax //caller MODREF + lea eax, [ebp-4Ch] + mov dword ptr [esp+12], eax + jmp ExportFromName + } +} + +/* stack on entry: + * ret_addr + * PEh + * ordinal + * edi + * esi + * ebx + * caller_addr + */ +__declspec(naked) +PROC ExportFromOrdinalDynamic_thunk(IMAGE_NT_HEADERS* PEh, WORD ordinal) +{ +__asm { + push edx //target IMTE + push dword ptr [esp+4] + push dword ptr [esp+20h] //tested w98se 2225 + call MRfromCallerAddr + add esp, 4 + mov [esp+8], eax //caller MODREF + mov dword ptr [esp+12], 0 + jmp ExportFromOrdinal + } +} + +__declspec(naked) +PROC ExportFromNameDynamic_thunk(IMAGE_NT_HEADERS* PEh, WORD hint, LPCSTR name) +{ +__asm { + push edx //target IMTE + push dword ptr [esp+4] + push dword ptr [esp+24h] //tested w98se 2225 + call MRfromCallerAddr + add esp, 4 + mov [esp+8], eax //caller MODREF + mov dword ptr [esp+12], 0 + jmp ExportFromName + } +} diff --git a/core/thunks.h b/core/thunks.h new file mode 100644 index 0000000..6f52043 --- /dev/null +++ b/core/thunks.h @@ -0,0 +1,30 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#ifndef __THUNKS_H +#define __THUNKS_H + +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); + +#endif diff --git a/core/version.h b/core/version.h new file mode 100644 index 0000000..7f429ee --- /dev/null +++ b/core/version.h @@ -0,0 +1,29 @@ +/* + * 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. + * + */ + +#ifndef __VERSION_H +#define __VERSION_H + +#define VERSION_STR "4.0 RC 1" +#define VERSION_CODE 0x0400000B +#define RCVERSION 4, 0, 1, 0 + +#endif diff --git a/core/wildcmp.cpp b/core/wildcmp.cpp new file mode 100644 index 0000000..454e09e --- /dev/null +++ b/core/wildcmp.cpp @@ -0,0 +1,37 @@ +//public domain wildcard match function by Jack Handy +#include "wildcmp.h" + +int wildcmp(const char *wild, const char *string) { + const char *cp = 0, *mp = 0; + while ((*string) && (*wild != '*')) { + if ((*wild != *string) && (*wild != '?')) { + return 0; + } + wild++; + string++; + } + + while (*string) { + if (*wild == '*') { + if (!*++wild) { + return 1; + } + mp = wild; + cp = string+1; + } else if ((*wild == *string) || (*wild == '?')) { + wild++; + string++; + } else { + if (!cp || !mp) + return 0; + wild = mp; + string = cp++; + } + } + + while (*wild == '*') { + wild++; + } + + return !*wild; +} diff --git a/core/wildcmp.h b/core/wildcmp.h new file mode 100644 index 0000000..23540e0 --- /dev/null +++ b/core/wildcmp.h @@ -0,0 +1,6 @@ +#ifndef __WILDCMP_H +#define __WILDCMP_H + +int wildcmp(const char*, const char*); + +#endif diff --git a/kexcontrol/kexcontrol.cpp b/kexcontrol/kexcontrol.cpp new file mode 100644 index 0000000..38f8fc0 --- /dev/null +++ b/kexcontrol/kexcontrol.cpp @@ -0,0 +1,73 @@ +/* + * 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. + * + */ + +#include +#include +#include "kexcoresdk.h" +#include "debugproto.h" + +int menu() +{ + printf("\n------------------------------------------------------------\n"); + printf("KernelEx control options:\n"); + printf("1. dump configurations\n"); + printf("2. dump imtes\n"); + printf("3. dump application settings\n"); + printf("4. flush application settings\n"); + printf("0. exit\n"); + printf("\nyour choice: "); + int ch; + scanf("%d", &ch); + printf("\n"); + return ch; +} + +int main() +{ + printf("KernelEx control tool by Xeno86\n"); + printf("init return %d\n", kexInit()); + + int ch; + while ((ch = menu()) != 0) + { + switch(ch) + { + case 1: + kexDbgDumpConfigurations(); + break; + case 2: + kexDbgDumpImtes(); + break; + case 3: + kexDbgDumpAppSettings(); + break; + case 4: + kexFlushAppSettings(); + break; + default: + printf("Invalid option!\n"); + } + } + + printf("uninit return %d\n", kexUninit()); + + return 0; +} diff --git a/kexcontrol/kexcontrol.dsp b/kexcontrol/kexcontrol.dsp new file mode 100644 index 0000000..39b2d6f --- /dev/null +++ b/kexcontrol/kexcontrol.dsp @@ -0,0 +1,104 @@ +# Microsoft Developer Studio Project File - Name="kexcontrol" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=kexcontrol - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "kexcontrol.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "kexcontrol.mak" CFG="kexcontrol - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "kexcontrol - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "kexcontrol - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "kexcontrol - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /I "." /I "../common" /I "../core" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x415 /d "NDEBUG" +# ADD RSC /l 0x415 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib ../common/KernelEx.lib /nologo /subsystem:console /machine:I386 /OPT:NOWIN98 +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "kexcontrol - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "." /I "../common" /I "../core" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD BASE RSC /l 0x415 /d "_DEBUG" +# ADD RSC /l 0x415 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib ../common/KernelEx.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /OPT:NOWIN98 +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "kexcontrol - Win32 Release" +# Name "kexcontrol - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\kexcontrol.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/kexcrt/LICENSE b/kexcrt/LICENSE new file mode 100644 index 0000000..aa6d7a7 --- /dev/null +++ b/kexcrt/LICENSE @@ -0,0 +1,73 @@ +This license applies to all files in directory and its subdirectories, +unless otherwise noted in individual files. + + +Some files are derived from files derived from the include/ directory +of the Linux kernel, and are licensed under the terms of the GNU +General Public License, version 2, as released by the Free Software +Foundation, Inc.; incorporated herein by reference. + + ----- + +Some files are derived from files copyrighted by the Regents of The +University of California, and are available under the following +license: + +Note: The advertising clause in the license appearing on BSD Unix +files was officially rescinded by the Director of the Office of +Technology Licensing of the University of California on July 22 +1999. He states that clause 3 is "hereby deleted in its entirety." + + * Copyright (c) + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + + ----- + +For all remaining files, the following license applies: + + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * Any copyright notice(s) and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/kexcrt/README b/kexcrt/README new file mode 100644 index 0000000..5dc2ce2 --- /dev/null +++ b/kexcrt/README @@ -0,0 +1,80 @@ +This is klibc, what is intended to be a minimalistic libc subset for +use with initramfs. It is deliberately written for small size, +minimal entaglement, and portability, not speed. It is definitely a +work in progress, and a lot of things are still missing. + + +The build procedure is not very polished yet, but it should work like +this: + +a) In the source root directory (the directory above the one in which + this file is found) create a symlink called "linux" pointing to a + reasonably recent Linux kernel tree (2.4 or 2.6 should be OK.) + This tree must have the include/asm symlink set up for the + architecture you're compiling for, and include/linux/autoconf.h + must exist. The easiest way to make sure of all of these is to do + a "make config" or any of its variants on the kernel tree is + question, followed by a "make dep" (2.4) or "make prepare" (2.6). + +b) If you're cross-compiling, you need to set KLIBCARCH to the + appropriate architecture, and set CROSS_COMPILE to your toolchain + prefix. + + IMPORTANT: if you're on a 64-bit machine with a 32-bit userland + (ia64, mips64, ppc64 sparc64, s390x or x86_64), and you want to + build the 32-bit version: you need to set KLIBCARCH to the 32-bit + architecture as well as set up the linux/include/asm symlink to + point to the 32-bit architecture. Building the 32-bit architecture + usually (but not always) produces smaller binaries, and is likely + to be better tested. + + If you are on ARM, and want to build a thumb version of the library + (this is supported), change OPTFLAGS in arch/arm/MCONFIG to build + thumb code. + + The following is the last known status of various architectures: + + alpha: Working + arm-thumb: Untested + arm: Working + arm26: Not yet ported + cris: Working + h8300: Not yet ported + i386: Working + ia64: Working + m32r: Untested + m68k: Untested + m68knommu: Not yet ported + mips: Working + mips64: Not yet ported + parisc: Working + parisc64: Not yet ported + ppc: Working + ppc64: Working + s390: Working static, shared untested + s390x: Working + sh: Untested + sh64: Not yet ported + sparc: Working + sparc64: Untested + v850: Not yet ported + x86-64: Working + xtensa: Not yet ported + + Shared library support requires recent binutils on many + architectures. + + Note that even the "working" ones likely have bugs. Please report + them if you run into them. + +c) Type "make" and pray... + +d) Try the test programs in the tests/ directory. They should run... + +Contact the klibc mailing list: + + http://www.zytor.com/mailman/listinfo/klibc + +... for more info. + + -hpa diff --git a/kexcrt/_vsnprintf.c b/kexcrt/_vsnprintf.c new file mode 100644 index 0000000..872fe1e --- /dev/null +++ b/kexcrt/_vsnprintf.c @@ -0,0 +1,7 @@ +#include +#include + +int _vsnprintf(char *buffer, size_t n, const char *format, va_list ap) +{ + return vsnprintf(buffer, n, format, ap); +} diff --git a/kexcrt/atoi.c b/kexcrt/atoi.c new file mode 100644 index 0000000..a6ec0bf --- /dev/null +++ b/kexcrt/atoi.c @@ -0,0 +1,3 @@ +#define TYPE int +#define NAME atoi +#include "atox.c" diff --git a/kexcrt/atol.c b/kexcrt/atol.c new file mode 100644 index 0000000..e65484e --- /dev/null +++ b/kexcrt/atol.c @@ -0,0 +1,3 @@ +#define TYPE long +#define NAME atol +#include "atox.c" diff --git a/kexcrt/atoll.c b/kexcrt/atoll.c new file mode 100644 index 0000000..b396826 --- /dev/null +++ b/kexcrt/atoll.c @@ -0,0 +1,3 @@ +#define TYPE int64_t +#define NAME atoll +#include "atox.c" diff --git a/kexcrt/atox.c b/kexcrt/atox.c new file mode 100644 index 0000000..d21c89d --- /dev/null +++ b/kexcrt/atox.c @@ -0,0 +1,14 @@ +/* + * atox.c + * + * atoi(), atol(), atoll() + */ + +#include +#include +#include + +TYPE NAME(const char *nptr) +{ + return (TYPE) strntoumax(nptr, (char **)NULL, 10, ~(size_t) 0); +} diff --git a/kexcrt/ctype/ctypefunc.h b/kexcrt/ctype/ctypefunc.h new file mode 100644 index 0000000..243bc8d --- /dev/null +++ b/kexcrt/ctype/ctypefunc.h @@ -0,0 +1,13 @@ +/* + * ctype/ctype.h + * + * Common header for out-of-line ctype functions + */ + +#define __CTYPE_NO_INLINE +#include "ctypes.h" + +#define CTYPEFUNC(X) \ + int X(int c) { \ + return __ctype_##X(c); \ + } diff --git a/kexcrt/ctype/isalnum.c b/kexcrt/ctype/isalnum.c new file mode 100644 index 0000000..57af18b --- /dev/null +++ b/kexcrt/ctype/isalnum.c @@ -0,0 +1,2 @@ +#include "ctypefunc.h" +CTYPEFUNC(isalnum) diff --git a/kexcrt/ctype/isalpha.c b/kexcrt/ctype/isalpha.c new file mode 100644 index 0000000..8f2effe --- /dev/null +++ b/kexcrt/ctype/isalpha.c @@ -0,0 +1,2 @@ +#include "ctypefunc.h" +CTYPEFUNC(isalpha) diff --git a/kexcrt/ctype/isascii.c b/kexcrt/ctype/isascii.c new file mode 100644 index 0000000..6a974d5 --- /dev/null +++ b/kexcrt/ctype/isascii.c @@ -0,0 +1,2 @@ +#include "ctypefunc.h" +CTYPEFUNC(isascii) diff --git a/kexcrt/ctype/isblank.c b/kexcrt/ctype/isblank.c new file mode 100644 index 0000000..7728550 --- /dev/null +++ b/kexcrt/ctype/isblank.c @@ -0,0 +1,2 @@ +#include "ctypefunc.h" +CTYPEFUNC(isblank) diff --git a/kexcrt/ctype/iscntrl.c b/kexcrt/ctype/iscntrl.c new file mode 100644 index 0000000..81db804 --- /dev/null +++ b/kexcrt/ctype/iscntrl.c @@ -0,0 +1,2 @@ +#include "ctypefunc.h" +CTYPEFUNC(iscntrl) diff --git a/kexcrt/ctype/isdigit.c b/kexcrt/ctype/isdigit.c new file mode 100644 index 0000000..41a39d9 --- /dev/null +++ b/kexcrt/ctype/isdigit.c @@ -0,0 +1,2 @@ +#include "ctypefunc.h" +CTYPEFUNC(isdigit) diff --git a/kexcrt/ctype/isgraph.c b/kexcrt/ctype/isgraph.c new file mode 100644 index 0000000..e5b83d1 --- /dev/null +++ b/kexcrt/ctype/isgraph.c @@ -0,0 +1,2 @@ +#include "ctypefunc.h" +CTYPEFUNC(isgraph) diff --git a/kexcrt/ctype/islower.c b/kexcrt/ctype/islower.c new file mode 100644 index 0000000..9e179ae --- /dev/null +++ b/kexcrt/ctype/islower.c @@ -0,0 +1,2 @@ +#include "ctypefunc.h" +CTYPEFUNC(islower) diff --git a/kexcrt/ctype/isprint.c b/kexcrt/ctype/isprint.c new file mode 100644 index 0000000..9c6a351 --- /dev/null +++ b/kexcrt/ctype/isprint.c @@ -0,0 +1,2 @@ +#include "ctypefunc.h" +CTYPEFUNC(isprint) diff --git a/kexcrt/ctype/ispunct.c b/kexcrt/ctype/ispunct.c new file mode 100644 index 0000000..36b5258 --- /dev/null +++ b/kexcrt/ctype/ispunct.c @@ -0,0 +1,2 @@ +#include "ctypefunc.h" +CTYPEFUNC(ispunct) diff --git a/kexcrt/ctype/isspace.c b/kexcrt/ctype/isspace.c new file mode 100644 index 0000000..aed06c8 --- /dev/null +++ b/kexcrt/ctype/isspace.c @@ -0,0 +1,2 @@ +#include "ctypefunc.h" +CTYPEFUNC(isspace) diff --git a/kexcrt/ctype/isupper.c b/kexcrt/ctype/isupper.c new file mode 100644 index 0000000..70a139b --- /dev/null +++ b/kexcrt/ctype/isupper.c @@ -0,0 +1,2 @@ +#include "ctypefunc.h" +CTYPEFUNC(isupper) diff --git a/kexcrt/ctype/isxdigit.c b/kexcrt/ctype/isxdigit.c new file mode 100644 index 0000000..ab89c1f --- /dev/null +++ b/kexcrt/ctype/isxdigit.c @@ -0,0 +1,2 @@ +#include "ctypefunc.h" +CTYPEFUNC(isxdigit) diff --git a/kexcrt/ctype/tolower.c b/kexcrt/ctype/tolower.c new file mode 100644 index 0000000..24ca72b --- /dev/null +++ b/kexcrt/ctype/tolower.c @@ -0,0 +1,2 @@ +#include "ctypefunc.h" +CTYPEFUNC(tolower) diff --git a/kexcrt/ctype/toupper.c b/kexcrt/ctype/toupper.c new file mode 100644 index 0000000..15763f7 --- /dev/null +++ b/kexcrt/ctype/toupper.c @@ -0,0 +1,2 @@ +#include "ctypefunc.h" +CTYPEFUNC(toupper) diff --git a/kexcrt/ctypes.c b/kexcrt/ctypes.c new file mode 100644 index 0000000..1106418 --- /dev/null +++ b/kexcrt/ctypes.c @@ -0,0 +1,284 @@ +/* + * ctypes.c + * + * This is the array that defines classes. + * This assumes ISO 8859-1. + */ + +#include "ctypes.h" + +const unsigned char __ctypes[257] = { + 0, /* EOF */ + + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl | __ctype_space, /* BS */ + __ctype_cntrl | __ctype_space, /* TAB */ + __ctype_cntrl | __ctype_space, /* LF */ + __ctype_cntrl | __ctype_space, /* VT */ + __ctype_cntrl | __ctype_space, /* FF */ + __ctype_cntrl | __ctype_space, /* CR */ + __ctype_cntrl, /* control character */ + + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + + __ctype_print | __ctype_space, /* space */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + + __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */ + __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */ + __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */ + __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */ + __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */ + __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */ + __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */ + __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */ + __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */ + __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */ + __ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */ + __ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */ + __ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */ + __ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */ + __ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */ + __ctype_print | __ctype_upper, /* G-Z */ + __ctype_print | __ctype_upper, /* G-Z */ + __ctype_print | __ctype_upper, /* G-Z */ + __ctype_print | __ctype_upper, /* G-Z */ + __ctype_print | __ctype_upper, /* G-Z */ + __ctype_print | __ctype_upper, /* G-Z */ + __ctype_print | __ctype_upper, /* G-Z */ + __ctype_print | __ctype_upper, /* G-Z */ + __ctype_print | __ctype_upper, /* G-Z */ + + __ctype_print | __ctype_upper, /* G-Z */ + __ctype_print | __ctype_upper, /* G-Z */ + __ctype_print | __ctype_upper, /* G-Z */ + __ctype_print | __ctype_upper, /* G-Z */ + __ctype_print | __ctype_upper, /* G-Z */ + __ctype_print | __ctype_upper, /* G-Z */ + __ctype_print | __ctype_upper, /* G-Z */ + __ctype_print | __ctype_upper, /* G-Z */ + __ctype_print | __ctype_upper, /* G-Z */ + __ctype_print | __ctype_upper, /* G-Z */ + __ctype_print | __ctype_upper, /* G-Z */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */ + __ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */ + __ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */ + __ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */ + __ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */ + __ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */ + __ctype_print | __ctype_lower, /* g-z */ + __ctype_print | __ctype_lower, /* g-z */ + __ctype_print | __ctype_lower, /* g-z */ + __ctype_print | __ctype_lower, /* g-z */ + __ctype_print | __ctype_lower, /* g-z */ + __ctype_print | __ctype_lower, /* g-z */ + __ctype_print | __ctype_lower, /* g-z */ + __ctype_print | __ctype_lower, /* g-z */ + __ctype_print | __ctype_lower, /* g-z */ + + __ctype_print | __ctype_lower, /* g-z */ + __ctype_print | __ctype_lower, /* g-z */ + __ctype_print | __ctype_lower, /* g-z */ + __ctype_print | __ctype_lower, /* g-z */ + __ctype_print | __ctype_lower, /* g-z */ + __ctype_print | __ctype_lower, /* g-z */ + __ctype_print | __ctype_lower, /* g-z */ + __ctype_print | __ctype_lower, /* g-z */ + __ctype_print | __ctype_lower, /* g-z */ + __ctype_print | __ctype_lower, /* g-z */ + __ctype_print | __ctype_lower, /* g-z */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_cntrl, /* control character */ + + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + __ctype_cntrl, /* control character */ + + __ctype_print | __ctype_space, /* NBSP */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_punct, /* punctuation */ + + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_upper, /* upper accented */ + __ctype_print | __ctype_lower, /* lower accented */ + + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_punct, /* punctuation */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ + __ctype_print | __ctype_lower, /* lower accented */ +}; diff --git a/kexcrt/ctypes.h b/kexcrt/ctypes.h new file mode 100644 index 0000000..404027e --- /dev/null +++ b/kexcrt/ctypes.h @@ -0,0 +1,134 @@ +/* + * ctype.h + * + * This assumes ISO 8859-1, being a reasonable superset of ASCII. + */ + +#ifndef _CTYPE_H +#define _CTYPE_H + +#if defined( _MSC_VER ) && !defined( __cplusplus ) +# define inline __inline +#endif + +/* + * This relies on the following definitions: + * + * cntrl = !print + * alpha = upper|lower + * graph = punct|alpha|digit + * blank = '\t' || ' ' (per POSIX requirement) + */ +enum { + __ctype_upper = (1 << 0), + __ctype_lower = (1 << 1), + __ctype_digit = (1 << 2), + __ctype_xdigit = (1 << 3), + __ctype_space = (1 << 4), + __ctype_print = (1 << 5), + __ctype_punct = (1 << 6), + __ctype_cntrl = (1 << 7), +}; + +extern const unsigned char __ctypes[]; + +static inline int __ctype_isalnum(int __c) +{ + return __ctypes[__c + 1] & + (__ctype_upper | __ctype_lower | __ctype_digit); +} + +static inline int __ctype_isalpha(int __c) +{ + return __ctypes[__c + 1] & (__ctype_upper | __ctype_lower); +} + +static inline int __ctype_isascii(int __c) +{ + return !(__c & ~0x7f); +} + +static inline int __ctype_isblank(int __c) +{ + return (__c == '\t') || (__c == ' '); +} + +static inline int __ctype_iscntrl(int __c) +{ + return __ctypes[__c + 1] & __ctype_cntrl; +} + +static inline int __ctype_isdigit(int __c) +{ + return ((unsigned)__c - '0') <= 9; +} + +static inline int __ctype_isgraph(int __c) +{ + return __ctypes[__c + 1] & + (__ctype_upper | __ctype_lower | __ctype_digit | __ctype_punct); +} + +static inline int __ctype_islower(int __c) +{ + return __ctypes[__c + 1] & __ctype_lower; +} + +static inline int __ctype_isprint(int __c) +{ + return __ctypes[__c + 1] & __ctype_print; +} + +static inline int __ctype_ispunct(int __c) +{ + return __ctypes[__c + 1] & __ctype_punct; +} + +static inline int __ctype_isspace(int __c) +{ + return __ctypes[__c + 1] & __ctype_space; +} + +static inline int __ctype_isupper(int __c) +{ + return __ctypes[__c + 1] & __ctype_upper; +} + +static inline int __ctype_isxdigit(int __c) +{ + return __ctypes[__c + 1] & __ctype_xdigit; +} + +/* Note: this is decimal, not hex, to avoid accidental promotion to unsigned */ +#define _toupper(__c) ((__c) & ~32) +#define _tolower(__c) ((__c) | 32) + +static inline int __ctype_toupper(int __c) +{ + return __ctype_islower(__c) ? _toupper(__c) : __c; +} + +static inline int __ctype_tolower(int __c) +{ + return __ctype_isupper(__c) ? _tolower(__c) : __c; +} + +# define __CTYPEFUNC(X) \ + extern int X(int); + +__CTYPEFUNC(isalnum) + __CTYPEFUNC(isalpha) + __CTYPEFUNC(isascii) + __CTYPEFUNC(isblank) + __CTYPEFUNC(iscntrl) + __CTYPEFUNC(isdigit) + __CTYPEFUNC(isgraph) + __CTYPEFUNC(islower) + __CTYPEFUNC(isprint) + __CTYPEFUNC(ispunct) + __CTYPEFUNC(isspace) + __CTYPEFUNC(isupper) + __CTYPEFUNC(isxdigit) + __CTYPEFUNC(toupper) + __CTYPEFUNC(tolower) +#endif /* _CTYPE_H */ diff --git a/kexcrt/kexcrt.dsp b/kexcrt/kexcrt.dsp new file mode 100644 index 0000000..c605940 --- /dev/null +++ b/kexcrt/kexcrt.dsp @@ -0,0 +1,341 @@ +# Microsoft Developer Studio Project File - Name="kexcrt" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Static Library" 0x0104 + +CFG=KEXCRT - WIN32 RELEASE +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "kexcrt.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "kexcrt.mak" CFG="KEXCRT - WIN32 RELEASE" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "kexcrt - Win32 Release" (based on "Win32 (x86) Static Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "" +# PROP Intermediate_Dir "obj" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD CPP /nologo /O2 /I "." /I "msvc" /D "_CTYPE_DISABLE_MACROS" /FD /Oi- /c +# ADD BASE RSC /l 0x415 /d "NDEBUG" +# ADD RSC /l 0x415 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo +# Begin Target + +# Name "kexcrt - Win32 Release" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\_vsnprintf.c +# End Source File +# Begin Source File + +SOURCE=.\msvc\argcargv.c +# End Source File +# Begin Source File + +SOURCE=.\atoi.c +# End Source File +# Begin Source File + +SOURCE=.\atol.c +# End Source File +# Begin Source File + +SOURCE=.\atoll.c +# End Source File +# Begin Source File + +SOURCE=.\msvc\concrt0.c +# End Source File +# Begin Source File + +SOURCE=.\ctypes.c +# End Source File +# Begin Source File + +SOURCE=.\msvc\dllcrt0.c +# End Source File +# Begin Source File + +SOURCE=.\msvc\init.c +# End Source File +# Begin Source File + +SOURCE=.\ctype\isalnum.c +# End Source File +# Begin Source File + +SOURCE=.\ctype\isalpha.c +# End Source File +# Begin Source File + +SOURCE=.\ctype\isascii.c +# End Source File +# Begin Source File + +SOURCE=.\ctype\isblank.c +# End Source File +# Begin Source File + +SOURCE=.\ctype\iscntrl.c +# End Source File +# Begin Source File + +SOURCE=.\ctype\isdigit.c +# End Source File +# Begin Source File + +SOURCE=.\ctype\isgraph.c +# End Source File +# Begin Source File + +SOURCE=.\ctype\islower.c +# End Source File +# Begin Source File + +SOURCE=.\ctype\isprint.c +# End Source File +# Begin Source File + +SOURCE=.\ctype\ispunct.c +# End Source File +# Begin Source File + +SOURCE=.\ctype\isspace.c +# End Source File +# Begin Source File + +SOURCE=.\ctype\isupper.c +# End Source File +# Begin Source File + +SOURCE=.\ctype\isxdigit.c +# End Source File +# Begin Source File + +SOURCE=.\memccpy.c +# End Source File +# Begin Source File + +SOURCE=.\memchr.c +# End Source File +# Begin Source File + +SOURCE=.\memcmp.c +# End Source File +# Begin Source File + +SOURCE=.\memcpy.c +# End Source File +# Begin Source File + +SOURCE=.\memmem.c +# End Source File +# Begin Source File + +SOURCE=.\memmove.c +# End Source File +# Begin Source File + +SOURCE=.\memrchr.c +# End Source File +# Begin Source File + +SOURCE=.\memset.c +# End Source File +# Begin Source File + +SOURCE=.\memswap.c +# End Source File +# Begin Source File + +SOURCE=.\snprintf.c +# End Source File +# Begin Source File + +SOURCE=.\sprintf.c +# End Source File +# Begin Source File + +SOURCE=.\sscanf.c +# End Source File +# Begin Source File + +SOURCE=.\strcat.c +# End Source File +# Begin Source File + +SOURCE=.\strchr.c +# End Source File +# Begin Source File + +SOURCE=.\strcmp.c +# End Source File +# Begin Source File + +SOURCE=.\strcmpi.c +# End Source File +# Begin Source File + +SOURCE=.\strcpy.c +# End Source File +# Begin Source File + +SOURCE=.\strlen.c +# End Source File +# Begin Source File + +SOURCE=.\strncat.c +# End Source File +# Begin Source File + +SOURCE=.\strncmp.c +# End Source File +# Begin Source File + +SOURCE=.\strncpy.c +# End Source File +# Begin Source File + +SOURCE=.\strnicmp.c +# End Source File +# Begin Source File + +SOURCE=.\strnlen.c +# End Source File +# Begin Source File + +SOURCE=.\strntoimax.c +# End Source File +# Begin Source File + +SOURCE=.\strntoumax.c +# End Source File +# Begin Source File + +SOURCE=.\strpbrk.c +# End Source File +# Begin Source File + +SOURCE=.\strrchr.c +# End Source File +# Begin Source File + +SOURCE=.\strsep.c +# End Source File +# Begin Source File + +SOURCE=.\strstr.c +# End Source File +# Begin Source File + +SOURCE=.\strtok.c +# End Source File +# Begin Source File + +SOURCE=.\strtol.c +# End Source File +# Begin Source File + +SOURCE=.\strtoll.c +# End Source File +# Begin Source File + +SOURCE=.\strtoul.c +# End Source File +# Begin Source File + +SOURCE=.\strtoull.c +# End Source File +# Begin Source File + +SOURCE=.\strtoumax.c +# End Source File +# Begin Source File + +SOURCE=.\strupr.c +# End Source File +# Begin Source File + +SOURCE=.\strxspn.c +# End Source File +# Begin Source File + +SOURCE=.\ctype\tolower.c +# End Source File +# Begin Source File + +SOURCE=.\ctype\toupper.c +# End Source File +# Begin Source File + +SOURCE=.\vsnprintf.c +# End Source File +# Begin Source File + +SOURCE=.\vsprintf.c +# End Source File +# Begin Source File + +SOURCE=.\vsscanf.c +# End Source File +# Begin Source File + +SOURCE=.\msvc\wincrt0.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\msvc\argcargv.h +# End Source File +# Begin Source File + +SOURCE=.\ctype\ctypefunc.h +# End Source File +# Begin Source File + +SOURCE=.\ctypes.h +# End Source File +# Begin Source File + +SOURCE=.\msvc\init.h +# End Source File +# Begin Source File + +SOURCE=.\strxspn.h +# End Source File +# End Group +# End Target +# End Project diff --git a/kexcrt/makefile b/kexcrt/makefile new file mode 100644 index 0000000..378723a --- /dev/null +++ b/kexcrt/makefile @@ -0,0 +1,19 @@ +OBJ = atoi.o atol.o atoll.o ctypes.o memccpy.o memchr.o memcmp.o memcpy.o memmem.o memmove.o memrchr.o memset.o memswap.o snprintf.o sprintf.o sscanf.o strcat.o strchr.o strcmp.o strcmpi.o strcpy.o strlen.o strncat.o strncmp.o strncpy.o strnicmp.o strnlen.o strntoimax.o strntoumax.o strpbrk.o strrchr.o strsep.o strstr.o strtok.o strtol.o strtoll.o strtoul.o strtoull.o strtoumax.o strupr.o strxspn.o vsnprintf.o vsprintf.o vsscanf.o _vsnprintf.o \ +ctype/isalnum.o ctype/isalpha.o ctype/isascii.o ctype/isblank.o ctype/iscntrl.o ctype/isdigit.o ctype/isgraph.o ctype/islower.o ctype/isprint.o ctype/ispunct.o ctype/isspace.o ctype/isupper.o ctype/isxdigit.o ctype/tolower.o ctype/toupper.o + +CC = gcc +CFLAGS = -O2 -s -I. -D__NO_CTYPE_INLINES -D__NO_ISOCEXT + +BIN = libkexcrt.a + +all : $(BIN) + +clean : + @del *.o >NUL + @del ctype\*.o >NUL + +$(BIN) : $(OBJ) + ar qcs $@ $(OBJ) + +.c.o : + $(CC) $(CFLAGS) -c -o $@ $< diff --git a/kexcrt/makefile.msv b/kexcrt/makefile.msv new file mode 100644 index 0000000..c18eda6 --- /dev/null +++ b/kexcrt/makefile.msv @@ -0,0 +1,21 @@ +OBJ = atoi.obj atol.obj atoll.obj ctypes.obj memccpy.obj memchr.obj memcmp.obj memcpy.obj memmem.obj memmove.obj memrchr.obj memset.obj memswap.obj snprintf.obj sprintf.obj sscanf.obj strcat.obj strchr.obj strcmp.obj strcmpi.obj strcpy.obj strlen.obj strncat.obj strncmp.obj strncpy.obj strnicmp.obj strnlen.obj strntoimax.obj strntoumax.obj strpbrk.obj strrchr.obj strsep.obj strstr.obj strtok.obj strtol.obj strtoll.obj strtoul.obj strtoull.obj strtoumax.obj strupr.obj strxspn.obj vsnprintf.obj vsprintf.obj vsscanf.obj _vsnprintf.obj \ +ctype/isalnum.obj ctype/isalpha.obj ctype/isascii.obj ctype/isblank.obj ctype/iscntrl.obj ctype/isdigit.obj ctype/isgraph.obj ctype/islower.obj ctype/isprint.obj ctype/ispunct.obj ctype/isspace.obj ctype/isupper.obj ctype/isxdigit.obj ctype/tolower.obj ctype/toupper.obj \ +msvc/init.obj msvc/dllcrt0.obj + +CFLAGS = /O2 /Oi- /I. /nologo /D_CTYPE_DISABLE_MACROS + +CC = cl +BIN = kexcrt.lib + +all : $(BIN) + +clean : + @del *.obj >NUL + @del ctype\*.obj >NUL + @del msvc\*.obj >NUL + +$(BIN) : $(OBJ) + link /LIB /NODEFAULTLIB /OUT:$@ $(OBJ) + +.c.obj : + $(CC) $(CFLAGS) /c /Fo$@ $< diff --git a/kexcrt/memccpy.c b/kexcrt/memccpy.c new file mode 100644 index 0000000..83d02c9 --- /dev/null +++ b/kexcrt/memccpy.c @@ -0,0 +1,23 @@ +/* + * memccpy.c + * + * memccpy() + */ + +#include +#include + +void *memccpy(void *dst, const void *src, int c, size_t n) +{ + char *q = dst; + const char *p = src; + char ch; + + while (n--) { + *q++ = ch = *p++; + if (ch == (char)c) + return q; + } + + return NULL; /* No instance of "c" found */ +} diff --git a/kexcrt/memchr.c b/kexcrt/memchr.c new file mode 100644 index 0000000..f1947fb --- /dev/null +++ b/kexcrt/memchr.c @@ -0,0 +1,19 @@ +/* + * memchr.c + */ + +#include +#include + +void *memchr(const void *s, int c, size_t n) +{ + const unsigned char *sp = s; + + while (n--) { + if (*sp == (unsigned char)c) + return (void *)sp; + sp++; + } + + return NULL; +} diff --git a/kexcrt/memcmp.c b/kexcrt/memcmp.c new file mode 100644 index 0000000..3ce9941 --- /dev/null +++ b/kexcrt/memcmp.c @@ -0,0 +1,19 @@ +/* + * memcmp.c + */ + +#include + +int memcmp(const void *s1, const void *s2, size_t n) +{ + const unsigned char *c1 = s1, *c2 = s2; + int d = 0; + + while (n--) { + d = (int)*c1++ - (int)*c2++; + if (d) + break; + } + + return d; +} diff --git a/kexcrt/memcpy.c b/kexcrt/memcpy.c new file mode 100644 index 0000000..a097ef0 --- /dev/null +++ b/kexcrt/memcpy.c @@ -0,0 +1,28 @@ +/* + * memcpy.c + */ + +#include + +void *memcpy(void *dst, const void *src, size_t n) +{ + const char *p = src; + char *q = dst; +#if defined(__i386__) + size_t nl = n >> 2; + asm volatile ("cld ; rep ; movsl ; movl %3,%0 ; rep ; movsb":"+c" (nl), + "+S"(p), "+D"(q) + :"r"(n & 3)); +#elif defined(__x86_64__) + size_t nq = n >> 3; + asm volatile ("cld ; rep ; movsq ; movl %3,%%ecx ; rep ; movsb":"+c" + (nq), "+S"(p), "+D"(q) + :"r"((uint32_t) (n & 7))); +#else + while (n--) { + *q++ = *p++; + } +#endif + + return dst; +} diff --git a/kexcrt/memmem.c b/kexcrt/memmem.c new file mode 100644 index 0000000..8b5faa0 --- /dev/null +++ b/kexcrt/memmem.c @@ -0,0 +1,52 @@ +/* + * memmem.c + * + * Find a byte string inside a longer byte string + * + * This uses the "Not So Naive" algorithm, a very simple but + * usually effective algorithm, see: + * + * http://www-igm.univ-mlv.fr/~lecroq/string/ + */ + +#include + +void *memmem(const void *haystack, size_t n, const void *needle, size_t m) +{ + const unsigned char *y = (const unsigned char *)haystack; + const unsigned char *x = (const unsigned char *)needle; + + size_t j, k, l; + + if (m > n || !m || !n) + return NULL; + + if (1 != m) { + if (x[0] == x[1]) { + k = 2; + l = 1; + } else { + k = 1; + l = 2; + } + + j = 0; + while (j <= n - m) { + if (x[1] != y[j + 1]) { + j += k; + } else { + if (!memcmp(x + 2, y + j + 2, m - 2) + && x[0] == y[j]) + return (void *)&y[j]; + j += l; + } + } + } else + do { + if (*y == *x) + return (void *)y; + y++; + } while (--n); + + return NULL; +} diff --git a/kexcrt/memmove.c b/kexcrt/memmove.c new file mode 100644 index 0000000..659c778 --- /dev/null +++ b/kexcrt/memmove.c @@ -0,0 +1,36 @@ +/* + * memmove.c + */ + +#include + +void *memmove(void *dst, const void *src, size_t n) +{ + const char *p = src; + char *q = dst; +#if defined(__i386__) || defined(__x86_64__) + if (q < p) { + asm volatile("cld ; rep ; movsb" + : "+c" (n), "+S"(p), "+D"(q)); + } else { + p += (n - 1); + q += (n - 1); + asm volatile("std ; rep ; movsb" + : "+c" (n), "+S"(p), "+D"(q)); + } +#else + if (q < p) { + while (n--) { + *q++ = *p++; + } + } else { + p += n; + q += n; + while (n--) { + *--q = *--p; + } + } +#endif + + return dst; +} diff --git a/kexcrt/memrchr.c b/kexcrt/memrchr.c new file mode 100644 index 0000000..ff6d711 --- /dev/null +++ b/kexcrt/memrchr.c @@ -0,0 +1,19 @@ +/* + * memrchr.c + */ + +#include +#include + +void *memrchr(const void *s, int c, size_t n) +{ + const unsigned char *sp = (const unsigned char *)s + n - 1; + + while (n--) { + if (*sp == (unsigned char)c) + return (void *)sp; + sp--; + } + + return NULL; +} diff --git a/kexcrt/memset.c b/kexcrt/memset.c new file mode 100644 index 0000000..e86980b --- /dev/null +++ b/kexcrt/memset.c @@ -0,0 +1,29 @@ +/* + * memset.c + */ + +#include + +void *memset(void *dst, int c, size_t n) +{ + char *q = dst; + +#if defined(__i386__) + size_t nl = n >> 2; + asm volatile ("cld ; rep ; stosl ; movl %3,%0 ; rep ; stosb" + : "+c" (nl), "+D" (q) + : "a" ((unsigned char)c * 0x01010101U), "r" (n & 3)); +#elif defined(__x86_64__) + size_t nq = n >> 3; + asm volatile ("cld ; rep ; stosq ; movl %3,%%ecx ; rep ; stosb" + :"+c" (nq), "+D" (q) + : "a" ((unsigned char)c * 0x0101010101010101U), + "r" ((uint32_t) n & 7)); +#else + while (n--) { + *q++ = c; + } +#endif + + return dst; +} diff --git a/kexcrt/memswap.c b/kexcrt/memswap.c new file mode 100644 index 0000000..b32315c --- /dev/null +++ b/kexcrt/memswap.c @@ -0,0 +1,24 @@ +/* + * memswap() + * + * Swaps the contents of two nonoverlapping memory areas. + * This really could be done faster... + */ + +#include + +void memswap(void *m1, void *m2, size_t n) +{ + char *p = m1; + char *q = m2; + char tmp; + + while (n--) { + tmp = *p; + *p = *q; + *q = tmp; + + p++; + q++; + } +} diff --git a/kexcrt/msvc/STDINT.H b/kexcrt/msvc/STDINT.H new file mode 100644 index 0000000..3d77f99 --- /dev/null +++ b/kexcrt/msvc/STDINT.H @@ -0,0 +1,184 @@ +/* ISO C9x 7.18 Integer types + * Based on ISO/IEC SC22/WG14 9899 Committee draft (SC22 N2794) + * + * THIS SOFTWARE IS NOT COPYRIGHTED + * + * Contributor: Danny Smith + * + * 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 + +/* 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 : + "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 diff --git a/kexcrt/msvc/argcargv.c b/kexcrt/msvc/argcargv.c new file mode 100644 index 0000000..7b0df34 --- /dev/null +++ b/kexcrt/msvc/argcargv.c @@ -0,0 +1,112 @@ +//========================================== +// LIBCTINY - Matt Pietrek 2001 +// MSDN Magazine, January 2001 +//========================================== +#include +#include "argcargv.h" + +#define _MAX_CMD_LINE_ARGS 128 + +char * _ppszArgv[_MAX_CMD_LINE_ARGS+1]; + +int __cdecl _ConvertCommandLineToArgcArgv( void ) +{ + int cbCmdLine; + int argc; + PSTR pszSysCmdLine, pszCmdLine; + + // Set to no argv elements, in case we have to bail out + _ppszArgv[0] = 0; + + // First get a pointer to the system's version of the command line, and + // figure out how long it is. + pszSysCmdLine = GetCommandLine(); + cbCmdLine = lstrlen( pszSysCmdLine ); + + // Allocate memory to store a copy of the command line. We'll modify + // this copy, rather than the original command line. Yes, this memory + // currently doesn't explicitly get freed, but it goes away when the + // process terminates. + pszCmdLine = (PSTR)HeapAlloc( GetProcessHeap(), 0, cbCmdLine+1 ); + if ( !pszCmdLine ) + return 0; + + // Copy the system version of the command line into our copy + lstrcpy( pszCmdLine, pszSysCmdLine ); + + if ( '"' == *pszCmdLine ) // If command line starts with a quote ("), + { // it's a quoted filename. Skip to next quote. + pszCmdLine++; + + _ppszArgv[0] = pszCmdLine; // argv[0] == executable name + + while ( *pszCmdLine && (*pszCmdLine != '"') ) + pszCmdLine++; + + if ( *pszCmdLine ) // Did we see a non-NULL ending? + *pszCmdLine++ = 0; // Null terminate and advance to next char + else + return 0; // Oops! We didn't see the end quote + } + else // A regular (non-quoted) filename + { + _ppszArgv[0] = pszCmdLine; // argv[0] == executable name + + while ( *pszCmdLine && (' ' != *pszCmdLine) && ('\t' != *pszCmdLine) ) + pszCmdLine++; + + if ( *pszCmdLine ) + *pszCmdLine++ = 0; // Null terminate and advance to next char + } + + // Done processing argv[0] (i.e., the executable name). Now do th + // actual arguments + + argc = 1; + + while ( 1 ) + { + // Skip over any whitespace + while ( *pszCmdLine && (' ' == *pszCmdLine) || ('\t' == *pszCmdLine) ) + pszCmdLine++; + + if ( 0 == *pszCmdLine ) // End of command line??? + return argc; + + if ( '"' == *pszCmdLine ) // Argument starting with a quote??? + { + pszCmdLine++; // Advance past quote character + + _ppszArgv[ argc++ ] = pszCmdLine; + _ppszArgv[ argc ] = 0; + + // Scan to end quote, or NULL terminator + while ( *pszCmdLine && (*pszCmdLine != '"') ) + pszCmdLine++; + + if ( 0 == *pszCmdLine ) + return argc; + + if ( *pszCmdLine ) + *pszCmdLine++ = 0; // Null terminate and advance to next char + } + else // Non-quoted argument + { + _ppszArgv[ argc++ ] = pszCmdLine; + _ppszArgv[ argc ] = 0; + + // Skip till whitespace or NULL terminator + while ( *pszCmdLine && (' '!=*pszCmdLine) && ('\t'!=*pszCmdLine) ) + pszCmdLine++; + + if ( 0 == *pszCmdLine ) + return argc; + + if ( *pszCmdLine ) + *pszCmdLine++ = 0; // Null terminate and advance to next char + } + + if ( argc >= (_MAX_CMD_LINE_ARGS) ) + return argc; + } +} diff --git a/kexcrt/msvc/argcargv.h b/kexcrt/msvc/argcargv.h new file mode 100644 index 0000000..7e73344 --- /dev/null +++ b/kexcrt/msvc/argcargv.h @@ -0,0 +1,3 @@ +extern char * _ppszArgv[]; + +int __cdecl _ConvertCommandLineToArgcArgv( void ); diff --git a/kexcrt/msvc/concrt0.c b/kexcrt/msvc/concrt0.c new file mode 100644 index 0000000..b2064aa --- /dev/null +++ b/kexcrt/msvc/concrt0.c @@ -0,0 +1,20 @@ +#include +#include "argcargv.h" +#include "init.h" + +int main(int, char **); + +void mainCRTStartup(void) +{ + int mainret, argc; + + argc = _ConvertCommandLineToArgcArgv(); + + __init(); + + mainret = main(argc, _ppszArgv); + + __exit(); + + ExitProcess(mainret); +} diff --git a/kexcrt/msvc/dllcrt0.c b/kexcrt/msvc/dllcrt0.c new file mode 100644 index 0000000..7441c95 --- /dev/null +++ b/kexcrt/msvc/dllcrt0.c @@ -0,0 +1,27 @@ +#include +#include "init.h" + +extern BOOL WINAPI DllMain( + HINSTANCE hDllHandle, + DWORD dwReason, + LPVOID lpReserved +); + +BOOL WINAPI _DllMainCRTStartup( + HINSTANCE hDllHandle, + DWORD dwReason, + LPVOID lpReserved + ) +{ + BOOL ret; + + if (dwReason == DLL_PROCESS_ATTACH) + __init(); + + ret = DllMain(hDllHandle, dwReason, lpReserved); + + if (dwReason == DLL_PROCESS_DETACH) + __exit(); + + return ret; +} diff --git a/kexcrt/msvc/init.c b/kexcrt/msvc/init.c new file mode 100644 index 0000000..b8a899e --- /dev/null +++ b/kexcrt/msvc/init.c @@ -0,0 +1,85 @@ +#include +#include "init.h" + +#define MAX_ATEXIT 32 + +typedef void (__cdecl *_PVFV)(void); + +static _PVFV _atexitlist[MAX_ATEXIT]; +static int _atexitlist_cnt; + +// C initializers +#pragma data_seg(".CRT$XIA") +_PVFV __xi_a[] = { NULL }; +#pragma data_seg(".CRT$XIZ") +_PVFV __xi_z[] = { NULL }; + +// C++ initializers +#pragma data_seg(".CRT$XCA") +_PVFV __xc_a[] = { NULL }; +#pragma data_seg(".CRT$XCZ") +_PVFV __xc_z[] = { NULL }; + +// C pre-terminators +#pragma data_seg(".CRT$XPA") +_PVFV __xp_a[] = { NULL }; +#pragma data_seg(".CRT$XPZ") +_PVFV __xp_z[] = { NULL }; + +// C terminators +#pragma data_seg(".CRT$XTA") +_PVFV __xt_a[] = { NULL }; +#pragma data_seg(".CRT$XTZ") +_PVFV __xt_z[] = { NULL }; + +#pragma data_seg() /* reset */ + +#pragma comment(linker, "/merge:.CRT=.data") + +static void _initterm(_PVFV * pfbegin, _PVFV * pfend) +{ + while (pfbegin < pfend) + { + if (*pfbegin != NULL) + (**pfbegin)(); + ++pfbegin; + } +} + +void __init(void) +{ + // do initializations + _initterm( __xi_a, __xi_z ); + // do C++ initializations + _initterm( __xc_a, __xc_z ); +} + +int atexit(_PVFV func) +{ + if (_atexitlist_cnt < MAX_ATEXIT) + { + _atexitlist[_atexitlist_cnt++] = func; + return 0; + } + + return -1; +} + +void __exit(void) +{ + // do pre-terminators + _initterm(__xp_a, __xp_z); + // do terminators + _initterm(__xt_a, __xt_z); + + if (_atexitlist_cnt) + { + _PVFV* p; + for (p = _atexitlist + _atexitlist_cnt - 1 ; p >= _atexitlist ; p--) + { + if (*p != NULL) + (**p)(); + p--; + } + } +} diff --git a/kexcrt/msvc/init.h b/kexcrt/msvc/init.h new file mode 100644 index 0000000..bf761cc --- /dev/null +++ b/kexcrt/msvc/init.h @@ -0,0 +1,7 @@ +#ifndef __INIT_H +#define __INIT_H + +void __init(void); +void __exit(void); + +#endif diff --git a/kexcrt/msvc/wincrt0.c b/kexcrt/msvc/wincrt0.c new file mode 100644 index 0000000..5404622 --- /dev/null +++ b/kexcrt/msvc/wincrt0.c @@ -0,0 +1,53 @@ +#include +#include "init.h" + +void WinMainCRTStartup(void) +{ + int mainret; + char* lpszCommandLine; + STARTUPINFO StartupInfo; + + lpszCommandLine = GetCommandLine(); + + // Skip past program name (first token in command line). + + if ( *lpszCommandLine == '"' ) // Check for and handle quoted program name + { + lpszCommandLine++; // Get past the first quote + + // Now, scan, and skip over, subsequent characters until another + // double-quote or a null is encountered + while( *lpszCommandLine && (*lpszCommandLine != '"') ) + lpszCommandLine++; + + // If we stopped on a double-quote (usual case), skip over it. + + if ( *lpszCommandLine == '"' ) + lpszCommandLine++; + } + else // First token wasn't a quote + { + while ( *lpszCommandLine > ' ' ) + lpszCommandLine++; + } + + // Skip past any white space preceeding the second token. + + while ( *lpszCommandLine && (*lpszCommandLine <= ' ') ) + lpszCommandLine++; + + StartupInfo.dwFlags = 0; + GetStartupInfo( &StartupInfo ); + + __init(); + + mainret = WinMain( GetModuleHandle(NULL), + NULL, + lpszCommandLine, + StartupInfo.dwFlags & STARTF_USESHOWWINDOW + ? StartupInfo.wShowWindow : SW_SHOWDEFAULT ); + + __exit(); + + ExitProcess(mainret); +} diff --git a/kexcrt/snprintf.c b/kexcrt/snprintf.c new file mode 100644 index 0000000..4edcb06 --- /dev/null +++ b/kexcrt/snprintf.c @@ -0,0 +1,17 @@ +/* + * snprintf.c + */ + +#include +#include + +int snprintf(char *buffer, size_t n, const char *format, ...) +{ + va_list ap; + int rv; + + va_start(ap, format); + rv = vsnprintf(buffer, n, format, ap); + va_end(ap); + return rv; +} diff --git a/kexcrt/sprintf.c b/kexcrt/sprintf.c new file mode 100644 index 0000000..47da695 --- /dev/null +++ b/kexcrt/sprintf.c @@ -0,0 +1,18 @@ +/* + * sprintf.c + */ + +#include +#include + +int sprintf(char *buffer, const char *format, ...) +{ + va_list ap; + int rv; + + va_start(ap, format); + rv = vsnprintf(buffer, ~(size_t) 0, format, ap); + va_end(ap); + + return rv; +} diff --git a/kexcrt/sscanf.c b/kexcrt/sscanf.c new file mode 100644 index 0000000..8fb9106 --- /dev/null +++ b/kexcrt/sscanf.c @@ -0,0 +1,18 @@ +/* + * sscanf() + */ + +#include +#include + +int sscanf(const char *str, const char *format, ...) +{ + va_list ap; + int rv; + + va_start(ap, format); + rv = vsscanf(str, format, ap); + va_end(ap); + + return rv; +} diff --git a/kexcrt/strcat.c b/kexcrt/strcat.c new file mode 100644 index 0000000..6c5b673 --- /dev/null +++ b/kexcrt/strcat.c @@ -0,0 +1,11 @@ +/* + * strcat.c + */ + +#include + +char *strcat(char *dst, const char *src) +{ + strcpy(strchr(dst, '\0'), src); + return dst; +} diff --git a/kexcrt/strchr.c b/kexcrt/strchr.c new file mode 100644 index 0000000..fc0ebcb --- /dev/null +++ b/kexcrt/strchr.c @@ -0,0 +1,16 @@ +/* + * strchr.c + */ + +#include + +char *strchr(const char *s, int c) +{ + while (*s != (char)c) { + if (!*s) + return NULL; + s++; + } + + return (char *)s; +} diff --git a/kexcrt/strcmp.c b/kexcrt/strcmp.c new file mode 100644 index 0000000..3ab9f5a --- /dev/null +++ b/kexcrt/strcmp.c @@ -0,0 +1,21 @@ +/* + * strcmp.c + */ + +#include + +int strcmp(const char *s1, const char *s2) +{ + const unsigned char *c1 = (const unsigned char *)s1; + const unsigned char *c2 = (const unsigned char *)s2; + unsigned char ch; + int d = 0; + + while (1) { + d = (int)(ch = *c1++) - (int)*c2++; + if (d || !ch) + break; + } + + return d; +} diff --git a/kexcrt/strcmpi.c b/kexcrt/strcmpi.c new file mode 100644 index 0000000..60955ec --- /dev/null +++ b/kexcrt/strcmpi.c @@ -0,0 +1,24 @@ +/* + * strcmpi.c + */ + +#include +#include + +int strcmpi(const char *s1, const char *s2) +{ + const unsigned char *c1 = (const unsigned char *)s1; + const unsigned char *c2 = (const unsigned char *)s2; + unsigned char ch; + int d = 0; + + while (1) { + /* toupper() expects an unsigned char (implicitly cast to int) + as input, and returns an int, which is exactly what we want. */ + d = toupper(ch = *c1++) - toupper(*c2++); + if (d || !ch) + break; + } + + return d; +} diff --git a/kexcrt/strcpy.c b/kexcrt/strcpy.c new file mode 100644 index 0000000..aa656cf --- /dev/null +++ b/kexcrt/strcpy.c @@ -0,0 +1,20 @@ +/* + * strcpy.c + * + * strcpy() + */ + +#include + +char *strcpy(char *dst, const char *src) +{ + char *q = dst; + const char *p = src; + char ch; + + do { + *q++ = ch = *p++; + } while (ch); + + return dst; +} diff --git a/kexcrt/strlen.c b/kexcrt/strlen.c new file mode 100644 index 0000000..86526a5 --- /dev/null +++ b/kexcrt/strlen.c @@ -0,0 +1,13 @@ +/* + * strlen() + */ + +#include + +size_t strlen(const char *s) +{ + const char *ss = s; + while (*ss) + ss++; + return ss - s; +} diff --git a/kexcrt/strncat.c b/kexcrt/strncat.c new file mode 100644 index 0000000..5b86216 --- /dev/null +++ b/kexcrt/strncat.c @@ -0,0 +1,21 @@ +/* + * strncat.c + */ + +#include + +char *strncat(char *dst, const char *src, size_t n) +{ + char *q = strchr(dst, '\0'); + const char *p = src; + char ch; + + while (n--) { + *q++ = ch = *p++; + if (!ch) + return dst; + } + *q = '\0'; + + return dst; +} diff --git a/kexcrt/strncmp.c b/kexcrt/strncmp.c new file mode 100644 index 0000000..5235545 --- /dev/null +++ b/kexcrt/strncmp.c @@ -0,0 +1,21 @@ +/* + * strncmp.c + */ + +#include + +int strncmp(const char *s1, const char *s2, size_t n) +{ + const unsigned char *c1 = (const unsigned char *)s1; + const unsigned char *c2 = (const unsigned char *)s2; + unsigned char ch; + int d = 0; + + while (n--) { + d = (int)(ch = *c1++) - (int)*c2++; + if (d || !ch) + break; + } + + return d; +} diff --git a/kexcrt/strncpy.c b/kexcrt/strncpy.c new file mode 100644 index 0000000..fffc118 --- /dev/null +++ b/kexcrt/strncpy.c @@ -0,0 +1,24 @@ +/* + * strncpy.c + */ + +#include + +char *strncpy(char *dst, const char *src, size_t n) +{ + char *q = dst; + const char *p = src; + char ch; + + while (n) { + n--; + *q++ = ch = *p++; + if (!ch) + break; + } + + /* The specs say strncpy() fills the entire buffer with NUL. Sigh. */ + memset(q, 0, n); + + return dst; +} diff --git a/kexcrt/strnicmp.c b/kexcrt/strnicmp.c new file mode 100644 index 0000000..9421714 --- /dev/null +++ b/kexcrt/strnicmp.c @@ -0,0 +1,24 @@ +/* + * strnicmp.c + */ + +#include +#include + +int strnicmp(const char *s1, const char *s2, size_t n) +{ + const unsigned char *c1 = (const unsigned char *)s1; + const unsigned char *c2 = (const unsigned char *)s2; + unsigned char ch; + int d = 0; + + while (n--) { + /* toupper() expects an unsigned char (implicitly cast to int) + as input, and returns an int, which is exactly what we want. */ + d = toupper(ch = *c1++) - toupper(*c2++); + if (d || !ch) + break; + } + + return d; +} diff --git a/kexcrt/strnlen.c b/kexcrt/strnlen.c new file mode 100644 index 0000000..1678f4b --- /dev/null +++ b/kexcrt/strnlen.c @@ -0,0 +1,18 @@ +/* + * strnlen() + */ + +#include + +size_t strnlen(const char *s, size_t maxlen) +{ + const char *ss = s; + + /* Important: the maxlen test must precede the reference through ss; + since the byte beyond the maximum may segfault */ + while ((maxlen > 0) && *ss) { + ss++; + maxlen--; + } + return ss - s; +} diff --git a/kexcrt/strntoimax.c b/kexcrt/strntoimax.c new file mode 100644 index 0000000..d761feb --- /dev/null +++ b/kexcrt/strntoimax.c @@ -0,0 +1,13 @@ +/* + * strntoimax.c + * + * strntoimax() + */ + +#include +#include + +intmax_t strntoimax(const char *nptr, char **endptr, int base, size_t n) +{ + return (intmax_t) strntoumax(nptr, endptr, base, n); +} diff --git a/kexcrt/strntoumax.c b/kexcrt/strntoumax.c new file mode 100644 index 0000000..b6d161e --- /dev/null +++ b/kexcrt/strntoumax.c @@ -0,0 +1,80 @@ +/* + * strntoumax.c + * + * The strntoumax() function and associated + */ + +#include +#include +#include + +#ifdef _MSC_VER +# define inline __inline +#endif + +static inline int digitval(int ch) +{ + if (ch >= '0' && ch <= '9') { + return ch - '0'; + } else if (ch >= 'A' && ch <= 'Z') { + return ch - 'A' + 10; + } else if (ch >= 'a' && ch <= 'z') { + return ch - 'a' + 10; + } else { + return -1; + } +} + +uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n) +{ + int minus = 0; + uintmax_t v = 0; + int d; + + while (n && isspace((unsigned char)*nptr)) { + nptr++; + n--; + } + + /* Single optional + or - */ + if (n) { + char c = *nptr; + if (c == '-' || c == '+') { + minus = (c == '-'); + nptr++; + n--; + } + } + + if (base == 0) { + if (n >= 2 && nptr[0] == '0' && + (nptr[1] == 'x' || nptr[1] == 'X')) { + n -= 2; + nptr += 2; + base = 16; + } else if (n >= 1 && nptr[0] == '0') { + n--; + nptr++; + base = 8; + } else { + base = 10; + } + } else if (base == 16) { + if (n >= 2 && nptr[0] == '0' && + (nptr[1] == 'x' || nptr[1] == 'X')) { + n -= 2; + nptr += 2; + } + } + + while (n && (d = digitval(*nptr)) >= 0 && d < base) { + v = v * base + d; + n--; + nptr++; + } + + if (endptr) + *endptr = (char *)nptr; + + return minus ? -v : v; +} diff --git a/kexcrt/strpbrk.c b/kexcrt/strpbrk.c new file mode 100644 index 0000000..ba53d02 --- /dev/null +++ b/kexcrt/strpbrk.c @@ -0,0 +1,12 @@ +/* + * strpbrk + */ + +#include "strxspn.h" + +char *strpbrk(const char *s, const char *accept) +{ + const char *ss = s + __strxspn(s, accept, 1); + + return *ss ? (char *)ss : NULL; +} diff --git a/kexcrt/strrchr.c b/kexcrt/strrchr.c new file mode 100644 index 0000000..d3a626b --- /dev/null +++ b/kexcrt/strrchr.c @@ -0,0 +1,18 @@ +/* + * strrchr.c + */ + +#include + +char *strrchr(const char *s, int c) +{ + const char *found = NULL; + + while (*s) { + if (*s == (char)c) + found = s; + s++; + } + + return (char *)found; +} diff --git a/kexcrt/strsep.c b/kexcrt/strsep.c new file mode 100644 index 0000000..44e76bd --- /dev/null +++ b/kexcrt/strsep.c @@ -0,0 +1,21 @@ +/* + * strsep.c + */ + +#include + +char *strsep(char **stringp, const char *delim) +{ + char *s = *stringp; + char *e; + + if (!s) + return NULL; + + e = strpbrk(s, delim); + if (e) + *e++ = '\0'; + + *stringp = e; + return s; +} diff --git a/kexcrt/strstr.c b/kexcrt/strstr.c new file mode 100644 index 0000000..8850858 --- /dev/null +++ b/kexcrt/strstr.c @@ -0,0 +1,11 @@ +/* + * strstr.c + */ + +#include + +char *strstr(const char *haystack, const char *needle) +{ + return (char *)memmem(haystack, strlen(haystack), needle, + strlen(needle)); +} diff --git a/kexcrt/strtok.c b/kexcrt/strtok.c new file mode 100644 index 0000000..5e7ffb1 --- /dev/null +++ b/kexcrt/strtok.c @@ -0,0 +1,19 @@ +/* + * strtok.c + */ + +char *strsep(char **stringp, const char *delim); + +char *strtok(char *s, const char *delim) +{ + static char *holder; + + if (s) + holder = s; + + do { + s = strsep(&holder, delim); + } while (s && !*s); + + return s; +} diff --git a/kexcrt/strtol.c b/kexcrt/strtol.c new file mode 100644 index 0000000..9efc8b9 --- /dev/null +++ b/kexcrt/strtol.c @@ -0,0 +1,3 @@ +#define TYPE signed long +#define NAME strtol +#include "strtox.c" diff --git a/kexcrt/strtoll.c b/kexcrt/strtoll.c new file mode 100644 index 0000000..b4e302a --- /dev/null +++ b/kexcrt/strtoll.c @@ -0,0 +1,3 @@ +#define TYPE int64_t +#define NAME strtoll +#include "strtox.c" diff --git a/kexcrt/strtoul.c b/kexcrt/strtoul.c new file mode 100644 index 0000000..3189aaa --- /dev/null +++ b/kexcrt/strtoul.c @@ -0,0 +1,3 @@ +#define TYPE unsigned long +#define NAME strtoul +#include "strtox.c" diff --git a/kexcrt/strtoull.c b/kexcrt/strtoull.c new file mode 100644 index 0000000..cf6b662 --- /dev/null +++ b/kexcrt/strtoull.c @@ -0,0 +1,3 @@ +#define TYPE uint64_t +#define NAME strtoull +#include "strtox.c" diff --git a/kexcrt/strtoumax.c b/kexcrt/strtoumax.c new file mode 100644 index 0000000..a379710 --- /dev/null +++ b/kexcrt/strtoumax.c @@ -0,0 +1,3 @@ +#define TYPE uintmax_t +#define NAME strtoumax +#include "strtox.c" diff --git a/kexcrt/strtox.c b/kexcrt/strtox.c new file mode 100644 index 0000000..263fd98 --- /dev/null +++ b/kexcrt/strtox.c @@ -0,0 +1,13 @@ +/* + * strtox.c + * + * strto...() functions, by macro definition + */ + +#include +#include + +TYPE NAME(const char *nptr, char **endptr, int base) +{ + return (TYPE) strntoumax(nptr, endptr, base, ~(size_t) 0); +} diff --git a/kexcrt/strupr.c b/kexcrt/strupr.c new file mode 100644 index 0000000..c91302c --- /dev/null +++ b/kexcrt/strupr.c @@ -0,0 +1,18 @@ +/* + * strupr.c + */ + +#include +#include + +char* strupr(char *s) +{ + unsigned char *c = s; + + while (*c) { + *c = toupper(*c); + c++; + } + + return s; +} diff --git a/kexcrt/strxspn.c b/kexcrt/strxspn.c new file mode 100644 index 0000000..ee8feac --- /dev/null +++ b/kexcrt/strxspn.c @@ -0,0 +1,28 @@ +/* + * strpbrk + */ + +#include +#include +#include +#include "strxspn.h" + +size_t __strxspn(const char *s, const char *map, int parity) +{ + char matchmap[UCHAR_MAX + 1]; + size_t n = 0; + + /* Create bitmap */ + memset(matchmap, 0, sizeof matchmap); + while (*map) + matchmap[(unsigned char)*map++] = 1; + + /* Make sure the null character never matches */ + matchmap[0] = parity; + + /* Calculate span length */ + while (matchmap[(unsigned char)*s++] ^ parity) + n++; + + return n; +} diff --git a/kexcrt/strxspn.h b/kexcrt/strxspn.h new file mode 100644 index 0000000..ce56ff2 --- /dev/null +++ b/kexcrt/strxspn.h @@ -0,0 +1,12 @@ +/* + * strxspn.h + */ + +#ifndef STRXSPN_H +#define STRXSPN_H + +#include + +extern size_t __strxspn(const char *s, const char *map, int parity); + +#endif diff --git a/kexcrt/vsnprintf.c b/kexcrt/vsnprintf.c new file mode 100644 index 0000000..5ea8d58 --- /dev/null +++ b/kexcrt/vsnprintf.c @@ -0,0 +1,487 @@ +/* + * vsnprintf.c + * + * vsnprintf(), from which the rest of the printf() + * family is built + */ + +#include +#include +#include +#include +#include +#include + +enum flags { + FL_ZERO = 0x01, /* Zero modifier */ + FL_MINUS = 0x02, /* Minus modifier */ + FL_PLUS = 0x04, /* Plus modifier */ + FL_TICK = 0x08, /* ' modifier */ + FL_SPACE = 0x10, /* Space modifier */ + FL_HASH = 0x20, /* # modifier */ + FL_SIGNED = 0x40, /* Number is signed */ + FL_UPPER = 0x80 /* Upper case digits */ +}; + +/* These may have to be adjusted on certain implementations */ +enum ranks { + rank_char = -2, + rank_short = -1, + rank_int = 0, + rank_long = 1, + rank_longlong = 2 +}; + +#define MIN_RANK rank_char +#define MAX_RANK rank_longlong + +#define INTMAX_RANK rank_longlong +#define SIZE_T_RANK rank_long +#define PTRDIFF_T_RANK rank_long + +#define EMIT(x) do { if (o nchars) { + while (width > nchars) { + EMIT(' '); + width--; + } + } + + /* Emit nondigits */ + if (minus) + EMIT('-'); + else if (flags & FL_PLUS) + EMIT('+'); + else if (flags & FL_SPACE) + EMIT(' '); + + if ((flags & FL_HASH) && base == 16) { + EMIT('0'); + EMIT((flags & FL_UPPER) ? 'X' : 'x'); + } + + /* Emit zero padding */ + if ((flags & (FL_MINUS | FL_ZERO)) == FL_ZERO && width > ndigits) { + while (width > nchars) { + EMIT('0'); + width--; + } + } + + /* Generate the number. This is done from right to left. */ + q += ndigits; /* Advance the pointer to end of number */ + o += ndigits; + qq = q; + oo = o; /* Temporary values */ + + b4tick = tickskip; + while (ndigits > 0) { + if (!b4tick--) { + qq--; + oo--; + ndigits--; + if (oo < n) + *qq = '_'; + b4tick = tickskip - 1; + } + qq--; + oo--; + ndigits--; + if (oo < n) + *qq = digits[val % base]; + val /= base; + } + + /* Emit late space padding */ + while ((flags & FL_MINUS) && width > nchars) { + EMIT(' '); + width--; + } + + return o; +} + +int vsnprintf(char *buffer, size_t n, const char *format, va_list ap) +{ + const char *p = format; + char ch; + char *q = buffer; + size_t o = 0; /* Number of characters output */ + uintmax_t val = 0; + int rank = rank_int; /* Default rank */ + int width = 0; + int prec = -1; + int base; + size_t sz; + enum flags flags = 0; + enum { + st_normal, /* Ground state */ + st_flags, /* Special flags */ + st_width, /* Field width */ + st_prec, /* Field precision */ + st_modifiers /* Length or conversion modifiers */ + } state = st_normal; + const char *sarg; /* %s string argument */ + char carg; /* %c char argument */ + int slen; /* String length */ + + while ((ch = *p++)) { + switch (state) { + case st_normal: + if (ch == '%') { + state = st_flags; + flags = 0; + rank = rank_int; + width = 0; + prec = -1; + } else { + EMIT(ch); + } + break; + + case st_flags: + switch (ch) { + case '-': + flags |= FL_MINUS; + break; + case '+': + flags |= FL_PLUS; + break; + case '\'': + flags |= FL_TICK; + break; + case ' ': + flags |= FL_SPACE; + break; + case '#': + flags |= FL_HASH; + break; + case '0': + flags |= FL_ZERO; + break; + default: + state = st_width; + p--; /* Process this character again */ + break; + } + break; + + case st_width: + if (ch >= '0' && ch <= '9') { + width = width * 10 + (ch - '0'); + } else if (ch == '*') { + width = va_arg(ap, int); + if (width < 0) { + width = -width; + flags |= FL_MINUS; + } + } else if (ch == '.') { + prec = 0; /* Precision given */ + state = st_prec; + } else { + state = st_modifiers; + p--; /* Process this character again */ + } + break; + + case st_prec: + if (ch >= '0' && ch <= '9') { + prec = prec * 10 + (ch - '0'); + } else if (ch == '*') { + prec = va_arg(ap, int); + if (prec < 0) + prec = -1; + } else { + state = st_modifiers; + p--; /* Process this character again */ + } + break; + + case st_modifiers: + switch (ch) { + /* Length modifiers - nonterminal sequences */ + case 'h': + rank--; /* Shorter rank */ + break; + case 'l': + rank++; /* Longer rank */ + break; + case 'j': + rank = INTMAX_RANK; + break; + case 'z': + rank = SIZE_T_RANK; + break; + case 't': + rank = PTRDIFF_T_RANK; + break; + case 'L': + case 'q': + rank += 2; + break; + default: + /* Output modifiers - terminal sequences */ + + /* Next state will be normal */ + state = st_normal; + + /* Canonicalize rank */ + if (rank < MIN_RANK) + rank = MIN_RANK; + else if (rank > MAX_RANK) + rank = MAX_RANK; + + switch (ch) { + case 'P': /* Upper case pointer */ + flags |= FL_UPPER; + /* fall through */ + case 'p': /* Pointer */ + base = 16; + prec = (CHAR_BIT*sizeof(void *)+3)/4; + flags |= FL_HASH; + val = (uintmax_t)(uintptr_t) + va_arg(ap, void *); + goto is_integer; + + case 'd': /* Signed decimal output */ + case 'i': + base = 10; + flags |= FL_SIGNED; + switch (rank) { + case rank_char: + /* Yes, all these casts are + needed... */ + val = (uintmax_t)(intmax_t) + (signed char) + va_arg(ap, signed int); + break; + case rank_short: + val = (uintmax_t)(intmax_t) + (signed short) + va_arg(ap, signed int); + break; + case rank_int: + val = (uintmax_t)(intmax_t) + va_arg(ap, signed int); + break; + case rank_long: + val = (uintmax_t)(intmax_t) + va_arg(ap, signed long); + break; + case rank_longlong: + val = (uintmax_t)(intmax_t) + va_arg(ap, + int64_t); + break; + } + goto is_integer; + case 'o': /* Octal */ + base = 8; + goto is_unsigned; + case 'u': /* Unsigned decimal */ + base = 10; + goto is_unsigned; + case 'X': /* Upper case hexadecimal */ + flags |= FL_UPPER; + /* fall through */ + case 'x': /* Hexadecimal */ + base = 16; + goto is_unsigned; + + is_unsigned: + switch (rank) { + case rank_char: + val = (uintmax_t) + (unsigned char) + va_arg(ap, unsigned + int); + break; + case rank_short: + val = (uintmax_t) + (unsigned short) + va_arg(ap, unsigned + int); + break; + case rank_int: + val = (uintmax_t) + va_arg(ap, unsigned + int); + break; + case rank_long: + val = (uintmax_t) + va_arg(ap, unsigned + long); + break; + case rank_longlong: + val = (uintmax_t) + va_arg(ap, uint64_t); + break; + } + /* fall through */ + + is_integer: + sz = format_int(q, (o < n) ? n - o : 0, + val, flags, base, + width, prec); + q += sz; + o += sz; + break; + + case 'c': /* Character */ + carg = (char)va_arg(ap, int); + sarg = &carg; + slen = 1; + goto is_string; + case 's': /* String */ + sarg = va_arg(ap, const char *); + sarg = sarg ? sarg : "(null)"; + slen = strlen(sarg); + goto is_string; + + is_string: + { + char sch; + int i; + + if (prec != -1 && slen > prec) + slen = prec; + + if (width > slen + && !(flags & FL_MINUS)) { + char pad = + (flags & FL_ZERO) ? + '0' : ' '; + while (width > slen) { + EMIT(pad); + width--; + } + } + for (i = slen; i; i--) { + sch = *sarg++; + EMIT(sch); + } + if (width > slen + && (flags & FL_MINUS)) { + while (width > slen) { + EMIT(' '); + width--; + } + } + } + break; + + case 'n': + { + /* Output the number of + characters written */ + + switch (rank) { + case rank_char: + *va_arg(ap, + signed char *) + = o; + break; + case rank_short: + *va_arg(ap, + signed short *) + = o; + break; + case rank_int: + *va_arg(ap, + signed int *) + = o; + break; + case rank_long: + *va_arg(ap, + signed long *) + = o; + break; + case rank_longlong: + *va_arg(ap, + int64_t *) + = o; + break; + } + } + break; + + default: /* Anything else, including % */ + EMIT(ch); + break; + } + } + } + } + + /* Null-terminate the string */ + if (o < n) + *q = '\0'; /* No overflow */ + else if (n > 0) + buffer[n - 1] = '\0'; /* Overflow - terminate at end of buffer */ + + return o; +} diff --git a/kexcrt/vsprintf.c b/kexcrt/vsprintf.c new file mode 100644 index 0000000..c744feb --- /dev/null +++ b/kexcrt/vsprintf.c @@ -0,0 +1,11 @@ +/* + * vsprintf.c + */ + +#include +#include + +int vsprintf(char *buffer, const char *format, va_list ap) +{ + return vsnprintf(buffer, ~(size_t) 0, format, ap); +} diff --git a/kexcrt/vsscanf.c b/kexcrt/vsscanf.c new file mode 100644 index 0000000..f45337f --- /dev/null +++ b/kexcrt/vsscanf.c @@ -0,0 +1,411 @@ +/* + * vsscanf.c + * + * vsscanf(), from which the rest of the scanf() + * family is built + */ + +#include +#include +#include +#include +#include +#include +#include + +#ifndef LONG_BIT +#define LONG_BIT (CHAR_BIT*sizeof(long)) +#endif + +#ifdef _MSC_VER +# define inline __inline +#endif + +enum flags { + FL_SPLAT = 0x01, /* Drop the value, do not assign */ + FL_INV = 0x02, /* Character-set with inverse */ + FL_WIDTH = 0x04, /* Field width specified */ + FL_MINUS = 0x08, /* Negative number */ +}; + +enum ranks { + rank_char = -2, + rank_short = -1, + rank_int = 0, + rank_long = 1, + rank_longlong = 2, + rank_ptr = INT_MAX /* Special value used for pointers */ +}; + +#define MIN_RANK rank_char +#define MAX_RANK rank_longlong + +#define INTMAX_RANK rank_longlong +#define SIZE_T_RANK rank_long +#define PTRDIFF_T_RANK rank_long + +enum bail { + bail_none = 0, /* No error condition */ + bail_eof, /* Hit EOF */ + bail_err /* Conversion mismatch */ +}; + +static inline const char *skipspace(const char *p) +{ + while (isspace((unsigned char)*p)) + p++; + return p; +} + +#undef set_bit +static inline void set_bit(unsigned long *bitmap, unsigned int bit) +{ + bitmap[bit / LONG_BIT] |= 1UL << (bit % LONG_BIT); +} + +#undef test_bit +static inline int test_bit(unsigned long *bitmap, unsigned int bit) +{ + return (int)(bitmap[bit / LONG_BIT] >> (bit % LONG_BIT)) & 1; +} + +int vsscanf(const char *buffer, const char *format, va_list ap) +{ + const char *p = format; + char ch; + unsigned char uc; + const char *q = buffer; + const char *qq; + uintmax_t val = 0; + int rank = rank_int; /* Default rank */ + unsigned int width = UINT_MAX; + int base; + enum flags flags = 0; + enum { + st_normal, /* Ground state */ + st_flags, /* Special flags */ + st_width, /* Field width */ + st_modifiers, /* Length or conversion modifiers */ + st_match_init, /* Initial state of %[ sequence */ + st_match, /* Main state of %[ sequence */ + st_match_range, /* After - in a %[ sequence */ + } state = st_normal; + char *sarg = NULL; /* %s %c or %[ string argument */ + enum bail bail = bail_none; + int sign; + int converted = 0; /* Successful conversions */ + unsigned long matchmap[((1 << CHAR_BIT) + (LONG_BIT - 1)) / LONG_BIT]; + int matchinv = 0; /* Is match map inverted? */ + unsigned char range_start = 0; + + while ((ch = *p++) && !bail) { + switch (state) { + case st_normal: + if (ch == '%') { + state = st_flags; + flags = 0; + rank = rank_int; + width = UINT_MAX; + } else if (isspace((unsigned char)ch)) { + q = skipspace(q); + } else { + if (*q == ch) + q++; + else + bail = bail_err; /* Match failure */ + } + break; + + case st_flags: + switch (ch) { + case '*': + flags |= FL_SPLAT; + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + width = (ch - '0'); + state = st_width; + flags |= FL_WIDTH; + break; + default: + state = st_modifiers; + p--; /* Process this character again */ + break; + } + break; + + case st_width: + if (ch >= '0' && ch <= '9') { + width = width * 10 + (ch - '0'); + } else { + state = st_modifiers; + p--; /* Process this character again */ + } + break; + + case st_modifiers: + switch (ch) { + /* Length modifiers - nonterminal sequences */ + case 'h': + rank--; /* Shorter rank */ + break; + case 'l': + rank++; /* Longer rank */ + break; + case 'j': + rank = INTMAX_RANK; + break; + case 'z': + rank = SIZE_T_RANK; + break; + case 't': + rank = PTRDIFF_T_RANK; + break; + case 'L': + case 'q': + rank = rank_longlong; /* long double/long long */ + break; + + default: + /* Output modifiers - terminal sequences */ + /* Next state will be normal */ + state = st_normal; + + /* Canonicalize rank */ + if (rank < MIN_RANK) + rank = MIN_RANK; + else if (rank > MAX_RANK) + rank = MAX_RANK; + + switch (ch) { + case 'P': /* Upper case pointer */ + case 'p': /* Pointer */ + rank = rank_ptr; + base = 0; + sign = 0; + goto scan_int; + + case 'i': /* Base-independent integer */ + base = 0; + sign = 1; + goto scan_int; + + case 'd': /* Decimal integer */ + base = 10; + sign = 1; + goto scan_int; + + case 'o': /* Octal integer */ + base = 8; + sign = 0; + goto scan_int; + + case 'u': /* Unsigned decimal integer */ + base = 10; + sign = 0; + goto scan_int; + + case 'x': /* Hexadecimal integer */ + case 'X': + base = 16; + sign = 0; + goto scan_int; + + case 'n': /* # of characters consumed */ + val = (q - buffer); + goto set_integer; + + scan_int: + q = skipspace(q); + if (!*q) { + bail = bail_eof; + break; + } + val = + strntoumax(q, (char **)&qq, base, + width); + if (qq == q) { + bail = bail_err; + break; + } + q = qq; + if (!(flags & FL_SPLAT)) + converted++; + /* fall through */ + + set_integer: + if (!(flags & FL_SPLAT)) { + switch (rank) { + case rank_char: + *va_arg(ap, + unsigned char *) + = val; + break; + case rank_short: + *va_arg(ap, + unsigned short + *) = val; + break; + case rank_int: + *va_arg(ap, + unsigned int *) + = val; + break; + case rank_long: + *va_arg(ap, + unsigned long *) + = val; + break; + case rank_longlong: + *va_arg(ap, + uint64_t *) = val; + break; + case rank_ptr: + *va_arg(ap, void **) = + (void *) + (uintptr_t)val; + break; + } + } + break; + + case 'c': /* Character */ + /* Default width == 1 */ + width = (flags & FL_WIDTH) ? width : 1; + if (flags & FL_SPLAT) { + while (width--) { + if (!*q) { + bail = bail_eof; + break; + } + } + } else { + sarg = va_arg(ap, char *); + while (width--) { + if (!*q) { + bail = bail_eof; + break; + } + *sarg++ = *q++; + } + if (!bail) + converted++; + } + break; + + case 's': /* String */ + uc = 1; /* Anything nonzero */ + if (flags & FL_SPLAT) { + while (width-- && (uc = *q) && + !isspace(uc)) { + q++; + } + } else { + char *sp; + sp = sarg = va_arg(ap, char *); + while (width-- && (uc = *q) && + !isspace(uc)) { + *sp++ = uc; + q++; + } + if (sarg != sp) { + /* Terminate output */ + *sp = '\0'; + converted++; + } + } + if (!uc) + bail = bail_eof; + break; + + case '[': /* Character range */ + sarg = (flags & FL_SPLAT) ? NULL + : va_arg(ap, char *); + state = st_match_init; + matchinv = 0; + memset(matchmap, 0, sizeof matchmap); + break; + + case '%': /* %% sequence */ + if (*q == '%') + q++; + else + bail = bail_err; + break; + + default: /* Anything else */ + /* Unknown sequence */ + bail = bail_err; + break; + } + } + break; + + case st_match_init: /* Initial state for %[ match */ + if (ch == '^' && !(flags & FL_INV)) { + matchinv = 1; + } else { + set_bit(matchmap, (unsigned char)ch); + state = st_match; + } + break; + + case st_match: /* Main state for %[ match */ + if (ch == ']') { + goto match_run; + } else if (ch == '-') { + range_start = (unsigned char)ch; + state = st_match_range; + } else { + set_bit(matchmap, (unsigned char)ch); + } + break; + + case st_match_range: /* %[ match after - */ + if (ch == ']') { + /* - was last character */ + set_bit(matchmap, (unsigned char)'-'); + goto match_run; + } else { + int i; + for (i = range_start; i < (unsigned char)ch; + i++) + set_bit(matchmap, i); + state = st_match; + } + break; + + match_run: /* Match expression finished */ + qq = q; + uc = 1; /* Anything nonzero */ + while (width && (uc = *q) + && test_bit(matchmap, uc)^matchinv) { + if (sarg) + *sarg++ = uc; + q++; + } + if (q != qq && sarg) { + *sarg = '\0'; + converted++; + } else { + bail = bail_err; + } + if (!uc) + bail = bail_eof; + break; + } + } + + if (bail == bail_eof && !converted) + converted = -1; /* Return EOF (-1) */ + + return converted; +} diff --git a/setup/debug.h b/setup/debug.h new file mode 100644 index 0000000..da8b581 --- /dev/null +++ b/setup/debug.h @@ -0,0 +1,31 @@ +/* + * 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. + * + */ + +#ifndef __DEBUG_H +#define __DEBUG_H + +#ifdef _DEBUG +#define DBGPRINTF(x) printf x +#else +#define DBGPRINTF(x) do {} while (0) +#endif + +#endif diff --git a/setup/loadstub.h b/setup/loadstub.h new file mode 100644 index 0000000..38ecd26 --- /dev/null +++ b/setup/loadstub.h @@ -0,0 +1,55 @@ +/* + * KernelEx + * Copyright (C) 2008, 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. + * + */ + +#ifndef __LOADSTUB_H +#define __LOADSTUB_H + +#define KEX_SIGNATURE "KrnlEx" +#define KEX_STUB_VER 0 + +#define JTAB_SIZE 4 +#define JTAB_EFO_DYN 0 +#define JTAB_EFO_STA 1 +#define JTAB_EFN_DYN 2 +#define JTAB_EFN_STA 3 + +#include +typedef struct +{ + char signature[6]; /* "KrnlEx" */ + unsigned short version; + struct + { + WORD opcode; /* 0xFF 0x25 */ + DWORD addr; /* address to jtab */ + WORD nop; /* dword align */ + } jmp_stub[JTAB_SIZE]; +} KernelEx_codeseg; + +typedef struct +{ + char signature[6]; /* "KrnlEx" */ + unsigned short version; + DWORD jtab[JTAB_SIZE]; +} KernelEx_dataseg; +#include + +#endif diff --git a/setup/resource.h b/setup/resource.h new file mode 100644 index 0000000..25ebef5 --- /dev/null +++ b/setup/resource.h @@ -0,0 +1,24 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by setup.rc +// +#define IDS_OLDKEX 1 +#define IDS_NOPAT 2 +#define IDS_MULPAT 3 +#define IDS_FAILOPEN 4 +#define IDS_FAILSEC 5 +#define IDS_FAILBAK 6 +#define IDS_ERRCHECK 7 +#define IDS_INVSTUB 8 +#define IDS_WINVER 9 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1000 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/setup/setup.cpp b/setup/setup.cpp new file mode 100644 index 0000000..3e59423 --- /dev/null +++ b/setup/setup.cpp @@ -0,0 +1,483 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#include +#include +#include +#include +#include +#include "debug.h" +#include "pemanip.h" +#include "loadstub.h" +#include "setup.h" +#include "wininit.h" +#include "resource.h" + +#define CODE_SEG ".text" +#define DATA_SEG ".data" + + +Setup::Setup(const char* backup_file) +{ + this->backup_file = backup_file; + h_kernel32 = GetModuleHandle("kernel32"); + + detect_old_version(); + + pemem.OpenMemory(h_kernel32); + if (!pemem.HasTarget()) + ShowError(IDS_FAILOPEN, "k32mem"); + + version = get_signature_ver(); + + OSVERSIONINFOA osv; + osv.dwOSVersionInfoSize = sizeof(osv); + + GetVersionEx(&osv); + if ((osv.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS) + || (osv.dwMajorVersion != 4) + || (osv.dwMinorVersion != 10 && osv.dwMinorVersion != 90)) + ShowError(IDS_WINVER); + + //on WinMe and file called "setup.exe" we get 4.10 (lol) + if (osv.dwMinorVersion == 90) + { + DBGPRINTF(("Detected Windows Me\n")); + is_winme = true; + } + else + { + DBGPRINTF(("Detected Windows 98\n")); + is_winme = false; + } +} + +bool Setup::detect_old_version() +{ + typedef void (WINAPI *KV_t)(char *); + KV_t h_KVersion; + char buf[32]; + + h_KVersion = (KV_t)GetProcAddress(h_kernel32, "KUPVersion"); + if (!h_KVersion) + h_KVersion = (KV_t)GetProcAddress(h_kernel32, "KEXVersion"); + if (!h_KVersion) + return false; + h_KVersion(buf); + if (strcmp(buf, "4") < 0) + ShowError(IDS_OLDKEX); + return true; +} + +int Setup::find_pattern(DWORD offset, int size, const short* pattern, + int pat_len, DWORD* found_loc) +{ + DWORD end_offset = offset + size - pat_len; + int found = 0; + + for (DWORD i = offset ; i <= end_offset ; i++) + { + if (pattern[0] < 0 || *(unsigned char*)i == pattern[0]) + { + int j; + for (j = 1 ; j < pat_len ; j++) + { + if (pattern[j] >= 0 && *(unsigned char*)(i + j) != pattern[j]) + break; + } + if (j == pat_len) //pattern found + { + *found_loc = i; + found++; + } + } + } + return found; +} + +void Setup::set_pattern(DWORD loc, const short* new_pattern, int pat_len) +{ + unsigned char* offset = (unsigned char*) loc; + const short* pat_ptr = new_pattern; + + while (pat_len--) + { + if (*pat_ptr != -1) + *offset = *pat_ptr & 0xff; + offset++; + pat_ptr++; + } +} + +int Setup::get_signature_ver() +{ + DWORD ptr; + KernelEx_dataseg* dseg = NULL; + DWORD sign_len = sizeof(KEX_SIGNATURE) - 1; + + DWORD data = (DWORD) pemem.GetSectionByName(DATA_SEG); + int data_size = pemem.GetSectionSize(DATA_SEG); + + ptr = data + data_size - sign_len; + while (ptr >= data) + { + if (!memcmp((void*)ptr, KEX_SIGNATURE, sign_len)) + { + dseg = (KernelEx_dataseg*) ptr; + break; + } + ptr--; + } + + if (!dseg) + { + DBGPRINTF(("Signature not found\n")); + return -1; + } + else + DBGPRINTF(("Signature found @ 0x%08x\n", ptr)); + + return dseg->version; +} + +void Setup::disable_platform_check() +{ + static const short pattern[] = { + 0x66,0x8b,0x46,0x48,0x66,0x3d,0x04,0x00,0x0f,0x87,0x9c,0x01,0x00,0x00, + 0x75,0x0b,0x66,0x83,0x7e,0x4a,0x0a,0x0f,0x87,0x8f,0x01,0x00,0x00,0x66, + 0x81,0x7e,0x04,0x4c,0x01, + }; + static const short after[] = { + 0xeb,0x19,0x46,0x48,0x66,0x3d,0x04,0x00,0x0f,0x87,0x9c,0x01,0x00,0x00, + 0x75,0x0b,0x66,0x83,0x7e,0x4a,0x0a,0x0f,0x87,0x8f,0x01,0x00,0x00,0x66, + 0x81,0x7e,0x04,0x4c,0x01, + }; + + DWORD offset = (DWORD) pefile.GetSectionByName(CODE_SEG); + int size = pefile.GetSectionSize(CODE_SEG); + int length = sizeof(pattern) / sizeof(short); + DWORD found_loc; + int found = find_pattern(offset, size, pattern, length, &found_loc); + if (found != 1) + { + if (!found) ShowError(IDS_NOPAT, "disable_platform_check"); + else ShowError(IDS_MULPAT, "disable_platform_check"); + } + DBGPRINTF(("%s: pattern found @ 0x%08x\n", "disable_platform_check", + pefile.PointerToRva((void*) found_loc) + pefile.GetImageBase())); + set_pattern(found_loc, after, length); +} + +void Setup::mod_imte_alloc() +{ + //VA BFF8745C, RVA 1745C, file 15A5C, sec E45C + static const short pattern[] = { + 0x66,0xff,0x05,-1,-1,-1,0xbf,0x6a,0x3c,0xe8, + }; + static const short after[] = { + 0x66,0xff,0x05,-1,-1,-1,0xbf,0x6a,0x44,0xe8, + }; + + DWORD offset = (DWORD) pefile.GetSectionByName(CODE_SEG); + int size = pefile.GetSectionSize(CODE_SEG); + int length = sizeof(pattern) / sizeof(short); + DWORD found_loc; + int found = find_pattern(offset, size, pattern, length, &found_loc); + if (found != 1) + { + if (!found) ShowError(IDS_NOPAT, "mod_imte_alloc"); + else ShowError(IDS_MULPAT, "mod_imte_alloc"); + } + DBGPRINTF(("%s: pattern found @ 0x%08x\n", "mod_imte_alloc", + pefile.PointerToRva((void*) found_loc) + pefile.GetImageBase())); + set_pattern(found_loc, after, length); +} + +void Setup::find_ExportFromX() +{ + static const short pattern[] = { + 0x8B,0x0D,-1,-1,-1,-1,0x0F,0xBF,0x40,0x10,0x8B,0x14,0x81,0x8B,0x44, + 0x24,0x14,0x3D,0x00,0x00,0x01,0x00,0x8B,0x4A,0x04,0x73,0x15,0x3B,0x1D, + -1,-1,-1,-1,0x75,0x04,0x6A,0x32,0xEB,0x3E,0x50,0x51,0xE8,-2,-2,-2,-2, + 0xEB,0x0C,0xFF,0x74,0x24,0x14,0x6A,0x00,0x51,0xE8,-2,-2,-2,-2,0x83, + 0x7F,0x54,0x00,0x8B,0xF0 + }; + + DWORD offset = (DWORD) pefile.GetSectionByName(CODE_SEG); + int size = pefile.GetSectionSize(CODE_SEG); + int length = sizeof(pattern) / sizeof(short); + DWORD found_loc; + int found = find_pattern(offset, size,pattern, length, &found_loc); + if (found != 1) + { + if (!found) ShowError(IDS_NOPAT, "exportfromX"); + else ShowError(IDS_MULPAT, "exportfromX"); + } + DBGPRINTF(("%s: pattern found @ 0x%08x\n", "exportfromX", + pefile.PointerToRva((void*) found_loc) + pefile.GetImageBase())); + gpa_ExportFromOrdinal_call = found_loc + 0x29; + gpa_ExportFromName_call = found_loc + 0x37; + _ExportFromOrdinal = decode_call(gpa_ExportFromOrdinal_call, 5); + _ExportFromName = decode_call(gpa_ExportFromName_call, 5); + DWORD start = (DWORD) pefile.RvaToPointer(_ExportFromName); + for (DWORD a = start ; a < start + 0x100 ; a++) + if (is_call_ref(a, _ExportFromOrdinal)) + EFN_EFO_call = a; +} + +void Setup::kill_process(const char* name) +{ + PROCESSENTRY32 pe32; + void * h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + + if (h == INVALID_HANDLE_VALUE) + return; + + pe32.dwSize = sizeof(PROCESSENTRY32); + + Process32First(h, &pe32); + do + { + if (strstr(pe32.szExeFile, name)) + { + DBGPRINTF(("Terminating process: %s... ", name)); + HANDLE hp = OpenProcess(PROCESS_TERMINATE, FALSE, pe32.th32ProcessID); + if (hp == INVALID_HANDLE_VALUE) + { + DBGPRINTF(("open fail\n")); + continue; + } + if (TerminateProcess(hp, 0)) + DBGPRINTF(("ok\n")); + else + DBGPRINTF(("fail\n")); + CloseHandle(hp); + } + } + while (Process32Next(h, &pe32)); + + CloseHandle(h); +} + +DWORD Setup::decode_call(DWORD addr, int len) +{ + unsigned char* code = (unsigned char*)addr; + + if (len == 5 && *code == 0xe8) /* call rel32 */ + { + return (DWORD)(pefile.PointerToRva(code) + 5 + *(DWORD*)(code + 1)); + } + else if (len == 6 && code[0] == 0xff + && code[1] == 0x15) /* call m32 */ + { + return *(DWORD*)(code + 2); + } + else return 0; +} + +bool Setup::is_call_ref(DWORD loc, DWORD target) +{ + DWORD addr = decode_call(loc, 5); // size of call imm32 opcode + if (addr == target) + return true; + return false; +} + +// Both addresses have to be from the same section! +void Setup::set_call_ref(DWORD loc, DWORD target) +{ + DWORD rel; + + assert(*(BYTE*) loc == 0xe8); + + rel = target - (loc + 5); + *(DWORD*)(loc + 1) = rel; +} + +bool Setup::is_fixupc(DWORD addr) +{ + if (*(DWORD*)(addr - 5) == 0xDAC) + return true; + return false; +} + +string Setup::get_temp_file_name() +{ + char tmpdir[MAX_PATH]; + char target[MAX_PATH]; + + GetSystemDirectory(tmpdir, sizeof(tmpdir)); + GetTempFileName(tmpdir, "kex", 0, target); + + return target; +} + +void Setup::ShowError(UINT id, ...) +{ + char format[512]; + char out[512]; + va_list vargs; + + va_start(vargs, id); + if (!LoadString(GetModuleHandle(NULL), id, format, sizeof(format))) + sprintf(out, "ERROR: Missing string resource %d", id); + else + _vsnprintf(out, sizeof(out), format, vargs); + va_end(vargs); + MessageBox(NULL, out, "KernelEx Setup", MB_OK | MB_ICONERROR); + exit(id); +} + +void Setup::install() +{ + upgrade = false; + + if (version == KEX_STUB_VER) + return; + + if (version >= 0) + { + if (version > KEX_STUB_VER) + ShowError(IDS_INVSTUB, version); + else + upgrade = true; + } + + char kernel32path[MAX_PATH]; + GetModuleFileName(h_kernel32, kernel32path, sizeof(kernel32path)); + + pefile.OpenFile(upgrade ? backup_file.c_str() : kernel32path, 0x10000); + if (!pefile.HasTarget()) + ShowError(IDS_FAILOPEN, upgrade ? backup_file.c_str() : kernel32path); + + find_ExportFromX(); + disable_platform_check(); + mod_imte_alloc(); + + KernelEx_codeseg* cseg; + KernelEx_dataseg* dseg; + if (!pefile.AllocSectionSpace(CODE_SEG, + sizeof(KernelEx_codeseg), (void**) &cseg, sizeof(DWORD))) + ShowError(IDS_FAILSEC, CODE_SEG); + if (!pefile.AllocSectionSpace(DATA_SEG, + sizeof(KernelEx_dataseg), (void**) &dseg, sizeof(DWORD))) + ShowError(IDS_FAILSEC, DATA_SEG); + + memcpy(cseg->signature, "KrnlEx", 6); + cseg->version = KEX_STUB_VER; + for (int i = 0 ; i < JTAB_SIZE ; i++) + { + cseg->jmp_stub[i].opcode = 0x25ff; + cseg->jmp_stub[i].addr = (DWORD) + pefile.PointerToRva(&dseg->jtab[i]) + pefile.GetImageBase(); + cseg->jmp_stub[i].nop = 0x9090; + } + + memcpy(dseg->signature, "KrnlEx", 6); + dseg->version = KEX_STUB_VER; + dseg->jtab[0] = _ExportFromOrdinal + pefile.GetImageBase(); + dseg->jtab[1] = _ExportFromOrdinal + pefile.GetImageBase(); + dseg->jtab[2] = _ExportFromName + pefile.GetImageBase(); + dseg->jtab[3] = _ExportFromName + pefile.GetImageBase(); + + DWORD code = (DWORD) pefile.GetSectionByName(CODE_SEG); + int code_size = pefile.GetSectionSize(CODE_SEG); + + int efo_cnt = 0; + int efn_cnt = 0; + + for (DWORD a = code ; a < code + code_size ; a++) + { + if (is_call_ref(a, _ExportFromOrdinal)) + { + DWORD file_loc = a; + if (a == EFN_EFO_call) + continue; + if (a == gpa_ExportFromOrdinal_call) + set_call_ref(file_loc, (DWORD) &cseg->jmp_stub[JTAB_EFO_DYN]); + else + set_call_ref(file_loc, (DWORD) &cseg->jmp_stub[JTAB_EFO_STA]); + DBGPRINTF(("EFO: address %08x\n", pefile.PointerToRva((void*) a) + + pefile.GetImageBase())); + efo_cnt++; + } + else if (is_call_ref(a, _ExportFromName)) + { + DWORD file_loc = a; + if (is_fixupc(a)) + continue; + if (a == gpa_ExportFromName_call) + set_call_ref(file_loc, (DWORD) &cseg->jmp_stub[JTAB_EFN_DYN]); + else + set_call_ref(file_loc, (DWORD) &cseg->jmp_stub[JTAB_EFN_STA]); + DBGPRINTF(("EFN: address %08x\n", pefile.PointerToRva((void*) a) + + pefile.GetImageBase())); + efn_cnt++; + } + } + + if (efo_cnt != 2 || efn_cnt != 2) + ShowError(IDS_ERRCHECK); + + // backup original file + if (!upgrade) + { + if (!CopyFile(kernel32path, backup_file.c_str(), FALSE)) + ShowError(IDS_FAILBAK, backup_file.c_str()); + } + + // save patched file + string tmp_file = get_temp_file_name(); + pefile.SaveFile(tmp_file.c_str()); + + if (is_winme) + { + kill_process("\\STATEMGR.EXE"); + kill_process("\\STMGR.EXE"); + } + + Wininit.add(kernel32path, tmp_file); + + if (is_winme) + { + char path[MAX_PATH]; + GetWindowsDirectory(path, sizeof(path)); + if (path[strlen(path) - 1] != '\\') + strcat(path, "\\"); + strcat(path, "WININIT.LOG"); + Wininit.add("NUL", path); + path[3] = '\0'; + strcat(path, "_RESTORE\\TEMP"); + Wininit.add("DIRNUL", path); + } + + Wininit.save(); +} + +int main(int argc, char** argv) +{ + if (argc != 2) + return 1; + + Setup setup(argv[1]); + setup.install(); + return 0; +} diff --git a/setup/setup.dsp b/setup/setup.dsp new file mode 100644 index 0000000..1f68033 --- /dev/null +++ b/setup/setup.dsp @@ -0,0 +1,132 @@ +# Microsoft Developer Studio Project File - Name="setup" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=setup - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "setup.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "setup.mak" CFG="setup - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "setup - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "setup - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "setup - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /I "../common" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GF /c +# ADD BASE RSC /l 0x415 /d "NDEBUG" +# ADD RSC /l 0x415 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /machine:I386 /out:"Release/setupkex.exe" /OPT:NOWIN98 +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "setup - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "." /I "../common" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /GF /c +# ADD BASE RSC /l 0x415 /d "_DEBUG" +# ADD RSC /l 0x415 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /debug /machine:I386 /out:"Debug/setupkex.exe" /pdbtype:sept /OPT:NOWIN98 +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "setup - Win32 Release" +# Name "setup - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\common\pemanip.cpp +# End Source File +# Begin Source File + +SOURCE=.\setup.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\debug.h +# End Source File +# Begin Source File + +SOURCE=.\loadstub.h +# End Source File +# Begin Source File + +SOURCE=..\common\pemanip.h +# End Source File +# Begin Source File + +SOURCE=.\setup.h +# End Source File +# Begin Source File + +SOURCE=.\wininit.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# Begin Source File + +SOURCE=.\setup.rc +# End Source File +# End Group +# End Target +# End Project diff --git a/setup/setup.h b/setup/setup.h new file mode 100644 index 0000000..080b477 --- /dev/null +++ b/setup/setup.h @@ -0,0 +1,68 @@ +/* + * KernelEx + * Copyright (C) 2008-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. + * + */ + +#ifndef __SETUP_H +#define __SETUP_H + +#include + +using namespace std; + +class Setup +{ +public: + Setup(const char* backup_file); + int get_signature_ver(); + void install(); + +protected: +private: + string backup_file; + DWORD _ExportFromOrdinal; + DWORD _ExportFromName; + HMODULE h_kernel32; + PEmanip pemem; + PEmanip pefile; + DWORD gpa_ExportFromOrdinal_call; + DWORD gpa_ExportFromName_call; + DWORD EFN_EFO_call; + int version; + bool is_winme; + bool upgrade; + + bool detect_old_version(); + int find_pattern(DWORD offset, int size, const short* pattern, int pat_len, DWORD* found_loc); + void set_pattern(DWORD loc, const short* new_pattern, int pat_len); + void disable_platform_check(); + void mod_imte_alloc(); + void find_ExportFromX(); + DWORD find_ExportFromOrdinal(); + DWORD find_ExportFromName(); + void kill_process(const char* name); + DWORD decode_call(DWORD addr, int len); + bool is_call_ref(DWORD loc, DWORD target); + void set_call_ref(DWORD loc, DWORD target); + bool is_fixupc(DWORD addr); + string get_temp_file_name(); + void ShowError(UINT id, ...); +}; + +#endif diff --git a/setup/setup.rc b/setup/setup.rc new file mode 100644 index 0000000..9afb89c --- /dev/null +++ b/setup/setup.rc @@ -0,0 +1,94 @@ +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// Neutral resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU) +#ifdef _WIN32 +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL +#pragma code_page(1250) +#endif //_WIN32 + +///////////////////////////////////////////////////////////////////////////// +// +// String Table +// + +STRINGTABLE DISCARDABLE +BEGIN + IDS_OLDKEX "Setup has detected previous version of KernelEx installed on this computer. Please uninstall it before continuing." + IDS_NOPAT "ERROR: %s: pattern not found" + IDS_MULPAT "ERROR: %s: multiple pattern matches" + IDS_FAILOPEN "ERROR: Failed to open %s" + IDS_FAILSEC "ERROR: Failed to allocate %s section memory" + IDS_FAILBAK "ERROR: Failed to create backup in %s" + IDS_ERRCHECK "ERROR: Checksum error" + IDS_INVSTUB "ERROR: Invalid stub version found: %d. Possibly newer KernelEx. Aborting." + IDS_WINVER "Incompatible Windows version" +END + +#endif // Neutral resources +///////////////////////////////////////////////////////////////////////////// + + +///////////////////////////////////////////////////////////////////////////// +// Polish resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_PLK) +#ifdef _WIN32 +LANGUAGE LANG_POLISH, SUBLANG_DEFAULT +#pragma code_page(1250) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + +#endif // Polish resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/setup/wininit.h b/setup/wininit.h new file mode 100644 index 0000000..0684579 --- /dev/null +++ b/setup/wininit.h @@ -0,0 +1,154 @@ +/* + * KernelEx + * Copyright (C) 2007-2008, 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 wininit.h + * Class WININIT. + */ + +#ifndef __WININIT_H +#define __WININIT_H + +#include +#include + +using namespace std; + +/** @class WININIT + * Maintains wininit.ini entries. + */ +class WININIT +{ + /** @struct _2files + * Helper struct holding two filenames. + */ + struct _2files + { + string dest; + string src; + }; + + /** Stack holding wininit.ini entries. */ + std::queue<_2files> que; + + /** Holds path to wininit.ini file. */ + char InitFile[MAX_PATH]; + +public: + + /** Constructor. */ + WININIT() + { + if (GetWindowsDirectory(InitFile, MAX_PATH) > 3) strcat(InitFile, "\\"); + strcat(InitFile, "WININIT.INI"); + } + + /** Destructor. */ + ~WININIT() + { + clear(); + } + + /** Deletes all files not saved by save() method. @see save */ + void clear() + { + if (!que.empty()) DBGPRINTF(("\nRemoving temporary files ...\n")); + while (!que.empty()) + { + DeleteFile(que.front().src.c_str()); + DBGPRINTF(("... %s\n", que.front().src.c_str())); + que.pop(); + } + } + + /** Checks if wininit.ini file exists. + * @return true if exists, false otherwise. + */ + bool exists() + { + return (GetFileAttributes(InitFile) != 0xffffffff); + } + + /** Pushes new source-destination pair onto the stack. + * @param dest Destination file name (or 'NUL' for delete). + * @param src Source file name. + */ + void add(const string& dest, const string& src) + { + _2files t; + t.dest = dest; + t.src = src; + que.push(t); + } + + /** Saves all data from stack to wininit.ini file. */ + bool save() + { + char buf[32767]; + int buf_len; + + if (que.empty()) + return true; + + buf_len = GetPrivateProfileSection("rename", buf, sizeof(buf), "wininit.ini"); + + DBGPRINTF(("\nSaving WININIT.INI entries ...\n")); + + while (!que.empty()) + { + char line[256]; + int line_len; + char short_dest[MAX_PATH]; + char short_src[MAX_PATH]; + + if (!GetShortPathName(que.front().dest.c_str(), short_dest, sizeof(short_dest))) + //if fail, assume destination doesn't exit + //fixme: may not be short path name or be invalid path name + strcpy(short_dest, que.front().dest.c_str()); + if (!GetShortPathName(que.front().src.c_str(), short_src, sizeof(short_src))) + strcpy(short_src, que.front().src.c_str()); + + strcpy(line, short_dest); + strcat(line, "="); + strcat(line, short_src); + strcat(line, "\r\n"); + line_len = strlen(line); + + if (buf_len + line_len + 2 <= sizeof(buf)) + { + DBGPRINTF(("... %s => %s\n", que.front().src.c_str(), que.front().dest.c_str())); + memcpy(&buf[buf_len], line, line_len); + buf_len += line_len; + } + else //buffer overflow + return false; + + que.pop(); + } + buf[buf_len] = 0; + buf[buf_len + 1] = 0; + + if (WritePrivateProfileSection("rename", buf, "wininit.ini")) + return true; + return false; + } +} Wininit; + +#endif // __WININIT_H diff --git a/sheet/KexLinkage.cpp b/sheet/KexLinkage.cpp new file mode 100644 index 0000000..e45650e --- /dev/null +++ b/sheet/KexLinkage.cpp @@ -0,0 +1,111 @@ +/* + * 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. + * + */ + +#include +#include "KexLinkage.h" + + +KexLinkage KexLinkage::instance; + + +KexLinkage::KexLinkage() +{ + m_ready = Prepare(); +} + + +KexLinkage::~KexLinkage() +{ + if (hKernelEx) + FreeLibrary(hKernelEx); +} + + +bool KexLinkage::Prepare() +{ + char core_conf_file[MAX_PATH]; + HKEY key; + DWORD type; + DWORD len = sizeof(core_conf_file); + + hKernelEx = LoadLibrary("KERNELEX.DLL"); + if (!hKernelEx) + return false; + + m_kexGetModuleSettings = (kexGetModuleSettings_t) GetProcAddress(hKernelEx, + "kexGetModuleSettings"); + m_kexSetModuleSettings = (kexSetModuleSettings_t) GetProcAddress(hKernelEx, + "kexSetModuleSettings"); + m_kexGetKEXVersion = (kexGetKEXVersion_t) GetProcAddress(hKernelEx, + "kexGetKEXVersion"); + + if (!m_kexGetModuleSettings || !m_kexSetModuleSettings || !m_kexGetKEXVersion) + return false; + + //read config file location from registry + long result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\KernelEx", + 0, KEY_QUERY_VALUE, &key); + if (result != ERROR_SUCCESS) + return false; + + result = RegQueryValueEx(key, "InstallDir", NULL, &type, + (BYTE*)core_conf_file, &len); + RegCloseKey(key); + if (result != ERROR_SUCCESS || type != REG_SZ || len == 0) + return false; + strcat(core_conf_file, "\\core.ini"); + if (GetFileAttributes(core_conf_file) == 0xffffffff) + return false; + + //parse config file + default_index = GetPrivateProfileInt("ApiConfigurations", + "default", 0, core_conf_file); + + for (int i = 0 ; i < 65536 ; i++) + { + char num[6]; + char conf_name[256]; + char conf_desc[256]; + + sprintf(num, "%d", i); + + if (!GetPrivateProfileString("ApiConfigurations", num, "", + conf_name, sizeof(conf_name), core_conf_file)) + break; + + if (GetPrivateProfileInt(conf_name, "noshow", 0, core_conf_file)) + continue; + + GetPrivateProfileString(conf_name, "desc", conf_name, + conf_desc, sizeof(conf_desc), core_conf_file); + + conf c(conf_name, conf_desc); + confs.push_back(c); + } + + return true; +} + + +bool KexLinkage::IsReady() +{ + return m_ready; +} diff --git a/sheet/KexLinkage.h b/sheet/KexLinkage.h new file mode 100644 index 0000000..7d40462 --- /dev/null +++ b/sheet/KexLinkage.h @@ -0,0 +1,67 @@ +/* + * 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. + * + */ + +#ifndef __KEXLINKAGE_H +#define __KEXLINKAGE_H + +#pragma warning(disable:4530) //exceptions within strings class which we don't use +#include +#pragma warning(default:4530) +#include "sstring.hpp" +#include "kexcoresdk.h" + +using namespace std; + +class KexLinkage +{ + typedef void (*kexGetModuleSettings_t)(const char* module, + char* conf_name, BYTE* ldr_flags); + typedef void (*kexSetModuleSettings_t)(const char* module, + const char* conf_name, BYTE ldr_flags); + typedef unsigned long (*kexGetKEXVersion_t)(void); + + struct conf + { + conf(const char* n, const char* d) : name(n), desc(d) {} + sstring name; + sstring desc; + }; + +public: + ~KexLinkage(); + bool IsReady(); + + static KexLinkage instance; + vector confs; + int default_index; + kexGetModuleSettings_t m_kexGetModuleSettings; + kexSetModuleSettings_t m_kexSetModuleSettings; + kexGetKEXVersion_t m_kexGetKEXVersion; + +protected: + KexLinkage(); + bool Prepare(); + + HMODULE hKernelEx; + bool m_ready; +}; + +#endif diff --git a/sheet/factory.cpp b/sheet/factory.cpp new file mode 100644 index 0000000..5bce597 --- /dev/null +++ b/sheet/factory.cpp @@ -0,0 +1,96 @@ +/* + * 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. + * + */ + +#include +#include "factory.h" +#include "server.h" +#include "sheet.h" +#include "KexLinkage.h" + +Factory::Factory() +{ + m_RefCount = 0; +} + + +STDMETHODIMP_(ULONG) Factory::AddRef() +{ + g_LockCount++; + return ++m_RefCount; +} + + +STDMETHODIMP_(ULONG) Factory::Release() +{ + g_LockCount--; + return --m_RefCount; +} + + +STDMETHODIMP Factory::QueryInterface(REFIID riid,LPVOID *ppv) +{ + if (riid==IID_IUnknown) + *ppv = static_cast(this); + else if (riid==IID_IClassFactory) + *ppv = static_cast(this); + else + { + *ppv = NULL; + return E_NOINTERFACE; + } + + AddRef(); + return S_OK; +} + + +STDMETHODIMP Factory::LockServer(BOOL bLock) +{ + if (bLock==TRUE) + g_LockCount++; + else + g_LockCount--; + return S_OK; +} + + +STDMETHODIMP Factory::CreateInstance(IUnknown *pUnkOuter,REFIID riid, LPVOID *ppv) +{ + *ppv = NULL; + + if (pUnkOuter != NULL) + return CLASS_E_NOAGGREGATION; + + if (!KexLinkage::instance.IsReady()) + return E_ACCESSDENIED; + + KexShlExt* pShlExt = new KexShlExt; + if (pShlExt == NULL) + return E_OUTOFMEMORY; + + HRESULT hr = pShlExt->QueryInterface(riid,ppv); + if (FAILED(hr)) + { + delete pShlExt; + return E_NOINTERFACE; + } + return S_OK; +} diff --git a/sheet/factory.h b/sheet/factory.h new file mode 100644 index 0000000..637db2e --- /dev/null +++ b/sheet/factory.h @@ -0,0 +1,42 @@ +/* + * 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. + * + */ + +#ifndef _FACTORY_H +#define _FACTORY_H + +class Factory : public IClassFactory +{ + ULONG m_RefCount; + +public: + Factory(); + + // IUnknown + STDMETHODIMP QueryInterface(REFIID riid,LPVOID *ppv); + STDMETHODIMP_(ULONG) AddRef(); + STDMETHODIMP_(ULONG) Release(); + + // IClassFactory + STDMETHODIMP CreateInstance(IUnknown *pUnkOuter,REFIID riid, LPVOID *ppv); + STDMETHODIMP LockServer(BOOL bLock); +}; + +#endif // _FACTORY_H diff --git a/sheet/resource.h b/sheet/resource.h new file mode 100644 index 0000000..995660b --- /dev/null +++ b/sheet/resource.h @@ -0,0 +1,24 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by sheet.rc +// +#define IDD_PROPPAGE 102 +#define IDC_CHECK 1000 +#define IDC_COMPAT 1000 +#define IDC_SYSTEM 1001 +#define IDC_DISABLE 1003 +#define IDC_HORIZ1 1004 +#define IDC_KEXVER 1005 +#define IDC_GCOMPAT 1006 +#define IDC_TCOMPAT 1007 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1008 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/sheet/server.cpp b/sheet/server.cpp new file mode 100644 index 0000000..990fb33 --- /dev/null +++ b/sheet/server.cpp @@ -0,0 +1,192 @@ +/* + * 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. + * + */ + +#include +#include +#include "server.h" +#include "factory.h" +#include "sheet.h" + +UINT g_LockCount; +HMODULE g_hModule; + + +// {2338519D-676A-4ff8-99B9-924252B43710} +static const GUID CLSID_KexShlExt = +{ 0x2338519d, 0x676a, 0x4ff8, { 0x99, 0xb9, 0x92, 0x42, 0x52, 0xb4, 0x37, 0x10 } }; +static const char sCLSID_KexShlExt[] = { "{2338519D-676A-4ff8-99B9-924252B43710}" }; + + +STDAPI DllCanUnloadNow() +{ + return (g_LockCount > 0) ? S_FALSE : S_OK; +} + + +STDAPI DllRegisterServer() +{ + bool result = true; + HKEY hkey, hkey2, keyCLSID; + + if (RegOpenKey(HKEY_CLASSES_ROOT, "CLSID", &keyCLSID) + != ERROR_SUCCESS) + result = false; + + if (result) + { + if (RegCreateKey(keyCLSID, sCLSID_KexShlExt, &hkey) != ERROR_SUCCESS) + result = false; + + if (result) + { + RegSetValueEx(hkey, NULL, 0, REG_SZ, (LPBYTE)"KernelEx Shell Extension", + sizeof("KernelEx Shell Extension")); + + if (RegCreateKey(hkey, "InProcServer32", &hkey2) != ERROR_SUCCESS) + result = false; + + if (result) + { + char filename[MAX_PATH]; + GetModuleFileName(g_hModule, filename, sizeof(filename)); + + RegSetValueEx(hkey2, NULL, 0, REG_SZ, (LPBYTE)filename, strlen(filename) + 1); + RegSetValueEx(hkey2, "ThreadingModel", 0, REG_SZ, (LPBYTE)"Apartment", + sizeof("Apartment")); + + RegCloseKey(hkey2); + } + + RegCloseKey(hkey); + } + + RegCloseKey(keyCLSID); + } + + if (RegCreateKey(HKEY_CLASSES_ROOT, "exefile\\shellex\\PropertySheetHandlers", + &hkey) != ERROR_SUCCESS) + result = false; + + if (result) + { + if (RegCreateKey(hkey, sCLSID_KexShlExt, &hkey2) != ERROR_SUCCESS) + result = false; + + if (result) + { + RegSetValueEx(hkey2, NULL, 0, REG_SZ, (LPBYTE)"", sizeof("")); + RegCloseKey(hkey2); + } + + RegCloseKey(hkey); + } + + if (RegCreateKey(HKEY_CLASSES_ROOT, "lnkfile\\shellex\\PropertySheetHandlers", + &hkey) != ERROR_SUCCESS) + result = false; + + if (result) + { + if (RegCreateKey(hkey, sCLSID_KexShlExt, &hkey2) != ERROR_SUCCESS) + result = false; + + if (result) + { + RegSetValueEx(hkey2, NULL, 0, REG_SZ, (LPBYTE)"", sizeof("")); + RegCloseKey(hkey2); + } + + RegCloseKey(hkey); + } + + return result ? S_OK : SELFREG_E_CLASS; +} + + +STDAPI DllUnregisterServer() +{ + bool result = true; + HKEY hkey, keyCLSID; + + if (RegOpenKey(HKEY_CLASSES_ROOT, "CLSID", &keyCLSID) + != ERROR_SUCCESS) + result = false; + + if (result) + { + if (RegOpenKey(keyCLSID, sCLSID_KexShlExt, &hkey) != ERROR_SUCCESS) + result = false; + + if (result) + { + RegDeleteKey(hkey, "InProcServer32"); + RegCloseKey(hkey); + } + + RegDeleteKey(keyCLSID, sCLSID_KexShlExt); + RegCloseKey(keyCLSID); + } + + if (RegOpenKey(HKEY_CLASSES_ROOT, "exefile\\shellex\\PropertySheetHandlers", + &hkey) != ERROR_SUCCESS) + result = false; + + if (result) + { + RegDeleteKey(hkey, sCLSID_KexShlExt); + RegCloseKey(hkey); + } + + if (RegOpenKey(HKEY_CLASSES_ROOT, "lnkfile\\shellex\\PropertySheetHandlers", + &hkey) != ERROR_SUCCESS) + result = false; + + if (result) + { + RegDeleteKey(hkey, sCLSID_KexShlExt); + RegCloseKey(hkey); + } + + return S_OK; +} + + +STDAPI DllGetClassObject(REFCLSID rclsid,REFIID riid,LPVOID * ppv) +{ + static Factory factory; + *ppv = NULL; + + if (rclsid != CLSID_KexShlExt) + return CLASS_E_CLASSNOTAVAILABLE; + + return factory.QueryInterface(riid,ppv); +} + + +BOOL APIENTRY DllMain(HINSTANCE hModule,DWORD dwReason,LPVOID lpReserved) +{ + if (dwReason == DLL_PROCESS_ATTACH) + { + g_hModule = hModule; + DisableThreadLibraryCalls(hModule); + } + return TRUE; +} diff --git a/sheet/server.def b/sheet/server.def new file mode 100644 index 0000000..7795ee5 --- /dev/null +++ b/sheet/server.def @@ -0,0 +1,6 @@ + +EXPORTS +DllRegisterServer PRIVATE +DllUnregisterServer PRIVATE +DllGetClassObject PRIVATE +DllCanUnloadNow PRIVATE \ No newline at end of file diff --git a/sheet/server.h b/sheet/server.h new file mode 100644 index 0000000..24497fb --- /dev/null +++ b/sheet/server.h @@ -0,0 +1,28 @@ +/* + * 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. + * + */ + +#ifndef _SERVER_H +#define _SERVER_H + +extern UINT g_LockCount; +extern HMODULE g_hModule; + +#endif // _SERVER_H diff --git a/sheet/sheet.cpp b/sheet/sheet.cpp new file mode 100644 index 0000000..afed3a6 --- /dev/null +++ b/sheet/sheet.cpp @@ -0,0 +1,388 @@ +/* + * 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. + * + */ + +#include +#include +#include +#include "sheet.h" +#include "server.h" +#include "resource.h" +#include "KexLinkage.h" + + +KexShlExt::KexShlExt() +{ + g_LockCount++; + m_RefCount = 0; +} + +KexShlExt::~KexShlExt() +{ + g_LockCount--; +} + + +STDMETHODIMP KexShlExt::QueryInterface(REFIID riid,LPVOID *ppv) +{ + if (riid == IID_IUnknown) + *ppv = static_cast(static_cast(this)); + else if (riid == IID_IShellExtInit) + *ppv = static_cast(this); + else if (riid == IID_IShellPropSheetExt) + *ppv = static_cast(this); + else + { + *ppv = NULL; + return E_NOINTERFACE; + } + + AddRef(); + return S_OK; +} + + +STDMETHODIMP_(ULONG) KexShlExt::AddRef() +{ + return ++m_RefCount; +} + + +STDMETHODIMP_(ULONG) KexShlExt::Release() +{ + if (!--m_RefCount) + { + delete this; + return 0; + } + return m_RefCount; +} + + +bool KexShlExt::IsPEModule(const char* path) +{ + IMAGE_DOS_HEADER MZh; + IMAGE_NT_HEADERS PEh; + FILE* f; + bool result = false; + + f = fopen(path, "rb"); + if (!f) + return false; + + if (fread(&MZh, sizeof(MZh), 1, f) != 1) + goto __end; + + if (MZh.e_magic != IMAGE_DOS_SIGNATURE) + goto __end; + + if (fseek(f, MZh.e_lfanew, SEEK_SET)) + goto __end; + + if (fread(&PEh, sizeof(PEh), 1, f) != 1) + goto __end; + + if ((PEh.Signature != IMAGE_NT_SIGNATURE) + || (PEh.FileHeader.Machine != IMAGE_FILE_MACHINE_I386) + || (PEh.OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR_MAGIC)) + goto __end; + + result = true; + +__end: + fclose(f); + + return result; +} + +bool KexShlExt::ResolveShortcut(const char* shortcutPath, char* filePath) +{ + HRESULT result; + IShellLink* shellLink; + IPersistFile* persistFile; + char path[MAX_PATH]; + WCHAR tmp[MAX_PATH]; + + result = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, + IID_IShellLink, (void**) &shellLink); + + if (FAILED(result)) + return false; + + result = shellLink->QueryInterface(IID_IPersistFile, (void**) &persistFile); + if (SUCCEEDED(result)) + { + MultiByteToWideChar(CP_ACP, 0, shortcutPath, -1, tmp, MAX_PATH); + + result = persistFile->Load(tmp, STGM_READ); + if (SUCCEEDED(result)) + { + result = shellLink->Resolve(NULL, SLR_UPDATE); + if (SUCCEEDED(result)) + { + result = shellLink->GetPath(path, + MAX_PATH, NULL, SLGP_RAWPATH); + if (SUCCEEDED(result)) + lstrcpyn(filePath, path, MAX_PATH); + } + } + + persistFile->Release(); + } + + shellLink->Release(); + + return SUCCEEDED(result); +} + +STDMETHODIMP KexShlExt::Initialize(LPCITEMIDLIST pidlFolder, + LPDATAOBJECT pDataObj, HKEY hProgID) +{ + FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; + STGMEDIUM stg; + HDROP hdrop; + HRESULT result = S_OK; + + if (KexLinkage::instance.confs.empty()) + return E_FAIL; + + InitCommonControls(); + + if (FAILED(pDataObj->GetData(&etc, &stg))) + return E_INVALIDARG; + + // Get an HDROP handle. + hdrop = (HDROP) GlobalLock (stg.hGlobal); + + if (!hdrop) + { + ReleaseStgMedium(&stg); + return E_INVALIDARG; + } + + ms = new ModuleSetting; + if (!ms) + return E_OUTOFMEMORY; + + // Determine how many files are involved in this operation. + UINT numFiles = DragQueryFile (hdrop, 0xFFFFFFFF, NULL, 0); + + if (numFiles != 1) + result = E_FAIL; + else + { + // Get the filename. + if (!DragQueryFile(hdrop, 0, ms->file, MAX_PATH) || PathIsDirectory(ms->file)) + result = E_FAIL; + else + { + char* ext = PathFindExtension(ms->file); + if (!lstrcmpi(ext, ".lnk")) + { + if (!ResolveShortcut(ms->file, ms->file)) + result = E_FAIL; + } + + if (!IsPEModule(ms->file)) + result = E_FAIL; + } + } + + // Release resources. + GlobalUnlock(stg.hGlobal); + ReleaseStgMedium(&stg); + + strupr(ms->file); + + return result; +} + + +STDMETHODIMP KexShlExt::AddPages(LPFNADDPROPSHEETPAGE lpfnAddPageProc, LPARAM lParam) +{ + PROPSHEETPAGE psp; + HPROPSHEETPAGE hPage; + + memset(&psp, 0, sizeof(psp)); + psp.dwSize = sizeof(psp); + psp.dwFlags = PSP_USEREFPARENT | PSP_USECALLBACK; + psp.hInstance = g_hModule; + psp.pszTemplate = MAKEINTRESOURCE(IDD_PROPPAGE); + psp.pfnDlgProc = DlgProc; + psp.pfnCallback = CallbackProc; + psp.lParam = (LPARAM) ms; + psp.pcRefParent = &g_LockCount; + + hPage = CreatePropertySheetPage(&psp); + if (hPage) + { + if (!lpfnAddPageProc(hPage, lParam)) + DestroyPropertySheetPage(hPage); + } + + return S_OK; +} + + +STDMETHODIMP KexShlExt::ReplacePage(UINT, LPFNADDPROPSHEETPAGE, LPARAM) +{ + return E_NOTIMPL; +} + + +BOOL CALLBACK KexShlExt::DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (uMsg) + { + case WM_INITDIALOG: + { + PROPSHEETPAGE* ppsp = (PROPSHEETPAGE*) lParam; + OnInitDialog(hwnd, (ModuleSetting*) ppsp->lParam); + } + break; + + case WM_SIZE: + { + WORD h = HIWORD(lParam); + WORD w = LOWORD(lParam); + + RECT r; + POINT p; + GetWindowRect(GetDlgItem(hwnd, IDC_GCOMPAT), &r); + p.x = r.left; + p.y = r.top; + ScreenToClient(hwnd, &p); + + //reposition horizontal spacer and version text + MoveWindow(GetDlgItem(hwnd, IDC_GCOMPAT), p.x, p.y, w - 2 * p.x, r.bottom - r.top, TRUE); + MoveWindow(GetDlgItem(hwnd, IDC_HORIZ1), p.x, h - 14 - p.x, w - 2 * p.x, 1, TRUE); + MoveWindow(GetDlgItem(hwnd, IDC_KEXVER), p.x, h - 12 - p.x, w - 2 * p.x, 12, TRUE); + GetWindowRect(GetDlgItem(hwnd, IDC_TCOMPAT), &r); + MoveWindow(GetDlgItem(hwnd, IDC_TCOMPAT), p.x, p.x, w - 2 * p.x, r.bottom - r.top, TRUE); + } + break; + + case WM_NOTIFY: + { + NMHDR* phdr = (NMHDR*) lParam; + if (phdr->code == PSN_APPLY) + OnApply(hwnd); + } + break; + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case IDC_DISABLE: + if (IsDlgButtonChecked(hwnd, IDC_DISABLE)) + { + EnableWindow(GetDlgItem(hwnd, IDC_COMPAT), FALSE); + EnableWindow(GetDlgItem(hwnd, IDC_SYSTEM), FALSE); + } + else + { + EnableWindow(GetDlgItem(hwnd, IDC_COMPAT), TRUE); + EnableWindow(GetDlgItem(hwnd, IDC_SYSTEM), + IsDlgButtonChecked(hwnd, IDC_COMPAT)); + } + PropSheet_Changed(GetParent(hwnd), hwnd); + break; + case IDC_COMPAT: + EnableWindow(GetDlgItem(hwnd, IDC_SYSTEM), + IsDlgButtonChecked(hwnd, IDC_COMPAT)); + PropSheet_Changed(GetParent(hwnd), hwnd); + break; + case IDC_SYSTEM: + PropSheet_Changed(GetParent(hwnd), hwnd); + break; + } + } + break; + } + + return FALSE; +} + + +void KexShlExt::OnInitDialog(HWND hwnd, ModuleSetting* ms) +{ + SetWindowLong(hwnd, GWL_USERDATA, (LONG) ms); + vector::const_iterator it; + for (it = KexLinkage::instance.confs.begin() ; + it != KexLinkage::instance.confs.end() ; it++) + SendMessage(GetDlgItem(hwnd, IDC_SYSTEM), CB_ADDSTRING, + 0, (LPARAM) it->desc.get()); + + if (KexLinkage::instance.default_index >= 0 + && KexLinkage::instance.default_index < KexLinkage::instance.confs.size()) + SendMessage(GetDlgItem(hwnd, IDC_SYSTEM), CB_SETCURSEL, + KexLinkage::instance.default_index, 0); + else + SendMessage(GetDlgItem(hwnd, IDC_SYSTEM), CB_SETCURSEL, 0, 0); + + KexLinkage::instance.m_kexGetModuleSettings(ms->file, ms->conf, &ms->flags); + + for (int i = 0 ; i < KexLinkage::instance.confs.size() ; i++) + if (!strcmp(ms->conf, KexLinkage::instance.confs[i].name.get())) + { + CheckDlgButton(hwnd, IDC_COMPAT, BST_CHECKED); + EnableWindow(GetDlgItem(hwnd, IDC_SYSTEM), TRUE); + SendMessage(GetDlgItem(hwnd, IDC_SYSTEM), CB_SETCURSEL, i, 0); + break; + } + if (ms->flags & 1) + { + CheckDlgButton(hwnd, IDC_DISABLE, BST_CHECKED); + EnableWindow(GetDlgItem(hwnd, IDC_COMPAT), FALSE); + EnableWindow(GetDlgItem(hwnd, IDC_SYSTEM), FALSE); + } + + //set KernelEx version + unsigned long ver = KexLinkage::instance.m_kexGetKEXVersion(); + char ver_s[32]; + sprintf(ver_s, "KernelEx Core v%d.%d.%d", ver>>24, (ver>>16) & 0xff, ver & 0xffff); + SendMessage(GetDlgItem(hwnd, IDC_KEXVER), WM_SETTEXT, 0, (LPARAM) ver_s); +} + + +void KexShlExt::OnApply(HWND hwnd) +{ + ModuleSetting* ms = (ModuleSetting*) GetWindowLong(hwnd, GWL_USERDATA); + BYTE flags = 0; + const char* conf = "default"; + if (IsDlgButtonChecked(hwnd, IDC_DISABLE)) + flags |= 1; + if (IsDlgButtonChecked(hwnd, IDC_COMPAT)) + conf = KexLinkage::instance.confs[SendMessage( + GetDlgItem(hwnd, IDC_SYSTEM), CB_GETCURSEL, 0, 0)].name.get(); + + if (flags != ms->flags || strcmp(conf, ms->conf) != 0) + KexLinkage::instance.m_kexSetModuleSettings(ms->file, conf, flags); +} + + +UINT CALLBACK KexShlExt::CallbackProc(HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp) +{ + if (uMsg == PSPCB_RELEASE) + delete (ModuleSetting*) ppsp->lParam; + + return 1; // used for PSPCB_CREATE - let the page be created +} diff --git a/sheet/sheet.dsp b/sheet/sheet.dsp new file mode 100644 index 0000000..fdaf4ea --- /dev/null +++ b/sheet/sheet.dsp @@ -0,0 +1,149 @@ +# Microsoft Developer Studio Project File - Name="sheet" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=sheet - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "sheet.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "sheet.mak" CFG="sheet - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "sheet - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "sheet - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "sheet - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SHEET_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /O2 /I "../common" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SHEET_EXPORTS" /YX /FD /GF /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x415 /d "NDEBUG" +# ADD RSC /l 0x415 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib comctl32.lib advapi32.lib shell32.lib shlwapi.lib ole32.lib /nologo /dll /machine:I386 /OPT:NOWIN98 +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "sheet - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SHEET_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MD /W3 /Gm /ZI /Od /I "../common" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SHEET_EXPORTS" /YX /FD /GZ /GF /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x415 /d "_DEBUG" +# ADD RSC /l 0x415 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib comctl32.lib advapi32.lib shell32.lib shlwapi.lib ole32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept /OPT:NOWIN98 +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "sheet - Win32 Release" +# Name "sheet - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\factory.cpp +# End Source File +# Begin Source File + +SOURCE=.\KexLinkage.cpp +# End Source File +# Begin Source File + +SOURCE=.\server.cpp +# End Source File +# Begin Source File + +SOURCE=.\server.def +# End Source File +# Begin Source File + +SOURCE=.\sheet.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\factory.h +# End Source File +# Begin Source File + +SOURCE=.\KexLinkage.h +# End Source File +# Begin Source File + +SOURCE=.\resource.h +# End Source File +# Begin Source File + +SOURCE=.\server.h +# End Source File +# Begin Source File + +SOURCE=.\sheet.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# Begin Source File + +SOURCE=.\sheet.rc +# End Source File +# End Group +# End Target +# End Project diff --git a/sheet/sheet.h b/sheet/sheet.h new file mode 100644 index 0000000..69d865b --- /dev/null +++ b/sheet/sheet.h @@ -0,0 +1,65 @@ +/* + * 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. + * + */ + +#ifndef _SHEET_H +#define _SHEET_H + +#include + +struct ModuleSetting +{ + char file[MAX_PATH]; + char conf[256]; + BYTE flags; +}; + +class KexShlExt : public IShellExtInit, + public IShellPropSheetExt +{ +protected: + ULONG m_RefCount; + ModuleSetting* ms; + + bool IsPEModule(const char* path); + bool ResolveShortcut(const char* shortcutPath, char* filePath); + static BOOL CALLBACK DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + static UINT CALLBACK CallbackProc(HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp); + static void OnInitDialog(HWND hwnd, ModuleSetting* ms); + static void OnApply(HWND hwnd); + +public: + KexShlExt(); + ~KexShlExt(); + + // IUnknown + STDMETHODIMP QueryInterface(REFIID riid,LPVOID *ppv); + STDMETHODIMP_(ULONG) AddRef(); + STDMETHODIMP_(ULONG) Release(); + + // IShellExtInit + STDMETHODIMP Initialize(LPCITEMIDLIST, LPDATAOBJECT, HKEY); + + // IShellPropSheetExt + STDMETHODIMP AddPages(LPFNADDPROPSHEETPAGE, LPARAM); + STDMETHODIMP ReplacePage(UINT, LPFNADDPROPSHEETPAGE, LPARAM); +}; + +#endif // _SHEET_H diff --git a/sheet/sheet.rc b/sheet/sheet.rc new file mode 100644 index 0000000..43a1399 --- /dev/null +++ b/sheet/sheet.rc @@ -0,0 +1,165 @@ +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// Polish resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_PLK) +#ifdef _WIN32 +LANGUAGE LANG_POLISH, SUBLANG_DEFAULT +#pragma code_page(1250) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +#ifndef _MAC +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,0,0,2 + PRODUCTVERSION 1,0,0,2 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004b0" + BEGIN + VALUE "Comments", "\0" + VALUE "CompanyName", "Xeno86\0" + VALUE "FileDescription", "sheet\0" + VALUE "FileVersion", "1, 0, 0, 2\0" + VALUE "InternalName", "sheet\0" + VALUE "LegalCopyright", "Copyright © 2009, Xeno86\0" + VALUE "LegalTrademarks", "\0" + VALUE "OriginalFilename", "sheet.dll\0" + VALUE "PrivateBuild", "\0" + VALUE "ProductName", "KernelEx\0" + VALUE "ProductVersion", "1, 0, 0, 2\0" + VALUE "SpecialBuild", "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0, 1200 + END +END + +#endif // !_MAC + +#endif // Polish resources +///////////////////////////////////////////////////////////////////////////// + + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_PROPPAGE DIALOG DISCARDABLE 0, 0, 190, 127 +STYLE WS_CHILD | WS_DISABLED | WS_CAPTION +CAPTION "Compatibility" +FONT 8, "MS Sans Serif" +BEGIN + GROUPBOX "Compatibility mode",IDC_GCOMPAT,7,30,176,64 + CONTROL "Run this program in compatibility mode for:",IDC_COMPAT, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,57,164,10 + COMBOBOX IDC_SYSTEM,15,70,157,60,CBS_DROPDOWNLIST | WS_DISABLED | + WS_VSCROLL | WS_TABSTOP + CONTROL "Disable KernelEx extensions for this program", + IDC_DISABLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,43, + 165,10 + GROUPBOX "",IDC_HORIZ1,7,108,172,9 + LTEXT "kexver here",IDC_KEXVER,7,111,71,9,WS_DISABLED + LTEXT "If you have problems with this program, try selecting\na different compatibility mode.", + IDC_TCOMPAT,7,7,175,22 +END + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO DISCARDABLE +BEGIN + IDD_PROPPAGE, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 183 + TOPMARGIN, 7 + BOTTOMMARGIN, 120 + END +END +#endif // APSTUDIO_INVOKED + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/util/dumpconf.c b/util/dumpconf.c new file mode 100644 index 0000000..c25d0f5 --- /dev/null +++ b/util/dumpconf.c @@ -0,0 +1,29 @@ +/* + * 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. + * + */ + +#include +#include "core/debugproto.h" + +void start() +{ + kexDbgDumpConfigurations(); + ExitProcess(0); +} diff --git a/util/dumpimte.c b/util/dumpimte.c new file mode 100644 index 0000000..f290361 --- /dev/null +++ b/util/dumpimte.c @@ -0,0 +1,29 @@ +/* + * 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. + * + */ + +#include +#include "core/debugproto.h" + +void start() +{ + kexDbgDumpImtes(); + ExitProcess(0); +} diff --git a/util/dumpsett.c b/util/dumpsett.c new file mode 100644 index 0000000..063be84 --- /dev/null +++ b/util/dumpsett.c @@ -0,0 +1,29 @@ +/* + * 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. + * + */ + +#include +#include "core/debugproto.h" + +void start() +{ + kexDbgDumpAppSettings(); + ExitProcess(0); +} diff --git a/util/funique.cpp b/util/funique.cpp new file mode 100644 index 0000000..7ce2c6d --- /dev/null +++ b/util/funique.cpp @@ -0,0 +1,140 @@ +/* + * 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. + * + */ + +#include +#include +#include "pemanip.h" + +DWORD find_unique_pattern(void* loc, int size, const short* pattern, int pat_len, const char* pat_name) +{ + unsigned char* pos = (unsigned char*) loc; + unsigned char* end_pos = pos + size - pat_len; + unsigned char* found_loc = NULL; + int found = 0; + + while (pos <= end_pos) + { + if (pattern[0] < 0 || *pos == pattern[0]) + { + int j; + for (j = 1 ; j < pat_len ; j++) + { + if (pattern[j] >= 0 && pos[j] != pattern[j]) + break; + } + if (j == pat_len) //pattern found + { + found++; + if (!found_loc) + found_loc = pos; + } + } + pos++; + } + + if (found != 1) + { + if (!found) + printf("%s: pattern not found\n", pat_name); + else + printf("%s: pattern not unique, found occurrences: %d\n", pat_name, found); + return 0; + } + + for (int i = 0 ; i < pat_len ; i++) + if (pattern[i] == -2) + return *(DWORD*) &found_loc[i]; + + printf("%s: invalid pattern\n", pat_name); + return 0; +} + +void eparse() +{ + printf("error parsing string\n"); + exit(1); +} + +int main(int argc, char** argv) +{ + char buf[512]; + int debug = 0; + + if (argc < 2 || argc > 3) + { + printf("invalid parameters\n"); + return 1; + } + + PEmanip pe(argv[1]); + if (argc == 3 && !strcmp(argv[2], "-d")) + debug = 1; + + FILE* f = fopen("patterns.txt", "rt"); + if (!f) + { + printf("failed to open pattern list\n"); + return 1; + } + + while (fgets(buf, sizeof(buf), f)) + { + short pat[128]; + int patlen = 0; + char* p, *p2; + char* pat_name; + char* sec_name; + + pat_name = buf; + p = strchr(buf, ':'); + if (!p) eparse(); + *p++ = 0; + sec_name = p; + p = strchr(p, '{'); + if (!p) eparse(); + *p++ = 0; + p2 = strchr(p, '}'); + if (!p2) eparse(); + *p2 = 0; + + while (p < p2) + { + char* p3; + short i; + i = strtol(p, &p3, 0); + if (p == p3) eparse(); + pat[patlen++] = i; + p = p3 + 1; + } + //DWORD start = GetTickCount(); + DWORD ret = find_unique_pattern(pe.GetSectionByName(sec_name), pe.GetSectionSize(sec_name), pat, patlen, pat_name); + //printf("algo completed in %dms\n", GetTickCount() - start); + if (debug) + { + printf("processing %s in %s: {", pat_name, sec_name); + for (int i = 0 ; i < patlen ; i++) if (pat[i] < 0) printf("%d,", pat[i]); else printf("0x%02x,", pat[i]); + printf("\b}=0x%08x\n", ret); + } + } + fclose(f); + + return 0; +} diff --git a/util/load.c b/util/load.c new file mode 100644 index 0000000..3a89a4d --- /dev/null +++ b/util/load.c @@ -0,0 +1,42 @@ +#include +#include + +typedef int (* initproc_t)(); + +int main() +{ + HMODULE h; + initproc_t init; + initproc_t uninit; + DWORD starttime; + int i; + + h = LoadLibrary("KernelEx.dll"); + if (h) + { + printf("KernelEx successfully loaded @ 0x%08x\n", h); + } + else + { + printf("Load error\n"); + } + + init = (initproc_t) GetProcAddress(h, "kexInit"); + uninit = (initproc_t) GetProcAddress(h, "kexUninit"); + + starttime = GetTickCount(); + i = init(); + if (i) + printf("init completed (%d) in %d ms\n", i, GetTickCount() - starttime); + else + printf("init failure\n"); + + printf("Press ENTER.\n"); + getchar(); + + i = uninit(); + printf("uninit complete (%d)\n", i); + + FreeLibrary(h); + return 0; +} diff --git a/util/patterns.txt b/util/patterns.txt new file mode 100644 index 0000000..0b3cd7b --- /dev/null +++ b/util/patterns.txt @@ -0,0 +1,9 @@ +ppTDBXCur:_FREQASM{0xA1,-2,-2,-2,-2,0x8B,0x00,0xFF,0x40,-1,0xFF,0x4A,0x10} +imteMax:.text{0x66,0x8B,0x44,0x24,0x04,0x66,-1,0x05,-2,-2,-2,-2,-1,0x17,0x8B,0x0D,-1,-1,-1,-1,0x0F,0xBF,0xC0,0x8B,0x04,0x81,0x85,0xC0,0x74,0x07,0x8B,0x40,0x04,0x85,0xC0,0x75,0x09} +krnl32lock:.text{0x55,0xA1,-2,-2,-2,-2,0x8B,0xEC,0x56,0x57,0x33,0xF6,0x50,0xE8} +pppdbCur:.text{0xA1,-2,-2,-2,-2,0xFF,0x30,0xE8,-1,-1,-1,-1,0xC3} +TidToTDB:.text{0x89,-1,0xFF,0x75,0xFC,0xFF,0x77,0x14,0xE8,-2,-2,-2,-2,0x50} +MRLoadTree:.text{0x33,0xF6,0xE8,-1,-1,-1,-1,0x39,0x35,-1,-1,-1,-1,0x74,0x11,0xA1,-1,-1,-1,-1,0x50,0xE8,-1,-1,-1,-1,0x89,0x35,-1,-1,-1,-1,0xFF,0x74,0x24,0x14,0xE8,-2,-2,-2,-2,0x8B,0xF0,0x85,0xF6} +FLoadTreeNotify:.text{0x56,0xA1,-1,-1,-1,-1,0x6A,0x01,0x8B,0x08,0xFF,0xB1,0x98,0x00,0x00,0x00,0xE8,-2,-2,-2,-2,0x83,0xF8,0x01,0x1B,0xF6,0xF7,0xDE,0x85,0xF6} +FreeLibRemove:.text{0x8B,0xF0,0x85,0xF6,0x75,0x05,0xE8,-2,-2,-2,-2,0xA1,-1,-1,-1,-1,0x50} +ExportFromX:.text{0x8B,0x0D,-1,-1,-1,-1,0x0F,0xBF,0x40,0x10,0x8B,0x14,0x81,0x8B,0x44,0x24,0x14,0x3D,0x00,0x00,0x01,0x00,0x8B,0x4A,0x04,0x73,0x15,0x3B,0x1D,-1,-1,-1,-1,0x75,0x04,0x6A,0x32,0xEB,0x3E,0x50,0x51,0xE8,-2,-2,-2,-2,0xEB,0x0C,0xFF,0x74,0x24,0x14,0x6A,0x00,0x51,0xE8,-2,-2,-2,-2,0x83,0x7F,0x54,0x00,0x8B,0xF0} diff --git a/util/prep/prep.cpp b/util/prep/prep.cpp new file mode 100644 index 0000000..c7393e7 --- /dev/null +++ b/util/prep/prep.cpp @@ -0,0 +1,699 @@ +/* + * 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. + * + */ + +#pragma warning(disable:4786) + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#include "prep.h" + +////////////////////////////////////////////////////////////////////////// + +vector all_exports_named; +vector all_exports_ordinal; +stringstream all_declarations; + +////////////////////////////////////////////////////////////////////////// + +int count(const string& s, char c, size_t pos, size_t epos) +{ + int num = 0; + if (epos == string::npos) + epos = s.length(); + if (pos < 0 || pos >= epos) + return 0; + for (int i = pos ; i < epos ; i++) + if (s[i] == c) + num++; + return num; +} + +////////////////////////////////////////////////////////////////////////// + +FileFinder::FileFinder() +{ +} + +FileFinder::FileFinder(const string& fn) +{ + search_for(fn); +} + +FileFinder::~FileFinder() +{ +} + +void FileFinder::search_for(const string& fn) +{ + WIN32_FIND_DATA find_data; + files.clear(); + pos = 0; + HANDLE h = FindFirstFile(fn.c_str(), &find_data); + if (h == INVALID_HANDLE_VALUE) + return; + do + files.push_back(find_data.cFileName); + while (FindNextFile(h, &find_data)); + CloseHandle(h); + stable_sort(files.begin(), files.end()); +} + +string FileFinder::get_next_file() +{ + if (files.empty() || pos >= files.size()) + return ""; + return files[pos++]; +} + +////////////////////////////////////////////////////////////////////////// + +FileDeclParser::FileDeclParser(const char* file_name) throw(exception) +{ + this->file_name = file_name; + ifstream f(file_name); + if (!f) + throw Exception("Failed to open file"); + + stringstream buf; + buf << f.rdbuf(); + + buffer = buf.str(); +} + +void FileDeclParser::parse() throw(exception) +{ + size_t pos = 0; + while ((pos = buffer.find("MAKE_EXPORT", pos)) != string::npos) + { + size_t lfpos = buffer.find('\n', pos); + if (lfpos == string::npos) + break; + + parse_make_export(buffer.substr(pos, lfpos - pos)); + pos += sizeof("MAKE_EXPORT"); + } + + pos = 0; + while ((pos = buffer.find("FORWARD_TO_UNICOWS(", pos)) != string::npos) + { + size_t lfpos = buffer.find('\n', pos); + if (lfpos == string::npos) + break; + + if (!is_containing_line_commented(pos)) + parse_forward_to_unicows(buffer.substr(pos, lfpos - pos)); + pos = lfpos + 1; + } + + int total_exports = exports_named.size() + exports_ordinal.size(); + if (total_exports == 0) + { + cout << "File doesn't contain exports" << endl; + return; + } + + prefilter(); + + int dcount = 0; + size_t lpos = 0; //last pos + int nest_level = 0; // nest level + + while ((pos = buffer.find('(', lpos)) != string::npos) + { + nest_level += count(buffer, '{', lpos, pos) + - count(buffer, '}', lpos, pos); + + lpos = pos + 1; + + if (nest_level == 0) + { + if (is_containing_line_commented(pos)) + continue; + + //at this level we have position of function opening brace '(' + //the hard part is finding beginning of function declaration + + size_t beg = buffer.find_last_of(";}", pos); + if (beg == string::npos) + beg = 0; + + while (is_containing_line_commented(beg) && beg != string::npos) + beg = buffer.find_last_of(";}", beg - 1); + + if (beg == string::npos) + beg = 0; + + if (beg) + beg++; + + size_t end = buffer.find(')', pos); + if (end == string::npos) + continue; + + while (is_containing_line_commented(end) && end != string::npos) + end = buffer.find(')', end + 1); + + if (end == string::npos) + continue; + + end++; + + string decl = buffer.substr(beg, end - beg) + ';'; + filter_declaration(decl); + + int cnt = find_matching_export(decl); + + if (!cnt) + continue; + + all_declarations << decl << endl; + dcount += cnt; + + //cout << decl << endl; + + lpos = end + 1; + } + + } + + vector::iterator i1 = exports_named.begin(); + vector::iterator i2 = exports_ordinal.begin(); + + while (i1 != exports_named.end()) + all_exports_named.push_back(*i1++); + while (i2 != exports_ordinal.end()) + all_exports_ordinal.push_back(*i2++); + + if (dcount < total_exports) + cout << "!Unresolved exports: " << total_exports - dcount << endl; +} + +size_t FileDeclParser::find_line_start(size_t pos) +{ + size_t line_start = buffer.rfind('\n', pos); + if (line_start == string::npos) + line_start = 0; + else + line_start++; + return line_start; +} + +bool FileDeclParser::is_containing_line_commented(size_t pos) +{ + size_t line_start = find_line_start(pos); + string p = buffer.substr(line_start, pos - line_start); + size_t pp; + if ((pp = p.find("//")) != string::npos || (pp = p.find('#')) != string::npos) + { + for (int i = 0 ; i < pp ; i++) + // if there is something before '//' then the line isn't commented + if (p[i] != ' ' && p[i] != '\t') + return false; + return true; + } + return false; +} + +void FileDeclParser::parse_make_export(const string& line) throw(exception) +{ + size_t pos = line.find("MAKE_EXPORT"); + if (pos == string::npos) + throw Exception("MAKE_EXPORT tag not found"); + pos += sizeof("MAKE_EXPORT"); + pos = line.find_first_not_of(" \t", pos); + if (pos == string::npos) + throw Exception("Invalid MAKE_EXPORT tag"); + size_t pos2 = line.find('=', pos); + if (pos2 == string::npos) + throw Exception("Invalid MAKE_EXPORT tag"); + string source_name = line.substr(pos, pos2 - pos); + pos = pos2 + 1; + pos2 = line.find_first_of(" \t", pos); + if (line.compare(pos, sizeof("ordinal") - 1, "ordinal")) + { + export_entry_named ee; + ee.source_name = source_name; + ee.export_name = line.substr(pos, pos2 - pos); + exports_named.push_back(ee); + } + else + { + export_entry_ordinal ee; + ee.source_name = source_name; + ee.ordinal = strtol(line.substr(pos + sizeof("ordinal") - 1).c_str(), NULL, 0); + exports_ordinal.push_back(ee); + } +} + +void FileDeclParser::parse_forward_to_unicows(const string& line) throw(exception) +{ + size_t pos = line.find("FORWARD_TO_UNICOWS("); + if (pos == string::npos) + throw Exception("FORWARD_TO_UNICOWS("); + pos += sizeof("FORWARD_TO_UNICOWS(") - 1; + size_t pos2 = line.find(')', pos); + if (pos2 == string::npos) + throw Exception("Invalid FORWARD_TO_UNICOWS tag"); + string name = line.substr(pos, pos2 - pos); + export_entry_named ee; + ee.source_name = name + "_fwd"; + ee.export_name = name; + all_exports_named.push_back(ee); + all_declarations << "FWDPROC " + name + "_fwd;" << endl; +} + +int FileDeclParser::find_matching_export(const string& s) +{ + int count = 0; + + //try named exports first + vector::iterator itn = exports_named.begin(); + while (itn != exports_named.end()) + { + if (s.find(itn->source_name) != string::npos) + count++; + itn++; + } + //then try ordinal exports + vector::iterator ito = exports_ordinal.begin(); + while (ito != exports_ordinal.end()) + { + if (s.find(ito->source_name) != string::npos) + count++; + ito++; + } + return count; +} + +void FileDeclParser::prefilter() throw(exception) +{ + //erase C-style comments + size_t pos; + while ((pos = buffer.find("/*")) != string::npos) + { + size_t pos2 = buffer.find("*/", pos + 1); + if (pos2 == string::npos) + throw Exception("No matching C-style comment closing"); + buffer.erase(pos, pos2 - pos + sizeof("*/") - 1); + } +} + +void FileDeclParser::filter_declaration(string& s) +{ + int i = 0; + + //erase precompiler directives + size_t pos; + while ((pos = s.find('#')) != string::npos) + { + size_t p2 = s.find('\n', pos + 1); + if (p2 != string::npos) + p2 -= pos; + s.erase(pos, p2); + } + + //erase C++ style comments + while ((pos = s.find("//")) != string::npos) + { + size_t p2 = s.find('\n', pos + 1); + if (p2 != string::npos) + p2 -= pos; + s.erase(pos, p2); + } + + //erase "__declspec(naked)" + while ((pos = s.find("__declspec(naked)")) != string::npos) + s.erase(pos, sizeof("__declspec(naked)")); + + //replace tabs and newlines with spaces + for (i = 0 ; i < s.length() ; i++) + if (s[i] == '\t' || s[i] == '\n') + s[i] = ' '; + + //erase leading spaces + while (s[0] == ' ') + s.erase(0, 1); + + + //erase spaces after bracket + pos = s.find('('); + while (s[pos + 1] == ' ') + s.erase(pos + 1, 1); + + //erase spaces before bracket + pos = s.rfind(')'); + while (s[pos - 1] == ' ') + { + s.erase(pos - 1, 1); + pos--; + } + + //erase multiple spaces + i = 0; + while (i < s.length()) + { + if (s[i] == ' ') + while (i + 1 < s.length() && s[i + 1] == ' ') + s.erase(i + 1, 1); + i++; + } +} + +////////////////////////////////////////////////////////////////////////// + +StubsParser::StubsParser(const char* file_name) throw(exception) : FileDeclParser(file_name) +{ +} + +void StubsParser::parse() throw(exception) +{ + prefilter(); + + size_t pos = 0; + size_t lpos = 0; + + while ((pos = buffer.find("UNIMPL_FUNC", lpos)) != string::npos) + { + size_t beg = buffer.find('(', pos); + if (beg == string::npos) + continue; + beg++; + + while (isspace(buffer[beg])) + beg++; + + size_t end = buffer.find(',', beg + 1); + if (end == string::npos) + continue; + end--; + + while (isspace(buffer[end])) + end--; + + string name = buffer.substr(beg, end - beg + 1); + string decl = "STUB " + name + "_stub" + ';'; + all_declarations << decl << endl; + export_entry_named ee; + ee.export_name = name; + ee.source_name = name + "_stub"; + all_exports_named.push_back(ee); + + lpos = end + 1; + } +} + +////////////////////////////////////////////////////////////////////////// + +void write_named_exports(ostream& o) +{ + vector::iterator it = all_exports_named.begin(); + while (it != all_exports_named.end()) + { + o << "\tDECL_API(\"" << it->export_name << "\", " + << it->source_name << ")," << endl; + it++; + } +} + +void write_ordinal_exports(ostream& o) +{ + vector::iterator it = all_exports_ordinal.begin(); + while (it != all_exports_ordinal.end()) + { + o << "\tDECL_API(" << it->ordinal << ", " + << it->source_name << ")," << endl; + it++; + } +} + +void dump_all() +{ + cout << "*** function declarations:" << endl; + cout << all_declarations.rdbuf(); + cout << "*** named exports:" << endl; + write_named_exports(cout); + cout << "*** ordinal exports:" << endl; + write_ordinal_exports(cout); +} + +void replace_if_changed(const string& out, const string& in) +{ + fstream f; + stringstream buf; + string in1; + string in2; + + f.open(out.c_str(), fstream::in); + if (!f) + throw Exception("Failed to open file"); + buf << f.rdbuf(); + in1 = buf.str(); + f.close(); + + f.open(in.c_str(), fstream::in); + if (!f) + throw Exception("Failed to open file"); + buf.clear(); + buf.str(""); + buf << f.rdbuf(); + in2 = buf.str(); + f.close(); + + if (in1.compare(in2)) + { + f.open(out.c_str(), ios::out | ios::trunc); + if (!f) + throw Exception("Failed to open file"); + f << in2; + f.close(); + } + + remove(in.c_str()); +} + +void work() +{ + ifstream dirlist("dirlist"); + if (!dirlist) + throw Exception("Couldn't open dirlist"); + + while (!dirlist.eof()) + { + fstream out_file; + stringstream buf; + string path; + string file; + FileFinder ff; + string line; + + all_exports_named.clear(); + all_exports_ordinal.clear(); + all_declarations.clear(); + all_declarations.str(""); + + getline(dirlist, path); + + //skip empty lines + if (path.empty()) + continue; + + path += '\\'; + + cout << "Processing directory: '" << path << '\'' << endl; + + ff.search_for(path + "*.c"); + + //read declarations + while (!(file = ff.get_next_file()).empty()) + { + FileDeclParser* parser; + + //if (file.find("_apilist.") != string::npos) + // continue; + + file = path + file; + + cout << "Parsing file: '" << file << '\'' << endl; + + if (file.find("_stubs.") != string::npos) + parser = new StubsParser(file.c_str()); + else + parser = new FileDeclParser(file.c_str()); + + parser->parse(); + delete parser; + } + + stable_sort(all_exports_named.begin(), all_exports_named.end()); + stable_sort(all_exports_ordinal.begin(), all_exports_ordinal.end()); + + //write output defs + ff.search_for(path + "_*_apilist.c"); + file = ff.get_next_file(); + if (file.empty()) + throw Exception("Couldn't find output def file"); + + file = path + file; + + cout << "Definitions output: '" << file << '\'' << endl; + + out_file.open(file.c_str(), fstream::in); + if (!out_file.is_open()) + throw Exception("Failed to open output def file for read"); + + buf << out_file.rdbuf(); + + out_file.close(); + + out_file.open((file + ".tmp").c_str(), ios::out | ios::trunc); + if (!out_file.is_open()) + throw Exception("Failed to open output def file for write"); + + while (true) + { + getline(buf, line); + if (0 == line.compare("/*** AUTOGENERATED APILIST NAMED EXPORTS BEGIN ***/")) + { + out_file << line << endl; + while (true) + { + getline(buf,line); + if (0 == line.compare("/*** AUTOGENERATED APILIST NAMED EXPORTS END ***/")) + break; + } + + write_named_exports(out_file); + } + else if (0 == line.compare("/*** AUTOGENERATED APILIST ORDINAL EXPORTS BEGIN ***/")) + { + out_file << line << endl; + while (true) + { + getline(buf,line); + if (0 == line.compare("/*** AUTOGENERATED APILIST ORDINAL EXPORTS END ***/")) + break; + } + + write_ordinal_exports(out_file); + } + out_file << line; + + if (!buf.eof()) + out_file << endl; + else + break; + } + + out_file.close(); + replace_if_changed(file, file + ".tmp"); + + //write output decls + ff.search_for(path + "_*_apilist.h"); + + file = ff.get_next_file(); + if (file.empty()) + throw Exception("Couldn't find output decl file"); + + file = path + file; + + cout << "Declarations output: '" << file << '\'' << endl; + + out_file.open(file.c_str(), fstream::in); + if (!out_file.is_open()) + throw Exception("Failed to open output decl file for read"); + + buf.clear(); + buf.str(""); + buf << out_file.rdbuf(); + + out_file.close(); + + out_file.open((file + ".tmp").c_str(), ios::out | ios::trunc); + if (!out_file.is_open()) + throw Exception("Failed to open output decl file for write"); + + while (true) + { + getline(buf, line); + if (0 == line.compare("/*** AUTOGENERATED APILIST DECLARATIONS BEGIN ***/")) + { + out_file << line << endl; + while (true) + { + getline(buf,line); + if (0 == line.compare("/*** AUTOGENERATED APILIST DECLARATIONS END ***/")) + break; + } + + all_declarations.peek(); + if (all_declarations.good()) + out_file << all_declarations.rdbuf(); + } + out_file << line; + + if (!buf.eof()) + out_file << endl; + else + break; + } + + out_file.close(); + replace_if_changed(file, file + ".tmp"); + } + +} + +int main(int argc, char* argv[]) +{ + if (argc > 2) + { + cout << "Invalid parameters!" << endl; + return 1; + } + + if (argc == 2) + if (!SetCurrentDirectory(argv[1])) + { + cout << "Failed to change directory" << endl; + return 1; + } + + try + { + work(); + } + catch (const exception& e) + { + cout << "Exception: " << e.what() << endl; + return 1; + } + + return 0; +} diff --git a/util/prep/prep.dsp b/util/prep/prep.dsp new file mode 100644 index 0000000..27d8252 --- /dev/null +++ b/util/prep/prep.dsp @@ -0,0 +1,120 @@ +# Microsoft Developer Studio Project File - Name="prep" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=prep - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "prep.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "prep.mak" CFG="prep - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "prep - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "prep - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "prep - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GF /c +# ADD BASE RSC /l 0x415 /d "NDEBUG" +# ADD RSC /l 0x415 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /OPT:NOWIN98 +# SUBTRACT LINK32 /pdb:none +# Begin Custom Build +OutDir=.\Release +WkspDir=. +TargetName=prep +InputPath=.\Release\prep.exe +SOURCE="$(InputPath)" + +"nope" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(OutDir)\$(TargetName) $(WkspDir)\apilibs\kexbases + $(OutDir)\$(TargetName) $(WkspDir)\apilibs\kexbasen + +# End Custom Build + +!ELSEIF "$(CFG)" == "prep - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /GF /c +# ADD BASE RSC /l 0x415 /d "_DEBUG" +# ADD RSC /l 0x415 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /OPT:NOWIN98 +# SUBTRACT LINK32 /pdb:none +# Begin Custom Build +OutDir=.\Debug +WkspDir=. +TargetName=prep +InputPath=.\Debug\prep.exe +SOURCE="$(InputPath)" + +"nope" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(OutDir)\$(TargetName) $(WkspDir)\apilibs\kexbases + $(OutDir)\$(TargetName) $(WkspDir)\apilibs\kexbasen + +# End Custom Build + +!ENDIF + +# Begin Target + +# Name "prep - Win32 Release" +# Name "prep - Win32 Debug" +# Begin Source File + +SOURCE=.\prep.cpp +# End Source File +# Begin Source File + +SOURCE=.\prep.h +# End Source File +# End Target +# End Project diff --git a/util/prep/prep.h b/util/prep/prep.h new file mode 100644 index 0000000..5bd153a --- /dev/null +++ b/util/prep/prep.h @@ -0,0 +1,117 @@ +/* + * 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. + * + */ + +#ifndef __PREP_H +#define __PREP_H + +////////////////////////////////////////////////////////////////////////// + +int count(const string& s, char c, size_t pos = 0, size_t epos = string::npos); + +////////////////////////////////////////////////////////////////////////// + +class Exception : public exception +{ +private: + string reason; + +public: + Exception(const char* what) : reason(what) {} + ~Exception() throw() {} + const char* what() const throw() { return reason.c_str(); } +}; + +////////////////////////////////////////////////////////////////////////// + +class FileFinder +{ +public: + FileFinder(); + FileFinder(const string& fn); + ~FileFinder(); + void search_for(const string& fn); + string get_next_file(); + +private: + int pos; + vector files; +}; + +////////////////////////////////////////////////////////////////////////// + +struct export_entry_named +{ + string source_name; + string export_name; + + bool operator<(const export_entry_named& e) const + { + return this->export_name.compare(e.export_name) < 0; + } +}; + +struct export_entry_ordinal +{ + string source_name; + unsigned short ordinal; + + export_entry_ordinal() : ordinal(0) {} + bool operator<(const export_entry_ordinal& e) const + { + return this->ordinal < e.ordinal; + } +}; + +////////////////////////////////////////////////////////////////////////// + +class FileDeclParser +{ +public: + FileDeclParser(const char* file_name) throw(exception); + virtual void parse() throw(exception); + +protected: + string buffer; + string file_name; + vector exports_named; + vector exports_ordinal; + + size_t find_line_start(size_t pos); + bool is_containing_line_commented(size_t pos); + void prefilter() throw(exception); + void parse_make_export(const string& line) throw(exception); + void parse_forward_to_unicows(const string& line) throw(exception); + int find_matching_export(const string& s); + void filter_declaration(string& s); +}; + +////////////////////////////////////////////////////////////////////////// + +class StubsParser : public FileDeclParser +{ +public: + StubsParser(const char* file_name) throw(exception); + void parse() throw(exception); +}; + +////////////////////////////////////////////////////////////////////////// + +#endif diff --git a/util/prep/test/_te_apilist.c b/util/prep/test/_te_apilist.c new file mode 100644 index 0000000..9ac8cc8 --- /dev/null +++ b/util/prep/test/_te_apilist.c @@ -0,0 +1,5 @@ +junk1 +/*** APILIST NAMED EXPORTS BEGIN HERE ***/ + DECL_API("junkjard", junk), +/*** APILIST NAMED EXPORTS END HERE ***/ +junk5 diff --git a/util/prep/test/dirlist b/util/prep/test/dirlist new file mode 100644 index 0000000..945c9b4 --- /dev/null +++ b/util/prep/test/dirlist @@ -0,0 +1 @@ +. \ No newline at end of file diff --git a/util/prep/test/junk.c b/util/prep/test/junk.c new file mode 100644 index 0000000..262a75c --- /dev/null +++ b/util/prep/test/junk.c @@ -0,0 +1,4 @@ +// MAKE_EXPORT junk=junkjard +int junk(void** sf, float fd) +{ +} diff --git a/util/prep/test/test.c b/util/prep/test/test.c new file mode 100644 index 0000000..011e485 --- /dev/null +++ b/util/prep/test/test.c @@ -0,0 +1,38 @@ +#include + +// MAKE_EXPORT fun=funny +void fun() +{ + int foobar; + foobar++; +} + +typedef int sad; + +/* MAKE_EXPORT barbar=jarjar + */ + //difficutly gets higher +/* _cdecl barbar(bool b) +{ +} +*/ +#ifdef WINDOWS +__declspec(dllexport) +//total fuckup +#else + __cdecl +#endif + + + +long long barbar(int a, //test + bool b, /* dfas */ char /* sad */ c, + //dumb stuff + + float f, + double d) + { + } int main() { + fun(); + return (int) barbar(0, true, 'a', 2.3f, 0.34); +}