wud

package module
v0.0.0-...-04c68dd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2023 License: BSD-3-Clause Imports: 19 Imported by: 0

README

Go Report Card GoDoc Go version Go version

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)
	}
}

Documentation

Overview

Package wud implements reading of Nintendo Wii-U disc images. These can either be a regular 23 GB file, split into 2 GB parts, or compressed.

Example usage:

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.Reader, io.Closer, error) {
        f, err := os.Open(name)
        if err != nil {
                return nil, nil ,err
        }

        if r, err := wux.NewReader(f); err != nil {
                if err != wux.ErrBadMagic {
                        return nil, nil, multierror.Append(err, f.Close())
                }
                if err = f.Close(); err != nil {
                        return nil, nil, err
                }
        } else {
                return r, f, nil
        }

        rc, err := wud.OpenReader(name)
        if err != nil {
                return nil, nil, err
        }

        return rc, rc, nil
}

func main() {
        r, c, err := openFile(os.Args[1])
        if err != nil {
                panic(err)
        }
        defer c.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(r, commonKey, gameKey)
        if err != nil {
                panic(err)
        }

        if err = w.Extract(os.Args[4]); err != nil {
                panic(err)
        }
}

Index

Constants

View Source
const (
	// Extension is the conventional file extension used
	Extension = ".wud"
	// SectorSize is the sector size for Wii-U disc images
	SectorSize uint32 = 0x8000
	// UncompressedSize is the uncompressed size for Wii-U disc images
	UncompressedSize uint64 = 25025314816
	// CommonKeyFile represents the standard "common.key" filename
	CommonKeyFile = "common.key"
	// GameKeyFile represents the standard "game.key" filename
	GameKeyFile = "game.key"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ReadCloser

type ReadCloser interface {
	Reader
	io.Closer
}

A ReadCloser extends the Reader interface to also have a Close method.

func OpenReader

func OpenReader(name string) (ReadCloser, error)

OpenReader opens the disc image indicated by name and returns a new ReadCloser. If name matches "game_part1.wud" then the image is assumed to be split into 2 GB parts and each sequential part will also be opened.

type Reader

type Reader interface {
	io.Reader
	io.Seeker
	readerutil.SizeReaderAt
}

A Reader has Read, Seek, ReadAt, and Size methods.

type WUD

type WUD struct {
	// contains filtered or unexported fields
}

WUD represents a Wii-U disc image

func NewWUD

func NewWUD(r readerutil.SizeReaderAt, commonKey, gameKey []byte) (*WUD, error)

NewWUD returns a WUD read from the provided r, using the commonKey and gameKey to decrypt where necessary.

func (*WUD) Extract

func (w *WUD) Extract(directory string) error

Extract writes all of the files from the underlying disc image to the passed directory, which is created if necessary.

Directories

Path Synopsis
cmd
wud
Package wux implements compression of Nintendo Wii-U disc images.
Package wux implements compression of Nintendo Wii-U disc images.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL