summaryrefslogtreecommitdiff
path: root/src/VBox/Additions/WINNT/SharedFolders/driver/Win2kWorkarounds.c
blob: e23fe524032a6d0e69bc4dee96e2a066cf1b9335 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/* $Id$ */
/** @file
 * VirtualBox Windows Guest Shared Folders - Windows 2000 Hacks.
 */

/*
 * Copyright (C) 2012-2022 Oracle Corporation
 *
 * This file is part of VirtualBox Open Source Edition (OSE), as
 * available from http://www.virtualbox.org. This file is free software;
 * you can redistribute it and/or modify it under the terms of the GNU
 * General Public License (GPL) as published by the Free Software
 * Foundation, in version 2 as it comes in the "COPYING" file of the
 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
 */


/*********************************************************************************************************************************
*   Header Files                                                                                                                 *
*********************************************************************************************************************************/
#define FsRtlTeardownPerStreamContexts  FsRtlTeardownPerStreamContexts_AvoidIt
#define RtlGetVersion                   RtlGetVersion_AvoidIt
#define PsGetProcessImageFileName       PsGetProcessImageFileName_AvoidIt
#include "vbsf.h"

#include <iprt/asm.h>


#if 0
/*
 * FsRtlTeardownPerStreamContexts.
 */
static VOID __stdcall Resolve_FsRtlTeardownPerStreamContexts(PFSRTL_ADVANCED_FCB_HEADER);
static volatile PFN_FSRTLTEARDOWNPERSTREAMCONTEXTS g_pfnFsRtlTeardownPerStreamContexts = Resolve_FsRtlTeardownPerStreamContexts;


static VOID __stdcall Fake_FsRtlTeardownPerStreamContexts(PFSRTL_ADVANCED_FCB_HEADER pAdvancedHeader)
{
    PLIST_ENTRY pCur;

    ExAcquireFastMutex(pAdvancedHeader->FastMutex);

    pCur = pAdvancedHeader->FilterContexts.Flink;
    while (pCur != &pAdvancedHeader->FilterContexts)
    {
        PLIST_ENTRY                 pNext = pCur->Flink;
        PFSRTL_PER_STREAM_CONTEXT   pCtx  = CONTAINING_RECORD(pCur, FSRTL_PER_STREAM_CONTEXT, Links);
        Log(("Fake_FsRtlTeardownPerStreamContexts: %p\n", pCtx));
        pCtx->FreeCallback(pCtx);
        pCur = pNext;
    }
    InitializeListHead(&pAdvancedHeader->FilterContexts);

    ExReleaseFastMutex(pAdvancedHeader->FastMutex);
    return;
}


static VOID __stdcall Resolve_FsRtlTeardownPerStreamContexts(PFSRTL_ADVANCED_FCB_HEADER pAdvancedHeader)
{
    UNICODE_STRING                      RoutineName;
    PFN_FSRTLTEARDOWNPERSTREAMCONTEXTS  pfn;
    Log(("Resolve_FsRtlTeardownPerStreamContexts: %p\n", pAdvancedHeader));

    RtlInitUnicodeString(&RoutineName, L"KeIpiGenericCall");
    pfn = (PFN_FSRTLTEARDOWNPERSTREAMCONTEXTS)MmGetSystemRoutineAddress(&RoutineName);
    if (!pfn)
        pfn = Fake_FsRtlTeardownPerStreamContexts;
    ASMAtomicWritePtr(&g_pfnFsRtlTeardownPerStreamContexts, pfn);
    pfn(pAdvancedHeader);
}


#undef FsRtlTeardownPerStreamContexts
__declspec(dllexport) VOID
FsRtlTeardownPerStreamContexts(PFSRTL_ADVANCED_FCB_HEADER pAdvancedHeader)
{
    Log(("FsRtlTeardownPerStreamContexts: %p\n", pAdvancedHeader));
    g_pfnFsRtlTeardownPerStreamContexts(pAdvancedHeader);
    Log(("FsRtlTeardownPerStreamContexts: returns\n"));
}
#endif


/*
 * RtlGetVersion
 */
typedef NTSTATUS (__stdcall * PFNRTLGETVERSION)(PRTL_OSVERSIONINFOW);
static NTSTATUS __stdcall Resolve_RtlGetVersion(PRTL_OSVERSIONINFOW pVerInfo);
static volatile PFNRTLGETVERSION g_pfnRtlGetVersion = Resolve_RtlGetVersion;


