MCPcopy Create free account
hub / github.com/beefytech/Beef / BfpProcess_Enumerate

Function BfpProcess_Enumerate

BeefySysLib/platform/win/Platform.cpp:1320–1400  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1318}
1319
1320BFP_EXPORT void BFP_CALLTYPE BfpProcess_Enumerate(const char* machineName, BfpProcess** outProcesses, int* inOutProcessesSize, BfpProcessResult* outResult)
1321{
1322 ImportNTDll();
1323 if (gNtQuerySystemInformation == NULL)
1324 {
1325 *inOutProcessesSize = 0;
1326 return;
1327 }
1328
1329 uint allocSize = 1024;
1330 uint8* data = NULL;
1331
1332 while (true)
1333 {
1334 data = new uint8[allocSize];
1335
1336 ULONG wantSize = 0;
1337 NTSTATUS status = gNtQuerySystemInformation(SystemProcessInformation, data, allocSize, &wantSize);
1338
1339 if (status != STATUS_INFO_LENGTH_MISMATCH)
1340 {
1341 auto processInfo = (SYSTEM_PROCESS_INFORMATION*)data;
1342
1343 auto curProcessInfo = processInfo;
1344 int count = 0;
1345 while (true)
1346 {
1347 if (curProcessInfo == NULL)
1348 break;
1349
1350 count++;
1351 if (curProcessInfo->NextEntryOffset == 0)
1352 break;
1353 curProcessInfo = (SYSTEM_PROCESS_INFORMATION*)((intptr)curProcessInfo + curProcessInfo->NextEntryOffset);
1354 }
1355
1356 if (count > *inOutProcessesSize)
1357 {
1358 *inOutProcessesSize = count;
1359 OUTRESULT(BfpProcessResult_InsufficientBuffer);
1360 delete data;
1361 return;
1362 }
1363
1364 curProcessInfo = processInfo;
1365 count = 0;
1366 while (true)
1367 {
1368 if (curProcessInfo == NULL)
1369 break;
1370
1371 if (curProcessInfo->ProcessId != 0)
1372 {
1373 BfpProcess* process = new BfpProcess();
1374 int dataSize = sizeof(SYSTEM_PROCESS_INFORMATION) + sizeof(SYSTEM_THREAD) * (curProcessInfo->NumberOfThreads - 1);
1375 process->mProcessId = (int)(intptr)curProcessInfo->ProcessId;
1376 process->mInfo = (SYSTEM_PROCESS_INFORMATION*)malloc(dataSize);
1377 memcpy(process->mInfo, curProcessInfo, dataSize);

Callers

nothing calls this directly

Calls 3

ImportNTDllFunction · 0.85
mallocFunction · 0.50
SetMethod · 0.45

Tested by

no test coverage detected