Skip to content

Commit

Permalink
Merge pull request #76 from mrexodia/fix-guard-pages
Browse files Browse the repository at this point in the history
Fix a bug in the minidump library to support guard pages
  • Loading branch information
mrexodia authored May 6, 2023
2 parents 19af557 + 4647c78 commit 7bc153d
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/minidump/streams/MemoryInfoListStream.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#
import io
import enum
from minidump.common_structs import *
from minidump.common_structs import *

class AllocationProtect(enum.Enum):
class AllocationProtect(enum.Flag):
NONE = 0
PAGE_EXECUTE = 0x10 #Enables execute access to the committed region of pages. An attempt to write to the committed region results in an access violation.
#This flag is not supported by the CreateFileMapping function.
Expand Down Expand Up @@ -51,7 +51,7 @@ class AllocationProtect(enum.Enum):
#The PAGE_WRITECOMBINE flag cannot be specified with the PAGE_NOACCESS, PAGE_GUARD, and PAGE_NOCACHE flags.
#The PAGE_WRITECOMBINE flag can be used only when allocating private memory with the VirtualAlloc, VirtualAllocEx, or VirtualAllocExNuma functions. To enable write-combined memory access for shared memory, specify the SEC_WRITECOMBINE flag when calling the CreateFileMapping function.
#Windows Server 2003 and Windows XP: This flag is not supported until Windows Server 2003 with SP1.

class MemoryType(enum.Enum):
MEM_IMAGE = 0x1000000 #Indicates that the memory pages within the region are mapped into the view of an image section.
MEM_MAPPED = 0x40000 #Indicates that the memory pages within the region are mapped into the view of a section.
Expand All @@ -78,17 +78,17 @@ def to_bytes(self):
t += self.SizeOfEntry.to_bytes(4, byteorder = 'little', signed = False)
t += len(self.entries).to_bytes(8, byteorder = 'little', signed = False)
return t

@staticmethod
def parse(buff):
mhds = MINIDUMP_MEMORY_INFO_LIST()
mhds.SizeOfHeader = int.from_bytes(buff.read(4), byteorder = 'little', signed = False)
mhds.SizeOfEntry = int.from_bytes(buff.read(4), byteorder = 'little', signed = False)
mhds.NumberOfEntries = int.from_bytes(buff.read(8), byteorder = 'little', signed = False)

return mhds
# https://msdn.microsoft.com/en-us/library/windows/desktop/ms680386(v=vs.85).aspx

# https://msdn.microsoft.com/en-us/library/windows/desktop/ms680386(v=vs.85).aspx
class MINIDUMP_MEMORY_INFO:
def __init__(self):
self.BaseAddress = None
Expand Down Expand Up @@ -121,7 +121,7 @@ def to_bytes(self):
t += self.Type.value.to_bytes(4, byteorder = 'little', signed = False)
t += self.__alignment2.to_bytes(4, byteorder = 'little', signed = False)
return t

@staticmethod
def parse(buff):
mmi = MINIDUMP_MEMORY_INFO()
Expand All @@ -143,9 +143,9 @@ def parse(buff):
except:
pass
mmi.__alignment2 = int.from_bytes(buff.read(4), byteorder = 'little', signed = False)

return mmi

class MinidumpMemoryInfo:
def __init__(self):
self.BaseAddress = None
Expand All @@ -155,7 +155,7 @@ def __init__(self):
self.State = None
self.Protect = None
self.Type = None

@staticmethod
def parse(t, buff):
mmi = MinidumpMemoryInfo()
Expand All @@ -167,7 +167,7 @@ def parse(t, buff):
mmi.Protect = t.Protect
mmi.Type = t.Type
return mmi

@staticmethod
def get_header():
t = [
Expand All @@ -192,13 +192,13 @@ def to_row(self):
self.Type.name if self.Type else 'N/A',
]
return t


class MinidumpMemoryInfoList:
def __init__(self):
self.header = None
self.infos = []

@staticmethod
def parse(dir, buff):
t = MinidumpMemoryInfoList()
Expand All @@ -209,7 +209,7 @@ def parse(dir, buff):
for _ in range(t.header.NumberOfEntries):
mi = MINIDUMP_MEMORY_INFO.parse(chunk)
t.infos.append(MinidumpMemoryInfo.parse(mi, buff))

return t

@staticmethod
Expand All @@ -222,15 +222,15 @@ async def aparse(dir, buff):
for _ in range(t.header.NumberOfEntries):
mi = MINIDUMP_MEMORY_INFO.parse(chunk)
t.infos.append(MinidumpMemoryInfo.parse(mi, None))

return t

def to_table(self):
t = []
t.append(MinidumpMemoryInfo.get_header())
for info in self.infos:
t.append(info.to_row())
return t

def __str__(self):
return '== MinidumpMemoryInfoList ==\n' + construct_table(self.to_table())

0 comments on commit 7bc153d

Please sign in to comment.