ReXGlue SDK
Loading...
Searching...
No Matches
io.h
Go to the documentation of this file.
1
12
13#pragma once
14
15#include <string>
16#include <string_view>
17
18#include <rex/assert.h>
19#include <rex/memory.h>
23#include <rex/string/text.h>
24#include <rex/kernel/heap.h>
25
26namespace rex::kernel {
27
28#pragma pack(push, 4)
29
35 kXFileAttributeNone = 0x0000,
36 kXFileAttributeReadOnly = 0x0001,
37 kXFileAttributeHidden = 0x0002,
38 kXFileAttributeSystem = 0x0004,
39 kXFileAttributeDirectory = 0x0010,
40 kXFileAttributeArchive = 0x0020,
43 kXFileAttributeTemporary = 0x0100,
44 kXFileAttributeCompressed = 0x0800,
45 kXFileAttributeEncrypted = 0x4000,
46};
47
50 be_u32 result;
51 be_u32 length;
52 be_u32 context;
53 be_u32 event;
55 be_u32 completion_context;
56 be_u32 extended_error;
57};
58
59REX_STATIC_ASSERT_SIZE(XOVERLAPPED, 0x1C);
60
66inline void XOverlappedSetResult(void* ptr, u32 value) {
67 static_cast<XOVERLAPPED*>(ptr)->result.Store(value, std::memory_order_release);
68}
69
75inline u32 XOverlappedGetResult(void* ptr) {
76 return static_cast<XOVERLAPPED*>(ptr)->result.Load(std::memory_order_acquire);
77}
78
79inline void XOverlappedSetLength(void* ptr, u32 value) {
80 static_cast<XOVERLAPPED*>(ptr)->length = value;
81}
82
83inline u32 XOverlappedGetContext(void* ptr) {
84 return static_cast<XOVERLAPPED*>(ptr)->context;
85}
86
87inline void XOverlappedSetContext(void* ptr, u32 value) {
88 static_cast<XOVERLAPPED*>(ptr)->context = value;
89}
90
96inline X_HANDLE XOverlappedGetEvent(void* ptr) {
97 return static_cast<XOVERLAPPED*>(ptr)->event;
98}
99
105inline u32 XOverlappedGetCompletionRoutine(void* ptr) {
106 return static_cast<XOVERLAPPED*>(ptr)->completion_routine;
107}
108
109inline void XOverlappedSetExtendedError(void* ptr, u32 value) {
110 static_cast<XOVERLAPPED*>(ptr)->extended_error = value;
111}
112
115 be_u16 length;
117 be_u32 pointer;
118
119 void Reset() {
120 length = 0;
121 maximum_length = 0;
122 pointer = 0;
123 }
124};
125REX_STATIC_ASSERT_SIZE(X_ANSI_STRING, 8);
126
129 be_u16 length;
131 be_u32 pointer;
132
133 void Reset() {
134 length = 0;
135 maximum_length = 0;
136 pointer = 0;
137 }
138};
139REX_STATIC_ASSERT_SIZE(X_UNICODE_STRING, 8);
140
142 union {
143 BE<X_STATUS> status;
144 be_u32 pointer;
145 };
146
148};
149
152 be_u32 name_ptr;
153 be_u32 attributes;
154};
155REX_STATIC_ASSERT_SIZE(X_OBJECT_ATTRIBUTES, 0xC);
156
157#pragma pack(pop)
158
160inline constexpr u32 kObjOpenIf = 0x80;
161
163inline constexpr u32 kFileObjectSize = 0x68;
164
166inline constexpr u16 kFileObjectTypeId = 5;
167
170 be_u16 type;
171 u8 flags;
172 u8 pad_03;
173 be_u32 device_ptr;
174 u8 pad_08[0x14];
176 u8 pad_20[4];
177 be_u32 unk_24;
178 u8 unk_28;
179 u8 pad_29[7];
180 X_LIST_ENTRY unk_list_30;
181 X_DISPATCH_HEADER event;
182 u8 pad_48[0x10];
183 u8 unk_58;
184 u8 pad_59[0xF];
185};
186REX_STATIC_ASSERT_SIZE(XFileObject, kFileObjectSize);
187
189inline constexpr u32 kIOCompletionObjectSize = 0x28;
190
192inline constexpr u32 kSymbolicLinkObjectSize = 0xC;
193
196 XFileDirectoryInformation = 1,
197 XFileFullDirectoryInformation,
198 XFileBothDirectoryInformation,
199 XFileBasicInformation,
200 XFileStandardInformation,
201 XFileInternalInformation,
202 XFileEaInformation,
203 XFileAccessInformation,
204 XFileNameInformation,
205 XFileRenameInformation,
206 XFileLinkInformation,
207 XFileNamesInformation,
208 XFileDispositionInformation,
209 XFilePositionInformation,
210 XFileFullEaInformation,
211 XFileModeInformation,
212 XFileAlignmentInformation,
213 XFileAllInformation,
214 XFileAllocationInformation,
215 XFileEndOfFileInformation,
216 XFileAlternateNameInformation,
217 XFileStreamInformation,
218 XFileMountPartitionInformation,
219 XFileMountPartitionsInformation,
220 XFilePipeRemoteInformation,
221 XFileSectorInformation,
222 XFileXctdCompressionInformation,
223 XFileCompressionInformation,
224 XFileObjectIdInformation,
225 XFileCompletionInformation,
226 XFileMoveClusterInformation,
227 XFileIoPriorityInformation,
228 XFileReparsePointInformation,
229 XFileNetworkOpenInformation,
230 XFileAttributeTagInformation,
231 XFileTrackingInformation,
233};
234
235#pragma pack(push, 1)
236
238 be_u64 creation_time;
239 be_u64 last_access_time;
240 be_u64 last_write_time;
241 be_u64 change_time;
242 be_u64 attributes;
243};
244REX_STATIC_ASSERT_SIZE(X_FILE_BASIC_INFORMATION, 0x28);
245
250REX_STATIC_ASSERT_SIZE(X_FILE_INTERNAL_INFORMATION, 8);
251
257REX_STATIC_ASSERT_SIZE(X_FILE_RENAME_INFORMATION, 16);
258
262REX_STATIC_ASSERT_SIZE(X_FILE_DISPOSITION_INFORMATION, 1);
263
265 be_u64 current_byte_offset;
266};
267REX_STATIC_ASSERT_SIZE(X_FILE_POSITION_INFORMATION, 8);
268
272REX_STATIC_ASSERT_SIZE(X_FILE_END_OF_FILE_INFORMATION, 8);
273
277REX_STATIC_ASSERT_SIZE(X_FILE_ALLOCATION_INFORMATION, 8);
278
281 be_u32 unknown;
282};
283REX_STATIC_ASSERT_SIZE(X_FILE_XCTD_COMPRESSION_INFORMATION, 4);
284
287 be_u32 handle;
288 be_u32 key;
289};
290REX_STATIC_ASSERT_SIZE(X_FILE_COMPLETION_INFORMATION, 8);
291
293 be_u64 creation_time;
294 be_u64 last_access_time;
295 be_u64 last_write_time;
296 be_u64 change_time;
298 be_u64 end_of_file;
299 be_u32 attributes;
300 be_u32 pad;
301};
302REX_STATIC_ASSERT_SIZE(X_FILE_NETWORK_OPEN_INFORMATION, 56);
303
304#pragma pack(pop)
305
313
315// NOLINTNEXTLINE(performance-enum-size): guest memory field width
317 kFileDeviceUnknown = 0x00000022,
318 kFileDeviceEHSTOR = 0x00000046,
319};
320
321#pragma pack(push, 1)
322
324 be_u64 creation_time;
325 be_u32 serial_number;
327 u8 supports_objects;
328 char label[1];
329 u8 pad[6];
330};
331REX_STATIC_ASSERT_SIZE(X_FILE_FS_VOLUME_INFORMATION, 24);
332
334 be_u64 total_allocation_units;
336 be_u32 sectors_per_allocation_unit;
337 be_u32 bytes_per_sector;
338};
339REX_STATIC_ASSERT_SIZE(X_FILE_FS_SIZE_INFORMATION, 24);
340
342 be_u32 attributes;
344 be_u32 name_length;
345 char name[1];
346 u8 pad[3];
347};
348REX_STATIC_ASSERT_SIZE(X_FILE_FS_ATTRIBUTE_INFORMATION, 16);
349
351 BE<X_FILE_DEVICE_TYPE> device_type;
352 be_u32 characteristics;
353};
354REX_STATIC_ASSERT_SIZE(X_FILE_FS_DEVICE_INFORMATION, 8);
355
356#pragma pack(pop)
357
358} // namespace rex::kernel
359
360namespace rex {
361namespace kernel {
362
370 const X_ANSI_STRING* ansi_string) {
371 if (!ansi_string || !ansi_string->length) {
372 return "";
373 }
374 return std::string_view(memory->TranslateVirtual<const char*>(ansi_string->pointer),
375 ansi_string->length);
376}
377
384 const X_ANSI_STRING* ansi_string) {
385 return rex::string::TrimString(std::string(TranslateAnsiString(memory, ansi_string)));
386}
387
395 u32 guest_address) {
396 if (!guest_address) {
397 return "";
398 }
399 return TranslateAnsiString(memory, memory->TranslateVirtual<const X_ANSI_STRING*>(guest_address));
400}
401
409 const X_UNICODE_STRING* unicode_string) {
410 if (!unicode_string) {
411 return u"";
412 }
413 u16 length = unicode_string->length;
414 if (!length) {
415 return u"";
416 }
417 auto src = memory->TranslateVirtual<const be_u16*>(unicode_string->pointer);
418 std::u16string result;
419 result.reserve(length);
420 for (u16 i = 0; i < length / 2; ++i) {
421 result.push_back(src[i]);
422 }
423 return result;
424}
425
426} // namespace kernel
427} // namespace rex
Definition heap.h:594
Guest list and spin lock structures.
Definition export.h:24
constexpr u32 kFileObjectSize
Definition io.h:163
constexpr u32 kIOCompletionObjectSize
Definition io.h:189
X_HANDLE XOverlappedGetEvent(void *ptr)
Definition io.h:96
constexpr u16 kFileObjectTypeId
Definition io.h:166
X_FILE_DEVICE_TYPE
Definition io.h:316
@ kFileDeviceUnknown
Definition io.h:317
std::string_view TranslateAnsiString(const kernel::GuestAddressSpace *memory, const X_ANSI_STRING *ansi_string)
Definition io.h:369
X_FILE_INFORMATION_CLASS
Definition io.h:195
@ XFileMaximumInformation
Definition io.h:232
constexpr u32 kSymbolicLinkObjectSize
Definition io.h:192
u32 XOverlappedGetResult(void *ptr)
Definition io.h:75
void XOverlappedSetResult(void *ptr, u32 value)
Definition io.h:66
X_FILE_FS_INFORMATION_CLASS
Definition io.h:307
@ XFileFsAttributeInformation
Definition io.h:311
@ XFileFsSizeInformation
Definition io.h:309
@ XFileFsVolumeInformation
Definition io.h:308
constexpr u32 kObjOpenIf
Definition io.h:160
std::string_view TranslateAnsiStringAddress(const kernel::GuestAddressSpace *memory, u32 guest_address)
Definition io.h:394
u32 XOverlappedGetCompletionRoutine(void *ptr)
Definition io.h:105
std::string TranslateAnsiPath(const kernel::GuestAddressSpace *memory, const X_ANSI_STRING *ansi_string)
Definition io.h:383
std::u16string TranslateUnicodeString(const kernel::GuestAddressSpace *memory, const X_UNICODE_STRING *unicode_string)
Definition io.h:408
X_FILE_ATTRIBUTES
Definition io.h:34
@ kXFileAttributeDevice
Definition io.h:41
@ kXFileAttributeNormal
Definition io.h:42
Definition endian.h:27
Definition app.h:36
Definition io.h:169
be_u32 related_file
Definition io.h:175
be_u32 device_ptr
Definition io.h:173
be_u16 type
Definition io.h:170
Definition io.h:49
be_u32 completion_routine
Definition io.h:54
be_u32 event
Definition io.h:53
be_u32 context
Definition io.h:52
Definition io.h:114
be_u16 maximum_length
Definition io.h:116
be_u16 length
Definition io.h:115
be_u32 pointer
Definition io.h:117
Definition thread.h:70
be_u64 allocation_size
Definition io.h:275
be_i32 component_name_max_length
Definition io.h:343
be_u64 available_allocation_units
Definition io.h:335
char label[1]
Definition io.h:328
be_u32 label_length
Definition io.h:326
be_u64 index_number
Definition io.h:248
be_u64 allocation_size
Definition io.h:297
be_u32 root_dir_handle
Definition io.h:254
be_u32 replace_existing
Definition io.h:253
be_u32 information
Definition io.h:147
Definition list.h:24
be_u32 root_directory
Definition io.h:151
be_u32 name_ptr
Definition io.h:152
be_u16 length
Definition io.h:129
be_u32 pointer
Definition io.h:131
be_u16 maximum_length
Definition io.h:130
ASCII and UTF-8 text operations, the string builder and the string keys.
std::string TrimString(std::string_view sv, std::string_view chars=kWhitespace)
Definition text.h:151