olestream-unwrap.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  OLEUNWRAP_object

Defines

#define OLEUW_ELEMENT_10NATIVE   10
#define OLEUW_ELEMENT_10NATIVE_STRING   "Ole10Native"
#define OLEUW_OK   0
#define OLEUW_STREAM_NOT_DECODED   100

Functions

int OLEUNWRAP_init (struct OLEUNWRAP_object *oleuw)
int OLEUNWRAP_set_debug (struct OLEUNWRAP_object *oleuw, int level)
int OLEUNWRAP_set_verbose (struct OLEUNWRAP_object *oleuw, int level)
int OLEUNWRAP_set_save_unknown_streams (struct OLEUNWRAP_object *oleuw, int level)
int OLEUNWRAP_save_stream (struct OLEUNWRAP_object *oleuw, char *fname, char *decode_path, char *stream, size_t bytes)
int OLEUNWRAP_decode_attachment (struct OLEUNWRAP_object *oleuw, char *stream, size_t stream_size, char *decode_path)
int OLEUNWRAP_decodestream (struct OLEUNWRAP_object *oleuw, char *element_string, char *stream, size_t stream_size, char *decode_path)
int OLEUNWRAP_set_filename_report_fn (struct OLEUNWRAP_object *oleuw, int(*ptr_to_fn)(char *))
int OLEUNWRAP_sanitize_filename (char *fname)


Define Documentation

#define OLEUW_ELEMENT_10NATIVE   10

Definition at line 2 of file olestream-unwrap.h.

#define OLEUW_ELEMENT_10NATIVE_STRING   "Ole10Native"

Definition at line 3 of file olestream-unwrap.h.

Referenced by OLEUNWRAP_decodestream().

#define OLEUW_OK   0

Definition at line 5 of file olestream-unwrap.h.

Referenced by OLEUNWRAP_decode_attachment(), OLEUNWRAP_decodestream(), OLEUNWRAP_init(), OLEUNWRAP_set_debug(), OLEUNWRAP_set_save_unknown_streams(), and OLEUNWRAP_set_verbose().

#define OLEUW_STREAM_NOT_DECODED   100

Definition at line 6 of file olestream-unwrap.h.

Referenced by OLE_decode_stream(), and OLEUNWRAP_decodestream().


Function Documentation

int OLEUNWRAP_decode_attachment ( struct OLEUNWRAP_object oleuw,
char *  stream,
size_t  stream_size,
char *  decode_path 
)

Definition at line 227 of file olestream-unwrap.c.

References OLE10_header::attach_name, OLE10_header::attach_size, OLE10_header::attach_size_1, OLE10_header::attach_start_offset, OLE10_header::data, OLE10_header::data2, OLEUNWRAP_object::debug, DUW, OLEUNWRAP_object::filename_report_fn, FL, OLE10_header::fname_1, OLE10_header::fname_2, FREE, get_4byte_value(), LOGGER_log(), memcpy(), NULL, OLEUNWRAP_sanitize_filename(), OLEUNWRAP_save_stream(), OLEUW_OK, PLD_dprintf(), result, sp(), and OLEUNWRAP_object::verbose.

Referenced by OLEUNWRAP_decodestream().

