1 /*---------------------------------------------------------------------------* 2 Project: TwlSDK - include - mi 3 File: secureUncompression.h 4 5 Copyright 2008 Nintendo. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Date:: 2008-06-20#$ 14 $Rev: 6675 $ 15 $Author: nishimoto_takashi $ 16 *---------------------------------------------------------------------------*/ 17 18 #ifndef NITRO_MI_SECURE_UNCOMPRESSION_H__ 19 #define NITRO_MI_SECURE_UNCOMPRESSION_H__ 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #include <nitro/types.h> 26 27 #define MI_ERR_SUCCESS 0 28 #define MI_ERR_UNSUPPORTED -1 29 #define MI_ERR_SRC_SHORTAGE -2 30 #define MI_ERR_SRC_REMAINDER -3 31 #define MI_ERR_DEST_OVERRUN -4 32 #define MI_ERR_ILLEGAL_TABLE -5 33 34 //====================================================================== 35 // Expanding Compressed Data 36 //====================================================================== 37 38 /*---------------------------------------------------------------------------* 39 Name: MI_SecureUncompressAny 40 41 Description: Determines the compression type from the data header and runs the appropriate decompression process. 42 43 Decompression processing will be linked for all compression types, so it may be better to run separate functions for each compression type if you are only using a specific compression format. 44 45 46 47 Arguments: srcp Source address 48 srcSize Source data size 49 destp Destination address 50 dstSize: Destination size 51 52 Returns: 0 if the conversion was successful 53 A negative error code on failure 54 *---------------------------------------------------------------------------*/ 55 s32 MI_SecureUncompressAny( const void* srcp, u32 srcSize, void* destp, u32 dstSize ); 56 57 58 /*---------------------------------------------------------------------------* 59 Name: MI_SecureUncompressRL 60 61 Description: 8-bit decompression of run-length compressed data 62 63 - Decompresses run-length compressed data, writing in 8 bit units. 64 - Use 4 byte alignment for the source address. 65 66 - Data header 67 u32 :4 : Reserved 68 compType:4 Compression type( = 3) 69 destSize:24 Data size after decompression 70 71 - Flag data format 72 u8 length:7 Decompressed data length - 1 (When not compressed) 73 Decompressed data length - 3 (only compress when the contiguous length is 3 bytes or greater) 74 flag:1 (0, 1) = (not compressed, compressed) 75 76 Arguments: *srcp Source address 77 srcSize Source data size 78 *destp Destination address 79 dstSize: Destination size 80 81 Returns: 0 if the conversion was successful 82 A negative error code on failure 83 *---------------------------------------------------------------------------*/ 84 s32 MI_SecureUncompressRL( const void *srcp, u32 srcSize, void *destp, u32 dstSize ); 85 86 87 /*---------------------------------------------------------------------------* 88 Name: MI_SecureUncompressLZ 89 90 Description: 8-bit decompression of LZ77 compressed data 91 92 * Expands LZ77-compressed data and writes it in 8-bit units. 93 - Use 4 byte alignment for the source address. 94 95 - Data header 96 u32 :4 : Reserved 97 compType:4 Compression type( = 1) 98 destSize:24 Data size after decompression 99 100 - Flag data format 101 u8 flags Compression/no compression flag 102 (0, 1) = (not compressed, compressed) 103 - Code data format (Big Endian) 104 u16 length:4 Decompressed data length - 3 (only compress when the match length is 3 bytes or greater) 105 offset:12 Match data offset - 1 106 107 Arguments: *srcp Source address 108 srcSize Source data size 109 *destp Destination address 110 dstSize: Destination size 111 112 Returns: 0 if the conversion was successful 113 A negative error code on failure 114 *---------------------------------------------------------------------------*/ 115 s32 MI_SecureUncompressLZ( const void *srcp, u32 srcSize, void *destp, u32 dstSize ); 116 117 118 /*---------------------------------------------------------------------------* 119 Name: MI_SecureUncompressHuffman 120 121 Description: Decompression of Huffman compressed data 122 123 - Decompresses Huffman compressed data, writing in 32 bit units. 124 - Use 4 byte alignment for the source address. 125 - Use 4-byte alignment for the destination address. 126 - The target decompression buffer size must be prepared in 4-byte multiples. 127 128 - Data header 129 u32 bitSize:4 1 data bit size (Normally 4|8) 130 compType:4 Compression type( = 2) 131 destSize:24 Data size after decompression 132 133 - Tree table 134 u8 treeSize Tree table size/2 - 1 135 TreeNodeData nodeRoot Root node 136 137 TreeNodeData nodeLeft Root left node 138 TreeNodeData nodeRight Root right node 139 140 TreeNodeData nodeLeftLeft Left left node 141 TreeNodeData nodeLeftRight Left right node 142 143 TreeNodeData nodeRightLeft Right left node 144 TreeNodeData nodeRightRight Right right node 145 146 �E 147 �E 148 149 The compressed data itself follows 150 151 - TreeNodeData structure 152 u8 nodeNextOffset:6 : Offset to the next node data - 1 (2 byte units) 153 rightEndFlag:1 Right node end flag 154 leftEndzflag:1 Left node end flag 155 When the end flag is set 156 There is data in next node 157 158 Arguments: *srcp Source address 159 srcSize Source data size 160 *destp Destination address 161 dstSize: Destination size 162 163 Returns: 0 if the conversion was successful 164 A negative error code on failure 165 *---------------------------------------------------------------------------*/ 166 s32 MI_SecureUncompressHuffman( const void *srcp, u32 srcSize, void *destp, u32 dstSize ); 167 168 /*---------------------------------------------------------------------------* 169 Name: MI_SecureUnfilterDiff 170 171 Description: 8-bit decompression to restore differential filter conversion. 172 173 - Restores a differential filter, writing in 8 bit units. 174 - Cannot decompress directly into VRAM 175 - If the compressed data size was not a multiple of four, adjust by padding with 0s as much as possible. 176 177 - Use 4 byte alignment for the source address. 178 179 Arguments: *srcp Source address 180 srcSize Source size 181 *destp Destination address 182 dstSize: Destination size 183 184 Returns: 0 if the conversion was successful 185 A negative error code on failure 186 *---------------------------------------------------------------------------*/ 187 s32 MI_SecureUnfilterDiff( register const void *srcp, u32 srcSize, register void *destp, u32 dstSize ); 188 189 /*---------------------------------------------------------------------------* 190 Name: MI_SecureUncompressBLZ 191 192 Description: Uncompress BLZ ( backward LZ ) 193 194 Arguments: 195 void *srcp source address ( data buffer compressed by compBLZ.exe ) 196 u32 srcSize source data size ( data size of compressed data ) 197 u32 dstSize data size after uncompressing 198 199 Returns: None. 200 *---------------------------------------------------------------------------*/ 201 s32 MI_SecureUncompressBLZ(const void *srcp, u32 srcSize, u32 dstSize); 202 203 //================================================================================ 204 205 #ifdef __cplusplus 206 } /* extern "C" */ 207 #endif 208 209 /* NITRO_MI_SECURE_UNCOMPRESSION_H__ */ 210 #endif 211