-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_usb.asm
More file actions
73 lines (60 loc) · 2.5 KB
/
Copy pathlist_usb.asm
File metadata and controls
73 lines (60 loc) · 2.5 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
section .data
usb_dir db "/sys/bus/usb/devices/", 0 ; USB devices directory path
buf db 256 ; Buffer to hold file names
newline db 10 ; Newline character for printing
section .bss
fd resd 1 ; File descriptor for the directory
section .text
global _start
_start:
; Open the directory /sys/bus/usb/devices/
mov eax, 5 ; syscall: open
mov ebx, usb_dir ; directory path
mov ecx, 0 ; O_RDONLY
int 0x80 ; syscall interrupt
mov [fd], eax ; store file descriptor
; Check if directory opened successfully
cmp eax, 0
js error_exit ; exit if error occurred
read_directory:
; Read directory entries
mov eax, 141 ; syscall: getdents
mov ebx, [fd] ; file descriptor
mov ecx, buf ; buffer for directory entries
mov edx, 256 ; size of buffer
int 0x80 ; syscall interrupt
; Check if there are no more entries
cmp eax, 0
jle close_and_exit ; exit if done reading
; Display each entry in the buffer
mov esi, buf ; pointer to buffer
add esi, eax ; calculate end of buffer
next_entry:
; Find and print the entry name (assuming USB devices)
mov eax, 4 ; syscall: write
mov ebx, 1 ; stdout
mov ecx, buf ; buffer (entry name)
mov edx, eax ; size
int 0x80 ; syscall interrupt
; Print newline after each entry
mov eax, 4
mov ebx, 1
mov ecx, newline
mov edx, 1
int 0x80
; Move to the next entry
jmp next_entry
close_and_exit:
; Close directory
mov eax, 6 ; syscall: close
mov ebx, [fd] ; file descriptor
int 0x80
; Exit program
mov eax, 1 ; syscall: exit
xor ebx, ebx ; exit code 0
int 0x80
error_exit:
; Exit with error code
mov eax, 1 ; syscall: exit
mov ebx, 1 ; exit code 1
int 0x80