00228 {
00229         struct OLE10_header oh;
00230         char *sp = stream;
00231         char *data_start_point = stream;
00232         int result = OLEUW_OK;
00233 
00234         /* Get the data size*/
00235         oh.attach_size_1 = (size_t)get_4byte_value( sp );
00236         sp += 4;
00237 
00238         DUW LOGGER_log("%s:%d:OLEUNWRAP_decode_attachment:DEBUG: attachsize = %d, stream length = %d\n", FL, oh.attach_size_1, stream_size );
00239 
00240         oh.attach_start_offset = (stream_size -oh.attach_size_1);
00241         data_start_point = stream +oh.attach_start_offset;
00242 
00243         /*if (oh.attach_start_offset == 4)*/
00244         if (oh.attach_start_offset < 4)
00245         {
00246           /* If we only had the stream byte-lenght in our header*/
00247           /*            then we know we don't have a complex header.*/
00248                 oh.attach_name = PLD_dprintf("unknown-%ld",oh.attach_size_1);
00249                 oh.attach_size = oh.attach_size_1;
00250         } else {
00251 
00252                 DUW LOGGER_log("%s:%d:OLEUNWRAP_decode_attachment:DEBUG: Decoding file information header",FL);
00253                 /* Unknown memory segment*/
00254                 memcpy( oh.data, sp, 2 );
00255                 sp += 2;
00256                 
00257                 /* Full attachment string*/
00258                 oh.attach_name = strdup( sp );
00259                 sp = sp + strlen(oh.attach_name) +1;
00260 
00261                 /* Attachment full path*/
00262                 oh.fname_1 = strdup( sp );
00263                 sp += strlen(oh.fname_1) +1;
00264 
00265                 /* Unknown memory segment*/
00266                 memcpy( oh.data2, sp, 8 );
00267                 sp = sp +8;
00268 
00269                 /* Attachment full path*/
00270                 oh.fname_2 = strdup( sp );
00271                 sp += strlen(oh.fname_2) +1;
00272 
00273                 oh.attach_size = (size_t)get_4byte_value( sp );
00274                 sp += 4;
00275 
00276                 if (oh.attach_size > stream_size) oh.attach_size = stream_size;
00277                 
00278                 data_start_point = sp;
00279         } 
00280 
00281         DUW LOGGER_log("%s:%d:OLEUNWRAP_decode_attachment:DEBUG: Attachment %s:%s:%s size = %d\n",FL, oh.attach_name, oh.fname_1, oh.fname_2, oh.attach_size );
00282 
00283 
00286         OLEUNWRAP_sanitize_filename(oh.attach_name);
00287         OLEUNWRAP_sanitize_filename(oh.fname_1);
00288         OLEUNWRAP_sanitize_filename(oh.fname_2);
00289 
00290         result = OLEUNWRAP_save_stream( oleuw, oh.attach_name, decode_path, data_start_point, oh.attach_size );
00291         if (result == OLEUW_OK)
00292         {
00293                 if (oleuw->debug > 0) LOGGER_log("%s:%d:OLEUNWRAP_decode_attachment:DEBUG: Calling reporter for the filename",FL);
00294                 if ((oleuw->verbose > 0)&&(oleuw->filename_report_fn != NULL))
00295                 {
00296                         oleuw->filename_report_fn(oh.attach_name);
00297                 }
00298                 /* Do call back to reporting function*/
00299         }
00300 
00301         /* Clean up our previously allocated data*/
00302         if (oh.fname_1 != NULL) FREE(oh.fname_1);
00303         if (oh.attach_name != NULL) FREE(oh.attach_name);
00304         if (oh.fname_2 != NULL) FREE(oh.fname_2);
00305         
00306         return OLEUW_OK;
00307 }

Here is the call graph for this function:

Here is the caller graph for this function:

int OLEUNWRAP_decodestream ( struct OLEUNWRAP_object oleuw,
char *  element_string,
char *  stream,
size_t  stream_size,
char *  decode_path 
)

Definition at line 325 of file olestream-unwrap.c.

References OLEUNWRAP_object::debug, LOGGER_log(), NULL, OLEUNWRAP_decode_attachment(), OLEUW_ELEMENT_10NATIVE_STRING, OLEUW_OK, OLEUW_STREAM_NOT_DECODED, and result.

Referenced by OLE_decode_stream().

00326 {
00327         int result = OLEUW_OK;
00328 
00329         if (strstr(element_string, OLEUW_ELEMENT_10NATIVE_STRING) != NULL) 
00330         {
00331                 OLEUNWRAP_decode_attachment( oleuw, stream, stream_size, decode_path );
00332 
00333         } else {
00334                 if (oleuw->debug) LOGGER_log("Unable to decode stream with element string '%s'\n", element_string);
00335                 result = OLEUW_STREAM_NOT_DECODED;
00336         }
00337 
00338         return result;
00339 }

Here is the call graph for this function:

Here is the caller graph for this function:

int OLEUNWRAP_init ( struct OLEUNWRAP_object oleuw  ) 

Definition at line 47 of file olestream-unwrap.c.

References OLEUNWRAP_object::debug, OLEUNWRAP_object::filename_report_fn, NULL, OLEUW_OK, and OLEUNWRAP_object::verbose.

Referenced by OLE_decode_stream().

00048 {
00049         oleuw->debug = 0;
00050         oleuw->verbose = 0;
00051         oleuw->filename_report_fn = NULL;
00052 
00053         return OLEUW_OK;
00054 }

Here is the caller graph for this function:

int OLEUNWRAP_sanitize_filename ( char *  fname  ) 

Definition at line 201 of file olestream-unwrap.c.

