Created
January 3, 2024 18:30
-
-
Save smlu/1267e064ffe3387ee7abc0f7b213965b to your computer and use it in GitHub Desktop.
Windows Predictive Failure Analysis (PFA) Memory List Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mmap | |
from typing import List | |
def get_bcdedit_set_badmemory_command(start_addr: int, end_addr: int) -> str: | |
pages: str = '' | |
pstart = start_addr // mmap.PAGESIZE | |
pend = (end_addr + mmap.PAGESIZE - 1) // mmap.PAGESIZE | |
for p in range(pstart, pend + 1): | |
pages += f'{hex(p)} ' | |
return f'bcdedit /set {{badmemory}} badmemorylist {pages}' | |
def decode_pfn_memorylist(data: str): | |
# Note, decoding of addresses as 4 bytes integer (32bit) | |
pages = [] | |
for i in range(0, len(data), 8): | |
page = int(data[i:i+8][::-1], 16) | |
pages.append(page) | |
return pages | |
def encode_pfn_memorylist(pages: List[int]) -> str: | |
# Note, encoding of addresses as 4 bytes integer (32bit) | |
memlist: str = "" | |
for p in pages: | |
memlist += f'{p:08X}'[::-1] | |
return memlist |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment