| ... | @@ -228,20 +228,43 @@ pub fn DeviceIoControl( | ... | @@ -228,20 +228,43 @@ pub fn DeviceIoControl( |
| 228 | out: ?[]u8, | 228 | out: ?[]u8, |
| 229 | ) DeviceIoControlError!void { | 229 | ) DeviceIoControlError!void { |
| 230 | // Logic from: https://doxygen.reactos.org/d3/d74/deviceio_8c.html | 230 | // Logic from: https://doxygen.reactos.org/d3/d74/deviceio_8c.html |
| 231 | const syscall = if ((ioControlCode >> 16) == FILE_DEVICE_FILE_SYSTEM) ntdll.NtFsControlFile else ntdll.NtDeviceIoControlFile; | 231 | const is_fsctl = (ioControlCode >> 16) == FILE_DEVICE_FILE_SYSTEM; |
| | 232 | |
| 232 | var io: IO_STATUS_BLOCK = undefined; | 233 | var io: IO_STATUS_BLOCK = undefined; |
| 233 | const rc = syscall( | 234 | const in_ptr = if (in) |i| i.ptr else null; |
| 234 | h, | 235 | const in_len = if (in) |i| @intCast(ULONG, i.len) else 0; |
| 235 | null, | 236 | const out_ptr = if (out) |o| o.ptr else null; |
| 236 | null, | 237 | const out_len = if (out) |o| @intCast(ULONG, o.len) else 0; |
| 237 | null, | 238 | |
| 238 | &io, | 239 | const rc = blk: { |
| 239 | ioControlCode, | 240 | if (is_fsctl) { |
| 240 | if (in) |i| i.ptr else null, | 241 | break :blk ntdll.NtFsControlFile( |
| 241 | if (in) |i| @intCast(ULONG, i.len) else 0, | 242 | h, |
| 242 | if (out) |o| o.ptr else null, | 243 | null, |
| 243 | if (out) |o| @intCast(ULONG, o.len) else 0, | 244 | null, |
| 244 | ); | 245 | null, |
| | 246 | &io, |
| | 247 | ioControlCode, |
| | 248 | in_ptr, |
| | 249 | in_len, |
| | 250 | out_ptr, |
| | 251 | out_len, |
| | 252 | ); |
| | 253 | } else { |
| | 254 | break :blk ntdll.NtDeviceIoControlFile( |
| | 255 | h, |
| | 256 | null, |
| | 257 | null, |
| | 258 | null, |
| | 259 | &io, |
| | 260 | ioControlCode, |
| | 261 | in_ptr, |
| | 262 | in_len, |
| | 263 | out_ptr, |
| | 264 | out_len, |
| | 265 | ); |
| | 266 | } |
| | 267 | }; |
| 245 | switch (rc) { | 268 | switch (rc) { |
| 246 | .SUCCESS => {}, | 269 | .SUCCESS => {}, |
| 247 | .INVALID_PARAMETER => unreachable, | 270 | .INVALID_PARAMETER => unreachable, |