-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquine.min.s
157 lines (157 loc) · 4 KB
/
quine.min.s
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
%macro psym 1
mov r8, %1
call pstr
%endmacro
section .text
pstr:
mov rdx, 0
.lstart:
mov rcx, r8
add rcx, rdx
xor rbx, rbx
mov bl, [rcx]
cmp bl, 0x00
jz .lend
add rdx, 1
jnz .lstart
.lend:
mov rax, 4
mov rbx, 1
mov rcx, r8
int 0x80
ret
pch:
mov rax, 4
mov rbx, 1
mov rcx, r8
mov rdx, 1
int 0x80
ret
global main
main:
psym text
psym start
sub rsp, 16
mov qword [rsp + 8], 0x0000000000000000
mov qword [rsp + 16], 0x0000000000000000
.lstart:
mov rax, [rsp + 8]
mov al, [text + rax]
cmp al, 0x00
je .lend
cmp qword [rsp + 16], 1
jne .lafter_newlinecheck
mov qword [rsp + 16], 0
psym startl
.lafter_newlinecheck:
cmp al, 0x0A
je .lfound_newline
cmp al, 0x22
je .lfound_quote
jne .lfound_literal
.lfound_literal:
mov r8, text
add r8, [rsp + 8]
call pch
jmp .linc
.lfound_quote:
psym quotescape
jmp .linc
.lfound_newline:
psym endl
mov qword [rsp + 16], 1
jmp .linc
.linc:
inc qword [rsp + 8]
jmp .lstart
.lend:
psym end
mov rax, 1
mov rbx, 0x00
int 0x80
section .data
start db " ", 0x22, 0x00
startl db " , ", 0x22, 0x00
quotescape db 0x22, ", 0x22, ", 0x22, 0x00
endl db 0x22, ", 0x0A \", 0x0A, 0x00
end db " , 0x00", 0x0A, 0x00
text db \
"%macro psym 1", 0x0A \
, " mov r8, %1", 0x0A \
, " call pstr", 0x0A \
, "%endmacro", 0x0A \
, "section .text", 0x0A \
, "pstr:", 0x0A \
, " mov rdx, 0", 0x0A \
, ".lstart:", 0x0A \
, " mov rcx, r8", 0x0A \
, " add rcx, rdx", 0x0A \
, " xor rbx, rbx", 0x0A \
, " mov bl, [rcx]", 0x0A \
, " cmp bl, 0x00", 0x0A \
, " jz .lend", 0x0A \
, " add rdx, 1", 0x0A \
, " jnz .lstart", 0x0A \
, ".lend:", 0x0A \
, " mov rax, 4", 0x0A \
, " mov rbx, 1", 0x0A \
, " mov rcx, r8", 0x0A \
, " int 0x80", 0x0A \
, " ret", 0x0A \
, "pch:", 0x0A \
, " mov rax, 4", 0x0A \
, " mov rbx, 1", 0x0A \
, " mov rcx, r8", 0x0A \
, " mov rdx, 1", 0x0A \
, " int 0x80", 0x0A \
, " ret", 0x0A \
, "global main", 0x0A \
, "main:", 0x0A \
, " psym text", 0x0A \
, " psym start", 0x0A \
, " sub rsp, 16", 0x0A \
, " mov qword [rsp + 8], 0x0000000000000000", 0x0A \
, " mov qword [rsp + 16], 0x0000000000000000", 0x0A \
, ".lstart:", 0x0A \
, " mov rax, [rsp + 8]", 0x0A \
, " mov al, [text + rax]", 0x0A \
, " cmp al, 0x00", 0x0A \
, " je .lend", 0x0A \
, " cmp qword [rsp + 16], 1", 0x0A \
, " jne .lafter_newlinecheck", 0x0A \
, " mov qword [rsp + 16], 0", 0x0A \
, " psym startl", 0x0A \
, ".lafter_newlinecheck:", 0x0A \
, " cmp al, 0x0A", 0x0A \
, " je .lfound_newline", 0x0A \
, " cmp al, 0x22", 0x0A \
, " je .lfound_quote", 0x0A \
, " jne .lfound_literal", 0x0A \
, ".lfound_literal:", 0x0A \
, " mov r8, text", 0x0A \
, " add r8, [rsp + 8]", 0x0A \
, " call pch", 0x0A \
, " jmp .linc", 0x0A \
, ".lfound_quote:", 0x0A \
, " psym quotescape", 0x0A \
, " jmp .linc", 0x0A \
, ".lfound_newline:", 0x0A \
, " psym endl", 0x0A \
, " mov qword [rsp + 16], 1", 0x0A \
, " jmp .linc", 0x0A \
, ".linc:", 0x0A \
, " inc qword [rsp + 8]", 0x0A \
, " jmp .lstart", 0x0A \
, ".lend:", 0x0A \
, " psym end", 0x0A \
, " mov rax, 1", 0x0A \
, " mov rbx, 0x00", 0x0A \
, " int 0x80", 0x0A \
, "section .data", 0x0A \
, "start db ", 0x22, " ", 0x22, ", 0x22, 0x00", 0x0A \
, "startl db ", 0x22, " , ", 0x22, ", 0x22, 0x00", 0x0A \
, "quotescape db 0x22, ", 0x22, ", 0x22, ", 0x22, ", 0x22, 0x00", 0x0A \
, "endl db 0x22, ", 0x22, ", 0x0A \", 0x22, ", 0x0A, 0x00", 0x0A \
, "end db ", 0x22, " , 0x00", 0x22, ", 0x0A, 0x00", 0x0A \
, "text db \", 0x0A \
, 0x00