Referenced by OLEUNWRAP_decode_attachment().

00202 {
00203                 while (*fname)
00204                 {
00205                         if( !isalnum((int)*fname) && (*fname != '.') ) *fname='_';
00206                         if( (*fname < ' ')||(*fname > '~') ) *fname='_';
00207                         fname++;
00208                 }
00209                 return 0;
00210 }

Here is the caller graph for this function:

int OLEUNWRAP_save_stream ( struct OLEUNWRAP_object oleuw,
char *  fname,
char *  decode_path,
char *  stream,
size_t  bytes 
)

Definition at line 140 of file olestream-unwrap.c.

References DUW, errno, f(), FL, FREE, LOGGER_log(), NULL, PLD_dprintf(), result, and strerror().

Referenced by OLEUNWRAP_decode_attachment().

00141 {
00142         char *full_name;
00143         FILE *f;
00144         int result = 0;
00145 
00146         DUW LOGGER_log("%s:%d:OLEUNWRAP_save_stream:DEBUG: fname=%s, decodepath=%s, size=%ld"
00147                         ,FL
00148                         ,fname
00149                         ,decode_path
00150                         ,bytes
00151                         );
00152 
00153         full_name = PLD_dprintf("%s/%s", decode_path, fname );
00154         if (full_name == NULL)
00155         {
00156                 LOGGER_log("%s:%d:OLEUNWRAP_save_stream:ERROR: Unable to create filename string from '%s' and '%s'",FL,fname,decode_path);
00157                 return -1;
00158         }
00159 
00160         f = fopen(full_name,"wb");
00161         if (f != NULL)
00162         {
00163                 size_t write_count;
00164 
00165                 write_count = fwrite( stream, 1, bytes, f );
00166                 if (write_count != bytes)
00167                 {
00168                         LOGGER_log("%s:%d:OLEUNWRAP_save_stream:WARNING: Only wrote %d of %d bytes to file %s\n",FL, write_count, bytes, full_name );
00169                 }
00170 
00171                 fclose(f);
00172 
00173 
00174         } else {
00175                 LOGGER_log("%s:%d:OLEUNWRAP_save_stream:ERROR: Unable to open %s for writing (%s)\n",FL,full_name, strerror(errno));
00176                 result = -1;
00177         }
00178 
00179         if (full_name) FREE(full_name);
00180 
00181         DUW LOGGER_log("%s:%d:OLEUNWRAP_save_stream:DEBUG: Done saving '%s'",FL, fname);
00182 
00183         return result;
00184 }

Here is the call graph for this function:

Here is the caller graph for this function:

int OLEUNWRAP_set_debug ( struct OLEUNWRAP_object oleuw,
int  level 
)

Definition at line 72 of file olestream-unwrap.c.

References OLEUNWRAP_object::debug, and OLEUW_OK.

Referenced by OLE_decode_stream().

00073 {
00074         oleuw->debug = level;
00075         return OLEUW_OK;
00076 }

Here is the caller graph for this function:

int OLEUNWRAP_set_filename_report_fn ( struct OLEUNWRAP_object oleuw,
int(*)(char *)  ptr_to_fn 
)

Definition at line 358 of file olestream-unwrap.c.

References OLEUNWRAP_object::filename_report_fn.

Referenced by OLE_decode_stream().

00359 {
00360 
00361         oleuw->filename_report_fn = ptr_to_fn;
00362 
00363         return 0;
00364 }

Here is the caller graph for this function:

int OLEUNWRAP_set_save_unknown_streams ( struct OLEUNWRAP_object oleuw,
int  level 
)

Definition at line 116 of file olestream-unwrap.c.

References OLEUW_OK, and OLEUNWRAP_object::save_unknown_streams.

Referenced by OLE_decode_stream().

00117 {
00118         oleuw->save_unknown_streams = level;
00119         return OLEUW_OK;
00120 }

Here is the caller graph for this function:

int OLEUNWRAP_set_verbose ( struct OLEUNWRAP_object oleuw,
int  level 
)

Definition at line 94 of file olestream-unwrap.c.

References OLEUW_OK, and OLEUNWRAP_object::verbose.

Referenced by OLE_decode_stream().

00095 {
00096         oleuw->verbose = level;
00097         return OLEUW_OK;
00098 }

Here is the caller graph for this function:


Generated on Sun Mar 4 15:19:18 2007 for Scilab [trunk] by  doxygen 1.5.1