modulepackage
0.0.0-20230206130336-04c68dd6bbef
Repository: https://github.com/bodgit/wud.git
Documentation: pkg.go.dev
# README
Nintendo Wii-U disc images
The github.com/bodgit/wud package provides read access to Wii-U disc images, such as those created by the github.com/FIX94/wudump homebrew.
How to read a disc image:
package main
import (
"io"
"os"
"github.com/bodgit/wud"
"github.com/bodgit/wud/wux"
"github.com/hashicorp/go-multierror"
)
// openFile will first try and open name as a compressed image, then as
// a regular or split image.
func openFile(name string) (wud.ReadCloser, error) {
f, err := os.Open(name)
if err != nil {
return nil, err
}
if rc, err := wux.NewReadCloser(f); err != nil {
if err != wux.ErrBadMagic {
return nil, multierror.Append(err, f.Close())
}
if err = f.Close(); err != nil {
return nil, err
}
} else {
return rc, nil
}
return wud.OpenReader(name)
}
func main() {
rc, err := openFile(os.Args[1])
if err != nil {
panic(err)
}
defer rc.Close()
commonKey, err := os.ReadFile(os.Args[2])
if err != nil {
panic(err)
}
gameKey, err := os.ReadFile(os.Args[3])
if err != nil {
panic(err)
}
w, err := wud.NewWUD(rc, commonKey, gameKey)
if err != nil {
panic(err)
}
if err = w.Extract(os.Args[4]); err != nil {
panic(err)
}
}
To compress a disc image:
package main
import (
"io"
"os"
"github.com/bodgit/wud"
"github.com/bodgit/wud/wux"
)
func main() {
rc, err := wud.OpenReader(os.Args[1])
if err != nil {
panic(err)
}
defer rc.Close()
f, err := os.Create(os.Args[2])
if err != nil {
panic(err)
}
defer f.Close()
w, err := wux.NewWriter(f, wud.SectorSize, wud.UncompressedSize)
if err != nil {
panic(err)
}
if _, err = io.Copy(w, r); err != nil {
panic(err)
}
}
And the reverse decompression operation:
package main
import (
"io"
"os"
"github.com/bodgit/wud/wux"
)
func main() {
f, err := os.Open(os.Args[1])
if err != nil {
panic(err)
}
defer f.Close()
r, err := wux.NewReader(f)
if err != nil {
panic(err)
}
w, err := os.Create(os.Args[2])
if err != nil {
panic(err)
}
defer w.Close()
if _, err = io.Copy(w, r); err != nil {
panic(err)
}
}
# Functions
NewWUD returns a WUD read from the provided r, using the commonKey and gameKey to decrypt where necessary.
OpenReader opens the disc image indicated by name and returns a new ReadCloser.
# Constants
CommonKeyFile represents the standard "common.key" filename.
Extension is the conventional file extension used.
GameKeyFile represents the standard "game.key" filename.
SectorSize is the sector size for Wii-U disc images.
UncompressedSize is the uncompressed size for Wii-U disc images.
# Interfaces
A ReadCloser extends the Reader interface to also have a Close method.
A Reader has Read, Seek, ReadAt, and Size methods.