WoWs depack
World of Warships resource files unpacker
wows-depack.h File Reference

Header file for the wows-depack library. More...

#include <stdint.h>
#include <stdbool.h>

Go to the source code of this file.

Functions

WOWS_CONTEXTwows_init_context (uint8_t debug_level)
 Initializes a WoWs resource extractor context. More...
 
int wows_free_context (WOWS_CONTEXT *context)
 Frees a WoWs resource extractor context. More...
 
int wows_free_context_no_munmap (WOWS_CONTEXT *context)
 Frees a WoW Stats Parser context without unmapping the memory. More...
 
int wows_parse_index_file (const char *index_file_path, WOWS_CONTEXT *context)
 Parses a single WoWs resource index file. More...
 
int wows_parse_index_dir (const char *index_dir_path, WOWS_CONTEXT *context)
 Parses all files in a given directory. More...
 
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. More...
 
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. More...
 
int wows_extract_file_fp (WOWS_CONTEXT *context, char *file_path, FILE *output)
 Extract a given file from the archive (file pointer version). More...
 
int wows_extract_file (WOWS_CONTEXT *context, char *file_path, char *out_path)
 Extract a given file from the archive (output file version). More...
 
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). More...
 
int wows_print_tree (WOWS_CONTEXT *context)
 Prints the directory tree of the given WoWs resource parser context in a tree format. More...
 
int wows_print_flat (WOWS_CONTEXT *context)
 Prints the directory tree of the given WoWs resource parser context in a flat format. More...
 
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. More...
 
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. More...
 
int wows_get_latest_idx_dir (char *wows_base_dir, char **idx_dir)
 Gets the latest index directory in the specified WoWs installation directory. More...
 

Data Structures

struct  WOWS_CONTEXT
 

Macros

#define WOWS_ERROR_CORRUPTED_FILE   1
 
#define WOWS_ERROR_BAD_MAGIC   2
 
#define WOWS_ERROR_MISSING_METADATA_ENTRY   3
 
#define WOWS_ERROR_MAX_LEVEL_REACHED   4
 
#define WOWS_ERROR_NON_ZERO_TERMINATED_STRING   5
 
#define WOWS_ERROR_PATH_TOO_LONG   6
 
#define WOWS_ERROR_UNKNOWN   7
 
#define WOWS_ERROR_ID_COLLISION_FILE_DIR   8
 
#define WOWS_ERROR_FILE_OPEN_FAILURE   9
 
#define WOWS_ERROR_DECOMPOSE_PATH   10
 
#define WOWS_ERROR_INVALID_SEARCH_PATTERN   11
 
#define WOWS_ERROR_NOT_A_FILE   12
 
#define WOWS_ERROR_NOT_A_DIR   13
 
#define WOWS_ERROR_NOT_FOUND   14
 
#define WOWS_ERROR_FILE_WRITE   15
 
#define WOWS_ERROR_MAX_FILE   16
 
#define WOWS_NO_DEBUG   0
 
#define WOWS_DEBUG_RAW_RECORD   (1 << 0)
 
#define WOWS_DEBUG_FILE_LISTING   (1 << 1)
 
#define WOWS_SEARCH_FILE_ONLY   0
 
#define WOWS_SEARCH_DIR_ONLY   1
 
#define WOWS_SEARCH_FILE_PLUS_DIR   2
 
#define WOWS_SEARCH_FULL_PATH   3
 

Detailed Description

Header file for the wows-depack library.

Function Documentation

◆ wows_error_string()

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.

This function converts an error code into an error message string for the given WoWs resource parser context.

Parameters
error_codeThe error code to convert.
contextA pointer to the WoWs resource parser context to use.
Returns
0 on success, or an error code if an error occurred.
Note
It's up to the caller to free the returned string

◆ wows_extract_dir()

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).

This function will extract all files under the given directory. The whole directory tree from the archive will be recreated under out_dir_path.

Parameters
contextPointer to a WOWS_CONTEXT structure.
dir_pathPath of the directory to extract.
out_dir_pathPath to the output directory.
Returns
0 on success, or an error code if an error occurred.

◆ wows_extract_file()

int wows_extract_file ( WOWS_CONTEXT context,
char *  file_path,
char *  out_path 
)

Extract a given file from the archive (output file version).

Parameters
contextPointer to a WOWS_CONTEXT structure.
file_pathPath of the file to extract.
out_pathPath to the output file.
Returns
0 on success, or an error code if an error occurred.

◆ wows_extract_file_fp()

int wows_extract_file_fp ( WOWS_CONTEXT context,
char *  file_path,
FILE *  output 
)

Extract a given file from the archive (file pointer version).

