summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordusoleil <howcansocksbereal@gmail.com>2022-03-11 10:27:58 -0500
committerdusoleil <howcansocksbereal@gmail.com>2022-03-13 23:27:30 -0400
commit5cec6f91cb03e568fe30f06b429a178279a518bb (patch)
tree645c18a4c8f32a3ef15184c30f110ba3327d0d5e
parent13a1931d7b765009d35c72594310f4a5abcacff4 (diff)
downloadsploit-5cec6f91cb03e568fe30f06b429a178279a518bb.tar.gz
sploit-5cec6f91cb03e568fe30f06b429a178279a518bb.zip
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 <howcansocksbereal@gmail.com>
-rw-r--r--sploit/rev/elf.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/sploit/rev/elf.py b/sploit/rev/elf.py
index a748f10..bdced0a 100644
--- a/sploit/rev/elf.py
+++ b/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)