Skip to content

Commit

Permalink
Add tqdm progressbar to find_relative_cross_references function
Browse files Browse the repository at this point in the history
  • Loading branch information
insolor committed Nov 7, 2024
1 parent 2fc9d6d commit fe7faff
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
8 changes: 5 additions & 3 deletions dfint64_patch/cross_references/cross_references_relative.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
6 changes: 2 additions & 4 deletions dfint64_patch/extract_strings/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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__":
Expand Down
23 changes: 22 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit fe7faff

Please sign in to comment.