Add partial support (zcid, rtmr, non-functional kms4k) for vista
Co-authored-by: InvoxiPlayGames <22731889+InvoxiPlayGames@users.noreply.github.com>
This commit is contained in:
47
LibTSforge/SPP/SPSys.cs
Normal file
47
LibTSforge/SPP/SPSys.cs
Normal file
@ -0,0 +1,47 @@
|
||||
namespace LibTSforge.SPP
|
||||
{
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
public class SPSys
|
||||
{
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
private static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);
|
||||
private static SafeFileHandle CreateFileSafe(string device)
|
||||
{
|
||||
return new SafeFileHandle(CreateFile(device, 0xC0000000, 0, IntPtr.Zero, 3, 0, IntPtr.Zero), true);
|
||||
}
|
||||
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern bool DeviceIoControl([In] SafeFileHandle hDevice, [In] uint dwIoControlCode, [In] IntPtr lpInBuffer, [In] int nInBufferSize, [Out] IntPtr lpOutBuffer, [In] int nOutBufferSize, out int lpBytesReturned, [In] IntPtr lpOverlapped);
|
||||
|
||||
public static bool IsSpSysRunning()
|
||||
{
|
||||
SafeFileHandle file = CreateFileSafe(@"\\.\SpDevice");
|
||||
IntPtr buffer = Marshal.AllocHGlobal(1);
|
||||
int bytesReturned = 0;
|
||||
DeviceIoControl(file, 0x80006008, IntPtr.Zero, 0, buffer, 1, out bytesReturned, IntPtr.Zero);
|
||||
bool running = Marshal.ReadByte(buffer) != 0;
|
||||
Marshal.FreeHGlobal(buffer);
|
||||
file.Close();
|
||||
return running;
|
||||
}
|
||||
|
||||
public static int ControlSpSys(bool start)
|
||||
{
|
||||
SafeFileHandle file = CreateFileSafe(@"\\.\SpDevice");
|
||||
IntPtr buffer = Marshal.AllocHGlobal(4);
|
||||
int bytesReturned = 0;
|
||||
DeviceIoControl(file, start ? 0x8000a000 : 0x8000a004, IntPtr.Zero, 0, buffer, 4, out bytesReturned, IntPtr.Zero);
|
||||
int result = Marshal.ReadInt32(buffer);
|
||||
Marshal.FreeHGlobal(buffer);
|
||||
file.Close();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user