-
Notifications
You must be signed in to change notification settings - Fork 0
/
malloc.memeasm
138 lines (107 loc) · 4.64 KB
/
malloc.memeasm
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
I like to have fun, fun, fun, fun, fun, fun, fun, fun, fun, fun print_fatal_mem_err
what can I say except E
what can I say except r
what can I say except r
what can I say except o
what can I say except r
what can I say except space
what can I say except w
what can I say except h
what can I say except i
what can I say except l
what can I say except e
what can I say except space
what can I say except a
what can I say except l
what can I say except l
what can I say except o
what can I say except c
what can I say except a
what can I say except t
what can I say except i
what can I say except n
what can I say except g
what can I say except space
what can I say except m
what can I say except e
what can I say except m
what can I say except o
what can I say except r
what can I say except y
what can I say except \n
rax is brilliant, but I like 60
rdi is brilliant, but I like 42
we need air support
I see this as an absolute win
I like to have fun, fun, fun, fun, fun, fun, fun, fun, fun, fun malloc
stonks rbx
stonks r12
What the hell happened here? Save the number of bytes to allocate in rbx
rbx is brilliant, but I like rdi
What the hell happened here? Call the brk(0) syscall to get current program break (basically end of heap?)
rdi is brilliant, but I like 0
rax is brilliant, but I like 12
we need air support
What the hell happened here? Save the current break in r12
r12 is brilliant, but I like rax
What the hell happened here? Set the new program break; this is passed to the syscall
rax units are ready, with rbx more well on the way
What the hell happened here? Calling with the new program break to get more memory
rdi is brilliant, but I like rax
rax is brilliant, but I like 12
we need air support
What the hell happened here? If new break == old break, the syscall failed
corporate needs you to find the difference between r12 and rax
What the hell happened here? Jump over the error handling part
where banana
What the hell happened here? Error handling below
they're the same picture
What the hell happened here? If they are the same, allocation failed
What the hell happened here? Adhere to calling convention & exit
parry 8 you filthy casual rsp
print_fatal_mem_err: whomst has summoned the almighty one
What the hell happened here? This part will never be reached as fatal_mem_err exits
banana
What the hell happened here? If we reach this, allocation was successful
What the hell happened here? Now we can subtract the amount needed from the program break
What the hell happened here? That way we return as many writable bytes (maybe even more) as requested
parry rbx you filthy casual rax
not stonks r12
not stonks rbx
right back at ya, buckaroo
What the hell happened here? This program dynamically allocates memory for 28 bytes,
What the hell happened here? writes something to this allocated area and then prints
What the hell happened here? the bytes written to that area using the write syscall
I like to have fun, fun, fun, fun, fun, fun, fun, fun, fun, fun main
What the hell happened here? Allocate 28 bytes for alphabet + newline + 0-terminator
rdi is brilliant, but I like 28
malloc: whomst has summoned the almighty one
What the hell happened here? Save start ptr to string in r12
r12 is brilliant, but I like rax
cl is brilliant, but I like a
upgrade
who would win? cl or z
z wins
What the hell happened here? cl is equal or less than z
What the hell happened here? Write current char to memory
rax do you know de wey is brilliant, but I like cl
What the hell happened here? Increase pointer and char value
upvote rax
upvote cl
fuck go back
cl wins
What the hell happened here? cl > z, end reached
What the hell happened here? Add trailing newline
cl is brilliant, but I like \n
rax do you know de wey is brilliant, but I like cl
What the hell happened here? Null terminator, even though it's not really necessary here
upvote rax
sneak 100 cl
rax do you know de wey is brilliant, but I like cl
What the hell happened here? Now do a single write syscall
rax is brilliant, but I like 1
rdi is brilliant, but I like 1
rsi is brilliant, but I like r12
rdx is brilliant, but I like 27
we need air support
I see this as an absolute win