This repository has been archived by the owner on Jan 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsd.go
55 lines (44 loc) · 1.57 KB
/
sd.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
52
53
54
55
package main
import (
"github.com/wii-tools/wadlib"
)
// sdTitle returns a usable SD-oriented title ID for the given application ID.
func sdTitle(appId int) uint64 {
// 00010008-53xxxxxx (Sxxx)
return titleForType("sd", appId)
}
// generateSD generates a SD title for the given application ID.
// This is an unpacked WAD. Refer to the Wii Shop Channel documentation
// for what this fully entails.
// It additionally inserts an updated ticket to the SOAP table for the title ID.
func generateSD(appId int, zipUuid string, version int) {
titleId := sdTitle(appId)
fauxWad := createFauxWad(titleId, version)
clearTitle(titleId)
// Read our zip file content.
zipContent := readZip(zipUuid)
// Insert our data.
fauxWad.Data = make([]wadlib.WADFile, 1)
fauxWad.Data[0] = wadlib.WADFile{
Record: &fauxWad.TMD.Contents[0],
}
// Encrypt our content.
// This additionally updates our TMD.
err := fauxWad.UpdateContent(0, zipContent)
check(err)
// Write our encrypted content to disk.
// We only have one - 00000000.
// As it is encrypted, we do not append .app as an extension.
writeForTitle(titleId, "00000000", fauxWad.Data[0].RawData)
// Next, write our TMD to disk.
tmd, err := fauxWad.GetTMD()
check(err)
// The TMD on disk expects to have a certificate chain following it.
writtenTmd := append(tmd, wadlib.CertChainTemplate...)
writeForTitle(titleId, "tmd", writtenTmd)
// After that, obtain our ticket in a byte form.
ticket, err := fauxWad.GetTicket()
check(err)
// Lastly, update the ticket for this title in our database.
updateTicket(titleId, ticket, version)
}