惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
阮一峰的网络日志
阮一峰的网络日志
有赞技术团队
有赞技术团队
小众软件
小众软件
P
Proofpoint News Feed
P
Proofpoint News Feed
Apple Machine Learning Research
Apple Machine Learning Research
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
O
OpenAI News
Security Latest
Security Latest
博客园 - Franky
Forbes - Security
Forbes - Security
N
Netflix TechBlog - Medium
H
Hacker News: Front Page
Cloudbric
Cloudbric
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Hugging Face - Blog
Hugging Face - Blog
Microsoft Security Blog
Microsoft Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Security Affairs
Recent Announcements
Recent Announcements
The GitHub Blog
The GitHub Blog
S
Schneier on Security
MongoDB | Blog
MongoDB | Blog
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
Attack and Defense Labs
Attack and Defense Labs
C
Cyber Attacks, Cyber Crime and Cyber Security
F
Fortinet All Blogs
Webroot Blog
Webroot Blog
S
Secure Thoughts
Spread Privacy
Spread Privacy
Blog — PlanetScale
Blog — PlanetScale
T
Troy Hunt's Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
V2EX
Security Archives - TechRepublic
Security Archives - TechRepublic
P
Privacy & Cybersecurity Law Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Simon Willison's Weblog
Simon Willison's Weblog
C
Check Point Blog
L
LINUX DO - 最新话题
NISL@THU
NISL@THU
博客园_首页
罗磊的独立博客
A
Arctic Wolf
U
Unit 42

Bluemangoo's Blog

看一点答辩Issue 在 Vercel 上部署 MCSManager 的 UI 项目 Python 语言基础 Vercel 折腾笔记 建站一周年纪念! Bing Points 辅助工具 白象过湾 Windows 10 触摸键盘大小调整 尘烟 One一个 文章推荐 Markdown 加载器 力扣 0899 - 有序队列 【芒果快评】安倍晋三遭枪击 常用软件下载链接 那些震惊了我的文案(持续更新) 一个抛鸡蛋的小游戏 《1984》书评 Explorer Patcher 推荐 英语书也会出错啊 图片转Python的turtle库代码 Phigros电脑版 Windows 11 子系统(WSA)安装方法
内存填充器
Bluemangoo · 2022-08-08 · via Bluemangoo's Blog

本文章的内容很危险,会导致电脑死机、蓝屏,请勿在实体机上尝试。

朋友要录视频,虚拟机里面养病毒,有一些经典的病毒,还有一些自己写的 C++ 程序。

我: C++ ? 我来,保证你电脑死机。

原理

C++ 没有 GC(Garbage Collection, 垃圾回收)机制,一切病毒都要自己手动管理。

如果我疯狂申请内存,但是坚决不释放,就可以达到内存泄露的效果。

new 申请内存,用 delete 释放内存。如果不 delete 会在程序运行结束后由系统自动释放。(反正也结束不了)

内存泄露是指不用的内存没有及时释放一直占用空间。

代码

1
2
3
4
5
6
7
#define NUM 1000000
int main(){
int **a=new int*[NUM];
for(int j=0;j<NUM;j++){
a[j]=new int[NUM];
}
}

改进

第一个版本可以导致巨量卡顿,但是会因为报错而退出。

为了解决这个问题只要套个 try 就行了。

这里用了一个 for 代替 goto ,也算是奇技淫巧了 (不是

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#define NUM 1000000
int main(){
for(int i=0;i<1;i++){
try{
int **a=new int*[NUM];
for(int j=0;j<NUM;j++){
a[j]=new int[NUM];
}
}
catch(...){
i--;
}
}
}

再改进

new 分配内存的效率不高,要想效率高需要用 malloc

malloc 在头文件 malloc.h 中。

函数原型:

1
2
extern void *malloc(unsigned int num_bytes);
//void *__cdecl malloc(size_t _Size); //(in malloc.h 78:3)

改进后的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#define NUM 1000000
#include<malloc.h>
int main(){
for(int i=0;i<1;i++){
try{
int **a=new int*[NUM];
for(int j=0;j<NUM;j++){
a[j]=(int*)malloc(NUM);
}
}
catch(...){
i--;
}
}
}

备注

NUM 是火力,小了可以成功运行,只要足够大就能榨干内存。

会申请 NUM * NUMint 类型的存储空间,1int 类型占 4字节16384 * 16384int 类型占 1G,普通电脑 NUM 打到 65,536 大概就受不了了。

请大家千(yí)万(dìng)不(shì)要(shì)把 NUM 打到这么高。