Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[mms-dump] Added option to dump attachment data
Also, ignore failure to parse part headers. If we know the total size of the
part headers, such a failure doesn't stop us from continuing to parse the rest
of the PDU. The purpose of this tool is not to validate the PDU but to dump as
much information as possible even if PDU is not perfectly valid.
  • Loading branch information
monich committed May 13, 2014
1 parent 1a808b9 commit 4af0f02
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions mms-dump/mms-dump.c
Expand Up @@ -16,6 +16,7 @@
#include <wsputil.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>

static const char pname[] = "mms-dump";

Expand All @@ -27,6 +28,7 @@ enum app_ret_value {
};

#define MMS_DUMP_FLAG_VERBOSE (0x01)
#define MMS_DUMP_FLAG_DATA (0x02)

#define WSP_QUOTE (127)

Expand Down Expand Up @@ -961,6 +963,41 @@ mms_part_decode_headers(
mms_part_value_decoder_for_header);
}

static
void
mms_decode_dump_data(
const unsigned char* data,
unsigned int len)
{
const unsigned int linelen = 16;
unsigned int i;
char line[80];
for (i=0; i<len; i+=linelen) {
unsigned int j;
char tmp[8];
sprintf(line," %04x: ", (unsigned int)i);
for (j=i; j<(i+linelen); j++) {
if ((j%16) == 8) strcat(line, " ");
if (j < len) {
sprintf(tmp, "%02x ", (unsigned int)data[j]);
strcat(line, tmp);
} else {
strcat(line, " ");
}
}
strcat(line, " ");
for (j=i; j<(i+linelen); j++) {
if (j<len) {
sprintf(tmp, "%c", isprint(data[j]) ? data[j] : '.');
strcat(line, tmp);
} else {
strcat(line, " ");
}
}
printf("%s\n", line);
}
}

static
gboolean
mms_decode_multipart(
Expand Down Expand Up @@ -994,10 +1031,12 @@ mms_decode_multipart(
printf("\n");
wsp_header_iter_init(&hi, wsp_multipart_iter_get_hdr(&mi),
wsp_multipart_iter_get_hdr_len(&mi), 0);
if (mms_part_decode_headers(&hi, " ", flags) &&
wsp_header_iter_at_end(&hi)) {
continue;
mms_part_decode_headers(&hi, " ", flags);
if (flags & MMS_DUMP_FLAG_DATA) {
printf("Data:\n");
mms_decode_dump_data(body, len);
}
if (wsp_header_iter_at_end(&hi)) continue;
}
return FALSE;
}
Expand Down Expand Up @@ -1113,11 +1152,13 @@ mms_decode_file(
int main(int argc, char* argv[])
{
int ret = RET_ERR_CMDLINE;
gboolean ok, verbose = FALSE;
gboolean ok, verbose = FALSE, data = FALSE;
GError* error = NULL;
GOptionEntry entries[] = {
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
"Enable verbose output", NULL },
{ "data", 'd', 0, G_OPTION_ARG_NONE, &data,
"Dump attachment data", NULL },
{ NULL }
};
GOptionContext* options = g_option_context_new("FILES");
Expand All @@ -1127,6 +1168,7 @@ int main(int argc, char* argv[])
if (argc > 1) {
int i, flags = 0;
if (verbose) flags |= MMS_DUMP_FLAG_VERBOSE;
if (data) flags |= MMS_DUMP_FLAG_DATA;
for (i=1; i<argc; i++) {
const char* fname = argv[i];
if (argc > 2) printf("\n%s\n\n", fname);
Expand Down

0 comments on commit 4af0f02

Please sign in to comment.