コード例 #1
0
ファイル: jpeg_carver.py プロジェクト: anarchivist/pyflag
    def generate_function(self, c):
        ## Find the next discontinuity:
        s_old = self.find_discontinuity(c)

        d = jpeg.decoder(c)
        d.decode(s_old)
        x_old, y = d.find_frame_bounds()
        y_old = y - self.row_height
        ## This is the image coordinate of the discontinuity:
        image_offset, left = c.interpolate(s_old * 512)

        ## Try to fuzz the discontiuity
        for image_offset_to in range(image_offset, image_offset + 10 * 512, 512):
            for s_from in range(s_old, s_old + 2):
                ## Enforce the projection rule
                if s_from * 512 > image_offset_to: continue

                c.add_point(s_from * 512, image_offset_to , "Test_point")
                d = jpeg.decoder(c)
                print "Will decode up to %s" % ((s_from + 5) * 512)
                d.decode(s_from + 10)
                e = self.estimate(x_old, y_old, d)
                print "Estimate %s-%s %s" % (s_from, image_offset_to / 512, e)
                d.save(open("estimate_%s-%s.ppm" % (s_from, image_offset_to / 512),'w'))
                c.del_point(s_from * 512)
コード例 #2
0
ファイル: jpeg_carver.py プロジェクト: ntvis/pyflag
    def generate_function(self, c):
        ## Find the next discontinuity:
        s_old = self.find_discontinuity(c)

        d = jpeg.decoder(c)
        d.decode(s_old)
        x_old, y = d.find_frame_bounds()
        y_old = y - self.row_height
        ## This is the image coordinate of the discontinuity:
        image_offset, left = c.interpolate(s_old * 512)

        ## Try to fuzz the discontiuity
        for image_offset_to in range(image_offset, image_offset + 10 * 512,
                                     512):
            for s_from in range(s_old, s_old + 2):
                ## Enforce the projection rule
                if s_from * 512 > image_offset_to: continue

                c.add_point(s_from * 512, image_offset_to, "Test_point")
                d = jpeg.decoder(c)
                print "Will decode up to %s" % ((s_from + 5) * 512)
                d.decode(s_from + 10)
                e = self.estimate(x_old, y_old, d)
                print "Estimate %s-%s %s" % (s_from, image_offset_to / 512, e)
                d.save(
                    open(
                        "estimate_%s-%s.ppm" % (s_from, image_offset_to / 512),
                        'w'))
                c.del_point(s_from * 512)
コード例 #3
0
ファイル: jpeg_carver.py プロジェクト: anarchivist/pyflag
    def find_discontinuity(self, c):
        c.overread = 1000 * 1024
        i = 1
        while not self.row_height:
            d = jpeg.decoder(c)
            d.decode(i)
            self.estimate(0,0,d)
            i+=1

        d = jpeg.decoder(c)
        d.decode(self.start_sector-1)    
        old_x, old_y = d.find_frame_bounds()

        print "Discontinuity detected after %s" % d.last_good_sector()
##        for sector in range(d.last_good_sector()-10, d.last_good_sector()+30):
        sector = self.start_sector
        while 1:
            sector += 1 
            d = jpeg.decoder(c)
            print "Trying to decompress %s" % sector
            d.decode(sector)
            x, y = d.find_frame_bounds()
            print "Frame bounded at %s, %s, %s" % (x,y, y-self.row_height)

            estimate = self.estimate(old_x, old_y, d)

#            x,y, y_min = d.find_frame_bounds()


#            if y==height: return sector, width, height

#            if y_min > old_y_min:
#                e1 = d.estimate(old_y_min, old_x, width)
#                e2 = d.estimate(y_min, 0, x)
#                estimate = (e1+e2)/2
#            else:
#                estimate = d.estimate(old_y_min, old_x, x)

            print "Sector %s Integral calculated %s" % (sector, estimate)

            if self.options.verbose > 1:
                d.save(open("output_test%03u.ppm" % sector,'w'))
                
            if estimate > self.options.max_estimate:
                print "Estimate too large - returning sector %s" % (sector-2)
                return sector-2

            if d.warnings()>0:
                print "Warnings are %s" % d.warnings()
                return sector-2
            
            print "Last sector %s" % d.last_sector()
            if d.last_sector() < sector:
                return d.last_sector()

            old_x = x
            old_y = y - self.row_height
コード例 #4
0
ファイル: jpeg_carver.py プロジェクト: ntvis/pyflag
    def find_discontinuity(self, c):
        c.overread = 1000 * 1024
        i = 1
        while not self.row_height:
            d = jpeg.decoder(c)
            d.decode(i)
            self.estimate(0, 0, d)
            i += 1

        d = jpeg.decoder(c)
        d.decode(self.start_sector - 1)
        old_x, old_y = d.find_frame_bounds()

        print "Discontinuity detected after %s" % d.last_good_sector()
        ##        for sector in range(d.last_good_sector()-10, d.last_good_sector()+30):
        sector = self.start_sector
        while 1:
            sector += 1
            d = jpeg.decoder(c)
            print "Trying to decompress %s" % sector
            d.decode(sector)
            x, y = d.find_frame_bounds()
            print "Frame bounded at %s, %s, %s" % (x, y, y - self.row_height)

            estimate = self.estimate(old_x, old_y, d)

            #            x,y, y_min = d.find_frame_bounds()

            #            if y==height: return sector, width, height

            #            if y_min > old_y_min:
            #                e1 = d.estimate(old_y_min, old_x, width)
            #                e2 = d.estimate(y_min, 0, x)
            #                estimate = (e1+e2)/2
            #            else:
            #                estimate = d.estimate(old_y_min, old_x, x)

            print "Sector %s Integral calculated %s" % (sector, estimate)

            if self.options.verbose > 1:
                d.save(open("output_test%03u.ppm" % sector, 'w'))

            if estimate > self.options.max_estimate:
                print "Estimate too large - returning sector %s" % (sector - 2)
                return sector - 2

            if d.warnings() > 0:
                print "Warnings are %s" % d.warnings()
                return sector - 2

            print "Last sector %s" % d.last_sector()
            if d.last_sector() < sector:
                return d.last_sector()

            old_x = x
            old_y = y - self.row_height
コード例 #5
0
ファイル: jpeg_test.py プロジェクト: olivierh59500/pyflag
#    c.add_point(924877, 49486541, "EOF")
elif x==5:
    c.add_point(0, 41611 * SECTOR_SIZE, "File header")
#    c.add_point(100 * SECTOR_SIZE, 41564 * SECTOR_SIZE, "File header")
#    c.add_point(1021085, 22630556, "EOF")
elif x==6:
    c.add_point(0, 90377 * SECTOR_SIZE, "File header")
#    c.add_point(675 * SECTOR_SIZE, 93669 * SECTOR_SIZE, "Forced")
    
elif x==7:
    c.add_point(0, 93780 * SECTOR_SIZE, "File header")

elif x==12:
    c.add_point(0, 87716 * SECTOR_SIZE, "File header")

d = jpeg.decoder(c)
def best_sector(d):
    start = d.decode() or 0
    print start
    
    print "Discontinuity detected after %s" % d.last_good_sector()
    for sector in range(d.last_good_sector(), d.last_good_sector()+30):
        print "Trying to decompress %s" % sector
        d.decode(sector)
        print "Errors %s - best sector so far %s" % (d.warnings(), d.last_sector())
        #d.save(open("output_test%s.ppm" % sector,'w'))
        if d.warnings()>0:
            return sector-2

        print "Last sector %s" % d.last_sector()
        if d.last_sector() < sector: