From 9e3037822ac046e18a554113f45bf88294168c77 Mon Sep 17 00:00:00 2001 From: yumaojun03 <18108053819@163.com> Date: Tue, 7 Jul 2020 23:25:38 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E6=A3=80=E6=9F=A5=E6=95=B0?= =?UTF-8?q?=E7=BB=84=E8=B6=8A=E7=95=8C=E8=AE=BF=E9=97=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/main.go | 2 +- parser/bios/parse.go | 11 +++++------ parser/chassis/parse.go | 24 +++++++++++------------- parser/onboard/parse.go | 18 ++++++------------ parser/port/parse.go | 7 +++---- parser/processor/parse.go | 20 +++++++++----------- parser/slot/parse.go | 25 +++++++++++++------------ parser/system/parse.go | 6 ++---- 8 files changed, 50 insertions(+), 63 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 2f907c0..ba02c0a 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -128,7 +128,7 @@ func checkDecodeErr(t string, err error) { } func usage() { - fmt.Fprintf(os.Stderr, `dmidecode version: 0.1.2 + fmt.Fprintf(os.Stderr, `dmidecode version: 0.1.3 Usage: dmidecode [-h] [-d] [-t type] Options: diff --git a/parser/bios/parse.go b/parser/bios/parse.go index 7b19b13..ba74f12 100644 --- a/parser/bios/parse.go +++ b/parser/bios/parse.go @@ -6,8 +6,7 @@ import ( // Parse 参考 https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.1.1.pdf func Parse(s *smbios.Structure) (*Information, error) { - data := s.Formatted - sas := smbios.U16(data[0x02:0x04]) + sas := s.U16(0x02, 0x04) bi := &Information{ Header: s.Header, @@ -15,16 +14,16 @@ func Parse(s *smbios.Structure) (*Information, error) { BIOSVersion: s.GetString(0x1), ReleaseDate: s.GetString(0x4), StartingAddressSegment: sas, - RomSize: RomSize(64 * (data[0x05] + 1)), + RomSize: RomSize(64 * (s.GetByte(0x05) + 1)), RuntimeSize: RuntimeSize((uint(0x10000) - uint(sas)) << 4), - Characteristics: Characteristics(smbios.U64(data[0x06:0x08])), + Characteristics: Characteristics(s.U64(0x06, 0x08)), } if s.Header.Length >= 0x08 { - bi.CharacteristicsExt1 = Ext1(data[0x08]) + bi.CharacteristicsExt1 = Ext1(s.GetByte(0x08)) } if s.Header.Length >= 0x09 { - bi.CharacteristicsExt2 = Ext2(data[0x09]) + bi.CharacteristicsExt2 = Ext2(s.GetByte(0x09)) } return bi, nil diff --git a/parser/chassis/parse.go b/parser/chassis/parse.go index 470e4ac..71f3885 100644 --- a/parser/chassis/parse.go +++ b/parser/chassis/parse.go @@ -6,24 +6,22 @@ import ( // Parse 解析底座信息 func Parse(s *smbios.Structure) (*Information, error) { - data := s.Formatted - info := &Information{ Manufacturer: s.GetString(0x0), - Type: Type(data[0x01] & 127), - Lock: Lock(data[0x01] >> 7), + Type: Type(s.GetByte(0x01) & 127), + Lock: Lock(s.GetByte(0x01) >> 7), Version: s.GetString(0x2), SerialNumber: s.GetString(0x3), AssetTag: s.GetString(0x4), - BootUpState: State(data[0x05]), - PowerSupplyState: State(data[0x06]), - ThermalState: State(data[0x07]), - SecurityStatus: SecurityStatus(data[0x08]), - OEMdefined: smbios.U16(data[0x09 : 0x09+4]), - Height: Height(data[0xD]), - NumberOfPowerCords: data[0xE], - ContainedElementCount: data[0xF], - ContainedElementRecordLength: data[0x10], + BootUpState: State(s.GetByte(0x05)), + PowerSupplyState: State(s.GetByte(0x06)), + ThermalState: State(s.GetByte(0x07)), + SecurityStatus: SecurityStatus(s.GetByte(0x08)), + OEMdefined: s.U16(0x09, 0xd), + Height: Height(s.GetByte(0xd)), + NumberOfPowerCords: s.GetByte(0xe), + ContainedElementCount: s.GetByte(0xf), + ContainedElementRecordLength: s.GetByte(0x10), // TODO: 7.4.4 //ci.ContainedElements: SKUNumber: s.GetString(4), diff --git a/parser/onboard/parse.go b/parser/onboard/parse.go index 4c0463a..bb21c9c 100644 --- a/parser/onboard/parse.go +++ b/parser/onboard/parse.go @@ -12,20 +12,14 @@ func ParseType41(s *smbios.Structure) (*ExtendedInformation, error) { return nil, fmt.Errorf("ParseType41 only parse type 41 data, but now: %d", s.Type()) } - data := s.Formatted - info := &ExtendedInformation{ ReferenceDesignation: s.GetString(0x0), - DeviceType: ExtendedInformationType(data[0x01] & 127), - DeviceStatus: DeviceStatus(data[0x01] >> 7), - DeviceTypeInstance: data[0x02], - SegmentGroupNumber: smbios.U16(data[0x03:0x05]), - BusNumber: data[0x05], - DeviceFunctionNumber: data[0x06], - } - - if len(s.Formatted) >= 0x06 { - info.DeviceFunctionNumber = data[0x06] + DeviceType: ExtendedInformationType(s.GetByte(0x01) & 127), + DeviceStatus: DeviceStatus(s.GetByte(0x01) >> 7), + DeviceTypeInstance: s.GetByte(0x02), + SegmentGroupNumber: s.U16(0x03, 0x05), + BusNumber: s.GetByte(0x05), + DeviceFunctionNumber: s.GetByte(0x06), } return info, nil diff --git a/parser/port/parse.go b/parser/port/parse.go index 04eed28..c2d3492 100644 --- a/parser/port/parse.go +++ b/parser/port/parse.go @@ -6,14 +6,13 @@ import ( // Parse 解析port信息 func Parse(s *smbios.Structure) (*Information, error) { - data := s.Formatted info := &Information{ Header: s.Header, InternalReferenceDesignator: s.GetString(0x0), - InternalConnectorType: ConnectorType(data[0x01]), + InternalConnectorType: ConnectorType(s.GetByte(0x01)), ExternalReferenceDesignator: s.GetString(0x2), - ExternalConnectorType: ConnectorType(data[0x03]), - Type: PortType(data[0x04]), + ExternalConnectorType: ConnectorType(s.GetByte(0x03)), + Type: PortType(s.GetByte(0x04)), } return info, nil } diff --git a/parser/processor/parse.go b/parser/processor/parse.go index ea3a842..d7190a8 100644 --- a/parser/processor/parse.go +++ b/parser/processor/parse.go @@ -51,19 +51,17 @@ func ParseProcessor(s *smbios.Structure) (*Processor, error) { // ParseCache 缓存信息 func ParseCache(s *smbios.Structure) (*Cache, error) { - data := s.Formatted - cache := &Cache{ SocketDesignation: s.GetString(0x0), - Configuration: NewCacheConfiguration(smbios.U16(data[0x01:0x03])), - MaximumCacheSize: NewCacheSize(smbios.U16(data[0x03:0x05])), - InstalledSize: NewCacheSize(smbios.U16(data[0x05:0x07])), - SupportedSRAMType: CacheSRAMType(smbios.U16(data[0x07:0x09])), - CurrentSRAMType: CacheSRAMType(smbios.U16(data[0x09:0x0B])), - CacheSpeed: CacheSpeed(data[0x0B]), - ErrorCorrectionType: CacheErrorCorrectionType(data[0xC]), - SystemCacheType: CacheSystemCacheType(data[0xD]), - Associativity: CacheAssociativity(data[0xE]), + Configuration: NewCacheConfiguration(s.U16(0x01, 0x03)), + MaximumCacheSize: NewCacheSize(s.U16(0x03, 0x05)), + InstalledSize: NewCacheSize(s.U16(0x05, 0x07)), + SupportedSRAMType: CacheSRAMType(s.U16(0x07, 0x09)), + CurrentSRAMType: CacheSRAMType(s.U16(0x09, 0x0b)), + CacheSpeed: CacheSpeed(s.GetByte(0x0b)), + ErrorCorrectionType: CacheErrorCorrectionType(s.GetByte(0xc)), + SystemCacheType: CacheSystemCacheType(s.GetByte(0xd)), + Associativity: CacheAssociativity(s.GetByte(0xe)), } return cache, nil diff --git a/parser/slot/parse.go b/parser/slot/parse.go index bc6de4d..6f2d65b 100644 --- a/parser/slot/parse.go +++ b/parser/slot/parse.go @@ -1,22 +1,23 @@ package slot -import "github.com/yumaojun03/dmidecode/smbios" +import ( + "github.com/yumaojun03/dmidecode/smbios" +) // Parse 解析slot信息 func Parse(s *smbios.Structure) (*SystemSlot, error) { - data := s.Formatted info := &SystemSlot{ Designation: s.GetString(0x0), - Type: Type(data[0x01]), - DataBusWidth: DataBusWidth(data[0x02]), - CurrentUsage: Usage(data[0x03]), - Length: Length(data[0x04]), - ID: ID(smbios.U16(data[0x05:0x07])), - Characteristics1: Characteristics1(data[0x07]), - Characteristics2: Characteristics2(data[0x08]), - SegmentGroupNumber: SegmengGroupNumber(smbios.U16(data[0x09:0x0B])), - BusNumber: Number(data[0x0B]), - DeviceFunctionNumber: Number(data[0x0C]), + Type: Type(s.GetByte(0x01)), + DataBusWidth: DataBusWidth(s.GetByte(0x02)), + CurrentUsage: Usage(s.GetByte(0x03)), + Length: Length(s.GetByte(0x04)), + ID: ID(s.U16(0x05, 0x07)), + Characteristics1: Characteristics1(s.GetByte(0x07)), + Characteristics2: Characteristics2(s.GetByte(0x08)), + SegmentGroupNumber: SegmengGroupNumber(s.U16(0x09, 0x0b)), + BusNumber: Number(s.GetByte(0x0b)), + DeviceFunctionNumber: Number(s.GetByte(0x0c)), } return info, nil diff --git a/parser/system/parse.go b/parser/system/parse.go index 0c8a2e7..73e2934 100644 --- a/parser/system/parse.go +++ b/parser/system/parse.go @@ -9,16 +9,14 @@ import ( // Parse 解析smbios struct数据 func Parse(s *smbios.Structure) (*Information, error) { - data := s.Formatted - return &Information{ Header: s.Header, Manufacturer: s.GetString(0x0), ProductName: s.GetString(0x1), Version: s.GetString(0x2), SerialNumber: s.GetString(0x3), - UUID: uuid(data[0x04:0x14], s.GetString(2)), - WakeUpType: WakeUpType(data[0x14]), + UUID: uuid(s.GetBytes(0x04, 0x14), s.GetString(2)), + WakeUpType: WakeUpType(s.GetByte(0x14)), SKUNumber: s.GetString(0x15), Family: s.GetString(0x16), }, nil