Hack Forums
[The Brotherhood] CPU Monitoring Tool [C++ Source Code] - Scan CPU % Every X Seconds - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Hacks, Exploits, and Various Discussions (https://hackforums.net/forumdisplay.php?fid=45)
+--- Forum: Whitehat • Blue Team • Defensive Security (https://hackforums.net/forumdisplay.php?fid=448)
+---- Forum: Malware, Rat, and Virus Removal (https://hackforums.net/forumdisplay.php?fid=110)
+---- Thread: [The Brotherhood] CPU Monitoring Tool [C++ Source Code] - Scan CPU % Every X Seconds (/showthread.php?tid=6270592)



CPU Monitoring Tool [C++ Source Code] - Scan CPU % Every X Seconds - Hackers - May 8, 2024

[Image: header4.gif]


CPU Monitoring Tool
C++ Source Code


When it comes to keeping your computer safe from malware or other malicious software, the first thing is to detect that its there in the first place. There are many ways to do this, but one thing you can do is look for abnormal CPU usage. Of course, having hundreds of Chrome tabs, or opening a large Adobe file will eat through resources (RAM, CPU, GPU, etc). However, when your computer is truly idle, not updating, not refreshing in the background, your resource usage should be minimal.

For that reason, I asked GPT-4 to create a program using C++ that can find the current CPU % usage, via WMI query lookups (WQL).

Checking CPU % patterns can help identify if a software is running processes "secretly" on your computer.


[Image: Screenshot-2024-05-08-224709.png]



The full source code can be seen below, but first I will show you some highlights to give you a better idea of how this program works.


Code
hres = CoInitializeEx(0, COINIT_MULTITHREADED);

Here is a snippet about this function:
https://pubs.opengroup.org/onlinepubs/009899899/CHP05GDC.HTM#:~:text=Library%20Initialization%20/%20Uninitialization
Quote:To use basic COM services, all COM threads of execution in clients and out-of-process servers must call either the CoInitialize() or the CoInitializeEx() function before calling any other COM function except memory allocation calls. CoInitializeEx() replaces the other function, adding a parameter that allows you to specify the threading model of the thread--either apartment-threaded or free-threaded. A call to CoInitialize() simply sets the threading model to apartment-threaded. For information on threading in clients and servers, refer to Chapter 6.



To use COM, you set the security levels before usage.

[Image: Screenshot-2024-05-08-222720.png]

https://learn.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-coinitializesecurity

Here are the security levels for the code I'm sharing:
Code
hres = CoInitializeSecurity(
    NULL,
    -1,
    NULL,
    NULL,
    RPC_C_AUTHN_LEVEL_DEFAULT,
    RPC_C_IMP_LEVEL_IMPERSONATE,
    NULL,
    EOAC_NONE,
    NULL
);

According to the docs, once we've established our COM variables, we can then continue on to connect to a WMI namespace. Again, still learning about this myself, but from what I understand, it's a "bridge" or a "proxy" to the core WMI database on your machine.

https://learn.microsoft.com/en-us/windows/win32/wmisdk/creating-a-connection-to-a-wmi-namespace

Code
hres = CoCreateInstance(
    CLSID_WbemLocator,
    0,
    CLSCTX_INPROC_SERVER,
    IID_IWbemLocator, (LPVOID*)&pLoc);

// snipped code

hres = pLoc->ConnectServer(
    _bstr_t(L"ROOT\\CIMV2"),
    NULL,
    NULL,
    0,
    NULL,
    0,
    0,
    &pSvc
);

Finally, now that we have prepared our WMI connection, we can start querying!
Lets get the CPU load percentage:

Code
HRESULT hres = pSvc->ExecQuery(
    bstr_t("WQL"),
    bstr_t("SELECT LoadPercentage FROM Win32_Processor"),
    WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
    NULL,
    &pEnumerator
);

If you want to try out other WQL queries, here's more info:
https://learn.microsoft.com/en-us/windows/win32/api/wbemcli/nf-wbemcli-iwbemservices-execquery
Code
HRESULT ExecQuery(
  [in]  const BSTR           strQueryLanguage,
  [in]  const BSTR           strQuery,
  [in]  long                 lFlags,
  [in]  IWbemContext         *pCtx,
  [out] IEnumWbemClassObject **ppEnum
);




[/align]


Source Code
Spoiler (Click to View)



BUMP - Stanley - Mar 16, 2026

I'm Stanley HF's helper bot. The OP (original poster) of this thread wants everyone to see this page and has elected to bump it to the top of the showthread listing. Since HF doesn't want a ton of LQP (Low Quality Posts) this is the best method of bumping your content. There is a small βyte fee for each bump. Any OP can bump any of their threads on HF from the linked icon on the top of their first post.

If you haven't already read the first post of this thread we encourage you to do so.

Thanks,
Stanley


RE: CPU Monitoring Tool [C++ Source Code] - Scan CPU % Every X Seconds - Null State - Mar 17, 2026

(May 8, 2024 07:48 PM)Hackers Wrote:  
[Image: header4.gif]


CPU Monitoring Tool
C++ Source Code


When it comes to keeping your computer safe from malware or other malicious software, the first thing is to detect that its there in the first place. There are many ways to do this, but one thing you can do is look for abnormal CPU usage. Of course, having hundreds of Chrome tabs, or opening a large Adobe file will eat through resources (RAM, CPU, GPU, etc). However, when your computer is truly idle, not updating, not refreshing in the background, your resource usage should be minimal.

For that reason, I asked GPT-4 to create a program using C++ that can find the current CPU % usage, via WMI query lookups (WQL).

Checking CPU % patterns can help identify if a software is running processes "secretly" on your computer.


[Image: Screenshot-2024-05-08-224709.png]



The full source code can be seen below, but first I will show you some highlights to give you a better idea of how this program works.


Code
hres = CoInitializeEx(0, COINIT_MULTITHREADED);

Here is a snippet about this function:
https://pubs.opengroup.org/onlinepubs/009899899/CHP05GDC.HTM#:~:text=Library%20Initialization%20/%20Uninitialization


To use COM, you set the security levels before usage.

[Image: Screenshot-2024-05-08-222720.png]

https://learn.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-coinitializesecurity

Here are the security levels for the code I'm sharing:
Code
hres = CoInitializeSecurity(
    NULL,
    -1,
    NULL,
    NULL,
    RPC_C_AUTHN_LEVEL_DEFAULT,
    RPC_C_IMP_LEVEL_IMPERSONATE,
    NULL,
    EOAC_NONE,
    NULL
);

According to the docs, once we've established our COM variables, we can then continue on to connect to a WMI namespace. Again, still learning about this myself, but from what I understand, it's a "bridge" or a "proxy" to the core WMI database on your machine.

https://learn.microsoft.com/en-us/windows/win32/wmisdk/creating-a-connection-to-a-wmi-namespace

Code
hres = CoCreateInstance(
    CLSID_WbemLocator,
    0,
    CLSCTX_INPROC_SERVER,
    IID_IWbemLocator, (LPVOID*)&pLoc);

// snipped code

hres = pLoc->ConnectServer(
    _bstr_t(L"ROOT\\CIMV2"),
    NULL,
    NULL,
    0,
    NULL,
    0,
    0,
    &pSvc
);

Finally, now that we have prepared our WMI connection, we can start querying!
Lets get the CPU load percentage:

Code
HRESULT hres = pSvc->ExecQuery(
    bstr_t("WQL"),
    bstr_t("SELECT LoadPercentage FROM Win32_Processor"),
    WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
    NULL,
    &pEnumerator
);

If you want to try out other WQL queries, here's more info:
https://learn.microsoft.com/en-us/windows/win32/api/wbemcli/nf-wbemcli-iwbemservices-execquery
Code
HRESULT ExecQuery(
  [in]  const BSTR           strQueryLanguage,
  [in]  const BSTR           strQuery,
  [in]  long                 lFlags,
  [in]  IWbemContext         *pCtx,
  [out] IEnumWbemClassObject **ppEnum
);




[/align]


Source Code
Spoiler (Click to View)

Do you have a repo anywhere for this?


RE: CPU Monitoring Tool [C++ Source Code] - Scan CPU % Every X Seconds - zyleak - Apr 2, 2026

hey bro u didn't need to block me and give me a -12, im new here and i thought this was a hacker forum, where you are allowed to ask anything.


RE: CPU Monitoring Tool [C++ Source Code] - Scan CPU % Every X Seconds - UPGRADING - May 9, 2026

(May 8, 2024 07:48 PM)Hackers Wrote:  
[Image: header4.gif]


CPU Monitoring Tool
C++ Source Code


When it comes to keeping your computer safe from malware or other malicious software, the first thing is to detect that its there in the first place. There are many ways to do this, but one thing you can do is look for abnormal CPU usage. Of course, having hundreds of Chrome tabs, or opening a large Adobe file will eat through resources (RAM, CPU, GPU, etc). However, when your computer is truly idle, not updating, not refreshing in the background, your resource usage should be minimal.

For that reason, I asked GPT-4 to create a program using C++ that can find the current CPU % usage, via WMI query lookups (WQL).

Checking CPU % patterns can help identify if a software is running processes "secretly" on your computer.


[Image: Screenshot-2024-05-08-224709.png]



The full source code can be seen below, but first I will show you some highlights to give you a better idea of how this program works.


Code
hres = CoInitializeEx(0, COINIT_MULTITHREADED);

Here is a snippet about this function:
https://pubs.opengroup.org/onlinepubs/009899899/CHP05GDC.HTM#:~:text=Library%20Initialization%20/%20Uninitialization


To use COM, you set the security levels before usage.

[Image: Screenshot-2024-05-08-222720.png]

https://learn.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-coinitializesecurity

Here are the security levels for the code I'm sharing:
Code
hres = CoInitializeSecurity(
    NULL,
    -1,
    NULL,
    NULL,
    RPC_C_AUTHN_LEVEL_DEFAULT,
    RPC_C_IMP_LEVEL_IMPERSONATE,
    NULL,
    EOAC_NONE,
    NULL
);

According to the docs, once we've established our COM variables, we can then continue on to connect to a WMI namespace. Again, still learning about this myself, but from what I understand, it's a "bridge" or a "proxy" to the core WMI database on your machine.

https://learn.microsoft.com/en-us/windows/win32/wmisdk/creating-a-connection-to-a-wmi-namespace

Code
hres = CoCreateInstance(
    CLSID_WbemLocator,
    0,
    CLSCTX_INPROC_SERVER,
    IID_IWbemLocator, (LPVOID*)&pLoc);

// snipped code

hres = pLoc->ConnectServer(
    _bstr_t(L"ROOT\\CIMV2"),
    NULL,
    NULL,
    0,
    NULL,
    0,
    0,
    &pSvc
);

Finally, now that we have prepared our WMI connection, we can start querying!
Lets get the CPU load percentage:

Code
HRESULT hres = pSvc->ExecQuery(
    bstr_t("WQL"),
    bstr_t("SELECT LoadPercentage FROM Win32_Processor"),
    WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
    NULL,
    &pEnumerator
);

If you want to try out other WQL queries, here's more info:
https://learn.microsoft.com/en-us/windows/win32/api/wbemcli/nf-wbemcli-iwbemservices-execquery
Code
HRESULT ExecQuery(
  [in]  const BSTR           strQueryLanguage,
  [in]  const BSTR           strQuery,
  [in]  long                 lFlags,
  [in]  IWbemContext         *pCtx,
  [out] IEnumWbemClassObject **ppEnum
);




[/align]


Source Code
Spoiler (Click to View)

how is it different from https://www.alcpu.com/CoreTemp/