Skip to content

Commit

Permalink
Add tests and fix label
Browse files Browse the repository at this point in the history
  • Loading branch information
cccs-jh committed Oct 30, 2024
1 parent b769f1d commit cd38b53
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/multidecoder/decoders/powershell.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def decode_byte(byte: bytes) -> int:
plaintexts = xortool(binary, [0])
if plaintexts:
node.children.append(
Node("POWERSHELL_BYTES_TYPE", plaintexts[0], "multibyte_xor", 0, len(binary), parent=node)
Node(POWERSHELL_BYTES_TYPE, plaintexts[0], "cipher.multibyte_xor", 0, len(binary), parent=node)
)
out.append(node)

Expand Down
43 changes: 43 additions & 0 deletions tests/test_decoders/test_powershell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pytest

from multidecoder.decoders.powershell import POWERSHELL_BYTES_TYPE, find_powershell_bytes
from multidecoder.node import Node


def to_powershell(data: bytes) -> bytes:
return ", ".join(hex(byte) for byte in data).encode()


@pytest.mark.parametrize(
("data", "expected"),
[
(
to_powershell(b"duck" * 200) + b"-bxor",
[
Node(
POWERSHELL_BYTES_TYPE,
b"duck" * 200,
"",
0,
4798,
children=[Node(POWERSHELL_BYTES_TYPE, b"\x00" * 800, "cipher.multibyte_xor", 0, 800)],
)
],
),
(
to_powershell(b"a" * 600) + b" -bxor 65",
[
Node(
POWERSHELL_BYTES_TYPE,
b"a" * 600,
"",
0,
3598,
children=[Node(POWERSHELL_BYTES_TYPE, b" " * 600, "cipher.xor65", 0, 600)],
)
],
),
],
)
def test_find_powershell_bytes(data: bytes, expected):
assert find_powershell_bytes(data) == expected

0 comments on commit cd38b53

Please sign in to comment.