From 29b9da475a5115ec0d453989ce545316cbc0a013 Mon Sep 17 00:00:00 2001 From: Malfurious Date: Fri, 12 Jan 2024 14:28:26 -0500 Subject: util: Promote from module to package We would like to move additional modules under the namespace of "util" to clean up the top-level "sploit" package. To start, the functions from the previous util module are moved. Given the package is named "util" the module is renamed to "cmd" to somewhat match the theme of the contained functions. Per the previous commits, these functions are now exposed via the util package as well. Signed-off-by: Malfurious --- sploit/rev/ldd.py | 2 +- sploit/rev/r2.py | 2 +- sploit/util.py | 27 --------------------------- sploit/util/__init__.py | 1 + sploit/util/cmd.py | 27 +++++++++++++++++++++++++++ 5 files changed, 30 insertions(+), 29 deletions(-) delete mode 100644 sploit/util.py create mode 100644 sploit/util/__init__.py create mode 100644 sploit/util/cmd.py diff --git a/sploit/rev/ldd.py b/sploit/rev/ldd.py index 1a28c7c..b5bc564 100644 --- a/sploit/rev/ldd.py +++ b/sploit/rev/ldd.py @@ -1,4 +1,4 @@ -from sploit.util import run_cmd_cached +from sploit.util.cmd import run_cmd_cached from sploit.log import ilog import re diff --git a/sploit/rev/r2.py b/sploit/rev/r2.py index 1be731c..d9dbabd 100644 --- a/sploit/rev/r2.py +++ b/sploit/rev/r2.py @@ -2,7 +2,7 @@ from sploit.arch import arch from sploit.log import ilog from sploit.rev.gadget import Gadget from sploit.symtbl import Symtbl -from sploit.util import run_cmd_cached +from sploit.util.cmd import run_cmd_cached from collections import namedtuple as nt from functools import cache diff --git a/sploit/util.py b/sploit/util.py deleted file mode 100644 index ac1d428..0000000 --- a/sploit/util.py +++ /dev/null @@ -1,27 +0,0 @@ -from os import path -from subprocess import run - -def run_cmd(cmd,cwd=None): - return run(cmd,cwd=cwd,capture_output=True,text=True,check=True).stdout.split('\n')[:-1] - -__RUN_CACHE__ = {} -def run_cmd_cached(cmd,cwd=None): - key = ''.join(cmd) - if key in __RUN_CACHE__: - return __RUN_CACHE__[key] - else: - result = run_cmd(cmd,cwd) - __RUN_CACHE__[key] = result - return result - -#try to get the version through git -def git_version(): - try: - cwd = path.dirname(path.realpath(__file__)) - version = run_cmd(["git","describe","--always","--first-parent","--dirty"],cwd=cwd)[0] - version += "-malfdev" - #PEP440 compliance - version = version.replace('-','+',1).replace('-','.') - return version - except: - return "0+unknown.version" diff --git a/sploit/util/__init__.py b/sploit/util/__init__.py new file mode 100644 index 0000000..9103509 --- /dev/null +++ b/sploit/util/__init__.py @@ -0,0 +1 @@ +from .cmd import * diff --git a/sploit/util/cmd.py b/sploit/util/cmd.py new file mode 100644 index 0000000..ac1d428 --- /dev/null +++ b/sploit/util/cmd.py @@ -0,0 +1,27 @@ +from os import path +from subprocess import run + +def run_cmd(cmd,cwd=None): + return run(cmd,cwd=cwd,capture_output=True,text=True,check=True).stdout.split('\n')[:-1] + +__RUN_CACHE__ = {} +def run_cmd_cached(cmd,cwd=None): + key = ''.join(cmd) + if key in __RUN_CACHE__: + return __RUN_CACHE__[key] + else: + result = run_cmd(cmd,cwd) + __RUN_CACHE__[key] = result + return result + +#try to get the version through git +def git_version(): + try: + cwd = path.dirname(path.realpath(__file__)) + version = run_cmd(["git","describe","--always","--first-parent","--dirty"],cwd=cwd)[0] + version += "-malfdev" + #PEP440 compliance + version = version.replace('-','+',1).replace('-','.') + return version + except: + return "0+unknown.version" -- cgit v1.2.3