Ejemplo n.º 1
0
    def upload(self, path):
        try:
            if not os.path.exists(path) or os.path.isdir(path):
                self.error('Surgeon not found.')
                    
            cbf.check(path)
            buf = ''
            with open(path, 'rb') as f:
                buf = f.read()
                f.close()

            buf_len = len(buf)

            packet_leftovers = buf_len % cbf.PACKET_SIZE
            if packet_leftovers > 0:
                padding_size = cbf.PACKET_SIZE - packet_leftovers
                buf += struct.pack('%ss' % padding_size, '\xFF'*padding_size)

            buf_len = len(buf)
            packets = buf_len/cbf.PACKET_SIZE

            byte1 = '00'
            total = 0
            last_total = 0

            for i in range(0, packets):
                cmdl = '%s %s -b -s %s -n 2A 00 00 00 00 %s 00 00 20 00' % (self._sg_raw, self._mount_config.device_id, cbf.PACKET_SIZE, byte1)
                cmd = shlex_split(cmdl)
                byte1 = '01'
                p = Popen(cmd, stdin=PIPE, stderr=PIPE)
                p.stdin.write(buf[last_total:last_total+cbf.PACKET_SIZE])
                err = p.stderr.read()
                
                if not 'Good' in err:
                    self.error('SCSI error.')
                
                last_total += cbf.PACKET_SIZE

            p = Popen([self._sg_verify, self._mount_config.device_id], stderr=PIPE)
            err = p.stderr.read()
            
            if len(err) != 0:
                self.error('SCSI error.')                
        except Exception, e:
            self.rerror(e)
Ejemplo n.º 2
0
def extract(path, suffix):
    if cbf.check(path, True):
        cbf.extract(path)
        path = os.path.join(os.path.dirname(path), 'zImage')

    irfs = initramfs(suffix)
    if irfs.gzip_find(irfs.file_open(path), True):
        irfs.extract(path)
        print 'Initramfs extracted.'
    else:
        error('Does not appear to be proper zImage.')