Last active
June 30, 2023 06:47
-
-
Save greatwolf/d21f81ab47d00f36e1a4400961059810 to your computer and use it in GitHub Desktop.
Lua script to force KDE Konsole to use a blinking vertical I cursor shape by default.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/lua | |
--[[ | |
Intended for SteamOS v3.4.8 build 20230508.1. | |
Usage: | |
sudo steamos-readonly disable | |
sudo chmod +x patch_konsolecursor.lua | |
sudo patch_konsolecursor.lua /usr/lib/libkonsoleprivate.so.22.08.2 | |
sudo steamos-readonly enable | |
Patch libkonsoleprivate.so.22.08.2 so the cursor is | |
blinking and non-block shape by default. It does this by | |
modifying the hex instruction bytes in the .text section | |
of the shared library binary so no recompiling is necessary. | |
Relevant byte sequences for locating offsets: | |
BlinkingCursorEnabled byte seq: | |
31 f6 xor esi,esi | |
48 8d bc 24 30 0c 00 lea rdi,[rsp+0xc30] | |
CursorShape byte seq: | |
31 f6 xor esi,esi | |
48 8d bc 24 20 0d 00 lea rdi,[rsp+0xd20] | |
]] | |
-- Raw byte sequences for libkonsoleprivate.so version 22.08.2 | |
local BlinkingCursorEnabled = "()\x31\xf6\x48\x8d\xbc\x24\x30\x0c\x00" | |
local CursorShape = "()\x31\xf6\x48\x8d\xbc\x24\x20\x0d\x00" | |
local function FindOffset(haystack, needle) | |
local found = {} | |
for off in haystack:gmatch(needle) do | |
table.insert(found, off) | |
end | |
assert(#found == 1, | |
"Could not find exactly one matching offset in shared library!") | |
return found[1] - 1 | |
end | |
local filename = assert(..., | |
"Target Shared Library not provided. eg. libkonsoleprivate.so") | |
local file = assert(io.open(filename, 'r+')) | |
local file_content = file:read 'a' | |
local blink_offset = FindOffset(file_content, BlinkingCursorEnabled) | |
file:seek('set', blink_offset) | |
file:write "\x21" -- xor esi,esi -> and esi,esi Precondition esi is 1 | |
print "Patched BlinkingCursorEnabled" | |
local cursorshape_offset = FindOffset(file_content, CursorShape) | |
file:seek('set', cursorshape_offset) | |
file:write "\xff\xc6" -- xor esi,esi -> inc esi Precondition esi is 0 | |
print "Patched CursorShape" | |
file:close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment