Пример #1
0
        public static byte[] GetTable(Provider provider, int table)
        {
            int size;

            try
            {
                size = SystemCall.GetSystemFirmwareTable(provider, table,
                                                         IntPtr.Zero, 0);
            }
            catch (DllNotFoundException)
            {
                return(null);
            }
            catch (EntryPointNotFoundException)
            {
                return(null);
            }

            if (size <= 0)
            {
                return(null);
            }

            var nativeBuffer = Marshal.AllocHGlobal(size);

            SystemCall.GetSystemFirmwareTable(provider, table, nativeBuffer, size);

            if (Marshal.GetLastWin32Error() != 0)
            {
                return(null);
            }

            var buffer = new byte[size];

            Marshal.Copy(nativeBuffer, buffer, 0, size);
            Marshal.FreeHGlobal(nativeBuffer);

            return(buffer);
        }
Пример #2
0
        public static string[] EnumerateTables(Provider provider)
        {
            int size;

            try
            {
                size = SystemCall.EnumSystemFirmwareTables(
                    provider, IntPtr.Zero, 0);
            }
            catch (DllNotFoundException)
            {
                return(null);
            }
            catch (EntryPointNotFoundException)
            {
                return(null);
            }

            var nativeBuffer = Marshal.AllocHGlobal(size);

            SystemCall.EnumSystemFirmwareTables(
                provider, nativeBuffer, size);
            var buffer = new byte[size];

            Marshal.Copy(nativeBuffer, buffer, 0, size);
            Marshal.FreeHGlobal(nativeBuffer);

            var result = new string[size / 4];

            for (var i = 0; i < result.Length; i++)
            {
                result[i] = Encoding.ASCII.GetString(buffer, 4 * i, 4);
            }

            return(result);
        }