Sample Code

Windows Driver Samples/ Windows Filtering Platform Sample/ C++/ exe/ Scenarios_AppContainers.cpp/

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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
////////////////////////////////////////////////////////////////////////////////////////////////////
//
//   Copyright (c) 2012 Microsoft Corporation.  All Rights Reserved.
//
//   Module Name:
//      Scenarios_AppContainers.cpp
//
//   Abstract:
//      This module contains functions which prepares and sends data for the APPLICATION_CONTAINER
//      scenario implementation.
//
//   Naming Convention:
//
//      <Scope><Object><Action><Modifier>
// 
//      i.e.
//
//       <Scope>
//          {
//                                 - Function is likely visible to other modules.
//            Prv                  - Function is private to this module.
//          }
//       <Object>
//          {
//            AppContainerScenario - Function pertains to all of the Application Container Scenarios.
//          }
//       <Action>
//          {
//            Execute              - Function packages data and invokes RPC to the WFPSampler
//                                      service.
//            Log                  - Function writes to the console.
//            Parse                - Function pulls data into the required format from the provided
//                                      data.
//          }
//       <Modifier>
//          {
//            DataForModifiers     - Function acts on scenario modifiers such as volatility and
//                                      removal.
//            Help                 - Function provides context sensitive help for the scenario.
//          }
//
//   Public Functions:
//      AppContainerScenarioExecute(),
//      AppContainerScenarioLogHelp
//
//   Author:
//      Dusty Harper      (DHarper)
//
//   Revision History:
//
//      [ Month ][Day] [Year] - [Revision]-[ Comments ]
//      May       01,   2010  -     1.0   -  Creation
//
////////////////////////////////////////////////////////////////////////////////////////////////////
 
#include "Framework_WFPSampler.h" /// .
 
#if(NTDDI_VERSION >= NTDDI_WIN8)
 
/**
 @private_function="PrvAppContainerScenarioParseDataForModifiers"
  
   Purpose:  Parse the command line parameters for any scenario modifiers such as:              <br>
                trust Windows Service Hardening        (-trustWSH)                              <br>
                add own filters for containers         (-distrustWSH)                           <br>
                use a callout                          (-c)                                     <br>
                make volatile / non persistent         (-v)                                     <br>
                mark objects available during boottime (-b)                                     <br>
                remove scenario                        (-r)                                     <br>
                                                                                                <br>
   Notes:                                                                                       <br>
                                                                                                <br>
   MSDN_Ref:                                                                                    <br>
*/
_Success_(return == NO_ERROR)
UINT32 PrvAppContainerScenarioParseDataForModifiers(_In_reads_(stringCount) PCWSTR* ppCLPStrings,
                                                    _In_ UINT32 stringCount,
                                                    _Inout_ BOOLEAN* pTrustWSH,
                                                    _Inout_ BOOLEAN* pRemoveScenario,
                                                    _Inout_ BOOLEAN* pIsPersistent,
                                                    _Inout_ BOOLEAN* pIsBootTime)
{
   ASSERT(ppCLPStrings);
   ASSERT(stringCount);
   ASSERT(pTrustWSH);
   ASSERT(pRemoveScenario);
   ASSERT(pIsPersistent);
   ASSERT(pIsBootTime);
 
   UINT32 status = NO_ERROR;
 
   for(UINT32 stringIndex = 0;
       stringIndex < stringCount;
       stringIndex++)
   {
      /// Trust that Windows Service Hardening rules are enforcing AppContainer constraints
      if(HlprStringsAreEqual(L"-trustWSH",
                             ppCLPStrings[stringIndex]))
      {
         *pTrustWSH = TRUE;
 
         continue;
      }
 
      /// Distrust that Windows Service Hardening rules are enforcing AppContainer constraints
      if(HlprStringsAreEqual(L"-distrustWSH",
                             ppCLPStrings[stringIndex]))
      {
         *pTrustWSH = FALSE;
 
         continue;
      }
 
      /// Remove any filter with this setup
      if(HlprStringsAreEqual(L"-r",
                             ppCLPStrings[stringIndex]))
      {
         *pRemoveScenario = TRUE;
 
         continue;
      }
 
      /// Make the objects volatile
      if(HlprStringsAreEqual(L"-v",
                             ppCLPStrings[stringIndex]) &&
         *pIsBootTime == FALSE)
      {
         *pIsPersistent = FALSE;
 
         continue;
      }
 
      /// Mark the objects available during BootTime
      if(HlprStringsAreEqual(L"-b",
                             ppCLPStrings[stringIndex]))
      {
         *pIsPersistent = TRUE;
 
         *pIsBootTime = TRUE;
 
         continue;
      }
   }
 
   return status;
}
 