static NTSTATUS __stdcall Fake_RtlGetVersion(PRTL_OSVERSIONINFOW pVerInfo)
{
    Log(("Fake_RtlGetVersion: %p\n", pVerInfo));
    if (pVerInfo->dwOSVersionInfoSize < sizeof(*pVerInfo))
    {
        Log(("Fake_RtlGetVersion: -> STATUS_INVALID_PARAMETER (size = %#x)\n", pVerInfo->dwOSVersionInfoSize));
        return STATUS_INVALID_PARAMETER;
    }

    /* Report Windows 2000 w/o SP. */
    pVerInfo->dwMajorVersion  = 5;
    pVerInfo->dwMinorVersion  = 0;
    pVerInfo->dwBuildNumber   = 2195;
    pVerInfo->dwPlatformId    = VER_PLATFORM_WIN32_NT;
    pVerInfo->szCSDVersion[0] = '\0';

    if (pVerInfo->dwOSVersionInfoSize >= sizeof(RTL_OSVERSIONINFOEXW))
    {
        PRTL_OSVERSIONINFOEXW pVerInfoEx = (PRTL_OSVERSIONINFOEXW)pVerInfo;
        pVerInfoEx->wServicePackMajor = 0;
        pVerInfoEx->wServicePackMinor = 0;
        pVerInfoEx->wSuiteMask        = 0;
        pVerInfoEx->wProductType      = VER_NT_WORKSTATION;
        pVerInfoEx->wReserved         = 0;
    }

    return STATUS_SUCCESS;
}


static NTSTATUS __stdcall Resolve_RtlGetVersion(PRTL_OSVERSIONINFOW pVerInfo)
{
    UNICODE_STRING  RoutineName;
    PFNRTLGETVERSION pfn;
    Log(("Resolve_RtlGetVersion: %p\n", pVerInfo));

    RtlInitUnicodeString(&RoutineName, L"RtlGetVersion");
    pfn = (PFNRTLGETVERSION)(uintptr_t)MmGetSystemRoutineAddress(&RoutineName);
    if (!pfn)
        pfn = Fake_RtlGetVersion;
    ASMAtomicWritePtr((void * volatile *)&g_pfnRtlGetVersion, (void *)(uintptr_t)pfn);

    return pfn(pVerInfo);
}


#undef RtlGetVersion
__declspec(dllexport) NTSTATUS __stdcall
RtlGetVersion(PRTL_OSVERSIONINFOW pVerInfo)
{
    return g_pfnRtlGetVersion(pVerInfo);
}


/*
 * PsGetProcessImageFileName
 */

typedef LPSTR (__stdcall * PFNPSGETPROCESSIMAGEFILENAME)(PEPROCESS pProcess);
static LPSTR __stdcall Resolve_PsGetProcessImageFileName(PEPROCESS pProcess);
static volatile PFNPSGETPROCESSIMAGEFILENAME g_pfnPsGetProcessImageFileName = Resolve_PsGetProcessImageFileName;


static LPSTR __stdcall Fake_PsGetProcessImageFileName(PEPROCESS pProcess)
{
    RT_NOREF(pProcess);
    Log(("Fake_PsGetProcessImageFileName: %p\n", pProcess));
    return "Fake_PsGetProcessImageFileName";
}


static LPSTR __stdcall Resolve_PsGetProcessImageFileName(PEPROCESS pProcess)
{
    UNICODE_STRING                  RoutineName;
    PFNPSGETPROCESSIMAGEFILENAME    pfn;
    Log(("Resolve_PsGetProcessImageFileName: %p\n", pProcess));

    RtlInitUnicodeString(&RoutineName, L"PsGetProcessImageFileName");
    pfn = (PFNPSGETPROCESSIMAGEFILENAME)(uintptr_t)MmGetSystemRoutineAddress(&RoutineName);
    if (!pfn)
        pfn = Fake_PsGetProcessImageFileName;
    ASMAtomicWritePtr((void * volatile *)&g_pfnPsGetProcessImageFileName, (void *)(uintptr_t)pfn);

    return pfn(pProcess);
}


#undef PsGetProcessImageFileName
__declspec(dllexport) LPSTR __stdcall
PsGetProcessImageFileName(PEPROCESS pProcess)
{
    return g_pfnPsGetProcessImageFileName(pProcess);
}