Skip to content

Commit

Permalink
Add u64, p64, u64be and p64be packing aliases (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
yunzheng authored Jun 16, 2022
1 parent 07ce458 commit 3ddd002
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dissect/cobaltstrike/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def pack(n: int, size: int = None, byteorder="little") -> bytes:
u32be = partial(unpack, size=4, byteorder="big")
p32be = partial(pack, size=4, byteorder="big")

u64 = partial(unpack, size=8)
p64 = partial(pack, size=8)
u64be = partial(unpack, size=8, byteorder="big")
p64be = partial(pack, size=8, byteorder="big")


def iter_find_needle(
fp: BinaryIO,
Expand Down
6 changes: 6 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ def test_packing():
assert utils.p8(0x41) == b"A"
assert utils.u8(b"A") == 0x41

assert utils.p64(0x800) == b"\x00\x08\x00\x00\x00\x00\x00\x00"
assert utils.u64(b"\x00\x08\x00\x00\x00\x00\x00\x00") == 0x800

assert utils.p64be(12345) == b"\x00\x00\x00\x00\x00\x0009"
assert utils.u64be(b"\x00\x00\x00\x00\x00\x0009") == 12345

assert utils.unpack(b"ABCDEFGHIJ") == 0x4A494847464544434241
assert utils.unpack_be(b"ABCDEFGHIJ") == 0x4142434445464748494A

Expand Down

0 comments on commit 3ddd002

Please sign in to comment.