WoWs depack
World of Warships resource files unpacker
Loading...
Searching...
No Matches
wows-depack.h
Go to the documentation of this file.
1
7#include <stdint.h>
8#include <stdbool.h>
9
10/* Error codes */
11
12#define WOWS_ERROR_CORRUPTED_FILE 1
13#define WOWS_ERROR_BAD_MAGIC 2
14#define WOWS_ERROR_MISSING_METADATA_ENTRY 3
15#define WOWS_ERROR_MAX_LEVEL_REACHED 4
16#define WOWS_ERROR_NON_ZERO_TERMINATED_STRING 5
17#define WOWS_ERROR_PATH_TOO_LONG 6
18#define WOWS_ERROR_UNKNOWN 7
19#define WOWS_ERROR_ID_COLLISION_FILE_DIR 8
20#define WOWS_ERROR_FILE_OPEN_FAILURE 9
21#define WOWS_ERROR_DECOMPOSE_PATH 10
22#define WOWS_ERROR_INVALID_SEARCH_PATTERN 11
23#define WOWS_ERROR_NOT_A_FILE 12
24#define WOWS_ERROR_NOT_A_DIR 13
25#define WOWS_ERROR_NOT_FOUND 14
26#define WOWS_ERROR_FILE_WRITE 15
27#define WOWS_ERROR_MAX_FILE 16
29/* ---------- */
30
31/* Debug levels */
32
33#define WOWS_NO_DEBUG 0
34#define WOWS_DEBUG_RAW_RECORD (1 << 0)
35#define WOWS_DEBUG_FILE_LISTING (1 << 1)
37/* ---------- */
38
39/* Search Modes */
40
41#define WOWS_SEARCH_FILE_ONLY 0
42#define WOWS_SEARCH_DIR_ONLY 1
43#define WOWS_SEARCH_FILE_PLUS_DIR 2
44#define WOWS_SEARCH_FULL_PATH 3
46/* ---------- */
47
48/*
49 * @brief WoWs resource extractor context.
50 *
51 * This structure is used to hold the context for the WoWs extractor.
52 *
53 * This structure is not meant to be manipulated directly.
54 * Internal fields are private and could be subject to changes.
55 */
56typedef struct {
57 uint8_t debug_level; // Debug level for logging
58 void *root; // Root Inode (WOWS_DIR_INODE * root;)
59 void *metadata_map; // Global Metadata hashmap (struct hashmap *metadata_map;)
60 void *file_map; // Global File hashmap (struct hashmap *file_map;)
61 void *current_dir; // Current directory (WOWS_DIR_INODE *current_dir;)
62 void **indexes; // Array of structures representing each index file (WOWS_INDEX
63 // **indexes;)
64 uint32_t index_count; // Size of the array
65 bool is_le; // Flag for endianess (true if LE, false if BE)
66 char *err_msg; // Last error message
68
69/* ---------- */
70
71/* Context init/destruction */
72
85WOWS_CONTEXT *wows_init_context(uint8_t debug_level);
86
97
110/* ---------- */
111
112/* Index parsing functions */
113
125int wows_parse_index_file(const char *index_file_path, WOWS_CONTEXT *context);
126
138int wows_parse_index_dir(const char *index_dir_path, WOWS_CONTEXT *context);
139
154int wows_parse_index_buffer(char *contents, size_t length, const char *index_file_path, int fd, WOWS_CONTEXT *context);
155
156/* Archive exploration functions */
157
186int wows_search(WOWS_CONTEXT *context, char *pattern, int mode, int *result_count, char ***results);
187
188/* read the content of a directory */
189// Not implemented
190// int wows_readdir(WOWS_CONTEXT *context, char dir_path, char **result[]);
191
192// Not implemented
193/* give the stat of a given path (mainly if it's a directory or a file, and the file size) */
194// int wows_stat_path(WOWS_CONTEXT *context, char path);
195
196/* ---------- */
197
198/* Archive extraction functions */
199
211int wows_extract_file_fp(WOWS_CONTEXT *context, char *file_path, FILE *output);
212
223int wows_extract_file(WOWS_CONTEXT *context, char *file_path, char *out_path);
224
238int wows_extract_dir(WOWS_CONTEXT *context, char *dir_path, char *out_dir_path);
239
240/* ---------- */
241
242/* Debugging/output functions */
243
254
271
284char *wows_error_string(int error_code, WOWS_CONTEXT *context);
285
286/* ---------- */
287
304int wows_write_pkg(WOWS_CONTEXT *context, char *in_path, char *name, FILE *pkg_fp, FILE *idx_fp);
305
319int wows_get_latest_idx_dir(char *wows_base_dir, char **idx_dir);
Definition wows-depack.h:56
void * root
Definition wows-depack.h:58
bool is_le
Definition wows-depack.h:65
void * current_dir
Definition wows-depack.h:61
void ** indexes
Definition wows-depack.h:62
uint32_t index_count
Definition wows-depack.h:64
void * metadata_map
Definition wows-depack.h:59
void * file_map
Definition wows-depack.h:60
uint8_t debug_level
Definition wows-depack.h:57
char * err_msg
Definition wows-depack.h:66
int wows_parse_index_dir(const char *index_dir_path, WOWS_CONTEXT *context)
Parses all files in a given directory.
int wows_free_context_no_munmap(WOWS_CONTEXT *context)
Frees a WoW Stats Parser context without unmapping the memory.
int wows_get_latest_idx_dir(char *wows_base_dir, char **idx_dir)
Gets the latest index directory in the specified WoWs installation directory.
int wows_parse_index_buffer(char *contents, size_t length, const char *index_file_path, int fd, WOWS_CONTEXT *context)
Low level, parses a memory buffer directly.
char * wows_error_string(int error_code, WOWS_CONTEXT *context)
Converts an error code into an error message string for the given WoWs resource parser context.
int wows_search(WOWS_CONTEXT *context, char *pattern, int mode, int *result_count, char ***results)
Recursively searches for files in the WOWS archive tree that match a PCRE regular expression pattern.
int wows_print_flat(WOWS_CONTEXT *context)
Prints the directory tree of the given WoWs resource parser context in a flat format.
int wows_parse_index_file(const char *index_file_path, WOWS_CONTEXT *context)
Parses a single WoWs resource index file.
int wows_print_tree(WOWS_CONTEXT *context)
Prints the directory tree of the given WoWs resource parser context in a tree format.
int wows_extract_file_fp(WOWS_CONTEXT *context, char *file_path, FILE *output)
Extract a given file from the archive (file pointer version).
WOWS_CONTEXT * wows_init_context(uint8_t debug_level)
Initializes a WoWs resource extractor context.
int wows_write_pkg(WOWS_CONTEXT *context, char *in_path, char *name, FILE *pkg_fp, FILE *idx_fp)
Writes a package file and its index.
int wows_extract_file(WOWS_CONTEXT *context, char *file_path, char *out_path)
Extract a given file from the archive (output file version).
int wows_free_context(WOWS_CONTEXT *context)
Frees a WoWs resource extractor context.
int wows_extract_dir(WOWS_CONTEXT *context, char *dir_path, char *out_dir_path)
Extract a given directory (recursively) from the archive (output file version).