summaryrefslogtreecommitdiff
path: root/plugins/python/liveconv/panel.py
blob: 644bfa997e0353139521297aab098f0c85d9fd47 (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

import os
from gi.repository import Gtk
from pychrysalide.analysis import LoadedBinary
from pychrysalide.gui import core
from pychrysalide.gui import PanelItem

from .converters import *


class ConvPanel(PanelItem):

    def __init__(self):
        """Initialize the GUI panel."""

        directory = os.path.dirname(os.path.realpath(__file__))

        self._builder = Gtk.Builder()
        self._builder.add_from_file(os.path.join(directory, 'panel.ui'))

        params = {

            'name' : 'Converter',
            'widget' : self._builder.get_object('content'),

            'personality' : PanelItem.PIP_SINGLETON,
            'lname' : 'Data live converter',
            'dock' : True,
            'path' : 'MES'

        }

        super(ConvPanel, self).__init__(**params)

        self._conversions = {

            'int8':   lambda c, a, o: data_to_number(c, a, o, 'b'),
            'uint8':  lambda c, a, o: data_to_number(c, a, o, 'B'),
            'int16':  lambda c, a, o: data_to_number(c, a, o, 'h'),
            'uint16': lambda c, a, o: data_to_number(c, a, o, 'H'),
            'int32':  lambda c, a, o: data_to_number(c, a, o, 'l'),
            'uint32': lambda c, a, o: data_to_number(c, a, o, 'L'),
            'int64':  lambda c, a, o: data_to_number(c, a, o, 'q'),
            'uint64': lambda c, a, o: data_to_number(c, a, o, 'Q'),
            'half_float': lambda c, a, o: data_to_number(c, a, o, 'e'),
            'float':  lambda c, a, o: data_to_number(c, a, o, 'f'),
            'double': lambda c, a, o: data_to_number(c, a, o, 'd'),

            'time':     lambda c, a, o: data_to_time(c, a, o, 'L'),
            'time64':   lambda c, a, o: data_to_time(c, a, o, 'Q'),
            'filetime': data_to_filetime,
            'dostime':  data_to_dos_time,
            'dosdate':  data_to_dos_date,

            'char':  data_to_char,
            'ansi':  data_to_ansi,
            'utf8':  data_to_utf8,
            'utf16': data_to_utf16,

        }

        for kind, func in self._conversions.items():

            label = self._builder.get_object('%s_value' % kind)
            label.set_text('-')

        self._order = '@'


    def _track_cursor(self, source, cursor):
        """Track moves from the current cursor."""

        loaded = core.get_current_content()
        assert(loaded)

        for kind, func in self._conversions.items():

            label = self._builder.get_object('%s_value' % kind)

            try:
                addr = cursor.retrieve()
                label.set_text(func(loaded.content, addr, self._order))

            except Exception as e:
                label.set_text('-')