-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_matrix.s
More file actions
298 lines (298 loc) · 5.43 KB
/
Copy pathmain_matrix.s
File metadata and controls
298 lines (298 loc) · 5.43 KB
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
.file "main_matrix.c"
.text
.section .rodata
.align 8
.LC0:
.string "\n[ALERT] Security Breach! Return address mismatch.\n"
.align 8
.LC1:
.string "[Detail] Expected: %lx | Found: %lx\n"
.text
.globl calculate_row_sum
.type calculate_row_sum, @function
calculate_row_sum:
.LFB6:
.cfi_startproc
endbr64
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $48, %rsp
movq %rdi, -40(%rbp)
movl %esi, -44(%rbp)
movq 8(%rbp), %rax
movq %rax, -24(%rbp)
movl shadow_sp(%rip), %eax
leal 1(%rax), %edx
movl %edx, shadow_sp(%rip)
cltq
leaq 0(,%rax,8), %rcx
leaq shadow_stack(%rip), %rdx
movq -24(%rbp), %rax
movq %rax, (%rcx,%rdx)
movl $0, -32(%rbp)
movl $0, -28(%rbp)
jmp .L2
.L3:
movl -28(%rbp), %eax
cltq
leaq 0(,%rax,4), %rdx
movq -40(%rbp), %rax
addq %rdx, %rax
movl (%rax), %eax
addl %eax, -32(%rbp)
addl $1, -28(%rbp)
.L2:
movl -28(%rbp), %eax
cmpl -44(%rbp), %eax
jl .L3
movq 8(%rbp), %rax
movq %rax, -16(%rbp)
movl shadow_sp(%rip), %eax
subl $1, %eax
movl %eax, shadow_sp(%rip)
movl shadow_sp(%rip), %eax
cltq
leaq 0(,%rax,8), %rdx
leaq shadow_stack(%rip), %rax
movq (%rdx,%rax), %rax
movq %rax, -8(%rbp)
movq -16(%rbp), %rax
cmpq -8(%rbp), %rax
je .L4
movq stderr(%rip), %rax
movq %rax, %rcx
movl $51, %edx
movl $1, %esi
leaq .LC0(%rip), %rax
movq %rax, %rdi
call fwrite@PLT
movq stderr(%rip), %rax
movq -16(%rbp), %rcx
movq -8(%rbp), %rdx
leaq .LC1(%rip), %rsi
movq %rax, %rdi
movl $0, %eax
call fprintf@PLT
movl $1, %edi
call _exit@PLT
.L4:
movl -32(%rbp), %eax
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE6:
.size calculate_row_sum, .-calculate_row_sum
.section .rodata
.align 8
.LC2:
.string "Matris toplama i\305\237lemi ba\305\237lat\304\261ld\304\261..."
.LC3:
.string "Sat\304\261r %d Toplam\304\261: %d\n"
.align 8
.LC4:
.string "\n[Attack] Matris i\305\237lenirken araya girildi! Stack bozuluyor..."
.text
.globl sum_matrix
.type sum_matrix, @function
sum_matrix:
.LFB7:
.cfi_startproc
endbr64
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
pushq %rbx
subq $88, %rsp
.cfi_offset 3, -24
movl %edi, -68(%rbp)
movl %esi, -72(%rbp)
movq %rdx, -80(%rbp)
movl %ecx, -84(%rbp)
movl -72(%rbp), %ebx
movslq %ebx, %rax
subq $1, %rax
movq %rax, -56(%rbp)
movq 8(%rbp), %rax
movq %rax, -48(%rbp)
movl shadow_sp(%rip), %eax
leal 1(%rax), %edx
movl %edx, shadow_sp(%rip)
cltq
leaq 0(,%rax,8), %rcx
leaq shadow_stack(%rip), %rdx
movq -48(%rbp), %rax
movq %rax, (%rcx,%rdx)
leaq .LC2(%rip), %rax
movq %rax, %rdi
call puts@PLT
movl $0, -64(%rbp)
jmp .L7
.L9:
movl -64(%rbp), %eax
movslq %eax, %rdx
movslq %ebx, %rax
imulq %rdx, %rax
leaq 0(,%rax,4), %rdx
movq -80(%rbp), %rax
addq %rax, %rdx
movl -72(%rbp), %eax
movl %eax, %esi
movq %rdx, %rdi
call calculate_row_sum
movl %eax, -60(%rbp)
movl -60(%rbp), %edx
movl -64(%rbp), %eax
movl %eax, %esi
leaq .LC3(%rip), %rax
movq %rax, %rdi
movl $0, %eax
call printf@PLT
cmpl $0, -84(%rbp)
je .L8
cmpl $1, -64(%rbp)
jne .L8
leaq .LC4(%rip), %rax
movq %rax, %rdi
call puts@PLT
movq %rbp, %rax
addq $8, %rax
movq %rax, -24(%rbp)
movq -24(%rbp), %rax
movq $195935983, (%rax)
.L8:
addl $1, -64(%rbp)
.L7:
movl -64(%rbp), %eax
cmpl -68(%rbp), %eax
jl .L9
movq 8(%rbp), %rax
movq %rax, -40(%rbp)
movl shadow_sp(%rip), %eax
subl $1, %eax
movl %eax, shadow_sp(%rip)
movl shadow_sp(%rip), %eax
cltq
leaq 0(,%rax,8), %rdx
leaq shadow_stack(%rip), %rax
movq (%rdx,%rax), %rax
movq %rax, -32(%rbp)
movq -40(%rbp), %rax
cmpq -32(%rbp), %rax
je .L11
movq stderr(%rip), %rax
movq %rax, %rcx
movl $51, %edx
movl $1, %esi
leaq .LC0(%rip), %rax
movq %rax, %rdi
call fwrite@PLT
movq stderr(%rip), %rax
movq -40(%rbp), %rcx
movq -32(%rbp), %rdx
leaq .LC1(%rip), %rsi
movq %rax, %rdi
movl $0, %eax
call fprintf@PLT
movl $1, %edi
call _exit@PLT
.L11:
nop
movq -8(%rbp), %rbx
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE7:
.size sum_matrix, .-sum_matrix
.section .rodata
.align 8
.LC5:
.string "=== Nested Shadow Stack Test ==="
.align 8
.LC6:
.string "\n--- Test 1: Normal \304\260\305\237leyi\305\237 ---"
.align 8
.LC7:
.string "\n--- Test 2: D\303\266ng\303\274 Esnas\304\261nda Sald\304\261r\304\261 ---"
.text
.globl main
.type main, @function
main:
.LFB8:
.cfi_startproc
endbr64
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $48, %rsp
movq %fs:40, %rax
movq %rax, -8(%rbp)
xorl %eax, %eax
movl $1, -48(%rbp)
movl $2, -44(%rbp)
movl $3, -40(%rbp)
movl $4, -36(%rbp)
movl $5, -32(%rbp)
movl $6, -28(%rbp)
movl $7, -24(%rbp)
movl $8, -20(%rbp)
movl $9, -16(%rbp)
leaq .LC5(%rip), %rax
movq %rax, %rdi
call puts@PLT
leaq .LC6(%rip), %rax
movq %rax, %rdi
call puts@PLT
leaq -48(%rbp), %rax
movl $0, %ecx
movq %rax, %rdx
movl $3, %esi
movl $3, %edi
call sum_matrix
leaq .LC7(%rip), %rax
movq %rax, %rdi
call puts@PLT
leaq -48(%rbp), %rax
movl $1, %ecx
movq %rax, %rdx
movl $3, %esi
movl $3, %edi
call sum_matrix
movl $0, %eax
movq -8(%rbp), %rdx
subq %fs:40, %rdx
je .L14
call __stack_chk_fail@PLT
.L14:
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE8:
.size main, .-main
.ident "GCC: (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0"
.section .note.GNU-stack,"",@progbits
.section .note.gnu.property,"a"
.align 8
.long 1f - 0f
.long 4f - 1f
.long 5
0:
.string "GNU"
1:
.align 8
.long 0xc0000002
.long 3f - 2f
2:
.long 0x3
3:
.align 8
4: