Skip to content

Commit f23bf3e

Browse files
committed
Write binary dump to a compact file rather than a sparse file.
1 parent fcbca1d commit f23bf3e

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

dmidecode.c

+37-18
Original file line numberDiff line numberDiff line change
@@ -3851,20 +3851,14 @@ static void dmi_table_dump(u32 base, u16 len, const char *devmem)
38513851
{
38523852
u8 *buf;
38533853

3854-
if(base+len>0xFFFFF)
3855-
{
3856-
fprintf(stderr, "Table is too far away in memory, can't dump, sorry.\n");
3857-
return;
3858-
}
3859-
38603854
if((buf=mem_chunk(base, len, devmem))==NULL)
38613855
{
38623856
fprintf(stderr, "Failed to read table, sorry.\n");
38633857
return;
38643858
}
38653859

38663860
printf("# Writing %d bytes to %s.\n", len, opt.dumpfile);
3867-
write_dump(base, len, buf, opt.dumpfile);
3861+
write_dump(32, len, buf, opt.dumpfile);
38683862
free(buf);
38693863
}
38703864

@@ -3990,6 +3984,20 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem)
39903984
}
39913985

39923986

3987+
/*
3988+
* Build a crafted entry point with table address hard-coded to 32,
3989+
* as this is where we will put it in the output file. We adjust the
3990+
* DMI checksum appropriately. The SMBIOS checksum needs no adjustment.
3991+
*/
3992+
static void overwrite_dmi_address(u8 *buf)
3993+
{
3994+
buf[0x05]+=buf[0x08]+buf[0x09]+buf[0x0A]+buf[0x0B]-32;
3995+
buf[0x08]=32;
3996+
buf[0x09]=0;
3997+
buf[0x0A]=0;
3998+
buf[0x0B]=0;
3999+
}
4000+
39934001
static int smbios_decode(u8 *buf, const char *devmem)
39944002
{
39954003
if(!checksum(buf, buf[0x05])
@@ -4004,6 +4012,17 @@ static int smbios_decode(u8 *buf, const char *devmem)
40044012
dmi_table(DWORD(buf+0x18), WORD(buf+0x16), WORD(buf+0x1C),
40054013
(buf[0x06]<<8)+buf[0x07], devmem);
40064014

4015+
if(opt.flags & FLAG_DUMP_BIN)
4016+
{
4017+
u8 crafted[32];
4018+
4019+
memcpy(crafted, buf, 32);
4020+
overwrite_dmi_address(crafted+0x10);
4021+
4022+
printf("# Writing %d bytes to %s.\n", crafted[0x05], opt.dumpfile);
4023+
write_dump(0, crafted[0x05], crafted, opt.dumpfile);
4024+
}
4025+
40074026
return 1;
40084027
}
40094028

@@ -4019,6 +4038,17 @@ static int legacy_decode(u8 *buf, const char *devmem)
40194038
dmi_table(DWORD(buf+0x08), WORD(buf+0x06), WORD(buf+0x0C),
40204039
((buf[0x0E]&0xF0)<<4)+(buf[0x0E]&0x0F), devmem);
40214040

4041+
if(opt.flags & FLAG_DUMP_BIN)
4042+
{
4043+
u8 crafted[16];
4044+
4045+
memcpy(crafted, buf, 16);
4046+
overwrite_dmi_address(crafted);
4047+
4048+
printf("# Writing %d bytes to %s.\n", 0x0F, opt.dumpfile);
4049+
write_dump(0, 0x0F, crafted, opt.dumpfile);
4050+
}
4051+
40224052
return 1;
40234053
}
40244054

@@ -4137,16 +4167,6 @@ int main(int argc, char * const argv[])
41374167
goto exit_free;
41384168
}
41394169

4140-
if(opt.flags & FLAG_DUMP_BIN)
4141-
{
4142-
printf("# Writing %d bytes to %s.\n", 0x10000, opt.dumpfile);
4143-
if(write_dump(0xF0000, 0x10000, buf, opt.dumpfile))
4144-
{
4145-
ret=2;
4146-
goto exit_free_buf;
4147-
}
4148-
}
4149-
41504170
for(fp=0; fp<=0xFFF0; fp+=16)
41514171
{
41524172
if(memcmp(buf+fp, "_SM_", 4)==0 && fp<=0xFFE0)
@@ -4168,7 +4188,6 @@ int main(int argc, char * const argv[])
41684188
if(!found && !(opt.flags & FLAG_QUIET))
41694189
printf("# No SMBIOS nor DMI entry point found, sorry.\n");
41704190

4171-
exit_free_buf:
41724191
free(buf);
41734192
exit_free:
41744193
free(opt.type);

dmiopt.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ void print_help(void)
312312
" -s, --string KEYWORD Only display the value of the given DMI string\n"
313313
" -t, --type TYPE Only display the entries of given type\n"
314314
" -u, --dump Do not decode the entries\n"
315-
" --dump-bin FILE Dump the DMI data to a sparse binary file\n"
315+
" --dump-bin FILE Dump the DMI data to a binary file\n"
316316
" -V, --version Display the version and exit\n";
317317

318318
printf("%s", help);

0 commit comments

Comments
 (0)