-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathMemory.java
More file actions
354 lines (316 loc) · 13.1 KB
/
Memory.java
File metadata and controls
354 lines (316 loc) · 13.1 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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
package org.python.modules.jffi;
/**
* Abstracted memory operations.
* <p>
* This abstracts read/write operations to either a native memory area, or a java
* ByteBuffer.
* </p>
*/
public interface Memory {
/**
* Checks if the memory area is NULL.
*
* @return <tt>true</tt> if the memory area is invalid.
*/
public boolean isNull();
/**
* Checks if the memory area is a native memory pointer.
*
* @return <tt>true</tt> if the memory area is a native pointer.
*/
public boolean isDirect();
/**
* Creates a new MemoryIO pointing to a subset of the memory area of this
* <tt>MemoryIO</tt>.
* @param offset The offset within the existing memory area to start the
* new <tt>MemoryIO</tt> at.
* @return A <tt>MemoryIO</tt> instance.
*/
public Memory slice(long offset);
/**
* Reads an 8 bit integer value from the memory area.
*
* @param offset The offset within the memory area to read the value.
* @return The 8 bit integer value read from <tt>offset</tt>
*/
public byte getByte(long offset);
/**
* Reads a 16 bit integer value from the memory area.
*
* @param offset The offset within the memory area to read the value.
* @return The 16 bit integer value read from <tt>offset</tt>
*/
public short getShort(long offset);
/**
* Reads a 32 bit integer value from the memory area.
*
* @param offset The offset within the memory area to read the value.
* @return The 32 bit integer value read from <tt>offset</tt>
*/
public int getInt(long offset);
/**
* Reads a 64 bit integer value from the memory area.
*
* @param offset The offset within the memory area to read the value.
* @return The 64 bit integer value read from <tt>offset</tt>
*/
public long getLong(long offset);
/**
* Reads a native long integer value from the memory area.
* <p>
* A native long is 32bits on either ILP32 or LLP64 architectures, and
* 64 bits on an LP64 architecture.
* </p>
* <p>
* This means that it will always read a 32bit value on Windows, but on
* Unix systems such as MacOS or Linux, it will read a 32bit value on 32bit
* systems, and a 64bit value on 64bit systems.
*
* @param offset The offset within the memory area to read the value.
* @return The native long value read from <tt>offset</tt>
*/
public long getNativeLong(long offset);
/**
* Reads a float value from the memory area.
*
* @param offset The offset within the memory area to read the value.
* @return The float value read from <tt>offset</tt>
*/
public float getFloat(long offset);
/**
* Reads a double value from the memory area.
*
* @param offset The offset within the memory area to read the value.
* @return The double value read from <tt>offset</tt>
*/
public double getDouble(long offset);
/**
* Reads a pointer value at the specified offset within the memory area.
*
* @param offset The offset within the memory area to read the value.
* @return A <tt>long</tt> value that represents the address.
*/
public long getAddress(long offset);
/**
* Reads a pointer value at the specified offset within the memory area, and
* wraps it in an abstract memory accessor.
*
* @param offset The offset within the memory area to read the value.
* @return A <tt>DirectMemory</tt> accessor that can be used to access the memory
* pointed to by the address.
*/
public DirectMemory getMemory(long offset);
/**
* Reads a zero terminated byte array (e.g. an ascii or utf-8 string)
*
* @param offset The offset within the memory area of the start of the string.
* @return A byte array containing a copy of the data.
*/
public byte[] getZeroTerminatedByteArray(long offset);
/**
* Writes an 8 bit integer value to the memory area at the specified offset.
*
* @param offset The offset within the memory area to write the value.
* @param value The 8 bit integer value to write to the memory location.
*/
public void putByte(long offset, byte value);
/**
* Writes a 16 bit integer value to the memory area at the specified offset.
*
* @param offset The offset within the memory area to write the value.
* @param value The 16 bit integer value to write to the memory location.
*/
public void putShort(long offset, short value);
/**
* Writes a 32 bit integer value to the memory area at the specified offset.
*
* @param offset The offset within the memory area to write the value.
* @param value The 32 bit integer value to write to the memory location.
*/
public void putInt(long offset, int value);
/**
* Writes a 64 bit integer value to the memory area at the specified offset.
*
* @param offset The offset within the memory area to write the value.
* @param value The 64 bit integer value to write to the memory location.
*/
public void putLong(long offset, long value);
/**
* Writes a native long integer value to the memory area at the specified offset.
*
* @param offset The offset within the memory area to write the value.
* @param value The native long integer value to write to the memory location.
*/
public void putNativeLong(long offset, long value);
/**
* Writes a 32 bit float value to the memory area at the specified offset.
*
* @param offset The offset within the memory area to write the value.
* @param value The 32 bit float value to write to the memory location.
*/
public void putFloat(long offset, float value);
/**
* Writes a 64 bit float value to the memory area at the specified offset.
*
* @param offset The offset within the memory area to write the value.
* @param value The 64 bit float value to write to the memory location.
*/
public void putDouble(long offset, double value);
/**
* Writes a pointer value to the memory area at the specified offset.
*
* @param offset The offset within the memory area to write the value.
* @param value The pointer value to write to the memory location.
*/
public void putAddress(long offset, Memory value);
/**
* Writes a pointer value to the memory area at the specified offset.
*
* @param offset The offset within the memory area to write the value.
* @param value The pointer value to write to the memory location.
*/
public void putAddress(long offset, long value);
/**
* Writes a byte array to memory, and appends a zero terminator
*
* @param offset The offset within the memory area of the start of the string.
* @param bytes The byte array to write to the memory.
* @param off The offset with the byte array to start copying.
* @param len The number of bytes of the byte array to write to the memory area. (not including zero byte)
*/
public void putZeroTerminatedByteArray(long offset, byte[] bytes, int off, int len);
/**
* Reads an array of bytes from the memory area at the specified offset.
*
* @param offset The offset within the memory area to read the bytes.
* @param dst The output byte array to place the data.
* @param off The offset within the byte array to start copying.
* @param len The length of data to read.
*/
public void get(long offset, byte[] dst, int off, int len);
/**
* Writes an array of bytes to the memory area at the specified offset.
*
* @param offset The offset within the memory area to start writing the bytes.
* @param src The byte array to write to the memory area.
* @param off The offset within the byte array to start copying.
* @param len The length of data to write.
*/
public void put(long offset, byte[] src, int off, int len);
/**
* Reads an array of shorts from the memory area at the specified offset.
*
* @param offset The offset within the memory area to read the shorts.
* @param dst The output array to place the data in.
* @param off The offset within the array to start copying.
* @param len The number of shorts to read.
*/
public void get(long offset, short[] dst, int off, int len);
/**
* Writes an array of shorts to the memory area at the specified offset.
*
* @param offset The offset within the memory area to start writing the shorts.
* @param src The array to write to the memory area.
* @param off The offset within the array to start copying.
* @param len The number of shorts to write.
*/
public void put(long offset, short[] src, int off, int len);
/**
* Reads an array of ints from the memory area at the specified offset.
*
* @param offset The offset within the memory area to read the ints.
* @param dst The output array to place the data in.
* @param off The offset within the array to start copying.
* @param len The number of ints to read.
*/
public void get(long offset, int[] dst, int off, int len);
/**
* Writes an array of ints to the memory area at the specified offset.
*
* @param offset The offset within the memory area to start writing the ints.
* @param src The array to write to the memory area.
* @param off The offset within the array to start copying.
* @param len The number of ints to write.
*/
public void put(long offset, int[] src, int off, int len);
/**
* Reads an array of longs from the memory area at the specified offset.
*
* @param offset The offset within the memory area to read the longs.
* @param dst The output array to place the data in.
* @param off The offset within the array to start copying.
* @param len The number of longs to read.
*/
public void get(long offset, long[] dst, int off, int len);
/**
* Writes an array of longs to the memory area at the specified offset.
*
* @param offset The offset within the memory area to start writing the longs.
* @param src The array to write to the memory area.
* @param off The offset within the array to start copying.
* @param len The number of longs to write.
*/
public void put(long offset, long[] src, int off, int len);
/**
* Reads an array of floats from the memory area at the specified offset.
*
* @param offset The offset within the memory area to read the floats.
* @param dst The output array to place the data in.
* @param off The offset within the array to start copying.
* @param len The number of floats to read.
*/
public void get(long offset, float[] dst, int off, int len);
/**
* Writes an array of floats to the memory area at the specified offset.
*
* @param offset The offset within the memory area to start writing the floats.
* @param src The array to write to the memory area.
* @param off The offset within the array to start copying.
* @param len The number of floats to write.
*/
public void put(long offset, float[] src, int off, int len);
/**
* Reads an array of doubles from the memory area at the specified offset.
*
* @param offset The offset within the memory area to read the doubles.
* @param dst The output array to place the data in.
* @param off The offset within the array to start copying.
* @param len The number of doubles to read.
*/
public void get(long offset, double[] dst, int off, int len);
/**
* Writes an array of doubles to the memory area at the specified offset.
*
* @param offset The offset within the memory area to start writing the doubles.
* @param src The array to write to the memory area.
* @param off The offset within the array to start copying.
* @param len The number of doubles to write.
*/
public void put(long offset, double[] src, int off, int len);
/**
* Gets the first index within the memory area of a particular 8 bit value.
*
* @param offset The offset within the memory area to start searching.
* @param value The value to search for.
*
* @return The index of the value, relative to offset.
*/
public int indexOf(long offset, byte value);
/**
* Gets the first index within the memory area of a particular 8 bit value.
*
* @param offset The offset within the memory area to start searching.
* @param value The value to search for.
*
* @return The index of the value, relative to offset.
*/
public int indexOf(long offset, byte value, int maxlen);
/**
* Sets the contents of the memory area to the value.
*
* @param offset The offset within the memory area to start writing.
* @param size The number of bytes to set to the value.
* @param value The value to set each byte to.
*/
public void setMemory(long offset, long size, byte value);
}