wadlib

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2022 License: MIT Imports: 9 Imported by: 4

README

wadlib

Package to parse, extract and modify WAD contents.

Documentation

License

wadlib is released under the MIT License, read here for more information.

Documentation

Index

Constants

View Source
const (
	// WADTypeCommon is used for IOS, channels, and roughly all other items.
	WADTypeCommon WADType = 0x49730000
	// WADTypeBoot is used for WADs containing boot-related items.
	WADTypeBoot = 0x69620000
	// WADTypeUnknown is documented under https://wiibrew.org/wiki/WAD_files#Header by bushing.
	// I have not encountered this format in the wild, nor any SDK.
	WADTypeUnknown = 0x426b000
)

WADType contains a list of WAD types to compare against.

View Source
const (
	KeyTypeCommon KeyType = 0x0
	KeyTypeKoren          = 0x1
	KeyTypevWii           = 0x2
)

Variables

View Source
var (
	// CommonKey is the common key for titles in all regions but Korea.
	// Put into hex, "ebe42a225e8593e448d9c5457381aaf7"
	CommonKey = [16]byte{0xeb, 0xe4, 0x2a, 0x22, 0x5e, 0x85, 0x93, 0xe4, 0x48, 0xd9, 0xc5, 0x45, 0x73, 0x81, 0xaa, 0xf7}
	// KoreanKey is the common key for titles in the Korean-covered regions.
	// As hex, "63b82bb4f4614e2e13f2fefbba4c9b7e"
	KoreanKey = [16]byte{0x63, 0xb8, 0x2b, 0xb4, 0xf4, 0x61, 0x4e, 0x2e, 0x13, 0xf2, 0xfe, 0xfb, 0xba, 0x4c, 0x9b, 0x7e}
	// WiiUvWiiKey is untested.
	// Used for system titles as updated from Wii U mode, and never actually known to anything inside of vWii.
	WiiUvWiiKey = [16]byte{0x30, 0xbf, 0xc7, 0x6e, 0x7c, 0x19, 0xaf, 0xbb, 0x23, 0x16, 0x33, 0x30, 0xce, 0xd7, 0xc2, 0x8d}
)
View Source
var (
	// CertChainTemplate is an example certificate chain
	// that may go alongside a TMD.
	//go:embed templates/certs
	CertChainTemplate []byte

	// TMDTemplate is an example TMD that may be loaded
	// in order to create a custom WAD.
	//go:embed templates/tmd
	TMDTemplate []byte

	// TicketTemplate is an example Ticket that may be loaded
	// in order to create a custom WAD.
	//go:embed templates/tik
	TicketTemplate []byte
)
View Source
var (
	ErrInvalidIndex = errors.New("index does not exist within WAD")
)

Functions

This section is empty.

Types

type BinaryTMD

type BinaryTMD struct {
	SignatureType SignatureType
	Signature     [256]byte

	Issuer            [64]byte
	FileVersion       uint8
	CACRLVersion      uint8
	SignerCRLVersion  uint8
	IsvWii            bool
	SystemVersionHigh uint32
	SystemVersionLow  uint32
	TitleID           uint64
	TitleType         uint32
	GroupID           uint16
	Unknown           uint16
	Region            uint16
	Ratings           [16]byte
	Reserved          [12]byte
	IPCMask           [12]byte
	Reserved2         [18]byte
	AccessRightsFlags uint32
	TitleVersion      uint16
	NumberOfContents  uint16
	BootIndex         uint16
	// contains filtered or unexported fields
}

BinaryTMD describes a byte-level format for a TMD.

type ContentRecord

type ContentRecord struct {
	ID    uint32
	Index uint16
	Type  ContentType
	Size  uint64
	Hash  [20]byte
}

ContentRecord describes information about a given content.

type ContentType

type ContentType uint16

ContentType specifies the type of content expected. It can be a shared content held in /shared2, or a normal content for the title itself.

const (
	TitleTypeNormal ContentType = 0x0001
	TitleTypeShared             = 0x8001
)

type ESLicenseType

type ESLicenseType uint8

ESLicenseType describes the current title's license type.

const (
	LicensePermanent ESLicenseType = iota
	LicenseDemo
	LicenseTrial
	LicenseRental
	LicenseSubscription
	LicenseService
)

type KeyType

type KeyType uint8

KeyType represents the key type for the given "index". There are 3 known types.

type SignatureType

type SignatureType uint32

SignatureType allows specification of the type of signature to be parsed in a ticket.

const (
	// SignatureRSA2048 is only one of several internal signature types.
	// See https://git.io/JfJzH or, from acer_cloud_wifi_copy,
	// /sw_x/es_core/esc/core/base/include/esitypes.h#L74
	// However, only RSA 2048 is used in the Wii's title system.
	SignatureRSA2048 SignatureType = 0x00010001
)

type TMD

type TMD struct {
	BinaryTMD
	Contents []ContentRecord
}

TMD describes a human-usable TMD format.

type Ticket

