diff options
author | Malfurious <m@lfurio.us> | 2025-01-01 06:51:10 -0500 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2025-01-01 06:51:10 -0500 |
commit | f01ec45e773291c3659a1dcaf8cd9a51ece19823 (patch) | |
tree | 0db3ef432a6f3b06c07060bdb0dd61c7fd164ad2 /sploit/util/log.py | |
parent | 3f5532857807d628a5dadaf5c30a384f873878ea (diff) | |
parent | 221742f7c5c89dc50ec4374bed5d2ccc0d7534bf (diff) | |
download | nsploit-f01ec45e773291c3659a1dcaf8cd9a51ece19823.tar.gz nsploit-f01ec45e773291c3659a1dcaf8cd9a51ece19823.zip |
Merge branch 'pkg-reorg'
This branch is a rework of nsploit's intended package imports. User
scripts need only import a given nsploit subpackage to obtain that
package's full collection of classes, functions, etc. This is the new
intended style for exploit scripts.
Along the way, some modules are reorganized into different packages, the
"builder" package is renamed to "payload", and some unnecessary files
are consolidated.
* pkg-reorg:
main: Automatically provide top-level sploit modules to user scripts
sploit: Expose modules' contents through package
Remove extra "main.py" file
comm: Promote from module to package
log: Move to sploit.util package
util: Promote from module to package
builder: Rename package to payload and expose contents
rev: Expose modules' contents through package
Remove outer __init__.py file
Diffstat (limited to 'sploit/util/log.py')
-rw-r--r-- | sploit/util/log.py | 32 |
1 files changed, 32 insertions, 0 deletions
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) |