1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
#include "tsk/tsk_tools_i.h"
#include <locale.h>
static TSK_TCHAR *progname;
static void
usage()
{
TFPRINTF(stderr,
_TSK_T
("usage: %" PRIttocTSK " [-tvV] [-p pooltype] [-i imgtype] [-b dev_sector_size] [-o imgoffset] image\n"),
progname);
tsk_fprintf(stderr, "\t-t: display type only\n");
tsk_fprintf(stderr,
"\t-i imgtype: The format of the image file (use '-i list' for supported types)\n");
tsk_fprintf(stderr,
"\t-b dev_sector_size: The size (in bytes) of the device sectors\n");
tsk_fprintf(stderr,
"\t-P pooltype: Pool container type (use '-P list' for supported types)\n");
tsk_fprintf(stderr,
"\t-o imgoffset: The offset of the file system in the image (in sectors)\n");
tsk_fprintf(stderr, "\t-v: verbose output to stderr\n");
tsk_fprintf(stderr, "\t-V: Print version\n");
exit(1);
}
int
main(int argc, char **argv1)
{
TSK_IMG_TYPE_ENUM imgtype = TSK_IMG_TYPE_DETECT;
TSK_OFF_T imgaddr = 0;
TSK_POOL_TYPE_ENUM pooltype = TSK_POOL_TYPE_DETECT;
int ch;
uint8_t type = 0;
TSK_TCHAR **argv;
unsigned int ssize = 0;
TSK_TCHAR *cp;
#ifdef TSK_WIN32
// On Windows, get the wide arguments (mingw doesn't support wmain)
argv = CommandLineToArgvW(GetCommandLineW(), &argc);
if (argv == nullptr) {
fprintf(stderr, "Error getting wide arguments\n");
exit(1);
}
#else
argv = (TSK_TCHAR **) argv1;
#endif
progname = argv[0];
setlocale(LC_ALL, "");
while ((ch = GETOPT(argc, argv, _TSK_T("b:P:i:o:tvV"))) > 0) {
switch (ch) {
case _TSK_T('?'):
default:
TFPRINTF(stderr, _TSK_T("Invalid argument: %" PRIttocTSK "\n"),
argv[OPTIND]);
usage();
case _TSK_T('b'):
ssize = (unsigned int) TSTRTOUL(OPTARG, &cp, 0);
if (*cp || *cp == *OPTARG || ssize < 1) {
TFPRINTF(stderr,
_TSK_T
("invalid argument: sector size must be positive: %" PRIttocTSK "\n"),
OPTARG);
usage();
}
break;
case _TSK_T('P'):
if (TSTRCMP(OPTARG, _TSK_T("list")) == 0) {
tsk_pool_type_print(stderr);
exit(1);
}
pooltype = tsk_pool_type_toid(OPTARG);
if (pooltype == TSK_POOL_TYPE_UNSUPP) {
TFPRINTF(stderr,
_TSK_T("Unsupported pool container type: %" PRIttocTSK "\n"), OPTARG);
usage();
}
break;
case _TSK_T('i'):
if (TSTRCMP(OPTARG, _TSK_T("list")) == 0) {
tsk_img_type_print(stderr);
exit(1);
}
imgtype = tsk_img_type_toid(OPTARG);
if (imgtype == TSK_IMG_TYPE_UNSUPP) {
TFPRINTF(stderr, _TSK_T("Unsupported image type: %" PRIttocTSK "\n"),
OPTARG);
usage();
}
break;
case _TSK_T('o'):
if ((imgaddr = tsk_parse_offset(OPTARG)) == -1) {
tsk_error_print(stderr);
exit(1);
}
break;
case _TSK_T('t'):
type = 1;
break;
case _TSK_T('v'):
tsk_verbose++;
break;
case _TSK_T('V'):
tsk_version_print(stdout);
exit(0);
}
}
/* We need at least one more argument */
if (OPTIND >= argc) {
tsk_fprintf(stderr, "Missing image name\n");
usage();
}
const auto img = tsk_img_open(argc - OPTIND, &argv[OPTIND], imgtype,
ssize);
if (img == nullptr) {
tsk_error_print(stderr);
exit(1);
}
if ((imgaddr * img->sector_size) >= img->size) {
tsk_fprintf(stderr,
"Sector offset supplied is larger than disk image (maximum: %"
PRIu64 ")\n", img->size / img->sector_size);
exit(1);
}
const auto pool = tsk_pool_open_img_sing(img, imgaddr * img->sector_size, pooltype);
if (pool == nullptr) {
tsk_error_print(stderr);
if (tsk_error_get_errno() == TSK_ERR_FS_UNSUPTYPE)
tsk_pool_type_print(stderr);
tsk_img_close(img);
exit(1);
}
if (type) {
tsk_printf("%s\n", tsk_pool_type_toname(pool->ctype));
}
else {
if (pool->poolstat(pool, stdout)) {
tsk_error_print(stderr);
tsk_pool_close(pool);
tsk_img_close(img);
exit(1);
}
}
tsk_pool_close(pool);
tsk_img_close(img);
exit(0);
}
|