ReactOS 0.4.16-dev-197-g92996da
SfcIsFileProtected.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Test for SfcIsFileProtected
5 * COPYRIGHT: Copyright 2018 Mark Jansen (mark.jansen@reactos.org)
6 */
7
8#include <apitest.h>
9#include <strsafe.h>
10#include <ndk/umtypes.h>
11#include <ndk/rtlfuncs.h>
12
15
16typedef struct _osrange
17{
21
22typedef struct _testdata
23{
28
29
30#define _WIN32_WINNT_MINVER 0x0001
31
32#define MAKERANGE(from, to) \
33 { _WIN32_WINNT_ ## from, _WIN32_WINNT_ ## to }
34
35#define PASS(from, to) \
36 MAKERANGE(from, to)
37
38static testdata tests[] =
39{
40 { L"%systemroot%\\system32\\kernel32.dll", TRUE, PASS(MINVER, WIN10) },
41 { L"%SYSTEMROOT%\\SYSTEM32\\KERNEL32.DLL", TRUE, PASS(MINVER, WIN10) },
42 /* Paths are normalized on newer windows */
43 { L"%systemroot%//system32\\kernel32.dll", TRUE, PASS(VISTA, WIN10) },
44 { L"%systemroot%\\system32\\..\\system32\\kernel32.dll", TRUE, PASS(VISTA, WIN10) },
45
46 /* These are rejected as-is */
47 { L"kernel32.dll", FALSE, PASS(MINVER, MINVER) },
48 { L"%systemroot%//system32\\kernel32.dll", FALSE, PASS(MINVER, MINVER) },
49 /* Environment strings are expanded on older windows */
50 { L"%systemroot%\\system32\\kernel32.dll", FALSE, PASS(MINVER, WS03) },
51 { L"%SYSTEMROOT%\\SYSTEM32\\KERNEL32.DLL", FALSE, PASS(MINVER, WS03) },
52
53 /* Show some files under SFC protection */
54 { L"%systemroot%\\system32\\user32.dll", TRUE, PASS(MINVER, WIN10) },
55 { L"%systemroot%\\system32\\shell32.dll", TRUE, PASS(MINVER, WIN10) },
56 { L"%systemroot%\\system32\\browseui.dll", TRUE, PASS(MINVER, WIN10) },
57 { L"%systemroot%\\system32\\apphelp.dll", TRUE, PASS(MINVER, WIN10) },
58 { L"%systemroot%\\system32\\sfc.dll", TRUE, PASS(MINVER, WIN10) },
59 { L"%systemroot%\\system32\\sfc_os.dll", TRUE, PASS(MINVER, WIN10) },
60 { L"%systemroot%\\system32\\sdbinst.exe", TRUE, PASS(MINVER, WIN10) },
61 { L"%systemroot%\\AppPatch\\sysmain.sdb", TRUE, PASS(MINVER, WIN10) },
62 { L"%systemroot%\\fonts\\tahoma.ttf", TRUE, PASS(MINVER, WIN10) },
63 { L"%systemroot%\\fonts\\tahomabd.ttf", TRUE, PASS(MINVER, WIN10) },
64 { L"%systemroot%\\system32\\ntoskrnl.exe", TRUE, PASS(MINVER, WIN10) },
65 { L"%systemroot%\\system32\\c_1252.nls", TRUE, PASS(MINVER, WIN10) },
66 { L"%systemroot%\\NOTEPAD.EXE", TRUE, PASS(MINVER, WIN10) },
67};
68
69
71{
72 ULONG n;
73 BOOL Protected;
75
76 for (n = 0; n < _countof(tests); ++n)
77 {
78 if (tests[n].Expand)
80 else
82
83 Protected = SfcIsFileProtected(NULL, Buffer);
84
86 {
87 ok(Protected, "[%lu,0x%04lx]: Failed: %S\n", n, g_WinVersion, Buffer);
88 }
89 else
90 {
91 ok(!Protected, "[%lu,0x%04lx]: Succeeded: %S\n", n, g_WinVersion, Buffer);
92 }
93 }
94}
95
96
98{
99 RTL_OSVERSIONINFOW rtlinfo = { sizeof(rtlinfo) };
100 HMODULE mod;
101
102 mod = LoadLibraryA("sfc_os.dll");
103 ok(mod != NULL, "Unable to load sfc_os: 0x%lu\n", GetLastError());
104 if (!mod)
105 return;
106
107 SfcIsFileProtected = (void*)GetProcAddress(mod, "SfcIsFileProtected");
108 ok(SfcIsFileProtected != NULL, "Unable to resolve SfcIsFileProtected: 0x%lu\n", GetLastError());
110 return;
111
112 RtlGetVersion(&rtlinfo);
113 g_WinVersion = (rtlinfo.dwMajorVersion << 8) | rtlinfo.dwMinorVersion;
114
116}
std::map< E_MODULE, HMODULE > mod
Definition: LocaleTests.cpp:66
PRTL_UNICODE_STRING_BUFFER Path
static void Test_ProtectedFiles()
struct _testdata testdata
static DWORD g_WinVersion
#define PASS(from, to)
struct _osrange osrange
LPCWSTR ProtFileName
static testdata tests[]
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: version.c:158
#define GetProcAddress(x, y)
Definition: compat.h:753
#define MAX_PATH
Definition: compat.h:34
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
@ Success
Definition: eventcreate.c:712
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLdouble n
Definition: glext.h:7729
#define BOOL
Definition: nt_native.h:43
#define L(x)
Definition: ntvdm.h:50
BOOL WINAPI SfcIsFileProtected(HANDLE RpcHandle, LPCWSTR ProtFileName)
Definition: sfc_os.c:83
#define _countof(array)
Definition: sndvol32.h:70
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
ULONG dwMinorVersion
Definition: rtltypes.h:248
ULONG dwMajorVersion
Definition: rtltypes.h:247
const uint16_t * PCWSTR
Definition: typedefs.h:57
uint32_t ULONG
Definition: typedefs.h:59
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WINAPI
Definition: msvc.h:6
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185