ReactOS  0.4.13-dev-249-gcba1a2f
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 
16 typedef struct _osrange
17 {
20 } osrange;
21 
22 typedef struct _testdata
23 {
27 } testdata;
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 
38 static 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 
70 static void Test_ProtectedFiles()
71 {
72  ULONG n;
73  BOOL Protected;
74  WCHAR Buffer[MAX_PATH * 3];
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());
109  if (!SfcIsFileProtected)
110  return;
111 
112  RtlGetVersion(&rtlinfo);
113  g_WinVersion = (rtlinfo.dwMajorVersion << 8) | rtlinfo.dwMinorVersion;
114 
116 }
struct _osrange osrange
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define TRUE
Definition: types.h:120
struct _testdata testdata
NTSTATUS NTAPI RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: version.c:158
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
static testdata tests[]
BOOL WINAPI SfcIsFileProtected(HANDLE RpcHandle, LPCWSTR ProtFileName)
Definition: sfc_os.c:83
#define _countof(array)
Definition: fontsub.cpp:30
BOOL(WINAPI *SfcIsFileProtected)(HANDLE RpcHandle
GLdouble n
Definition: glext.h:7729
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
START_TEST(SfcIsFileProtected)
unsigned int BOOL
Definition: ntddk_ex.h:94
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
ULONG dwMajorVersion
Definition: rtltypes.h:243
static void Test_ProtectedFiles()
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
LPCWSTR ProtFileName
#define PASS(from, to)
static const WCHAR L[]
Definition: oid.c:1250
static DWORD g_WinVersion
PRTL_UNICODE_STRING_BUFFER Path
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
ULONG dwMinorVersion
Definition: rtltypes.h:244
unsigned int ULONG
Definition: retypes.h:1
#define GetProcAddress(x, y)
Definition: compat.h:410
static int mod
Definition: i386-dis.c:1273