mirror of
https://github.com/volatilityfoundation/volatility3.git
synced 2026-09-06 09:47:38 +02:00
transfer deprecated_method into framework module
This commit is contained in:
@@ -11,7 +11,8 @@ import inspect
|
||||
import logging
|
||||
import os
|
||||
import traceback
|
||||
from typing import Any, Dict, Generator, List, Optional, Tuple, Type, TypeVar
|
||||
import functools
|
||||
from typing import Any, Callable, Dict, Generator, List, Optional, Tuple, Type, TypeVar
|
||||
|
||||
from volatility3.framework import constants, interfaces
|
||||
|
||||
@@ -52,6 +53,32 @@ def require_interface_version(*args) -> None:
|
||||
)
|
||||
|
||||
|
||||
class Deprecation:
|
||||
"""Deprecation related methods."""
|
||||
|
||||
@staticmethod
|
||||
def deprecated_method(replacement: Callable, additional_information: str = ""):
|
||||
"""A decorator for marking functions as deprecated.
|
||||
|
||||
Args:
|
||||
replacement: The replacement function overriding the deprecated API, in the form of a Callable (typically a method)
|
||||
additional_information: Information appended at the end of the deprecation message
|
||||
"""
|
||||
|
||||
def decorator(deprecated_func):
|
||||
@functools.wraps(deprecated_func)
|
||||
def wrapper(*args, **kwargs):
|
||||
nonlocal replacement, additional_information
|
||||
deprecation_msg = f"Method \"{deprecated_func.__module__ + '.' + deprecated_func.__name__}\" is deprecated, use \"{replacement.__module__ + '.' + replacement.__name__}\" instead. {additional_information}"
|
||||
vollog.warning(deprecation_msg)
|
||||
# Return the wrapped function with its original arguments
|
||||
return deprecated_func(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
class NonInheritable:
|
||||
def __init__(self, value: Any, cls: Type) -> None:
|
||||
self.default_value = value
|
||||
|
||||
@@ -11,7 +11,6 @@ expect to be in the context (such as particular layers or symboltables).
|
||||
import abc
|
||||
import logging
|
||||
import os
|
||||
import functools
|
||||
from typing import Any, ClassVar, Dict, List, Optional, Set, Tuple, Type
|
||||
from urllib import parse, request
|
||||
|
||||
@@ -724,25 +723,3 @@ class ModuleRequirement(
|
||||
"""Builds the appropriate configuration for the specified
|
||||
requirement."""
|
||||
return context.modules[value].build_configuration()
|
||||
|
||||
|
||||
def deprecated_method(replacement: str, additional_information: str = ""):
|
||||
"""A decorator for marking functions as deprecated.
|
||||
|
||||
Args:
|
||||
replacement: The replacement function overriding the deprecated API (full path preferred, starting from "volatility3."). String was preferred, for convenience and to prevent import conflicts on caller side.
|
||||
additional_information: Information appended at the end of the deprecation message
|
||||
"""
|
||||
|
||||
def decorator(deprecated_func):
|
||||
@functools.wraps(deprecated_func)
|
||||
def wrapper(*args, **kwargs):
|
||||
nonlocal replacement, additional_information
|
||||
deprecation_msg = f"Method \"{deprecated_func.__module__ + '.' + deprecated_func.__name__}\" is deprecated, use \"{replacement}\" instead. {additional_information}"
|
||||
vollog.warning(deprecation_msg)
|
||||
# Return the wrapped function with its original arguments
|
||||
return deprecated_func(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
@@ -10,11 +10,16 @@ from typing import Iterator, List, Tuple, Optional, Union
|
||||
|
||||
import volatility3.framework.symbols.linux.utilities.modules as linux_utilities_modules
|
||||
from volatility3 import framework
|
||||
from volatility3.framework import constants, exceptions, interfaces, objects
|
||||
from volatility3.framework import (
|
||||
constants,
|
||||
exceptions,
|
||||
interfaces,
|
||||
objects,
|
||||
Deprecation,
|
||||
)
|
||||
from volatility3.framework.objects import utility
|
||||
from volatility3.framework.symbols import intermed
|
||||
from volatility3.framework.symbols.linux import extensions
|
||||
from volatility3.framework.configuration import requirements
|
||||
|
||||
vollog = logging.getLogger(__name__)
|
||||
|
||||
@@ -455,8 +460,8 @@ class LinuxUtilities(interfaces.configuration.VersionableInterface):
|
||||
|
||||
## Deprecated APIs ##
|
||||
@classmethod
|
||||
@requirements.deprecated_method(
|
||||
replacement="volatility3.framework.symbols.linux.utilities.modules.Modules.mask_mods_list"
|
||||
@Deprecation.deprecated_method(
|
||||
replacement=linux_utilities_modules.Modules.mask_mods_list
|
||||
)
|
||||
def mask_mods_list(
|
||||
cls,
|
||||
@@ -472,8 +477,8 @@ class LinuxUtilities(interfaces.configuration.VersionableInterface):
|
||||
return linux_utilities_modules.Modules.mask_mods_list(context, layer_name, mods)
|
||||
|
||||
@classmethod
|
||||
@requirements.deprecated_method(
|
||||
replacement="volatility3.framework.symbols.linux.utilities.modules.Modules.lookup_module_address"
|
||||
@Deprecation.deprecated_method(
|
||||
replacement=linux_utilities_modules.Modules.lookup_module_address
|
||||
)
|
||||
def lookup_module_address(
|
||||
cls,
|
||||
|
||||
Reference in New Issue
Block a user