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

推荐订阅源

WordPress大学
WordPress大学
Martin Fowler
Martin Fowler
Schneier on Security
Schneier on Security
S
Schneier on Security
A
Arctic Wolf
L
LangChain Blog
T
Threatpost
GbyAI
GbyAI
V2EX - 技术
V2EX - 技术
Jina AI
Jina AI
U
Unit 42
P
Proofpoint News Feed
M
MIT News - Artificial intelligence
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
Spread Privacy
Spread Privacy
F
Fortinet All Blogs
Y
Y Combinator Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
月光博客
月光博客
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
F
Full Disclosure
博客园 - 【当耐特】
S
Secure Thoughts
美团技术团队
N
News | PayPal Newsroom
爱范儿
爱范儿
Latest news
Latest news
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
S
Security @ Cisco Blogs
V
V2EX
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
腾讯CDC
The Hacker News
The Hacker News
V
Vulnerabilities – Threatpost
Cyberwarzone
Cyberwarzone
Google Online Security Blog
Google Online Security Blog
N
Netflix TechBlog - Medium
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
The Last Watchdog
The Last Watchdog
N
News and Events Feed by Topic
T
Tor Project blog
博客园 - 三生石上(FineUI控件)
Security Archives - TechRepublic
Security Archives - TechRepublic
大猫的无限游戏
大猫的无限游戏
Security Latest
Security Latest

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