Skip to content

Commit fac8f1e

Browse files
k4lizenpeace-maker
andauthored
Support starting a kitty debugging window with the 'kitten' command (#2522)
* support starting a kitty window with the 'kitten' command * get kitty pid and sigterm instead of close-window --------- Co-authored-by: peace-maker <[email protected]>
1 parent 5f616ad commit fac8f1e

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ The table below shows which release corresponds to each branch, and what date th
7575
## 5.0.0 (`dev`)
7676

7777
- [#2507][2507] Add `+LINUX` and `+WINDOWS` doctest options and start proper testing on Windows
78+
- [#2522][2522] Support starting a kitty debugging window with the 'kitten' command
7879

7980
[2507]: https://github.com/Gallopsled/pwntools/pull/2507
81+
[2522]: https://github.com/Gallopsled/pwntools/pull/2522
8082

8183
## 4.15.0 (`beta`)
8284
- [#2508][2508] Ignore a warning when compiling with asm on nix

pwnlib/util/misc.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import division
22

3+
import json
34
import base64
45
import errno
56
import os
@@ -450,13 +451,11 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
450451
log.debug("Launching a new terminal: %r" % argv)
451452

452453
stdin = stdout = stderr = open(os.devnull, 'r+b')
453-
if terminal == 'tmux' or terminal == 'kitty':
454+
if terminal == 'tmux' or terminal in ('kitty', 'kitten'):
454455
stdout = subprocess.PIPE
455456

456457
p = subprocess.Popen(argv, stdin=stdin, stdout=stdout, stderr=stderr, preexec_fn=preexec_fn)
457458

458-
kittyid = None
459-
460459
if terminal == 'tmux':
461460
out, _ = p.communicate()
462461
try:
@@ -469,16 +468,24 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
469468
with subprocess.Popen((qdbus, konsole_dbus_service, '/Sessions/{}'.format(last_konsole_session),
470469
'org.kde.konsole.Session.processId'), stdout=subprocess.PIPE) as proc:
471470
pid = int(proc.communicate()[0].decode())
472-
elif terminal == 'kitty':
473-
pid = p.pid
474-
471+
elif terminal in ('kitty', 'kitten'):
472+
pid = None
475473
out, _ = p.communicate()
476474
try:
477475
kittyid = int(out)
478476
except ValueError:
479477
kittyid = None
480478
if kittyid is None:
481479
log.error("Could not parse kitty window ID from output (%r)", out)
480+
else:
481+
lsout, _ = subprocess.Popen(["kitten", "@", "ls", "--match", "id:%d" % kittyid], stdin=stdin, stdout=stdout, stderr=stderr).communicate()
482+
try:
483+
lsj = json.loads(lsout)
484+
pid = int(lsj[0]["tabs"][0]["windows"][0]["pid"])
485+
except json.JSONDecodeError as e:
486+
pid = None
487+
log.error("Json decode failed while parsing 'kitten @ ls' output (%r) (error: %r)", lsout, e)
488+
482489
elif terminal == 'cmd.exe':
483490
# p.pid is cmd.exe's pid instead of the WSL process we want to start eventually.
484491
# I don't know how to trace the execution through Windows and back into the WSL2 VM.
@@ -503,8 +510,6 @@ def kill():
503510
try:
504511
if terminal == 'qdbus':
505512
os.kill(pid, signal.SIGHUP)
506-
elif terminal == 'kitty':
507-
subprocess.Popen(["kitten", "@", "close-window", "--match", "id:{}".format(kittyid)], stderr=stderr)
508513
else:
509514
os.kill(pid, signal.SIGTERM)
510515
except OSError:

0 commit comments

Comments
 (0)