Added runtime CPU detection for SSE2 capability to the GUI front-end.
This commit is contained in:
parent
9f5e1faf6d
commit
17d807bbb3
BIN
etc/deps/cpu-capabilities/cpu-capabilities-x64.dll
Normal file
BIN
etc/deps/cpu-capabilities/cpu-capabilities-x64.dll
Normal file
Binary file not shown.
BIN
etc/deps/cpu-capabilities/cpu-capabilities-x86.dll
Normal file
BIN
etc/deps/cpu-capabilities/cpu-capabilities-x86.dll
Normal file
Binary file not shown.
@ -209,7 +209,7 @@
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<OutDir>$(SolutionDir)bin\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)obj\$(Configuration)\$(PlatformShortName)\$(ProjectName)\</IntDir>
|
||||
<TargetName>slunkcrypt-cli-$(PlatformShortName)</TargetName>
|
||||
<TargetName>slunkcrypt-cli-$(PlatformShortName)-sse2</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_WithDbgInfo|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
@ -239,7 +239,7 @@
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<OutDir>$(SolutionDir)bin\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)obj\$(Configuration)\$(PlatformShortName)\$(ProjectName)\</IntDir>
|
||||
<TargetName>slunkcrypt-cli-$(PlatformShortName)</TargetName>
|
||||
<TargetName>slunkcrypt-cli-$(PlatformShortName)-sse2</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_WithDbgInfo|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
@ -421,6 +421,7 @@
|
||||
<FloatingPointModel>Fast</FloatingPointModel>
|
||||
<DisableSpecificWarnings>4706;4204</DisableSpecificWarnings>
|
||||
<CreateHotpatchableImage>false</CreateHotpatchableImage>
|
||||
<EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
@ -25,6 +25,7 @@ namespace com.muldersoft.slunkcrypt.gui.process
|
||||
private const string COMMAND_DECRYPT = "-d";
|
||||
|
||||
private static readonly Regex RX_PROGRESS = new Regex(@"(\d+)\.(\d)%", RegexOptions.Compiled);
|
||||
|
||||
private readonly FileStream m_executableFile;
|
||||
|
||||
// =============================================================================
|
||||
@ -77,15 +78,20 @@ namespace com.muldersoft.slunkcrypt.gui.process
|
||||
{
|
||||
FileStream executableFile = null;
|
||||
string appBaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
||||
if (Environment.Is64BitOperatingSystem)
|
||||
{
|
||||
if (CheckExecutableFile(ref executableFile, appBaseDirectory, "x64"))
|
||||
CPUFeatures cpuFeatures = CPUFeatures.Features;
|
||||
if (cpuFeatures.x64 && CheckExecutableFile(ref executableFile, appBaseDirectory, "x64"))
|
||||
{
|
||||
Trace.Assert(executableFile != null);
|
||||
return executableFile;
|
||||
}
|
||||
if (cpuFeatures.sse2 && CheckExecutableFile(ref executableFile, appBaseDirectory, "x86-sse2"))
|
||||
{
|
||||
Trace.Assert(executableFile != null);
|
||||
return executableFile;
|
||||
}
|
||||
if (CheckExecutableFile(ref executableFile, appBaseDirectory, "x86"))
|
||||
{
|
||||
Trace.Assert(executableFile != null);
|
||||
return executableFile;
|
||||
}
|
||||
throw new ExecutableNotFoundException("SlunkCrypt executable file not found!", FILENAME_FORMAT);
|
||||
@ -140,7 +146,7 @@ namespace com.muldersoft.slunkcrypt.gui.process
|
||||
return double.NaN;
|
||||
}
|
||||
|
||||
private string GetCommandString(Mode mode)
|
||||
private static string GetCommandString(Mode mode)
|
||||
{
|
||||
switch(mode)
|
||||
{
|
||||
|
@ -19,5 +19,5 @@ using System.Windows;
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
|
||||
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyVersion("1.1.*")]
|
||||
[assembly: AssemblyFileVersion("1.1.0.0")]
|
||||
|
@ -79,8 +79,10 @@
|
||||
<Compile Include="Controls\PasswordToggleBox.xaml.cs">
|
||||
<DependentUpon>PasswordToggleBox.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Utilities\CPUFeatures.cs" />
|
||||
<Compile Include="Process\SlunkCryptRunner.cs" />
|
||||
<Compile Include="Utilities\BusyManager.cs" />
|
||||
<Compile Include="Utilities\CPU\CPUCapabilities.cs" />
|
||||
<Compile Include="Utilities\PathUtils.cs" />
|
||||
<Compile Include="Utilities\SecureRandom.cs" />
|
||||
<Compile Include="Utilities\SystemMenu.cs" />
|
||||
@ -187,6 +189,9 @@
|
||||
<Resource Include="Resources\Refresh.png" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>copy /Y "$(SolutionDir)\etc\deps\cpu-capabilities\*.dll" "$(TargetDir)"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
|
@ -58,9 +58,9 @@ namespace com.muldersoft.slunkcrypt.gui
|
||||
{
|
||||
InitializeComponent();
|
||||
m_defaultStatusText = Label_Status.Text;
|
||||
m_dispatcherTimer = new DispatcherTimer(DispatcherPriority.ApplicationIdle, Dispatcher);
|
||||
m_dispatcherTimer = new DispatcherTimer(DispatcherPriority.SystemIdle, Dispatcher);
|
||||
m_dispatcherTimer.Tick += DispatcherTimer_Tick;
|
||||
m_dispatcherTimer.Interval = TimeSpan.FromMilliseconds(150);
|
||||
m_dispatcherTimer.Interval = TimeSpan.FromMilliseconds(125);
|
||||
m_logFileReadOnly = new ReadOnlyObservableCollection<string>(m_logFile);
|
||||
}
|
||||
|
||||
@ -794,6 +794,7 @@ namespace com.muldersoft.slunkcrypt.gui
|
||||
|
||||
private static string CreateAboutText()
|
||||
{
|
||||
CPUFeatures cpuFeatures = CPUFeatures.Features;
|
||||
return new StringBuilder()
|
||||
.AppendLine("SlunkCrypt, by LoRd_MuldeR <MuldeR2@GMX.de>")
|
||||
.AppendLine(VersionInfo.VersionStr)
|
||||
@ -803,10 +804,11 @@ namespace com.muldersoft.slunkcrypt.gui
|
||||
.AppendLine("https://gitlab.com/lord_mulder/slunkcrypt/")
|
||||
.AppendLine()
|
||||
.AppendLine("Operating System: " + Environment.OSVersion.VersionString)
|
||||
.AppendLine(string.Format("Operating System Bitness: {0:D}, Process Bitness: {1:D}", Environment.Is64BitOperatingSystem ? 64 : 32, Environment.Is64BitProcess ? 64 : 32))
|
||||
.AppendLine(".NET Runtime Version: " + Environment.Version)
|
||||
.AppendLine(string.Format("Processor Count: {0:D}, System Bitness: {1:D}, Process Bitness: {2:D}", Environment.ProcessorCount, Environment.Is64BitOperatingSystem ? 64 : 32, Environment.Is64BitProcess ? 64 : 32))
|
||||
.AppendLine(string.Format("CPU Count: {0:D}, Architecture: {1}, SSE2 Supported: {2}", Environment.ProcessorCount, cpuFeatures.x64 ? "x64" : "x86", cpuFeatures.sse2 ? "Yes" : "No"))
|
||||
.AppendLine()
|
||||
.AppendLine("Using “Silk” icons, by Mark James (famfamfam.com)")
|
||||
.AppendLine("Using “Silk” icons, by Mark James")
|
||||
.ToString();
|
||||
}
|
||||
|
||||
@ -976,10 +978,5 @@ namespace com.muldersoft.slunkcrypt.gui
|
||||
Keyboard.ClearFocus();
|
||||
element.Focus();
|
||||
}
|
||||
|
||||
private static string TrimToEmpty(string str)
|
||||
{
|
||||
return string.IsNullOrEmpty(str) ? string.Empty : str.Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
378
gui/Utilities/CPU/CPUCapabilities.cs
Normal file
378
gui/Utilities/CPU/CPUCapabilities.cs
Normal file
@ -0,0 +1,378 @@
|
||||
/******************************************************************************/
|
||||
/* CPUCapabilities.NET, by LoRd_MuldeR <MuldeR2@GMX.de> */
|
||||
/* This work has been released under the CC0 1.0 Universal license! */
|
||||
/******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace com.muldersoft.slunkcrypt.gui.utils.cpu
|
||||
{
|
||||
// ==================================================================
|
||||
// CPU Flags
|
||||
// ==================================================================
|
||||
|
||||
public enum CPUArchitecture : uint
|
||||
{
|
||||
CPU_ARCH_X86 = 0x00000001,
|
||||
CPU_ARCH_X64 = 0x00000002
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum CPUCapabilities : ulong
|
||||
{
|
||||
CPU_3DNOW = 0x0000000000000001,
|
||||
CPU_3DNOWEXT = 0x0000000000000002,
|
||||
CPU_ADX = 0x0000000000000004,
|
||||
CPU_AES = 0x0000000000000008,
|
||||
CPU_AVX = 0x0000000000000010,
|
||||
CPU_AVX2 = 0x0000000000000020,
|
||||
CPU_AVX512_BITALG = 0x0000000000000040,
|
||||
CPU_AVX512_BW = 0x0000000000000080,
|
||||
CPU_AVX512_CD = 0x0000000000000100,
|
||||
CPU_AVX512_DQ = 0x0000000000000200,
|
||||
CPU_AVX512_ER = 0x0000000000000400,
|
||||
CPU_AVX512_F = 0x0000000000000800,
|
||||
CPU_AVX512_IFMA = 0x0000000000001000,
|
||||
CPU_AVX512_PF = 0x0000000000002000,
|
||||
CPU_AVX512_VBMI = 0x0000000000004000,
|
||||
CPU_AVX512_VBMI2 = 0x0000000000008000,
|
||||
CPU_AVX512_VL = 0x0000000000010000,
|
||||
CPU_AVX512_VNNI = 0x0000000000020000,
|
||||
CPU_AVX512_VPOPCNTDQ = 0x0000000000040000,
|
||||
CPU_BMI1 = 0x0000000000080000,
|
||||
CPU_BMI2 = 0x0000000000100000,
|
||||
CPU_CLFSH = 0x0000000000200000,
|
||||
CPU_CMOV = 0x0000000000400000,
|
||||
CPU_CX16 = 0x0000000000800000,
|
||||
CPU_CX8 = 0x0000000001000000,
|
||||
CPU_ERMS = 0x0000000002000000,
|
||||
CPU_FMA3 = 0x0000000004000000,
|
||||
CPU_FMA4 = 0x0000000008000000,
|
||||
CPU_FPU = 0x0000000010000000,
|
||||
CPU_FSGSBASE = 0x0000000020000000,
|
||||
CPU_FXSR = 0x0000000040000000,
|
||||
CPU_HLE = 0x0000000080000000,
|
||||
CPU_HTT = 0x0000000100000000,
|
||||
CPU_INVPCID = 0x0000000200000000,
|
||||
CPU_LAHF = 0x0000000400000000,
|
||||
CPU_LZCNT = 0x0000000800000000,
|
||||
CPU_MMX = 0x0000001000000000,
|
||||
CPU_MMXEXT = 0x0000002000000000,
|
||||
CPU_MONITOR = 0x0000004000000000,
|
||||
CPU_MOVBE = 0x0000008000000000,
|
||||
CPU_MSR = 0x0000010000000000,
|
||||
CPU_OSXSAVE = 0x0000020000000000,
|
||||
CPU_PCLMULQDQ = 0x0000040000000000,
|
||||
CPU_POPCNT = 0x0000080000000000,
|
||||
CPU_PREFETCHWT1 = 0x0000100000000000,
|
||||
CPU_RDRND = 0x0000200000000000,
|
||||
CPU_RDSEED = 0x0000400000000000,
|
||||
CPU_RDTSCP = 0x0000800000000000,
|
||||
CPU_RTM = 0x0001000000000000,
|
||||
CPU_SEP = 0x0002000000000000,
|
||||
CPU_SHA = 0x0004000000000000,
|
||||
CPU_SSE = 0x0008000000000000,
|
||||
CPU_SSE2 = 0x0010000000000000,
|
||||
CPU_SSE3 = 0x0020000000000000,
|
||||
CPU_SSE41 = 0x0040000000000000,
|
||||
CPU_SSE42 = 0x0080000000000000,
|
||||
CPU_SSE4a = 0x0100000000000000,
|
||||
CPU_SSSE3 = 0x0200000000000000,
|
||||
CPU_SYSCALL = 0x0400000000000000,
|
||||
CPU_TBM = 0x0800000000000000,
|
||||
CPU_TSC = 0x1000000000000000,
|
||||
CPU_XOP = 0x2000000000000000,
|
||||
CPU_XSAVE = 0x4000000000000000
|
||||
}
|
||||
|
||||
// ==================================================================
|
||||
// CPUInformation
|
||||
// ==================================================================
|
||||
|
||||
public struct CPUInformation
|
||||
{
|
||||
public CPUInformation(byte type, byte familyExt, byte family, byte modelExt, byte model, byte stepping)
|
||||
{
|
||||
Type = type;
|
||||
RawFamily = family;
|
||||
RawFamilyExt = familyExt;
|
||||
RawModel = model;
|
||||
RawModelExt = modelExt;
|
||||
Stepping = stepping;
|
||||
}
|
||||
|
||||
public byte Type { get; }
|
||||
public byte RawFamily { get; }
|
||||
public byte RawFamilyExt { get; }
|
||||
public byte RawModel { get; }
|
||||
public byte RawModelExt { get; }
|
||||
public byte Stepping { get; }
|
||||
|
||||
public uint Family
|
||||
{
|
||||
get { return (RawFamily == 15U) ? (((uint)RawFamilyExt) + RawFamily) : RawFamily; }
|
||||
}
|
||||
|
||||
public uint Model
|
||||
{
|
||||
get { return ((RawFamily == 6U) || (RawFamily == 15U)) ? ((((uint)RawModelExt) << 4) + RawModel) : RawModel; }
|
||||
}
|
||||
|
||||
public override String ToString()
|
||||
{
|
||||
return String.Format("Type={0}, Family={1}, Model={2}, Stepping={3}", Type, Family, Model, Stepping);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================================================================
|
||||
// CPU class
|
||||
// ==================================================================
|
||||
|
||||
public static class CPU
|
||||
{
|
||||
private static readonly Lazy<bool> m_x64Process = new Lazy<bool>(() => Environment.Is64BitProcess);
|
||||
private static readonly Lazy<CPUArchitecture> m_architecture = new Lazy<CPUArchitecture>(GetCPUArchitecture);
|
||||
private static readonly Lazy<uint> m_count = new Lazy<uint>(GetCPUCount);
|
||||
private static readonly Lazy<CPUInformation> m_information = new Lazy<CPUInformation>(GetCPUInformation);
|
||||
private static readonly Lazy<string> m_vendor = new Lazy<string>(GetCPUVendorString);
|
||||
private static readonly Lazy<CPUCapabilities> m_capabilities = new Lazy<CPUCapabilities>(GetCPUCapabilities);
|
||||
private static readonly Lazy<Tuple<ushort, ushort>> m_libraryVersion = new Lazy<Tuple<ushort, ushort>>(GetCPULibraryVersion);
|
||||
private static readonly Lazy<string> m_brand = new Lazy<string>(GetCPUBrandString);
|
||||
|
||||
private static readonly Tuple<ushort, ushort> REQUIRED_LIBRARY_VERSION = Tuple.Create<ushort, ushort>(2, 0);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Properties
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
public static bool IsX64Process
|
||||
{
|
||||
get { return m_x64Process.Value; }
|
||||
}
|
||||
|
||||
public static CPUArchitecture Architecture
|
||||
{
|
||||
get { return m_architecture.Value; }
|
||||
}
|
||||
|
||||
public static uint Count
|
||||
{
|
||||
get { return m_count.Value; }
|
||||
}
|
||||
|
||||
public static string Vendor
|
||||
{
|
||||
get { return m_vendor.Value; }
|
||||
}
|
||||
|
||||
public static CPUInformation Information
|
||||
{
|
||||
get { return m_information.Value; }
|
||||
}
|
||||
|
||||
public static CPUCapabilities Capabilities
|
||||
{
|
||||
get { return m_capabilities.Value; }
|
||||
}
|
||||
|
||||
public static string Brand
|
||||
{
|
||||
get { return m_brand.Value; }
|
||||
}
|
||||
|
||||
public static Tuple<ushort, ushort> LibraryVersion
|
||||
{
|
||||
get { return m_libraryVersion.Value; }
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Initialization methods
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
private static CPUArchitecture GetCPUArchitecture()
|
||||
{
|
||||
try
|
||||
{
|
||||
VerifyLibraryVersion();
|
||||
uint value = IsX64Process ? Internal.GetCPUArchitectureX64() : Internal.GetCPUArchitectureX86();
|
||||
return (CPUArchitecture)value;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new SystemException("Failed to determine CPU architecture!", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static uint GetCPUCount()
|
||||
{
|
||||
try
|
||||
{
|
||||
VerifyLibraryVersion();
|
||||
return IsX64Process ? Internal.GetCPUCountX64() : Internal.GetCPUCountX86();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new SystemException("Failed to determine CPU count!", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetCPUVendorString()
|
||||
{
|
||||
const uint BUFFER_SIZE = 13;
|
||||
try
|
||||
{
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
VerifyLibraryVersion();
|
||||
if (IsX64Process ? Internal.GetCPUVendorStringX64(buffer, BUFFER_SIZE) : Internal.GetCPUVendorStringX86(buffer, BUFFER_SIZE))
|
||||
{
|
||||
return AllocateAsciiString(buffer);
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new SystemException("Failed to determine CPU vendor string!", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static CPUInformation GetCPUInformation()
|
||||
{
|
||||
try
|
||||
{
|
||||
byte type, familyExt, family, modelExt, model, stepping;
|
||||
VerifyLibraryVersion();
|
||||
if (IsX64Process ? Internal.GetCPUInformationX64(out type, out familyExt, out family, out modelExt, out model, out stepping) : Internal.GetCPUInformationX86(out type, out familyExt, out family, out modelExt, out model, out stepping))
|
||||
{
|
||||
return new CPUInformation(type, familyExt, family, modelExt, model, stepping);
|
||||
}
|
||||
return new CPUInformation(0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new SystemException("Failed to determine CPU family and model!", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static CPUCapabilities GetCPUCapabilities()
|
||||
{
|
||||
try
|
||||
{
|
||||
VerifyLibraryVersion();
|
||||
ulong value = IsX64Process ? Internal.GetCPUCapabilitiesX64() : Internal.GetCPUCapabilitiesX86();
|
||||
return (CPUCapabilities)value;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new SystemException("Failed to determine CPU capabilities!", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetCPUBrandString()
|
||||
{
|
||||
const uint BUFFER_SIZE = 48;
|
||||
try
|
||||
{
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
VerifyLibraryVersion();
|
||||
if (IsX64Process ? Internal.GetCPUBrandStringX64(buffer, BUFFER_SIZE) : Internal.GetCPUBrandStringX86(buffer, BUFFER_SIZE))
|
||||
{
|
||||
return AllocateAsciiString(buffer);
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new SystemException("Failed to determine CPU brand string!", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static Tuple<ushort, ushort> GetCPULibraryVersion()
|
||||
{
|
||||
try
|
||||
{
|
||||
uint value = IsX64Process ? Internal.GetCPULibraryVersionX64() : Internal.GetCPULibraryVersionX86();
|
||||
return Tuple.Create((ushort)((value >> 16) & 0xFFFF), (ushort)(value & 0xFFFF));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new SystemException("Failed to determine CPU library version!", e);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// P/Invoke methods
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
private class Internal
|
||||
{
|
||||
const string DLL_NAME_X86 = "cpu-capabilities-x86.dll";
|
||||
const string DLL_NAME_X64 = "cpu-capabilities-x64.dll";
|
||||
|
||||
/* GetCPUArchitecture() */
|
||||
[DllImport(DLL_NAME_X64, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint GetCPUArchitectureX64();
|
||||
[DllImport(DLL_NAME_X86, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint GetCPUArchitectureX86();
|
||||
|
||||
/* GetCPUCount() */
|
||||
[DllImport(DLL_NAME_X64, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint GetCPUCountX64();
|
||||
[DllImport(DLL_NAME_X86, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint GetCPUCountX86();
|
||||
|
||||
/* GetCPUVendorString() */
|
||||
[DllImport(DLL_NAME_X64, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool GetCPUVendorStringX64([Out] byte[] buffer, uint size);
|
||||
[DllImport(DLL_NAME_X86, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool GetCPUVendorStringX86([Out] byte[] buffer, uint size);
|
||||
|
||||
/* GetCPUInformation() */
|
||||
[DllImport(DLL_NAME_X64, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool GetCPUInformationX64(out byte type, out byte familyExt, out byte family, out byte modelExt, out byte model, out byte stepping);
|
||||
[DllImport(DLL_NAME_X86, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool GetCPUInformationX86(out byte type, out byte familyExt, out byte family, out byte modelExt, out byte model, out byte stepping);
|
||||
|
||||
/* GetCPUCapabilities() */
|
||||
[DllImport(DLL_NAME_X64, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern ulong GetCPUCapabilitiesX64();
|
||||
[DllImport(DLL_NAME_X86, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern ulong GetCPUCapabilitiesX86();
|
||||
|
||||
/* GetCPUBrandString() */
|
||||
[DllImport(DLL_NAME_X64, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool GetCPUBrandStringX64([Out] byte[] buffer, uint size);
|
||||
[DllImport(DLL_NAME_X86, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool GetCPUBrandStringX86([Out] byte[] buffer, uint size);
|
||||
|
||||
/* GetCPULibraryVersion() */
|
||||
[DllImport(DLL_NAME_X64, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint GetCPULibraryVersionX64();
|
||||
[DllImport(DLL_NAME_X86, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint GetCPULibraryVersionX86();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Utility methods
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
private static void VerifyLibraryVersion()
|
||||
{
|
||||
if ((LibraryVersion.Item1 != REQUIRED_LIBRARY_VERSION.Item1) || (LibraryVersion.Item2 < REQUIRED_LIBRARY_VERSION.Item2))
|
||||
{
|
||||
throw new InvalidOperationException(string.Format("CPU library version {0} is not supported! (required version: {1})", m_libraryVersion.Value.Item1, REQUIRED_LIBRARY_VERSION));
|
||||
}
|
||||
}
|
||||
|
||||
private static string AllocateAsciiString(byte[] buffer)
|
||||
{
|
||||
int index = Array.IndexOf(buffer, (byte)0);
|
||||
if (index >= 0)
|
||||
{
|
||||
return (index > 0) ? Encoding.ASCII.GetString(buffer, 0, index) : string.Empty;
|
||||
}
|
||||
return Encoding.ASCII.GetString(buffer);
|
||||
}
|
||||
}
|
||||
}
|
41
gui/Utilities/CPUFeatures.cs
Normal file
41
gui/Utilities/CPUFeatures.cs
Normal file
@ -0,0 +1,41 @@
|
||||
/******************************************************************************/
|
||||
/* SlunkCrypt, by LoRd_MuldeR <MuldeR2@GMX.de> */
|
||||
/* This work has been released under the CC0 1.0 Universal license! */
|
||||
/******************************************************************************/
|
||||
|
||||
using System;
|
||||
using com.muldersoft.slunkcrypt.gui.utils.cpu;
|
||||
|
||||
namespace com.muldersoft.slunkcrypt.gui.process
|
||||
{
|
||||
struct CPUFeatures
|
||||
{
|
||||
public readonly bool x64;
|
||||
public readonly bool sse2;
|
||||
|
||||
private static readonly Lazy<CPUFeatures> cpuFeatures = new Lazy<CPUFeatures>(DetectFeatures);
|
||||
|
||||
public static CPUFeatures Features
|
||||
{
|
||||
get { return cpuFeatures.Value; }
|
||||
}
|
||||
|
||||
public CPUFeatures(bool x64, bool sse2)
|
||||
{
|
||||
this.x64 = x64;
|
||||
this.sse2 = sse2;
|
||||
}
|
||||
|
||||
private static CPUFeatures DetectFeatures()
|
||||
{
|
||||
try
|
||||
{
|
||||
return new CPUFeatures(CPU.Architecture.Equals(CPUArchitecture.CPU_ARCH_X64), CPU.Capabilities.HasFlag(CPUCapabilities.CPU_SSE2));
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new CPUFeatures(false, false); /*fallback*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -8,7 +8,6 @@ using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Threading;
|
||||
|
@ -192,7 +192,7 @@
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<OutDir>$(SolutionDir)bin\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)obj\$(Configuration)\$(PlatformShortName)\$(ProjectName)\</IntDir>
|
||||
<TargetName>libslunkcrypt-1-$(PlatformShortName)</TargetName>
|
||||
<TargetName>libslunkcrypt-1-$(PlatformShortName)-sse2</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_WithDbgInfo|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
@ -222,7 +222,7 @@
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<OutDir>$(SolutionDir)bin\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)obj\$(Configuration)\$(PlatformShortName)\$(ProjectName)\</IntDir>
|
||||
<TargetName>libslunkcrypt-1-$(PlatformShortName)</TargetName>
|
||||
<TargetName>libslunkcrypt-1-$(PlatformShortName)-sse2</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_WithDbgInfo|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
@ -416,6 +416,7 @@
|
||||
<FloatingPointModel>Fast</FloatingPointModel>
|
||||
<DisableSpecificWarnings>4706;4204</DisableSpecificWarnings>
|
||||
<CreateHotpatchableImage>false</CreateHotpatchableImage>
|
||||
<EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>
|
||||
|
@ -7,7 +7,7 @@
|
||||
#define INC_SLUNKCRYPT_VERSION_H
|
||||
|
||||
#define LIB_VERSION_MAJOR 1
|
||||
#define LIB_VERSION_MINOR 0
|
||||
#define LIB_VERSION_MINOR 1
|
||||
#define LIB_VERSION_PATCH 0
|
||||
|
||||
#endif
|
||||
|
@ -17,6 +17,7 @@ for %%p in (x86,x64) do (
|
||||
for %%c in (Release,Release_SSE2) do (
|
||||
if not "%%p::%%c" == "x64::Release_SSE2" (
|
||||
set "TEMP_NAME=!RANDOM!-!RANDOM!"
|
||||
if "%%c"=="Release_SSE2" (set "SUFFIX=-sse2") else (set "SUFFIX=")
|
||||
%ECHO% white "\n------------------------------------------------------------------------------"
|
||||
%ECHO% white "Clean [%%p:%%c]"
|
||||
%ECHO% white "------------------------------------------------------------------------------\n"
|
||||
@ -32,11 +33,9 @@ for %%p in (x86,x64) do (
|
||||
%ECHO% white "------------------------------------------------------------------------------\n"
|
||||
"%~dp0.\etc\utils\win32\rand.exe" | "%~dp0.\etc\utils\win32\head.exe" -c 104857600 > "%TMP%\!TEMP_NAME!.dat"
|
||||
if not "%ERRORLEVEL%"=="0" goto:BuildFailed
|
||||
"%~dp0.\bin\%%p\%%c\slunkcrypt.exe" --self-test
|
||||
"%~dp0.\bin\%%c\slunkcrypt-cli-%%p!SUFFIX!.exe" --encrypt pass:"KVeW9;z4$#]d9~}z>(WC?v&f" "%TMP%\!TEMP_NAME!.dat" "%TMP%\!TEMP_NAME!.enc"
|
||||
if not "!ERRORLEVEL!"=="0" goto:BuildFailed
|
||||
"%~dp0.\bin\%%p\%%c\slunkcrypt.exe" --encrypt pass:"KVeW9;z4$#]d9~}z>(WC?v&f" "%TMP%\!TEMP_NAME!.dat" "%TMP%\!TEMP_NAME!.enc"
|
||||
if not "!ERRORLEVEL!"=="0" goto:BuildFailed
|
||||
"%~dp0.\bin\%%p\%%c\slunkcrypt.exe" --decrypt pass:"KVeW9;z4$#]d9~}z>(WC?v&f" "%TMP%\!TEMP_NAME!.enc" "%TMP%\!TEMP_NAME!.out"
|
||||
"%~dp0.\bin\%%c\slunkcrypt-cli-%%p!SUFFIX!.exe" --decrypt pass:"KVeW9;z4$#]d9~}z>(WC?v&f" "%TMP%\!TEMP_NAME!.enc" "%TMP%\!TEMP_NAME!.out"
|
||||
if not "!ERRORLEVEL!"=="0" goto:BuildFailed
|
||||
del /F "%TMP%\!TEMP_NAME!.dat" "%TMP%\!TEMP_NAME!.enc" "%TMP%\!TEMP_NAME!.out"
|
||||
%ECHO% white "\n------------------------------------------------------------------------------"
|
||||
|
@ -36,7 +36,6 @@ dd bs=1024 count=102400 < ${RANDOM_SOURCE} > /tmp/${TMP_NAME}.dat
|
||||
printf "\n"
|
||||
PASSWRD="$(./frontend/bin/slunkcrypt${SUFFIX} --make-pw)"
|
||||
|
||||
./frontend/bin/slunkcrypt${SUFFIX} --self-test
|
||||
./frontend/bin/slunkcrypt${SUFFIX} --encrypt pass:"${PASSWRD}" /tmp/${TMP_NAME}.dat /tmp/${TMP_NAME}.enc
|
||||
./frontend/bin/slunkcrypt${SUFFIX} --decrypt pass:"${PASSWRD}" /tmp/${TMP_NAME}.enc /tmp/${TMP_NAME}.out
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user