From c70fc87879f072edd178df502bb1c8c985c9d7f7 Mon Sep 17 00:00:00 2001 From: Malfurious Date: Fri, 12 Jan 2024 16:26:03 -0500 Subject: log: Move to sploit.util package Signed-off-by: Malfurious --- sploit/__init__.py | 1 - sploit/comm.py | 2 +- sploit/log.py | 32 -------------------------------- sploit/main.py | 2 +- sploit/rev/ldd.py | 2 +- sploit/rev/r2.py | 2 +- sploit/util/__init__.py | 1 + sploit/util/log.py | 32 ++++++++++++++++++++++++++++++++ 8 files changed, 37 insertions(+), 37 deletions(-) delete mode 100644 sploit/log.py create mode 100644 sploit/util/log.py diff --git a/sploit/__init__.py b/sploit/__init__.py index f761ead..f443fe9 100644 --- a/sploit/__init__.py +++ b/sploit/__init__.py @@ -1,7 +1,6 @@ from sploit import ( arch, comm, - log, payload, rev, symtbl, diff --git a/sploit/comm.py b/sploit/comm.py index 522d540..3bc448e 100644 --- a/sploit/comm.py +++ b/sploit/comm.py @@ -4,8 +4,8 @@ import os import sys import select -from sploit.log import * from sploit.until import bind +from sploit.util.log import * class Comm: logonread = True diff --git a/sploit/log.py b/sploit/log.py deleted file mode 100644 index 823b252..0000000 --- a/sploit/log.py +++ /dev/null @@ -1,32 +0,0 @@ -import codecs -import sys - -# https://docs.python.org/3/library/codecs.html#standard-encodings -ENCODING = None - -ERROR = 31 -WARNING = 33 -STATUS = 32 -NORMAL = 0 -ALT = 90 - -def enc_value(value, enc): - if type(value) is bytes: - if enc is not None: - value = codecs.encode(value, enc) - elif ENCODING is not None: - value = codecs.encode(value, ENCODING) - value = str(value)[2:-1] # strip b'' - return str(value) - -def generic_log(*values, sep, end, file, flush, enc, color): - string = sep.join([ enc_value(x, enc) for x in values ]) - print(f'\033[{color}m{string}\033[0m', end=end, file=file, flush=flush) - -# For library internal use -def ilog(*values, sep=' ', end='\n', file=sys.stderr, flush=True, enc=None, color=STATUS): - generic_log(*values, sep=sep, end=end, file=file, flush=flush, enc=enc, color=color) - -# For external use in user script (via print = elog) -def elog(*values, sep=' ', end='\n', file=sys.stdout, flush=True, enc=None, color=ALT): - generic_log(*values, sep=sep, end=end, file=file, flush=flush, enc=enc, color=color) diff --git a/sploit/main.py b/sploit/main.py index 6d71196..0d022f2 100644 --- a/sploit/main.py +++ b/sploit/main.py @@ -5,7 +5,7 @@ import tempfile import traceback from sploit.comm import * -from sploit.log import * +from sploit.util.log import * from sploit import __version__ def print_banner(color, line1=__version__, line2='', line3=''): diff --git a/sploit/rev/ldd.py b/sploit/rev/ldd.py index b5bc564..b773abf 100644 --- a/sploit/rev/ldd.py +++ b/sploit/rev/ldd.py @@ -1,5 +1,5 @@ from sploit.util.cmd import run_cmd_cached -from sploit.log import ilog +from sploit.util.log import ilog import re from collections import namedtuple as nt diff --git a/sploit/rev/r2.py b/sploit/rev/r2.py index d9dbabd..e81adc9 100644 --- a/sploit/rev/r2.py +++ b/sploit/rev/r2.py @@ -1,8 +1,8 @@ from sploit.arch import arch -from sploit.log import ilog from sploit.rev.gadget import Gadget from sploit.symtbl import Symtbl from sploit.util.cmd import run_cmd_cached +from sploit.util.log import ilog from collections import namedtuple as nt from functools import cache diff --git a/sploit/util/__init__.py b/sploit/util/__init__.py index 9103509..32a079b 100644 --- a/sploit/util/__init__.py +++ b/sploit/util/__init__.py @@ -1 +1,2 @@ from .cmd import * +from .log import * diff --git a/sploit/util/log.py b/sploit/util/log.py new file mode 100644 index 0000000..823b252 --- /dev/null +++ b/sploit/util/log.py @@ -0,0 +1,32 @@ +import codecs +import sys + +# https://docs.python.org/3/library/codecs.html#standard-encodings +ENCODING = None + +ERROR = 31 +WARNING = 33 +STATUS = 32 +NORMAL = 0 +ALT = 90 + +def enc_value(value, enc): + if type(value) is bytes: + if enc is not None: + value = codecs.encode(value, enc) + elif ENCODING is not None: + value = codecs.encode(value, ENCODING) + value = str(value)[2:-1] # strip b'' + return str(value) + +def generic_log(*values, sep, end, file, flush, enc, color): + string = sep.join([ enc_value(x, enc) for x in values ]) + print(f'\033[{color}m{string}\033[0m', end=end, file=file, flush=flush) + +# For library internal use +def ilog(*values, sep=' ', end='\n', file=sys.stderr, flush=True, enc=None, color=STATUS): + generic_log(*values, sep=sep, end=end, file=file, flush=flush, enc=enc, color=color) + +# For external use in user script (via print = elog) +def elog(*values, sep=' ', end='\n', file=sys.stdout, flush=True, enc=None, color=ALT): + generic_log(*values, sep=sep, end=end, file=file, flush=flush, enc=enc, color=color) -- cgit v1.2.3