Skip to content

Commit

Permalink
Use a more reliable way to split the KDE konsole (Gallopsled#2026)
Browse files Browse the repository at this point in the history
* Use a more reliable way to split the KDE konsole

* Changed xml parsing to pure parsing

* Update CHANGELOG.md
  • Loading branch information
TomasGl authored and vboxuser committed Sep 10, 2023
1 parent 2adaf9f commit 535c9a0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ The table below shows which release corresponds to each branch, and what date th
## 4.9.0 (`dev`)

- [#2011][2011] Fix tube's debug output of same byte compression
- [#2023][2023] Support KDE Konsole in run_in_new_terminal function
- [#2027][2027] Fix ELF.libc_start_main_return with glibc 2.34

[2011]: https://github.com/Gallopsled/pwntools/pull/2011
[2023]: https://github.com/Gallopsled/pwntools/pull/2023
[2027]: https://github.com/Gallopsled/pwntools/pull/2027

## 4.8.0 (`beta`)
Expand Down
26 changes: 22 additions & 4 deletions pwnlib/util/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,31 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
terminal = 'x-terminal-emulator'
args = ['-e']
elif 'KONSOLE_VERSION' in os.environ and which('qdbus'):
konsole_window = os.environ['KONSOLE_DBUS_WINDOW'].split('/')[-1]
konsole_dbus_service = os.environ['KONSOLE_DBUS_SERVICE']
qdbus = which('qdbus')
# SPLIT
subprocess.run((qdbus, konsole_dbus_service, '/konsole/MainWindow_{}'.format(konsole_window),
window_id = os.environ['WINDOWID']
konsole_dbus_service = os.environ['KONSOLE_DBUS_SERVICE']

with subprocess.Popen((qdbus, konsole_dbus_service), stdout=subprocess.PIPE) as proc:
lines = proc.communicate()[0].decode().split('\n')

# Iterate over all MainWindows
for line in lines:
parts = line.split('/')
if len(parts) == 3 and parts[2].startswith('MainWindow_'):
name = parts[2]
with subprocess.Popen((qdbus, konsole_dbus_service, '/konsole/' + name,
'org.kde.KMainWindow.winId'), stdout=subprocess.PIPE) as proc:
target_window_id = proc.communicate()[0].decode().strip()
if target_window_id == window_id:
break
else:
log.error('MainWindow not found')

# Split
subprocess.run((qdbus, konsole_dbus_service, '/konsole/' + name,
'org.kde.KMainWindow.activateAction', 'split-view-left-right'), stdout=subprocess.DEVNULL)

# Find new session
with subprocess.Popen((qdbus, konsole_dbus_service, os.environ['KONSOLE_DBUS_WINDOW'],
'org.kde.konsole.Window.sessionList'), stdout=subprocess.PIPE) as proc:
session_list = map(int, proc.communicate()[0].decode().split())
Expand Down

0 comments on commit 535c9a0

Please sign in to comment.