This file is indexed.

/usr/share/pyshared/ensymble/actions/altere32.py is in ensymble 0.29-1ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#!/usr/bin/env python
# -*- coding: utf-8 -*-

##############################################################################
# cmd_signsis.py - Ensymble command line tool, altere32 command
# Copyright 2006, 2007, 2008 Jussi Ylänen
#
# This file is part of Ensymble developer utilities for Symbian OS(TM).
#
# Ensymble 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.
#
# Ensymble 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 Ensymble; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
##############################################################################

import sys
import os
import getopt
import locale
import struct

from utils import symbianutil


##############################################################################
# Help texts
##############################################################################

shorthelp = 'Alter the IDs and capabilities of e32image files (EXEs, DLLs)'
longhelp  = '''altere32
    [--uid=0x01234567] [--secureid=0x01234567] [--vendorid=0x01234567]
    [--caps=Cap1+Cap2+...] [--heapsize=min,max] [--inplace]
    [--encoding=terminal,filesystem] [--verbose]
    <infile> [outfile]

Alter the IDs, capabilities and heap sizes of e32image files (Symbian OS
EXEs and DLLs).

Options:
    infile      - Path of the original e32image file (or many, if --inplace set)
    outfile     - Path of the modified e32image file (not used with --inplace)
    uid         - Symbian OS UID for the e32image
    secureid    - Secure ID for the e32image (should normally be same as UID)
    vendorid    - Vendor ID for the e32image
    caps        - Capability names, separated by "+"
    heapsize    - Heap size, minimum and/or maximum (not altered by default)
    inplace     - Allow more than one input file, modify input files in-place
    encoding    - Local character encodings for terminal and filesystem
    verbose     - Print extra statistics

When modifying the UID, the secure ID should be modified accordingly.
Modifying UIDs of application EXEs is generally not possible, because
applications usually include the UID in program code as well.
'''


##############################################################################
# Parameters
##############################################################################

MAXE32FILESIZE  = 1024 * 1024 * 8   # Eight megabytes


##############################################################################
# Global variables
##############################################################################

debug = False


##############################################################################
# Public module-level functions
##############################################################################

