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

推荐订阅源

Google DeepMind News
Google DeepMind News
The Last Watchdog
The Last Watchdog
腾讯CDC
Apple Machine Learning Research
Apple Machine Learning Research
有赞技术团队
有赞技术团队
Last Week in AI
Last Week in AI
量子位
雷峰网
雷峰网
宝玉的分享
宝玉的分享
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
博客园 - 叶小钗
P
Privacy International News Feed
NISL@THU
NISL@THU
V
V2EX
博客园 - 三生石上(FineUI控件)
T
The Exploit Database - CXSecurity.com
T
Threat Research - Cisco Blogs
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
IT之家
IT之家
T
Tor Project blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Threatpost
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
大猫的无限游戏
大猫的无限游戏
V
Vulnerabilities – Threatpost
V
Visual Studio Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
The Hacker News
The Hacker News
Scott Helme
Scott Helme
H
Hacker News: Front Page
罗磊的独立博客
Hacker News - Newest:
Hacker News - Newest: "LLM"
K
Kaspersky official blog
S
Secure Thoughts
www.infosecurity-magazine.com
www.infosecurity-magazine.com
The Cloudflare Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
小众软件
小众软件
月光博客
月光博客
人人都是产品经理
人人都是产品经理
AI
AI
Help Net Security
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
酷 壳 – CoolShell
酷 壳 – CoolShell
Webroot Blog
Webroot Blog
博客园 - 【当耐特】
PCI Perspectives
PCI Perspectives
A
Arctic Wolf

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 打到这么高。