From 84aae4be53028e543fa9b00f1bc53d6c2420cc51 Mon Sep 17 00:00:00 2001 From: dusoleil Date: Fri, 11 Mar 2022 10:27:58 -0500 Subject: sploit: cache ELF loads With recursive ELF loads, there is the possibility of loading in a heavy ELF (like libc) multiple times. Hiding instantiation of the class behind a factory method and caching instances should eliminate this problem. Signed-off-by: dusoleil --- tools/sploit/sploit/rev/elf.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/sploit/sploit/rev/elf.py b/tools/sploit/sploit/rev/elf.py index a748f10..bdced0a 100644 --- a/tools/sploit/sploit/rev/elf.py +++ b/tools/sploit/sploit/rev/elf.py @@ -1,6 +1,16 @@ from sploit.rev import ldd, r2 -class ELF: +__ELF_CACHE__ = {} + +def ELF(path): + if path in __ELF_CACHE__: + return __ELF_CACHE__[path] + else: + elf = __ELF__(path) + __ELF_CACHE__[path] = elf + return elf + +class __ELF__: def __init__(self, path): self.path = path self.sym = r2.get_elf_symbols(self.path) -- cgit v1.2.3