-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
214 lines (204 loc) · 6.67 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/* i'm here to introduce you my brainrot powered main.cpp file that i created to
* fulfill my sensless existence with something nice and funny! */
#include <cstdint>
#include <unistd.h>
typedef struct /* braindamage */
{
void (*hi)();
} silly;
__attribute((noinline)) auto
teeHee(void) -> decltype(void())
{
/* this function can be done in less lines but it looks ugly just like that,
* and i also like how it looks so... cope + ratio + l + don't care + didn't
* asked + stfu + you fell off + cry about it! */
const char *h[] = {"w", "w", "h", "e", "o"};
const char *w[] = {"l", "d", "r", "w", "o"};
const char *b[] = {">", "!", " ", "<", "w", "\n"};
asm volatile("movq $1, %%rax;"
"movq $1, %%rdi;"
"movq %0, %%rsi;"
"movq $1, %%rdx;"
"syscall;"
:
: "r"(h[2])
: "%rax", "%rdi", "%rsi", "%rdx");
asm volatile("movq $1, %%rax;"
"movq $1, %%rdi;"
"movq %0, %%rsi;"
"movq $1, %%rdx;"
"syscall;"
:
: "r"(h[3])
: "%rax", "%rdi", "%rsi", "%rdx");
asm volatile("movq $1, %%rax;"
"movq $1, %%rdi;"
"movq %0, %%rsi;"
"movq $1, %%rdx;"
"syscall;"
:
: "r"(h[0])
: "%rax", "%rdi", "%rsi", "%rdx");
asm volatile("movq $1, %%rax;"
"movq $1, %%rdi;"
"movq %0, %%rsi;"
"movq $1, %%rdx;"
"syscall;"
:
: "r"(h[1])
: "%rax", "%rdi", "%rsi", "%rdx");
asm volatile("movq $1, %%rax;"
"movq $1, %%rdi;"
"movq %0, %%rsi;"
"movq $1, %%rdx;"
"syscall;"
:
: "r"(h[4])
: "%rax", "%rdi", "%rsi", "%rdx");
asm volatile("movq $1, %%rax;"
"movq $1, %%rdi;"
"movq %0, %%rsi;"
"movq $1, %%rdx;"
"syscall;"
:
: "r"(b[2])
: "%rax", "%rdi", "%rsi", "%rdx");
asm volatile("movq $1, %%rax;"
"movq $1, %%rdi;"
"movq %0, %%rsi;"
"movq $1, %%rdx;"
"syscall;"
:
: "r"(w[3])
: "%rax", "%rdi", "%rsi", "%rdx");
asm volatile("movq $1, %%rax;"
"movq $1, %%rdi;"
"movq %0, %%rsi;"
"movq $1, %%rdx;"
"syscall;"
:
: "r"(w[4])
: "%rax", "%rdi", "%rsi", "%rdx");
asm volatile("movq $1, %%rax;"
"movq $1, %%rdi;"
"movq %0, %%rsi;"
"movq $1, %%rdx;"
"syscall;"
:
: "r"(w[2])
: "%rax", "%rdi", "%rsi", "%rdx");
asm volatile("movq $1, %%rax;"
"movq $1, %%rdi;"
"movq %0, %%rsi;"
"movq $1, %%rdx;"
"syscall;"
:
: "r"(w[0])
: "%rax", "%rdi", "%rsi", "%rdx");
asm volatile("movq $1, %%rax;"
"movq $1, %%rdi;"
"movq %0, %%rsi;"
"movq $1, %%rdx;"
"syscall;"
:
: "r"(w[1])
: "%rax", "%rdi", "%rsi", "%rdx");
asm volatile("movq $1, %%rax;"
"movq $1, %%rdi;"
"movq %0, %%rsi;"
"movq $1, %%rdx;"
"syscall;"
:
: "r"(b[1])
: "%rax", "%rdi", "%rsi", "%rdx");
asm volatile("movq $1, %%rax;"
"movq $1, %%rdi;"
"movq %0, %%rsi;"
"movq $1, %%rdx;"
"syscall;"
:
: "r"(b[2])
: "%rax", "%rdi", "%rsi", "%rdx");
asm volatile("movq $1, %%rax;"
"movq $1, %%rdi;"
"movq %0, %%rsi;"
"movq $1, %%rdx;"
"syscall;"
:
: "r"(b[0])
: "%rax", "%rdi", "%rsi", "%rdx");
asm volatile("movq $1, %%rax;"
"movq $1, %%rdi;"
"movq %0, %%rsi;"
"movq $1, %%rdx;"
"syscall;"
:
: "r"(b[4])
: "%rax", "%rdi", "%rsi", "%rdx");
asm volatile("movq $1, %%rax;"
"movq $1, %%rdi;"
"movq %0, %%rsi;"
"movq $1, %%rdx;"
"syscall;"
:
: "r"(b[3])
: "%rax", "%rdi", "%rsi", "%rdx");
asm volatile("movq $1, %%rax;"
"movq $1, %%rdi;"
"movq %0, %%rsi;"
"movq $1, %%rdx;"
"syscall;"
:
: "r"(b[5])
: "%rax", "%rdi", "%rsi", "%rdx");
}
__attribute((noinline)) auto
meowlloc(size_t size) -> void * /* ain't no way did you guys noticed too? */
{
/* tiny program break syscall implementation, because i don't want to use
* malloc like normal human beings -_- */
void *powointer = sbrk(
0); /* find the current program break location by passing 0 to sbrk */
if (powointer == (void *) -1)
return nullptr; /* EXPLOSION O_o*/
char *newPowointer = static_cast<char *>(powointer) + size;
powointer = sbrk(size); /* next location */
return (powointer == (void *) -1) ? nullptr
: reinterpret_cast<void *>(newPowointer);
}
__attribute((noinline)) auto
freeMeowmory(void *powointer) -> decltype(void())
{
if (sbrk(-static_cast<int>(reinterpret_cast<char *>(powointer) -
static_cast<char *>(sbrk(0))) /
sizeof(char *)) == (void *) -1)
{
const char *ret[] = {"void freeMeowmory() explode..."};
asm volatile("movq $1, %%rax;"
"movq $1, %%rdi;"
"movq %0, %%rsi;"
"movq $1, %%rdx;"
"syscall;"
:
: "r"(ret[0])
: "%rax", "%rdi", "%rsi", "%rdx");
}
}
__attribute((noinline)) auto
main(const std::int32_t argc, const char* argv[]) -> decltype(std::int32_t())
{
silly *hewwo = (silly *) meowlloc(sizeof(silly));
hewwo->hi = &teeHee;
((void (*)())(hewwo->hi))();
freeMeowmory(hewwo);
constexpr std::int32_t retuwurn{
0xff}; /* will output 255, and actually same effect can be achieved by
passing -1 */
asm volatile("mov $60, %%rax;"
"mov %[retuwurn], %%rdi;"
"syscall;"
:
: [retuwurn] "i"(retuwurn) /* oh wow such a useless thing :3 */
: "%rax", "%rdi");
__builtin_unreachable();
}