summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordusoleil <howcansocksbereal@gmail.com>2021-09-07 02:34:54 -0400
committerdusoleil <howcansocksbereal@gmail.com>2021-09-07 02:34:54 -0400
commit159eb86f979716b2e0c6d819b1ca598441c9ddf9 (patch)
tree7ea8f6a3c409327ec589f2878031ec79a0c7b76c
parent2c8177d5daff32b8b864dac08d093c3388c33241 (diff)
downloadlib-des-gnux-159eb86f979716b2e0c6d819b1ca598441c9ddf9.tar.gz
lib-des-gnux-159eb86f979716b2e0c6d819b1ca598441c9ddf9.zip
Clean up exception handling in main.py
The handling from the daemon mode code will also work in the process and pipes cases. Putting it in a common location removes the need for the outer try/except. It is also easier to read/maintain in general. Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
-rw-r--r--tools/sploit/sploit/main.py43
1 files changed, 21 insertions, 22 deletions
diff --git a/tools/sploit/sploit/main.py b/tools/sploit/sploit/main.py
index 6404786..f97e04e 100644
--- a/tools/sploit/sploit/main.py
+++ b/tools/sploit/sploit/main.py
@@ -14,18 +14,15 @@ def main():
help='target program to exploit')
args = parser.parse_args()
- try:
- if(len(args.target)>0):
- if(args.daemon):
- print("Target Given. Ignoring Daemon Flag...")
- target(args.script, args.target)
+ if(len(args.target)>0):
+ if(args.daemon):
+ print("Target Given. Ignoring Daemon Flag...")
+ target(args.script, args.target)
+ else:
+ if(args.daemon):
+ daemon(args.script)
else:
- if(args.daemon):
- daemon(args.script)
- else:
- pipe(args.script)
- except KeyboardInterrupt:
- pass
+ pipe(args.script)
def daemon(script):
print("Running in Pipe Daemon Mode...")
@@ -35,12 +32,7 @@ def daemon(script):
p = Pipes(tmpdir)
except KeyboardInterrupt:
break
- try:
- runscript(script, Comm(p));
- except KeyboardInterrupt:
- pass
- except:
- traceback.print_exc()
+ runscript(script, Comm(p));
del p
def pipe(script):
@@ -52,8 +44,15 @@ def target(script, target):
runscript(script, Comm(Process(target)));
def runscript(script, comm):
- print("Running Script...")
- code = compile(open(script).read(), script, 'exec')
- exec(code, {'io': comm})
- print("Script Finished!")
- comm.readall()
+ try:
+ print("Running Script...")
+ code = compile(open(script).read(), script, 'exec')
+ exec(code, {'io': comm})
+ print("Script Finished!")
+ comm.readall()
+ return
+ except KeyboardInterrupt:
+ pass
+ except:
+ traceback.print_exc()
+ print("Script Ended Early!")