Giter VIP home page Giter VIP logo

unuzip's Introduction

unuzip - Decompress FreeBSD UZIP images

UZIP is a compressed image format created by mkuzip on FreeBSD, not entirely dissimilar to cramfs on Linux. unuzip decompresses these images to plain UFS images that can be mounted on Linux.

unuzip is written in Python 2 and has been tested on Linux and Mac OS X.

Usage

unuzip [-v] <in.uzip> [out.ufs]

Decompress the input file. If no output file is given, the output filename defaults to inputfile.ufs. Add the -v flag to get details about each block as they are decompressed.

Note that unuzip will silently overwrite the output file.

Once the file is decompressed, you can mount it on a Linux system using a command like:

mount -o loop,ro,ufstype=ufs2 out.ufs /mnt/somewhere

Why?

As far as I could find, no tool exists to decompress UZIP images. I don't have any FreeBSD systems handy, but Linux can easily mount plain UFS file systems. Thus this tool was born.

UZIP file format

UZIP does not appear to be formally documented anywhere, so for the benefit of others interested in this format, this section is a brief overview of how the file is structured. All integers are big endian.

Magic:  128 bytes
Header: 8 bytes (uint32_t block_size, uint32_t total_blocks)
TOC:    8 bytes * (num_blocks + 1)
Compressed blocks

UZIP magic is a 128 byte string that also makes the file a valid shell script that will mount the image on FreeBSD. For version 2 images, the magic string is:

#!/bin/sh
#V2.0 Format
m=geom_uzip
(kldstat -m $m 2>&-||kldload $m)>&-&&mount_cd9660 /dev/`mdconfig -af $0`.uzip $1
exit $?

Version 3 images change the second line to #L3.0 Format, but this tool does not support such images.

The header declares the block size (size of decompressed blocks) and total number of blocks. Block size must be a multiple of 512 and defaults to 16384 in mkuzip.

The TOC is a list of uint64_t offsets into the file for each block. To determine the length of a given block, read the next TOC entry and subtract the current offset from the next offset (this is why there is an extra TOC entry at the end).

Each block is compressed using zlib. A standard zlib decompressor will decode them to a block of size block_size.

About

unuzip was written by Mike Ryan of ICE9 Consulting. Please report any issues on the unuzip GitHub.

unuzip is not part of FreeBSD and shares no code with FreeBSD.

unuzip's People

Contributors

mikeryan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

unuzip's Issues

unuzip with Python 3.8.12 on FreeBSD

Hi, must I install Python 2 for unuzip to work here?

% pwd
/tmp/0.6.0
% /usr/home/grahamperrin/dev/unuzip/unuzip -v ./system.uzip system.ufs
env: python2: No such file or directory
% python /usr/home/grahamperrin/dev/unuzip/unuzip -v ./system.uzip system.ufs
  File "/usr/home/grahamperrin/dev/unuzip/unuzip", line 41
    print "Error: can't open input file: %s" % e
          ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("Error: can't open input file: %s" % e)?
% cd /usr/home/grahamperrin/dev/unuzip
% python unuzip /tmp/0.6.0/system.uzip /tmp/0.6.0/system.ufs
  File "unuzip", line 41
    print "Error: can't open input file: %s" % e
          ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("Error: can't open input file: %s" % e)?
% which python
/usr/local/bin/python
% python --version
Python 3.8.12
% pkg search python2
py38-dnspython2-2.1.0          DNS toolkit for Python - 2.X branch
python2-2_3                    Meta-port for the Python interpreter 2.7
python27-2.7.18_1              Interpreted object-oriented programming language
% pkg info -x python
py38-dnspython-1.16.0
py38-gitpython-3.1.24
py38-python-distutils-extra-2.45
py38-python-poppler-qt5-0.75.0_22
py38-wxPython40-4.0.7_2
python-3.8_3,2
python3-3_3
python37-3.7.12_1
python38-3.8.12_1
python39-3.9.7_1
% uname -aKU
FreeBSD mowa219-gjp4-8570p-freebsd 14.0-CURRENT FreeBSD 14.0-CURRENT #112 main-n249988-2c614481fd5: Sun Oct 10 21:42:16 BST 2021     root@mowa219-gjp4-8570p-freebsd:/usr/obj/usr/src/amd64.amd64/sys/GENERIC-NODEBUG  amd64 1400036 1400036
% 

uzip file that fails to decompress the last block

I have an uzip 2.0 file which decompresses fine except for the last block where it fails:

UZIP v2.0 file detected
Decompressing rootfs.img to rootfs.ufs

Block size:         6144
Total blocks:     199510
Total size:   1225789440

  0%
 10%
 20%
 30%
 40%
 50%
 60%
 70%
 80%
 90%
Error: decompression error at 199509

I modified the output in that case to see what is going on:

Error: decompression error at 199509, expected 6144 bytes, got 2048

Seems there's 4096 bytes "missing" somehow. In my case I just added code to write the partial block to the output and the resulting image seems to work just fine...

I cannot post a link to the uzip-image in question (it contains copyrighted code) but I can share it with you privately if you want to take a look at it. It's around 350mb.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.