代码无法运行,请求帮忙优化一下,并指出在什么环境下可以运行。
#include<stdio.h>#include<string.h>
#include<dos.h>
#include<conio.h>
unsigned char far *TblAddr_Ptr;//pointer to SMBIOS Address
unsigned int TblLen;//SMBIOS Table length
int Search_Strs(void);
void PrintSpecifiedStr(char *HeaderOfStr,unsigned char far *HeadAddrOfTypeN,unsigned char length,unsigned char NumOfStr);
typedef struct
{
unsigned char type;
unsigned char length;
unsigned short handle;
}Header;
/*
Function:int Search_Strs(void)
Description:search "_SM_"and "_DMI_" of EPS
Return:0 or 1
*/
int Search_Strs(void)
{
unsigned char far *ptr;
char *str1="_SM_";
char *str2="_DMI_";
int j;
//search the address,0xf0000000-0xf000ffff
for(ptr=(unsigned char far *)0xf0000000;ptr<=(unsigned char far *)0xf000ffff;ptr++)
{
for(j=0;j<strlen(str1);j++) //search string1
if(*(ptr+j)!=*(str1+j))
{
break;
}
if(j>=strlen(str1))
{
ptr+=0x10;
for(j=0;j<strlen(str2);j++) //search string2
if(*(ptr+j)!=*(str2+j))
{
break;
}
if(j>=strlen(str2))
{
TblAddr_Ptr=ptr+8;
TblLen=*((unsigned int far *)(ptr+6));
return 1;
}
}
else
{
ptr+=0x10;
}
}
return 0;
}
/*
Function:void PrintSpecifiedStr(char *HeaderOfStr,unsigned char far *HeadAddrOfTypeN,unsigned char length,unsigned char NumOfStr)
Description:print the string in a structure specified by the number of it
*/
void PrintSpecifiedStr(char *HeaderOfStr,unsigned char far *HeadAddrOfTypeN,unsigned char length,unsigned char NumOfStr)
{
unsigned char far *p=HeadAddrOfTypeN+length;
int i=1,j=0;
printf("%s",HeaderOfStr);
if(!NumOfStr)
{
printf("Unknow\n");
return;
}
while(1)
{
while(*(p+(j++)));
if(i==NumOfStr)
{
for(i=0;i<j;i++)
printf("%c",*(p+i));
putchar('\n');
return;
}
else
{
i++;
p+=j;
j=0;
}
}
}
/*
Function:main()
Description:print type0 and type1
*/
void main(void)
{
unsigned int seg,offset;
unsigned char far *TableAddr;
unsigned char type,LenOfStructure;
unsigned char Major_Release;
unsigned char Minor_Release;
unsigned char Wake_up;
unsigned long ch32,ch8,ch4;
int i=0,flag=0;
if(Search_Strs())
{
//get segment and offset address of SMBIOS Table
seg=*((unsigned int far *)(TblAddr_Ptr+2));
seg<<=12;
offset=*((unsigned int far *)TblAddr_Ptr);
TableAddr=MK_FP(seg,offset);
while(i<TblLen)
{
type=((Header far *)TableAddr)->type;
//print type0
if(type==0&&flag==0)
{
LenOfStructure=((Header far *)TableAddr)->length;
printf("\nType 0(BIOS Information):\n");
printf("Type:%d\n",type);
printf("Length:%d bytes\n",LenOfStructure);
printf("Handle:0x%.4x\n",*((unsigned int far *)(TableAddr+0x02)));
PrintSpecifiedStr("Vender:",TableAddr,LenOfStructure,*(TableAddr+0x04));
PrintSpecifiedStr("BIOS Version:",TableAddr,LenOfStructure,*(TableAddr+0x05));
printf("BIOS Starting Address Segment:%.4x\n",(*(unsigned int far *)(TableAddr+0x06)));
PrintSpecifiedStr("BIOS Release Date:",TableAddr,LenOfStructure,*(TableAddr+0x08));
printf("BIOS ROM Size:%dKB\n",(*(TableAddr+0x09)+1)*64);
printf("System BIOS Major Release: %d\n",*(TableAddr+0x14));
Major_Release=*(TableAddr+0x14);
if(Major_Release==0x0a)
{
printf("Revision 10.22\n");
}
if(Major_Release==0x02)
{
printf("Revision 2.1\n");
}
printf("System BIOS Minor Release:%d\n",*(TableAddr+0x15));
Minor_Release=*(TableAddr+0x15);
if(Minor_Release==0x16)
{
printf("Revision 10.22\n");
}
if(Minor_Release==0x01)
{
printf("Revision 2.1\n");
}
printf("Embedded controller Firmware Major Release: %d\n",*(TableAddr+0x16));
printf("Embedded controller Firmware Minor Release: %d\n",*(TableAddr+0x17));
flag=1;
printf("press any key to print BIOS Characteristics...");
getch();
clrscr();
//print BIOS Characteristics
printf("\nBIOS Characteristics:\n");
ch32=*((unsigned long far *)(TableAddr+0x0a));
if(((ch32>>3)&1)==1)
printf("BIOS Characteristics are not supported\n");
if(((ch32>>4)&1)==1)
printf("ISA is supported\n");
if(((ch32>>5)&1)==1)
printf("MAC is supported\n");
if(((ch32>>6)&1)==1)
printf("EISA is supported\n");
if(((ch32>>7)&1)==1)
printf("PCI is supported\n");
if(((ch32>>8)&1)==1)
printf("PC card (PCMCIA) is supported\n");
if(((ch32>>9)&1)==1)
printf("Plug and Play is supported\n");
if(((ch32>>10)&1)==1)
printf("APM is supported\n");
if(((ch32>>11)&1)==1)
printf("BIOS is upgradeable\n");
if(((ch32>>12)&1)==1)
printf("BIOS shadowing is allowed\n");
if(((ch32>>13)&1)==1)
printf("VL-VESA is supported\n");
if(((ch32>>14)&1)==1)
printf("ESCD supported is avilable\n");
if(((ch32>>15)&1)==1)
printf("Boot from CD is supported\n");
if(((ch32>>16)&1)==1)
printf("Selectable boot is supported\n");
if(((ch32>>17)&1)==1)
printf("BIOS ROM is socketed\n");
if(((ch32>>18)&1)==1)
printf("Boot from PC card(PCMCIA) is supported\n");
if(((ch32>>19)&1)==1)
printf("EDD is supported\n");
if(((ch32>>20)&1)==1)
printf("Japanese floppy for NEC 9800 1.2MB is supported(Int 13h)\n");
if(((ch32>>21)&1)==1)
printf("Japanese floppy for Toshiba 1.2MB is supported(Int 13h)\n");
if(((ch32>>22)&1)==1)
printf("360KB floppy services are supported(Int 13h)\n");
if(((ch32>>23)&1)==1)
printf("1.2MB floppy services are supported(Int 13h)\n");
if(((ch32>>24)&1)==1)
printf("720KB floppy services are supported(Int 13h)\n");
if(((ch32>>25)&1)==1)
printf("2.88MB floppy services are supported(Int 13h)\n");
if(((ch32>>26)&1)==1)
printf("Print screen service is supported(Int 5h)\n");
if(((ch32>>27)&1)==1)
printf("8042 keyboard services is supported (Int 9h)\n");
if(((ch32>>28)&1)==1)
printf("Serial services are supported (Int 14h)\n");
if(((ch32>>29)&1)==1)
printf("Printer services are supported (Int 17h)\n");
if(((ch32>>30)&1)==1)
printf("CGA/Mono Video Services are supported (Int 10h)\n");
if(((ch32>>31)&1)==1)
printf("NEC PC-98\n");
ch8=*((unsigned long far *)(TableAddr+0x12));
if(((ch8>>0)&1)==1)
printf("ACPI is supported\n");
if(((ch8>>1)&1)==1)
printf("USB legacy is supported\n");
if(((ch8>>2)&1)==1)
printf("AGP is supported\n");
if(((ch8>>3)&1)==1)
printf("I2O boot is supported\n");
if(((ch8>>4)&1)==1)
printf("LS-120 SuperDisk is supported\n");
if(((ch8>>5)&1)==1)
printf("ATAPI ZIP driver boot is supported\n");
if(((ch8>>6)&1)==1)
printf("1394 boot is supported\n");
if(((ch8>>7)&1)==1)
printf("Smart battery is supported\n");
ch4=*((unsigned long far *)(TableAddr+0x13));
if(((ch4>>0)&1)==1)
printf("BIOS boot specification is supported\n");
if(((ch4>>1)&1)==1)
printf("Function key-initiated network service bootis supported\n");
if(((ch4>>2)&1)==1)
printf("Targeted content distribution is supported\n");
if(((ch4>>3)&1)==1)
printf("UEFI is supported\n");
printf("press any key to print Type1(System Information)...");
getch();
clrscr();
}
//print type1
else if(type==1)
{
LenOfStructure=((Header far *)TableAddr)->length;
printf("\n\n\nType 1(System Information):\n");
printf("Type:%d\n",type);
printf("Length:%d bytes\n",LenOfStructure);
printf("Handle:0x%.4x\n",*((unsigned int far *)(TableAddr+0x02)));
PrintSpecifiedStr("Manufacturer:",TableAddr,LenOfStructure,*(TableAddr+0x04));
PrintSpecifiedStr("Product Name:",TableAddr,LenOfStructure,*(TableAddr+0x05));
PrintSpecifiedStr("Version:",TableAddr,LenOfStructure,*(TableAddr+0x06));
PrintSpecifiedStr("Serial Number:",TableAddr,LenOfStructure,*(TableAddr+0x07));
printf("UUID:%2.2x%2.2x",*((unsigned char far *)(TableAddr+0x0b)),*((unsigned char far *)(TableAddr+0x0a)));
printf("%2.2x%2.2x-",*((unsigned char far *)(TableAddr+0x09)),*((unsigned char far *)(TableAddr+0x08)));
printf("%2.2x%2.2x-",*((unsigned char far *)(TableAddr+0x0d)),*((unsigned char far *)(TableAddr+0x0c)));
printf("%2.2x%2.2x-",*((unsigned char far *)(TableAddr+0x0f)),*((unsigned char far *)(TableAddr+0x0e)));
printf("%2.2x%2.2x",*((unsigned char far *)(TableAddr+0x10)),*((unsigned char far *)(TableAddr+0x11)));
printf("%2.2x%2.2x",*((unsigned char far *)(TableAddr+0x12)),*((unsigned char far *)(TableAddr+0x13)));
printf("%2.2x%2.2x",*((unsigned char far *)(TableAddr+0x14)),*((unsigned char far *)(TableAddr+0x15)));
printf("%2.2x%2.2x\n",*((unsigned char far *)(TableAddr+0x16)),*((unsigned char far *)(TableAddr+0x17)));
Wake_up=*((unsigned int far *)(TableAddr+0x18));
if(Wake_up==0x00)
printf("Wake_up type:Reserved\n");
if(Wake_up==0x01)
printf("Wake_up type:Other\n");
if(Wake_up==0x02)
printf("Wake_up type:Unkowm\n");
if(Wake_up==0x03)
printf("Wake_up type:APM Timer\n");
if(Wake_up==0x04)
printf("Wake_up type:Modem Ring\n");
if(Wake_up==0x05)
printf("Wake_up type:LAN Remote\n");
if(Wake_up==0x06)
printf("Wake_up type:Power Switch\n");
if(Wake_up==0x07)
printf("Wake_up type:PCI PME#\n");
if(Wake_up==0x08)
printf("Wake_up type:AC Power Restored\n");
PrintSpecifiedStr("SKU Number:",TableAddr,LenOfStructure,*(TableAddr+0x19));
PrintSpecifiedStr("Family:",TableAddr,LenOfStructure,*(TableAddr+0x1a));
getch();
clrscr();
break;
}
//skip the unformatt string
TableAddr+=((Header far *)TableAddr)->length;
while(*((unsigned int far *)TableAddr)!=0)
TableAddr++;
TableAddr+=2;
i++;
}
}
} #include<dos.h>
#include<conio.h>
dos.h?
conio.h???
你这代码哪来的?
帮你试了试,这代码没问题
人造人 发表于 2022-10-12 10:48
帮你试了试,这代码没问题
这个是在Windows里运行吗?我在Linux里运行不了,缺少dos.h,这是什么意思,我应该下载插件吗?还是什么 2wsx 发表于 2022-10-13 08:06
这个是在Windows里运行吗?我在Linux里运行不了,缺少dos.h,这是什么意思,我应该下载插件吗?还是什么
虽然我不懂,但是这都 DOS.H 了,dos是微软的东西,那八成是要在windows里运行的 2wsx 发表于 2022-10-13 08:06
这个是在Windows里运行吗?我在Linux里运行不了,缺少dos.h,这是什么意思,我应该下载插件吗?还是什么
你这代码哪来的?
我用的bochs
人造人 发表于 2022-10-13 10:54
你这代码哪来的?
我用的bochs
找的别人的代码,因为想实现类似他这种功能,想运行一下,Windows和Linux都报错,没法运行。如果我想用Linux或者windows运行应该怎么办? 2wsx 发表于 2022-10-13 13:08
找的别人的代码,因为想实现类似他这种功能,想运行一下,Windows和Linux都报错,没法运行。如果我想用Li ...
不好办,最简单的方法就是用这个代码要求的环境
用ms-dos操作系统
或者使用 /dev/mem
像这样 https://fishc.com.cn/thread-219097-1-1.html
人造人 发表于 2022-10-13 14:16
或者使用 /dev/mem
像这样 https://fishc.com.cn/thread-219097-1-1.html
FILE *fp = fopen("/dev/mem", "r");
这句代码是什么意思?
我不明白/dev/mem是什么 2wsx 发表于 2022-10-13 14:46
FILE *fp = fopen("/dev/mem", "r");
这句代码是什么意思?
我不明白/dev/mem是什么
https://cn.bing.com/search?form=MOZCON&pc=MOZI&q=%2Fdev%2Fmem
页:
[1]