-
Notifications
You must be signed in to change notification settings - Fork 2
/
certificate.go
49 lines (42 loc) · 1.2 KB
/
certificate.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
package mlcrestorerdownloader
import (
"fmt"
"os"
"github.com/cavaliergopher/grab/v3"
)
var cetkData []byte
func getCert(tmdData []byte, id int, numContents uint16) ([]byte, error) {
var certSlice []byte
if len(tmdData) == int((0x0B04+0x30*numContents+0xA00)-0x300) {
certSlice = tmdData[0x0B04+0x30*numContents : 0x0B04+0x30*numContents+0xA00-0x300]
} else {
certSlice = tmdData[0x0B04+0x30*numContents : 0x0B04+0x30*numContents+0xA00]
}
switch id {
case 0:
return certSlice[:0x400], nil
case 1:
return certSlice[0x400 : 0x400+0x300], nil
default:
return nil, fmt.Errorf("invalid id: %d", id)
}
}
func getDefaultCert(client *grab.Client) ([]byte, error) {
if len(cetkData) >= 0x350+0x300 {
return cetkData[0x350 : 0x350+0x300], nil
}
if err := downloadFile(client, "http://ccs.cdn.c.shop.nintendowifi.net/ccs/download/000500101000400a/cetk", "cetk"); err != nil {
return nil, err
}
cetkData, err := os.ReadFile("cetk")
if err != nil {
return nil, err
}
if err := os.Remove("cetk"); err != nil {
return nil, err
}
if len(cetkData) >= 0x350+0x300 {
return cetkData[0x350 : 0x350+0x300], nil
}
return nil, fmt.Errorf("failed to download OSv10 cetk, length: %d", len(cetkData))
}