mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[Refactor] Use LibraryImport instead of DllImport.
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<Authors>Natalia Portillo <claunia@claunia.com></Authors>
|
||||
<DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
|
||||
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Aaru.Checksums;
|
||||
/// <inheritdoc />
|
||||
/// <summary>Implements the Adler-32 algorithm</summary>
|
||||
[SuppressMessage("ReSharper", "UnusedMethodReturnValue.Global")]
|
||||
public sealed class Adler32Context : IChecksum
|
||||
public sealed partial class Adler32Context : IChecksum
|
||||
{
|
||||
internal const ushort ADLER_MODULE = 65521;
|
||||
internal const uint NMAX = 5552;
|
||||
@@ -130,17 +130,17 @@ public sealed class Adler32Context : IChecksum
|
||||
|
||||
#endregion
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern IntPtr adler32_init();
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial IntPtr adler32_init();
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern int adler32_update(IntPtr ctx, byte[] data, uint len);
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial int adler32_update(IntPtr ctx, byte[] data, uint len);
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern int adler32_final(IntPtr ctx, ref uint checksum);
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial int adler32_final(IntPtr ctx, ref uint checksum);
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern void adler32_free(IntPtr ctx);
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial void adler32_free(IntPtr ctx);
|
||||
|
||||
static void Step(ref ushort preSum1, ref ushort preSum2, byte[] data, uint len, bool useNative,
|
||||
IntPtr nativeContext)
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Aaru.Checksums;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>Implements a CRC16 algorithm</summary>
|
||||
public class Crc16Context : IChecksum
|
||||
public partial class Crc16Context : IChecksum
|
||||
{
|
||||
readonly ushort _finalSeed;
|
||||
readonly bool _inverse;
|
||||
@@ -198,29 +198,29 @@ public class Crc16Context : IChecksum
|
||||
|
||||
#endregion
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern IntPtr crc16_init();
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial IntPtr crc16_init();
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern int crc16_update(IntPtr ctx, byte[] data, uint len);
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial int crc16_update(IntPtr ctx, byte[] data, uint len);
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern int crc16_final(IntPtr ctx, ref ushort crc);
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial int crc16_final(IntPtr ctx, ref ushort crc);
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern void crc16_free(IntPtr ctx);
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial void crc16_free(IntPtr ctx);
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern IntPtr crc16_ccitt_init();
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial IntPtr crc16_ccitt_init();
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern int crc16_ccitt_update(IntPtr ctx, byte[] data, uint len);
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial int crc16_ccitt_update(IntPtr ctx, byte[] data, uint len);
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern int crc16_ccitt_final(IntPtr ctx, ref ushort crc);
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial int crc16_ccitt_final(IntPtr ctx, ref ushort crc);
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern void crc16_ccitt_free(IntPtr ctx);
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial void crc16_ccitt_free(IntPtr ctx);
|
||||
|
||||
static void Step(ref ushort previousCrc, ushort[][] table, byte[] data, uint len)
|
||||
{
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Aaru.Checksums;
|
||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
|
||||
[SuppressMessage("ReSharper", "UnusedMethodReturnValue.Global")]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
public sealed class Crc32Context : IChecksum
|
||||
public sealed partial class Crc32Context : IChecksum
|
||||
{
|
||||
const uint CRC32_ISO_POLY = 0xEDB88320;
|
||||
const uint CRC32_ISO_SEED = 0xFFFFFFFF;
|
||||
@@ -426,17 +426,17 @@ public sealed class Crc32Context : IChecksum
|
||||
|
||||
#endregion
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern IntPtr crc32_init();
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial IntPtr crc32_init();
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern int crc32_update(IntPtr ctx, byte[] data, uint len);
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial int crc32_update(IntPtr ctx, byte[] data, uint len);
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern int crc32_final(IntPtr ctx, ref uint crc);
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial int crc32_final(IntPtr ctx, ref uint crc);
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern void crc32_free(IntPtr ctx);
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial void crc32_free(IntPtr ctx);
|
||||
|
||||
static uint[][] GenerateTable(uint polynomial)
|
||||
{
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Aaru.Checksums;
|
||||
[SuppressMessage("ReSharper", "UnusedMethodReturnValue.Global")]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
|
||||
public sealed class Crc64Context : IChecksum
|
||||
public sealed partial class Crc64Context : IChecksum
|
||||
{
|
||||
/// <summary>ECMA CRC64 polynomial</summary>
|
||||
const ulong CRC64_ECMA_POLY = 0xC96C5795D7870F42;
|
||||
@@ -371,17 +371,17 @@ public sealed class Crc64Context : IChecksum
|
||||
|
||||
#endregion
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern IntPtr crc64_init();
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial IntPtr crc64_init();
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern int crc64_update(IntPtr ctx, byte[] data, uint len);
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial int crc64_update(IntPtr ctx, byte[] data, uint len);
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern int crc64_final(IntPtr ctx, ref ulong crc);
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial int crc64_final(IntPtr ctx, ref ulong crc);
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern void crc64_free(IntPtr ctx);
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial void crc64_free(IntPtr ctx);
|
||||
|
||||
static ulong[][] GenerateTable(ulong polynomial)
|
||||
{
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace Aaru.Checksums;
|
||||
[SuppressMessage("ReSharper", "UnusedMethodReturnValue.Global")]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||
public sealed class Fletcher32Context : IChecksum
|
||||
public sealed partial class Fletcher32Context : IChecksum
|
||||
{
|
||||
internal const ushort FLETCHER_MODULE = 0xFFFF;
|
||||
internal const uint NMAX = 5552;
|
||||
@@ -128,17 +128,17 @@ public sealed class Fletcher32Context : IChecksum
|
||||
|
||||
#endregion
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern IntPtr fletcher32_init();
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial IntPtr fletcher32_init();
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern int fletcher32_update(IntPtr ctx, byte[] data, uint len);
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial int fletcher32_update(IntPtr ctx, byte[] data, uint len);
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern int fletcher32_final(IntPtr ctx, ref uint crc);
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial int fletcher32_final(IntPtr ctx, ref uint crc);
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern void fletcher32_free(IntPtr ctx);
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial void fletcher32_free(IntPtr ctx);
|
||||
|
||||
static void Step(ref ushort previousSum1, ref ushort previousSum2, byte[] data, uint len, bool useNative,
|
||||
IntPtr nativeContext)
|
||||
@@ -418,7 +418,7 @@ public sealed class Fletcher32Context : IChecksum
|
||||
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
[SuppressMessage("ReSharper", "UnusedMethodReturnValue.Global")]
|
||||
public sealed class Fletcher16Context : IChecksum
|
||||
public sealed partial class Fletcher16Context : IChecksum
|
||||
{
|
||||
const byte FLETCHER_MODULE = 0xFF;
|
||||
const byte NMAX = 22;
|
||||
@@ -497,17 +497,17 @@ public sealed class Fletcher16Context : IChecksum
|
||||
|
||||
#endregion
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern IntPtr fletcher16_init();
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial IntPtr fletcher16_init();
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern int fletcher16_update(IntPtr ctx, byte[] data, uint len);
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial int fletcher16_update(IntPtr ctx, byte[] data, uint len);
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern int fletcher16_final(IntPtr ctx, ref ushort checksum);
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial int fletcher16_final(IntPtr ctx, ref ushort checksum);
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern void fletcher16_free(IntPtr ctx);
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial void fletcher16_free(IntPtr ctx);
|
||||
|
||||
static void Step(ref byte previousSum1, ref byte previousSum2, byte[] data, uint len, bool useNative,
|
||||
IntPtr nativeContext)
|
||||
|
||||
@@ -35,7 +35,7 @@ using System.Runtime.InteropServices;
|
||||
namespace Aaru.Checksums;
|
||||
|
||||
/// <summary>Handles native implementations of compression algorithms</summary>
|
||||
public static class Native
|
||||
public static partial class Native
|
||||
{
|
||||
static bool _checked;
|
||||
static bool _supported;
|
||||
@@ -76,6 +76,6 @@ public static class Native
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
static extern ulong get_acn_version();
|
||||
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
|
||||
private static partial ulong get_acn_version();
|
||||
}
|
||||
@@ -27,6 +27,7 @@
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<Authors>Natalia Portillo <claunia@claunia.com></Authors>
|
||||
<DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
|
||||
@@ -40,12 +40,13 @@ using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.Marshalling;
|
||||
using System.Security.Principal;
|
||||
|
||||
namespace Aaru.CommonTypes.Interop;
|
||||
|
||||
/// <summary>Detects the underlying execution framework and operating system</summary>
|
||||
public static class DetectOS
|
||||
public static partial class DetectOS
|
||||
{
|
||||
/// <summary>Are we running under Mono?</summary>
|
||||
public static readonly bool IsMono =
|
||||
@@ -98,11 +99,15 @@ public static class DetectOS
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("libc", SetLastError = true)]
|
||||
static extern int uname(out UtsName name);
|
||||
[LibraryImport("libc", SetLastError = true)]
|
||||
private static partial int uname(out UtsName name);
|
||||
|
||||
[DllImport("libc", SetLastError = true, EntryPoint = "sysctlbyname", CharSet = CharSet.Ansi)]
|
||||
static extern int OSX_sysctlbyname(string name, IntPtr oldp, IntPtr oldlenp, IntPtr newp, uint newlen);
|
||||
[LibraryImport("libc",
|
||||
EntryPoint = "sysctlbyname",
|
||||
SetLastError = true,
|
||||
StringMarshalling = StringMarshalling.Custom,
|
||||
StringMarshallingCustomType = typeof(AnsiStringMarshaller))]
|
||||
private static partial int OSX_sysctlbyname(string name, IntPtr oldp, IntPtr oldlenp, IntPtr newp, uint newlen);
|
||||
|
||||
/// <summary>Gets the real platform ID, not the incomplete .NET framework one</summary>
|
||||
/// <returns>Platform ID</returns>
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace Aaru.Compression;
|
||||
/// <summary>Implements the Apple version of RLE</summary>
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static class ADC
|
||||
public static partial class ADC
|
||||
{
|
||||
const int PLAIN = 1;
|
||||
const int TWO_BYTE = 2;
|
||||
@@ -53,8 +53,8 @@ public static class ADC
|
||||
/// <summary>Set to <c>true</c> if this algorithm is supported, <c>false</c> otherwise.</summary>
|
||||
public static bool IsSupported => true;
|
||||
|
||||
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
static extern int AARU_adc_decode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer, int srcSize);
|
||||
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
private static partial int AARU_adc_decode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer, int srcSize);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static int GetChunkType(byte byt) => (byt & 0x80) == 0x80
|
||||
|
||||
@@ -36,15 +36,16 @@ using System.Runtime.InteropServices;
|
||||
namespace Aaru.Compression;
|
||||
|
||||
/// <summary>Implements the Apple version of RLE</summary>
|
||||
public static class AppleRle
|
||||
public static partial class AppleRle
|
||||
{
|
||||
const uint DART_CHUNK = 20960;
|
||||
|
||||
/// <summary>Set to <c>true</c> if this algorithm is supported, <c>false</c> otherwise.</summary>
|
||||
public static bool IsSupported => true;
|
||||
|
||||
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
static extern int AARU_apple_rle_decode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer, int srcSize);
|
||||
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
private static partial int AARU_apple_rle_decode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer,
|
||||
int srcSize);
|
||||
|
||||
/// <summary>Decodes a buffer compressed with Apple RLE</summary>
|
||||
/// <param name="source">Encoded buffer</param>
|
||||
|
||||
@@ -33,17 +33,18 @@ using Ionic.BZip2;
|
||||
namespace Aaru.Compression;
|
||||
|
||||
/// <summary>Implements the BZIP2 compression algorithm</summary>
|
||||
public class BZip2
|
||||
public partial class BZip2
|
||||
{
|
||||
/// <summary>Set to <c>true</c> if this algorithm is supported, <c>false</c> otherwise.</summary>
|
||||
public static bool IsSupported => true;
|
||||
|
||||
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
static extern int AARU_bzip2_decode_buffer(byte[] dstBuffer, ref uint dstSize, byte[] srcBuffer, uint srcSize);
|
||||
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
private static partial int AARU_bzip2_decode_buffer(byte[] dstBuffer, ref uint dstSize, byte[] srcBuffer,
|
||||
uint srcSize);
|
||||
|
||||
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
static extern int AARU_bzip2_encode_buffer(byte[] dstBuffer, ref uint dstSize, byte[] srcBuffer, uint srcSize,
|
||||
int blockSize100K);
|
||||
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
private static partial int AARU_bzip2_encode_buffer(byte[] dstBuffer, ref uint dstSize, byte[] srcBuffer,
|
||||
uint srcSize, int blockSize100K);
|
||||
|
||||
/// <summary>Decodes a buffer compressed with BZIP2</summary>
|
||||
/// <param name="source">Encoded buffer</param>
|
||||
|
||||
@@ -36,23 +36,24 @@ namespace Aaru.Compression;
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
/// <summary>Implements the FLAC lossless audio compression algorithm</summary>
|
||||
public class FLAC
|
||||
public partial class FLAC
|
||||
{
|
||||
/// <summary>Set to <c>true</c> if this algorithm is supported, <c>false</c> otherwise.</summary>
|
||||
public static bool IsSupported => true;
|
||||
|
||||
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
static extern nuint AARU_flac_decode_redbook_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
|
||||
nuint srcSize);
|
||||
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
private static partial nuint AARU_flac_decode_redbook_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
|
||||
nuint srcSize);
|
||||
|
||||
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
static extern nuint AARU_flac_encode_redbook_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
|
||||
nuint srcSize, uint blocksize, int doMidSideStereo,
|
||||
int looseMidSideStereo, string apodization, uint maxLpcOrder,
|
||||
uint qlpCoeffPrecision, int doQlpCoeffPrecSearch,
|
||||
int doExhaustiveModelSearch, uint minResidualPartitionOrder,
|
||||
uint maxResidualPartitionOrder, string applicationID,
|
||||
uint applicationIDLen);
|
||||
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
private static partial nuint AARU_flac_encode_redbook_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
|
||||
nuint srcSize, uint blocksize, int doMidSideStereo,
|
||||
int looseMidSideStereo, string apodization,
|
||||
uint maxLpcOrder, uint qlpCoeffPrecision,
|
||||
int doQlpCoeffPrecSearch, int doExhaustiveModelSearch,
|
||||
uint minResidualPartitionOrder,
|
||||
uint maxResidualPartitionOrder, string applicationID,
|
||||
uint applicationIDLen);
|
||||
|
||||
/// <summary>Decodes a buffer compressed with FLAC</summary>
|
||||
/// <param name="source">Encoded buffer</param>
|
||||
|
||||
@@ -32,18 +32,18 @@ namespace Aaru.Compression;
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
/// <summary>Implements the LZFSE compression algorithm</summary>
|
||||
public class LZFSE
|
||||
public partial class LZFSE
|
||||
{
|
||||
/// <summary>Set to <c>true</c> if this algorithm is supported, <c>false</c> otherwise.</summary>
|
||||
public static bool IsSupported => Native.IsSupported;
|
||||
|
||||
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
static extern nuint AARU_lzfse_decode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer, nuint srcSize,
|
||||
byte[] scratchBuffer);
|
||||
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
private static partial nuint AARU_lzfse_decode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
|
||||
nuint srcSize, byte[] scratchBuffer);
|
||||
|
||||
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
static extern nuint AARU_lzfse_encode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer, nuint srcSize,
|
||||
byte[] scratchBuffer);
|
||||
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
private static partial nuint AARU_lzfse_encode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
|
||||
nuint srcSize, byte[] scratchBuffer);
|
||||
|
||||
/// <summary>Decodes a buffer compressed with LZFSE</summary>
|
||||
/// <param name="source">Encoded buffer</param>
|
||||
|
||||
@@ -32,17 +32,17 @@ namespace Aaru.Compression;
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
/// <summary>Implements the LZIP compression algorithm</summary>
|
||||
public class LZIP
|
||||
public partial class LZIP
|
||||
{
|
||||
/// <summary>Set to <c>true</c> if this algorithm is supported, <c>false</c> otherwise.</summary>
|
||||
public static bool IsSupported => Native.IsSupported;
|
||||
|
||||
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
static extern int AARU_lzip_decode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer, int srcSize);
|
||||
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
private static partial int AARU_lzip_decode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer, int srcSize);
|
||||
|
||||
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
static extern int AARU_lzip_encode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer, int srcSize,
|
||||
int dictionarySize, int matchLenLimit);
|
||||
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
private static partial int AARU_lzip_encode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer, int srcSize,
|
||||
int dictionarySize, int matchLenLimit);
|
||||
|
||||
/// <summary>Decodes a buffer compressed with LZIP</summary>
|
||||
/// <param name="source">Encoded buffer</param>
|
||||
|
||||
@@ -34,19 +34,20 @@ using SharpCompress.Compressors.LZMA;
|
||||
namespace Aaru.Compression;
|
||||
|
||||
/// <summary>Implements the LZMA compression algorithm</summary>
|
||||
public class LZMA
|
||||
public partial class LZMA
|
||||
{
|
||||
/// <summary>Set to <c>true</c> if this algorithm is supported, <c>false</c> otherwise.</summary>
|
||||
public static bool IsSupported => true;
|
||||
|
||||
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
static extern int AARU_lzma_decode_buffer(byte[] dstBuffer, ref nuint dstSize, byte[] srcBuffer, ref nuint srcSize,
|
||||
byte[] props, nuint propsSize);
|
||||
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
private static partial int AARU_lzma_decode_buffer(byte[] dstBuffer, ref nuint dstSize, byte[] srcBuffer,
|
||||
ref nuint srcSize, byte[] props, nuint propsSize);
|
||||
|
||||
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
static extern int AARU_lzma_encode_buffer(byte[] dstBuffer, ref nuint dstSize, byte[] srcBuffer, nuint srcSize,
|
||||
byte[] outProps, ref nuint outPropsSize, int level, uint dictSize, int lc,
|
||||
int lp, int pb, int fb, int numThreads);
|
||||
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
private static partial int AARU_lzma_encode_buffer(byte[] dstBuffer, ref nuint dstSize, byte[] srcBuffer,
|
||||
nuint srcSize, byte[] outProps, ref nuint outPropsSize,
|
||||
int level, uint dictSize, int lc, int lp, int pb, int fb,
|
||||
int numThreads);
|
||||
|
||||
/// <summary>Decodes a buffer compressed with LZMA</summary>
|
||||
/// <param name="source">Encoded buffer</param>
|
||||
|
||||
@@ -35,7 +35,7 @@ using System.Runtime.InteropServices;
|
||||
namespace Aaru.Compression;
|
||||
|
||||
/// <summary>Handles native implementations of compression algorithms</summary>
|
||||
public static class Native
|
||||
public static partial class Native
|
||||
{
|
||||
static bool _checked;
|
||||
static bool _supported;
|
||||
@@ -76,6 +76,6 @@ public static class Native
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
static extern ulong AARU_get_acn_version();
|
||||
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
private static partial ulong AARU_get_acn_version();
|
||||
}
|
||||
@@ -32,17 +32,18 @@ namespace Aaru.Compression;
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
/// <summary>Implements the zstandard compression algorithm</summary>
|
||||
public class ZSTD
|
||||
public partial class ZSTD
|
||||
{
|
||||
/// <summary>Set to <c>true</c> if this algorithm is supported, <c>false</c> otherwise.</summary>
|
||||
public static bool IsSupported => Native.IsSupported;
|
||||
|
||||
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
static extern nuint AARU_zstd_decode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer, nuint srcSize);
|
||||
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
private static partial nuint AARU_zstd_decode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
|
||||
nuint srcSize);
|
||||
|
||||
[DllImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
static extern nuint AARU_zstd_encode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer, nuint srcSize,
|
||||
int compressionLevel);
|
||||
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
|
||||
private static partial nuint AARU_zstd_encode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
|
||||
nuint srcSize, int compressionLevel);
|
||||
|
||||
/// <summary>Decodes a buffer compressed with ZSTD</summary>
|
||||
/// <param name="source">Encoded buffer</param>
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<Authors>Natalia Portillo <claunia@claunia.com></Authors>
|
||||
<DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
|
||||
@@ -32,47 +32,64 @@
|
||||
// ****************************************************************************/
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.Marshalling;
|
||||
|
||||
namespace Aaru.Devices.Linux;
|
||||
|
||||
static class Extern
|
||||
static partial class Extern
|
||||
{
|
||||
[DllImport("libc", CharSet = CharSet.Ansi, SetLastError = true)]
|
||||
internal static extern int open(string pathname, [MarshalAs(UnmanagedType.U4)] FileFlags flags);
|
||||
[LibraryImport("libc",
|
||||
SetLastError = true,
|
||||
StringMarshalling = StringMarshalling.Custom,
|
||||
StringMarshallingCustomType = typeof(AnsiStringMarshaller))]
|
||||
internal static partial int open(string pathname, [MarshalAs(UnmanagedType.U4)] FileFlags flags);
|
||||
|
||||
[DllImport("libc")]
|
||||
internal static extern int close(int fd);
|
||||
[LibraryImport("libc")]
|
||||
internal static partial int close(int fd);
|
||||
|
||||
[DllImport("libc", EntryPoint = "ioctl", SetLastError = true)]
|
||||
internal static extern int ioctlSg(int fd, LinuxIoctl request, ref SgIoHdrT value);
|
||||
[LibraryImport("libc", EntryPoint = "ioctl", SetLastError = true)]
|
||||
internal static partial int ioctlSg(int fd, LinuxIoctl request, ref SgIoHdrT value);
|
||||
|
||||
[DllImport("libc", EntryPoint = "ioctl", SetLastError = true)]
|
||||
internal static extern int ioctlMmc(int fd, LinuxIoctl request, ref MmcIocCmd value);
|
||||
[LibraryImport("libc", EntryPoint = "ioctl", SetLastError = true)]
|
||||
internal static partial int ioctlMmc(int fd, LinuxIoctl request, ref MmcIocCmd value);
|
||||
|
||||
[DllImport("libc", CharSet = CharSet.Ansi, SetLastError = true)]
|
||||
internal static extern int readlink(string path, nint buf, int bufsize);
|
||||
[LibraryImport("libc",
|
||||
SetLastError = true,
|
||||
StringMarshalling = StringMarshalling.Custom,
|
||||
StringMarshallingCustomType = typeof(AnsiStringMarshaller))]
|
||||
internal static partial int readlink(string path, nint buf, int bufsize);
|
||||
|
||||
[DllImport("libc", CharSet = CharSet.Ansi, EntryPoint = "readlink", SetLastError = true)]
|
||||
internal static extern long readlink64(string path, nint buf, long bufsize);
|
||||
[LibraryImport("libc",
|
||||
EntryPoint = "readlink",
|
||||
SetLastError = true,
|
||||
StringMarshalling = StringMarshalling.Custom,
|
||||
StringMarshallingCustomType = typeof(AnsiStringMarshaller))]
|
||||
internal static partial long readlink64(string path, nint buf, long bufsize);
|
||||
|
||||
[DllImport("libudev", CharSet = CharSet.Ansi, SetLastError = true)]
|
||||
internal static extern nint udev_new();
|
||||
[LibraryImport("libudev", SetLastError = true)]
|
||||
internal static partial nint udev_new();
|
||||
|
||||
[DllImport("libudev", CharSet = CharSet.Ansi, SetLastError = true)]
|
||||
internal static extern nint udev_device_new_from_subsystem_sysname(nint udev, string subsystem, string sysname);
|
||||
[LibraryImport("libudev",
|
||||
SetLastError = true,
|
||||
StringMarshalling = StringMarshalling.Custom,
|
||||
StringMarshallingCustomType = typeof(AnsiStringMarshaller))]
|
||||
internal static partial nint udev_device_new_from_subsystem_sysname(nint udev, string subsystem, string sysname);
|
||||
|
||||
[DllImport("libudev", CharSet = CharSet.Ansi, SetLastError = true)]
|
||||
internal static extern string udev_device_get_property_value(nint udevDevice, string key);
|
||||
[LibraryImport("libudev",
|
||||
SetLastError = true,
|
||||
StringMarshalling = StringMarshalling.Custom,
|
||||
StringMarshallingCustomType = typeof(AnsiStringMarshaller))]
|
||||
internal static partial string udev_device_get_property_value(nint udevDevice, string key);
|
||||
|
||||
[DllImport("libc", EntryPoint = "ioctl", SetLastError = true)]
|
||||
internal static extern int ioctlMmcMulti(int fd, LinuxIoctl request, nint value);
|
||||
[LibraryImport("libc", EntryPoint = "ioctl", SetLastError = true)]
|
||||
internal static partial int ioctlMmcMulti(int fd, LinuxIoctl request, nint value);
|
||||
|
||||
[DllImport("libc", SetLastError = true)]
|
||||
internal static extern long lseek(int fd, long offset, SeekWhence whence);
|
||||
[LibraryImport("libc", SetLastError = true)]
|
||||
internal static partial long lseek(int fd, long offset, SeekWhence whence);
|
||||
|
||||
[DllImport("libc", SetLastError = true)]
|
||||
internal static extern int read(int fd, byte[] buf, int count);
|
||||
[LibraryImport("libc", SetLastError = true)]
|
||||
internal static partial int read(int fd, byte[] buf, int count);
|
||||
|
||||
[DllImport("libc", EntryPoint = "read", SetLastError = true)]
|
||||
internal static extern long read64(int fd, byte[] buf, long count);
|
||||
[LibraryImport("libc", EntryPoint = "read", SetLastError = true)]
|
||||
internal static partial long read64(int fd, byte[] buf, long count);
|
||||
}
|
||||
@@ -39,85 +39,101 @@ using Microsoft.Win32.SafeHandles;
|
||||
namespace Aaru.Devices.Windows;
|
||||
|
||||
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||
static class Extern
|
||||
static partial class Extern
|
||||
{
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
internal static extern 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 = "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);
|
||||
|
||||
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
|
||||
internal static extern 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 DeviceIoControlScsi(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
|
||||
ref ScsiPassThroughDirectAndSenseBuffer inBuffer,
|
||||
uint nInBufferSize,
|
||||
ref ScsiPassThroughDirectAndSenseBuffer outBuffer,
|
||||
uint nOutBufferSize, ref uint pBytesReturned, nint overlapped);
|
||||
|
||||
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
|
||||
internal static extern 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 DeviceIoControlAta(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
|
||||
ref AtaPassThroughDirect inBuffer, uint nInBufferSize,
|
||||
ref AtaPassThroughDirect outBuffer, uint nOutBufferSize,
|
||||
ref uint pBytesReturned, nint overlapped);
|
||||
|
||||
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
|
||||
internal static extern 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 DeviceIoControlStorageQuery(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
|
||||
ref StoragePropertyQuery inBuffer, uint nInBufferSize,
|
||||
nint outBuffer, uint nOutBufferSize,
|
||||
ref uint pBytesReturned, nint overlapped);
|
||||
|
||||
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
|
||||
internal static extern 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 DeviceIoControlIde(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
|
||||
ref IdePassThroughDirect inBuffer, uint nInBufferSize,
|
||||
ref IdePassThroughDirect outBuffer, uint nOutBufferSize,
|
||||
ref uint pBytesReturned, nint overlapped);
|
||||
|
||||
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
|
||||
internal static extern 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 DeviceIoControlGetDeviceNumber(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
|
||||
nint inBuffer, uint nInBufferSize,
|
||||
ref StorageDeviceNumber outBuffer, uint nOutBufferSize,
|
||||
ref uint pBytesReturned, nint overlapped);
|
||||
|
||||
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
|
||||
internal static extern 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, nint inBuffer,
|
||||
uint nInBufferSize, ref SffdiskQueryDeviceProtocolData outBuffer,
|
||||
uint nOutBufferSize, out uint pBytesReturned, nint overlapped);
|
||||
|
||||
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
|
||||
internal static extern bool DeviceIoControl(SafeFileHandle hDevice, WindowsIoctl ioControlCode, byte[] inBuffer,
|
||||
uint nInBufferSize, byte[] 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);
|
||||
|
||||
[DllImport("setupapi.dll", CharSet = CharSet.Auto)]
|
||||
internal static extern SafeFileHandle SetupDiGetClassDevs(ref Guid classGuid, nint enumerator, nint hwndParent,
|
||||
DeviceGetClassFlags flags);
|
||||
[LibraryImport("setupapi.dll", EntryPoint = "SetupDiGetClassDevsW")]
|
||||
internal static partial SafeFileHandle SetupDiGetClassDevs(ref Guid classGuid, nint enumerator, nint hwndParent,
|
||||
DeviceGetClassFlags flags);
|
||||
|
||||
[DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern bool SetupDiEnumDeviceInterfaces(SafeFileHandle hDevInfo, nint devInfo,
|
||||
ref Guid interfaceClassGuid, uint memberIndex,
|
||||
ref DeviceInterfaceData deviceInterfaceData);
|
||||
[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);
|
||||
|
||||
[DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern bool SetupDiGetDeviceInterfaceDetail(SafeFileHandle hDevInfo,
|
||||
ref DeviceInterfaceData deviceInterfaceData,
|
||||
nint deviceInterfaceDetailData,
|
||||
uint deviceInterfaceDetailDataSize, ref uint requiredSize,
|
||||
nint deviceInfoData);
|
||||
[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);
|
||||
|
||||
[DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern bool SetupDiDestroyDeviceInfoList(SafeFileHandle hDevInfo);
|
||||
[LibraryImport("setupapi.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static partial bool SetupDiDestroyDeviceInfoList(SafeFileHandle hDevInfo);
|
||||
|
||||
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
internal static extern bool CloseHandle(SafeFileHandle hDevice);
|
||||
[LibraryImport("Kernel32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static partial bool CloseHandle(SafeFileHandle hDevice);
|
||||
|
||||
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern bool SetFilePointerEx(SafeFileHandle hFile, long liDistanceToMove, out long lpNewFilePointer,
|
||||
MoveMethod dwMoveMethod);
|
||||
[LibraryImport("Kernel32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static partial bool SetFilePointerEx(SafeFileHandle hFile, long liDistanceToMove, out long lpNewFilePointer,
|
||||
MoveMethod dwMoveMethod);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern bool ReadFile(SafeFileHandle hFile, byte[] lpBuffer, uint nNumberOfBytesToRead,
|
||||
out uint lpNumberOfBytesRead, nint lpOverlapped);
|
||||
[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);
|
||||
}
|
||||
@@ -1170,54 +1170,76 @@ static partial class Usb
|
||||
|
||||
// ********************** API Definitions ************************
|
||||
|
||||
[DllImport("setupapi.dll", CharSet = CharSet.Auto)]
|
||||
static extern IntPtr SetupDiGetClassDevs( // 1st form using a ClassGUID
|
||||
[LibraryImport("setupapi.dll", EntryPoint = "SetupDiGetClassDevsW")]
|
||||
private static partial IntPtr SetupDiGetClassDevs( // 1st form using a ClassGUID
|
||||
ref Guid classGuid, int enumerator, IntPtr hwndParent, int flags);
|
||||
|
||||
[DllImport("setupapi.dll", CharSet = CharSet.Auto)] // 2nd form uses an Enumerator
|
||||
static extern IntPtr SetupDiGetClassDevs(int classGuid, string enumerator, IntPtr hwndParent, int flags);
|
||||
[LibraryImport("setupapi.dll",
|
||||
EntryPoint = "SetupDiGetClassDevsW",
|
||||
StringMarshalling = StringMarshalling.Utf16)] // 2nd form uses an Enumerator
|
||||
private static partial IntPtr SetupDiGetClassDevs(int classGuid, string enumerator,
|
||||
IntPtr hwndParent, int flags);
|
||||
|
||||
[DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
static extern bool SetupDiEnumDeviceInterfaces(IntPtr deviceInfoSet, IntPtr deviceInfoData,
|
||||
ref Guid interfaceClassGuid, int memberIndex,
|
||||
ref SpDeviceInterfaceData deviceInterfaceData);
|
||||
[LibraryImport("setupapi.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static partial bool SetupDiEnumDeviceInterfaces(IntPtr deviceInfoSet, IntPtr deviceInfoData,
|
||||
ref Guid interfaceClassGuid, int memberIndex,
|
||||
ref SpDeviceInterfaceData
|
||||
deviceInterfaceData);
|
||||
|
||||
[DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
static extern bool SetupDiGetDeviceInterfaceDetail(IntPtr deviceInfoSet,
|
||||
ref SpDeviceInterfaceData deviceInterfaceData,
|
||||
ref SpDeviceInterfaceDetailData deviceInterfaceDetailData,
|
||||
int deviceInterfaceDetailDataSize, ref int requiredSize,
|
||||
ref SpDevinfoData deviceInfoData);
|
||||
[LibraryImport("setupapi.dll", EntryPoint = "SetupDiGetDeviceInterfaceDetailW", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static partial bool SetupDiGetDeviceInterfaceDetail(IntPtr deviceInfoSet,
|
||||
ref SpDeviceInterfaceData
|
||||
deviceInterfaceData,
|
||||
ref SpDeviceInterfaceDetailData
|
||||
deviceInterfaceDetailData,
|
||||
int deviceInterfaceDetailDataSize,
|
||||
ref int requiredSize,
|
||||
ref SpDevinfoData deviceInfoData);
|
||||
|
||||
[DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
static extern bool SetupDiGetDeviceRegistryProperty(IntPtr deviceInfoSet, ref SpDevinfoData deviceInfoData,
|
||||
int iProperty, ref int propertyRegDataType,
|
||||
IntPtr propertyBuffer, int propertyBufferSize,
|
||||
ref int requiredSize);
|
||||
[LibraryImport("setupapi.dll",
|
||||
EntryPoint = "SetupDiGetDeviceRegistryPropertyW",
|
||||
SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static partial bool SetupDiGetDeviceRegistryProperty(
|
||||
IntPtr deviceInfoSet, ref SpDevinfoData deviceInfoData, int iProperty,
|
||||
ref int propertyRegDataType, IntPtr propertyBuffer, int propertyBufferSize,
|
||||
ref int requiredSize);
|
||||
|
||||
[DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
static extern bool SetupDiEnumDeviceInfo(IntPtr deviceInfoSet, int memberIndex, ref SpDevinfoData deviceInfoData);
|
||||
[LibraryImport("setupapi.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static partial bool SetupDiEnumDeviceInfo(IntPtr deviceInfoSet, int memberIndex,
|
||||
ref SpDevinfoData deviceInfoData);
|
||||
|
||||
[DllImport("setupapi.dll", SetLastError = true)]
|
||||
static extern bool SetupDiDestroyDeviceInfoList(IntPtr deviceInfoSet);
|
||||
[LibraryImport("setupapi.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static partial bool SetupDiDestroyDeviceInfoList(IntPtr deviceInfoSet);
|
||||
|
||||
[DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
static extern bool SetupDiGetDeviceInstanceId(IntPtr deviceInfoSet, ref SpDevinfoData deviceInfoData,
|
||||
StringBuilder deviceInstanceId, int deviceInstanceIdSize,
|
||||
out int requiredSize);
|
||||
[LibraryImport("setupapi.dll", EntryPoint = "SetupDiGetDeviceInstanceIdW", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static partial bool SetupDiGetDeviceInstanceId(
|
||||
IntPtr deviceInfoSet, ref SpDevinfoData deviceInfoData, StringBuilder deviceInstanceId,
|
||||
int deviceInstanceIdSize, out int requiredSize);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
static extern bool DeviceIoControl(IntPtr hDevice, int dwIoControlCode, IntPtr lpInBuffer, int nInBufferSize,
|
||||
IntPtr lpOutBuffer, int nOutBufferSize, out int lpBytesReturned,
|
||||
IntPtr lpOverlapped);
|
||||
[LibraryImport("kernel32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static partial bool DeviceIoControl(IntPtr hDevice, int dwIoControlCode, IntPtr lpInBuffer,
|
||||
int nInBufferSize, IntPtr lpOutBuffer,
|
||||
int nOutBufferSize, out int lpBytesReturned,
|
||||
IntPtr lpOverlapped);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
static extern IntPtr CreateFile(string lpFileName, int dwDesiredAccess, int dwShareMode,
|
||||
IntPtr lpSecurityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes,
|
||||
IntPtr hTemplateFile);
|
||||
[LibraryImport("kernel32.dll",
|
||||
EntryPoint = "CreateFileW",
|
||||
SetLastError = true,
|
||||
StringMarshalling = StringMarshalling.Utf16)]
|
||||
private static partial IntPtr CreateFile(string lpFileName, int dwDesiredAccess, int dwShareMode,
|
||||
IntPtr lpSecurityAttributes, int dwCreationDisposition,
|
||||
int dwFlagsAndAttributes, IntPtr hTemplateFile);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
static extern bool CloseHandle(IntPtr hObject);
|
||||
[LibraryImport("kernel32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static partial bool CloseHandle(IntPtr hObject);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -164,11 +164,11 @@ static partial class Usb
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("setupapi.dll")]
|
||||
static extern int CM_Get_Parent(out uint pdnDevInst, uint dnDevInst, int ulFlags);
|
||||
[LibraryImport("setupapi.dll")]
|
||||
private static partial int CM_Get_Parent(out uint pdnDevInst, uint dnDevInst, int ulFlags);
|
||||
|
||||
[DllImport("setupapi.dll", CharSet = CharSet.Auto)]
|
||||
static extern int CM_Get_Device_ID(uint dnDevInst, IntPtr buffer, int bufferLen, int ulFlags);
|
||||
[LibraryImport("setupapi.dll", EntryPoint = "CM_Get_Device_IDW")]
|
||||
private static partial int CM_Get_Device_ID(uint dnDevInst, IntPtr buffer, int bufferLen, int ulFlags);
|
||||
|
||||
/// <summary>Find a device based upon a Drive Letter</summary>
|
||||
/// <param name="driveLetter">Drive letter</param>
|
||||
|
||||
Reference in New Issue
Block a user