MCPcopy Create free account
hub / github.com/NoMercy-ac/NoMercy / CreateCustomThread

Method CreateCustomThread

Source/Client/NM_Engine/ThreadManagerHelper.cpp:29–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27}
28
29std::shared_ptr <CThread> CThreadManager::CreateCustomThread(int iThreadCode, LPTHREAD_START_ROUTINE pFunc, std::size_t ulFuncSize, LPVOID lpParam, DWORD dwMaxDelay, bool bIsTemporaryThread /* TODO: LPDWORD pdwErrorStep, bool bCreateSuspended = false */)
30{
31 DEBUG_LOG(LL_SYS, "Custom thread(%u) create has been started!", iThreadCode);
32
33 if (GetThreadFromThreadCode(iThreadCode))
34 {
35 DEBUG_LOG(LL_CRI, "Already exist thread with code(%d)!", iThreadCode);
36
37 g_nmApp->OnCloseRequest(EXIT_ERR_CUSTOM_THREAD_ALREADY_EXIST, g_winapiApiTable->GetLastError());
38 return nullptr;
39 }
40
41 auto dwThreadId = 0UL;
42 auto hThread = CThreadFunctions::CreateThread(iThreadCode, pFunc, lpParam, &dwThreadId);
43 if (!IS_VALID_HANDLE(hThread))
44 {
45 DEBUG_LOG(LL_CRI, "Thread: %d can NOT created! Error: %u", iThreadCode, g_winapiApiTable->GetLastError());
46
47 g_nmApp->OnCloseRequest(EXIT_ERR_CUSTOM_THREAD_CREATE_FAIL, g_winapiApiTable->GetLastError());
48 return nullptr;
49 }
50
51 if (g_nmApp->AccessHelperInstance()->BlockAccess(hThread) == false)
52 {
53 DEBUG_LOG(LL_CRI, "Thread access rules(1) can NOT adjusted for: %d Error: %u", iThreadCode, g_winapiApiTable->GetLastError());
54
55 g_nmApp->OnCloseRequest(EXIT_ERR_CUSTOM_THREAD_ACCESS_1_FAIL, g_winapiApiTable->GetLastError());
56 return nullptr;
57 }
58
59 if (g_nmApp->AccessHelperInstance()->DenyThreadAccess(hThread) == false)
60 {
61 DEBUG_LOG(LL_CRI, "Thread access rules(2) can NOT adjusted for: %d Error: %u", iThreadCode, g_winapiApiTable->GetLastError());
62
63 g_nmApp->OnCloseRequest(EXIT_ERR_CUSTOM_THREAD_ACCESS_2_FAIL, g_winapiApiTable->GetLastError());
64 return nullptr;
65 }
66
67 auto customThread = std::make_shared<CThread>(hThread, dwThreadId, iThreadCode);
68 if (!IS_VALID_SMART_PTR(customThread))
69 {
70 DEBUG_LOG(LL_CRI, "Thread class can NOT created! Thread: %d Error: %u", iThreadCode, g_winapiApiTable->GetLastError());
71
72 g_nmApp->OnCloseRequest(EXIT_ERR_CUSTOM_THREAD_ALLOC_CLASS_FAIL, g_winapiApiTable->GetLastError());
73 return nullptr;
74 }
75
76 auto threadInfos = std::make_shared<SSelfThreads>();
77 if (!IS_VALID_SMART_PTR(threadInfos))
78 {
79 DEBUG_LOG(LL_CRI, "Thread data container can NOT created! Thread: %d Error: %u", iThreadCode, g_winapiApiTable->GetLastError());
80
81 g_nmApp->OnCloseRequest(EXIT_ERR_CUSTOM_THREAD_ALLOC_CONTAINER_FAIL, g_winapiApiTable->GetLastError());
82 return nullptr;
83 }
84
85 auto pExitCallbackHelper = std::make_shared<CThreadExitWatcher>();
86 if (!IS_VALID_SMART_PTR(pExitCallbackHelper))

Callers 12

InitWindowCheckMethod · 0.80
InitAntiMacroMethod · 0.80
InitAntiSoftBPMethod · 0.80
InitSocketConnectionMethod · 0.80
OnClientInitMethod · 0.80
InitializeWatchdogMethod · 0.80
InitWMIWatcherMethod · 0.80
InitChecksumScanMethod · 0.80
InitThreadTickCheckerMethod · 0.80

Calls 7

IsWindows10OrGreaterFunction · 0.85
GetWindowsBuildNumberFunction · 0.85
OnCloseRequestMethod · 0.80
BlockAccessMethod · 0.80
AccessHelperInstanceMethod · 0.80
DenyThreadAccessMethod · 0.80

Tested by

no test coverage detected