From 0d0fffcd7a16c4efa587f4e040b4552b1faaebd4 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Fri, 5 Nov 2021 11:35:38 -0400 Subject: [PATCH] Agent: Add performance-related TODOs to bit_manipulators.py --- monkey/infection_monkey/utils/bit_manipulators.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/monkey/infection_monkey/utils/bit_manipulators.py b/monkey/infection_monkey/utils/bit_manipulators.py index 8e87e6768..25280b813 100644 --- a/monkey/infection_monkey/utils/bit_manipulators.py +++ b/monkey/infection_monkey/utils/bit_manipulators.py @@ -2,10 +2,25 @@ def flip_bits(data: bytes) -> bytes: flipped_bits = bytearray(len(data)) for i, byte in enumerate(data): + # TODO: The function call to flip_bits_in_single_byte() adds significant + # overhead. While python is supposed to "inline" function calls + # like this, I've yet to see any changes in runtime that indicate + # this optimization is actually happening. + # + # The value of breaking this into separate functions is the unit + # test that tests all possible bytes (0-255). This gives us + # confidence that our bit-flip operation is correct. + # + # Remove the flip_bits_in_single_byte() function and rework the + # unit tests so that we still have a high-degree of confidence + # that this code is correct. flipped_bits[i] = flip_bits_in_single_byte(byte) return bytes(flipped_bits) def flip_bits_in_single_byte(byte) -> int: + # TODO: The operation `255 - byte` appears to be 12% faster than 255 ^ byte. + # Switch the operator and thoroughly test the ransomware payload to + # ensure this doesn't introduce any defects. return 255 ^ byte