Current News Archived News Search News Discussion Forum Old Forum Install Programs More Downloads... Troubleshooting Source Code Format Specs. Misc. Information Non-SF Stuff Links Small banner for links to this site: |
1 These structs are to demonstrate the layout of a CWAD file. Note that they are not actual working structs.
3 In C++:
5 struct CWAD {
6 char IDTag[4] = "CWAD";
7 CWADFILE Files[];
8 };
10 struct CWADFILE {
11 DWORD dwPackedSize;
12 DWORD dwNameLength;
13 DWORD dwFullSize;
14 DWORD dwFlags;
15 char lpFileName[dwNameLength];
16 BYTE lpData[dwPackedSize];
17 };
19 In VB:
21 Type CWAD
22 IDTag As String * 4 = "CWAD"
23 Files() as CWADFILE
24 End Type
26 Type CWADFILE
27 dwPackedSize As Long
28 dwNameLength As Long
29 dwFullSize As Long
30 dwFlags As Long
31 lpFileName As String * dwNameLength
32 lpData(dwPackedSize) As Byte
33 End Type
35 At the beginning, there are 4 bytes, the string "CWAD". After that there is a CWADFILE struct for each file until the end of the CWAD file. After the 16 bytes for the header for each file is the filename, then the actual file data, then the next file header.
37 If dwFlags is 0, the file is uncompressed.
38 If it is 1, the file is compressed.
40 Filenames are encrypted with a fairly simple encryption method. Here is some code for decrypting them:
42 In C++:
44 void DecryptData(BYTE *lpBuffer, DWORD dwBufferLength)
45 {
46 if (lpBuffer==0 || dwBufferLength==0) return;
47 lpBuffer += dwBufferLength - 1;
48 BYTE byCWadKey;
49 byCWadKey = (BYTE)(66 - (dwBufferLength << 1));
50 for (DWORD i=0;i<dwBufferLength;i++) {
51 lpBuffer[0] ^= (BYTE)(byCWadKey + (i << 1));
52 lpBuffer--;
53 }
54 }
56 In VB:
58 Sub DecryptData(ByRef lpBuffer As String)
59 Dim byCWadKey As Byte, i As Long, n As Long
60 n = Len(lpBuffer)
61 byCWadKey = (66 - (n * 2)) Mod 256
62 For i = 0 To Len(lpBuffer) - 1
63 Mid(lpBuffer, n, 1) = Chr$(Asc(Mid$(lpBuffer, n, 1)) Xor ((byCWadKey + (i * 2)) Mod 256))
64 n = n - 1
65 Next i
66 End Function
68 The actual file data is compressed with zlib's compress function, so use zlib's decompress function to decompress the file data. You may get zlib at http://zlib.net/
|