Skip to content

Commit f7a237f

Browse files
committed
Adding basic functionality to a hidden feature
1 parent 948903f commit f7a237f

File tree

3 files changed

+50
-40
lines changed

3 files changed

+50
-40
lines changed

lib/core/gui.py

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,23 @@
55
See the file 'LICENSE' for copying permission
66
"""
77

8+
import os
89
import re
910
import socket
1011
import subprocess
1112
import sys
13+
import tempfile
1214
import threading
1315
import webbrowser
1416

1517
from lib.core.common import getSafeExString
18+
from lib.core.common import saveConfig
19+
from lib.core.data import paths
1620
from lib.core.defaults import defaults
21+
from lib.core.enums import MKSTEMP_PREFIX
1722
from lib.core.exception import SqlmapMissingDependence
1823
from lib.core.settings import DEV_EMAIL_ADDRESS
24+
from lib.core.settings import IS_WIN
1925
from lib.core.settings import ISSUES_PAGE
2026
from lib.core.settings import GIT_PAGE
2127
from lib.core.settings import SITE
@@ -110,48 +116,19 @@ def onReturnPress(event):
110116
line = ""
111117
event.widget.master.master.destroy()
112118
return "break"
119+
except:
120+
return
113121

114122
event.widget.insert(tkinter.END, "\n")
115123

116-
counter = 0
117-
while True:
118-
line = ""
119-
try:
120-
#line = queue.get_nowait()
121-
line = queue.get(timeout=.1)
122-
event.widget.insert(tkinter.END, line)
123-
counter = 0
124-
except _queue.Empty:
125-
event.widget.see(tkinter.END)
126-
event.widget.update_idletasks()
127-
if counter > 3:
128-
break
129-
else:
130-
counter += 1
131-
132124
return "break"
133125

134126
def run():
127+
global alive
135128
global process
136129
global queue
137130

138-
ON_POSIX = "posix" in sys.builtin_module_names
139-
140-
def enqueue(stream, queue):
141-
for line in iter(stream.readline, b''):
142-
queue.put(line)
143-
stream.close()
144-
145-
process = subprocess.Popen("/bin/bash", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE, bufsize=1, close_fds=ON_POSIX)
146-
147-
# Reference: https://stackoverflow.com/a/4896288
148-
queue = _queue.Queue()
149-
thread = threading.Thread(target=enqueue, args=(process.stdout, queue))
150-
thread.daemon = True
151-
thread.start()
152-
153-
154-
options = {}
131+
config = {}
155132

156133
for key in window._widgets:
157134
dest, type = key
@@ -168,12 +145,34 @@ def enqueue(stream, queue):
168145
else:
169146
value = bool(widget.var.get())
170147

171-
options[dest] = value
148+
config[dest] = value
172149

173150
for option in parser.option_list:
174-
options[option.dest] = defaults.get(option.dest, None)
151+
config[option.dest] = defaults.get(option.dest, None)
152+
153+
handle, configFile = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.CONFIG, text=True)
154+
os.close(handle)
175155

176-
parser._args = options
156+
saveConfig(config, configFile)
157+
158+
def enqueue(stream, queue):
159+
global alive
160+
161+
for line in iter(stream.readline, b''):
162+
queue.put(line)
163+
164+
alive = False
165+
stream.close()
166+
167+
alive = True
168+
169+
process = subprocess.Popen([sys.executable or "python", os.path.join(paths.SQLMAP_ROOT_PATH, "sqlmap.py"), "-c", configFile], shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE, bufsize=1, close_fds=not IS_WIN)
170+
171+
# Reference: https://stackoverflow.com/a/4896288
172+
queue = _queue.Queue()
173+
thread = threading.Thread(target=enqueue, args=(process.stdout, queue))
174+
thread.daemon = True
175+
thread.start()
177176

178177
top = tkinter.Toplevel()
179178
top.title("Console")
@@ -187,6 +186,16 @@ def enqueue(stream, queue):
187186

188187
center(top)
189188

189+
while alive:
190+
line = ""
191+
try:
192+
#line = queue.get_nowait()
193+
line = queue.get(timeout=.1)
194+
text.insert(tkinter.END, line)
195+
except _queue.Empty:
196+
text.see(tkinter.END)
197+
text.update_idletasks()
198+
190199
menubar = tkinter.Menu(window)
191200

192201
filemenu = tkinter.Menu(menubar, tearoff=0)
@@ -262,4 +271,4 @@ def enqueue(stream, queue):
262271

263272
first.focus()
264273

265-
window.mainloop()
274+
window.mainloop()

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from thirdparty.six import unichr as _unichr
1919

2020
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
21-
VERSION = "1.3.12.0"
21+
VERSION = "1.3.12.1"
2222
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2323
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2424
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

lib/parse/cmdline.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def get_all_options(parser):
7878
from lib.core.dicts import DEPRECATED_OPTIONS
7979
from lib.core.enums import AUTOCOMPLETE_TYPE
8080
from lib.core.exception import SqlmapShellQuitException
81+
from lib.core.exception import SqlmapSilentQuitException
8182
from lib.core.exception import SqlmapSyntaxException
8283
from lib.core.option import _createHomeDirectories
8384
from lib.core.settings import BASIC_HELP_ITEMS
@@ -863,10 +864,10 @@ def _format_action_invocation(self, action):
863864

864865
if "--gui" in argv:
865866
from lib.core.gui import runGui
867+
866868
runGui(parser)
867869

868-
if hasattr(parser, "_args"):
869-
return parser._args
870+
raise SqlmapSilentQuitException
870871

871872
elif "--sqlmap-shell" in argv:
872873
_createHomeDirectories()

0 commit comments

Comments
 (0)