FIX: fixed all fingerprint marker inserts, file_positions (fpos) is now perfectly accurate. changed -fp to -pa -printall
This commit is contained in:
parent
7c9fec279b
commit
1898238955
126
libs/jpg_bin.py
126
libs/jpg_bin.py
|
@ -46,32 +46,55 @@ class JpgBin:
|
||||||
self.prev_fpos = 0
|
self.prev_fpos = 0
|
||||||
self.prev_mhex = 0xdead
|
self.prev_mhex = 0xdead
|
||||||
self.prev_mstr = "DUH!"
|
self.prev_mstr = "DUH!"
|
||||||
|
self.prev_imgData = False
|
||||||
|
|
||||||
self.jpg_fp = JpgFingerprint()
|
self.jpg_fp = JpgFingerprint()
|
||||||
|
|
||||||
|
#
|
||||||
|
# check for JPG file type marker
|
||||||
|
# add the marker to the processing variables to be used later
|
||||||
#
|
#
|
||||||
def __isJPG(self):
|
def __isJPG(self):
|
||||||
(m1, m2) = struct.unpack('>HB', self.data_buf[0:3])
|
(m1, m2) = struct.unpack('>HB', self.data_buf[0:3])
|
||||||
if (0xffd8 == m1 and 0xff == m2):
|
if (0xffd8 == m1 and 0xff == m2):
|
||||||
self.data_idx = 2
|
self.data_idx = 2
|
||||||
|
self.prev_mhex = 0xffd8
|
||||||
|
self.prev_mstr = "SOI "
|
||||||
|
self.prev_fpos = 0
|
||||||
|
self.prev_imgData = False
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
#
|
#
|
||||||
def processFile(self, file_h):
|
def processFile(self, file_h):
|
||||||
self.fh = file_h
|
self.fh = file_h
|
||||||
self.getMoreBytes(True)
|
self.__getMoreBytes(True)
|
||||||
if (self.data_buf):
|
if (self.data_buf):
|
||||||
if (not self.__isJPG()):
|
if (not self.__isJPG()):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
while(self.continue_process):
|
while(self.continue_process):
|
||||||
self.findAllMarkers()
|
self.findAllMarkers()
|
||||||
self.getMoreBytes()
|
self.__getMoreBytes()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
#
|
||||||
|
def genHash(self, file_h, hash_h):
|
||||||
|
self.hh = hash_h
|
||||||
|
for marker in self.jpg_fp.markers_img:
|
||||||
|
pass
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
#
|
||||||
|
def genImgHash222(self):
|
||||||
|
self.hh.update(self.data_buf[self.data_idx:])
|
||||||
|
while(self.continue_process):
|
||||||
|
self.__getMoreBytes()
|
||||||
|
self.hh.update(self.data_buf)
|
||||||
|
|
||||||
#
|
#
|
||||||
def findAllMarkers(self):
|
def findAllMarkers(self):
|
||||||
(word_b,) = struct.unpack('>H', self.data_buf[self.data_idx:self.data_idx+2])
|
(word_b,) = struct.unpack('>H', self.data_buf[self.data_idx:self.data_idx+2])
|
||||||
|
@ -125,98 +148,91 @@ class JpgBin:
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
def markerAppData(self, marker_hex):
|
def markerAppData(self, marker_hex):
|
||||||
fpos = self.fh.tell()
|
# fpos = self.fh.tell()
|
||||||
rec_len = self.calcSeekBytes()
|
# self.jpg_fp.addImgMetadata(marker_hex, fpos, rec_len, "APP ")
|
||||||
self.jpg_fp.addImgMetadata(marker_hex, fpos, rec_len, "APP ")
|
self.__addPrevMarkerData(marker_hex, "APP ", False)
|
||||||
|
rec_len = self.__calcSeekBytes()
|
||||||
|
|
||||||
#
|
#
|
||||||
def markerComment(self, marker_hex):
|
def markerComment(self, marker_hex):
|
||||||
fpos = self.fh.tell()
|
# fpos = self.fh.tell()
|
||||||
rec_len = self.calcSeekBytes()
|
# self.jpg_fp.addImgMetadata(marker_hex, fpos, rec_len, "COM ")
|
||||||
self.jpg_fp.addImgMetadata(marker_hex, fpos, rec_len, "COM ")
|
self.__addPrevMarkerData(marker_hex, "COM ", False)
|
||||||
|
rec_len = self.__calcSeekBytes()
|
||||||
|
|
||||||
#
|
#
|
||||||
# Image Data
|
# Image Data
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
def markerSOS(self, marker_hex):
|
def markerSOS(self, marker_hex):
|
||||||
# rec_len = self.calcSeekBytes()
|
# rec_len = self.__calcSeekBytes()
|
||||||
self.__addImgData(marker_hex, "SOS ")
|
self.__addPrevMarkerData(marker_hex, "SOS ")
|
||||||
|
|
||||||
#
|
#
|
||||||
def markerRST(self, marker_hex):
|
def markerRST(self, marker_hex):
|
||||||
self.__addImgData(marker_hex, "RST ")
|
self.__addPrevMarkerData(marker_hex, "RST ")
|
||||||
|
|
||||||
#
|
#
|
||||||
def markerDQT(self, marker_hex):
|
def markerDQT(self, marker_hex):
|
||||||
fpos = self.fh.tell()
|
# fpos = self.fh.tell()
|
||||||
rec_len = self.calcSeekBytes()
|
rec_len = self.__calcSeekBytes()
|
||||||
self.jpg_fp.addImgData(marker_hex, fpos, rec_len, "DQT ")
|
# self.jpg_fp.addImgData(marker_hex, fpos, rec_len, "DQT ")
|
||||||
|
self.__addPrevMarkerData(marker_hex, "DQT ")
|
||||||
|
|
||||||
#
|
#
|
||||||
def markerDRI(self, marker_hex):
|
def markerDRI(self, marker_hex):
|
||||||
fpos = self.fh.tell()
|
# fpos = self.fh.tell()
|
||||||
self.data_idx += 4
|
# self.jpg_fp.addImgData(marker_hex, fpos, 4, "DRI ")
|
||||||
self.jpg_fp.addImgData(marker_hex, fpos, 4, "DRI ")
|
self.__addPrevMarkerData(marker_hex, "DRI ")
|
||||||
|
# self.data_idx += 4
|
||||||
|
|
||||||
#
|
#
|
||||||
def markerSOF0(self, marker_hex):
|
def markerSOF0(self, marker_hex):
|
||||||
fpos = self.fh.tell()
|
# fpos = self.fh.tell()
|
||||||
rec_len = self.calcSeekBytes()
|
# self.jpg_fp.addImgData(marker_hex, fpos, rec_len, "SOF0")
|
||||||
self.jpg_fp.addImgData(marker_hex, fpos, rec_len, "SOF0")
|
self.__addPrevMarkerData(marker_hex, "SOF0")
|
||||||
|
rec_len = self.__calcSeekBytes()
|
||||||
|
|
||||||
#
|
#
|
||||||
def markerSOF2(self, marker_hex):
|
def markerSOF2(self, marker_hex):
|
||||||
fpos = self.fh.tell()
|
# fpos = self.fh.tell()
|
||||||
rec_len = self.calcSeekBytes()
|
# self.jpg_fp.addImgData(marker_hex, fpos, rec_len, "SOF2")
|
||||||
self.jpg_fp.addImgData(marker_hex, fpos, rec_len, "SOF2")
|
self.__addPrevMarkerData(marker_hex, "SOF2")
|
||||||
|
rec_len = self.__calcSeekBytes()
|
||||||
|
|
||||||
def markerDHT(self, marker_hex):
|
def markerDHT(self, marker_hex):
|
||||||
fpos = self.fh.tell()
|
# fpos = self.fh.tell()
|
||||||
rec_len = self.calcSeekBytes()
|
# self.jpg_fp.addImgData(marker_hex, fpos, rec_len, "DHT ")
|
||||||
self.jpg_fp.addImgData(marker_hex, fpos, rec_len, "DHT ")
|
self.__addPrevMarkerData(marker_hex, "DHT ")
|
||||||
|
rec_len = self.__calcSeekBytes()
|
||||||
|
|
||||||
#
|
#
|
||||||
def markerEOI(self, marker_hex):
|
def markerEOI(self, marker_hex):
|
||||||
fpos = self.fh.tell()
|
# fpos = self.fh.tell()
|
||||||
self.__addImgData(marker_hex, "EOI ")
|
self.__addPrevMarkerData(marker_hex, "EOI ")
|
||||||
self.jpg_fp.addImgData(marker_hex, fpos, 2, "EOI ")
|
self.__addPrevMarkerData(marker_hex, "JUST A DUMMY VALUE")
|
||||||
|
# self.jpg_fp.addImgData(marker_hex, fpos, 2, "EOI ")
|
||||||
|
|
||||||
|
|
||||||
# private helper function
|
# private helper function
|
||||||
def __addImgData(self, mhex, mstr):
|
def __addPrevMarkerData(self, mhex, mstr, imgData=True):
|
||||||
fpos = self.fh.tell()
|
fpos = self.fh.tell()
|
||||||
cur_fpos = (fpos - (self.data_len - self.data_idx))
|
cur_fpos = (fpos - (self.data_len - self.data_idx))
|
||||||
if (self.prev_fpos > 0):
|
rec_len = cur_fpos - self.prev_fpos
|
||||||
rec_len = cur_fpos - self.prev_fpos
|
|
||||||
|
if (self.prev_imgData):
|
||||||
self.jpg_fp.addImgData(self.prev_mhex, self.prev_fpos, rec_len, self.prev_mstr)
|
self.jpg_fp.addImgData(self.prev_mhex, self.prev_fpos, rec_len, self.prev_mstr)
|
||||||
|
else:
|
||||||
|
self.jpg_fp.addImgMetadata(self.prev_mhex, self.prev_fpos, rec_len, self.prev_mstr)
|
||||||
|
|
||||||
self.prev_mhex = mhex
|
self.prev_mhex = mhex
|
||||||
self.prev_mstr = mstr
|
self.prev_mstr = mstr
|
||||||
self.prev_fpos = cur_fpos
|
self.prev_fpos = cur_fpos
|
||||||
self.data_idx += 2
|
self.data_idx += 2
|
||||||
|
self.prev_imgData = imgData
|
||||||
|
|
||||||
#
|
#
|
||||||
def genHash(self, file_h, hash_h):
|
def __getMoreBytes(self, force_bytes=False):
|
||||||
self.hh = hash_h
|
|
||||||
#self.processFile(file_h)
|
|
||||||
|
|
||||||
while(self.continue_process):
|
|
||||||
if (self.findMarker(self.makers['SOS'])):
|
|
||||||
self.genImgHash()
|
|
||||||
self.getMoreBytes()
|
|
||||||
|
|
||||||
return self.hh
|
|
||||||
|
|
||||||
#
|
|
||||||
def genImgHash(self):
|
|
||||||
self.hh.update(self.data_buf[self.data_idx:])
|
|
||||||
while(self.continue_process):
|
|
||||||
self.getMoreBytes()
|
|
||||||
self.hh.update(self.data_buf)
|
|
||||||
|
|
||||||
#
|
|
||||||
def getMoreBytes(self, force_bytes=False):
|
|
||||||
if (self.data_idx >= (self.data_len-1) or force_bytes):
|
if (self.data_idx >= (self.data_len-1) or force_bytes):
|
||||||
self.data_buf = self.fh.read(self.BUF_CHUNK_SIZE)
|
self.data_buf = self.fh.read(self.BUF_CHUNK_SIZE)
|
||||||
self.data_idx = 0
|
self.data_idx = 0
|
||||||
|
@ -226,7 +242,9 @@ class JpgBin:
|
||||||
logging.debug("DATA: len=={}".format(self.data_len))
|
logging.debug("DATA: len=={}".format(self.data_len))
|
||||||
|
|
||||||
#
|
#
|
||||||
def calcSeekBytes(self):
|
# move the index 2 bytes, then read the 2 bytes to get the length
|
||||||
|
#
|
||||||
|
def __calcSeekBytes(self):
|
||||||
self.data_idx += 2
|
self.data_idx += 2
|
||||||
(rec_len,) = struct.unpack('>H', self.data_buf[self.data_idx:self.data_idx+2])
|
(rec_len,) = struct.unpack('>H', self.data_buf[self.data_idx:self.data_idx+2])
|
||||||
remain_bytes = self.data_len - self.data_idx
|
remain_bytes = self.data_len - self.data_idx
|
||||||
|
@ -240,8 +258,8 @@ class JpgBin:
|
||||||
#
|
#
|
||||||
def seekBytes(self, num_bytes):
|
def seekBytes(self, num_bytes):
|
||||||
pos = self.fh.seek(num_bytes, 1)
|
pos = self.fh.seek(num_bytes, 1)
|
||||||
|
self.__getMoreBytes(True)
|
||||||
logging.debug("SEEK: seek=={}, cur_loc=={}".format(num_bytes, pos))
|
logging.debug("SEEK: seek=={}, cur_loc=={}".format(num_bytes, pos))
|
||||||
self.getMoreBytes(True)
|
|
||||||
return pos
|
return pos
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
12
picseal.py
12
picseal.py
|
@ -10,7 +10,7 @@ from libs.crypto_pub import Signature
|
||||||
from libs.toolbox import Toolbox
|
from libs.toolbox import Toolbox
|
||||||
from libs.jpg_tools import JpgTools
|
from libs.jpg_tools import JpgTools
|
||||||
|
|
||||||
fingerprint = False
|
printall = False
|
||||||
printmeta = False
|
printmeta = False
|
||||||
printimage = False
|
printimage = False
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ def copyImage(image_fn):
|
||||||
|
|
||||||
#
|
#
|
||||||
def printImageInfo(jpg_bin2):
|
def printImageInfo(jpg_bin2):
|
||||||
if (fingerprint):
|
if (printall):
|
||||||
print( str(jpg_bin2) )
|
print( str(jpg_bin2) )
|
||||||
|
|
||||||
if (printimage):
|
if (printimage):
|
||||||
|
@ -85,7 +85,7 @@ def parseArgs():
|
||||||
parser.add_argument('-l', '--logging', action='store_true', help="will supercede the -v option and send all logging to a file, logging.DEBUG")
|
parser.add_argument('-l', '--logging', action='store_true', help="will supercede the -v option and send all logging to a file, logging.DEBUG")
|
||||||
parser.add_argument('-pm', '--printmeta', action='store_true', help="print the metadata markers")
|
parser.add_argument('-pm', '--printmeta', action='store_true', help="print the metadata markers")
|
||||||
parser.add_argument('-pi', '--printimage', action='store_true', help="print the image markers")
|
parser.add_argument('-pi', '--printimage', action='store_true', help="print the image markers")
|
||||||
parser.add_argument('-fp', '--fingerprint', action='store_true', help="fingerprint")
|
parser.add_argument('-pa', '--printall', action='store_true', help="print all markers")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if (args.logging):
|
if (args.logging):
|
||||||
|
@ -98,9 +98,9 @@ def parseArgs():
|
||||||
else:
|
else:
|
||||||
logging.basicConfig(level=logging.CRITICAL)
|
logging.basicConfig(level=logging.CRITICAL)
|
||||||
|
|
||||||
if (args.fingerprint):
|
if (args.printall):
|
||||||
global fingerprint
|
global printall
|
||||||
fingerprint = True
|
printall = True
|
||||||
|
|
||||||
if (args.printmeta):
|
if (args.printmeta):
|
||||||
global printmeta
|
global printmeta
|
||||||
|
|
Loading…
Reference in New Issue