diff --git a/netdump.c b/netdump.c index abc85e0..ef2c839 100644 --- a/netdump.c +++ b/netdump.c @@ -488,6 +488,10 @@ check_dumpfile_size(char *file) if (stat64(file, &stat) < 0) return; + Elf64_Phdr *load64 = nd->load64; + Elf32_Phdr *load32 = nd->load32; + unsigned int e_flag = (NULL == nd->elf64) ? (nd->elf32)->e_flags : (nd->elf64)->e_flags; + int status = e_flag & DUMP_ELF_INCOMPLETE; for (i = 0; i < nd->num_pt_load_segments; i++) { pls = &nd->pt_load_segments[i]; @@ -495,16 +499,35 @@ check_dumpfile_size(char *file) (pls->phys_end - pls->phys_start); if (segment_end > stat.st_size) { - error(WARNING, "%s: may be truncated or incomplete\n" - " PT_LOAD p_offset: %lld\n" - " p_filesz: %lld\n" - " bytes required: %lld\n" - " dumpfile size: %lld\n\n", - file, pls->file_offset, - pls->phys_end - pls->phys_start, - segment_end, stat.st_size); - return; + if (!status){ + error(WARNING, "%s: may be truncated or incomplete\n" + " PT_LOAD p_offset: %lld\n" + " p_filesz: %lld\n" + " bytes required: %lld\n" + " dumpfile size: %lld\n\n", + file, pls->file_offset, + pls->phys_end - pls->phys_start, + segment_end, stat.st_size); + return; + } + if (pls->file_offset > stat.st_size){ + pls->file_offset = 0; + pls->phys_start = 0; + pls->phys_end = 0; + } + else { + if (NULL == load32) + load64->p_filesz = stat.st_size - pls->file_offset; + else + load32->p_filesz = stat.st_size - pls->file_offset; + pls->zero_fill = pls->phys_end; + pls->phys_end = stat.st_size - pls->file_offset + pls->phys_start; + } } + if (NULL == load32) + load64++; + else + load32++; } }