Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make dumps of type CompleteMemoryDump trust TotalNumberOfPages header field instead of just MetadataSize #28

Merged
merged 5 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ The library supports loading 64-bit dumps and provides read access to things lik
Compiled binaries are available in the [releases](https://github.com/0vercl0k/kdmp-parser/releases) section.

Special thanks to:
- [hugsy](https://github.com/hugsy) for numerous contributions: the new Python bindings, CI improvements, new dump types, etc.,
- [masthoon](https://github.com/masthoon) for the initial version of the Python bindings,
- [yrp604](https://github.com/yrp604) for being knowledgeable about the format,
- the [rekall](https://github.com/google/rekall) project and their [Python implementation](https://github.com/google/rekall/blob/master/rekall-core/rekall/plugins/overlays/windows/crashdump.py) (most of the structures in [kdmp-parser-structs.h](https://github.com/0vercl0k/kdmp-parser/blob/master/src/kdmp-parser/kdmp-parser-structs.h) have been adapted from it).

Expand Down
25 changes: 24 additions & 1 deletion src/lib/kdmp-parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,8 @@ class KernelDumpParser {
uint8_t *Page = nullptr;
uint64_t MetadataSize = 0;
uint8_t *Bitmap = nullptr;
uint64_t TotalNumberOfPages = 0;
uint64_t CurrentPageCount = 0;

switch (Type) {
case DumpType_t::KernelMemoryDump:
Expand All @@ -597,10 +599,11 @@ class KernelDumpParser {
}

case DumpType_t::CompleteMemoryDump: {
FirstPageOffset = DmpHdr_->u3.RdmpHeader.Hdr.FirstPageOffset;
FirstPageOffset = DmpHdr_->u3.FullRdmpHeader.Hdr.FirstPageOffset;
Page = (uint8_t *)DmpHdr_ + FirstPageOffset;
MetadataSize = DmpHdr_->u3.FullRdmpHeader.Hdr.MetadataSize;
Bitmap = DmpHdr_->u3.FullRdmpHeader.Bitmap.data();
TotalNumberOfPages = DmpHdr_->u3.FullRdmpHeader.TotalNumberOfPages;
break;
}

Expand All @@ -626,13 +629,33 @@ class KernelDumpParser {
uint64_t NumberOfPages;
};

// Sanity check
if (MetadataSize % sizeof(PfnRange)) {
return false;
}

for (uint64_t Offset = 0; Offset < MetadataSize;
Offset += sizeof(PfnRange)) {

if (Type == DumpType_t::CompleteMemoryDump) {
// `CompleteMemoryDump` type seems to be bound by the
// `TotalNumberOfPages` field, *not* by `MetadataSize`.
if (CurrentPageCount == TotalNumberOfPages) {
break;
}

if (CurrentPageCount > TotalNumberOfPages) {
return false;
}
}

const PfnRange &Entry = (PfnRange &)Bitmap[Offset];
if (!FileMap_.InBounds(&Entry, sizeof(Entry))) {
return false;
}

CurrentPageCount += Entry.NumberOfPages;

const uint64_t Pfn = Entry.PageFileNumber;
if (!Pfn) {
break;
Expand Down
Loading