News:

HTTPS is back; rejoice if you love security theatre

Main Menu

NS/OS Tar extractor on Linux by Cuby

Started by ptek, Sep 20, 2026, 03:19 AM

Previous topic - Next topic

ptek

This tar file (I assume you extracted the file from the EIDE.pkg installer?) uses a variant of the ancient V7 tar format - see the Wikipedia page under "Pre-POSIX.1-1988 (i.e. v7) tar header" - with different offsets (0xe0 instead of 100).

In theory, GNU tar should be able to handle that file, but it might have problems detecting the format since V7 tar has no identifying magic at the start of the file.

This is a quick and dirty extractor I wrote since I stumbled across this problem before, too... hope it helps.

#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <stdio.h>
#include <stdint.h>
#include <fcntl.h>

int main(int argc, char **argv) {
  uint8_t buf[512];
  int fd;

  fd = open(argv[1], O_RDONLY);

  while(1) {
    int n = read(fd, buf, 512);
    if (n < 512) break;

    char *fn = (char *)buf;
    char *smode = (char *)buf+0xe1;
    int mode;
    sscanf(smode, "%o", &mode);

    char *suid = (char *)buf+0xe9;
    int uid;
    sscanf(suid, "%o", &uid);

    char *sgid = (char *)buf+0xf1;
    int gid;
    sscanf(sgid, "%o", &gid);

    char *ssize = (char *)buf+0xf9;
    int size;
    sscanf(ssize, "%o", &size);

    buf[0x114] = 0;
    char *sts = (char *)buf+0xf9;
    int ts;
    sscanf(sts, "%o", &ts);

    printf("# %s %o %d %d %d\n", fn, mode, uid, gid, size);

    if (size > 0) { // file
      int wfd = open(fn, O_CREAT|O_WRONLY, mode);
      for (int pos = 0; pos < size; pos+=512) {
        int n = read(fd, buf, 512);
        printf("# %d %d %d\n", size, pos, size-pos);
        write(wfd, buf, ((size-pos) >= 512) ? 512 : (size-pos));
      }
      close(wfd);
    } else { // dir
      mkdir(fn, mode);
    }
  }
}

ZombiePhysicist