def run(pgmname, argv):
    global debug

    # Determine system character encodings.
    try:
        # getdefaultlocale() may sometimes return None.
        # Fall back to ASCII encoding in that case.
        terminalenc = locale.getdefaultlocale()[1] + ""
    except TypeError:
        # Invalid locale, fall back to ASCII terminal encoding.
        terminalenc = "ascii"

    try:
        # sys.getfilesystemencoding() was introduced in Python v2.3 and
        # it can sometimes return None. Fall back to ASCII if something
        # goes wrong.
        filesystemenc = sys.getfilesystemencoding() + ""
    except (AttributeError, TypeError):
        filesystemenc = "ascii"

    try:
        gopt = getopt.gnu_getopt
    except:
        # Python <v2.3, GNU-style parameter ordering not supported.
        gopt = getopt.getopt

    # Parse command line arguments.
    short_opts = "u:s:r:b:H:ie:vh"
    long_opts = [
        "uid=", "secureid=", "vendorid=", "caps=", "heapsize=",
        "inplace", "encoding=", "verbose", "debug", "help"
    ]
    args = gopt(argv, short_opts, long_opts)

    opts = dict(args[0])
    pargs = args[1]

    if len(pargs) == 0:
        raise ValueError("no input e32image file name given")

    # Override character encoding of command line and filesystem.
    encs = opts.get("--encoding", opts.get("-e", "%s,%s" % (terminalenc,
                                                            filesystemenc)))
    try:
        terminalenc, filesystemenc = encs.split(",")
    except (ValueError, TypeError):
        raise ValueError("invalid encoding string '%s'" % encs)

    # Get UID3.
    uid3 = opts.get("--uid", opts.get("-u", None))
    if uid3 != None:
        uid3 = parseuid(pgmname, uid3)

    # Get secure ID.
    secureid = opts.get("--secureid", opts.get("-s", None))
    if secureid != None:
        secureid = parseuid(pgmname, secureid)

    # Get vendor ID.
    vendorid = opts.get("--vendorid", opts.get("-r", None))
    if vendorid != None:
        vendorid = parseuid(pgmname, vendorid)

    # Get capabilities and normalize the names.
    caps = opts.get("--caps", opts.get("-b", None))
    if caps != None:
        capmask = symbianutil.capstringtomask(caps)
        caps = symbianutil.capmasktostring(capmask, True)
    else:
        capmask = None

    # Get heap sizes.
    heapsize = opts.get("--heapsize", opts.get("-H", None))
    if heapsize != None:
        try:
            heapsize = heapsize.split(",", 1)
            heapsizemin = symbianutil.parseintmagnitude(heapsize[0])
            if len(heapsize) == 1:
                # Only one size given, use it as both.
                heapsizemax = heapsizemin
            else:
                heapsizemax = symbianutil.parseintmagnitude(heapsize[1])
        except (ValueError, TypeError, IndexError):
            raise ValueError("%s: invalid heap size, one or two values expected"
                             % ",".join(heapsize))

        # Warn if the minimum heap size is larger than the maximum heap size.
        # Resulting e32image file will probably prevent any SIS from installing.
        if heapsizemin > heapsizemax:
            print ("%s: warning: minimum heap size larger than "
                   "maximum heap size" % pgmname)
    else:
        heapsizemin = None
        heapsizemax = None

    # Determine parameter format. Modifying files in-place or not.
    inplace = False
    if "--inplace" in opts.keys() or "-i" in opts.keys():
        inplace = True

    # Determine e32image input / output file names.
    files = [name.decode(terminalenc).encode(filesystemenc) for name in pargs]
    if not inplace:
        if len(files) == 2:
            if os.path.isdir(files[1]):
                # Output to directory, use input file name.
                files[1] = os.path.join(files[1], os.path.basename(files[0]))
        else:
            raise ValueError("wrong number of arguments")

    # Determine verbosity.
    verbose = False
    if "--verbose" in opts.keys() or "-v" in opts.keys():
        verbose = True

    # Determine if debug output is requested.
    if "--debug" in opts.keys():
        debug = True

    # Ingredients for successful e32image file alteration:
    #
    # terminalenc      Terminal character encoding (autodetected)
    # filesystemenc    File system name encoding (autodetected)
    # files            File names of e32image files, filesystemenc encoded
    # uid3             Application UID3, long integer or None
    # secureid         Secure ID, long integer or None
    # vendorid         Vendor ID, long integer or None
    # caps, capmask    Capability names and bitmask or None
    # heapsizemin      Heap that must be available for the app. to start or None
    # heapsizemax      Maximum amount of heap the app. can allocate or None
    # inplace          Multiple input files or single input / output pair
    # verbose          Boolean indicating verbose terminal output

    if verbose:
        print
        if not inplace:
            print "Input e32image file      %s"        % (
                files[0].decode(filesystemenc).encode(terminalenc))
            print "Output e32image file     %s"        % (
                files[1].decode(filesystemenc).encode(terminalenc))
        else:
            print "Input e32image file(s)   %s"        % " ".join(
                [f.decode(filesystemenc).encode(terminalenc) for f in files])
        if uid3 != None:
            print "UID                      0x%08x" % uid3
        else:
            print "UID                      <not set>"
        if secureid != None:
            print "Secure ID                0x%08x" % secureid
        else:
            print "Secure ID                <not set>"
        if vendorid != None:
            print "Vendor ID                0x%08x" % vendorid
        else:
            print "Vendor ID                <not set>"
        if caps != None:
            print "Capabilities             0x%x (%s)" % (capmask, caps)
        else:
            print "Capabilities             <not set>"
        if heapsizemin != None:
            print "Heap size in bytes       %d, %d" % (heapsizemin, heapsizemax)
        else:
            print "Heap size in bytes       <not set>"
        print

    if ((uid3, secureid, vendorid, caps, heapsizemin) ==
        (None, None, None, None, None)):
        print "%s: no options set, doing nothing" % pgmname
        return

    for infile in files:
        # Read input e32image file.
        f = file(infile, "rb")
        instring = f.read(MAXE32FILESIZE + 1)
        f.close()

        if len(instring) > MAXE32FILESIZE:
            raise ValueError("input e32image file too large")

        # Modify the e32image header.
        try:
            outstring = symbianutil.e32imagecrc(instring, uid3,
                                                secureid, vendorid, heapsizemin,
                                                heapsizemax, capmask)
        except ValueError:
            raise ValueError("%s: not a valid e32image file" % infile)

        if not inplace:
            outfile = files[1]
        else:
            outfile = infile

        # Write output e32image file.
        f = file(outfile, "wb")
        f.write(outstring)
        f.close()

        if not inplace:
            # While --inplace is not in effect, files[1] is the output
            # file name, so must stop after one iteration.
            break


##############################################################################
# Module-level functions which are normally only used by this module
##############################################################################

def parseuid(pgmname, uid):
    if uid.lower().startswith("0x"):
        # Prefer hex UIDs with leading "0x".
        uid = long(uid, 16)
    else:
        try:
            if len(uid) == 8:
                # Assuming hex UID even without leading "0x".
                print ('%s: warning: assuming hex UID even '
                       'without leading "0x"' % pgmname)
                uid = long(uid, 16)
            else:
                # Decimal UID.
                uid = long(uid)
                print ('%s: warning: decimal UID converted to 0x%08x' %
                       (pgmname, uid))
        except ValueError:
            raise ValueError("invalid UID string '%s'" % uid)
    return uid