Skip to content

Commit dd3bd7e

Browse files
authored
Add files via upload
1 parent e5b20a2 commit dd3bd7e

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed

ASM_x86/LinuxAPI_08_mkdir.asm

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
;Simple example of creating a directory with the mkdir API call. API calls found in this example program:
2+
; mkdir, exit
3+
; High level description of what theis example program does:
4+
; Create a new directroy called 'newdir' using the mkdir API call
5+
; exits gracefully with exit().
6+
7+
section .text
8+
global _start
9+
10+
_start:
11+
12+
; Create a new directroy called 'newdir' using the mkdir API call
13+
;------------------------------------------------------------------------------
14+
mov eax, 39 ;mkdir
15+
mov ebx, newdir ;pointer to the directory name
16+
mov ecx, 600o ;Read/Write for Owner
17+
int 0x80
18+
19+
20+
; Exit program
21+
;------------------------------------------------------------------------------
22+
mov eax, 1
23+
int 0x80
24+
25+
section .data
26+
newdir db 'newdir', 0x00
27+
28+
; ------------------------------
29+
; | Some bitfield explanations |
30+
; ------------------------------
31+
32+
; Mode Octal codes
33+
;------------------------------------------------------------------------------
34+
; Read 4
35+
; Write 2
36+
; Execute 1

ASM_x86/LinuxAPI_09_rmdir.asm

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
;Simple example of removing a directory with the rmdir API call. API calls found in this example program:
2+
; rmdir, exit
3+
; High level description of what theis example program does:
4+
; Attempts ot remove the directory 'newdir' if it exists, using the rmdir API
5+
; exits gracefully with exit().
6+
7+
section .text
8+
global _start
9+
10+
_start:
11+
12+
; Attempts ot remove the directory 'newdir' if it exists, using the rmdir API
13+
;------------------------------------------------------------------------------
14+
mov eax, 40 ;rmdir
15+
mov ebx, newdir ;pointer to the directory name
16+
int 0x80
17+
18+
19+
; Exit program
20+
;------------------------------------------------------------------------------
21+
mov eax, 1
22+
int 0x80
23+
24+
section .data
25+
newdir db 'newdir', 0x00
26+
27+
; ------------------------------
28+
; | Some bitfield explanations |
29+
; ------------------------------
30+
31+
; Mode Octal codes
32+
;------------------------------------------------------------------------------
33+
; Read 4
34+
; Write 2
35+
; Execute 1

ASM_x86/LinuxAPI_10_getdents.asm

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
;Example of reading the contents of a directory using the getdents API call. API calls found in this example program:
2+
; open, getdents, exit
3+
; High level description of what theis example program does:
4+
; Opens a directory in readonly mode for the file descriptor with open API
5+
; Reads data structure for directory and places in memory buffer with getdents API
6+
; Closes fd for directory with close API
7+
; exits gracefully with exit().
8+
9+
section .text
10+
global _start
11+
12+
_start:
13+
14+
; Open dir with open() call and a dir specified at 'dir' buffer
15+
;------------------------------------------------------------------------------
16+
mov eax, 5 ;open
17+
mov ebx, dir ;pointer to the directory
18+
xor ecx, ecx ;readonly
19+
xor edx, edx ;permissions not relevant
20+
int 0x80
21+
mov [filehandle], eax ;save filehandle
22+
23+
; Get directroy contents into dirbuffer memory location
24+
;------------------------------------------------------------------------------
25+
mov eax, 141 ;getdents
26+
mov ebx, [filehandle] ;pointer to the directory fd
27+
mov ecx, dirbuffer ;where we want the results
28+
mov edx, 300 ;size of buffer for results
29+
int 0x80
30+
31+
; Close the file with close().
32+
;------------------------------------------------------------------------------
33+
mov ebx, [filehandle] ;get filehandle return value
34+
mov eax, 6 ;close
35+
int 0x80
36+
37+
; Exit program
38+
;------------------------------------------------------------------------------
39+
mov eax, 1
40+
int 0x80
41+
42+
section .data
43+
dir db '.', 0x00
44+
45+
section .bss
46+
filehandle resb 4
47+
dirbuffer resb 300
48+
49+
; Seems simple right? Oh...you wanted something inteligible as far as the
50+
; directory listing results, and you wanted them printed out, not just a data
51+
; blob in a memory buffer? Aint nobody got time for that, below is some
52+
; documentation for the datastructure, parse it (with your brain) from memory
53+
; yourself. This is just a quick PoC for getdents, not a PoC for parsing a
54+
; complex data structure and displaying it to a human (that program would be
55+
; bigger).
56+
; ------------------------------
57+
; | Some bitfield explanations |
58+
; ------------------------------
59+
60+
; Data Structure for the directory results that show up in the provided buffer
61+
;------------------------------------------------------------------------------
62+
; struct linux_dirent {
63+
; unsigned long d_ino; /* Inode number */
64+
; unsigned long d_off; /* Offset to next linux_dirent */
65+
; unsigned short d_reclen; /* Length of this linux_dirent */
66+
; char d_name[]; /* Filename (null-terminated) */
67+
; /* length is actually (d_reclen - 2 -
68+
; offsetof(struct linux_dirent, d_name)) */
69+
; /*
70+
; char pad; // Zero padding byte
71+
; char d_type; // File type (only since Linux
72+
; // 2.6.4); offset is (d_reclen - 1)
73+
;
74+
; }

0 commit comments

Comments
 (0)