WoWs depack
World of Warships resource files unpacker
Loading...
Searching...
No Matches
wows-depack.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <stdint.h>
10#include <stdbool.h>
11
12/* Error codes */
13
14#define WOWS_ERROR_CORRUPTED_FILE 1
15#define WOWS_ERROR_BAD_MAGIC 2
16#define WOWS_ERROR_MISSING_METADATA_ENTRY 3
17#define WOWS_ERROR_MAX_LEVEL_REACHED 4
18#define WOWS_ERROR_NON_ZERO_TERMINATED_STRING 5
19#define WOWS_ERROR_PATH_TOO_LONG 6
20#define WOWS_ERROR_UNKNOWN 7
21#define WOWS_ERROR_ID_COLLISION_FILE_DIR 8
22#define WOWS_ERROR_FILE_OPEN_FAILURE 9
23#define WOWS_ERROR_DECOMPOSE_PATH 10
24#define WOWS_ERROR_INVALID_SEARCH_PATTERN 11
25#define WOWS_ERROR_NOT_A_FILE 12
26#define WOWS_ERROR_NOT_A_DIR 13
27#define WOWS_ERROR_NOT_FOUND 14
28#define WOWS_ERROR_FILE_WRITE 15
29#define WOWS_ERROR_MAX_FILE 16
31/* ---------- */
32
33/* Debug levels */
34
35#define WOWS_NO_DEBUG 0
36#define WOWS_DEBUG_RAW_RECORD (1 << 0)
37#define WOWS_DEBUG_FILE_LISTING (1 << 1)
39/* ---------- */
40
41/* Search Modes */
42
43#define WOWS_SEARCH_FILE_ONLY 0
44#define WOWS_SEARCH_DIR_ONLY 1
45#define WOWS_SEARCH_FILE_PLUS_DIR 2
46#define WOWS_SEARCH_FULL_PATH 3
48/* ---------- */
49
50/*
51 * @brief WoWs resource extractor context.
52 *
53 * This structure is used to hold the context for the WoWs extractor.
54 *
55 * This structure is not meant to be manipulated directly.
56 * Internal fields are private and could be subject to changes.
57 */
58typedef struct {
59 uint8_t debug_level; // Debug level for logging
60 void *root; // Root Inode (WOWS_DIR_INODE * root;)
61 void *metadata_map; // Global Metadata hashmap (struct hashmap *metadata_map;)
62 void *file_map; // Global File hashmap (struct hashmap *file_map;)
63 void *current_dir; // Current directory (WOWS_DIR_INODE *current_dir;)
64 void **indexes; // Array of structures representing each index file (WOWS_INDEX
65 // **indexes;)
66 uint32_t index_count; // Size of the array
67 bool is_le; // Flag for endianess (true if LE, false if BE)
68 char *err_msg; // Last error message
70
71/* ---------- */
72
73/* Context init/destruction */
74
87WOWS_CONTEXT *wows_init_context(uint8_t debug_level);
88
99
112/* ---------- */
113
114/* Index parsing functions */
115
127int wows_parse_index_file(const char *index_file_path, WOWS_CONTEXT *context);
128
140int wows_parse_index_dir(const char *index_dir_path, WOWS_CONTEXT *context);
141
156int wows_parse_index_buffer(char *contents, size_t length, const char *index_file_path, int fd, WOWS_CONTEXT *context);
157
158/* Archive exploration functions */
159
163typedef struct {
164 uint8_t type;
165 uint32_t size;
166} WOWS_STAT;
167
178int wows_stat_path(WOWS_CONTEXT *context, char *path, WOWS_STAT *stat);
179
195int wows_readdir(WOWS_CONTEXT *context, char *dir_path, int *entry_count, char ***entries);
196
225int wows_search(WOWS_CONTEXT *context, char *pattern, int mode, int *result_count, char ***results);
226
227/* ---------- */
228
229/* Archive extraction functions */
230
242int wows_extract_file_fp(WOWS_CONTEXT *context, char *file_path, FILE *output);
243
254int wows_extract_file(WOWS_CONTEXT *context, char *file_path, char *out_path);
255
269int wows_extract_dir(WOWS_CONTEXT *context, char *dir_path, char *out_dir_path);
270
271/* ---------- */
272
273/* Debugging/output functions */
274
285
302
315char *wows_error_string(int error_code, WOWS_CONTEXT *context);
316
317/* ---------- */
318
335int wows_write_pkg(WOWS_CONTEXT *context, char *in_path, char *name, FILE *pkg_fp, FILE *idx_fp);
336
350int wows_get_latest_idx_dir(char *wows_base_dir, char **idx_dir);
Definition wows-depack.h:58
void * root
Definition wows-depack.h:60
bool is_le
Definition wows-depack.h:67
void * current_dir
Definition wows-depack.h:63
void ** indexes
Definition wows-depack.h:64
uint32_t index_count
Definition wows-depack.h:66
void * metadata_map
Definition wows-depack.h:61
void * file_map
Definition wows-depack.h:62
uint8_t debug_level
Definition wows-depack.h:59
char * err_msg
Definition wows-depack.h:68
Stat structure returned by wows_stat_path().
Definition wows-depack.h:163
uint8_t type
Definition wows-depack.h:164
uint32_t size
Definition wows-depack.h:165
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_readdir(WOWS_CONTEXT *context, char *dir_path, int *entry_count, char ***entries)
Lists the immediate children of a directory in the archive.
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).
int wows_stat_path(WOWS_CONTEXT *context, char *path, WOWS_STAT *stat)
Returns the type and size of a path in the archive.
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).