This repository has been archived by the owner on Sep 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
sys.asm
187 lines (157 loc) · 2.27 KB
/
sys.asm
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
format ELF64
public fcreate
public fdelete
public fopen
public fclose
public fwrite
public fread
public fseek
public time
public exit
section '.fcreate' executable
; | input:
; rax = filename
; rbx = permissions
; | output:
; rax = descriptor
fcreate:
push rbx
push rcx
mov rcx, rbx
mov rbx, rax
mov rax, 8 ; creat
int 0x80
pop rcx
pop rbx
ret
section '.fdelete' executable
; | input:
; rax = filename
fdelete:
push rax
push rbx
mov rbx, rax
mov rax, 10 ; unlink
int 0x80
pop rbx
pop rax
ret
section '.fopen' executable
; | input:
; rax = filename
; rbx = mode
; ; O_RDONLY = 0
; ; O_WRONLY = 1
; ; O_RDWR = 2
; | output:
; rax = descriptor
fopen:
push rbx
push rcx
mov rcx, rbx
mov rbx, rax
mov rax, 5 ; open
int 0x80
pop rcx
pop rbx
ret
section '.fclose' executable
; | input:
; rax = descriptor
fclose:
push rbx
mov rbx, rax
mov rax, 6 ; close
int 0x80
pop rbx
ret
section '.fwrite' executable
; | input:
; rax = descriptor
; rbx = data
; rcx = data size
fwrite:
push rax
push rbx
push rcx
push rdx
push rbx
push rcx
mov rbx, 1
xor rcx, rcx
call fseek
pop rcx
pop rbx
mov rdx, rcx
mov rcx, rbx
mov rbx, rax
mov rax, 4 ; write
int 0x80
pop rdx
pop rcx
pop rbx
pop rax
ret
section '.fread' executable
; | input:
; rax = descriptor
; rbx = buffer
; rcx = buffer size
fread:
push rax
push rbx
push rcx
push rdx
push rbx
push rcx
mov rbx, 1
xor rcx, rcx
call fseek
pop rcx
pop rbx
mov rdx, rcx
mov rcx, rbx
mov rbx, rax
mov rax, 3 ; read
int 0x80
pop rdx
pop rcx
pop rbx
pop rax
ret
section '.fseek' executable
; | input:
; rax = descriptor
; rbx = mode seek
; ; SEEK_SET = 0
; ; SEEK_CUR = 1
; ; SEEK_END = 2
; rcx = position
fseek:
push rax
push rbx
push rdx
mov rdx, rbx
; rcx
mov rbx, rax
mov rax, 19 ; seek
int 0x80
pop rdx
pop rbx
pop rax
ret
section '.time' executable
; | ouput:
; rax = number
time:
push rbx
mov rax, 13
xor rbx, rbx
int 0x80
pop rbx
ret
section '.exit' executable
exit:
mov rax, 1
mov rbx, 0
int 0x80