| 16 | imgmarker=[] |
| 17 | |
| 18 | def main(): |
| 19 | |
| 20 | if len(sys.argv) < 2: |
| 21 | print 'Usage: picdumper <file>\n' |
| 22 | sys.exit(1) |
| 23 | |
| 24 | filename = os.path.abspath(sys.argv[1]) |
| 25 | |
| 26 | if not os.path.isfile(filename): |
| 27 | print 'Error: No such file ', filename |
| 28 | sys.exit(2) |
| 29 | |
| 30 | #open file in binary mode |
| 31 | try: |
| 32 | infile = open(filename, 'rb') |
| 33 | #dont bother about specific exceptions |
| 34 | except: |
| 35 | print 'Could not open file to read !', filename |
| 36 | sys.exit(3) |
| 37 | |
| 38 | if infile is None: |
| 39 | print 'Error opening file ', filename |
| 40 | sys.exit(3) |
| 41 | |
| 42 | c = infile.read(1) |
| 43 | |
| 44 | lastmatch="" |
| 45 | while c != '': |
| 46 | |
| 47 | #look for image sig |
| 48 | for x in range(0, len(imgsigs)): |
| 49 | |
| 50 | #find if c is first character of imgsig |
| 51 | sig=imgsigs[x] |
| 52 | |
| 53 | if c == sig[0]: |
| 54 | #find if the rest of imgsig match |
| 55 | lentoread=len(sig) - 1 |
| 56 | chunk=c + infile.read(lentoread) |
| 57 | #print chunk |
| 58 | #matches |
| 59 | if chunk==sig: |
| 60 | fpos=int(infile.tell()) |
| 61 | |
| 62 | #now we are at end of sig, for getting image |
| 63 | #pos we need to subtract length of sig and offset |
| 64 | sigpos=fpos - len(sig) |
| 65 | imgpos=sigpos - imgsigoffs[x] |
| 66 | |
| 67 | #write position and image type to marker |
| 68 | imgmarker.append((imgpos, imgtypes[x])) |
| 69 | lastmatch=imgtypes[x] |
| 70 | else: |
| 71 | #bug, we need to reset file position |
| 72 | #to match other sigs correctly if this |
| 73 | #one does not. |
| 74 | currpos=int(infile.tell()) |
| 75 | prevpos=currpos-lentoread |