MCPcopy Create free account
hub / github.com/dobin/RedEdr / start_child_process

Function start_child_process

RedEdrPplService/control.cpp:158–251  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156
157
158DWORD start_child_process(wchar_t* childCMD)
159{
160 DWORD retval = 0;
161 LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList = NULL;
162 PROCESS_INFORMATION ProcessInformation = { 0 };
163 DWORD ProtectionLevel = PROTECTION_LEVEL_SAME;
164
165
166 if (childCMD == NULL) {
167 LOG_W(LOG_ERROR, L"start_child_process: Invalid command parameter");
168 return ERROR_INVALID_PARAMETER;
169 }
170
171 LOG_W(LOG_INFO, L"start_child_process: Starting");
172
173 // Create Attribute List
174 STARTUPINFOEXW StartupInfoEx = { 0 };
175 SIZE_T AttributeListSize = 0;
176 StartupInfoEx.StartupInfo.cb = sizeof(StartupInfoEx);
177
178 InitializeProcThreadAttributeList(NULL, 1, 0, &AttributeListSize);
179 if (AttributeListSize == 0) {
180 retval = GetLastError();
181 LOG_W(LOG_ERROR, L"start_child_process: InitializeProcThreadAttributeList1 Error: %d", retval);
182 return retval;
183 }
184
185 lpAttributeList = (LPPROC_THREAD_ATTRIBUTE_LIST)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, AttributeListSize);
186 if (lpAttributeList == NULL) {
187 LOG_W(LOG_ERROR, L"start_child_process: HeapAlloc failed");
188 return ERROR_NOT_ENOUGH_MEMORY;
189 }
190
191 StartupInfoEx.lpAttributeList = lpAttributeList;
192
193 if (InitializeProcThreadAttributeList(lpAttributeList, 1, 0, &AttributeListSize) == FALSE) {
194 retval = GetLastError();
195 LOG_W(LOG_ERROR, L"start_child_process: InitializeProcThreadAttributeList2 Error: %d", retval);
196 goto cleanup;
197 }
198
199 // Set ProtectionLevel to be the same, i.e. PPL
200 if (UpdateProcThreadAttribute(lpAttributeList,
201 0,
202 PROC_THREAD_ATTRIBUTE_PROTECTION_LEVEL,
203 &ProtectionLevel,
204 sizeof(ProtectionLevel),
205 NULL,
206 NULL) == FALSE)
207 {
208 retval = GetLastError();
209 LOG_W(LOG_ERROR, L"start_child_process: UpdateProcThreadAttribute Error: %d", retval);
210 goto cleanup;
211 }
212
213 // Start Process (hopefully)
214 LOG_W(LOG_INFO, L"start_child_process: Creating Process: '%s'", childCMD);
215 if (CreateProcess(NULL,

Callers 1

rededr_remove_serviceFunction · 0.85

Calls 1

LOG_WFunction · 0.70

Tested by

no test coverage detected