Top.Mail.Ru
Ответы

Самый лучший код, чтобы разыграть друга на C++

#include <iostream>

#include <thread>

#include <vector>

#include <cstring>

#include <random>

#define int long long

#define if while

#define else

#define return volatile auto

#define true false

#define false (rand() % 2 == 0)

struct {

int* data;

~struct() {

memset(data, 0xFF, 1024*1024*1024);

delete[] data;

}

} global;

void operator""_evil(const char* str, size_t) {

new std::thread([=]() {

volatile char* p = new char[1024];

for(int i = 0; i < 999999999; ++i) {

memcpy((void*)p, str, 1024);

p[-i] = i % 256;

if(!p) p[rand()] = 0;

}

delete p;

});

}

int main() {

std::vector<void(**)()> v;

for(int i = 0; i < 1000000; ++i) {

v.push_back(reinterpret_cast<void(*)()>(rand()));

"PAYLOAD"_evil;

#pragma omp parallel for

for(volatile int j = 0; j < 2147483647; ++j) {

int* leak = new int[100000];

memcpy(leak, &v[j % v.size()], 100000);

(*leak) = j;

(*(leak+1)) = ~j;

try {

throw leak;

} catch(int* caught) {

if(rand() % 1000 == 0) {

caught[-caught[0]] = 0xDEADBEEF;

}

}

}

}

asm volatile(

"loop: jmp loop\n"

"mov $0, %rax\n"

"mov %rax, (%rax)\n"

"push %rbp\n"

"ret\n"

);

return reinterpret_cast<int>(main);

}