From fe7faffd07fd6f938801dd0ba8c679de5a6aa95f Mon Sep 17 00:00:00 2001 From: insolor <2442833+insolor@users.noreply.github.com> Date: Thu, 7 Nov 2024 23:28:39 +0300 Subject: [PATCH] Add tqdm progressbar to find_relative_cross_references function --- .../cross_references_relative.py | 8 ++++--- dfint64_patch/extract_strings/cli.py | 6 ++--- poetry.lock | 23 ++++++++++++++++++- pyproject.toml | 1 + 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/dfint64_patch/cross_references/cross_references_relative.py b/dfint64_patch/cross_references/cross_references_relative.py index 2528eed..b4cd588 100644 --- a/dfint64_patch/cross_references/cross_references_relative.py +++ b/dfint64_patch/cross_references/cross_references_relative.py @@ -2,6 +2,8 @@ from collections.abc import Iterable, Iterator, Mapping from itertools import chain +from tqdm import tqdm + from dfint64_patch.type_aliases import Rva REFERENCE_SIZE = 4 @@ -26,10 +28,10 @@ def find_relative_cross_references( if not isinstance(addresses, range | dict): addresses = set(addresses) - for i in range(len(bytes_block) - 3): - relative_offset = int.from_bytes(bytes(view[i : i + 4]), byteorder="little", signed=True) + for i in tqdm(range(len(bytes_block) - REFERENCE_SIZE + 1), desc="find_relative_cross_references"): + relative_offset = int.from_bytes(bytes(view[i : i + REFERENCE_SIZE]), byteorder="little", signed=True) - destination = Rva(base_address + i + 4 + relative_offset) + destination = Rva(base_address + i + REFERENCE_SIZE + relative_offset) if destination in addresses: result[destination].append(Rva(base_address + i)) diff --git a/dfint64_patch/extract_strings/cli.py b/dfint64_patch/extract_strings/cli.py index e4c5577..488f6b4 100644 --- a/dfint64_patch/extract_strings/cli.py +++ b/dfint64_patch/extract_strings/cli.py @@ -3,7 +3,6 @@ from pathlib import Path from typing import BinaryIO, cast -from loguru import logger from omegaconf import DictConfig from peclasses.portable_executable import PortableExecutable @@ -55,9 +54,8 @@ class ExtractConfig(DictConfig): @with_config(ExtractConfig, ".extract.yaml") def main(conf: ExtractConfig) -> None: with Path(conf.file_name).open("rb") as pe_file, maybe_open(conf.out_file) as out_file_object: - for address, string in extract_strings(pe_file): - print(string, file=out_file_object) - logger.info(f"0x{address:X} {string!r}") + for item in extract_strings(pe_file): + print(item.string, file=out_file_object) if __name__ == "__main__": diff --git a/poetry.lock b/poetry.lock index 93e409f..5393062 100644 --- a/poetry.lock +++ b/poetry.lock @@ -508,6 +508,27 @@ files = [ {file = "tomli-2.0.2.tar.gz", hash = "sha256:d46d457a85337051c36524bc5349dd91b1877838e2979ac5ced3e710ed8a60ed"}, ] +[[package]] +name = "tqdm" +version = "4.67.0" +description = "Fast, Extensible Progress Meter" +optional = false +python-versions = ">=3.7" +files = [ + {file = "tqdm-4.67.0-py3-none-any.whl", hash = "sha256:0cd8af9d56911acab92182e88d763100d4788bdf421d251616040cc4d44863be"}, + {file = "tqdm-4.67.0.tar.gz", hash = "sha256:fe5a6f95e6fe0b9755e9469b77b9c3cf850048224ecaa8293d7d2d31f97d869a"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} + +[package.extras] +dev = ["pytest (>=6)", "pytest-cov", "pytest-timeout", "pytest-xdist"] +discord = ["requests"] +notebook = ["ipywidgets (>=6)"] +slack = ["slack-sdk"] +telegram = ["requests"] + [[package]] name = "typing-extensions" version = "4.12.2" @@ -536,4 +557,4 @@ dev = ["black (>=19.3b0)", "pytest (>=4.6.2)"] [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "e8f7007c89f47442862f8dbaf7b109ee0ce9dd24d646139c3050d72a1b5fc40f" +content-hash = "4c7fab8450a9c8530ad75a206a1cc391a67f65536f0a5a484728ace05d47b630" diff --git a/pyproject.toml b/pyproject.toml index 00a80a2..0eed751 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,6 +12,7 @@ loguru = "^0.7.2" peclasses = {version = "^0.4.0", source = "dfint"} omegaconf = "^2.3.0" poethepoet = "^0.29.0" +tqdm = "^4.67.0" [tool.poetry.group.dev.dependencies] pytest = "^8.3.3"