From 9b6403f830b9b386b3343e80e8dbe2bbee185d48 Mon Sep 17 00:00:00 2001 From: Han Dai Date: Wed, 10 Jan 2024 02:49:18 -0500 Subject: [PATCH] easier for user to add unused funcs --- .../allocation_managers/allocation_manager.py | 17 +++++++++++++++++ src/patcherex2/targets/elf_leon3_bare.py | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/patcherex2/components/allocation_managers/allocation_manager.py b/src/patcherex2/components/allocation_managers/allocation_manager.py index 084cd8e..376494f 100644 --- a/src/patcherex2/components/allocation_managers/allocation_manager.py +++ b/src/patcherex2/components/allocation_managers/allocation_manager.py @@ -87,6 +87,23 @@ def add_block(self, block): self.blocks[type(block)].sort() self.coalesce(self.blocks[type(block)]) + def add_free_space(self, addr, size, flag="RX"): + _flag = 0 + if "r" in flag.lower(): + _flag |= MemoryFlag.R + if "w" in flag.lower(): + _flag |= MemoryFlag.W + if "x" in flag.lower(): + _flag |= MemoryFlag.X + block = MappedBlock( + self.p.binary_analyzer.mem_addr_to_file_offset(addr), + addr, + size, + is_free=True, + flag=_flag, + ) + self.p.allocation_manager.add_block(block) + def _find_in_mapped_blocks(self, size, flag=MemoryFlag.RWX, align=0x1): best_fit = None for block in self.blocks[MappedBlock]: diff --git a/src/patcherex2/targets/elf_leon3_bare.py b/src/patcherex2/targets/elf_leon3_bare.py index 9e447b4..4c15e58 100644 --- a/src/patcherex2/targets/elf_leon3_bare.py +++ b/src/patcherex2/targets/elf_leon3_bare.py @@ -39,7 +39,7 @@ def _init_memory_analysis(self): func["addr"], func["size"], is_free=True, - flag=MemoryFlag.RWX, + flag=MemoryFlag.RX, ) self.p.allocation_manager.add_block(block)