2 """ Dump data about a Metrowerks object file.
4 Based on reverse-engineering the library file format, since the docs are
7 Copyright (C) 1997 Chris Herborth (chrish@qnx.com)
10 # ----------------------------------------------------------------------
12 import sys
, getopt
, string
, time
14 # ----------------------------------------------------------------------
16 from dumpar
import mk_long
, str2hex
, print_offset
, get_string
18 # ----------------------------------------------------------------------
20 """ convert a 2-byte string into a number
25 raise ValueError, "str must be 2 bytes long"
28 num
= num
+ ord( str[0] ) * 0x100
32 # ----------------------------------------------------------------------
34 """ Display a usage message and exit.
36 print "dumpo [-v] object1 [object2 ... objectn]"
38 print "Attempt to display some useful information about the contents"
39 print "of the given Metrowerks object file(s)."
41 print "-v Be verbose (displays offsets along with the data)"
44 # ----------------------------------------------------------------------
45 def dump_o( file, verbose
):
46 """ dump information about a Metrowerks object file
48 Note that there is more info there, 6 more quads before the file name.
52 print "Dumping object:", file
54 # Attempt to read the data.
56 data
= open( file ).read()
57 except IOError, retval
:
58 print "*** Unable to open file %s: %s" % ( file, retval
[1] )
61 # Check the magic number.
63 print_offset( offset
)
65 magic
= data
[offset
:offset
+ 8]
66 print "'%s'" % ( magic
)
67 if magic
!= "MWOBPPC ":
68 print "*** Invalid magic number!"
75 print_offset( offset
)
76 print "version:", mk_long( data
[offset
:offset
+ 4] )
81 print_offset( offset
)
82 print "flags:", str2hex( data
[offset
:offset
+ 4] )
87 print_offset( offset
)
88 print "code size:", mk_long( data
[offset
:offset
+ 4] )
93 print_offset( offset
)
94 print "data size:", mk_long( data
[offset
:offset
+ 4] )
97 # ----------------------------------------------------------------------
102 # Set up some defaults
105 # First, check the command-line arguments
107 opt
, args
= getopt
.getopt( sys
.argv
[1:], "vh?" )
109 print "*** Error parsing command-line options!"
113 if o
[0] == "-h" or o
[0] == "-?":
118 print "*** Unknown command-line option!"
121 # Now we can attempt to dump info about the arguments.
123 dump_o( obj
, be_verbose
)
125 if __name__
== "__main__":