pax_global_header00006660000000000000000000000064140670650530014520gustar00rootroot0000000000000052 comment=1eb17be0b1d533fdcdef68be8687efde147b53f0 mozillainstallhash-1.0.0/000077500000000000000000000000001406706505300154205ustar00rootroot00000000000000mozillainstallhash-1.0.0/.gitignore000066400000000000000000000004151406706505300174100ustar00rootroot00000000000000# Binaries for programs and plugins *.exe *.exe~ *.dll *.so *.dylib # Test binary, built with `go test -c` *.test # Output of the go coverage tool, specifically when used with LiteIDE *.out # Dependency directories (remove the comment below to include it) # vendor/ mozillainstallhash-1.0.0/LICENSE000066400000000000000000000020551406706505300164270ustar00rootroot00000000000000MIT License Copyright (c) 2021 bradenhilton Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. mozillainstallhash-1.0.0/README.md000066400000000000000000000032051406706505300166770ustar00rootroot00000000000000# mozillainstallhash Gets the hash used to differentiate between installs of Mozilla software in `installs.ini` and `profiles.ini`. ### Example 1. Create a new local Go module: 1. Create a new directory e.g. `$GOPATH/src/get_mozilla_install_hash` 2. Change into the newly created directory 3. Run `go mod init get_mozilla_install_hash` 2. Create a new file `get_mozilla_install_hash.go`: ```go package main import ( "fmt" "log" "os" "strings" "github.com/bradenhilton/mozillainstallhash" ) const usage = ` get_mozilla_install_hash Get the hash used to differentiate between installs of Mozilla software. Usage: get_mozilla_install_hash [ ...] Where is a string describing the parent directory of the executable, e.g. "C:\Program Files\Mozilla Firefox", with platform specific path separators ("\" on Windows and "/" on Unix-like systems) Example: get_mozilla_install_hash "C:\Program Files\Mozilla Firefox" 308046B0AF4A39CB get_mozilla_install_hash "C:/Program Files/Mozilla Firefox" 9D561FCD08DC6D55 get_mozilla_install_hash "/usr/lib/firefox" 4F96D1932A9F858E` func main() { if len(os.Args) == 1 { log.Println(fmt.Errorf("error: no path specified")) fmt.Println(usage) os.Exit(1) } paths := os.Args[1:] for _, path := range paths { path = strings.TrimSuffix(path, "/") path = strings.TrimSuffix(path, "\\") hash, err := mozillainstallhash.MozillaInstallHash(path) if err != nil { log.Println(err) continue } fmt.Println(hash) } } ``` 1. Run `go get github.com/bradenhilton/mozillainstallhash` 2. Run `go run get_mozilla_install_hash.go ` ### License MITmozillainstallhash-1.0.0/go.mod000066400000000000000000000002131406706505300165220ustar00rootroot00000000000000module github.com/bradenhilton/mozillainstallhash go 1.15 require ( github.com/bradenhilton/cityhash v1.0.0 golang.org/x/text v0.3.6 ) mozillainstallhash-1.0.0/go.sum000066400000000000000000000006751406706505300165630ustar00rootroot00000000000000github.com/bradenhilton/cityhash v1.0.0 h1:1QauDCwfxwIGwO2jBTJdEBqXgfCusAgQOSgdl4RsTMI= github.com/bradenhilton/cityhash v1.0.0/go.mod h1:Wmb8yW1egA9ulrsRX4mxfYx5zq4nBWOCZ+j63oK6uz8= golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= mozillainstallhash-1.0.0/mozillainstallhash.go000066400000000000000000000022051406706505300216500ustar00rootroot00000000000000package mozillainstallhash import ( "fmt" "golang.org/x/text/encoding/unicode" "golang.org/x/text/transform" "github.com/bradenhilton/cityhash" ) // MozillaInstallHash returns the Mozilla install hash for the path given in // installPath. // // installPath should be the path to the parent directory of the executable. // // A UTF-16 encoding of installPath is transformed to a byte array and passed // to CityHash64 (version 1). // // Other than the UTF-16 encoding and byte array conversion, installPath is // hashed as is, so must contain the correct path separators for the // intended operating system, with any trailing path separator removed. // // It returns a string of the hash in uppercase hexadecimal format. func MozillaInstallHash(installPath string) (string, error) { endianness := unicode.LittleEndian bomPolicy := unicode.IgnoreBOM encoder := unicode.UTF16(endianness, bomPolicy).NewEncoder() pathBytes, _, err := transform.Bytes(encoder, []byte(installPath)) if err != nil { return "", err } pathSize := uint32(len(pathBytes)) hash := cityhash.CityHash64(pathBytes, pathSize) return fmt.Sprintf("%016X", hash), nil } mozillainstallhash-1.0.0/mozillainstallhash_test.go000066400000000000000000000026161406706505300227150ustar00rootroot00000000000000package mozillainstallhash import "testing" func TestMozillaInstallHash(t *testing.T) { type args struct { installPath string } tests := []struct { name string args args want string }{ { name: "Default Windows Firefox Release Path", args: args{ installPath: "C:\\Program Files\\Mozilla Firefox", }, want: "308046B0AF4A39CB", }, { name: "Default Windows Firefox Nightly Path", args: args{ installPath: "C:\\Program Files\\Firefox Nightly", }, want: "6F193CCC56814779", }, { name: "Default macOS Firefox Release Path", args: args{ installPath: "/Applications/Firefox.app/Contents/MacOS", }, want: "2656FF1E876E9973", }, { name: "Default macOS Firefox Nightly Path", args: args{ installPath: "/Applications/Firefox Nightly.app/Contents/MacOS", }, want: "31210A081F86E80E", }, { name: "Default Arch Linux Firefox Release Path", args: args{ installPath: "/usr/lib/firefox", }, want: "4F96D1932A9F858E", }, { name: "Default Arch Linux Firefox Nightly Path", args: args{ installPath: "/opt/firefox-nightly", }, want: "6BA5C87ECB35E12F", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got, err := MozillaInstallHash(tt.args.installPath); err != nil || got != tt.want { t.Errorf("MozillaInstallHash() = %v, %v, want %v, ", got, err, tt.want) } }) } }