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

推荐订阅源

雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
Scott Helme
Scott Helme
P
Proofpoint News Feed
D
Docker
The Hacker News
The Hacker News
云风的 BLOG
云风的 BLOG
Vercel News
Vercel News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Project Zero
Project Zero
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
GbyAI
GbyAI
Jina AI
Jina AI
P
Proofpoint News Feed
P
Privacy & Cybersecurity Law Blog
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
博客园 - 叶小钗
U
Unit 42
博客园_首页
Apple Machine Learning Research
Apple Machine Learning Research
Latest news
Latest news
T
The Exploit Database - CXSecurity.com
博客园 - 三生石上(FineUI控件)
博客园 - 聂微东
T
Threatpost
V
Vulnerabilities – Threatpost
C
Cisco Blogs
Spread Privacy
Spread Privacy
Cisco Talos Blog
Cisco Talos Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
V
Visual Studio Blog
G
GRAHAM CLULEY
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky
G
Google Developers Blog
Know Your Adversary
Know Your Adversary
F
Fortinet All Blogs
H
Hackread – Cybersecurity News, Data Breaches, AI and More
NISL@THU
NISL@THU
N
Netflix TechBlog - Medium
Y
Y Combinator Blog
L
Lohrmann on Cybersecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
Recent Announcements
Recent Announcements
量子位
S
Schneier on Security
I
Intezer
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Darknet – Hacking Tools, Hacker News & Cyber Security

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