https://github.com/akkartik/mu/blob/main/linux/306files.subx
1
2
3
4
5
6
7 == code
8
9 open:
10
11 55/push-ebp
12 89/<- %ebp 4/r32/esp
13
14 50/push-eax
15 51/push-ecx
16
17 (open-fd *(ebp+8) *(ebp+0xc))
18 89/<- %ecx 0/r32/eax
19
20 3d/compare-eax-with 0/imm32
21 7c/jump-if-< $open:end/disp8
22
23 (allocate Heap 0x1010 *(ebp+0x10))
24
25 8b/-> *(ebp+0x10) 0/r32/eax
26 (lookup *eax *(eax+4))
27
28 c7 0/subop/copy *(eax+0xc) 0x1000/imm32/file-buffer-size
29
30 89/<- *eax 1/r32/ecx
31 $open:end:
32
33 59/pop-to-ecx
34 58/pop-to-eax
35
36 89/<- %esp 5/r32/ebp
37 5d/pop-to-ebp
38 c3/return
39
40 open-fd:
41
42 55/push-ebp
43 89/<- %ebp 4/r32/esp
44
45 51/push-ecx
46 52/push-edx
47 53/push-ebx
48 56/push-esi
49
50 8b/-> *(ebp+8) 1/r32/ecx
51
52 8b/-> *ecx 2/r32/edx
53 42/increment-edx
54
55 29/subtract-from %esp 2/r32/edx
56 52/push-edx
57 68/push 0/imm32/read
58 68/push 0/imm32/write
59 89/<- %esi 4/r32/esp
60
61 (clear-stream %esi)
62 (write %esi %ecx)
63
64 52/push-edx
65
66 8d/copy-address *(esi+0xc) 3/r32/ebx
67 8b/-> *(ebp+0xc) 1/r32/ecx/flags
68 ba/copy-to-edx 0x180/imm32/permissions
69 e8/call syscall_open/disp32
70
71 5a/pop-to-edx
72 $open-fd:end:
73
74 01/add-to %esp 2/r32/edx
75 81 0/subop/add %esp 0xc/imm32
76
77 5e/pop-to-esi
78 5b/pop-to-ebx
79 5a/pop-to-edx
80 59/pop-to-ecx
81
82 89/<- %esp 5/r32/ebp
83 5d/pop-to-ebp
84 c3/return
85
86 populate-buffered-file-containing:
87
88 55/push-ebp
89 89/<- %ebp 4/r32/esp
90
91 50/push-eax
92 51/push-ecx
93 56/push-esi
94 57/push-edi
95
96 8b/-> *(ebp+8) 6/r32/esi
97
98 8b/-> *esi 1/r32/ecx
99
100 68/push 0/imm32
101 68/push 0/imm32
102 89/<- %edi 4/r32/esp
103
104 (new-stream Heap %ecx 1 %edi)
105
106 (lookup *edi *(edi+4))
107 89/<- %edi 0/r32/eax
108
109 (write %edi %esi)
110
111 (allocate Heap 0x110 *(ebp+0xc))
112
113 8b/-> *(ebp+0xc) 0/r32/eax
114 (lookup *eax *(eax+4))
115
116 c7 0/subop/copy *(eax+0xc) 0x100/imm32/file-buffer-size
117
118 89/<- *eax 7/r32/edi
119 $populate-buffered-file-containing:end:
120
121 81 0/subop/add %esp 8/imm32
122
123 5f/pop-to-edi
124 5e/pop-to-esi
125 59/pop-to-ecx
126 58/pop-to-eax
127
128 89/<- %esp 5/r32/ebp
129 5d/pop-to-ebp
130 c3/return
131
132
133 new-buffered-file:
134
135 55/push-ebp
136 89/<- %ebp 4/r32/esp
137
138 50/push-eax
139 51/push-ecx
140
141 68/push 0/imm32
142 68/push 0/imm32
143 89/<- %ecx 4/r32/esp
144
145 (new-stream Heap 0x100 1 %ecx)
146
147 (lookup *ecx *(ecx+4))
148 89/<- %ecx 0/r32/eax
149
150 (allocate Heap 0x110 *(ebp+8))
151
152 8b/-> *(ebp+8) 0/r32/eax
153 (lookup *eax *(eax+4))
154
155 c7 0/subop/copy *(eax+0xc) 0x100/imm32/file-buffer-size
156
157 89/<- *eax 1/r32/ecx
158 $new-buffered-file:end:
159
160 81 0/subop/add %esp 8/imm32
161
162 59/pop-to-ecx
163 58/pop-to-eax
164
165 89/<- %esp 5/r32/ebp
166 5d/pop-to-ebp
167 c3/return