Skip to content

Commit e6813e5

Browse files
committed
engine: add support for Kalidroid (--kalidroid) miniterminal's
1 parent 33fac9f commit e6813e5

4 files changed

Lines changed: 72 additions & 0 deletions

File tree

wifite/args.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ def __init__(self, configuration):
1414
# Hack: Check for -v before parsing args;
1515
# so we know which commands to display.
1616
self.verbose = '-v' in sys.argv or '-hv' in sys.argv or '-vh' in sys.argv
17+
# Activate Kalidroid MiniTerminal output mode as early as possible (before
18+
# any option-echo prints) so the whole run streams scrollback-friendly
19+
# output to the Kalidroid app's MiniTerminal.
20+
if '--kalidroid' in sys.argv:
21+
Color.kalidroid = True
1722
self.config = configuration
1823
self.args = self.get_arguments()
1924

@@ -270,6 +275,15 @@ def _add_global_args(self, glob):
270275
help=self._verbose(
271276
'Write debug log to {C}[path]{W} (implies {C}-vv{W} minimum verbosity)'))
272277

278+
glob.add_argument('--kalidroid',
279+
action='store_true',
280+
default=False,
281+
dest='kalidroid',
282+
help=self._verbose(
283+
'Emit {C}MiniTerminal{W}-friendly output for the {C}Kalidroid{W} app: '
284+
'flatten carriage-return progress redraws into discrete lines and '
285+
'skip clear-line escapes (default: {G}off{W})'))
286+
273287
glob.add_argument('-i',
274288
action='store',
275289
dest='interface',

wifite/config/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Configuration:
2121

2222
initialized = False # Flag indicating config has been initialized
2323
verbose = 0
24+
kalidroid = False # --kalidroid: MiniTerminal-friendly output for the Kalidroid app
2425
version = _get_version()
2526

2627
all_bands = None

wifite/config/parsers/settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
def parse_settings_args(cls, args):
1212
"""Parses basic settings/configurations from arguments."""
1313

14+
if getattr(args, 'kalidroid', False):
15+
cls.kalidroid = True
16+
Color.kalidroid = True # already set early in Arguments.__init__; keep in sync
17+
Color.pl('{+} {C}option:{W} {G}Kalidroid MiniTerminal{W} output mode enabled')
18+
1419
if args.random_mac or args.random_mac_vendor:
1520
if args.random_mac and args.random_mac_vendor:
1621
Color.pl('{!} {O}Warning: Cannot use both --random-mac and --random-mac-vendor')

wifite/util/color.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,29 @@ class Color:
2929

3030
last_sameline_length = 0
3131

32+
# ── Kalidroid MiniTerminal mode ───────────────────────────────────────────
33+
# The Kalidroid Android app streams wifite's stdout into a MiniTerminal: an
34+
# append-only scrollback view, NOT a terminal emulator. Carriage-return
35+
# redraws (the live attack progress lines) and clear-line escapes therefore
36+
# render as overwritten/garbled text. When --kalidroid is set these are
37+
# flattened into discrete, newline-terminated lines (throttled so a
38+
# per-second timer doesn't flood the view) and the clear-line ops become
39+
# no-ops. ANSI colours are kept — the MiniTerminal parses SGR codes.
40+
kalidroid = False
41+
_kalidroid_last_emit = 0.0
42+
_kalidroid_last_line = ''
43+
_KALIDROID_MIN_INTERVAL = 0.4 # seconds between same-line progress emits
44+
3245
@staticmethod
3346
def p(text):
3447
"""
3548
Prints text using colored format on same line.
3649
Example:
3750
Color.p('{R}This text is red. {W} This text is white')
3851
"""
52+
if Color.kalidroid:
53+
Color._p_kalidroid(text)
54+
return
3955
sys.stdout.write(Color.s(text))
4056
sys.stdout.flush()
4157
if '\r' in text:
@@ -44,6 +60,34 @@ def p(text):
4460
else:
4561
Color.last_sameline_length += len(text)
4662

63+
@staticmethod
64+
def _p_kalidroid(text):
65+
"""
66+
Same as [p] but for the Kalidroid MiniTerminal: a carriage-return
67+
same-line update (e.g. the per-second attack progress line) is emitted
68+
as its own newline-terminated line so the append-only scrollback stays
69+
readable. Identical consecutive redraws and bursts faster than
70+
[_KALIDROID_MIN_INTERVAL] are dropped so timers don't flood the view.
71+
Plain text (no '\\r') — including the newline-terminated Color.pl prints
72+
— passes through unchanged, so final/result lines are never throttled.
73+
"""
74+
if '\r' not in text:
75+
sys.stdout.write(Color.s(text))
76+
sys.stdout.flush()
77+
return
78+
content = text[text.rfind('\r') + 1:].rstrip('\n')
79+
if content.strip() == '':
80+
return # bare '\r' / whitespace-only clear carries no information
81+
import time
82+
now = time.time()
83+
if (content == Color._kalidroid_last_line
84+
or now - Color._kalidroid_last_emit < Color._KALIDROID_MIN_INTERVAL):
85+
return
86+
Color._kalidroid_last_emit = now
87+
Color._kalidroid_last_line = content
88+
sys.stdout.write(Color.s(content) + '\n')
89+
sys.stdout.flush()
90+
4791
@staticmethod
4892
def pl(text):
4993
"""Prints text using colored format with trailing new line."""
@@ -71,13 +115,21 @@ def s(text):
71115

72116
@staticmethod
73117
def clear_line():
118+
# MiniTerminal has no cursor to rewind — the '\r<spaces>\r' erase would
119+
# just append blanks. The flattened progress lines stand on their own.
120+
if Color.kalidroid:
121+
Color.last_sameline_length = 0
122+
return
74123
spaces = ' ' * Color.last_sameline_length
75124
sys.stdout.write('\r%s\r' % spaces)
76125
sys.stdout.flush()
77126
Color.last_sameline_length = 0
78127

79128
@staticmethod
80129
def clear_entire_line():
130+
if Color.kalidroid:
131+
Color.last_sameline_length = 0
132+
return
81133
import shutil
82134
columns = shutil.get_terminal_size(fallback=(80, 24)).columns
83135
Color.p('\r' + (' ' * columns) + '\r')

0 commit comments

Comments
 (0)