summaryrefslogtreecommitdiffstats
path: root/tools/msidump.in
blob: 5edab46e0f6b6a073a68134718f608cc321654d7 (plain)
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
#!/bin/bash
# -*- coding: utf-8 -*-

# msidump - dump raw MSI tables and stream content
#
# Copyright (c) 2013 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

set -e

tables=
streams=
signature=
destdir=.

version()
{
    cat <<EOF
@PACKAGE_VERSION@
EOF
}

help()
{
    cat <<EOF
msidump dumps MSI tables as idt text and streams
EOF
    usage
    echo ""
    echo "Report bugs to <@PACKAGE_BUGREPORT@>."
}

usage()
{
    cat <<EOF
Usage: msidump [OPTION]... MSI-FILE

Options:
  -t, --tables         Dump tables.  This is the default.
  -s, --streams        Dump streams
  -S, --signature      Dump asn1parse of digital signature.
  -d, --directory DIR  Dump to given directory DIR
  -h, --help           Print help message and exit.
  -v, --version        Print version information and exit.

More than one of -t, -s or -S may be specified.
EOF
}

while true ; do
    case $1 in
        -t|--tables)
            tables=true
            ;;
        -s|--streams)
            streams=true
            ;;
        -S|--signature)
            signature=true
            ;;
        -d|--directory)
            destdir=$2
            shift
            ;;
        -h|--help)
            help
            exit 0
            ;;
        -v|--version)
            version
            exit 0
            ;;
        *)
            break
            ;;
    esac
    shift
done
if [[ $# -lt 1 ]] ; then
    usage
    exit 1
fi
for file in "$1" ; do
    if [[ ! -f $file ]] ; then
        [[ -e $file ]] && \
            echo "Error: not a regular file: '$file'" >&2 ||
            echo "Error: file does not exist: '$file'" >&2
        exit 1
    fi
done

if [[ ! -d $destdir ]] ; then
    echo "Error: directory does not exist: '$destdir'" >&2
    exit 1
fi

# Tables mode is the default.
if [[ -z $tables$streams$signature ]] ; then
    tables=true
else
    tables=${tables:-false}
fi
streams=${streams:-false}
signature=${signature:-false}


# Here we go

if $tables ; then
    TABLES=$(msiinfo tables "$1")
    for i in $TABLES; do
        echo "Exporting table $i..."
        msiinfo export "$1" "$i" > "$destdir/$i.idt"
    done
fi

if $streams ; then
    mkdir -p "$destdir/_Streams"
    STREAMS=$(msiinfo streams "$1")
    for i in $STREAMS; do
        echo "Exporting stream $i..."
        msiinfo extract "$1" "$i" > "$destdir/_Streams/$i"
    done
fi

if $signature ; then
    signature="$destdir/signature"
    echo "Exporting asn1parsed $signature ..."
    rm -f "$signature"
    (msiinfo extract "$1" $'\005DigitalSignature' 2>/dev/null | openssl asn1parse -i -inform de > "$signature") || true
fi