I am currently writing a .net library for use with Wii Files and IO. I will be posting snippets and updates here.

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Security.Cryptography;
using System.Text;
 
 
namespace Wii_Code_Examples
{
    public class WadInformation
    {
		public static string GetSystemCode(string titleId)
            {
                string code = String.Empty;
                switch (titleId[0].ToString())
                {
	                case "C":
                        code = "Commodore 64 Virtual Console.";
                        break;
 
                    case "D":
                        code = "Virtual Console Arcade.";
                        break;
 
                    case "E":
                        code = "NeoGeo Virtual Console.";
                        break;
 
                    case "F":
                        code = "Nintendo Virtual Console.";
                        break;
 
                    case "H":
                        code = "General Channel.";
                        break;
 
                    case "J":
                        code = "Super Nintendo Virtual Console.";
                        break;
 
                    case "L":
                        code = "Sega Master System Virtual Console.";
                        break;
 
                    case "M":
                        code = "Sega Megadrive Virtual Console.";
                        break;
 
                    case "N":
                        code = "Nintendo 64 Virtual Console.";
                        break;
 
                    case "P":
                        code = "TurboGraFX Virtual Console";
                        break;
 
                    case "Q":
                        code = "TurboGraFX CD Virtual Console.";
                        break;
 
                    case "R":
                        code = "Wii Disc.";
                        break;
 
                    case "W":
                        code = "WiiWare.";
                        break;
 
                    case "X":
                        code = "MSX Virtual Console.";
                        break;
                }
 
                return code;
            }
    }
 
    class WadFileClass
    {
        public const long CONST_TITLEID = 0xc20L; //Length: 4
        public const long CONST_TMDSIZE = 0x014; //Length: 4
        public const long CONST_APPSIZE = 0x018; //Length: 4
        public const long CONST_WADTYPE = 0x004; //Length: 4
 
        private static byte[] _PublicKey;
        private static byte[] PublicKey
        {
            get 
            {
                if (_PublicKey == null)
                {
                    _PublicKey = File.ReadAllBytes(@"C:\common-key.bin");
                }
                return _PublicKey; 
            }
        }
 
        /// <summary>
        /// This is the wad file data.
        /// </summary>
        public static byte[] FileData;
 
        /// <summary>
        /// Reads the file data. This needs to be done first for Data to populate in this class.
        /// </summary>
        /// <param name="fileLocation">The file location.</param>
        public static void ReadFileData(string fileLocation)
        {
            FileData = File.ReadAllBytes(fileLocation);
        }
 
        /// <summary>
        /// This is the raw unencrypted file data inside the wad.
        /// </summary>
        private byte[] _UnencryptedBlock;
        public byte[] UnencryptedBlock
        {
            get 
            {
                if (_UnencryptedBlock == null)
                {
                    // pull block here
                }
                return _UnencryptedBlock; 
            }
        }
 
        public static string CommonKey
        {
            get 
            {
                StringBuilder sbString = new StringBuilder();
                foreach (byte b in PublicKey)
                {
                    sbString.Append(Convert.ToChar(b));
                }
                return Convert.ToString(sbString);
            }
        }
 
        public static string GetWadInfo(string fileLocation, long address, int length)
        {
            byte[] bytes = new byte[length];
            using (FileStream input = new FileStream(fileLocation, FileMode.Open))
            {
                FileStream fs = input;
                fs.Seek(address, SeekOrigin.Begin);
                fs.Read(bytes, 0, length);
            }
 
            StringBuilder sbString = new StringBuilder();
            foreach (byte b in bytes)
            {
                sbString.Append(Convert.ToChar(b));
            }
            return Convert.ToString(sbString);
        }
 
        public static void ReadCryptedArea()
        {
            if (FileData != null)
            {
 
            }
        }
 
    }
}
Share and Enjoy:
  • Digg
  • Facebook
  • Google
  • Slashdot
  • TwitThis
  • E-mail this story to a friend!
  • LinkedIn
  • Live