mirror of
https://github.com/Xpl0itU/WiiUDownloader.git
synced 2025-05-09 13:52:02 -04:00
Rewrite cert generation and fix bad cert
This commit is contained in:
parent
ba6ff5d548
commit
f4eee481fe
4 changed files with 24 additions and 42 deletions
|
@ -1,7 +1,7 @@
|
|||
package wiiudownloader
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -33,21 +33,28 @@ func getDefaultCert(progressReporter ProgressReporter, client *http.Client) ([]b
|
|||
return nil, fmt.Errorf("failed to download OSv10 cetk, length: %d", len(cetkData))
|
||||
}
|
||||
|
||||
func GenerateCert(tmd *TMD, progressReporter ProgressReporter, client *http.Client) (bytes.Buffer, error) {
|
||||
cert := bytes.Buffer{}
|
||||
func GenerateCert(tmd *TMD, outputPath string, progressReporter ProgressReporter, client *http.Client) error {
|
||||
cert, err := os.Create(outputPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cert.Close()
|
||||
|
||||
if _, err := cert.Write(tmd.Certificate1); err != nil {
|
||||
return bytes.Buffer{}, err
|
||||
if err := binary.Write(cert, binary.BigEndian, tmd.Certificate1); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := cert.Write(tmd.Certificate2); err != nil {
|
||||
return bytes.Buffer{}, err
|
||||
if err := binary.Write(cert, binary.BigEndian, tmd.Certificate2); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defaultCert, err := getDefaultCert(progressReporter, client)
|
||||
if err != nil {
|
||||
return bytes.Buffer{}, err
|
||||
return err
|
||||
}
|
||||
cert.Write(defaultCert)
|
||||
return cert, nil
|
||||
|
||||
if err := binary.Write(cert, binary.BigEndian, defaultCert); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
@ -251,20 +250,9 @@ func (mw *MainWindow) ShowAll() {
|
|||
|
||||
wiiudownloader.GenerateTicket(filepath.Join(parentDir, "title.tik"), tmd.TitleID, titleKey, tmd.TitleVersion)
|
||||
|
||||
cert, err := wiiudownloader.GenerateCert(tmd, mw.progressWindow, http.DefaultClient)
|
||||
if err != nil {
|
||||
if err := wiiudownloader.GenerateCert(tmd, filepath.Join(parentDir, "title.cert"), mw.progressWindow, http.DefaultClient); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
certPath := filepath.Join(parentDir, "title.cert")
|
||||
certFile, err := os.Create(certPath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err := binary.Write(certFile, binary.BigEndian, cert.Bytes()); err != nil {
|
||||
return
|
||||
}
|
||||
defer certFile.Close()
|
||||
})
|
||||
toolsSubMenu.Append(generateFakeTicketCert)
|
||||
|
||||
|
|
|
@ -2,10 +2,8 @@ package wiiudownloader
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
@ -211,25 +209,13 @@ func DownloadTitle(titleID, outputDirectory string, doDecryption bool, progressR
|
|||
|
||||
progressReporter.SetDownloadSize(int64(titleSize))
|
||||
|
||||
cert, err := GenerateCert(tmd, progressReporter, client)
|
||||
if err != nil {
|
||||
if err := GenerateCert(tmd, filepath.Join(outputDir, "title.cert"), progressReporter, client); err != nil {
|
||||
if progressReporter.Cancelled() {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
certPath := filepath.Join(outputDir, "title.cert")
|
||||
certFile, err := os.Create(certPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := binary.Write(certFile, binary.BigEndian, cert.Bytes()); err != nil {
|
||||
return err
|
||||
}
|
||||
certFile.Close()
|
||||
log.Printf("Certificate saved to %v \n", certPath)
|
||||
|
||||
g, ctx := errgroup.WithContext(context.Background())
|
||||
g.SetLimit(maxConcurrentDownloads)
|
||||
sem := semaphore.NewWeighted(maxConcurrentDownloads)
|
||||
|
|
9
tmd.go
9
tmd.go
|
@ -72,7 +72,7 @@ func ParseTMD(data []byte) (*TMD, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
tmd.Contents[i].Hash = make([]byte, 0x14)
|
||||
tmd.Contents[i].Hash = make([]byte, 0x20)
|
||||
if err := binary.Read(reader, binary.BigEndian, &tmd.Contents[i].Hash); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -126,17 +126,18 @@ func ParseTMD(data []byte) (*TMD, error) {
|
|||
}
|
||||
|
||||
reader.Seek(0xB14+(0x30*int64(c)), io.SeekStart)
|
||||
tmd.Contents[c].Hash = make([]byte, 0x14)
|
||||
tmd.Contents[c].Hash = make([]byte, 0x20)
|
||||
if err := binary.Read(reader, binary.BigEndian, &tmd.Contents[c].Hash); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
tmd.Certificate1 = make([]byte, 0x400)
|
||||
if _, err := io.ReadFull(reader, tmd.Certificate1); err != nil {
|
||||
if err := binary.Read(reader, binary.BigEndian, &tmd.Certificate1); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tmd.Certificate2 = make([]byte, 0x300)
|
||||
if _, err := io.ReadFull(reader, tmd.Certificate2); err != nil {
|
||||
if err := binary.Read(reader, binary.BigEndian, &tmd.Certificate2); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue