From 7e15ea607d60b4860d221161e128944b1017f1ee Mon Sep 17 00:00:00 2001 From: Maksim Syomochkin Date: Thu, 10 Oct 2024 13:12:01 +0300 Subject: [PATCH] inital release --- .github/workflows/go.yaml | 33 +++++++++++++ README.md | 14 ++++++ go.mod | 3 ++ go.sum | 0 main.go | 101 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 151 insertions(+) create mode 100644 .github/workflows/go.yaml create mode 100644 README.md create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml new file mode 100644 index 0000000..a8d7981 --- /dev/null +++ b/.github/workflows/go.yaml @@ -0,0 +1,33 @@ +name: Go + +on: + create: + tags: + - v* + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.23' + + - name: Build + run: | + go build . + go get github.com/mitchellh/gox + /home/runner/go/bin/gox -osarch="linux/amd64 linux/arm darwin/amd64 windows/amd64" --output "build/{{ .Dir }}_{{.OS}}_{{.Arch}}" + + - name: Release + uses: softprops/action-gh-release@v2 + with: + files: | + build/photok-recovery_darwin_amd64 + build/photok-recovery_windows_amd64.exe + build/photok-recovery_linux_amd64 + build/photok-recovery_linux_arm \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b41464c --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# Photok Backup Recovery +## Description + +This utility allows you to restore data from backups created by the Photok application without needing an Android phone. Easily access and recover your files directly from your computer. + +## Usage + +1. Go to the Releases page. +2. Download the executable file for your platform. +3. Run the utility using the command: +```bash +photok-recovery --password --file +``` +Replace with your actual password and with the path to your backup file. \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..1fcca31 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/maksim77/photok-recovery + +go 1.23.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e69de29 diff --git a/main.go b/main.go new file mode 100644 index 0000000..9859282 --- /dev/null +++ b/main.go @@ -0,0 +1,101 @@ +package main + +import ( + "archive/zip" + "crypto/aes" + "crypto/cipher" + "crypto/sha256" + "flag" + "io" + "log" + "os" + "strings" + "sync" +) + +func main() { + password := flag.String("password", "", "photok password") + backupFile := flag.String("file", "", "path to backup file") + numWorkers := flag.Int("worker", 10, "number of workers") + flag.Parse() + + var wg sync.WaitGroup + + jobs := make(chan *zip.File) + + for i := 0; i < *numWorkers; i++ { + wg.Add(1) + + go worker(*password, jobs, &wg) + } + + r, err := zip.OpenReader(*backupFile) + if err != nil { + log.Fatal(err) + } + defer r.Close() + + for _, f := range r.File { + if !strings.HasSuffix(f.Name, ".tn") && strings.HasSuffix(f.Name, ".photok") { + jobs <- f + } + } + + close(jobs) + + wg.Wait() +} + +func worker(password string, jobs <-chan *zip.File, wg *sync.WaitGroup) { + defer wg.Done() + + key := photokKey(password) + iv := photokIV(password) + + block, err := aes.NewCipher(key) + if err != nil { + log.Fatal(err) + } + + aesgcm, err := cipher.NewGCMWithNonceSize(block, 16) + if err != nil { + log.Fatal(err) + } + + for file := range jobs { + reader, err := file.Open() + if err != nil { + log.Fatal(err) + } + + ciphertext, err := io.ReadAll(reader) + if err != nil { + log.Fatal(err) + } + + plaintext, err := aesgcm.Open(nil, iv, ciphertext, nil) + if err != nil { + log.Fatal(err) + } + + if err := os.WriteFile(file.Name+".plaintext", plaintext, 0o644); err != nil { + log.Fatal(err) + } + } +} + +func photokKey(password string) []byte { + h := sha256.New() + h.Write([]byte(password)) + + return h.Sum(nil) +} + +func photokIV(password string) []byte { + iv := make([]byte, 16) + for i := 0; i < 16 && i < len(password); i++ { + iv[i] = password[i] + } + + return iv +}