INNER CODE UNIT · Python

make_zip

KSwordDEV/KSword · GhidraRuntimePlugin/package.py:108

def make_zip(tree: Path, output: Path):
    if output.exists():
        raise ValueError('output ZIP already exists; refusing replacement')
    output.parent.mkdir(parents=True, exist_ok=True)
    with zipfile.ZipFile(output, 'x', compression=zipfile.ZIP_DEFLATED, compresslevel=6,
                         allowZip64=True) as archive:
        for file in sorted(path for path in tree.rglob('*') if path.is_file()):
            info = zipfile.ZipInfo('ghidra/' + file.relative_to(tree).as_posix(), (1980, 1, 1, 0, 0, 0))
            info.compress_type = zipfile.ZIP_DEFLATED
            info.external_attr = 0o100644 << 16
            with file.open('rb') as source, archive.open(info, 'w', force_zip64=True) as sink:
                shutil.copyfileobj(source, sink, 1024 * 1024)


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--ghidra-archive', type=Path, required=True)
    parser.add_argument('--jdk-archive', type=Path, required=True)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…