2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2015-10-12 06:39:31 +01:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Extern.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2015-10-12 06:39:31 +01:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Component : Windows direct device access.
|
2015-10-12 06:39:31 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Contains the P/Invoke definitions of Windows syscalls used to directly
|
|
|
|
|
// interface devices.
|
2015-10-12 06:39:31 +01:00
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
// published by the Free Software Foundation; either version 2.1 of the
|
2015-10-12 06:39:31 +01:00
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// This library is distributed in the hope that it will be useful, but
|
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
// Lesser General Public License for more details.
|
2015-10-12 06:39:31 +01:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2015-10-12 06:39:31 +01:00
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2024-05-01 04:17:32 +01:00
|
|
|
// Copyright © 2011-2024 Natalia Portillo
|
2015-10-12 06:39:31 +01:00
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
2015-10-12 06:39:31 +01:00
|
|
|
using System;
|
2023-10-05 01:05:23 +01:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2015-10-05 21:20:25 +01:00
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using Microsoft.Win32.SafeHandles;
|
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
namespace Aaru.Devices.Windows;
|
|
|
|
|
|
2023-10-05 01:05:23 +01:00
|
|
|
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
2024-05-01 05:36:13 +01:00
|
|
|
static partial class Extern
|
2015-10-05 21:20:25 +01:00
|
|
|
{
|
2024-05-01 05:36:13 +01:00
|
|
|
[LibraryImport("kernel32.dll",
|
|
|
|
|
EntryPoint = "CreateFileW",
|
|
|
|
|
SetLastError = true,
|
|
|
|
|
StringMarshalling = StringMarshalling.Utf16)]
|
|
|
|
|
internal static partial SafeFileHandle CreateFile([MarshalAs(UnmanagedType.LPTStr)] string filename,
|
|
|
|
|
[MarshalAs(UnmanagedType.U4)] FileAccess access,
|
|
|
|
|
[MarshalAs(UnmanagedType.U4)] FileShare share,
|
|
|
|
|
nint securityAttributes, // optional SECURITY_ATTRIBUTES struct or IntPtr.Zero
|
|
|
|
|
[MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
|
|
|
|
|
[MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes,
|
|
|
|
|
nint templateFile);
|
|
|
|
|
|
|
|
|
|
[LibraryImport("Kernel32.dll", EntryPoint = "DeviceIoControl", SetLastError = true)]
|
|
|
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
|
|
|
internal static partial bool DeviceIoControlScsi(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
|
|
|
|
|
ref ScsiPassThroughDirectAndSenseBuffer inBuffer,
|
|
|
|
|
uint nInBufferSize,
|
|
|
|
|
ref ScsiPassThroughDirectAndSenseBuffer outBuffer,
|
|
|
|
|
uint nOutBufferSize, ref uint pBytesReturned, nint overlapped);
|
|
|
|
|
|
|
|
|
|
[LibraryImport("Kernel32.dll", EntryPoint = "DeviceIoControl", SetLastError = true)]
|
|
|
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
|
|
|
internal static partial bool DeviceIoControlAta(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
|
|
|
|
|
ref AtaPassThroughDirect inBuffer, uint nInBufferSize,
|
|
|
|
|
ref AtaPassThroughDirect outBuffer, uint nOutBufferSize,
|
|
|
|
|
ref uint pBytesReturned, nint overlapped);
|
|
|
|
|
|
|
|
|
|
[LibraryImport("Kernel32.dll", EntryPoint = "DeviceIoControl", SetLastError = true)]
|
|
|
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
|
|
|
internal static partial bool DeviceIoControlStorageQuery(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
|
|
|
|
|
ref StoragePropertyQuery inBuffer, uint nInBufferSize,
|
|
|
|
|
nint outBuffer, uint nOutBufferSize,
|
|
|
|
|
ref uint pBytesReturned, nint overlapped);
|
|
|
|
|
|
|
|
|
|
[LibraryImport("Kernel32.dll", EntryPoint = "DeviceIoControl", SetLastError = true)]
|
|
|
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
|
|
|
internal static partial bool DeviceIoControlIde(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
|
|
|
|
|
ref IdePassThroughDirect inBuffer, uint nInBufferSize,
|
|
|
|
|
ref IdePassThroughDirect outBuffer, uint nOutBufferSize,
|
|
|
|
|
ref uint pBytesReturned, nint overlapped);
|
|
|
|
|
|
|
|
|
|
[LibraryImport("Kernel32.dll", EntryPoint = "DeviceIoControl", SetLastError = true)]
|
|
|
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
|
|
|
internal static partial bool DeviceIoControlGetDeviceNumber(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
|
|
|
|
|
nint inBuffer, uint nInBufferSize,
|
|
|
|
|
ref StorageDeviceNumber outBuffer, uint nOutBufferSize,
|
|
|
|
|
ref uint pBytesReturned, nint overlapped);
|
|
|
|
|
|
|
|
|
|
[LibraryImport("Kernel32.dll", EntryPoint = "DeviceIoControl", SetLastError = true)]
|
|
|
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
|
|
|
internal static partial bool DeviceIoControl(SafeFileHandle hDevice, WindowsIoctl ioControlCode, nint inBuffer,
|
|
|
|
|
uint nInBufferSize, ref SffdiskQueryDeviceProtocolData outBuffer,
|
|
|
|
|
uint nOutBufferSize, out uint pBytesReturned, nint overlapped);
|
|
|
|
|
|
|
|
|
|
[LibraryImport("Kernel32.dll", EntryPoint = "DeviceIoControl", SetLastError = true)]
|
|
|
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
|
|
|
internal static partial bool DeviceIoControl(SafeFileHandle hDevice, WindowsIoctl ioControlCode, byte[] inBuffer,
|
|
|
|
|
uint nInBufferSize, byte[] outBuffer, uint nOutBufferSize,
|
|
|
|
|
out uint pBytesReturned, nint overlapped);
|
|
|
|
|
|
|
|
|
|
[LibraryImport("setupapi.dll", EntryPoint = "SetupDiGetClassDevsW")]
|
|
|
|
|
internal static partial SafeFileHandle SetupDiGetClassDevs(ref Guid classGuid, nint enumerator, nint hwndParent,
|
|
|
|
|
DeviceGetClassFlags flags);
|
|
|
|
|
|
|
|
|
|
[LibraryImport("setupapi.dll", SetLastError = true)]
|
|
|
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
|
|
|
public static partial bool SetupDiEnumDeviceInterfaces(SafeFileHandle hDevInfo, nint devInfo,
|
|
|
|
|
ref Guid interfaceClassGuid, uint memberIndex,
|
|
|
|
|
ref DeviceInterfaceData deviceInterfaceData);
|
|
|
|
|
|
|
|
|
|
[LibraryImport("setupapi.dll", EntryPoint = "SetupDiGetDeviceInterfaceDetailW", SetLastError = true)]
|
|
|
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
|
|
|
public static partial bool SetupDiGetDeviceInterfaceDetail(SafeFileHandle hDevInfo,
|
|
|
|
|
ref DeviceInterfaceData deviceInterfaceData,
|
|
|
|
|
nint deviceInterfaceDetailData,
|
|
|
|
|
uint deviceInterfaceDetailDataSize,
|
|
|
|
|
ref uint requiredSize, nint deviceInfoData);
|
|
|
|
|
|
|
|
|
|
[LibraryImport("setupapi.dll", SetLastError = true)]
|
|
|
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
|
|
|
public static partial bool SetupDiDestroyDeviceInfoList(SafeFileHandle hDevInfo);
|
|
|
|
|
|
|
|
|
|
[LibraryImport("Kernel32.dll", SetLastError = true)]
|
|
|
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
|
|
|
internal static partial bool CloseHandle(SafeFileHandle hDevice);
|
|
|
|
|
|
|
|
|
|
[LibraryImport("Kernel32.dll", SetLastError = true)]
|
|
|
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
|
|
|
public static partial bool SetFilePointerEx(SafeFileHandle hFile, long liDistanceToMove, out long lpNewFilePointer,
|
|
|
|
|
MoveMethod dwMoveMethod);
|
|
|
|
|
|
|
|
|
|
[LibraryImport("kernel32.dll", SetLastError = true)]
|
|
|
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
|
|
|
public static partial bool ReadFile(SafeFileHandle hFile, byte[] lpBuffer, uint nNumberOfBytesToRead,
|
|
|
|
|
out uint lpNumberOfBytesRead, nint lpOverlapped);
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|