LibT2FS 0.1
C API for accessing TEngine data in memory.
Loading...
Searching...
No Matches
rnc.h
Go to the documentation of this file.
1/* This file is part of LibT2FS.
2 *
3 * LibT2FS is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * LibT2FS is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <https://www.gnu.org/licenses/>.
15 */
16
17#ifndef H_T2FS_RNC
18#define H_T2FS_RNC
19
20#include <stdint.h>
21
22#define RNC_SIGN 0x524E43 // RNC
23#define RNC_HEADER_SIZE 0x12
24
25typedef enum e_RNCStatus {
26 RNC_OK = 0, // success
27 RNC_ERR_INPUT = 4, // input crc mismatch
28 RNC_ERR_CRC = 5, // crc mismatch
29 RNC_ERR_HEADER = 6, // invalid RNC header
30 RNC_ERR_NEED_KEY = 10, // decryption key needed
31 RNC_ERR_EOMEM = 16 // out of mem
33
34
35#pragma pack(push, 1)
36typedef struct s_rncHuftable {
37 uint32_t l1; // +0
38 uint16_t l2; // +4
39 uint32_t l3; // +6
40 uint16_t bit_depth; // +A
42#pragma pack(pop)
43
44
45typedef struct s_rnc {
46 // user input
47 uint16_t enc_key;
48 uint8_t *input; // user given, do not free
49 uint32_t input_size;
50
51 // read from input buffer
52 uint32_t method;
55 uint16_t unpacked_crc;
56 uint16_t packed_crc;
57 uint32_t leeway;
58 uint32_t chunks_count;
59
60 // inner
62 uint16_t bit_count;
63 uint16_t match_count;
64 uint16_t match_offset;
65 uint32_t bit_buffer;
66
67 uint32_t unpacked_size;
68 uint32_t rnc_data_size;
70
71 uint8_t *mem1; // allocated to heap, do free
72 uint8_t *pack_block_start; // pointer to allocated heap, do not free
73
74 uint8_t *decoded; // allocated to heap, do free
75 uint8_t *window; // pointer to allocated heap, do not free
76
78
79 // we allocate this on rnc_decompress_buf(), do only free on error,
80 // else user is responsible..
81 uint8_t *output;
83
87
88 // header reading endianess handling
89 uint32_t (*read_dword)(uint8_t *, size_t *);
90 uint16_t (*read_word)(uint8_t *, size_t *);
92
93
96
97
98void
100
101
102void
104
105
108 uint8_t *const input, const size_t input_size,
109 uint8_t **outbuf, size_t *outbufSize);
110
111#endif
void rnc_set_be(t_rnc *rnc)
struct s_rnc t_rnc
e_RNCStatus
Definition rnc.h:25
@ RNC_OK
Definition rnc.h:26
@ RNC_ERR_CRC
Definition rnc.h:28
@ RNC_ERR_NEED_KEY
Definition rnc.h:30
@ RNC_ERR_INPUT
Definition rnc.h:27
@ RNC_ERR_HEADER
Definition rnc.h:29
@ RNC_ERR_EOMEM
Definition rnc.h:31
void rnc_free(t_rnc *rnc)
enum e_RNCStatus RNCStatus
struct s_rncHuftable t_rncHuftable
RNCStatus rnc_init(t_rnc *rnc)
RNCStatus rnc_decompress_buf(t_rnc *rnc, uint8_t *const input, const size_t input_size, uint8_t **outbuf, size_t *outbufSize)
Definition rnc.h:36
uint32_t l1
Definition rnc.h:37
uint16_t l2
Definition rnc.h:38
uint32_t l3
Definition rnc.h:39
uint16_t bit_depth
Definition rnc.h:40
Definition rnc.h:45
uint32_t bit_buffer
Definition rnc.h:65
t_rncHuftable pos_table[16]
Definition rnc.h:85
uint32_t decompressed_size
Definition rnc.h:53
uint32_t method
Definition rnc.h:52
uint8_t * decoded
Definition rnc.h:74
uint32_t compressed_size
Definition rnc.h:54
t_rncHuftable raw_table[16]
Definition rnc.h:84
t_rncHuftable len_table[16]
Definition rnc.h:86
uint32_t chunks_count
Definition rnc.h:58
uint8_t * input
Definition rnc.h:48
uint32_t processed_size
Definition rnc.h:61
uint8_t * pack_block_start
Definition rnc.h:72
uint16_t enc_key
Definition rnc.h:47
uint32_t input_size
Definition rnc.h:49
uint16_t(* read_word)(uint8_t *, size_t *)
Definition rnc.h:90
uint16_t match_offset
Definition rnc.h:64
uint16_t packed_crc
Definition rnc.h:56
uint16_t match_count
Definition rnc.h:63
uint16_t bit_count
Definition rnc.h:62
uint8_t * mem1
Definition rnc.h:71
uint16_t unpacked_crc
Definition rnc.h:55
uint32_t unpacked_size
Definition rnc.h:67
size_t output_offset
Definition rnc.h:82
uint16_t unpacked_crc_real
Definition rnc.h:69
uint32_t rnc_data_size
Definition rnc.h:68
uint32_t(* read_dword)(uint8_t *, size_t *)
Definition rnc.h:89
uint8_t * window
Definition rnc.h:75
uint8_t * output
Definition rnc.h:81
size_t read_start_offset
Definition rnc.h:77
uint32_t leeway
Definition rnc.h:57
size_t input_offset
Definition rnc.h:82