Example #1
0
def extract_squashfs(path, destdir):
    cmd = ['unsquashfs', '-n', '-f', '-d', destdir, path]
    logger.debug("extracting %s into %s", path, destdir)
    p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE)
    p.communicate()
    p.wait()
    if p.returncode != 0:
        logger.error('unsquashfs exited with error code %d', p.returncode)
Example #2
0
def extract_cpio_archive(path, destdir):
    cmd = ['cpio', '--no-absolute-filenames', '--quiet', '-idF',
            os.path.abspath(path.encode('utf-8'))]
    logger.debug("extracting %s into %s", path.encode('utf-8'), destdir)
    p = subprocess.Popen(cmd, shell=False, cwd=destdir)
    p.communicate()
    p.wait()
    if p.returncode != 0:
        logger.error('cpio exited with error code %d', p.returncode)
Example #3
0
def extract_rpm_payload(path):
    cmd = ["rpm2cpio", path]
    with make_temp_directory() as temp_dir:
        temp_path = os.path.join(temp_dir, "CONTENTS.cpio")
        with open(temp_path, "wb") as temp_file:
            p = subprocess.Popen(cmd, shell=False, stdout=temp_file, stderr=subprocess.PIPE)
            p.wait()
            if p.returncode != 0:
                logger.error("rpm2cpio exited with error code %d", p.returncode)

            yield temp_path
Example #4
0
def extract_cpio_archive(path, destdir):
    cmd = [
        'cpio', '--no-absolute-filenames', '--quiet', '-idF',
        os.path.abspath(path.encode('utf-8'))
    ]
    logger.debug("extracting %s into %s", path.encode('utf-8'), destdir)
    p = subprocess.Popen(cmd, shell=False, cwd=destdir)
    p.communicate()
    p.wait()
    if p.returncode != 0:
        logger.error('cpio exited with error code %d', p.returncode)
Example #5
0
def extract_rpm_payload(path):
    cmd = ['rpm2cpio', path]
    with make_temp_directory() as temp_dir:
        temp_path = os.path.join(temp_dir, "CONTENTS.cpio")
        with open(temp_path, 'wb') as temp_file:
            p = subprocess.Popen(cmd,
                                 shell=False,
                                 stdout=temp_file,
                                 stderr=subprocess.PIPE)
            p.wait()
            if p.returncode != 0:
                logger.error("rpm2cpio exited with error code %d",
                             p.returncode)

            yield temp_path
Example #6
0
def get_rpm_header(path, ts):
    header = ''
    with open(path, 'r') as f:
        try:
            hdr = ts.hdrFromFdno(f)
        except rpm.error, e:
            logger.error("reading rpm header failed: %s", str(e))
            return str(e)
        for rpmtag in sorted(rpm.tagnames):
            if rpmtag not in hdr:
                continue
            # header fields can contain binary data
            try:
                value = str(hdr[rpmtag]).decode('utf-8')
            except UnicodeDecodeError:
                value = str(hdr[rpmtag]).encode('hex_codec')
            header += "%s: %s\n" % (rpm.tagnames[rpmtag], value)
Example #7
0
def get_rpm_header(path, ts):
    header = ''
    with open(path, 'r') as f:
        try:
            hdr = ts.hdrFromFdno(f)
        except rpm.error, e:
            logger.error("reading rpm header failed: %s", str(e))
            return str(e)
        for rpmtag in sorted(rpm.tagnames):
            if rpmtag not in hdr:
                continue
            # header fields can contain binary data
            try:
                value = str(hdr[rpmtag]).decode('utf-8')
            except UnicodeDecodeError:
                value = str(hdr[rpmtag]).encode('hex_codec')
            header += "%s: %s\n" % (rpm.tagnames[rpmtag], value)