/**
 @scenario_function="AppContainerScenarioExecute"
 
   Purpose:  Gather and package data neccessary to setup the APPLICATION_CONTAINER scenario,
             then invoke RPC to implement the scenario in the WFPSampler service.               <br>
                                                                                                <br>
   Notes:                                                                                       <br>
                                                                                                <br>
   MSDN_Ref:                                                                                    <br>
*/
_Success_(return == NO_ERROR)
UINT32 AppContainerScenarioExecute(_In_reads_(stringCount) PCWSTR* ppCLPStrings,
                                   _In_ UINT32 stringCount)
{
   ASSERT(ppCLPStrings);
   ASSERT(stringCount);
 
   UINT32  status         = NO_ERROR;
   BOOLEAN trustWSH       = TRUE;
   BOOLEAN removeScenario = FALSE;
   BOOLEAN persistent     = TRUE;
   BOOLEAN bootTime       = FALSE;
 
   status = PrvAppContainerScenarioParseDataForModifiers(ppCLPStrings,
                                                        stringCount,
                                                        &trustWSH,
                                                        &removeScenario,
                                                        &persistent,
                                                        &bootTime);
   HLPR_BAIL_ON_FAILURE(status);
 
   status = RPCInvokeScenarioAppContainer(wfpSamplerBindingHandle,
                                          SCENARIO_APP_CONTAINER,
                                          removeScenario ? FWPM_CHANGE_DELETE : FWPM_CHANGE_ADD,
                                          trustWSH,
                                          persistent,
                                          bootTime);
   if(status != NO_ERROR)
      HlprLogError(L"AppContainerScenarioExecute : RPCInvokeScenarioAppContainer() [status: %#x]",
                   status);
   else
      HlprLogInfo(L"AppContainerScenarioExecute : RPCInvokeScenarioAppContainer() [status: %#x]",
                  status);
 
   HLPR_BAIL_LABEL:
 
   return status;
}
 
/**
 @public_function="AppContainerScenarioLogHelp"
  
   Purpose:  Log usage information to the console for the APP_CONTAINER scenario.               <br>
                                                                                                <br>
   Notes:                                                                                       <br>
                                                                                                <br>
   MSDN_Ref:                                                                                    <br>
*/
VOID AppContainerScenarioLogHelp()
{
   PWSTR pScenario = L"APP_CONTAINER";
 
   wprintf(L"\n\t\t -s           \t %s ",
           pScenario);
   wprintf(L"\n\t\t -?           \t Receive usage information.");
   wprintf(L"\n\t\t -r           \t Remove the scenario objects.");
   wprintf(L"\n\t\t -v           \t Make the objects volatile (non-persistent). [Optional]");
   wprintf(L"\n\t\t -b           \t Makes the objects available during boot time. [Optional]");
   wprintf(L"\n\t\t -trustWSH    \t Adds filters that inherently allows Windows Service Hardening");
   wprintf(L"\n\t\t              \t    to handle all App Container decisions. (Default / Recommended)");
   wprintf(L"\n\t\t -distrustWSH \t Enumerates current WSH filters and subscribes to receive future");
   wprintf(L"\n\t\t              \t    filters.  Adds granular filters to allow contained apps.");
   wprintf(L"\n");
   wprintf(L"\n\t i.e.");
   wprintf(L"\n\t\t WFPSampler.Exe -s %s -trustWSH -v",
           pScenario);
   wprintf(L"\n\t\t WFPSampler.Exe -s %s -trustWSH -v -r",
           pScenario);
   wprintf(L"\n");
 
   return;
}
 
#endif /// (NTDDI_VERSION >= NTDDI_WIN8)

Our Services

  • What our customers say about us?

© 2011-2025 All Rights Reserved. Joya Systems. 4425 South Mopac Building II Suite 101 Austin, TX 78735 Tel: 800-DEV-KERNEL

Privacy Policy. Terms of use. Valid XHTML & CSS