// 跳过当前表的大小和字符串表
pCurrent += type2->Length;; //修改当前位置
while ((*pCurrent | *(pCurrent + 1)) != 0)
pCurrent++; //【个人:跳过每个表末尾的\0】
// 跳过两个NULL字符,以到达下一个表
pCurrent += 2; //【个人:跳过每个表的间隔NULL字符】
这几行代码是你写的,你真的理解这几行代码在做什么吗?
这几行代码在跳过格式区域后面的那个字符串区域
这是在跳字符串,你想要的那个序列号也是字符串,就在这里
你跳的时候数一数,跳到你想要的那个字符串的时候就停下来,就是这样
我这边的这个SN对应的字符串是 Default string
这是全部的6个字符串(gdb) print *board
$1 = {Header = {Type = 2 '\002', Length = 15 '\017', Handle = 2}, Manufacturer = 1 '\001', Product = 2 '\002', Version = 3 '\003', SN = 4 '\004',
AssetTag = 5 '\005', FeatureFlags = 9 '\t', LocationInChassis = 6 '\006', ChassisHandle = 3, Type = 10 '\n', NumObjHandle = 0 '\000',
pObjHandle = 0x6574796261676947}
Gigabyte Technology Co., Ltd.
Z790 UD
x.x
Default string
Default string
Default string
还有,要学着调试程序么,程序是调试出来的
#include <stdio.h>
#include <windows.h>
typedef struct RawSMBIOSData
{
BYTE Used20CallingMethod;
BYTE SMBIOSMajorVersion;
BYTE SMBIOSMinorVersion;
BYTE DmiRevision;
DWORD Length;
BYTE SMBIOSTableData[];
} __attribute__((packed)) RawSMBIOSData;
typedef struct {
BYTE Type;
BYTE Length;
WORD Handle;
} __attribute__((packed)) SMBIOSHEADER;
typedef struct {
SMBIOSHEADER Header;
UCHAR Manufacturer;
UCHAR Product;
UCHAR Version;
UCHAR SN;
UCHAR AssetTag;
UCHAR FeatureFlags;
UCHAR LocationInChassis;
UINT16 ChassisHandle;
UCHAR Type;
UCHAR NumObjHandle;
UINT16 *pObjHandle;
} __attribute__((packed)) BoardInfo;
int main(void) {
DWORD signature = 0x52534d42; // 'RSMB'
UINT size = GetSystemFirmwareTable(signature, 0, NULL, 0);
if(!size) return -1;
BYTE buff[size];
GetSystemFirmwareTable(signature, 0, buff, size);
RawSMBIOSData *smbios = (RawSMBIOSData *)buff;
BoardInfo *board = NULL;
BYTE *current = smbios->SMBIOSTableData;
while(current < &smbios->SMBIOSTableData[smbios->Length]) {
SMBIOSHEADER *header = (SMBIOSHEADER *)current;
if(header->Type == 2) {
board = (BoardInfo *)current; break;
}
current += header->Length;
while(*current || *(current + 1)) ++current;
current += 2;
}
current = (BYTE *)board + board->Header.Length;
BYTE *str = NULL;
DWORD index = board->SN;
DWORD count = 0;
/*
while(*current) {
while(*current) {putchar(*current); ++current;}
putchar('\n');
++count;
if(!*(current + 1)) break;
++current;
}
*/
while(*current) {
++count; if(count == index) { // 索引是从1开始的,这神奇的设计,对吧?
str = current;
}
while(*current) ++current;
if(!*(current + 1)) break;
++current;
}
if(str) printf("%s\n", str);
return 0;
}
|