Skip to content

Instantly share code, notes, and snippets.

@sonic2kk
Created June 3, 2024 19:39
Show Gist options
  • Save sonic2kk/934fc97d27d9d8c4ac9c1d817e163bf1 to your computer and use it in GitHub Desktop.
Save sonic2kk/934fc97d27d9d8c4ac9c1d817e163bf1 to your computer and use it in GitHub Desktop.
Fetch all Steam Shortcut App IDs from `shortcuts.vdf` and convert them to the Long Shortcut AppIDs using Bash.
#!/usr/bin/env bash
# Magic that represents 'appid' column
magic_appid="617070696400"
# Paste in your Steam UserID
steam_userid=""
shortcuts_vdf="$HOME/.steam/root/userdata/${steam_userid}/config/shortcuts.vdf"
# Parse short AppID (unsigned 32bit integer) and convert it to an unsigned 64bit integer
#
# This format of AppID is used for Steam shortcut files, such as `.desktop` files on Linux,
# and can be used to launch Non-Steam Games with `steam steam://rungameid/<your_long_appid_here>`
function convert_aid {
hex_aid="$1"
little_endian="$( echo "$hex_aid" | tac -rs .. | tr -d '\n' )"
short_appid="$((16#${little_endian}))"
# Use printf to get unsigned 64bit integer, without printf this will be stored as signed
printf "%u\n" "$(( ( ${short_appid} << 32 ) | 0x02000000 ))"
}
# Get first 8 characters after magic and convert it from hex to 32bit unsigned integer
mapfile -t non_steam_appids < <(xxd -ps "$shortcuts_vdf" | grep -oP "${magic_appid}\K.{8}")
for nsi in "${non_steam_appids[@]}"; do
convert_aid "$nsi"
done
@bkbilly
Copy link

bkbilly commented Sep 24, 2024

Thank you for sharing this bash script, it really helped me port it to python. If you are interested this is the code:

import vdf
import struct
import binascii

# Get integer value of appid
shortcuts_file = open("/home/user/.local/share/Steam/userdata/userid/config/shortcuts.vdf", "rb")
shortcuts_dict = vdf.binary_loads(shortcuts_file.read())

for shortcut in shortcuts_dict["shortcuts"].values():
    # Convert to HEX
    int32 = struct.Struct('<i')
    bin_appid = int32.pack(shortcut["appid"])
    hex_appid = binascii.hexlify(bin_appid).decode()

    # Convert to long_appid
    reversed_hex = bytes.fromhex(hex_appid)[::-1].hex()
    long_appid = int(reversed_hex, 16) << 32 | 0x02000000
    print(long_appid)

@matheusfaustino
Copy link

@bkbilly you saved me, thank you very much. I tried different approaches, but they were not working anymore (like crc32 with zlib and the combination of exe and appname). Your way is perfect

@aerodevxp
Copy link

thank you guys! been looking for this for quite some time now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment