Rizin
unix-like reverse engineering framework and cli tools
|
#include <sys/types.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fnmatch.h>
#include <limits.h>
#include <locale.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include "getopt.h"
#include <mspack.h>
#include <md5.h>
Go to the source code of this file.
Classes | |
struct | file_mem |
struct | filter |
struct | cabextract_args |
struct | mspack_file_p |
Macros | |
#define | _GNU_SOURCE 1 |
#define | FNM_CASEFOLD (0) |
Functions | |
static int | process_cabinet (char *cabname) |
static void | load_spanning_cabinets (struct mscabd_cabinet *basecab, char *basename) |
static char * | find_cabinet_file (char *origcab, char *cabname) |
static int | unix_path_seperators (struct mscabd_file *files) |
static char * | create_output_name (const char *fname, const char *dir, int lower, int isunix, int unicode) |
static void | set_date_and_perm (struct mscabd_file *file, char *filename) |
static void | memorise_file (struct file_mem **fml, char *name, char *from) |
static int | recall_file (struct file_mem *fml, char *name, char **from) |
static void | forget_files (struct file_mem **fml) |
static void | add_filter (char *arg) |
static void | free_filters () |
static int | ensure_filepath (char *path) |
static char * | cab_error (struct mscab_decompressor *cd) |
static struct mspack_file * | cabx_open (struct mspack_system *this, const char *filename, int mode) |
static void | cabx_close (struct mspack_file *file) |
static int | cabx_read (struct mspack_file *file, void *buffer, int bytes) |
static int | cabx_write (struct mspack_file *file, void *buffer, int bytes) |
static int | cabx_seek (struct mspack_file *file, off_t offset, int mode) |
static off_t | cabx_tell (struct mspack_file *file) |
static void | cabx_msg (struct mspack_file *file, const char *format,...) |
static void * | cabx_alloc (struct mspack_system *this, size_t bytes) |
static void | cabx_free (void *buffer) |
static void | cabx_copy (void *src, void *dest, size_t bytes) |
int | main (int argc, char *argv[]) |
Variables | |
struct option | optlist [] |
const char * | OPTSTRING = "d:fF:hlLpqstv" |
struct mscab_decompressor * | cabd = NULL |
struct file_mem * | cab_args = NULL |
struct file_mem * | cab_exts = NULL |
struct file_mem * | cab_seen = NULL |
mode_t | user_umask = 0 |
struct cabextract_args | args |
const char * | STDOUT_FNAME = "stdout" |
const char * | TEST_FNAME = "test" |
struct md5_ctx | md5_context |
unsigned char | md5_result [16] |
static struct mspack_system | cabextract_system |
#define _GNU_SOURCE 1 |
Definition at line 23 of file cabextract.c.
#define FNM_CASEFOLD (0) |
Definition at line 74 of file cabextract.c.
|
static |
Adds a filter to args.filters. On first call, sets up free_filters() to run at exit.
arg | filter to add |
Definition at line 1094 of file cabextract.c.
References arg(), args, f, cabextract_args::filters, free_filters(), and malloc().
Referenced by main().
|
static |
Returns a string with an error message appropriate for the last error of the CAB decompressor.
cd | the CAB decompressor. |
Definition at line 1146 of file cabextract.c.
References cd, MSPACK_ERR_CHECKSUM, MSPACK_ERR_DATAFORMAT, MSPACK_ERR_DECRUNCH, MSPACK_ERR_NOMEMORY, MSPACK_ERR_OPEN, MSPACK_ERR_READ, MSPACK_ERR_SEEK, MSPACK_ERR_SIGNATURE, and MSPACK_ERR_WRITE.
Referenced by load_spanning_cabinets(), and process_cabinet().
|
static |
Definition at line 1305 of file cabextract.c.
|
static |
Definition at line 1229 of file cabextract.c.
References fh, free(), md5_context, md5_finish_ctx(), md5_result, mspack_file_p::regular_file, and TEST_FNAME.
|
static |
Definition at line 1311 of file cabextract.c.
|
static |
Definition at line 1308 of file cabextract.c.
References free().
|
static |
Definition at line 1294 of file cabextract.c.
|
static |
Definition at line 1176 of file cabextract.c.
References fh, free(), malloc(), md5_context, md5_init_ctx(), MSPACK_SYS_OPEN_APPEND, MSPACK_SYS_OPEN_READ, MSPACK_SYS_OPEN_UPDATE, MSPACK_SYS_OPEN_WRITE, NULL, STDOUT_FNAME, and TEST_FNAME.
|
static |
Definition at line 1242 of file cabextract.c.
References bytes, count, fh, and mspack_file_p::regular_file.
|
static |
Definition at line 1267 of file cabextract.c.
References fh, fseeko, MSPACK_SYS_SEEK_CUR, MSPACK_SYS_SEEK_END, MSPACK_SYS_SEEK_START, mspack_file_p::regular_file, SEEK_CUR, SEEK_END, and SEEK_SET.
|
static |
Definition at line 1285 of file cabextract.c.
References fh, ftello, and mspack_file_p::regular_file.
|
static |
Definition at line 1251 of file cabextract.c.
References bytes, count, fh, md5_context, md5_process_bytes(), and TEST_FNAME.
|
static |
Creates a UNIX filename from the internal CAB filename and the given parameters.
fname | the internal CAB filename. |
dir | a directory path to prepend to the output filename. |
lower | if non-zero, filename should be made lower-case. |
isunix | if zero, MS-DOS path seperators are used in the internal CAB filename. If non-zero, UNIX path seperators are used. |
utf8 | if non-zero, the internal CAB filename is encoded in UTF-8. |
Definition at line 761 of file cabextract.c.
References c, filelen, create_tags_rz::fname, i, len, malloc(), name, NULL, tolower, and x.
Referenced by process_cabinet().
|
static |
Ensures that all directory components in a filepath exist. New directory components are created, if necessary.
path | the filepath to check |
Definition at line 1123 of file cabextract.c.
References mkdir, ok, p, path, S_ISDIR, stat, and user_umask.
Referenced by process_cabinet().
|
static |
Matches a cabinet's filename case-insensitively in the filesystem and returns the case-correct form.
origcab | if this is non-NULL, the pathname part of this filename will be extracted, and the search will be conducted in that directory. |
cabname | the internal CAB filename to search for. |
Definition at line 622 of file cabextract.c.
References found, free(), len, malloc(), memcpy(), NULL, readdir, S_ISREG, and stat.
Referenced by load_spanning_cabinets().
|
static |
Frees all memory used by a file_mem list.
fml | address of the list to free |
Definition at line 1078 of file cabextract.c.
References free(), file_mem::from, file_mem::next, and NULL.
Referenced by main().
|
static |
Frees all memory used by args.filters
Definition at line 1107 of file cabextract.c.
References args, f, cabextract_args::filters, free(), and filter::next.
Referenced by add_filter().
|
static |
Follows the spanning cabinet chain specified in a cabinet, loading and attaching the spanning cabinets as it goes.
basecab | the base cabinet to start the chain from. |
basename | the full pathname of the base cabinet, so spanning cabinets can be found in the same path as the base cabinet. |
Definition at line 564 of file cabextract.c.
References mscab_decompressor::append, args, basename, cab_args, cab_error(), cab_exts, cabd, mscab_decompressor::close, find_cabinet_file(), mscabd_cabinet::flags, memorise_file(), MSCAB_HDR_NEXTCAB, MSCAB_HDR_PREVCAB, name, mscabd_cabinet::nextcab, mscabd_cabinet::nextinfo, mscabd_cabinet::nextname, NULL, mscab_decompressor::open, mscab_decompressor::prepend, mscabd_cabinet::prevcab, mscabd_cabinet::previnfo, mscabd_cabinet::prevname, printf(), cabextract_args::quiet, recall_file(), and cabextract_args::single.
Referenced by process_cabinet().
Definition at line 211 of file cabextract.c.
References add_filter(), args, argv, cab_args, cab_exts, cab_seen, cabd, cabextract_system, cabextract_args::dir, cabextract_args::encoding, err, cabextract_args::fix, forget_files(), getopt_long(), cabextract_args::help, i, cabextract_args::lower, memorise_file(), MSCABD_PARAM_FIXMSZIP, MSCABD_PARAM_SALVAGE, mspack_create_cab_decompressor(), mspack_destroy_cab_decompressor(), MSPACK_ERR_SEEK, MSPACK_SYS_SELFTEST, NULL, optarg, optind, optlist, OPTSTRING, cabextract_args::pipe, printf(), process_cabinet(), cabextract_args::quiet, mscab_decompressor::set_param, cabextract_args::single, cabextract_args::test, umask, user_umask, VERSION, and cabextract_args::view.
|
static |
Memorises a file by its device and inode number rather than its name. If the file does not exist, it will not be memorised.
fml | address of the file_mem list that will memorise this file. |
name | name of the file to memorise. |
from | a string that, if not NULL, will be duplicated stored with the memorised file. |
Definition at line 1034 of file cabextract.c.
References from, file_mem::from, malloc(), file_mem::next, NULL, file_mem::st_dev, file_mem::st_ino, and stat.
Referenced by load_spanning_cabinets(), main(), and process_cabinet().
|
static |
Processes each file argument on the command line, as specified by the command line options. This does the main bulk of work in cabextract.
basename | the file to process |
Definition at line 391 of file cabextract.c.
References args, basename, cab_error(), cab_exts, cab_seen, cabd, mscab_decompressor::close, create_output_name(), cabextract_args::dir, ensure_filepath(), mscab_decompressor::extract, f, file, mscabd_cabinet::filename, mscabd_cabinet::files, cabextract_args::filters, FNM_CASEFOLD, fnmatch(), free(), from, mscab_decompressor::last_error, load_spanning_cabinets(), cabextract_args::lower, md5_result, memorise_file(), MSCAB_ATTRIB_UTF_NAME, name, mscabd_cabinet::next, file::next, mscabd_cabinet::nextcab, NULL, cabextract_args::pipe, mscabd_cabinet::prevcab, printf(), cabextract_args::quiet, recall_file(), mscab_decompressor::search, set_date_and_perm(), spaces(), STDOUT_FNAME, cabextract_args::test, TEST_FNAME, unix_path_seperators(), and cabextract_args::view.
Referenced by main().
Determines if a file has been memorised before, by its device and inode number. If the file does not exist, it cannot be recalled.
fml | list to search for previously memorised file |
name | name of file to recall. |
from | if non-NULL, this is an address that the associated "from" description pointer will be stored. |
Definition at line 1059 of file cabextract.c.
References from, file_mem::from, file_mem::next, file_mem::st_dev, file_mem::st_ino, and stat.
Referenced by load_spanning_cabinets(), and process_cabinet().
|
static |
Sets the last-modified time and file permissions on a file.
file | the internal CAB file whose date, time and attributes will be used. |
filename | the name of the UNIX file whose last-modified time and file permissions will be set. |
Definition at line 914 of file cabextract.c.
References chmod, MSCAB_ATTRIB_EXEC, MSCAB_ATTRIB_RDONLY, tv, user_umask, and utime.
Referenced by process_cabinet().
|
static |
Determines whether UNIX '/' or MS-DOS '\' path seperators are used in the cabinet file. The algorithm is as follows:
Look at all slashes in all filenames. If there are no slashes, MS-DOS seperators are assumed (it doesn't matter). If all are backslashes, MS-DOS seperators are assumed. If all are forward slashes, UNIX seperators are assumed.
If not all slashes are the same, go through each filename, looking for the first slash. If the part of the filename up to and including the slash matches the previous filename, that kind of slash is the directory seperator.
files | list of files in the cab file |
Definition at line 690 of file cabextract.c.
References c, mscabd_file::filename, files, len, name, mscabd_file::next, file::next, NULL, and p.
Referenced by process_cabinet().
struct cabextract_args args |
Definition at line 132 of file cabextract.c.
Referenced by add_filter(), createdb(), free_filters(), insertkeys(), invoke_cgi_script(), load_spanning_cabinets(), main(), process_cabinet(), read_name(), setup_workers(), and spp_help().
Definition at line 128 of file cabextract.c.
Referenced by load_spanning_cabinets(), and main().
Definition at line 129 of file cabextract.c.
Referenced by load_spanning_cabinets(), main(), and process_cabinet().
Definition at line 130 of file cabextract.c.
Referenced by main(), and process_cabinet().
struct mscab_decompressor* cabd = NULL |
Definition at line 126 of file cabextract.c.
Referenced by load_spanning_cabinets(), main(), process_cabinet(), and rz_bin_pdb_extract_in_folder().
|
static |
A cabextract-specific implementation of mspack_system that allows the NULL filename to be opened for writing as a synonym for writing to stdout.
Definition at line 199 of file cabextract.c.
Referenced by main().
struct md5_ctx md5_context |
A global MD5 context, used when a file is written to TEST_FNAME
Definition at line 155 of file cabextract.c.
Referenced by cabx_close(), cabx_open(), and cabx_write().
unsigned char md5_result[16] |
The resultant MD5 checksum, used when a file is written to TEST_FNAME
Definition at line 161 of file cabextract.c.
Referenced by cabx_close(), and process_cabinet().
struct option optlist[] |
const char* OPTSTRING = "d:fF:hlLpqstv" |
Definition at line 104 of file cabextract.c.
Referenced by main().
const char* STDOUT_FNAME = "stdout" |
A special filename. Extracting to this filename will send the output to standard output instead of a file on disk. The magic happens in cabx_open() when the STDOUT_FNAME pointer is given as a filename, so treat this like a constant rather than a string.
Definition at line 148 of file cabextract.c.
Referenced by cabx_open(), and process_cabinet().
const char* TEST_FNAME = "test" |
A special filename. Extracting to this filename will send the output through an MD5 checksum calculator, instead of a file on disk. The magic happens in cabx_open() when the TEST_FNAME pointer is given as a filename, so treat this like a constant rather than a string.
Definition at line 155 of file cabextract.c.
Referenced by cabx_close(), cabx_open(), cabx_write(), and process_cabinet().
mode_t user_umask = 0 |
Definition at line 132 of file cabextract.c.
Referenced by ensure_filepath(), main(), and set_date_and_perm().