3 from struct
import unpack
12 def __init__ (self
, file, pos
):
16 buf
= file.read (0x70)
17 D
= unpack ("<28I", buf
)
19 if not buf
[0:4] in ["xff\x00", "xff2"]:
20 xfferr ("%08x: invalid primary signature %s %x" % (pos
, buf
[0:4], D
[0]))
23 xfferr ("%08x: expected zero got %#x" % (pos
+ 4, D
[1]))
26 xfferr ("%08x: expected zero got %#x" % (pos
+ 4, D
[2]))
47 self
.off_50_count_1C
= D
[20]
48 self
.off_symbols1
= D
[21]
49 self
.off_symstrtab
= D
[22]
50 self
.off_sections
= D
[23]
51 self
.off_symbols2
= D
[24]
52 self
.off_64_count_38
= D
[25]
53 self
.off_secnameoffs
= D
[26]
54 self
.off_secstrtab
= D
[27]
57 file.seek (self
.off_50_count_1C
+ self
.pos
)
58 self
.data_50_count_1C
= file.read (self
.count_1C
* 4)
61 file.seek (self
.off_symbols1
+ self
.pos
)
62 buf
= file.read (self
.symcount
*4*4)
63 L
= unpack ("<%dI" % (self
.symcount
*4), buf
)
65 file.seek (self
.off_symbols2
+ self
.pos
)
66 buf
= file.read (self
.symcount
*4)
67 LL
= unpack ("<%dI" % self
.symcount
, buf
)
71 for i
in range (self
.symcount
):
73 maxoff
= max (maxoff
, Ls
[0])
74 symbols
.append (Ls
+ (LL
[i
],))
76 file.seek (self
.off_symstrtab
+ self
.pos
)
77 symstrtab
= file.read (maxoff
+ 512)
81 s
= symstrtab
[sym
[0]:]
82 name
= s
[:s
.find ("\x00")]
83 self
.symbols
.append ((name
, sym
[0], sym
[1], sym
[2], sym
[3]))
86 file.seek (self
.off_64_count_38
+ self
.pos
)
87 buf
= file.read (self
.count_38
* 7 * 4)
89 for i
in range (self
.count_38
):
90 L
= unpack ("<7I", buf
[i
*7*4:(i
+1)*7*4])
91 self
.hdr5_data
.append (L
)
94 file.seek (self
.off_secnameoffs
+ self
.pos
)
95 buf
= file.read (self
.seccount
* 4)
96 offs
= unpack ("<%dI" % self
.seccount
, buf
)
99 file.seek (self
.off_secstrtab
+ self
.pos
)
100 secstrtab
= file.read (maxoff
+ 512)
102 if self
.off_secnameoffs
+ self
.seccount
* 4 <> self
.off_sections
:
103 raise "Oh fuck", self
.off_secnameoffs
+ self
.seccount
* 4, self
.off_sections
105 file.seek (self
.off_sections
+ self
.pos
)
106 buf
= file.read (self
.seccount
* 8 * 4)
107 L
= unpack ("<%dI" % (self
.seccount
*8), buf
)
110 for i
in range (self
.seccount
):
112 # L5Cs = L5C[i*8:(i+1)*8]
113 s
= secstrtab
[offs
[i
]:]
114 name
= s
[:s
.find ("\x00")]
115 self
.sections
.append ((name
, Ls
))
117 def extr(self
, file, sectnr
, path
):
118 f
= open (path
, "wb")
119 sect
= self
.sections
[sectnr
]
120 file.seek (sect
[1][7])
121 buf
= file.read (sect
[1][2])
126 print "count_0C = %d (some kind of section count)" % self
.count_0C
127 print "xxxxx_10 = %08x" % self
.xxxxx_10
128 print "xff_size = %d" % self
.xff_size
129 print "xxxxx_18 = %08x" % self
.xxxxx_18
130 print "count_1C = %d" % self
.count_1C
131 print "xxxxx_20 = %08x" % self
.xxxxx_20
132 print "symcount = %d" % self
.symcount
133 print "xxxxx_28 = %08x" % self
.xxxxx_28
134 print "xxxxx_2C = %08x" % self
.xxxxx_2C
135 print "xxxxx_30 = %08x" % self
.xxxxx_30
136 print "xxxxx_34 = %08x" % self
.xxxxx_34
137 print "count_38 = %d" % self
.count_38
138 print "xxxxx_3C = %08x" % self
.xxxxx_3C
139 print "seccount = %d" % self
.seccount
140 print "xxxxx_44 = %08x" % self
.xxxxx_44
141 print "xxxxx_48 = %08x" % self
.xxxxx_48
144 print "off_sign = %08x %d" % (self
.off_sign
, self
.off_sign
)
145 print "50_count_1C = %08x" % self
.off_50_count_1C
146 print "symbols1 = %08x" % self
.off_symbols1
147 print "symstrtab = %08x" % self
.off_symstrtab
148 print "sections = %08x" % self
.off_sections
149 print "symbols2 = %08x" % self
.off_symbols2
150 print "64_count_38 = %08x" % self
.off_64_count_38
151 print "secnameoffs = %08x" % self
.off_secnameoffs
152 print "secstrtab = %08x" % self
.off_secstrtab
157 for sym
in self
.symbols
:
158 print " [%d] %s" % (i
, sym
[0])
159 print " %08x" % sym
[1]
160 print " %08x" % sym
[2]
161 print " %08x" % sym
[3]
162 print " %08x" % sym
[4]
167 x
= unpack (("<%dI" % self
.count_1C
), self
.data_50_count_1C
)
168 for i
in range (self
.count_1C
):
169 print " [%5d] %08x %d" % (i
, x
[i
], x
[i
])
174 for x
in self
.hdr5_data
:
182 for sec
in self
.sections
:
183 print " [%d] %s" % (i
, sec
[0])
186 print " %08x %d size" % (sec
[1][j
], sec
[1][j
])
188 print " %08x (%08x)" % (sec
[1][j
], sec
[1][j
] + self
.off_sign
)
190 print " %08x" % sec
[1][j
]
193 if __name__
== "__main__":
194 f
= open (sys
.argv
[1], "rb")
196 x
= XFF (f
, 0*0x3fff3edb)
198 ## x.extr (f, 4, "vutext")
201 ##s = f.read (0x73e-0x4e2-1)
202 ##print len (s.split ("\x00"))
205 ##s = f.read (0x00431742-0x430a50-1)
206 ##print len (s.split ("\x00"))