From 2bec0d8d2968e9246b5c304fd8514c2df4709b40 Mon Sep 17 00:00:00 2001 From: William Tan <1284324+Ninja3047@users.noreply.github.com> Date: Wed, 2 Oct 2024 14:07:56 -0400 Subject: [PATCH] Fix mips plt sections being clobbered (#485) * do not clobber plt sections that are previously found * fix mips test for plt on checkbytes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- cle/backends/elf/metaelf.py | 2 +- tests/test_plt.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cle/backends/elf/metaelf.py b/cle/backends/elf/metaelf.py index b1b5bd40..982d873d 100644 --- a/cle/backends/elf/metaelf.py +++ b/cle/backends/elf/metaelf.py @@ -149,7 +149,7 @@ def _load_plt(self): if ".plt.got" in self.sections_map: plt_secs = [self.sections_map[".plt.got"]] if ".MIPS.stubs" in self.sections_map: - plt_secs = [self.sections_map[".MIPS.stubs"]] + plt_secs.append(self.sections_map[".MIPS.stubs"]) if ".plt.sec" in self.sections_map: plt_secs.append(self.sections_map[".plt.sec"]) diff --git a/tests/test_plt.py b/tests/test_plt.py index 3afc6802..564d0cc8 100644 --- a/tests/test_plt.py +++ b/tests/test_plt.py @@ -26,7 +26,14 @@ def _check_plt_entries(self, filename): self.assertEqual(diffs, [4] * len(diffs)) return - # all our mips samples have no PLT, just resolver stubs + if filename == os.path.join("mips", "checkbyte"): + self.assertEqual( + ld.main_object.plt, + {"read": 0x4008C0, "puts": 0x4008D0, "__libc_start_main": 0x4008E0}, + ) + return + + # remaining mips samples have no PLT, just resolver stubs if filename.startswith("mips"): self.assertEqual(ld.main_object.plt, {}) return