278 | | self.tags = [ self.skipped ] * 256 |
279 | | self.tags[0x27] = lambda: self.debug("%08x : ASCII Binding" % self.infile.tell()) |
280 | | self.tags[0x28] = self.bigendian |
281 | | self.tags[0x29] = self.littleendian |
282 | | |
283 | | self.tags[0x41] = lambda: self.debug("%08x : BeginSession" % self.infile.tell()) |
284 | | self.tags[0x42] = lambda: self.debug("%08x : EndSession" % self.infile.tell()) |
| 283 | # Initialize table of tags |
| 284 | self.tags = [ 0 ] * 256 |
| 285 | |
| 286 | # GhostScript's sources tell us that HP printers |
| 287 | # only accept little endianness, but we can handle both. |
| 288 | self.tags[0x28] = self.bigEndian # BigEndian |
| 289 | self.tags[0x29] = self.littleEndian # LittleEndian |
287 | | self.tags[0x44] = self.endPage # EndPage |
288 | | |
289 | | self.tags[0x47] = lambda: self.debug("%08x : Comment" % self.infile.tell()) |
290 | | self.tags[0x48] = lambda: self.debug("%08x : OpenDataSource" % self.infile.tell()) |
291 | | self.tags[0x49] = lambda: self.debug("%08x : CloseDataSource" % self.infile.tell()) |
292 | | |
293 | | self.tags[0xc0] = lambda: self.debug("%08x : ubyte" % self.infile.tell()) or 1 # ubyte |
294 | | self.tags[0xc1] = lambda: self.debug("%08x : uint16" % self.infile.tell()) or 2 # uint16 |
295 | | self.tags[0xc2] = lambda: self.debug("%08x : uint32" % self.infile.tell()) or 4 # uint32 |
296 | | self.tags[0xc3] = lambda: self.debug("%08x : sint16" % self.infile.tell()) or 2 # sint16 |
297 | | self.tags[0xc4] = lambda: self.debug("%08x : sint32" % self.infile.tell()) or 4 # sint32 |
298 | | self.tags[0xc5] = lambda: self.debug("%08x : real32" % self.infile.tell()) or 4 # real32 |
| 292 | |
| 293 | self.tags[0xc0] = 1 # ubyte |
| 294 | self.tags[0xc1] = 2 # uint16 |
| 295 | self.tags[0xc2] = 4 # uint32 |
| 296 | self.tags[0xc3] = 2 # sint16 |
| 297 | self.tags[0xc4] = 4 # sint32 |
| 298 | self.tags[0xc5] = 4 # real32 |
307 | | self.tags[0xd0] = lambda: self.debug("%08x : ubyte_xy" % self.infile.tell()) or 2 # ubyte_xy |
308 | | self.tags[0xd1] = lambda: self.debug("%08x : uint16_xy" % self.infile.tell()) or 4 # uint16_xy |
309 | | self.tags[0xd2] = lambda: self.debug("%08x : uint32_xy" % self.infile.tell()) or 8 # uint32_xy |
310 | | self.tags[0xd3] = lambda: self.debug("%08x : sint16_xy" % self.infile.tell()) or 4 # sint16_xy |
311 | | self.tags[0xd4] = lambda: self.debug("%08x : sint32_xy" % self.infile.tell()) or 8 # sint32_xy |
312 | | self.tags[0xd5] = lambda: self.debug("%08x : real32_xy" % self.infile.tell()) or 8 # real32_xy |
313 | | |
314 | | self.tags[0xd0] = lambda: self.debug("%08x : ubyte_box" % self.infile.tell()) or 4 # ubyte_box |
315 | | self.tags[0xd1] = lambda: self.debug("%08x : uint16_box" % self.infile.tell()) or 8 # uint16_box |
316 | | self.tags[0xd2] = lambda: self.debug("%08x : uint32_box" % self.infile.tell()) or 16 # uint32_box |
317 | | self.tags[0xd3] = lambda: self.debug("%08x : sint16_box" % self.infile.tell()) or 8 # sint16_box |
318 | | self.tags[0xd4] = lambda: self.debug("%08x : sint32_box" % self.infile.tell()) or 16 # sint32_box |
319 | | self.tags[0xd5] = lambda: self.debug("%08x : real32_box" % self.infile.tell()) or 16 # real32_box |
320 | | |
321 | | self.tags[0xf8] = lambda: self.debug("%08x : attr_ubyte" % self.infile.tell()) or 1 # attr_ubyte |
322 | | self.tags[0xf9] = lambda: self.debug("%08x : attr_uint16" % self.infile.tell()) or 2 # attr_uint16 |
| 307 | self.tags[0xd0] = 2 # ubyte_xy |
| 308 | self.tags[0xd1] = 4 # uint16_xy |
| 309 | self.tags[0xd2] = 8 # uint32_xy |
| 310 | self.tags[0xd3] = 4 # sint16_xy |
| 311 | self.tags[0xd4] = 8 # sint32_xy |
| 312 | self.tags[0xd5] = 8 # real32_xy |
| 313 | |
| 314 | self.tags[0xe0] = 4 # ubyte_box |
| 315 | self.tags[0xe1] = 8 # uint16_box |
| 316 | self.tags[0xe2] = 16 # uint32_box |
| 317 | self.tags[0xe3] = 8 # sint16_box |
| 318 | self.tags[0xe4] = 16 # sint32_box |
| 319 | self.tags[0xe5] = 16 # real32_box |
| 320 | |
| 321 | self.tags[0xf8] = 1 # attr_ubyte |
| 322 | self.tags[0xf9] = 2 # attr_uint16 |
352 | | self.debug("Bogus array length at %s" % pos) |
353 | | else : |
354 | | sarraysize = self.infile.read(length) |
355 | | if self.islittleendian : |
356 | | fmt = "<" |
357 | | else : |
358 | | fmt = ">" |
359 | | if length == 1 : |
360 | | fmt += "B" |
361 | | elif length == 2 : |
362 | | fmt += "H" |
363 | | elif length == 4 : |
364 | | fmt += "I" |
365 | | else : |
366 | | raise PDLAnalyzerError, "Error on array size at %s" % self.infile.tell() |
367 | | arraysize = struct.unpack(fmt, sarraysize)[0] |
368 | | self.debug("itemsize %s * size %s = %s" % (itemsize, arraysize, itemsize*arraysize)) |
369 | | return arraysize * itemsize |
| 338 | raise PDLAnalyzerError, "Error on array length at %s" % self.pos |
| 339 | elif callable(length) : |
| 340 | length = length() |
| 341 | pos = self.pos |
| 342 | posl = pos + length |
| 343 | sarraysize = self.minfile[pos:posl] |
| 344 | self.pos = posl |
| 345 | if self.islittleendian : |
| 346 | fmt = "<" |
| 347 | else : |
| 348 | fmt = ">" |
| 349 | if length == 1 : |
| 350 | fmt += "B" |
| 351 | elif length == 2 : |
| 352 | fmt += "H" |
| 353 | elif length == 4 : |
| 354 | fmt += "I" |
| 355 | else : |
| 356 | raise PDLAnalyzerError, "Error on array size at %s" % self.pos |
| 357 | arraysize = struct.unpack(fmt, sarraysize)[0] |
| 358 | return arraysize * itemsize |
401 | | pos = self.infile.tell() |
402 | | data = self.infile.read(4) |
403 | | val = struct.unpack(fmt, data)[0] |
404 | | if val & 0xff000000 : # tries to detect possible errors when we missed an indianness tag maybe |
405 | | if fmt == "<I" : |
406 | | fmt = ">I" |
407 | | else : |
408 | | fmt = "<I" |
409 | | val = struct.unpack(fmt, data)[0] |
410 | | self.debug("%08x : Large datablock length : 0x%08x" % (self.infile.tell()-4, val)) |
411 | | self.debug("Endian : %i" % self.islittleendian) |
412 | | self.debug("Data read : %s" % str(["0x%02x" % ord(x) for x in data])) |
413 | | return val |
414 | | |
415 | | def littleendian(self) : |
| 384 | pos = self.pos |
| 385 | pos4 = pos + 4 |
| 386 | data = self.minfile[pos:pos4] |
| 387 | self.pos = pos4 |
| 388 | return struct.unpack(fmt, data)[0] |
| 389 | |
| 390 | def littleEndian(self) : |