Skip to content

Commit

Permalink
Development: Add stub files
Browse files Browse the repository at this point in the history
With the plugin module __path__ variable updated at runtime, and plugin
imports based on this updated path within their own module definitions,
static type checkers and language servers cannot resolve these imports
to provide support for autocompletion, type-checking, etc.

This commit:
- Adds the required stub files to make development easier when working
  on plugins
- Removes the stubs directory from the .gitignore file
- Adds a [tool.pyright] section to tell pyright where to look for stubs

Development: Additional stub updates
  • Loading branch information
dgmcdona committed Feb 28, 2025
1 parent 795b853 commit c7c83ca
Show file tree
Hide file tree
Showing 8 changed files with 333 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ workspace.xml

# Manually generated files
.mypy_cache
stubs
volatility3/symbols/linux*
volatility3/symbols/windows*
volatility3/symbols/mac*
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ include = ["volatility3*"]
mypy_path = "./stubs"
show_traceback = true

[tool.pyright]
stubPath = "./stubs"

[tool.ruff]
line-length = 88
target-version = "py38"
Expand Down
14 changes: 14 additions & 0 deletions stubs/volatility3/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from importlib import abc
from typing import Any, Callable

class classproperty(property):
def __init__(self, func: Callable[[_S], _T]) -> None: ...

Check failure on line 5 in stubs/volatility3/__init__.pyi

View workflow job for this annotation

GitHub Actions / lint

Ruff (F821)

stubs/volatility3/__init__.pyi:5:40: F821 Undefined name `_S`

Check failure on line 5 in stubs/volatility3/__init__.pyi

View workflow job for this annotation

GitHub Actions / lint

Ruff (F821)

stubs/volatility3/__init__.pyi:5:45: F821 Undefined name `_T`
def __get__(self, obj: Any, type: _S | None = None) -> _T: ...

Check failure on line 6 in stubs/volatility3/__init__.pyi

View workflow job for this annotation

GitHub Actions / lint

Ruff (F821)

stubs/volatility3/__init__.pyi:6:39: F821 Undefined name `_S`

Check failure on line 6 in stubs/volatility3/__init__.pyi

View workflow job for this annotation

GitHub Actions / lint

Ruff (F821)

stubs/volatility3/__init__.pyi:6:60: F821 Undefined name `_T`

class WarningFindSpec(abc.MetaPathFinder):
@staticmethod
def find_spec(
fullname: str, path: list[str] | None, target: None = None, **kwargs
) -> None: ...

warning_find_spec: list[abc.MetaPathFinder]
27 changes: 27 additions & 0 deletions stubs/volatility3/plugins/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from volatility3.framework.plugins import (
banners,
configwriter,
isfinfo,
layerwriter,
linux,
mac,
regexscan,
timeliner,
vmscan,
windows,
yarascan,
)

__all__ = [
"banners",
"configwriter",
"isfinfo",
"layerwriter",
"linux",
"mac",
"regexscan",
"timeliner",
"vmscan",
"windows",
"yarascan",
]
85 changes: 85 additions & 0 deletions stubs/volatility3/plugins/linux/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from volatility3.framework.plugins.linux import (
bash,
boottime,
capabilities,
check_afinfo,
check_creds,
check_idt,
check_modules,
check_syscall,
ebpf,
elfs,
envars,
hidden_modules,
iomem,
ip,
kallsyms,
keyboard_notifiers,
kmsg,
kthreads,
library_list,
lsmod,
lsof,
malfind,
modxview,
mountinfo,
netfilter,
pagecache,
pidhashtable,
proc,
psaux,
pscallstack,
pslist,
psscan,
pstree,
ptrace,
sockstat,
tracing,
tty_check,
vmaregexscan,
vmayarascan,
vmcoreinfo,
)

__all__ = [
"bash",
"boottime",
"capabilities",
"check_afinfo",
"check_creds",
"check_idt",
"check_modules",
"check_syscall",
"ebpf",
"elfs",
"envars",
"hidden_modules",
"iomem",
"ip",
"kallsyms",
"keyboard_notifiers",
"kmsg",
"kthreads",
"library_list",
"lsmod",
"lsof",
"malfind",
"modxview",
"mountinfo",
"netfilter",
"pagecache",
"pidhashtable",
"proc",
"psaux",
"pscallstack",
"pslist",
"psscan",
"pstree",
"ptrace",
"sockstat",
"tracing",
"tty_check",
"vmaregexscan",
"vmayarascan",
"vmcoreinfo",
]
51 changes: 51 additions & 0 deletions stubs/volatility3/plugins/mac/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from volatility3.framework.plugins.mac import (
bash,
check_syscall,
check_sysctl,
check_trap_table,
dmesg,
ifconfig,
kauth_listeners,
kauth_scopes,
kevents,
list_files,
lsmod,
lsof,
malfind,
mount,
netstat,
proc_maps,
psaux,
pslist,
pstree,
socket_filters,
timers,
trustedbsd,
vfsevents,
)

__all__ = [
"bash",
"check_syscall",
"check_sysctl",
"check_trap_table",
"dmesg",
"ifconfig",
"kauth_listeners",
"kauth_scopes",
"kevents",
"list_files",
"lsmod",
"lsof",
"malfind",
"mount",
"netstat",
"proc_maps",
"psaux",
"pslist",
"pstree",
"socket_filters",
"timers",
"trustedbsd",
"vfsevents",
]
153 changes: 153 additions & 0 deletions stubs/volatility3/plugins/windows/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
from volatility3.framework.plugins.windows import (
amcache,
bigpools,
cachedump,
callbacks,
cmdline,
cmdscan,
consoles,
crashinfo,
debugregisters,
devicetree,
direct_system_calls,
dlllist,
driverirp,
drivermodule,
driverscan,
dumpfiles,
envars,
filescan,
getservicesids,
getsids,
handles,
hashdump,
hollowprocesses,
iat,
indirect_system_calls,
info,
joblinks,
kpcrs,
ldrmodules,
lsadump,
malfind,
mbrscan,
memmap,
mftscan,
modscan,
modules,
mutantscan,
netscan,
netstat,
orphan_kernel_threads,
pe_symbols,
pedump,
poolscanner,
privileges,
processghosting,
pslist,
psscan,
pstree,
psxview,
registry,
scheduled_tasks,
sessions,
shimcachemem,
skeleton_key_check,
ssdt,
strings,
suspended_threads,
suspicious_threads,
svcdiff,
svclist,
svcscan,
symlinkscan,
thrdscan,
threads,
timers,
truecrypt,
unhooked_system_calls,
unloadedmodules,
vadinfo,
vadregexscan,
vadwalk,
vadyarascan,
verinfo,
virtmap,
)

__all__ = [
"amcache",
"bigpools",
"cachedump",
"callbacks",
"cmdline",
"cmdscan",
"consoles",
"crashinfo",
"debugregisters",
"devicetree",
"direct_system_calls",
"dlllist",
"driverirp",
"drivermodule",
"driverscan",
"dumpfiles",
"envars",
"filescan",
"getservicesids",
"getsids",
"handles",
"hashdump",
"hollowprocesses",
"iat",
"indirect_system_calls",
"info",
"joblinks",
"kpcrs",
"ldrmodules",
"lsadump",
"malfind",
"mbrscan",
"memmap",
"mftscan",
"modscan",
"modules",
"mutantscan",
"netscan",
"netstat",
"orphan_kernel_threads",
"pe_symbols",
"pedump",
"poolscanner",
"privileges",
"processghosting",
"pslist",
"psscan",
"pstree",
"psxview",
"registry",
"scheduled_tasks",
"sessions",
"shimcachemem",
"skeleton_key_check",
"ssdt",
"strings",
"suspended_threads",
"suspicious_threads",
"svcdiff",
"svclist",
"svcscan",
"symlinkscan",
"thrdscan",
"threads",
"timers",
"truecrypt",
"unhooked_system_calls",
"unloadedmodules",
"vadinfo",
"vadregexscan",
"vadwalk",
"vadyarascan",
"verinfo",
"virtmap",
]
Empty file added volatility3/py.typed
Empty file.

0 comments on commit c7c83ca

Please sign in to comment.