Skip to content

Commit

Permalink
fix black/style
Browse files Browse the repository at this point in the history
  • Loading branch information
msm-code committed Dec 19, 2024
1 parent be6fd0b commit 1dc9bd9
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def get_match_context(
expression_key = string_match.instances[0]

(before, matching, after) = read_bytes_with_context(
data, expression_key.matched_length, expression_key.offset
data, expression_key.offset, expression_key.matched_length
)
match_context[expression_key] = {
"before": base64.b64encode(before).decode("utf-8"),
Expand Down Expand Up @@ -332,12 +332,10 @@ def run_yara_batch(job_id: JobId, iterator: str, batch_size: int) -> None:


def read_bytes_with_context(
data: bytes, matched_length: int, offset: int, byte_range: int = 32
data: bytes, offset: int, length: int, context: int = 32
) -> tuple[bytes, bytes, bytes]:
"""Return `matched_length` bytes from `offset`, along with `byte_range` bytes before and after the match."""

before = data[max(0, offset - byte_range) : offset]
matching = data[offset : offset + matched_length]
after = data[offset + matched_length : offset + matched_length + byte_range]

before = data[max(0, offset - context) : offset]
matching = data[offset : offset + length]
after = data[offset + length : offset + length + context]
return before, matching, after

0 comments on commit 1dc9bd9

Please sign in to comment.