def test_read_encrypted_info(self) -> None: encrypted_binary = MachoParser(TestMachoBinary.ENCRYPTED_PATH).get_armv7_slice() assert encrypted_binary with pytest.raises(BinaryEncryptedError): # encrypted region is 0x4000 to 0x18000 encrypted_binary.get_bytes(StaticFilePointer(0x5000), 0x1000) # read from unencrypted section should not raise encrypted_binary.get_bytes(StaticFilePointer(0x3000), 0x500)
def dump_memory(parser: MachoParser, start_address: int, size: int) -> None: # XXX(PT): Modified from strongarm-cli data = parser.get_bytes(StaticFilePointer(start_address), size) # split to 16 byte regions region_size = 16 current_index = 0 while True: if current_index >= size or current_index >= len(data): break # grab the next grouping of bytes byte_region = data[current_index : current_index + region_size] region_start = start_address + current_index print(f"{region_start:#011x}", end="\t\t") ascii_rep = "|" for idx, byte in enumerate(byte_region): print("{:02x}".format(byte), end=" ") # indent every 8 bytes if idx > 0 and (idx + 1) % 8 == 0: print("\t", end="") ascii_byte = chr(byte) if 32 <= byte < 127 else "." ascii_rep += ascii_byte ascii_rep += "|" print(ascii_rep) current_index += region_size