-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_shell.asm
More file actions
99 lines (81 loc) · 1.42 KB
/
Copy pathbasic_shell.asm
File metadata and controls
99 lines (81 loc) · 1.42 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
global _start
section .text
_start:
print:
MOV eax, 0x1
MOV edi, 0x1
MOV esi, prompt
MOV edx, msglen
SYSCALL
read:
MOV eax, 0x0
MOV edi, 0x0
MOV esi, buffer
MOV edx, msgleni
SYSCALL
match:
lea rsi, cmd_exit
lea rdi, buffer
mov rcx, 4
compare:
repe cmpsb
je cmd_exit_handler
match1:
lea rsi, cmd_help
lea rdi, buffer
mov rcx, 4
compare1:
repe cmpsb
je cmd_help_handler
match2:
lea rsi, cmd_echo
lea rdi, buffer
mov rcx, 4
compare2:
repe cmpsb
je cmd_echo_handler
unknown_command:
mov eax, 1 ; sys_write
mov edi, 1 ; file descriptor (stdout)
mov rsi, msg
mov rdx, uk_len
syscall
jmp print
cmd_exit_handler:
mov eax, 0x3c
mov edi, 0x0
syscall
jmp print
cmd_help_handler:
mov eax, 0x1
mov edi, 0x1
mov rsi, help
mov rdx, helplen
syscall
jmp print
mov rsi, buffer
cmd_echo_handler:
lodsb
mov al,0
cmd_echo_handler_main:
mov eax, 0x1
mov edi, 0x1
mov rsi, rsi
mov rdx, bufferlen
syscall
jmp print
section .data
prompt: DB"shell> ", 0x0
msglen: equ $-prompt
help: DB"a smol program build by me. available commands are 1) echo 2) help 3) exit", 0xA
helplen: equ $ -help
msg: db"unknown command. use help",0xA
uk_len: equ $ - msg
cmd_exit: DB "exit\n", 0
cmd_help: DB "help\n", 0
cmd_echo: DB "echo\n", 0
cmd_ls: db"ls", 0
msgleni: equ 0x40
section .bss
buffer: resb 64
bufferlen: equ $ - buffer