Last active
October 24, 2025 12:41
-
-
Save felschr/70d1a1c6b81438f85373f7e0ff80ebb6 to your computer and use it in GitHub Desktop.
Parsing & editing `SiteSecurityServiceState.bin` via nushell script.
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 nu | |
| # See format description for `SiteSecurityServiceState.bin`: | |
| # https://gitlab.torproject.org/tpo/applications/tor-browser/-/blob/tor-browser-128.7.0esr-14.5-1/security/manager/ssl/data_storage/src/lib.rs#L349-353 | |
| # Format is [checksum][score][last accessed][key][value] | |
| let browsers = [ | |
| { name: "Firefox" path: "~/.mozilla/firefox" } | |
| { name: "Tor Browser" path: "~/.tor project/firefox" } | |
| { name: "Mullvad Browser" path: "~/.mullvad/mullvadbrowser" } | |
| ] | |
| let browser = $browsers | input list --display name --fuzzy "Select your browser" | |
| print $"Looking for profiles in ($browser.path)" | |
| let profiles = ls --short-names ...(glob $browser.path) | where type == "dir" | get name | |
| let profile = $profiles | input list --fuzzy "Select the profile you want to change" | |
| let file = $"($browser.path)/($profile)/SiteSecurityServiceState.bin" | |
| let bin_rec_len = 2 + 2 + 2 + 256 + 24 | |
| let pad_char = (0x[00] | decode utf-8) | |
| def bin_to_rec []: binary -> record { | |
| { | |
| checksum: ($in | bytes at 0..1) # 2 | |
| score: ($in | bytes at 2..3) # 2 | |
| last_accessed: ($in | bytes at 4..5) # 2 | |
| key: ($in | bytes at 6..261 | into binary --compact | decode utf-8) # 256 | |
| value: ($in | bytes at 262..285 | into binary --compact | decode utf-8) # 24 | |
| } | |
| } | |
| def rec_to_bin []: record -> binary { | |
| let list = [ | |
| $in.checksum, | |
| $in.score, | |
| $in.last_accessed, | |
| ($in.key | fill -c $pad_char --width 256 | encode utf-8), | |
| ($in.value | fill -c $pad_char --width 24 | encode utf-8), | |
| ] | |
| $list | bytes collect | |
| } | |
| let bin_list = $file | open | chunks $bin_rec_len | |
| let records = $bin_list | each {|x| $x | bin_to_rec} | |
| let bin_list_out = $records | each {|x| $x | rec_to_bin} | |
| let bin_out = $bin_list_out | bytes collect | |
| # parsed records | |
| $records | |
| # compare input & output to make sure format doesn't change | |
| # $bin_list | last | |
| # $bin_list_out | last | |
| # $records | first | get key | |
| # $records | first | get key | decode utf-8 | encode utf-8 | |
| # $records | first | get key | decode utf-8 | into binary --compact | |
| # let pad_char = (0x[0] | decode utf-8) | |
| # let bin_compact = $records | first | get key | into binary --compact | |
| # let str = $bin_compact | decode utf-8 | |
| # $str | fill --character $pad_char --width 256 | encode utf-8 | |
| # $records | first | get value | bytes length |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment