0
|
1 |
#!/usr/bin/env python
|
|
2 |
# -*- coding: utf-8 -*-
|
|
3 |
|
|
4 |
##############################################################################
|
|
5 |
# cmd_infoe32.py - Ensymble command line tool, infoe32 command
|
|
6 |
# Copyright 2006, 2007, 2008, 2009 Jussi Ylänen
|
|
7 |
#
|
|
8 |
# This file is part of Ensymble developer utilities for Symbian OS(TM).
|
|
9 |
#
|
|
10 |
# Ensymble is free software; you can redistribute it and/or modify
|
|
11 |
# it under the terms of the GNU General Public License as published by
|
|
12 |
# the Free Software Foundation; either version 2 of the License, or
|
|
13 |
# (at your option) any later version.
|
|
14 |
#
|
|
15 |
# Ensymble is distributed in the hope that it will be useful,
|
|
16 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 |
# GNU General Public License for more details.
|
|
19 |
#
|
|
20 |
# You should have received a copy of the GNU General Public License
|
|
21 |
# along with Ensymble; if not, write to the Free Software
|
|
22 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
23 |
##############################################################################
|
|
24 |
|
|
25 |
import sys
|
|
26 |
import os
|
|
27 |
import getopt
|
|
28 |
import locale
|
|
29 |
import struct
|
|
30 |
|
|
31 |
import symbianutil
|
|
32 |
|
|
33 |
|
|
34 |
##############################################################################
|
|
35 |
# Help texts
|
|
36 |
##############################################################################
|
|
37 |
|
|
38 |
shorthelp = 'Show the IDs and capabilities of e32image files (EXEs, DLLs)'
|
|
39 |
longhelp = '''infoe32
|
|
40 |
[--encoding=terminal,filesystem] [--verbose]
|
|
41 |
<infile>...
|
|
42 |
|
|
43 |
Show the IDs and capabilities of e32image files (Symbian OS EXEs and DLLs).
|
|
44 |
|
|
45 |
Options:
|
|
46 |
infile - Path of the e32image file/files
|
|
47 |
encoding - Local character encodings for terminal and filesystem
|
|
48 |
verbose - Not used
|
|
49 |
'''
|
|
50 |
|
|
51 |
|
|
52 |
##############################################################################
|
|
53 |
# Parameters
|
|
54 |
##############################################################################
|
|
55 |
|
|
56 |
MAXE32FILESIZE = 1024 * 1024 * 8 # Eight megabytes
|
|
57 |
|
|
58 |
|
|
59 |
##############################################################################
|
|
60 |
# Global variables
|
|
61 |
##############################################################################
|
|
62 |
|
|
63 |
debug = False
|
|
64 |
|
|
65 |
|
|
66 |
##############################################################################
|
|
67 |
# Public module-level functions
|
|
68 |
##############################################################################
|
|
69 |
|
|
70 |
def run(pgmname, argv):
|
|
71 |
global debug
|
|
72 |
|
|
73 |
# Determine system character encodings.
|
|
74 |
try:
|
|
75 |
# getdefaultlocale() may sometimes return None.
|
|
76 |
# Fall back to ASCII encoding in that case.
|
|
77 |
terminalenc = locale.getdefaultlocale()[1] + ""
|
|
78 |
except TypeError:
|
|
79 |
# Invalid locale, fall back to ASCII terminal encoding.
|
|
80 |
terminalenc = "ascii"
|
|
81 |
|
|
82 |
try:
|
|
83 |
# sys.getfilesystemencoding() was introduced in Python v2.3 and
|
|
84 |
# it can sometimes return None. Fall back to ASCII if something
|
|
85 |
# goes wrong.
|
|
86 |
filesystemenc = sys.getfilesystemencoding() + ""
|
|
87 |
except (AttributeError, TypeError):
|
|
88 |
filesystemenc = "ascii"
|
|
89 |
|
|
90 |
try:
|
|
91 |
gopt = getopt.gnu_getopt
|
|
92 |
except:
|
|
93 |
# Python <v2.3, GNU-style parameter ordering not supported.
|
|
94 |
gopt = getopt.getopt
|
|
95 |
|
|
96 |
short_opts = "e:vh"
|
|
97 |
long_opts = [
|
|
98 |
"encoding=", "verbose", "debug", "help"
|
|
99 |
]
|
|
100 |
args = gopt(argv, short_opts, long_opts)
|
|
101 |
|
|
102 |
opts = dict(args[0])
|
|
103 |
pargs = args[1]
|
|
104 |
|
|
105 |
if len(pargs) == 0:
|
|
106 |
raise ValueError("no e32image file name given")
|
|
107 |
|
|
108 |
# Override character encoding of command line and filesystem.
|
|
109 |
encs = opts.get("--encoding", opts.get("-e", "%s,%s" % (terminalenc,
|
|
110 |
filesystemenc)))
|
|
111 |
try:
|
|
112 |
terminalenc, filesystemenc = encs.split(",")
|
|
113 |
except (ValueError, TypeError):
|
|
114 |
raise ValueError("invalid encoding string '%s'" % encs)
|
|
115 |
|
|
116 |
# Determine e32image file name(s).
|
|
117 |
files = [name.decode(terminalenc).encode(filesystemenc) for name in pargs]
|
|
118 |
|
|
119 |
# Determine verbosity.
|
|
120 |
verbose = False
|
|
121 |
if "--verbose" in opts.keys() or "-v" in opts.keys():
|
|
122 |
verbose = True
|
|
123 |
|
|
124 |
# Determine if debug output is requested.
|
|
125 |
if "--debug" in opts.keys():
|
|
126 |
debug = True
|
|
127 |
|
|
128 |
# Ingredients for successful e32image inspection:
|
|
129 |
#
|
|
130 |
# terminalenc Terminal character encoding (autodetected)
|
|
131 |
# filesystemenc File system name encoding (autodetected)
|
|
132 |
# files File names of e32image files, filesystemenc encoded
|
|
133 |
# verbose Boolean indicating verbose terminal output (no-op)
|
|
134 |
|
|
135 |
for infile in files:
|
|
136 |
# Read input e32image file.
|
|
137 |
f = file(infile, "rb")
|
|
138 |
instring = f.read(MAXE32FILESIZE + 1)
|
|
139 |
f.close()
|
|
140 |
|
|
141 |
if len(instring) > MAXE32FILESIZE:
|
|
142 |
raise ValueError("input e32image file too large")
|
|
143 |
|
|
144 |
# Get info about the e32image
|
|
145 |
try:
|
|
146 |
(uid1, uid2, uid3,
|
|
147 |
sid, vid, capmask) = symbianutil.e32imageinfo(instring)
|
|
148 |
caps = symbianutil.capmasktostring(capmask, True)
|
|
149 |
|
|
150 |
print "%s:" % infile
|
|
151 |
print " UID1 0x%08x" % uid1
|
|
152 |
print " UID2 0x%08x" % uid2
|
|
153 |
print " UID3 0x%08x" % uid3
|
|
154 |
print " Secure ID 0x%08x" % sid
|
|
155 |
print " Vendor ID 0x%08x" % vid
|
|
156 |
print " Capabilities 0x%x (%s)" % (capmask, caps)
|
|
157 |
except ValueError:
|
|
158 |
raise ValueError("%s: not a valid e32image file" % infile)
|