Skip to content

Commit

Permalink
unknown tags script
Browse files Browse the repository at this point in the history
  • Loading branch information
lclevy committed Jul 8, 2016
1 parent 308df8d commit 806890e
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 123 deletions.
Binary file added docs/unknow_tags.txt
Binary file not shown.
1 change: 1 addition & 0 deletions python/FILES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ PyCanonRaw2.py historical implementation of libcraw2 in python (obsolet
PyTiffParser.py TIFF parser
cr2_analysis.py script using PyCanonRaw2 and PyTiffParser (obsolete)
thumbnails extract picture data from all IFDs. uses PyTiffParser
unknown_tags.py display length and presence of makernote tags
17 changes: 12 additions & 5 deletions python/PyTiffParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ def __init__(self, f, verbose=0):
self.file = f
self.verbose = verbose
self.order, self.base, self.type = self.checkHeader( verbose )
print self.base
#print self.base

def listTagsCsv(self):
for t in self.tags:
print t

def dumpTag( self, offset, len ):
old_pos = self.file.tell()
read = 0
self.file.seek(offset+self.base)
print "0x%06x:" % (self.file.tell()),
#print "0x%06x:" % (self.file.tell()),
line = min (16, len-read)
d = self.file.read( line )
read = read + line
Expand Down Expand Up @@ -86,11 +90,12 @@ def parseMakernote( self, offset ):
if self.verbose>0:
print "\n Makernote entries = %d" % (n)
for i in range(n):
offset = self.file.tell()
tag = self.fGetShort( self.order )
type = self.fGetShort( self.order )
length = self.fGetLong( self.order )
val = self.fGetLong( self.order )
self.tags[('maker', tag)] = (tag, type, length, val)
self.tags[('maker', tag)] = (tag, type, length, val, offset)
if self.verbose>0:
print "tag = 0x%x/%d, type = %d, length = 0x%x/%d, val = 0x%x/%d" % (tag,tag,type,length,length,val,val)
"""if (tag==0x4001) and self.verbose>1:
Expand All @@ -108,13 +113,14 @@ def parseExif( self, offset ):
if self.verbose>0:
print "\n Exif entries = %d" % (n)
for i in range(n):
offset = self.file.tell()
tag = self.fGetShort( self.order )
type = self.fGetShort( self.order )
length = self.fGetLong( self.order )
val = self.fGetLong( self.order )
if self.verbose>0:
print "tag = 0x%x/%d, type = %d, length = 0x%x/%d, val = 0x%x/%d" % (tag,tag,type,length,length,val,val)
self.tags[('exif', tag)] = (tag, type, length, val)
self.tags[('exif', tag)] = (tag, type, length, val, offset)
if tag == TIFFTAG_VAL_MAKERNOTE:
self.parseMakernote( val )
self.file.seek(old_pos)
Expand All @@ -125,14 +131,15 @@ def parseExif( self, offset ):
def parseIFD( self, currentIfd ):
n = self.fGetShort( self.order )
for i in range(n):
offset = self.file.tell()
tag = self.fGetShort( self.order )
type = self.fGetShort( self.order )
length = self.fGetLong( self.order )
val = self.fGetLong( self.order )
if self.verbose>0:
print "tag = 0x%x/%d, type = %d, length = 0x%x/%d, val = 0x%x/%d" % (tag,tag,type,length,length,val,val)
ifdName = 'ifd{0:x}'.format(currentIfd)
self.tags[(ifdName, tag)] = (tag, type, length, val)
self.tags[(ifdName, tag)] = (tag, type, length, val, offset)
if tag == TIFFTAG_VAL_EXIF:
self.parseExif( val )
return self.fGetLong( self.order )
Expand Down
118 changes: 0 additions & 118 deletions python/cr2_analysis_corr.py

This file was deleted.

73 changes: 73 additions & 0 deletions python/unknown_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import PyTiffParser
from binascii import hexlify
from struct import unpack
import sys

def getLongLE(d, a):
return unpack('<L',(d)[a:a+4])[0]
def getShortLE(d, a):
return unpack('<H',(d)[a:a+2])[0]

def getTagLength(tags, key):
if key in tags:
tag = tags[key]
return tag[2]
else:
return ''

def getTagValue(tags, key):
if key in tags:
tag = tags[key]
return tag[3]
else:
return ''

def getTagData(tags, key, f):
if key in tags:
tag = tags[key]
f.seek(tag[3])
return fread(tag[2])
else:
return ''

f = open(sys.argv[1],'rb')
pic = PyTiffParser.PyTiffParser( f, False )
pic.parse()
#print pic.tags
#pic.listTagsCsv()

#print 'modelId,',
tagList = [ 0x83, 0x97, 0x4001, 0x4002, 0x4003, 0x4004, 0x4005, 0x4008, 0x4009, 0x4010, 0x4011, 0x4012, 0x4013,
0x4014, 0x4015, 0x4016, 0x4017, 0x4018, 0x4019, 0x4020, 0x4021, 0x4023, 0x4024, 0x4025, 0x4027, 0x4028 ]
#tagList = range( 0x4001, 0x4029 )
"""for t in tagList:
print '0x%x,' % t,
print
"""
#modelId
t = pic.tags[('maker',0x10)]
#print t,
print '0x%08x,' % t[3],

#modelId
t = pic.tags[('ifd0',0x110)]
#print t,
f.seek(t[3])
val = f.read(t[2])
print '%s,' % val,

for t in tagList:
#print '0x%x:' % t,
print '%s,' % getTagLength( pic.tags, ('maker',t) ),
print
"""
print '0x4016:',
t = pic.tags[('maker',0x4016)]
print t,
f.seek(t[3])
val = f.read(t[2]*4)
print hexlify(val)
"""

f.close()

7 changes: 7 additions & 0 deletions unknow_tags.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

#echo "modelId, 0x83, 0x97, 0x4001, 0x4002, 0x4003, 0x4004, 0x4005, 0x4008, 0x4009, 0x4010, 0x4011, 0x4012, 0x4014, 0x4017, 0x4023, 0x4027, 0x4028,"
echo "modelId, modelName, 0x83, 0x97, 0x4001, 0x4002, 0x4003, 0x4004, 0x4005, 0x4008, 0x4009, 0x4010, 0x4011, 0x4012, 0x4013, 0x4014, 0x4015, 0x4016, 0x4017, 0x4018, 0x4019, 0x4020, 0x4021, 0x4023, 0x4024, 0x4025, 0x4027, 0x4028,"
for pic in `cat samples_list_rggb.txt`; do
python python/unknown_tags.py $pic
done

0 comments on commit 806890e

Please sign in to comment.