Skip to content

Commit

Permalink
添加项目文件。
Browse files Browse the repository at this point in the history
  • Loading branch information
MIAIONE committed May 9, 2022
1 parent 9f4ded6 commit 7ae8e1b
Show file tree
Hide file tree
Showing 28 changed files with 5,310 additions and 0 deletions.
10 changes: 10 additions & 0 deletions GlobalUsing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
global using System;
global using System.Collections.Generic;
global using System.Linq;
global using System.Text;
global using System.Threading.Tasks;
global using System.Runtime.InteropServices;
global using Microsoft.Win32;
global using System.Xml;
global using System.Diagnostics;
global using System.ServiceProcess;
126 changes: 126 additions & 0 deletions HWIDEx/BitUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Decompiled with JetBrains decompiler
// Type: HwidGetCurrentEx.BitUtil
// Assembly: HwidGetCurrentEx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 200C1AD7-2186-49E5-9EB2-5AB7013ECA80 Assembly location: D:\downloads\Programs\HwidGetCurrentEx.dll

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;

namespace HWIDEx
{
internal static class BitUtil
{
public static string ReadNullTerminatedAnsiString(byte[] buffer, int offset)
{
StringBuilder stringBuilder = new StringBuilder();
for (char ch = (char)buffer[offset]; ch > char.MinValue; ch = (char)buffer[offset])
{
stringBuilder.Append(ch);
++offset;
}
return stringBuilder.ToString();
}

public static byte[] StrToByteArray(string str)
{
Dictionary<string, byte> dictionary = new Dictionary<string, byte>();
for (int index = 0; index <= (int)byte.MaxValue; ++index)
dictionary.Add(index.ToString("X2"), (byte)index);
List<byte> byteList = new List<byte>();
for (int startIndex = 0; startIndex < str.Length; startIndex += 2)
byteList.Add(dictionary[str.Substring(startIndex, 2)]);
return byteList.ToArray();
}

public static ulong array2ulong(byte[] bytes, int start, int length)
{
bytes = ((IEnumerable<byte>)bytes).Skip<byte>(start).Take<byte>(length).ToArray<byte>();
ulong num1 = 0;
foreach (byte num2 in bytes)
num1 = num1 * 256UL + (ulong)num2;
return num1;
}

public static T[] Concats<T>(this T[] array1, params T[] array2) => BitUtil.ConcatArray<T>(array1, array2);

public static T[] ConcatArray<T>(params T[][] arrays)
{
int index1;
int length;
for (length = index1 = 0; index1 < arrays.Length; ++index1)
length += arrays[index1].Length;
T[] objArray = new T[length];
int index2;
for (int index3 = index2 = 0; index2 < arrays.Length; ++index2)
{
arrays[index2].CopyTo((Array)objArray, index3);
index3 += arrays[index2].Length;
}
return objArray;
}

public static byte LOBYTE(int a) => (byte)((uint)(short)a & (uint)byte.MaxValue);

public static short MAKEWORD(byte a, byte b) => (short)((int)(byte)((uint)a & (uint)byte.MaxValue) | (int)(byte)((uint)b & (uint)byte.MaxValue) << 8);

public static byte LOBYTE(short a) => (byte)((uint)a & (uint)byte.MaxValue);

public static byte HIBYTE(short a) => (byte)((uint)a >> 8);

public static int MAKELONG(short a, short b) => (int)a & (int)ushort.MaxValue | ((int)b & (int)ushort.MaxValue) << 16;

public static short HIWORD(int a) => (short)(a >> 16);

public static short LOWORD(int a) => (short)(a & (int)ushort.MaxValue);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint RotateLeft(uint value, int offset) => value << offset | value >> 32 - offset;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ulong RotateLeft64(ulong value, int offset) => value << offset | value >> 64 - offset;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint RotateRight(uint value, int offset) => value >> offset | value << 32 - offset;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ulong RotateRight64(ulong value, int offset) => value >> offset | value << 64 - offset;

public static int HIDWORD(long intValue) => Convert.ToInt32(intValue >> 32);

public static int LODWORD(long intValue) => Convert.ToInt32(intValue << 32 >> 32);

public static short PAIR(sbyte high, sbyte low) => (short)((int)high << 8 | (int)(byte)low);

public static int PAIR(short high, int low) => (int)high << 16 | (int)(ushort)low;

public static long PAIR(int high, long low) => (long)high << 32 | (long)(uint)low;

public static ushort PAIR(byte high, ushort low) => (ushort)((uint)high << 8 | (uint)(byte)low);

public static uint PAIR(ushort high, uint low) => (uint)high << 16 | (uint)(ushort)low;

public static ulong PAIR(uint high, ulong low) => (ulong)high << 32 | (ulong)(uint)low;

public static int adc(uint first, uint second, ref uint carry)
{
uint carry1 = 0;
if (carry == 0U)
{
uint num = first + second;
carry = num >= first || num >= second ? 0U : 1U;
return (int)num;
}
uint num1 = (uint)BitUtil.adc(first, second, ref carry1);
if (carry > 0U)
{
++num1;
carry1 |= num1 == 0U ? 1U : 0U;
}
carry = carry1;
return (int)num1;
}
}
}
151 changes: 151 additions & 0 deletions HWIDEx/CPUID.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// Decompiled with JetBrains decompiler
// Type: HwidGetCurrentEx.CPUID
// Assembly: HwidGetCurrentEx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 200C1AD7-2186-49E5-9EB2-5AB7013ECA80 Assembly location: D:\downloads\Programs\HwidGetCurrentEx.dll

