diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2012-08-03 13:03:26 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2012-08-03 13:03:26 (GMT) |
commit | b7c83221f2a60be8ee5d44a7599dbe6869af005f (patch) | |
tree | 814e294533920d18f8734baa9aaef47c676e520a /plugins/python/androperms/string.py | |
parent | 7d2b7ca95966c2d687526cd75a96d1ea67d3f503 (diff) |
Loaded the permissions used by an APK file.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@255 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'plugins/python/androperms/string.py')
-rw-r--r-- | plugins/python/androperms/string.py | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/plugins/python/androperms/string.py b/plugins/python/androperms/string.py new file mode 100644 index 0000000..09a7b93 --- /dev/null +++ b/plugins/python/androperms/string.py @@ -0,0 +1,82 @@ +#!/usr/bin/python -u +# -*- coding: utf-8 -*- + + +from defs import CHUNK_TYPE + + +class StringBlock(): + + + def __init__(self, reader): + + magic = reader.readInt() + if magic != CHUNK_TYPE: + raise Exception("Bad Magic Number (0x%08lx)!" % magic) + + chunk_size = reader.readInt() + str_count = reader.readInt() + style_offset_count = reader.readInt() + reader.readInt() # ??? + str_offset = reader.readInt() + styles_offset = reader.readInt() + + self._str_offsets = reader.readIntArray(str_count); + self._style_offsets = reader.readIntArray(style_offset_count); + + if styles_offset == 0: + size = chunk_size - str_offset + else: + size = styles_offset - str_offset + + if size % 4 != 0: + raise Exception("String data size is not multiple of 4 (%d)!" % size) + + self._strings = reader.readIntArray(size / 4) + + if styles_offset > 0: + + size = chunk_size - styles_offset + + if size % 4 != 0: + raise Exception("Style data size is not multiple of 4 (%d)!" % size) + + self._styles = reader.readIntArray(size / 4) + + self._str_data = [ self.getRaw(i) for i in range(self.count()) ] + + + def count(self): + """Count the number of strings in the current block.""" + + return len(self._str_offsets) + + + def getRaw(self, index): + """Provide a raw string (without any styling information) at specified index.""" + + if index < 0 or index >= len(self._str_offsets): + raise Exception("Invalid Index (%d)!" % index) + + offset = self._str_offsets[index] + length = self.getShort(self._strings, offset) + + data = '' + + for i in range(length): + offset += 2 + data += unichr(self.getShort(self._strings, offset)) + + return data + + + def getShort(self, array, offset): + + value = array[offset / 4] + + if ((offset % 4) / 2) == 0: + value &= 0xFFFF + else: + value >>= 16 + + return value |