Parameters
contextPointer to a WOWS_CONTEXT structure.
file_pathPath of the file to extract.
outputPointer to a FILE structure to write the output to.
Returns
0 on success, or an error code if an error occurred.
Note
It's up to the caller to open and close FILE *output

◆ wows_free_context()

int wows_free_context ( WOWS_CONTEXT context)

Frees a WoWs resource extractor context.

This function frees the memory allocated for a WoWs resource extractor context.

Parameters
contextA pointer to the context to free.
Returns
0 on success, or an error code if an error occurred.

◆ wows_free_context_no_munmap()

int wows_free_context_no_munmap ( WOWS_CONTEXT context)

Frees a WoW Stats Parser context without unmapping the memory.

This function frees the memory allocated for a WoWs resource extractor context, but does not unmap the memory or close files from the process address space. This function should only be used if the raw wows_parse_index_buffer function was used.

Parameters
contextA pointer to the context to free.
Returns
0 on success, or an error code if an error occurred.

◆ wows_get_latest_idx_dir()

int wows_get_latest_idx_dir ( char *  wows_base_dir,
char **  idx_dir 
)

Gets the latest index directory in the specified WoWs installation directory.

This function takes a base directory path for a World of Warships installation and a pointer to a char pointer to store the path of the latest index directory.

Parameters
wows_base_dirPath to the World of Warships installation directory.
idx_dirPointer to a char pointer to store the name of the latest index directory. The memory for this pointer will be allocated by the function and must be freed by the caller.
Returns
0 on success, or an error code if an error occurred.
Note
The caller is responsible for freeing the memory allocated for the idx_dir parameter.

◆ wows_init_context()

WOWS_CONTEXT* wows_init_context ( uint8_t  debug_level)

Initializes a WoWs resource extractor context.

This function creates and initializes a new WoW Stats Parser context with the given debug level.

Parameters
debug_levelThe debug level for the parser.
Returns
A pointer to the newly created context, or NULL if an error occurred.
Note
Call wows_free_context() to liberate context memory

◆ wows_parse_index_buffer()

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.

This function parses a WoWs resource index buffer directly from memory with the given contents and length, and updates the given parser context with the parsed data.

Parameters
contentsA pointer to the buffer containing the WoWs resource index contents to parse.
lengthThe length of the buffer in bytes.
index_file_pathThe path to the WoWs resource index file.
fdThe file descriptor associated with the index file.
contextA pointer to the parser context to update.
Returns
0 on success, or an error code if an error occurred.

◆ wows_parse_index_dir()

int wows_parse_index_dir ( const char *  index_dir_path,
WOWS_CONTEXT context 
)

Parses all files in a given directory.

This function parses all WoWs resource index files in a given directory with the given path and updates the given parser context with the parsed data.

Parameters
index_dir_pathThe path to the directory containing the WoWs resource index files to parse.
contextA pointer to the parser context to update.
Returns
0 on success, or an error code if an error occurred.

◆ wows_parse_index_file()

int wows_parse_index_file ( const char *  index_file_path,
WOWS_CONTEXT context 
)

Parses a single WoWs resource index file.

This function parses a single WoWs resource index file with the given path and updates the given parser context with the parsed data.

Parameters
index_file_pathThe path to the WoWs resource index file to parse.
contextA pointer to the parser context to update.
Returns
0 on success, or an error code if an error occurred.

◆ wows_print_flat()

int wows_print_flat ( WOWS_CONTEXT context)

Prints the directory tree of the given WoWs resource parser context in a flat format.

This function prints the directory tree of the given WoWs resource parser context in a flat format (each file with its full path).

For example: /dir1/file2 /dir3/dir4/file5

Parameters
contextA pointer to the WoWs resource parser context to print.
Returns
0 on success, or an error code if an error occurred.

◆ wows_print_tree()

int wows_print_tree ( WOWS_CONTEXT context)

Prints the directory tree of the given WoWs resource parser context in a tree format.

This function prints the directory tree of the given WoWs resource parser context in a tree format.

Parameters
contextA pointer to the WoWs resource parser context to print.
Returns
0 on success, or an error code if an error occurred.

◆ wows_search()

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.

Parameters
contextThe WOWS_CONTEXT object representing the root of the archive tree.
patternThe PCRE regular expression pattern to match against file names. The pattern is passed to the matcher as ^{PATTERN}$
modeThe search mode, which can be one of the following values:
  • WOWS_SEARCH_FILE_ONLY: search for files only (exclude directories)
  • WOWS_SEARCH_DIR_ONLY: search for directories only (exclude files)
  • WOWS_SEARCH_FILE_PLUS_DIR: search on directory and file names.
  • WOWS_SEARCH_FULL_PATH: search on the full file pathes
