66"""
77
88import re
9+ import socket
10+ import subprocess
11+ import sys
12+ import threading
913import webbrowser
1014
1115from lib .core .common import getSafeExString
1822from lib .core .settings import VERSION_STRING
1923from lib .core .settings import WIKI_PAGE
2024from thirdparty .six .moves import tkinter_messagebox as _tkinter_messagebox
25+ from thirdparty .six .moves import queue as _queue
26+
27+ line = ""
28+ process = None
29+ queue = None
2130
2231def runGui (parser ):
2332 try :
2433 import tkinter
34+ import tkinter .scrolledtext
2535 import tkinter .ttk
2636 except ImportError as ex :
2737 raise SqlmapMissingDependence ("missing dependence ('%s')" % getSafeExString (ex ))
@@ -64,7 +74,83 @@ def _on_tab_changed(self,event):
6474 style .theme_create ("custom" , parent = "alt" , settings = settings )
6575 style .theme_use ("custom" )
6676
77+ # Reference: https://stackoverflow.com/a/10018670
78+ def center (window ):
79+ window .update_idletasks ()
80+ width = window .winfo_width ()
81+ frm_width = window .winfo_rootx () - window .winfo_x ()
82+ win_width = width + 2 * frm_width
83+ height = window .winfo_height ()
84+ titlebar_height = window .winfo_rooty () - window .winfo_y ()
85+ win_height = height + titlebar_height + frm_width
86+ x = window .winfo_screenwidth () // 2 - win_width // 2
87+ y = window .winfo_screenheight () // 2 - win_height // 2
88+ window .geometry ('{}x{}+{}+{}' .format (width , height , x , y ))
89+ window .deiconify ()
90+
91+ def onKeyPress (event ):
92+ global line
93+ global queue
94+
95+ if process :
96+ if event .char == '\b ' :
97+ line = line [:- 1 ]
98+ else :
99+ line += event .char
100+
101+ def onReturnPress (event ):
102+ global line
103+ global queue
104+
105+ if process :
106+ try :
107+ process .stdin .write (("%s\n " % line .strip ()).encode ())
108+ process .stdin .flush ()
109+ except socket .error :
110+ line = ""
111+ event .widget .master .master .destroy ()
112+ return "break"
113+
114+ event .widget .insert (tkinter .END , "\n " )
115+
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+ return "break"
133+
67134 def run ():
135+ global process
136+ global queue
137+
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+
68154 options = {}
69155
70156 for key in window ._widgets :
@@ -80,15 +166,26 @@ def run():
80166 elif type == "int" :
81167 value = int (widget .get ())
82168 else :
83- value = bool (widget .getint ())
169+ value = bool (widget .var . get ())
84170
85171 options [dest ] = value
86172
87173 for option in parser .option_list :
88174 options [option .dest ] = defaults .get (option .dest , None )
89175
90176 parser ._args = options
91- window .destroy ()
177+
178+ top = tkinter .Toplevel ()
179+ top .title ("Console" )
180+
181+ # Reference: https://stackoverflow.com/a/13833338
182+ text = tkinter .scrolledtext .ScrolledText (top , undo = True )
183+ text .bind ("<Key>" , onKeyPress )
184+ text .bind ("<Return>" , onReturnPress )
185+ text .pack ()
186+ text .focus ()
187+
188+ center (top )
92189
93190 menubar = tkinter .Menu (window )
94191
0 commit comments