fast_byte_array_project.maml.html
35.9 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
p { text-align: justify; width: 600px; }
.dropdown { position: relative;
display: inline-block; }
.drp-content { display: none;
position: fixed;
bottom: 10px;
right: 10px;
background-color: #ffcc00;
max-width: 500px;
box-shadow: 0px 16px 16px 0px rgba(0,0,0,0.6);
padding: 0px 6px;
z-index: 0; }
.dropdown:hover .drp-content { display: block;
z-index: 2; }
</style>
</head><body><center><table style="width: 600px; font-size:12px;"><tr><td><div style="text-align: justify; text-justify: inter-word; width: 600px; line-height: 17px; ">
<br><br> <div style="text-align: center; color: inherit; font-size: inherit;"><span style="font-size: 120%;"><span style="font-size: 120%;"><span style="font-size: 120%;"><strong>Fast mutations of byte arrays</strong></span></span></span></div> <br><br> <div style="text-align: center; color: inherit; font-size: inherit;"><em>Alain Prouté</em></div><br><br> This is a project for <span style="font-style: normal;"><strong><span style="display: inline; color: rgb(110,000,000)">Anubis</span></strong></span>. There is a need to mutate byte arrays
in an efficient way. <br><br>
<a id="sec1"></a><div align="center"> </div><span style="font-size: 120%;"><span style="font-size: 120%;"><strong>1. Description</strong></span></span><div align="center"> </div>
We describe a kind of compiler that transforms a character string representing a function (of a particular kind) into
a compiled program that can be applied to all <em><span style="display: inline; color: rgb(160,032,240)">blocks</span></em> (of some given size) of a byte array.
<pre style="color: inherit; font-size: inherit; background-color: rgb(240,235,225); width: inherit;"><span style="display: inline; color: rgb(0,100,0)"> </span>
<strong><span style="display: inline; color: rgb(200,0,120)">public</span></strong> <strong><span style="display: inline; color: rgb(200,0,120)">define</span></strong> <strong><span style="display: inline; color: rgb(0,100,180)">ByteArray</span></strong> -> <strong><span style="display: inline; color: rgb(0,100,180)">ByteArray</span></strong>
<span style="display: inline; color: rgb(180,0,0)">fast_mutate</span>
(
<strong><span style="display: inline; color: rgb(0,100,180)">String</span></strong> <span style="display: inline; color: rgb(180,0,0)">function</span>
).<span style="display: inline; color: rgb(0,100,0)"> </span>
<span style="display: inline; color: rgb(0,100,0)"> </span></pre>
The <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">function</span></span></span> is written into a character string and must use the syntax described below.
This function is <em><span style="display: inline; color: rgb(160,032,240)">compiled</span></em> into a <em><span style="display: inline; color: rgb(160,032,240)">program</span></em> that is applied to a given byte array. This
makes a side effect in the sens that the returned byte array is the same one as the original one,
but mutated. <br><br> As an example,
<pre style="color: inherit; font-size: inherit; background-color: rgb(240,235,225); width: inherit;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;">
<span style="display: inline; color: rgb(120,70,200)"><em>with</em></span> <span style="display: inline; color: rgb(180,0,0)">a</span> = (<strong><span style="display: inline; color: rgb(0,100,180)">Word32</span></strong>)0<span style="display: inline; color: rgb(180,0,0)">x5a43d6f2</span>,
<span style="display: inline; color: rgb(180,0,0)">fast_mutate</span>(<span style="display: inline; color: rgb(175,130,0)"><strong>"</strong></span><span style="display: inline; color: rgb(175,130,0)"><strong>(Word32 w) |-> w := a</strong></span><span style="display: inline; color: rgb(175,130,0)"><strong>"</strong></span>)(<span style="display: inline; color: rgb(180,0,0)">ba</span>)
</span></span></pre>
will consider the byte array argument <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">ba</span></span></span> as a sequence of blocks of 32 bits, and <span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;">XOR</span> each of them with
<span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">a</span></span></span> (that is supposed to be of type <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><strong><span style="display: inline; color: rgb(0,100,180)">Word32</span></strong></span></span> and visible in the current local context). This will be executed
within a single instruction of the <span style="font-style: normal;"><strong><span style="display: inline; color: rgb(110,000,000)">Anubis</span></strong></span> virtual machine. There will be no memory allocation for a byte array
because the original byte array itself is mutated (and returned). If the number of bytes in the byte array is not a
multiple of the number of bytes in a block, the last bytes will not be treated. Consequently, this function should
better be used with byte arrays whose size is a multiple of the size of the words under consideration. If needed, the
user should pad the byte array with additional bytes. <br><br>
<a id="sec2"></a><div align="center"> </div><span style="font-size: 120%;"><span style="font-size: 120%;"><strong>2. The language</strong></span></span><div align="center"> </div>
We describe the language that must be used for writing the function in the character string.
If there is a syntax error, the function is just not applied (i.e. the byte array is not
mutated), and a <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><strong><span style="display: inline; color: rgb(255,000,000)">should_not_happen</span></strong></span></span> is triggered. <br><br> The function must have the following form:
<pre style="color: inherit; font-size: inherit; background-color: rgb(240,235,225); width: inherit;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;">
(<span style="display: inline; color: rgb(0,80,0)"><strong><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><type></span></strong></span> <span style="display: inline; color: rgb(180,0,0)">w</span>) |-> <span style="display: inline; color: rgb(0,80,0)"><strong><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><body></span></strong></span>
</span></span></pre>
where <span style="display: inline; color: rgb(0,80,0)"><strong><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><type></span></strong></span> can be one of <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><strong><span style="display: inline; color: rgb(0,100,180)">Word8</span></strong></span></span>, <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><strong><span style="display: inline; color: rgb(0,100,180)">Word16</span></strong></span></span>, <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><strong><span style="display: inline; color: rgb(0,100,180)">Word32</span></strong></span></span>, <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><strong><span style="display: inline; color: rgb(0,100,180)">Word64</span></strong></span></span> or <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><strong><span style="display: inline; color: rgb(0,100,180)">Word128</span></strong></span></span>. This type
determines the sizes of the blocks to be treated. What the compiled program will do is to apply the function to all
successive blocks in the byte array from left to right. We used the symbol <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">w</span></span></span> above for the name of the argument
of the function, but this name can be freely chosen (with some exceptions). We keep the name <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">w</span></span></span> in these
explanations. <br><br> <a id="subsec2_1"></a><span style="font-size: 120%;"><strong>2.1. Values</strong></span><div align="center"> </div>
The expressions described here represent <em><span style="display: inline; color: rgb(160,032,240)">values</span></em> whose type is the type of <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">w</span></span></span>. <br><br> <div align="left" style="display: inline-block; width: 120px;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">w</span></span></span></div> the value of the current block<br />
<div align="left" style="display: inline-block; width: 120px;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;">.<span style="display: inline; color: rgb(180,0,0)">w</span>[<span style="display: inline; color: rgb(180,0,0)">a</span>]</span></span></div> the value of the previous block or the value <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">a</span></span></span> if there is no previous block<br />
<div align="left" style="display: inline-block; width: 120px;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">w</span>.[<span style="display: inline; color: rgb(180,0,0)">a</span>]</span></span></div> the value of the next block or the value <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">a</span></span></span> if there is no next block<br />
<br />
The dot operator can be iterated. For example, the notation <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;">..<span style="display: inline; color: rgb(180,0,0)">w</span>[<span style="display: inline; color: rgb(180,0,0)">a</span>]</span></span> represents the value of the block that is
before the previous block (or <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">a</span></span></span> if this block does not exist). <br><br> Any <span style="font-style: normal;"><strong><span style="display: inline; color: rgb(110,000,000)">Anubis</span></strong></span> symbol representing a datum of the same type as <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">w</span></span></span> and that is present in the local context
<span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">fast_mutate</span></span></span> is within, represents the value of this local symbol. <br><br> The symbol <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">rand</span></span></span> represents a random value (hence, cannot be used instead of <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">w</span></span></span>). <br><br> The following expressions also represent values: <br><br> <div align="left" style="display: inline-block; width: 120px;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">a</span>+<span style="display: inline; color: rgb(180,0,0)">b</span></span></span></div> sum of two values<br />
<div align="left" style="display: inline-block; width: 120px;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">a</span>-<span style="display: inline; color: rgb(180,0,0)">b</span></span></span></div> difference of two values<br />
<div align="left" style="display: inline-block; width: 120px;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;">-<span style="display: inline; color: rgb(180,0,0)">a</span></span></span></div> opposite of a value<br />
<div align="left" style="display: inline-block; width: 120px;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">a</span>&<span style="display: inline; color: rgb(180,0,0)">b</span></span></span></div> bitwise AND<br />
<div align="left" style="display: inline-block; width: 120px;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">a</span>|<span style="display: inline; color: rgb(180,0,0)">b</span></span></span></div> bitwise OR<br />
<div align="left" style="display: inline-block; width: 120px;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">a</span>:<span style="display: inline; color: rgb(180,0,0)">b</span></span></span></div> bitwise XOR<br />
<div align="left" style="display: inline-block; width: 120px;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;">~<span style="display: inline; color: rgb(180,0,0)">a</span></span></span></div> bitwise complement<br />
<br />
In the following expressions, <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">n</span></span></span> must be a decimal notation. <br><br> <div align="left" style="display: inline-block; width: 120px;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">a</span><<<span style="display: inline; color: rgb(180,0,0)">n</span></span></span></div> left shift of <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">n</span></span></span> bits<br />
<div align="left" style="display: inline-block; width: 120px;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">a</span>>><span style="display: inline; color: rgb(180,0,0)">n</span></span></span></div> right shift of <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">n</span></span></span> bits<br /><br><br> <a id="subsec2_2"></a><span style="font-size: 120%;"><strong>2.2. Commands</strong></span><div align="center"> </div>
In order to mutate the current block, one can use the following commands:<br><br> <div align="left" style="display: inline-block; width: 120px;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">w</span> <- <span style="display: inline; color: rgb(180,0,0)">a</span></span></span></div> set the block to value <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">a</span></span></span><br />
<div align="left" style="display: inline-block; width: 120px;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">w</span> |= <span style="display: inline; color: rgb(180,0,0)">a</span></span></span></div> bitwise OR the block with <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">a</span></span></span><br />
<div align="left" style="display: inline-block; width: 120px;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">w</span> := <span style="display: inline; color: rgb(180,0,0)">a</span></span></span></div> bitwise XOR the block with <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">a</span></span></span><br />
<div align="left" style="display: inline-block; width: 120px;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">w</span> &= <span style="display: inline; color: rgb(180,0,0)">a</span></span></span></div> bitwise AND the block with <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">a</span></span></span><br />
<div align="left" style="display: inline-block; width: 120px;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">w</span> += <span style="display: inline; color: rgb(180,0,0)">a</span></span></span></div> add <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">a</span></span></span> to the block<br />
<div align="left" style="display: inline-block; width: 120px;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">w</span> -= <span style="display: inline; color: rgb(180,0,0)">a</span></span></span></div> substract <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">a</span></span></span> from the block<br />
<br />
In the following expressions, <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">n</span></span></span> must be a decimal notation. <br><br> <div align="left" style="display: inline-block; width: 120px;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">w</span> <<= <span style="display: inline; color: rgb(180,0,0)">n</span></span></span></div> shift the block <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">n</span></span></span> bits to the left<br />
<div align="left" style="display: inline-block; width: 120px;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">w</span> >>= <span style="display: inline; color: rgb(180,0,0)">n</span></span></span></div> shift the block <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">n</span></span></span> bits to the right<br />
<br />
If several commands must be executed on the current block, they must be separated by semi-colons. For example:
<span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">w</span> << 3; <span style="display: inline; color: rgb(180,0,0)">w</span> |= <span style="display: inline; color: rgb(180,0,0)">a</span></span></span>. <br><br>
<a id="sec3"></a><div align="center"> </div><span style="font-size: 120%;"><span style="font-size: 120%;"><strong>3. Examples</strong></span></span><div align="center"> </div>
Filling the byte array with zeros:
<pre style="color: inherit; font-size: inherit; background-color: rgb(240,235,225); width: inherit;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;">
(<strong><span style="display: inline; color: rgb(0,100,180)">Word8</span></strong> <span style="display: inline; color: rgb(180,0,0)">w</span>) |-> <span style="display: inline; color: rgb(180,0,0)">w</span> <- 0
</span></span></pre>
Filling the byte array with 32 bits words whose values are successive integers:
<pre style="color: inherit; font-size: inherit; background-color: rgb(240,235,225); width: inherit;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;">
(<strong><span style="display: inline; color: rgb(0,100,180)">Word32</span></strong> <span style="display: inline; color: rgb(180,0,0)">w</span>) |-> <span style="display: inline; color: rgb(180,0,0)">w</span> <- .<span style="display: inline; color: rgb(180,0,0)">w</span>[0] + 1
</span></span></pre>
Filling the byte array with random values
<pre style="color: inherit; font-size: inherit; background-color: rgb(240,235,225); width: inherit;"><span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;">
(<strong><span style="display: inline; color: rgb(0,100,180)">Word32</span></strong> <span style="display: inline; color: rgb(180,0,0)">w</span>) |-> <span style="display: inline; color: rgb(180,0,0)">w</span> <- <span style="display: inline; color: rgb(180,0,0)">rand</span>
</span></span></pre><br><br>
<a id="sec4"></a><div align="center"> </div><span style="font-size: 120%;"><span style="font-size: 120%;"><strong>4. Implementation</strong></span></span><div align="center"> </div>
I did not implement the above. Here are some guidelines. <br><br> Most of the source should be written in <span style="font-style: normal;"><strong><span style="display: inline; color: rgb(110,000,000)">Anubis</span></strong></span>. <span style="font-style: normal;"><strong><span style="display: inline; color: rgb(100,100,0)">A</span><span style="display: inline; color: rgb(0,100,100)">P</span><span style="display: inline; color: rgb(100,0,100)">G</span><span style="display: inline; color: rgb(0,0,220)"><sub>2</sub></span></strong></span> should be used for creating the parser for the above grammar.
The <span style="display: inline; color: rgb(0,80,0)"><strong><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><body></span></strong></span> of the function must be translated into a sequence of <em><span style="display: inline; color: rgb(160,032,240)">instructions</span></em>. The precise set of
instructions together with their format and coding is still to be designed. The resulting <em><span style="display: inline; color: rgb(160,032,240)">program</span></em> must be
written into a byte array. <br><br> The function <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">fast_mutate</span></span></span> is of course not a primitive, since it calls the parser generated by <span style="font-style: normal;"><strong><span style="display: inline; color: rgb(100,100,0)">A</span><span style="display: inline; color: rgb(0,100,100)">P</span><span style="display: inline; color: rgb(100,0,100)">G</span><span style="display: inline; color: rgb(0,0,220)"><sub>2</sub></span></strong></span>. It can
create an <em><span style="display: inline; color: rgb(160,032,240)">iterator</span></em>, i.e. a datum whose type looks like this:
<pre style="color: inherit; font-size: inherit; background-color: rgb(240,235,225); width: inherit;"><span style="display: inline; color: rgb(0,100,0)"> </span>
<strong><span style="display: inline; color: rgb(200,0,120)">type</span></strong> +++<strong><span style="display: inline; color: rgb(0,100,180)">ByteArrayIterator</span></strong>:
<span style="display: inline; color: rgb(180,0,0)">bai</span> (
<strong><span style="display: inline; color: rgb(0,100,180)">ByteArray</span></strong> <span style="display: inline; color: rgb(180,0,0)">program</span>,
<strong><span style="display: inline; color: rgb(0,100,180)">ByteArray</span></strong> <span style="display: inline; color: rgb(180,0,0)">microcontext</span>
).
<span style="display: inline; color: rgb(0,100,0)"> </span></pre>
where <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">program</span></span></span> is the program for executing a single step of iteration, and where <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">microcontext</span></span></span> is an array
containing the values of the local variables that are used within <span style="display: inline; color: rgb(0,80,0)"><strong><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><body></span></strong></span>. <br><br> Of course, the type <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;">+++<strong><span style="display: inline; color: rgb(0,100,180)">ByteArrayIterator</span></strong></span></span> is serializable. <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">fast_mutate</span></span></span> should serialize it and save it
into a file, for example in the directory <span style="display: inline; color: rgb(0,100,0)"><strong><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;">~/my_anubis/byte_array_iterators/</span></strong></span>, with name the <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">sha1</span></span></span> hash of
the function string. Actually, <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">fast_mutate</span></span></span> can just not do anything (except hashing its argument) if the file
already exists. This (precompiled) datum can be recovered at any time for being used on a byte array.
<span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">fast_mutate</span></span></span> returns a function of type <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><strong><span style="display: inline; color: rgb(0,100,180)">ByteArray</span></strong> -> <strong><span style="display: inline; color: rgb(0,100,180)">ByteArray</span></strong></span></span> using the iterator. <br><br> A primitive <em><span style="display: inline; color: rgb(160,032,240)">syscall</span></em> must be created that takes an iterator and a byte array as operands, and applies this
iterator to the byte array. This syscall must implement a <strong>C</strong> loop that <em><span style="display: inline; color: rgb(160,032,240)">execute</span></em> the <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">program</span></span></span> on each
block of the byte array. Actually, we need one syscall for each block size: <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">do_fast_mutate_8</span></span></span>,
<span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">do_fast_mutate_16</span></span></span>, etc. <br><br>
<a id="sec5"></a><div align="center"> </div><span style="font-size: 120%;"><span style="font-size: 120%;"><strong>5. Possible enhancements</strong></span></span><div align="center"> </div>
This project can be enhanced in several directions. <br><br> A feature such as <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(120,70,200)"><em>if</em></span> ... <span style="display: inline; color: rgb(120,70,200)"><em>then</em></span> ... <span style="display: inline; color: rgb(120,70,200)"><em>else</em></span> ...</span></span> that can produce either values or commands could be useful.<br><br> It can be interesting not only to mutate the byte array, but to compute something from it. This something can be an
array of <em><span style="display: inline; color: rgb(160,032,240)">values</span></em>. To this end, these <em><span style="display: inline; color: rgb(160,032,240)">output</span></em> values should have names and these names could
replace <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">w</span></span></span> in the above commands. Of course, the return type of the function created by <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">fast_mutate</span></span></span> must
be different. For example, it could be <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;">(<strong><span style="display: inline; color: rgb(0,100,180)">ByteArray</span></strong>,(<strong><span style="display: inline; color: rgb(0,100,180)">Word32</span></strong>,<strong><span style="display: inline; color: rgb(0,100,180)">Word32</span></strong>))</span></span> if we use two output variables. <br><br> For example, <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><span style="display: inline; color: rgb(180,0,0)">fast_mutate</span></span></span> could be declared like this:
<pre style="color: inherit; font-size: inherit; background-color: rgb(240,235,225); width: inherit;"><span style="display: inline; color: rgb(0,100,0)"> </span>
<strong><span style="display: inline; color: rgb(200,0,120)">public</span></strong> <strong><span style="display: inline; color: rgb(200,0,120)">define</span></strong> <strong><span style="display: inline; color: rgb(0,100,180)">ByteArray</span></strong> -> <strong><span style="display: inline; color: rgb(0,100,180)">ByteArray</span></strong> <span style="display: inline; color: rgb(180,0,0)">fast_mutate</span> (<strong><span style="display: inline; color: rgb(0,100,180)">String</span></strong> <span style="display: inline; color: rgb(180,0,0)">function</span>)<span style="display: inline; color: rgb(0,100,0)">.</span><span style="display: inline; color: rgb(0,100,0)"> </span>
<strong><span style="display: inline; color: rgb(200,0,120)">public</span></strong> <strong><span style="display: inline; color: rgb(200,0,120)">define</span></strong> <strong><span style="display: inline; color: rgb(0,100,180)">ByteArray</span></strong> -> (<strong><span style="display: inline; color: rgb(0,100,180)">ByteArray</span></strong>,<strong><span style="display: inline; color: rgb(150,70,0)">$Out</span></strong>) <span style="display: inline; color: rgb(180,0,0)">fast_mutate</span> (<strong><span style="display: inline; color: rgb(0,100,180)">String</span></strong> <span style="display: inline; color: rgb(180,0,0)">function</span>).<span style="display: inline; color: rgb(0,100,0)"> </span>
<span style="display: inline; color: rgb(0,100,0)"> </span></pre>
where of course, <span style="font-style: normal;"><span style="font-family:'Lucida Console', monospace; font-size:inherit; font-style: normal;"><strong><span style="display: inline; color: rgb(150,70,0)">$Out</span></strong></span></span> must be an anonymous product of the same kind of word type. <br><br> <div align="center"> </div><div align="center"> </div><div align="center"> </div><div align="center"> </div>
</div></td></tr></table></center></body></html>