Created
April 10, 2023 13:11
-
-
Save lfdominguez/6d280ae566215cfdbc50e9cd7afb2f5b to your computer and use it in GitHub Desktop.
Fix Github Copilot agent NixOS
This file contains hidden or 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/env nix-shell | |
#! nix-shell -i bash -p patchelf | |
## Pass the github copilot agent as first parameter. | |
## Example: /home/luis/.local/share/JetBrains/CLion2023.1/github-copilot-intellij/copilot-agent/bin/copilot-agent-linux | |
binaryLocation="$1" | |
cp "${binaryLocation}" "${binaryLocation}.bak" | |
orig_size=$(stat --printf=%s "${binaryLocation}") | |
echo "Orig Size: ${orig_size}" | |
interpreter=$(nix-shell -I /etc/nix/inputs/ -p gcc --command 'cat $NIX_CC/nix-support/dynamic-linker') | |
libPath=$(echo "lib.makeLibraryPath [ stdenv.cc.cc ]" | nix repl '<nixpkgs>' 2> /dev/null | tr -d '\n' | cut -d'"' -f 2) | |
echo "Using interpreter: ${interpreter}" | |
echo "Using libpath: ${libPath}" | |
patchelf --set-interpreter "${interpreter}" "${binaryLocation}" | |
patchelf --set-rpath "${libPath}" "${binaryLocation}" | |
chmod +x "${binaryLocation}" | |
new_size=$(stat --printf=%s "${binaryLocation}") | |
echo "New Size: ${new_size}" | |
var_skip=20 | |
var_select=22 | |
shift_by=$(expr $new_size - $orig_size) | |
echo "Diff Size: ${shift_by}" | |
function fix_offset { | |
location=$(grep -obUam1 "$1" "${binaryLocation}" | cut -d: -f1) | |
location=$(expr $location + $var_skip) | |
value=$(dd if="${binaryLocation}" iflag=count_bytes,skip_bytes skip=$location bs=1 count=$var_select status=none) | |
value=$(expr $shift_by + $value) | |
echo -n $value | dd of="${binaryLocation}" bs=1 seek=$location conv=notrunc | |
} | |
fix_offset PAYLOAD_POSITION | |
fix_offset PRELUDE_POSITION |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment