Skip to content

Commit 929c853

Browse files
committed
Updated Windows 11 loader to fix a severe Bug introduced by Microsoft in Windows 11 affecting conhost(crashes), details in oemcp.c - Is there any way to report bugs to M$?
1 parent 9d44d45 commit 929c853

File tree

11 files changed

+415
-193
lines changed

11 files changed

+415
-193
lines changed
1 KB
Binary file not shown.

ntvdmpatch/src/ldntvdm/ldntvdm/injector64.c

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "injector32.h"
55
#include "ntmmapi.h"
66
#include "detour.h"
7+
#include "ntpeb.h"
78
#include <stddef.h>
89
#include <Psapi.h>
910

@@ -25,91 +26,6 @@ extern BYTE LdrpInitializeProcessProcx86[];
2526
extern unsigned int LdrpInitializeProcessProcx86Size;
2627

2728
#pragma pack(1)
28-
typedef struct _PEB32
29-
{
30-
UCHAR InheritedAddressSpace; // 0
31-
UCHAR ReadImageFileExecOptions; // 1
32-
UCHAR BeingDebugged; // 2
33-
union
34-
{
35-
UCHAR BitField; //0x3
36-
struct
37-
{
38-
UCHAR ImageUsesLargePages : 1; //0x3
39-
UCHAR IsProtectedProcess : 1; //0x3
40-
UCHAR IsImageDynamicallyRelocated : 1; //0x3
41-
UCHAR SkipPatchingUser32Forwarders : 1; //0x3
42-
UCHAR IsPackagedProcess : 1; //0x3
43-
UCHAR IsAppContainer : 1; //0x3
44-
UCHAR IsProtectedProcessLight : 1; //0x3
45-
UCHAR IsLongPathAwareProcess : 1; //0x3
46-
};
47-
};
48-
ULONG Mutant; // 4
49-
ULONG ImageBaseAddress; // 8
50-
ULONG Ldr; // C
51-
ULONG ProcessParameters; // 10
52-
ULONG SubSystemData;
53-
ULONG ProcessHeap;
54-
ULONG FastPebLock;
55-
ULONG AtlThunkSListPtr;
56-
ULONG IFEOKey;
57-
union
58-
{
59-
ULONG CrossProcessFlags;
60-
struct
61-
{
62-
ULONG ProcessInJob : 1;
63-
ULONG ProcessInitializing : 1;
64-
ULONG ProcessUsingVEH : 1;
65-
ULONG ProcessUsingVCH : 1;
66-
ULONG ReservedBits0 : 28;
67-
};
68-
};
69-
union
70-
{
71-
ULONG KernelCallbackTable; //0x2c
72-
ULONG UserSharedInfoPtr; //0x2c
73-
};
74-
ULONG SystemReserved; //0x30
75-
ULONG AtlThunkSListPtr32; //0x34
76-
ULONG ApiSetMap; //0x38
77-
ULONG TlsExpansionCounter; //0x3c
78-
ULONG TlsBitmap; //0x40
79-
ULONG TlsBitmapBits[2]; //0x44
80-
ULONG ReadOnlySharedMemoryBase; //0x4c
81-
ULONG SharedData; //0x50
82-
ULONG ReadOnlyStaticServerData; //0x54
83-
ULONG AnsiCodePageData; //0x58
84-
ULONG OemCodePageData; //0x5c
85-
ULONG UnicodeCaseTableData; //0x60
86-
ULONG NumberOfProcessors; //0x64
87-
ULONG NtGlobalFlag; //0x68
88-
union _LARGE_INTEGER CriticalSectionTimeout; //0x70
89-
ULONG HeapSegmentReserve; //0x78
90-
ULONG HeapSegmentCommit; //0x7c
91-
ULONG HeapDeCommitTotalFreeThreshold; //0x80
92-
ULONG HeapDeCommitFreeBlockThreshold; //0x84
93-
ULONG NumberOfHeaps; //0x88
94-
ULONG MaximumNumberOfHeaps; //0x8c
95-
ULONG ProcessHeaps; //0x90
96-
ULONG GdiSharedHandleTable; //0x94
97-
ULONG ProcessStarterHelper; //0x98
98-
ULONG GdiDCAttributeList; //0x9c
99-
ULONG LoaderLock; //0xa0
100-
ULONG OSMajorVersion; //0xa4
101-
ULONG OSMinorVersion; //0xa8
102-
USHORT OSBuildNumber; //0xac
103-
USHORT OSCSDVersion; //0xae
104-
ULONG OSPlatformId; //0xb0
105-
ULONG ImageSubsystem; //0xb4
106-
ULONG ImageSubsystemMajorVersion; //0xb8
107-
ULONG ImageSubsystemMinorVersion; //0xbc
108-
ULONG ActiveProcessAffinityMask; //0xc0
109-
ULONG GdiHandleBuffer[34]; //0xc4
110-
ULONG PostProcessInitRoutine; //0x14c
111-
} PEB32, *PPEB32;
112-
11329
typedef struct _LDR_DATA_TABLE_ENTRY32
11430
{
11531
LIST_ENTRY32 InLoadOrderModuleList;

ntvdmpatch/src/ldntvdm/ldntvdm/ldntvdm.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "apppatch.h"
4141
#include "appinfo.h"
4242
#include "injector32.h"
43+
#include "oemcp.h"
4344

4445
#pragma comment(lib, "ntdll.lib")
4546

@@ -192,11 +193,11 @@ fpsprintf sprintf;
192193
fp_stricmp __stricmp;
193194
fp_wcsicmp __wcsicmp;
194195
fpstrcmp _strcmp;
196+
fpswprintf __swprintf;
195197
#ifdef NEED_BASEVDM
196198
fpwcsncpy _wcsncpy;
197199
fp_wcsnicmp __wcsnicmp;
198200
fpwcsrchr _wcsrchr;
199-
fpswprintf __swprintf;
200201
fpstrstr _strstr;
201202
#endif
202203
fpBaseIsDosApplication BaseIsDosApplication = NULL;
@@ -637,6 +638,7 @@ BOOL WINAPI _DllMainCRTStartup(
637638
__stricmp = (fp_stricmp)GetProcAddress(hNTDLL, "_stricmp");
638639
__wcsicmp = (fp_wcsicmp)GetProcAddress(hNTDLL, "_wcsicmp");
639640
_strcmp = (fpstrcmp)GetProcAddress(hNTDLL, "strcmp");
641+
__swprintf = (fpswprintf)GetProcAddress(hNTDLL, "swprintf");
640642
#ifdef TRACING
641643
sprintf = (fpsprintf)GetProcAddress(hNTDLL, "sprintf");
642644
#ifdef TRACE_FILE
@@ -652,7 +654,6 @@ BOOL WINAPI _DllMainCRTStartup(
652654
_wcsncpy = (fpwcsncpy)GetProcAddress(hNTDLL, "wcsncpy");
653655
__wcsnicmp = (fp_wcsnicmp)GetProcAddress(hNTDLL, "_wcsnicmp");
654656
_wcsrchr = (fpwcsrchr)GetProcAddress(hNTDLL, "wcsrchr");
655-
__swprintf = (fpswprintf)GetProcAddress(hNTDLL, "swprintf");
656657
_strstr = (fpstrstr)GetProcAddress(hNTDLL, "strstr");
657658
#endif
658659

@@ -766,6 +767,16 @@ BOOL WINAPI _DllMainCRTStartup(
766767
FixNTDLL();
767768
// Fix ConhostV1.dll bug where memory isn't initialized properly
768769
fNoConhostDll = ConsBmpBug_Install(&hModConhost);
770+
771+
#ifdef TARGET_WIN11
772+
// Windows 11 bug: OEM NLS Table not mapped
773+
if (OEMCP_FixNLSTable())
774+
{
775+
//SuspendThread(GetCurrentThread());
776+
OEMCP_CallInitializeCustomCP();
777+
}
778+
#endif
779+
769780
#ifndef CREATEPROCESS_HOOK
770781
// We want notification when new console process gets started so that we can inject
771782
WinEventHook_Install(fNoConhostDll ? GetModuleHandle(NULL) : hModConhost);

ntvdmpatch/src/ldntvdm/ldntvdm/ldntvdm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,19 @@ void Trace(char *pszLine);
136136
typedef int (__cdecl *fpstrcmp)(char * str, char *str2);
137137
typedef int (__cdecl *fp_stricmp)(const char * str, const char *str2);
138138
typedef int (__cdecl *fp_wcsicmp)(PWCHAR str, PWCHAR str2);
139+
typedef int(__cdecl *fpswprintf)(wchar_t *buffer, const wchar_t *format, ...);
139140
extern fp_stricmp __stricmp;
140141
extern fp_wcsicmp __wcsicmp;
141142
extern fpstrcmp _strcmp;
143+
extern fpswprintf __swprintf;
142144
#ifdef NEED_BASEVDM
143145
typedef wchar_t * (__cdecl *fpwcsncpy)(wchar_t *strDest, const wchar_t *strSource, size_t count);
144146
typedef int(__cdecl *fp_wcsnicmp)(const wchar_t *string1, const wchar_t *string2, size_t count);
145147
typedef wchar_t * (__cdecl *fpwcsrchr)(const wchar_t *str, wchar_t c);
146-
typedef int (__cdecl *fpswprintf)(wchar_t *buffer, const wchar_t *format, ...);
147148
typedef char *(__cdecl *fpstrstr)(const char *str, const char *strSearch);
148149
extern fpwcsncpy _wcsncpy;
149150
extern fp_wcsnicmp __wcsnicmp;
150151
extern fpwcsrchr _wcsrchr;
151-
extern fpswprintf __swprintf;
152152
extern fpstrstr _strstr;
153153
#endif
154154

ntvdmpatch/src/ldntvdm/ldntvdm/ldntvdm.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@
545545
<ClCompile Include="injector32.c" />
546546
<ClCompile Include="injector64.c" />
547547
<ClCompile Include="ldntvdm.c" />
548+
<ClCompile Include="oemcp.c" />
548549
<ClCompile Include="reg.c" />
549550
<ClCompile Include="symcache.c" />
550551
<ClCompile Include="symeng.c" />
@@ -577,9 +578,11 @@
577578
<ClInclude Include="newexe.h" />
578579
<ClInclude Include="newres.h" />
579580
<ClInclude Include="ntmmapi.h" />
581+
<ClInclude Include="ntpeb.h" />
580582
<ClInclude Include="ntpsapi.h" />
581583
<ClInclude Include="ntregapi.h" />
582584
<ClInclude Include="ntrtl.h" />
585+
<ClInclude Include="oemcp.h" />
583586
<ClInclude Include="reg.h" />
584587
<ClInclude Include="symcache.h" />
585588
<ClInclude Include="symeng.h" />

ntvdmpatch/src/ldntvdm/ldntvdm/ldntvdm.vcxproj.filters

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@
9393
<ClCompile Include="appinfo.c">
9494
<Filter>Quelldateien</Filter>
9595
</ClCompile>
96+
<ClCompile Include="oemcp.c">
97+
<Filter>Quelldateien</Filter>
98+
</ClCompile>
9699
</ItemGroup>
97100
<ItemGroup>
98101
<ClInclude Include="basemsg64.h">
@@ -203,5 +206,11 @@
203206
<ClInclude Include="injector.h">
204207
<Filter>Headerdateien</Filter>
205208
</ClInclude>
209+
<ClInclude Include="ntpeb.h">
210+
<Filter>Headerdateien</Filter>
211+
</ClInclude>
212+
<ClInclude Include="oemcp.h">
213+
<Filter>Headerdateien</Filter>
214+
</ClInclude>
206215
</ItemGroup>
207216
</Project>

0 commit comments

Comments
 (0)