Skip to content

Commit 7ae8e1b

Browse files
committed
添加项目文件。
1 parent 9f4ded6 commit 7ae8e1b

28 files changed

+5310
-0
lines changed

GlobalUsing.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
global using System;
2+
global using System.Collections.Generic;
3+
global using System.Linq;
4+
global using System.Text;
5+
global using System.Threading.Tasks;
6+
global using System.Runtime.InteropServices;
7+
global using Microsoft.Win32;
8+
global using System.Xml;
9+
global using System.Diagnostics;
10+
global using System.ServiceProcess;

HWIDEx/BitUtil.cs

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Decompiled with JetBrains decompiler
2+
// Type: HwidGetCurrentEx.BitUtil
3+
// Assembly: HwidGetCurrentEx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
4+
// MVID: 200C1AD7-2186-49E5-9EB2-5AB7013ECA80 Assembly location: D:\downloads\Programs\HwidGetCurrentEx.dll
5+
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Runtime.CompilerServices;
10+
using System.Text;
11+
12+
namespace HWIDEx
13+
{
14+
internal static class BitUtil
15+
{
16+
public static string ReadNullTerminatedAnsiString(byte[] buffer, int offset)
17+
{
18+
StringBuilder stringBuilder = new StringBuilder();
19+
for (char ch = (char)buffer[offset]; ch > char.MinValue; ch = (char)buffer[offset])
20+
{
21+
stringBuilder.Append(ch);
22+
++offset;
23+
}
24+
return stringBuilder.ToString();
25+
}
26+
27+
public static byte[] StrToByteArray(string str)
28+
{
29+
Dictionary<string, byte> dictionary = new Dictionary<string, byte>();
30+
for (int index = 0; index <= (int)byte.MaxValue; ++index)
31+
dictionary.Add(index.ToString("X2"), (byte)index);
32+
List<byte> byteList = new List<byte>();
33+
for (int startIndex = 0; startIndex < str.Length; startIndex += 2)
34+
byteList.Add(dictionary[str.Substring(startIndex, 2)]);
35+
return byteList.ToArray();
36+
}
37+
38+
public static ulong array2ulong(byte[] bytes, int start, int length)
39+
{
40+
bytes = ((IEnumerable<byte>)bytes).Skip<byte>(start).Take<byte>(length).ToArray<byte>();
41+
ulong num1 = 0;
42+
foreach (byte num2 in bytes)
43+
num1 = num1 * 256UL + (ulong)num2;
44+
return num1;
45+
}
46+
47+
public static T[] Concats<T>(this T[] array1, params T[] array2) => BitUtil.ConcatArray<T>(array1, array2);
48+
49+
public static T[] ConcatArray<T>(params T[][] arrays)
50+
{
51+
int index1;
52+
int length;
53+
for (length = index1 = 0; index1 < arrays.Length; ++index1)
54+
length += arrays[index1].Length;
55+
T[] objArray = new T[length];
56+
int index2;
57+
for (int index3 = index2 = 0; index2 < arrays.Length; ++index2)
58+
{
59+
arrays[index2].CopyTo((Array)objArray, index3);
60+
index3 += arrays[index2].Length;
61+
}
62+
return objArray;
63+
}
64+
65+
public static byte LOBYTE(int a) => (byte)((uint)(short)a & (uint)byte.MaxValue);
66+
67+
public static short MAKEWORD(byte a, byte b) => (short)((int)(byte)((uint)a & (uint)byte.MaxValue) | (int)(byte)((uint)b & (uint)byte.MaxValue) << 8);
68+
69+
public static byte LOBYTE(short a) => (byte)((uint)a & (uint)byte.MaxValue);
70+
71+
public static byte HIBYTE(short a) => (byte)((uint)a >> 8);
72+
73+
public static int MAKELONG(short a, short b) => (int)a & (int)ushort.MaxValue | ((int)b & (int)ushort.MaxValue) << 16;
74+
75+
public static short HIWORD(int a) => (short)(a >> 16);
76+
77+
public static short LOWORD(int a) => (short)(a & (int)ushort.MaxValue);
78+
79+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
80+
public static uint RotateLeft(uint value, int offset) => value << offset | value >> 32 - offset;
81+
82+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
83+
public static ulong RotateLeft64(ulong value, int offset) => value << offset | value >> 64 - offset;
84+
85+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
86+
public static uint RotateRight(uint value, int offset) => value >> offset | value << 32 - offset;
87+
88+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
89+
public static ulong RotateRight64(ulong value, int offset) => value >> offset | value << 64 - offset;
90+
91+
public static int HIDWORD(long intValue) => Convert.ToInt32(intValue >> 32);
92+
93+
public static int LODWORD(long intValue) => Convert.ToInt32(intValue << 32 >> 32);
94+
95+
public static short PAIR(sbyte high, sbyte low) => (short)((int)high << 8 | (int)(byte)low);
96+
97+
public static int PAIR(short high, int low) => (int)high << 16 | (int)(ushort)low;
98+
99+
public static long PAIR(int high, long low) => (long)high << 32 | (long)(uint)low;
100+
101+
public static ushort PAIR(byte high, ushort low) => (ushort)((uint)high << 8 | (uint)(byte)low);
102+
103+
public static uint PAIR(ushort high, uint low) => (uint)high << 16 | (uint)(ushort)low;
104+
105+
public static ulong PAIR(uint high, ulong low) => (ulong)high << 32 | (ulong)(uint)low;
106+
107+
public static int adc(uint first, uint second, ref uint carry)
108+
{
109+
uint carry1 = 0;
110+
if (carry == 0U)
111+
{
112+
uint num = first + second;
113+
carry = num >= first || num >= second ? 0U : 1U;
114+
return (int)num;
115+
}
116+
uint num1 = (uint)BitUtil.adc(first, second, ref carry1);
117+
if (carry > 0U)
118+
{
119+
++num1;
120+
carry1 |= num1 == 0U ? 1U : 0U;
121+
}
122+
carry = carry1;
123+
return (int)num1;
124+
}
125+
}
126+
}

