55See the file 'LICENSE' for copying permission
66"""
77
8+ import os
89import re
910import socket
1011import subprocess
1112import sys
13+ import tempfile
1214import threading
1315import webbrowser
1416
1517from lib .core .common import getSafeExString
18+ from lib .core .common import saveConfig
19+ from lib .core .data import paths
1620from lib .core .defaults import defaults
21+ from lib .core .enums import MKSTEMP_PREFIX
1722from lib .core .exception import SqlmapMissingDependence
1823from lib .core .settings import DEV_EMAIL_ADDRESS
24+ from lib .core .settings import IS_WIN
1925from lib .core .settings import ISSUES_PAGE
2026from lib .core .settings import GIT_PAGE
2127from 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 ()
0 commit comments