Skip to content

Latest commit

 

History

History
57 lines (51 loc) · 3.86 KB

README.md

File metadata and controls

57 lines (51 loc) · 3.86 KB

cpio_newc_dumper.js

Use it to dump (not properly extract directory tree with permissions!) an ASCII cpio archive (SVR4 with no CRC).

Search New ASCII Format here for explanation of archive format.

It is intended for editing ASCII cpio archives (SVR4 with no CRC) with minimal changes.

It almost perfectly replicates original achive from dump:
Archive is ungzipped ramdisk.img from primeOS-mainline_0.6.1-20211206.iso.
The zeros in the difference are garbage data after the TRAILER!!! file in original ungzipped archive (ramdisk).
bash-5.1$ zcat ramdisk.img > ramdisk
bash-5.1$ mkdir dumpdir
bash-5.1$ deno run --allow-read --allow-write cpio_newc_dumper.js dump ramdisk dumpdir
bash-5.1$ deno run --allow-read --allow-write cpio_newc_dumper.js pack ramdisk2 dumpdir
bash-5.1$ diff <(xxd ramdisk) <(xxd ramdisk2)
271681,271696c271681
< 00425400: 0000 0000 0000 0000 0000 0000 0000 0000  ................
< 00425410: 0000 0000 0000 0000 0000 0000 0000 0000  ................
< 00425420: 0000 0000 0000 0000 0000 0000 0000 0000  ................
< 00425430: 0000 0000 0000 0000 0000 0000 0000 0000  ................
< 00425440: 0000 0000 0000 0000 0000 0000 0000 0000  ................
< 00425450: 0000 0000 0000 0000 0000 0000 0000 0000  ................
< 00425460: 0000 0000 0000 0000 0000 0000 0000 0000  ................
< 00425470: 0000 0000 0000 0000 0000 0000 0000 0000  ................
< 00425480: 0000 0000 0000 0000 0000 0000 0000 0000  ................
< 00425490: 0000 0000 0000 0000 0000 0000 0000 0000  ................
< 004254a0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
< 004254b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
< 004254c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
< 004254d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
< 004254e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
< 004254f0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
---
> 00425400: 0000 0000                                ....
What it doesn't replicate:

  • data after TRAILER!!! file
  • case of hex letters (ABCDEF or abcdef) in headers
    • It understands both uppercase (0123456789ABCDEF) and lowercase (0123456789abcdef) hex digits but writes lowercase hex digits.

usage: deno run --allow-read --allow-write THIS_SCRIPT MODE ARCHIVE DUMP_DIR

MODE is case-insensitive and means what to do:
  "dump"    dump ARCHIVE into DUMP_DIR
            ARCHIVE is "-" means stdin
  "dumpgz"  ungzip and dump ARCHIVE into DUMP_DIR
            ARCHIVE is "-" means stdin
  "pack"    pack DUMP_DIR into ARCHIVE
            ARCHIVE is "-" means stdout
  "packgz"  pack and gzip DUMP_DIR into ARCHIVE
            ARCHIVE is "-" means stdout

DUMP_DIR contains non-empty files (symlinks is dumped as files with link target as content) and "table.txt".
"table.txt" contains file names from ARCHIVE and names of corresponding files in DUMP_DIR and numbers from cpio_newc_header struct.

I am not a cpio extractor that keeps file names and directory structure!
I am a tool to dump and pack newc cpio ("file" calls it "ASCII cpio archive (SVR4 with no CRC)") archives.
See https://manpages.ubuntu.com/manpages/jammy/en/man5/cpio.5.html "New ASCII Format".

some ARCHIVE and DUMP_DIR names won't work, example (bash):
  deno run --allow-read --allow-write cpio_newc_dumper.js dump $'\xee.cpio' asd