HWIDEx/CPUID.cs

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
// Decompiled with JetBrains decompiler
2+
// Type: HwidGetCurrentEx.CPUID
3+
// Assembly: HwidGetCurrentEx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
4+
// MVID: 200C1AD7-2186-49E5-9EB2-5AB7013ECA80 Assembly location: D:\downloads\Programs\HwidGetCurrentEx.dll
5+
6+
using System;
7+
using System.Runtime.InteropServices;
8+
9+
namespace HWIDEx
10+
{
11+
public static class CPUID
12+
{
13+
private static readonly byte[] x86CodeBytes = new byte[30]
14+
{
15+
(byte) 85,
16+
(byte) 139,
17+
(byte) 236,
18+
(byte) 83,
19+
(byte) 87,
20+
(byte) 139,
21+
(byte) 69,
22+
(byte) 8,
23+
(byte) 15,
24+
(byte) 162,
25+
(byte) 139,
26+
(byte) 125,
27+
(byte) 12,
28+
(byte) 137,
29+
(byte) 7,
30+
(byte) 137,
31+
(byte) 95,
32+
(byte) 4,
33+
(byte) 137,
34+
(byte) 79,
35+
(byte) 8,
36+
(byte) 137,
37+
(byte) 87,
38+
(byte) 12,
39+
(byte) 95,
40+
(byte) 91,
41+
(byte) 139,
42+
(byte) 229,
43+
(byte) 93,
44+
(byte) 195
45+
};
46+
47+
private static readonly byte[] x64CodeBytes = new byte[26]
48+
{
49+
(byte) 83,
50+
(byte) 73,
51+
(byte) 137,
52+
(byte) 208,
53+
(byte) 137,
54+
(byte) 200,
55+
(byte) 15,
56+
(byte) 162,
57+
(byte) 65,
58+
(byte) 137,
59+
(byte) 64,
60+
(byte) 0,
61+
(byte) 65,
62+
(byte) 137,
63+
(byte) 88,
64+
(byte) 4,
65+
(byte) 65,
66+
(byte) 137,
67+
(byte) 72,
68+
(byte) 8,
69+
(byte) 65,
70+
(byte) 137,
71+
(byte) 80,
72+
(byte) 12,
73+
(byte) 91,
74+
(byte) 195
75+
};
76+
77+
public static byte[] Invoke(int level)
78+
{
79+
IntPtr num = IntPtr.Zero;
80+
try
81+
{
82+
byte[] source = IntPtr.Size != 4 ? CPUID.x64CodeBytes : CPUID.x86CodeBytes;
83+
num = CPUID.VirtualAlloc(IntPtr.Zero, new UIntPtr((uint)source.Length), CPUID.AllocationType.COMMIT | CPUID.AllocationType.RESERVE, CPUID.MemoryProtection.EXECUTE_READWRITE);
84+
Marshal.Copy(source, 0, num, source.Length);
85+
CPUID.CpuIDDelegate forFunctionPointer = (CPUID.CpuIDDelegate)Marshal.GetDelegateForFunctionPointer(num, typeof(CPUID.CpuIDDelegate));
86+
GCHandle gcHandle = new GCHandle();
87+
byte[] buffer = new byte[16];
88+
try
89+
{
90+
gcHandle = GCHandle.Alloc((object)buffer, GCHandleType.Pinned);
91+
forFunctionPointer(level, buffer);
92+
}
93+
finally
94+
{
95+
if (gcHandle != new GCHandle())
96+
gcHandle.Free();
97+
}
98+
return buffer;
99+
}
100+
finally
101+
{
102+
if (num != IntPtr.Zero)
103+
{
104+
CPUID.VirtualFree(num, 0U, 32768U);
105+
IntPtr zero = IntPtr.Zero;
106+
}
107+
}
108+
}
109+
110+
[DllImport("kernel32.dll", SetLastError = true)]
111+
private static extern IntPtr VirtualAlloc(
112+
IntPtr lpAddress,
113+
UIntPtr dwSize,
114+
CPUID.AllocationType flAllocationType,
115+
CPUID.MemoryProtection flProtect);
116+
117+
[DllImport("kernel32")]
118+
private static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);
119+
120+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
121+
private delegate void CpuIDDelegate(int level, byte[] buffer);
122+
123+
[Flags]
124+
private enum AllocationType : uint
125+
{
126+
COMMIT = 4096, // 0x00001000
127+
RESERVE = 8192, // 0x00002000
128+
RESET = 524288, // 0x00080000
129+
LARGE_PAGES = 536870912, // 0x20000000
130+
PHYSICAL = 4194304, // 0x00400000
131+
TOP_DOWN = 1048576, // 0x00100000
132+
WRITE_WATCH = 2097152, // 0x00200000
133+
}
134+
135+
[Flags]
136+
private enum MemoryProtection : uint
137+
{
138+
EXECUTE = 16, // 0x00000010
139+
EXECUTE_READ = 32, // 0x00000020
140+
EXECUTE_READWRITE = 64, // 0x00000040
141+
EXECUTE_WRITECOPY = 128, // 0x00000080
142+
NOACCESS = 1,
143+
READONLY = 2,
144+
READWRITE = 4,
145+
WRITECOPY = 8,
146+
GUARD_Modifierflag = 256, // 0x00000100
147+
NOCACHE_Modifierflag = 512, // 0x00000200
148+
WRITECOMBINE_Modifierflag = 1024, // 0x00000400
149+
}
150+
}
151+
}

0 commit comments

Comments
 (0)