Skip to content

Commit

Permalink
apply unsafe fixes (ruff check --unsafe-fixes --fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
c0rydoras committed Nov 22, 2024
1 parent 72c5c32 commit a91d483
Show file tree
Hide file tree
Showing 21 changed files with 50 additions and 85 deletions.
3 changes: 1 addition & 2 deletions test/plugins/windows/test_scheduled_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ def test_decode_exe_action(self):
self.assertEqual(actions[0].action_type, scheduled_tasks.ActionType.Exe)
except Exception:
self.fail(
"ActionDecoder.decode should not raise exception:\n%s"
% traceback.format_exc()
f"ActionDecoder.decode should not raise exception:\n{traceback.format_exc()}"
)


Expand Down
7 changes: 2 additions & 5 deletions volatility3/framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ def class_subclasses(cls: Type[T]) -> Generator[Type[T], None, None]:
# The typing system is not clever enough to realize that clazz has a hidden attr after the hasattr check
if not hasattr(clazz, "hidden") or not clazz.hidden: # type: ignore
yield clazz
for return_value in class_subclasses(clazz):
yield return_value
yield from class_subclasses(clazz)


def import_files(base_module, ignore_errors: bool = False) -> List[str]:
Expand Down Expand Up @@ -160,9 +159,7 @@ def import_files(base_module, ignore_errors: bool = False) -> List[str]:
def _filter_files(filename: str):
"""Ensures that a filename traversed is an importable python file"""
return (
filename.endswith(".py")
or filename.endswith(".pyc")
or filename.endswith(".pyo")
filename.endswith((".py", ".pyc", ".pyo"))
) and not filename.startswith("__")


Expand Down
3 changes: 1 addition & 2 deletions volatility3/framework/plugins/linux/lsmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ def list_modules(

table_name = modules.vol.type_name.split(constants.BANG)[0]

for module in modules.to_list(table_name + constants.BANG + "module", "list"):
yield module
yield from modules.to_list(table_name + constants.BANG + "module", "list")

def _generator(self):
try:
Expand Down
2 changes: 1 addition & 1 deletion volatility3/framework/plugins/linux/sockstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def _bluetooth_sock(
bt_sock = sock.cast("bt_sock")

def bt_addr(addr):
return ":".join(reversed(["%02x" % x for x in addr.b]))
return ":".join(reversed([f"{x:02x}" for x in addr.b]))

src_addr = src_port = dst_addr = dst_port = None
bt_protocol = bt_sock.get_protocol()
Expand Down
5 changes: 2 additions & 3 deletions volatility3/framework/plugins/mac/check_sysctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ def _process_sysctl_list(self, kernel, sysctl_list, recursive=0):
val = self._parse_global_variable_sysctls(kernel, name)
elif ctltype == "CTLTYPE_NODE":
if sysctl.oid_handler == 0:
for info in self._process_sysctl_list(
yield from self._process_sysctl_list(
kernel, sysctl.oid_arg1, recursive=1
):
yield info
)

val = "Node"

Expand Down
3 changes: 1 addition & 2 deletions volatility3/framework/plugins/mac/kevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ def _walk_klist_array(cls, kernel, fdp, array_pointer_member, array_size_member)
return None

for klist in klist_array:
for kn in mac.MacUtilities.walk_slist(klist, "kn_link"):
yield kn
yield from mac.MacUtilities.walk_slist(klist, "kn_link")

@classmethod
def _get_task_kevents(cls, kernel, task):
Expand Down
3 changes: 1 addition & 2 deletions volatility3/framework/plugins/mac/mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ def list_mounts(

list_head = kernel.object_from_symbol(symbol_name="mountlist")

for mount in mac.MacUtilities.walk_tailq(list_head, "mnt_list"):
yield mount
yield from mac.MacUtilities.walk_tailq(list_head, "mnt_list")

def _generator(self):
for mount in self.list_mounts(self.context, self.config["kernel"]):
Expand Down
3 changes: 1 addition & 2 deletions volatility3/framework/plugins/timeliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ def _generator(
)
vollog.log(logging.DEBUG, traceback.format_exc())

for data_item in sorted(data, key=self._sort_function):
yield data_item
yield from sorted(data, key=self._sort_function)

# Write out a body file if necessary
if self.config.get("create-bodyfile", True):
Expand Down
6 changes: 2 additions & 4 deletions volatility3/framework/plugins/windows/handles.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,7 @@ def _make_handle_array(self, offset, level, depth=0):

for entry in table:
if level > 0:
for x in self._make_handle_array(entry, level - 1, depth):
yield x
yield from self._make_handle_array(entry, level - 1, depth)
depth += 1
else:
handle_multiplier = 4
Expand Down Expand Up @@ -372,8 +371,7 @@ def handles(self, handle_table):
)
return None

for handle_table_entry in self._make_handle_array(TableCode, table_levels):
yield handle_table_entry
yield from self._make_handle_array(TableCode, table_levels)

def _generator(self, procs):
kernel = self.context.modules[self.config["kernel"]]
Expand Down
3 changes: 1 addition & 2 deletions volatility3/framework/plugins/windows/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ def list_modules(
object_type=type_name, offset=list_entry.vol.offset - reloff, absolute=True
)

for mod in module.InLoadOrderLinks:
yield mod
yield from module.InLoadOrderLinks

def run(self):
return renderers.TreeGrid(
Expand Down
5 changes: 2 additions & 3 deletions volatility3/framework/plugins/windows/netstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,14 +488,13 @@ def list_sockets(
"""

# first, TCP endpoints by parsing the partition table
for endpoint in cls.parse_partitions(
yield from cls.parse_partitions(
context,
layer_name,
net_symbol_table,
tcpip_symbol_table,
tcpip_module_offset,
):
yield endpoint
)

# then, towards the UDP and TCP port pools
# first, find their addresses
Expand Down
7 changes: 3 additions & 4 deletions volatility3/framework/plugins/windows/shimcachemem.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,9 @@ def find_shimcache_win_2k3_to_7(
if not shim_head:
return

for shim_entry in shim_head.ListEntry.to_list(
yield from shim_head.ListEntry.to_list(
shimcache_symbol_table + constants.BANG + "SHIM_CACHE_ENTRY", "ListEntry"
):
yield shim_entry
)

@classmethod
def try_get_shim_head_at_offset(
Expand Down Expand Up @@ -333,7 +332,7 @@ def try_get_shim_head_at_offset(
eresource_rel_off = ersrc_size + ((offset - ersrc_size) % ersrc_alignment)
eresource_offset = offset - eresource_rel_off

vollog.debug("Constructing ERESOURCE at %s" % hex(eresource_offset))
vollog.debug(f"Constructing ERESOURCE at {hex(eresource_offset)}")
eresource = context.object(
kernel_symbol_table + constants.BANG + "_ERESOURCE",
layer_name,
Expand Down
5 changes: 2 additions & 3 deletions volatility3/framework/plugins/windows/svclist.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,10 @@ def service_list(
scanner=scanners.BytesScanner(needle=b"Sc27"),
sections=exe_range,
):
for record in cls.enumerate_vista_or_later_header(
yield from cls.enumerate_vista_or_later_header(
context,
service_table_name,
service_binary_dll_map,
layer_name,
offset,
):
yield record
)
3 changes: 1 addition & 2 deletions volatility3/framework/plugins/windows/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,4 @@ def list_process_threads(
symbol_table=symbol_table_name,
filter_func=filter_func,
):
for thread in cls.list_threads(module, proc):
yield thread
yield from cls.list_threads(module, proc)
3 changes: 1 addition & 2 deletions volatility3/framework/plugins/windows/unloadedmodules.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ def list_unloadedmodules(
)
unloadedmodules_array.UnloadedDrivers.count = unloaded_count

for mod in unloadedmodules_array.UnloadedDrivers:
yield mod
yield from unloadedmodules_array.UnloadedDrivers

def _generator(self):
kernel = self.context.modules[self.config["kernel"]]
Expand Down
3 changes: 1 addition & 2 deletions volatility3/framework/plugins/windows/virtmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ def scannable_sections(
mapping = cls.determine_map(module)
for entry in mapping:
if "Unused" not in entry:
for value in mapping[entry]:
yield value
yield from mapping[entry]

def run(self):
kernel = self.context.modules[self.config["kernel"]]
Expand Down
6 changes: 2 additions & 4 deletions volatility3/framework/symbols/linux/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,7 @@ def _iter_node(self, nodep, height) -> Iterator[int]:
if self.is_valid_node(nodep):
yield nodep
else:
for child_node in self._iter_node(nodep, height - 1):
yield child_node
yield from self._iter_node(nodep, height - 1)

def get_entries(self, root: interfaces.objects.ObjectInterface) -> Iterator[int]:
"""Walks the tree data structure
Expand Down Expand Up @@ -659,8 +658,7 @@ def get_entries(self, root: interfaces.objects.ObjectInterface) -> Iterator[int]
if self.is_valid_node(nodep):
yield nodep
else:
for child_node in self._iter_node(nodep, height):
yield child_node
yield from self._iter_node(nodep, height)


class XArray(IDStorage):
Expand Down
12 changes: 4 additions & 8 deletions volatility3/framework/symbols/linux/extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ def get_sections(self):
count=num_sects,
)

for attr in arr:
yield attr
yield from arr

def get_elf_table_name(self):
elf_table_name = intermed.IntermediateSymbolTable.create(
Expand Down Expand Up @@ -237,8 +236,7 @@ def get_symbols(self):
count=self.num_symtab + 1,
)
if self.section_strtab:
for sym in syms:
yield sym
yield from syms

def get_symbols_names_and_addresses(self) -> Iterable[Tuple[str, int]]:
"""Get names and addresses for each symbol of the module
Expand Down Expand Up @@ -2658,8 +2656,7 @@ def _new_kernel_get_entries(self) -> Iterable[int]:
id_storage = linux.IDStorage.choose_id_storage(
self._context, kernel_module_name="kernel"
)
for page_addr in id_storage.get_entries(root=self.idr_rt):
yield page_addr
yield from id_storage.get_entries(root=self.idr_rt)

def get_entries(self) -> Iterable[int]:
"""Walks the IDR and yield a pointer associated with each element.
Expand All @@ -2677,8 +2674,7 @@ def get_entries(self) -> Iterable[int]:
# Kernels < 4.11
get_entries_func = self._old_kernel_get_entries

for page_addr in get_entries_func():
yield page_addr
yield from get_entries_func()


class rb_root(objects.StructType):
Expand Down
15 changes: 6 additions & 9 deletions volatility3/framework/symbols/mac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,9 @@ def walk_tailq(
next_member: str,
max_elements: int = 4096,
) -> Iterable[interfaces.objects.ObjectInterface]:
for element in cls._walk_iterable(
yield from cls._walk_iterable(
queue, "tqh_first", "tqe_next", next_member, max_elements
):
yield element
)

@classmethod
def walk_list_head(
Expand All @@ -244,10 +243,9 @@ def walk_list_head(
next_member: str,
max_elements: int = 4096,
) -> Iterable[interfaces.objects.ObjectInterface]:
for element in cls._walk_iterable(
yield from cls._walk_iterable(
queue, "lh_first", "le_next", next_member, max_elements
):
yield element
)

@classmethod
def walk_slist(
Expand All @@ -256,7 +254,6 @@ def walk_slist(
next_member: str,
max_elements: int = 4096,
) -> Iterable[interfaces.objects.ObjectInterface]:
for element in cls._walk_iterable(
yield from cls._walk_iterable(
queue, "slh_first", "sle_next", next_member, max_elements
):
yield element
)
15 changes: 6 additions & 9 deletions volatility3/framework/symbols/windows/extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,11 +749,10 @@ def load_order_modules(self) -> Iterable[interfaces.objects.ObjectInterface]:

try:
peb = self.get_peb()
for entry in peb.Ldr.InLoadOrderModuleList.to_list(
yield from peb.Ldr.InLoadOrderModuleList.to_list(
f"{self.get_symbol_table_name()}{constants.BANG}_LDR_DATA_TABLE_ENTRY",
"InLoadOrderLinks",
):
yield entry
)
except exceptions.InvalidAddressException:
return None

Expand All @@ -762,11 +761,10 @@ def init_order_modules(self) -> Iterable[interfaces.objects.ObjectInterface]:

try:
peb = self.get_peb()
for entry in peb.Ldr.InInitializationOrderModuleList.to_list(
yield from peb.Ldr.InInitializationOrderModuleList.to_list(
f"{self.get_symbol_table_name()}{constants.BANG}_LDR_DATA_TABLE_ENTRY",
"InInitializationOrderLinks",
):
yield entry
)
except exceptions.InvalidAddressException:
return None

Expand All @@ -775,11 +773,10 @@ def mem_order_modules(self) -> Iterable[interfaces.objects.ObjectInterface]:

try:
peb = self.get_peb()
for entry in peb.Ldr.InMemoryOrderModuleList.to_list(
yield from peb.Ldr.InMemoryOrderModuleList.to_list(
f"{self.get_symbol_table_name()}{constants.BANG}_LDR_DATA_TABLE_ENTRY",
"InMemoryOrderLinks",
):
yield entry
)
except exceptions.InvalidAddressException:
return None

Expand Down
Loading

0 comments on commit a91d483

Please sign in to comment.