Skip to content

Commit

Permalink
Core: Apply black 24.1.0 to the whole codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
ikelos committed Jan 28, 2024
1 parent 4b86b9e commit 4dc6f63
Show file tree
Hide file tree
Showing 23 changed files with 88 additions and 93 deletions.
8 changes: 5 additions & 3 deletions volatility3/cli/text_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,11 @@ class JsonRenderer(CLIRenderer):
interfaces.renderers.Disassembly: quoted_optional(display_disassembly),
format_hints.MultiTypeData: quoted_optional(multitypedata_as_text),
bytes: optional(lambda x: " ".join([f"{b:02x}" for b in x])),
datetime.datetime: lambda x: x.isoformat()
if not isinstance(x, interfaces.renderers.BaseAbsentValue)
else None,
datetime.datetime: lambda x: (
x.isoformat()
if not isinstance(x, interfaces.renderers.BaseAbsentValue)
else None
),
"default": lambda x: x,
}

Expand Down
6 changes: 3 additions & 3 deletions volatility3/framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ def _zipwalk(path: str):
if not file.is_dir():
dirlist = zip_results.get(os.path.dirname(file.filename), [])
dirlist.append(os.path.basename(file.filename))
zip_results[
os.path.join(path, os.path.dirname(file.filename))
] = dirlist
zip_results[os.path.join(path, os.path.dirname(file.filename))] = (
dirlist
)
for value in zip_results:
yield value, zip_results[value]

Expand Down
6 changes: 3 additions & 3 deletions volatility3/framework/automagic/mac.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ def stack(
config_path = join("automagic", "MacIntelHelper", new_layer_name)
context.config[join(config_path, "memory_layer")] = layer_name
context.config[join(config_path, "page_map_offset")] = dtb
context.config[
join(config_path, MacSymbolFinder.banner_config_key)
] = str(banner, "latin-1")
context.config[join(config_path, MacSymbolFinder.banner_config_key)] = (
str(banner, "latin-1")
)

new_layer = intel.Intel32e(
context,
Expand Down
6 changes: 3 additions & 3 deletions volatility3/framework/automagic/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def __call__(
return None
# The requirement is unfulfilled and is a ModuleRequirement

context.config[
interfaces.configuration.path_join(new_config_path, "class")
] = "volatility3.framework.contexts.Module"
context.config[interfaces.configuration.path_join(new_config_path, "class")] = (
"volatility3.framework.contexts.Module"
)

for req in requirement.requirements:
if (
Expand Down
12 changes: 6 additions & 6 deletions volatility3/framework/automagic/symbol_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ def _banner_scan(
clazz = self.symbol_class
# Set the discovered options
path_join = interfaces.configuration.path_join
context.config[
path_join(config_path, requirement.name, "class")
] = clazz
context.config[
path_join(config_path, requirement.name, "isf_url")
] = isf_path
context.config[path_join(config_path, requirement.name, "class")] = (
clazz
)
context.config[path_join(config_path, requirement.name, "isf_url")] = (
isf_path
)
context.config[
path_join(config_path, requirement.name, "symbol_mask")
] = layer.address_mask
Expand Down
20 changes: 10 additions & 10 deletions volatility3/framework/automagic/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,19 +402,19 @@ def __call__(
if swap_location:
context.config[current_layer_path] = current_layer_name
try:
context.config[
layer_loc_path
] = requirements.URIRequirement.location_from_file(
swap_location
context.config[layer_loc_path] = (
requirements.URIRequirement.location_from_file(
swap_location
)
)
except ValueError:
vollog.warning(
f"Volatility swap_location {swap_location} could not be validated - swap layer disabled"
)
continue
context.config[
layer_class_path
] = "volatility3.framework.layers.physical.FileLayer"
context.config[layer_class_path] = (
"volatility3.framework.layers.physical.FileLayer"
)

# Add the requirement
new_req = requirements.TranslationLayerRequirement(
Expand All @@ -424,9 +424,9 @@ def __call__(
)
swap_req.add_requirement(new_req)

context.config[
path_join(swap_sub_config, "number_of_elements")
] = counter
context.config[path_join(swap_sub_config, "number_of_elements")] = (
counter
)
context.config[swap_sub_config] = True

swap_req.construct(context, swap_config)
Expand Down
6 changes: 3 additions & 3 deletions volatility3/framework/configuration/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,9 @@ def unsatisfied(
config_path = interfaces.configuration.path_join(config_path, self.name)
if not self.matches_required(self._version, self._component.version):
return {config_path: self}
context.config[
interfaces.configuration.path_join(config_path, self.name)
] = True
context.config[interfaces.configuration.path_join(config_path, self.name)] = (
True
)
return {}

@classmethod
Expand Down
6 changes: 3 additions & 3 deletions volatility3/framework/layers/avml.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def stack(
except exceptions.LayerException:
return None
new_name = context.layers.free_layer_name("AVMLLayer")
context.config[
interfaces.configuration.path_join(new_name, "base_layer")
] = layer_name
context.config[interfaces.configuration.path_join(new_name, "base_layer")] = (
layer_name
)
return AVMLLayer(context, new_name, new_name)
6 changes: 3 additions & 3 deletions volatility3/framework/layers/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ def stack(
vollog.log(constants.LOGLEVEL_VVVV, f"Exception: {excp}")
return None
new_name = context.layers.free_layer_name("Elf64Layer")
context.config[
interfaces.configuration.path_join(new_name, "base_layer")
] = layer_name
context.config[interfaces.configuration.path_join(new_name, "base_layer")] = (
layer_name
)

try:
return Elf64Layer(context, new_name, new_name)
Expand Down
6 changes: 3 additions & 3 deletions volatility3/framework/layers/intel.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ def mapping(
This allows translation layers to provide maps of contiguous
regions in one layer
"""
stashed_offset = (
stashed_mapped_offset
) = stashed_size = stashed_mapped_size = stashed_map_layer = None
stashed_offset = stashed_mapped_offset = stashed_size = stashed_mapped_size = (
stashed_map_layer
) = None
for offset, size, mapped_offset, mapped_size, map_layer in self._mapping(
offset, length, ignore_errors
):
Expand Down
6 changes: 3 additions & 3 deletions volatility3/framework/layers/lime.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def stack(
except LimeFormatException:
return None
new_name = context.layers.free_layer_name("LimeLayer")
context.config[
interfaces.configuration.path_join(new_name, "base_layer")
] = layer_name
context.config[interfaces.configuration.path_join(new_name, "base_layer")] = (
layer_name
)
return LimeLayer(context, new_name, new_name)
6 changes: 3 additions & 3 deletions volatility3/framework/layers/qemu.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,9 @@ def stack(
except exceptions.LayerException:
return None
new_name = context.layers.free_layer_name("QemuSuspendLayer")
context.config[
interfaces.configuration.path_join(new_name, "base_layer")
] = layer_name
context.config[interfaces.configuration.path_join(new_name, "base_layer")] = (
layer_name
)
layer = QemuSuspendLayer(context, new_name, new_name)
cls.stacker_slow_warning()
return layer
6 changes: 3 additions & 3 deletions volatility3/framework/layers/xen.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ def stack(
vollog.log(constants.LOGLEVEL_VVVV, f"Exception: {excp}")
return None
new_name = context.layers.free_layer_name("XenCoreDumpLayer")
context.config[
interfaces.configuration.path_join(new_name, "base_layer")
] = layer_name
context.config[interfaces.configuration.path_join(new_name, "base_layer")] = (
layer_name
)

return XenCoreDumpLayer(context, new_name, new_name)
6 changes: 2 additions & 4 deletions volatility3/framework/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,12 +768,10 @@ def child_template(
raise IndexError(f"Member not present in array template: {child}")

@overload
def __getitem__(self, i: int) -> interfaces.objects.Template:
...
def __getitem__(self, i: int) -> interfaces.objects.Template: ...

@overload
def __getitem__(self, s: slice) -> List[interfaces.objects.Template]:
...
def __getitem__(self, s: slice) -> List[interfaces.objects.Template]: ...

def __getitem__(self, i):
"""Returns the i-th item from the array."""
Expand Down
4 changes: 1 addition & 3 deletions volatility3/framework/plugins/mac/pslist.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ def get_requirements(cls):
]

@classmethod
def get_list_tasks(
cls, method: str
) -> Callable[
def get_list_tasks(cls, method: str) -> Callable[
[interfaces.context.ContextInterface, str, Callable[[int], bool]],
Iterable[interfaces.objects.ObjectInterface],
]:
Expand Down
6 changes: 3 additions & 3 deletions volatility3/framework/plugins/windows/crashinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def _generator(self, layer: crash.WindowsCrashDump32Layer):
bitmap_size = format_hints.Hex(summary_header.BitmapSize)
bitmap_pages = format_hints.Hex(summary_header.Pages)
else:
bitmap_header_size = (
bitmap_size
) = bitmap_pages = renderers.NotApplicableValue()
bitmap_header_size = bitmap_size = bitmap_pages = (
renderers.NotApplicableValue()
)

yield (
0,
Expand Down
1 change: 0 additions & 1 deletion volatility3/framework/plugins/windows/mftscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ def run(self):


class ADS(interfaces.plugins.PluginInterface):

"""Scans for Alternate Data Stream"""

_required_framework_version = (2, 0, 0)
Expand Down
10 changes: 6 additions & 4 deletions volatility3/framework/plugins/windows/netscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,12 @@ def generate_timeline(self):
if not isinstance(row_data[9], datetime.datetime):
continue
row_data = [
"N/A"
if isinstance(i, renderers.UnreadableValue)
or isinstance(i, renderers.UnparsableValue)
else i
(
"N/A"
if isinstance(i, renderers.UnreadableValue)
or isinstance(i, renderers.UnparsableValue)
else i
)
for i in row_data
]
description = (
Expand Down
6 changes: 3 additions & 3 deletions volatility3/framework/plugins/windows/registry/printkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ def _printkey_iterator(
vollog.debug(
"Couldn't read registry value type, so data is unreadable"
)
value_data: Union[
interfaces.renderers.BaseAbsentValue, bytes
] = renderers.UnreadableValue()
value_data: Union[interfaces.renderers.BaseAbsentValue, bytes] = (
renderers.UnreadableValue()
)
else:
try:
value_data = node.decode_data()
Expand Down
6 changes: 3 additions & 3 deletions volatility3/framework/renderers/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def wintime_to_datetime(
def unixtime_to_datetime(
unixtime: int,
) -> Union[interfaces.renderers.BaseAbsentValue, datetime.datetime]:
ret: Union[
interfaces.renderers.BaseAbsentValue, datetime.datetime
] = renderers.UnparsableValue()
ret: Union[interfaces.renderers.BaseAbsentValue, datetime.datetime] = (
renderers.UnparsableValue()
)

if unixtime > 0:
with contextlib.suppress(ValueError):
Expand Down
26 changes: 13 additions & 13 deletions volatility3/framework/symbols/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class SymbolSpace(interfaces.symbols.SymbolSpaceInterface):

def __init__(self) -> None:
super().__init__()
self._dict: Dict[
str, interfaces.symbols.BaseSymbolTableInterface
] = collections.OrderedDict()
self._dict: Dict[str, interfaces.symbols.BaseSymbolTableInterface] = (
collections.OrderedDict()
)
# Permanently cache all resolved symbols
self._resolved: Dict[str, interfaces.objects.Template] = {}
self._resolved_symbols: Dict[str, interfaces.objects.Template] = {}
Expand Down Expand Up @@ -73,9 +73,9 @@ def get_symbols_by_location(
self, offset: int, size: int = 0, table_name: str = None
) -> Iterable[str]:
"""Returns all symbols that exist at a specific relative address."""
table_list: Iterable[
interfaces.symbols.BaseSymbolTableInterface
] = self._dict.values()
table_list: Iterable[interfaces.symbols.BaseSymbolTableInterface] = (
self._dict.values()
)
if table_name is not None:
if table_name in self._dict:
table_list = [self._dict[table_name]]
Expand Down Expand Up @@ -179,15 +179,15 @@ def _iterative_resolve(self, traverse_list):
if child.vol.type_name not in self._resolved:
traverse_list.append(child.vol.type_name)
try:
self._resolved[
child.vol.type_name
] = self._weak_resolve(
SymbolType.TYPE, child.vol.type_name
self._resolved[child.vol.type_name] = (
self._weak_resolve(
SymbolType.TYPE, child.vol.type_name
)
)
except exceptions.SymbolError:
self._resolved[
child.vol.type_name
] = self.UnresolvedTemplate(child.vol.type_name)
self._resolved[child.vol.type_name] = (
self.UnresolvedTemplate(child.vol.type_name)
)
# Stash the replacement
replacements.add((traverser, child))
elif child.children:
Expand Down
6 changes: 3 additions & 3 deletions volatility3/framework/symbols/windows/extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,9 @@ def is_valid(self) -> bool:
].is_valid(self.FileName.Buffer)

def file_name_with_device(self) -> Union[str, interfaces.renderers.BaseAbsentValue]:
name: Union[
str, interfaces.renderers.BaseAbsentValue
] = renderers.UnreadableValue()
name: Union[str, interfaces.renderers.BaseAbsentValue] = (
renderers.UnreadableValue()
)

# this pointer needs to be checked against native_layer_name because the object may
# be instantiated from a primary (virtual) layer or a memory (physical) layer.
Expand Down
10 changes: 3 additions & 7 deletions volatility3/plugins/windows/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ def _generator(self):
# Do mass mapping and determine the number of different layers and how many pages go to each one
layer = self.context.layers[self.config["primary"]]

page_count = (
swap_count
) = (
invalid_page_count
) = (
large_page_count
) = large_swap_count = large_invalid_count = other_invalid = 0
page_count = swap_count = invalid_page_count = large_page_count = (
large_swap_count
) = large_invalid_count = other_invalid = 0

if isinstance(layer, intel.Intel):
page_addr = 0
Expand Down

0 comments on commit 4dc6f63

Please sign in to comment.