'Does GetSystemFirmwareTable return an unique result everytimes?
Im trying to create and Hardware identification system for my application.
Just by googling a bit i found the following code:
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Text;
namespace OpenHardwareMonitor.Hardware {
internal static class FirmwareTable {
public static byte[] GetTable(Provider provider, string table) {
int id = table[3] << 24 | table[2] << 16 | table[1] << 8 | table[0];
return GetTable(provider, id);
}
public static byte[] GetTable(Provider provider, int table) {
int size;
try {
size = NativeMethods.GetSystemFirmwareTable(provider, table,
IntPtr.Zero, 0);
} catch (DllNotFoundException) { return null; }
catch (EntryPointNotFoundException) { return null; }
if (size <= 0)
return null;
IntPtr nativeBuffer = Marshal.AllocHGlobal(size);
NativeMethods.GetSystemFirmwareTable(provider, table, nativeBuffer, size);
if (Marshal.GetLastWin32Error() != 0)
return null;
byte[] buffer = new byte[size];
Marshal.Copy(nativeBuffer, buffer, 0, size);
Marshal.FreeHGlobal(nativeBuffer);
return buffer;
}
public static string[] EnumerateTables(Provider provider) {
int size;
try {
size = NativeMethods.EnumSystemFirmwareTables(
provider, IntPtr.Zero, 0);
} catch (DllNotFoundException) { return null; }
catch (EntryPointNotFoundException) { return null; }
IntPtr nativeBuffer = Marshal.AllocHGlobal(size);
NativeMethods.EnumSystemFirmwareTables(
provider, nativeBuffer, size);
byte[] buffer = new byte[size];
Marshal.Copy(nativeBuffer, buffer, 0, size);
Marshal.FreeHGlobal(nativeBuffer);
string[] result = new string[size / 4];
for (int i = 0; i < result.Length; i++)
result[i] = Encoding.ASCII.GetString(buffer, 4 * i, 4);
return result;
}
public enum Provider : int {
ACPI = (byte)'A' << 24 | (byte)'C' << 16 | (byte)'P' << 8 | (byte)'I',
FIRM = (byte)'F' << 24 | (byte)'I' << 16 | (byte)'R' << 8 | (byte)'M',
RSMB = (byte)'R' << 24 | (byte)'S' << 16 | (byte)'M' << 8 | (byte)'B'
}
private static class NativeMethods {
private const string KERNEL = "kernel32.dll";
[DllImport(KERNEL, CallingConvention = CallingConvention.Winapi,
SetLastError = true)]
public static extern int EnumSystemFirmwareTables(
Provider firmwareTableProviderSignature,
IntPtr firmwareTableBuffer, int bufferSize);
[DllImport(KERNEL, CallingConvention = CallingConvention.Winapi,
SetLastError = true)]
public static extern int GetSystemFirmwareTable(
Provider firmwareTableProviderSignature,
int firmwareTableID, IntPtr firmwareTableBuffer, int bufferSize);
}
}
}
by calling GetTable(Provider.RSMB, 0) im getting a large amount of data where is also possible to read several hardware infos.
I read from https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsystemfirmwaretable that There is no way for applications to write to low physical memory. so thats also good (im assuming it will be really hard to spoof the value).
Now the questions are:
When does the data returned change? (Is is the same after every restart / windows updates) ?
Is the value unique for every computers?
Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