type Ticket struct {
	SignatureType SignatureType
	Signature     [256]byte

	Issuer           [64]byte
	ECDHData         [60]byte
	FileVersion      uint8
	CACRLVersion     uint8
	SignerCRLVersion uint8
	TitleKey         [16]byte
	Padding          byte
	TicketID         uint64
	ConsoleID        uint32
	TitleID          uint64
	SystemAccessMask [2]uint8
	TitleVersion     uint16
	// WiiBrew describes this as the "Permitted Titles Mask".
	// estypes.h does not agree. We'll use the official description.
	AccessTitleID   uint32
	AccessTitleMask uint32
	LicenseType     uint8
	KeyType         KeyType
	Unknown         [114]byte
	TimeLimits      [8]TimeLimitEntry
	// contains filtered or unexported fields
}

Ticket defines the binary structure of a given ticket file.

func (*Ticket) GetTitleKey added in v0.3.0

func (t *Ticket) GetTitleKey() [16]byte

func (*Ticket) UpdateTitleKey added in v0.3.0

func (t *Ticket) UpdateTitleKey(updated [16]byte)

UpdateTitleKey updates the key for the given ticket. Note that this will not re-encrypt existing data for the WAD. Consider using WAD.ChangeTitleKey to re-encrypt instead, where possible.

type TimeLimitEntry

type TimeLimitEntry struct {
	// It's unknown what code represents.
	Code uint32
	// Each limit is in seconds.
	Limit uint32
}

TimeLimitEntry holds a time limit entry for a title.

type WAD

type WAD struct {
	Header                    WADHeader
	CertificateChain          []byte
	CertificateRevocationList []byte
	Ticket                    Ticket
	TMD                       TMD
	Data                      []WADFile
	Meta                      []byte
}

WAD describes the structure enclosing information in a typical WAD's format.

func LoadWAD

func LoadWAD(contents []byte) (*WAD, error)

LoadWAD takes contents and parses the given binary WAD.

func LoadWADFromFile

func LoadWADFromFile(filePath string) (*WAD, error)

LoadWADFromFile takes a path, loads it, and parses the given binary WAD.

func (*WAD) ChangeTitleKey added in v0.3.0

func (w *WAD) ChangeTitleKey(updatedKey [16]byte) error

ChangeTitleKey updates the ticket to contain the given title key, and re-encrypts all data to match.

func (*WAD) GetContent added in v0.3.0

func (w *WAD) GetContent(index int) ([]byte, error)

GetContent returns the data for the given index.

func (*WAD) GetDataSection added in v0.3.0

func (w *WAD) GetDataSection() []byte

GetDataSection returns data as specified within the TMD.

func (*WAD) GetHeader added in v0.2.0

func (w *WAD) GetHeader() ([]byte, error)

GetHeader returns bytes based off the WADHeader for the given WAD.

func (*WAD) GetTMD added in v0.2.0

func (w *WAD) GetTMD() ([]byte, error)

GetTMD returns the bytes for the given TMD within the current WAD.

func (*WAD) GetTicket added in v0.2.0

func (w *WAD) GetTicket() ([]byte, error)

GetTicket returns the bytes of a given Ticket within the current WAD.

func (*WAD) GetWAD added in v0.2.0

func (w *WAD) GetWAD(wadType WADType) ([]byte, error)

GetWAD returns the bytes necessary for a usable WAD.

func (*WAD) LoadDataSection added in v0.3.0

func (w *WAD) LoadDataSection(data []byte) error

LoadDataSection loads the binary data from a WAD and parses it as specified within the TMD.

func (*WAD) LoadHeader added in v0.2.0

func (w *WAD) LoadHeader(source []byte) error

LoadHeader creates a WADHeader based off of the given contents.

func (*WAD) LoadTMD added in v0.2.0

func (w *WAD) LoadTMD(contents []byte) error

LoadTMD loads a given TMD from the passed contents into the WAD.

func (*WAD) LoadTicket added in v0.2.0

func (w *WAD) LoadTicket(source []byte) error

LoadTicket loads the given bytes from source into the Ticket for the current WAD.

func (*WAD) UpdateContent added in v0.3.0

func (w *WAD) UpdateContent(index int, contents []byte) error

UpdateContent updates the data at the given index with the given content.

type WADFile

type WADFile struct {
	Record  *ContentRecord
	RawData []byte
}

WADFile represents a file within a WAD. RawData should always be the encrypted data ready to be stored within a WAD.

func (*WADFile) DecryptData added in v0.2.0

func (d *WADFile) DecryptData(titleKey [16]byte) ([]byte, error)

DecryptData returns the decrypted contents of this WADFile with the given title key.

func (*WADFile) UpdateData added in v0.3.0

func (d *WADFile) UpdateData(contents []byte, titleKey [16]byte)

UpdateData updates the contents of this WADFile with the given data and title key.

type WADHeader

type WADHeader struct {
	HeaderSize      uint32
	WADType         WADType
	CertificateSize uint32
	CRLSize         uint32
	TicketSize      uint32
	TMDSize         uint32
	DataSize        uint32
	MetaSize        uint32
}

WADHeader describes a Nintendo WAD's typical header with sizes.

type WADType

type WADType uint32

Jump to

Keyboard shortcuts

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