Skip to content

Instantly share code, notes, and snippets.

@deliciouslytyped
Last active August 25, 2022 23:17
Show Gist options
  • Save deliciouslytyped/c185374649ceb25721c04f8b00c2583c to your computer and use it in GitHub Desktop.
Save deliciouslytyped/c185374649ceb25721c04f8b00c2583c to your computer and use it in GitHub Desktop.
Workaround gnome-shell disabling Eval by injecting js with gdb; no need to restart or poke the GUI!
#! /usr/bin/env nix-shell
#! nix-shell -p gdb psmisc fzf -i bash
# Workaround gnome-shell disabling Eval by injecting js with gdb; no need to restart or poke the GUI!
# https://askubuntu.com/questions/1201849/invoking-gnome-show-applications-from-command-line
# https://askubuntu.com/questions/1412130/dbus-calls-to-gnome-shell-dont-work-under-ubuntu-22-04
#TODO clean this up
#TODO extend this to load plugins at runtime? (well, unneeded once you have Eval access I guess, because you can then use it like lg.)
#alternatively, use this shebang:
#! /usr/bin/env bash
invoke_gdb() {
#string like: `-Xwayland,7747 :0 -rootless -noreset -accessx -core -auth/run/user/1000/.
# to pid 7747
gnome_pid=$(pgrep gnome-shell | xargs -L1 pstree -s -p -T -a | fzf --tac | sed 's/^[[:space:]]*//g' | cut -d " " -f 1 | cut -d "," -f "2")
echo "Selected pid is $gnome_pid. Process is:"
ps aux -q "$gnome_pid"
echo
echo 'Will attempt to run the following js code with gdb in batch mode:'
echo "$script"
echo
echo 'WARNING: this will attach the gdb debugger to your selected gnome-shell session.'
echo 'The session will hang until gdb is finished working.'
echo 'Press enter to continue or ^C to quit this script.'
echo 'TODO/WARNING: I have no idea how bad code may break this or hang your UI!'
read
#This is the only thing doing any real work here
# *some* explanation http://helgo.net/simon/introspection-tutorial/stepthree.xhtml , mostly sufficient for this though.
# The code is run on the main thread. You can check by breakpointing on Interpret.
# TODO ingest discussion notes
gdb -p "$gnome_pid" -batch -ex "call (void*)gjs_context_eval((void*)gjs_context_get_current(), \"$1\", -1, \"<injected>\", 0, 0)"
echo 'Check for success (in the default configuration a result of (true, 'true') means we were successful):'
gdbus call -e -d org.gnome.Shell -o /org/gnome/Shell -m org.gnome.Shell.Eval 'global.context.unsafe_mode'
}
main() {
case $1 in
t) {
script='global.context.unsafe_mode = true'
invoke_gdb "$script"
};;
f) {
echo 'Setting global.context.unsafe_mode to false. Note, this is kind of pointless:'
echo 'If it'\''s already false this is a no-op, if it'\''s true, it'\''s safer to use gdbus.'
script='global.context.unsafe_mode = false'
invoke_gdb "$script"
};;
toggle) {
script='global.context.unsafe_mode = ! global.context.unsafe_mode'
invoke_gdb "$script"
};;
*) {
echo 'Usage: enable_eval.sh (t|f|toggle)'
};;
esac
}
main "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment