2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2015-10-12 06:39:31 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// 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
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-01-03 17:51:30 +00:00
|
|
|
// Copyright © 2011-2020 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;
|
2015-10-05 21:20:25 +01:00
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using Microsoft.Win32.SafeHandles;
|
|
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
namespace Aaru.Devices.Windows
|
2015-10-05 21:20:25 +01:00
|
|
|
{
|
2019-10-27 20:46:24 +00:00
|
|
|
internal static class Extern
|
2015-10-05 21:20:25 +01:00
|
|
|
{
|
|
|
|
|
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
2019-10-27 20:46:24 +00:00
|
|
|
internal static extern SafeFileHandle CreateFile([MarshalAs(UnmanagedType.LPTStr)] string filename,
|
|
|
|
|
[MarshalAs(UnmanagedType.U4)] FileAccess access,
|
|
|
|
|
[MarshalAs(UnmanagedType.U4)] FileShare share,
|
|
|
|
|
IntPtr
|
|
|
|
|
securityAttributes, // optional SECURITY_ATTRIBUTES struct or IntPtr.Zero
|
|
|
|
|
[MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
|
|
|
|
|
[MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes, IntPtr templateFile);
|
2015-10-05 21:20:25 +01:00
|
|
|
|
2017-08-21 04:28:26 +01:00
|
|
|
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
|
2019-10-27 20:46:24 +00:00
|
|
|
internal static extern bool DeviceIoControlScsi(SafeFileHandle hDevice,
|
|
|
|
|
WindowsIoctl ioControlCode,
|
|
|
|
|
ref ScsiPassThroughDirectAndSenseBuffer inBuffer,
|
|
|
|
|
uint nInBufferSize,
|
|
|
|
|
ref ScsiPassThroughDirectAndSenseBuffer outBuffer,
|
|
|
|
|
uint nOutBufferSize,
|
|
|
|
|
ref uint pBytesReturned,
|
|
|
|
|
IntPtr overlapped);
|
2015-10-05 21:20:25 +01:00
|
|
|
|
2017-08-21 04:28:26 +01:00
|
|
|
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
|
2019-10-27 20:46:24 +00:00
|
|
|
internal static extern bool DeviceIoControlAta(SafeFileHandle hDevice,
|
|
|
|
|
WindowsIoctl ioControlCode,
|
|
|
|
|
ref AtaPassThroughExBuffer inBuffer,
|
|
|
|
|
uint nInBufferSize,
|
|
|
|
|
ref AtaPassThroughExBuffer outBuffer,
|
|
|
|
|
uint nOutBufferSize,
|
|
|
|
|
ref uint pBytesReturned, IntPtr overlapped);
|
2015-10-07 02:15:31 +01:00
|
|
|
|
2017-08-22 03:40:43 +01:00
|
|
|
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
|
2019-10-27 20:46:24 +00:00
|
|
|
internal static extern bool DeviceIoControlStorageQuery(SafeFileHandle hDevice,
|
|
|
|
|
WindowsIoctl ioControlCode,
|
|
|
|
|
ref StoragePropertyQuery inBuffer,
|
|
|
|
|
uint nInBufferSize,
|
|
|
|
|
IntPtr outBuffer,
|
|
|
|
|
uint nOutBufferSize,
|
|
|
|
|
ref uint pBytesReturned,
|
|
|
|
|
IntPtr overlapped);
|
2017-09-10 23:20:59 +01:00
|
|
|
|
|
|
|
|
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
|
2019-10-27 20:46:24 +00:00
|
|
|
internal static extern bool DeviceIoControlIde(SafeFileHandle hDevice,
|
|
|
|
|
WindowsIoctl ioControlCode,
|
|
|
|
|
ref IdePassThroughDirect inBuffer,
|
|
|
|
|
uint nInBufferSize,
|
|
|
|
|
ref IdePassThroughDirect outBuffer,
|
|
|
|
|
uint nOutBufferSize,
|
|
|
|
|
ref uint pBytesReturned,
|
|
|
|
|
IntPtr overlapped);
|
2017-08-22 03:40:43 +01:00
|
|
|
|
2017-12-06 13:46:35 +00:00
|
|
|
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
|
2019-10-27 20:46:24 +00:00
|
|
|
internal static extern bool DeviceIoControlGetDeviceNumber(SafeFileHandle hDevice,
|
|
|
|
|
WindowsIoctl ioControlCode,
|
|
|
|
|
IntPtr inBuffer,
|
|
|
|
|
uint nInBufferSize,
|
|
|
|
|
ref StorageDeviceNumber outBuffer,
|
|
|
|
|
uint nOutBufferSize,
|
|
|
|
|
ref uint pBytesReturned,
|
|
|
|
|
IntPtr overlapped);
|
2017-12-06 13:46:35 +00:00
|
|
|
|
2017-12-06 23:05:59 +00:00
|
|
|
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
|
2019-10-27 20:46:24 +00:00
|
|
|
internal static extern bool DeviceIoControl(SafeFileHandle hDevice,
|
|
|
|
|
WindowsIoctl ioControlCode, IntPtr inBuffer,
|
|
|
|
|
uint nInBufferSize,
|
|
|
|
|
ref SffdiskQueryDeviceProtocolData outBuffer,
|
|
|
|
|
uint nOutBufferSize,
|
|
|
|
|
out uint pBytesReturned,
|
|
|
|
|
IntPtr overlapped);
|
2017-12-06 23:05:59 +00:00
|
|
|
|
|
|
|
|
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
|
2018-06-22 08:08:38 +01:00
|
|
|
internal static extern bool DeviceIoControl(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
|
2019-10-27 20:46:24 +00:00
|
|
|
byte[] inBuffer,
|
|
|
|
|
uint nInBufferSize, byte[] outBuffer,
|
|
|
|
|
uint nOutBufferSize,
|
|
|
|
|
out uint pBytesReturned, IntPtr overlapped);
|
2017-12-06 23:05:59 +00:00
|
|
|
|
2017-12-06 13:46:35 +00:00
|
|
|
[DllImport("setupapi.dll", CharSet = CharSet.Auto)]
|
2019-10-27 20:46:24 +00:00
|
|
|
internal static extern SafeFileHandle SetupDiGetClassDevs(ref Guid classGuid, IntPtr enumerator,
|
|
|
|
|
IntPtr hwndParent, DeviceGetClassFlags flags);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2017-12-06 13:46:35 +00:00
|
|
|
[DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
2019-10-27 20:46:24 +00:00
|
|
|
public static extern bool SetupDiEnumDeviceInterfaces(SafeFileHandle hDevInfo,
|
|
|
|
|
IntPtr devInfo,
|
|
|
|
|
ref Guid interfaceClassGuid,
|
|
|
|
|
uint memberIndex,
|
|
|
|
|
ref DeviceInterfaceData deviceInterfaceData);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2017-12-06 13:46:35 +00:00
|
|
|
[DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
2019-10-27 20:46:24 +00:00
|
|
|
public static extern bool SetupDiGetDeviceInterfaceDetail(SafeFileHandle hDevInfo,
|
|
|
|
|
ref DeviceInterfaceData deviceInterfaceData,
|
|
|
|
|
IntPtr deviceInterfaceDetailData,
|
|
|
|
|
uint deviceInterfaceDetailDataSize,
|
|
|
|
|
ref uint requiredSize,
|
|
|
|
|
IntPtr deviceInfoData);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2017-12-06 13:46:35 +00:00
|
|
|
[DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
|
|
|
|
public static extern bool SetupDiDestroyDeviceInfoList(SafeFileHandle hDevInfo);
|
2017-12-06 19:30:03 +00:00
|
|
|
|
2015-10-05 21:20:25 +01:00
|
|
|
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
2015-10-12 06:25:49 +01:00
|
|
|
internal static extern bool CloseHandle(SafeFileHandle hDevice);
|
2015-10-05 21:20:25 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|