using System;
using System.Runtime.InteropServices;

namespace HWIDEx
{
public static class CPUID
{
private static readonly byte[] x86CodeBytes = new byte[30]
{
(byte) 85,
(byte) 139,
(byte) 236,
(byte) 83,
(byte) 87,
(byte) 139,
(byte) 69,
(byte) 8,
(byte) 15,
(byte) 162,
(byte) 139,
(byte) 125,
(byte) 12,
(byte) 137,
(byte) 7,
(byte) 137,
(byte) 95,
(byte) 4,
(byte) 137,
(byte) 79,
(byte) 8,
(byte) 137,
(byte) 87,
(byte) 12,
(byte) 95,
(byte) 91,
(byte) 139,
(byte) 229,
(byte) 93,
(byte) 195
};

private static readonly byte[] x64CodeBytes = new byte[26]
{
(byte) 83,
(byte) 73,
(byte) 137,
(byte) 208,
(byte) 137,
(byte) 200,
(byte) 15,
(byte) 162,
(byte) 65,
(byte) 137,
(byte) 64,
(byte) 0,
(byte) 65,
(byte) 137,
(byte) 88,
(byte) 4,
(byte) 65,
(byte) 137,
(byte) 72,
(byte) 8,
(byte) 65,
(byte) 137,
(byte) 80,
(byte) 12,
(byte) 91,
(byte) 195
};

public static byte[] Invoke(int level)
{
IntPtr num = IntPtr.Zero;
try
{
byte[] source = IntPtr.Size != 4 ? CPUID.x64CodeBytes : CPUID.x86CodeBytes;
num = CPUID.VirtualAlloc(IntPtr.Zero, new UIntPtr((uint)source.Length), CPUID.AllocationType.COMMIT | CPUID.AllocationType.RESERVE, CPUID.MemoryProtection.EXECUTE_READWRITE);
Marshal.Copy(source, 0, num, source.Length);
CPUID.CpuIDDelegate forFunctionPointer = (CPUID.CpuIDDelegate)Marshal.GetDelegateForFunctionPointer(num, typeof(CPUID.CpuIDDelegate));
GCHandle gcHandle = new GCHandle();
byte[] buffer = new byte[16];
try
{
gcHandle = GCHandle.Alloc((object)buffer, GCHandleType.Pinned);
forFunctionPointer(level, buffer);
}
finally
{
if (gcHandle != new GCHandle())
gcHandle.Free();
}
return buffer;
}
finally
{
if (num != IntPtr.Zero)
{
CPUID.VirtualFree(num, 0U, 32768U);
IntPtr zero = IntPtr.Zero;
}
}
}

[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr VirtualAlloc(
IntPtr lpAddress,
UIntPtr dwSize,
CPUID.AllocationType flAllocationType,
CPUID.MemoryProtection flProtect);

[DllImport("kernel32")]
private static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void CpuIDDelegate(int level, byte[] buffer);

[Flags]
private enum AllocationType : uint
{
COMMIT = 4096, // 0x00001000
RESERVE = 8192, // 0x00002000
RESET = 524288, // 0x00080000
LARGE_PAGES = 536870912, // 0x20000000
PHYSICAL = 4194304, // 0x00400000
TOP_DOWN = 1048576, // 0x00100000
WRITE_WATCH = 2097152, // 0x00200000
}

[Flags]
private enum MemoryProtection : uint
{
EXECUTE = 16, // 0x00000010
EXECUTE_READ = 32, // 0x00000020
EXECUTE_READWRITE = 64, // 0x00000040
EXECUTE_WRITECOPY = 128, // 0x00000080
NOACCESS = 1,
READONLY = 2,
READWRITE = 4,
WRITECOPY = 8,
GUARD_Modifierflag = 256, // 0x00000100
NOCACHE_Modifierflag = 512, // 0x00000200
WRITECOMBINE_Modifierflag = 1024, // 0x00000400
}
}
}
Loading

0 comments on commit 7ae8e1b

Please sign in to comment.