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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
|
/*
* Shows information obtained from an OLE Compound File
*
* Copyright (C) 2008-2016, Joachim Metz <joachim.metz@gmail.com>
*
* Refer to AUTHORS for acknowledgements.
*
* This software is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software. If not, see <http://www.gnu.org/licenses/>.
*/
#include <common.h>
#include <memory.h>
#include <system_string.h>
#include <types.h>
#include <stdio.h>
#if defined( HAVE_UNISTD_H )
#include <unistd.h>
#endif
#if defined( HAVE_STDLIB_H )
#include <stdlib.h>
#endif
#include "info_handle.h"
#include "olecfoutput.h"
#include "olecftools_libcerror.h"
#include "olecftools_libclocale.h"
#include "olecftools_libcnotify.h"
#include "olecftools_libcsystem.h"
#include "olecftools_libolecf.h"
info_handle_t *olecfinfo_info_handle = NULL;
int olecfinfo_abort = 0;
/* Prints the executable usage information
*/
void usage_fprint(
FILE *stream )
{
if( stream == NULL )
{
return;
}
fprintf( stream, "Use olecfinfo to determine information about an OLE Compound File.\n\n" );
fprintf( stream, "Usage: olecfinfo [ -c codepage ] [ -ahvV ] source\n\n" );
fprintf( stream, "\tsource: the source file\n\n" );
fprintf( stream, "\t-a: shows allocation information\n" );
fprintf( stream, "\t-c: codepage of ASCII strings, options: ascii, windows-874,\n"
"\t windows-932, windows-936, windows-949, windows-950,\n"
"\t windows-1250, windows-1251, windows-1252 (default),\n"
"\t windows-1253, windows-1254, windows-1255, windows-1256,\n"
"\t windows-1257 or windows-1258\n" );
fprintf( stream, "\t-h: shows this help\n" );
fprintf( stream, "\t-v: verbose output to stderr\n" );
fprintf( stream, "\t-V: print version\n" );
}
/* Signal handler for olecfinfo
*/
void olecfinfo_signal_handler(
libcsystem_signal_t signal LIBCSYSTEM_ATTRIBUTE_UNUSED )
{
libcerror_error_t *error = NULL;
static char *function = "olecfinfo_signal_handler";
LIBCSYSTEM_UNREFERENCED_PARAMETER( signal )
olecfinfo_abort = 1;
if( olecfinfo_info_handle != NULL )
{
if( info_handle_signal_abort(
olecfinfo_info_handle,
&error ) != 1 )
{
libcnotify_printf(
"%s: unable to signal info handle to abort.\n",
function );
libcnotify_print_error_backtrace(
error );
libcerror_error_free(
&error );
}
}
/* Force stdin to close otherwise any function reading it will remain blocked
*/
if( libcsystem_file_io_close(
0 ) != 0 )
{
libcnotify_printf(
"%s: unable to close stdin.\n",
function );
}
}
/* The main program
*/
#if defined( HAVE_WIDE_SYSTEM_CHARACTER )
int wmain( int argc, wchar_t * const argv[] )
#else
int main( int argc, char * const argv[] )
#endif
{
libcerror_error_t *error = NULL;
system_character_t *option_ascii_codepage = NULL;
system_character_t *source = NULL;
char *program = "olecfinfo";
system_integer_t option = 0;
uint8_t show_allocation_information = 0;
int result = 0;
int verbose = 0;
libcnotify_stream_set(
stderr,
NULL );
libcnotify_verbose_set(
1 );
if( libclocale_initialize(
"olecftools",
&error ) != 1 )
{
fprintf(
stderr,
"Unable to initialize locale values.\n" );
goto on_error;
}
if( libcsystem_initialize(
_IONBF,
&error ) != 1 )
{
fprintf(
stderr,
"Unable to initialize system values.\n" );
goto on_error;
}
olecfoutput_version_fprint(
stdout,
program );
while( ( option = libcsystem_getopt(
argc,
argv,
_SYSTEM_STRING( "ac:hvV" ) ) ) != (system_integer_t) -1 )
{
switch( option )
{
case (system_integer_t) '?':
default:
fprintf(
stderr,
"Invalid argument: %" PRIs_SYSTEM "\n",
argv[ optind - 1 ] );
usage_fprint(
stdout );
return( EXIT_FAILURE );
case (system_integer_t) 'a':
show_allocation_information = 1;
break;
case (system_integer_t) 'c':
option_ascii_codepage = optarg;
break;
case (system_integer_t) 'h':
usage_fprint(
stdout );
return( EXIT_SUCCESS );
case (system_integer_t) 'v':
verbose = 1;
break;
case (system_integer_t) 'V':
olecfoutput_copyright_fprint(
stdout );
return( EXIT_SUCCESS );
}
}
if( optind == argc )
{
fprintf(
stderr,
"Missing source file.\n" );
usage_fprint(
stdout );
return( EXIT_FAILURE );
}
source = argv[ optind ];
libcnotify_verbose_set(
verbose );
libolecf_notify_set_stream(
stderr,
NULL );
libolecf_notify_set_verbose(
verbose );
if( info_handle_initialize(
&olecfinfo_info_handle,
&error ) != 1 )
{
fprintf(
stderr,
"Unable to initialize info handle.\n" );
goto on_error;
}
if( option_ascii_codepage != NULL )
{
result = info_handle_set_ascii_codepage(
olecfinfo_info_handle,
option_ascii_codepage,
&error );
if( result == -1 )
{
fprintf(
stderr,
"Unable to set ASCII codepage in info handle.\n" );
goto on_error;
}
else if( result == 0 )
{
fprintf(
stderr,
"Unsupported ASCII codepage defaulting to: windows-1252.\n" );
}
}
if( info_handle_open_input(
olecfinfo_info_handle,
source,
&error ) != 1 )
{
fprintf(
stderr,
"Unable to open: %" PRIs_SYSTEM ".\n",
source );
goto on_error;
}
if( info_handle_file_fprint(
olecfinfo_info_handle,
&error ) != 1 )
{
fprintf(
stderr,
"Unable to print file information.\n" );
goto on_error;
}
if( info_handle_items_fprint(
olecfinfo_info_handle,
&error ) != 1 )
{
fprintf(
stderr,
"Unable to print file stream and storage items.\n" );
goto on_error;
}
if( show_allocation_information != 0 )
{
if( info_handle_unallocated_blocks_fprint(
olecfinfo_info_handle,
&error ) != 1 )
{
fprintf(
stderr,
"Unable to print file unallocated blocks.\n" );
goto on_error;
}
}
if( info_handle_summary_information_fprint(
olecfinfo_info_handle,
&error ) != 1 )
{
fprintf(
stderr,
"Unable to print summary information.\n" );
goto on_error;
}
if( info_handle_document_summary_information_fprint(
olecfinfo_info_handle,
&error ) != 1 )
{
fprintf(
stderr,
"Unable to print document summary information.\n" );
goto on_error;
}
if( info_handle_close(
olecfinfo_info_handle,
&error ) != 0 )
{
fprintf(
stderr,
"Unable to close info handle.\n" );
goto on_error;
}
if( info_handle_free(
&olecfinfo_info_handle,
&error ) != 1 )
{
fprintf(
stderr,
"Unable to free info handle.\n" );
goto on_error;
}
return( EXIT_SUCCESS );
on_error:
if( error != NULL )
{
libcnotify_print_error_backtrace(
error );
libcerror_error_free(
&error );
}
if( olecfinfo_info_handle != NULL )
{
info_handle_close(
olecfinfo_info_handle,
NULL );
info_handle_free(
&olecfinfo_info_handle,
NULL );
}
return( EXIT_FAILURE );
}
|