Script to patch Vivaldi to have 2.2 gamma exponent, for testing. Doesn't quite work for contrast for me, I couldn't find an easy to patch offset, but the first exponent offset that occurs in the file with the value 1.2 is the skia one that needs to be patched. This might work for other chromium browsers and apps too:
Needs python3, xxd, dd, awk and bgrep
#!/bin/bash
float_to_hex() {
local float_val="$1"
python3 -c "import struct; print(' '.join(f'{b:02x}' for b in struct.pack('<f', $float_val)))"
}
detect_browsers() {
local browsers=()
[ -f "/opt/vivaldi/vivaldi-bin" ] && browsers+=("/opt/vivaldi/vivaldi-bin")
[ -f "/opt/google/chrome/chrome" ] && browsers+=("/opt/google/chrome/chrome")
[ -f "/usr/bin/chromium" ] && browsers+=("/usr/bin/chromium")
echo "${browsers[@]}"
}
# request sudo
if [ "$(id -u)" -ne 0 ]; then
echo "This script requires root privileges. Please run with sudo."
exit 1
fi
BROWSERS=($(detect_browsers))
if [ ${#BROWSERS[@]} -eq 0 ]; then
echo "No supported browsers detected. Please specify browser path manually."
read -p "Enter browser binary path: " BROWSER
if [ ! -f "$BROWSER" ]; then
echo "Invalid browser path."
exit 1
fi
elif [ ${#BROWSERS[@]} -eq 1 ]; then
BROWSER="${BROWSERS[0]}"
echo "Auto-detected browser: $BROWSER"
read -p "Continue with this browser? [Y/n]: " choice
if [[ "$choice" =~ ^[Nn]$ ]]; then
read -p "Enter browser binary path: " BROWSER
fi
else
echo "Multiple browsers detected:"
for i in "${!BROWSERS[@]}"; do
echo "[$i] ${BROWSERS[$i]}"
done
read -p "Select browser (0-$((${#BROWSERS[@]}-1))) or enter custom path: " choice
if [[ "$choice" =~ ^[0-9]+$ ]] && [ "$choice" -lt "${#BROWSERS[@]}" ]; then
BROWSER="${BROWSERS[$choice]}"
else
BROWSER="$choice"
if [ ! -f "$BROWSER" ]; then
echo "Invalid browser path."
exit 1
fi
fi
fi
echo "Using browser: $BROWSER"
# check for backup and restore if exists
if [ -f "$BROWSER.gamma.bak" ]; then
echo "Backup found. Restoring original browser binary."
cp "$BROWSER.gamma.bak" "$BROWSER"
read -p "Backup restored. Press Enter to continue with patching or Ctrl+C to exit: "
fi
EXPONENT_ORIG=$(float_to_hex 1.2)
EXPONENT_NEW=$(float_to_hex 2.2)
CONTRAST_ORIG=$(float_to_hex 0.2)
CONTRAST_NEW=$(float_to_hex 1.0)
# Find first exponent offset
exp_offset=$(bgrep "$EXPONENT_ORIG" "$BROWSER" 2>/dev/null | awk -F: '{print $2}' | head -1 | xargs)
if [ -z "$exp_offset" ]; then
echo "No exponent value found"
exit 1
fi
echo "First exponent at: 0x$exp_offset"
exp_dec=$((0x$exp_offset))
# looking for contrast within 12 bytes
found_contrast=""
for offset in $(bgrep "$CONTRAST_ORIG" "$BROWSER" 2>/dev/null | awk -F: '{print $2}' | xargs); do
con_dec=$((0x$offset))
diff=$((exp_dec - con_dec))
[ $diff -lt 0 ] && diff=$((con_dec - exp_dec))
if [ $diff -le 12 ]; then
found_contrast=$offset
echo "Found contrast at: 0x$offset (distance: $diff bytes)"
break
fi
done
if [ -z "$found_contrast" ]; then
echo "No contrast value found near exponent. Contrast will remain at 0.2f. Continue anyway?"
read -p "Press Enter to continue or Ctrl+C to exit: "
else
echo "Contrast found at: 0x$found_contrast"
fi
cp "$BROWSER" "$BROWSER.gamma.bak"
# patch both
echo -ne "$(xxd -r -p <<< ${EXPONENT_NEW// /})" | dd of="$BROWSER" bs=1 seek=$((0x$exp_offset)) conv=notrunc status=none
if [ -z "$found_contrast" ]; then
echo "No contrast value found, exponent patched only."
exit 0
fi
echo -ne "$(xxd -r -p <<< ${CONTRAST_NEW// /})" | dd of="$BROWSER" bs=1 seek=$((0x$found_contrast)) conv=notrunc status=none
echo "Patched both values"