Skip to content

Commit fa47029

Browse files
authored
Merge pull request #50 from mrexodia/minor-improvements
Add support for SAL annotations to NT API
2 parents 644c10b + ed284d6 commit fa47029

File tree

6 files changed

+3737
-3215
lines changed

6 files changed

+3737
-3215
lines changed

src/dumpulator/dumpulator.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ def read(self, addr: int, size: int) -> bytearray:
189189
pages = []
190190
for page_addr, index, length in self.iter_chunks(addr, size):
191191
page = self.pages.get(page_addr, None)
192-
assert page is not None
192+
if page is None:
193+
raise IndexError(f"Could not find page {hex(page_addr)} while reading {hex(addr)}[{hex(size)}]")
193194
pages.append((page, index, length))
194195

195196
if all([page.committed for page, _, _ in pages]):
@@ -212,7 +213,8 @@ def write(self, addr: int, data: bytes) -> None:
212213
pages = []
213214
for page_addr, index, length in self.iter_chunks(addr, len(data)):
214215
page = self.pages.get(page_addr, None)
215-
assert page is not None
216+
if page is None:
217+
raise IndexError(f"Could not find page {hex(page_addr)} while writing {hex(addr)}[{hex(len(data))}]")
216218
pages.append((page, index, length))
217219

218220
if all([page.committed for page, _, _ in pages]):
@@ -1385,6 +1387,20 @@ def syscall_arg(index):
13851387
for i in range(0, argcount):
13861388
argname = argspec.args[1 + i]
13871389
argtype = argspec.annotations[argname]
1390+
# Extract the type information from the annotation
1391+
# Reference: https://github.com/python/cpython/issues/89543
1392+
# It looks like the python designers did an oopsie, so we're going
1393+
# the fully-undocumented route.
1394+
sal = None
1395+
if argtype.__name__ == "Annotated":
1396+
sal, = argtype.__metadata__
1397+
argtype = argtype.__origin__
1398+
1399+
if sal is None:
1400+
sal_pretty = ""
1401+
else:
1402+
sal_pretty = str(sal) + " "
1403+
13881404
argvalue = syscall_arg(i)
13891405
if issubclass(argtype, PVOID):
13901406
argvalue = argtype(argvalue, dp)
@@ -1401,7 +1417,7 @@ def syscall_arg(index):
14011417
if i + 1 == argcount:
14021418
comma = ""
14031419

1404-
dp.info(f" {_arg_type_string(argvalue)} {argname} = {_arg_to_string(dp, argvalue)}{comma}")
1420+
dp.info(f" {sal_pretty}{_arg_type_string(argvalue)} {argname} = {_arg_to_string(dp, argvalue)}{comma}")
14051421
dp.info(")")
14061422
try:
14071423
status = syscall_impl(dp, *args)

0 commit comments

Comments
 (0)