[out]result_countA pointer to an integer variable that will be set to the number of matching files or directories found.
[out]resultsA pointer to an array of strings that will be allocated to hold the names of the matching files or directories. The caller is responsible for freeing the memory allocated for this array and its elements.
Returns
0 on success, or a non-zero error code on failure.

This function searches recursively through the WOWS archive tree for files or directories that match the given PCRE regular expression pattern. The search can be restricted to files, directories, or the full path, depending on the value of the mode parameter. The names of the matching files or directories are stored in the results array, and the number of matches is stored in the result_count variable. The caller is responsible for freeing the memory allocated for the results array and its elements.

Returns
0 on success, or an error code if an error occurred.
Note
It's up to the caller to free each entry in the results array and free the array itself.

◆ wows_write_pkg()

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.

This function takes a WOWS_CONTEXT pointer, an input directory path, a name for the .pkg file, and pointers to file streams for the package file and its index. The function writes the package file and its index to the provided file streams, using the given name.

Parameters
contextPointer to a WOWS_CONTEXT struct.
in_pathInput directory path to package.
nameName for the '.pkg file'.
pkg_fpPointer to a file stream to write the package file to.
idx_fpPointer to a file stream to write the index file to.
Returns
0 on success, or an error code if an error occurred.
Note
This function is experimental

Macro Definition Documentation

◆ WOWS_DEBUG_FILE_LISTING

#define WOWS_DEBUG_FILE_LISTING   (1 << 1)

Debug output for file listings.

◆ WOWS_DEBUG_RAW_RECORD

#define WOWS_DEBUG_RAW_RECORD   (1 << 0)

Debug output for raw records.

◆ WOWS_ERROR_BAD_MAGIC

#define WOWS_ERROR_BAD_MAGIC   2

A bad magic number in a WoWs resource file.

◆ WOWS_ERROR_CORRUPTED_FILE

#define WOWS_ERROR_CORRUPTED_FILE   1

A corrupted WoWs resource file.

◆ WOWS_ERROR_DECOMPOSE_PATH

#define WOWS_ERROR_DECOMPOSE_PATH   10

An error while decomposing a path.

◆ WOWS_ERROR_FILE_OPEN_FAILURE

#define WOWS_ERROR_FILE_OPEN_FAILURE   9

A failure to open a file.

◆ WOWS_ERROR_FILE_WRITE

#define WOWS_ERROR_FILE_WRITE   15

file write error

◆ WOWS_ERROR_ID_COLLISION_FILE_DIR

#define WOWS_ERROR_ID_COLLISION_FILE_DIR   8

A file and directory identifier collision.

◆ WOWS_ERROR_INVALID_SEARCH_PATTERN

#define WOWS_ERROR_INVALID_SEARCH_PATTERN   11

failure to compile regex pattern

◆ WOWS_ERROR_MAX_FILE

#define WOWS_ERROR_MAX_FILE   16

maximum number of file/dir

◆ WOWS_ERROR_MAX_LEVEL_REACHED

#define WOWS_ERROR_MAX_LEVEL_REACHED   4

The maximum directory nesting level has been reached.

◆ WOWS_ERROR_MISSING_METADATA_ENTRY

#define WOWS_ERROR_MISSING_METADATA_ENTRY   3

A missing metadata entry in a WoWs resource file.

◆ WOWS_ERROR_NON_ZERO_TERMINATED_STRING

#define WOWS_ERROR_NON_ZERO_TERMINATED_STRING   5

A non-zero-terminated string in a WoWs resource file.

◆ WOWS_ERROR_NOT_A_DIR

#define WOWS_ERROR_NOT_A_DIR   13

path is not a directory

◆ WOWS_ERROR_NOT_A_FILE

#define WOWS_ERROR_NOT_A_FILE   12

path is not a file

◆ WOWS_ERROR_NOT_FOUND

#define WOWS_ERROR_NOT_FOUND   14

file or directory not found

◆ WOWS_ERROR_PATH_TOO_LONG

#define WOWS_ERROR_PATH_TOO_LONG   6

A path is too long to be processed.

◆ WOWS_ERROR_UNKNOWN

#define WOWS_ERROR_UNKNOWN   7

An unknown error occurred.

◆ WOWS_NO_DEBUG

#define WOWS_NO_DEBUG   0

No debug output.

◆ WOWS_SEARCH_DIR_ONLY

#define WOWS_SEARCH_DIR_ONLY   1

Search only on directory names.

◆ WOWS_SEARCH_FILE_ONLY

#define WOWS_SEARCH_FILE_ONLY   0

Search only on file names.

◆ WOWS_SEARCH_FILE_PLUS_DIR

#define WOWS_SEARCH_FILE_PLUS_DIR   2

Search on directory and file names.

◆ WOWS_SEARCH_FULL_PATH

#define WOWS_SEARCH_FULL_PATH   3

Search on the full path of files.