5
5
See the file 'LICENSE' for copying permission
6
6
"""
7
7
8
+ import os
8
9
import re
9
10
import socket
10
11
import subprocess
11
12
import sys
13
+ import tempfile
12
14
import threading
13
15
import webbrowser
14
16
15
17
from lib .core .common import getSafeExString
18
+ from lib .core .common import saveConfig
19
+ from lib .core .data import paths
16
20
from lib .core .defaults import defaults
21
+ from lib .core .enums import MKSTEMP_PREFIX
17
22
from lib .core .exception import SqlmapMissingDependence
18
23
from lib .core .settings import DEV_EMAIL_ADDRESS
24
+ from lib .core .settings import IS_WIN
19
25
from lib .core .settings import ISSUES_PAGE
20
26
from lib .core .settings import GIT_PAGE
21
27
from lib .core .settings import SITE
@@ -110,48 +116,19 @@ def onReturnPress(event):
110
116
line = ""
111
117
event .widget .master .master .destroy ()
112
118
return "break"
119
+ except :
120
+ return
113
121
114
122
event .widget .insert (tkinter .END , "\n " )
115
123
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
-
132
124
return "break"
133
125
134
126
def run ():
127
+ global alive
135
128
global process
136
129
global queue
137
130
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 = {}
155
132
156
133
for key in window ._widgets :
157
134
dest , type = key
@@ -168,12 +145,34 @@ def enqueue(stream, queue):
168
145
else :
169
146
value = bool (widget .var .get ())
170
147
171
- options [dest ] = value
148
+ config [dest ] = value
172
149
173
150
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 )
175
155
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 ()
177
176
178
177
top = tkinter .Toplevel ()
179
178
top .title ("Console" )
@@ -187,6 +186,16 @@ def enqueue(stream, queue):
187
186
188
187
center (top )
189
188
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
+
190
199
menubar = tkinter .Menu (window )
191
200
192
201
filemenu = tkinter .Menu (menubar , tearoff = 0 )
@@ -262,4 +271,4 @@ def enqueue(stream, queue):
262
271
263
272
first .focus ()
264
273
265
- window .mainloop ()
274
+ window .mainloop ()
0 commit comments