summaryrefslogtreecommitdiff
path: root/msodumper/ole2previewrecord.py
blob: 39016d96d6a8f62e8c937b9f1a758fa137072953 (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
#!/usr/bin/env python3
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from . import globals
from .binarystream import BinaryStream


class Ole2PreviewStream(BinaryStream):
    def __init__(self, bytes):
        BinaryStream.__init__(self, bytes)

    def dump(self):
        print('<stream type="Ole2Preview" size="%d">' % self.size)

        ansiClipboardFormat = ClipboardFormatOrAnsiString(self, "AnsiClipboardFormat")
        ansiClipboardFormat.dump()
        self.printAndSet("TargetDeviceSize", self.readuInt32())
        if self.TargetDeviceSize == 0x00000004:
            # TargetDevice is not present
            pass
        else:
            print('<todo what="TargetDeviceSize != 0x00000004"/>')
        self.printAndSet("Aspect", self.readuInt32())
        self.printAndSet("Lindex", self.readuInt32())
        self.printAndSet("Advf", self.readuInt32())
        self.printAndSet("Reserved1", self.readuInt32())
        self.printAndSet("Width", self.readuInt32(), hexdump=False)
        self.printAndSet("Height", self.readuInt32(), hexdump=False)
        self.printAndSet("Size", self.readuInt32(), hexdump=False)
        print('<Data offset="%s" size="%s"/>' % (self.pos, self.Size))

        print('</stream>')


class Record(BinaryStream):
    def __init__(self, parent):
        BinaryStream.__init__(self, parent.bytes)
        self.parent = parent
        self.pos = parent.pos


class ClipboardFormatOrAnsiString(Record):
    def __init__(self, parent, name):
        Record.__init__(self, parent)
        self.parent = parent
        self.pos = parent.pos
        self.name = name

    def dump(self):
        print('<%s type="ClipboardFormatOrAnsiString">' % self.name)

        self.printAndSet("MarkerOrLength", self.readuInt32())
        if self.MarkerOrLength == 0xffffffff:
            self.printAndSet("FormatOrAnsiLength", self.readuInt32(), dict=ClipboardFormats)
        else:
            print('<todo what="MarkerOrLength != 0xffffffff"/>')

        print('</%s>' % self.name)
        self.parent.pos = self.pos


ClipboardFormats = {
    0x00000002: "CF_BITMAP",
    0x00000003: "CF_METAFILEPICT",
    0x00000008: "CF_DIB",
    0x0000000E: "CF_ENHMETAFILE",
}

# vim:set filetype=python shiftwidth=4 softtabstop=4 expandtab: