summaryrefslogtreecommitdiff
path: root/plugins/python/androperms/reader.py
blob: f126850f45a10649dc323d430619354ef158f729 (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
#!/usr/bin/python -u
# -*- coding: utf-8 -*-


from struct import unpack


class AXMLReader():
    """Provide various read helpers."""

    def __init__(self, data):

        self._data = data

        self._position = 0
        self._length = len(self._data)


    def readInt(self):
        """Read a 4-bytes value."""

        self.skipInt()

        value = unpack('<L', self._data[self._position - 4 : self._position])[0]

        return value


    def skipInt(self):
        """Skip a 4-bytes value."""

        self._position += 4

        if self._position > self._length:
            raise Exception("Reader out of bound (%d > %d)!" % (self._position, self._length))


    def readIntArray(self, length):
        """Read an array composed of 4-bytes values."""

        return [ self.readInt() for i in range(0, length) ]