forked from gwatts/pinfinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecrypt.go
51 lines (45 loc) · 926 Bytes
/
decrypt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// +build !nodecrypt
package main
import (
"bytes"
plist "github.com/DHowett/go-plist"
iosbackup "github.com/gwatts/ios/backup"
)
var (
decryptEnabled = true
)
func decrypt(backupDir string, b *backup) {
pw := getpw()
if pw == "" {
b.Status = msgIsEncrypted
return
}
encbw, err := iosbackup.Open(backupDir)
if err != nil {
b.Status = "Failed to open backup: " + err.Error()
return
}
if err := encbw.SetPassword(pw); err != nil {
b.Status = msgIncorrectPassword
return
}
if err := encbw.Load(); err != nil {
b.Status = err.Error()
return
}
rec := encbw.RecordById(restrictionsPlistName)
if rec == nil {
b.Status = msgNoPassword
return
}
data, err := encbw.ReadFile(*rec)
if err != nil {
b.Status = msgIncorrectPassword
return
}
buf := bytes.NewReader(data)
if err := plist.NewDecoder(buf).Decode(&b.Restrictions); err != nil {
b.Status = msgIncorrectPassword
return
}
}