diff options
author | Pixel <Pixel> | 2002-07-14 17:00:53 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2002-07-14 17:00:53 +0000 |
commit | 50dbdbd466572928a619554e5c756bd52c415597 (patch) | |
tree | 121b0f0af6be3ec5288c1e8e7f01a2b839e611e7 /VP/unarc.cpp | |
parent | feeefcebf8053dc21a396c26c17a9f5fdbf90aff (diff) |
Plop
Diffstat (limited to 'VP/unarc.cpp')
-rw-r--r-- | VP/unarc.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/VP/unarc.cpp b/VP/unarc.cpp new file mode 100644 index 0000000..5699260 --- /dev/null +++ b/VP/unarc.cpp @@ -0,0 +1,76 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include "fileutils.h" +#include "generic.h" + +#define THRESHOLD 2000 + +int main(int argc, char ** argv) { + int h, o, n, * index, * sizes, i, d; + char temp[100]; + + verbosity = M_INFO; + + if (argc != 2) { + printm(M_BARE, "Usage: unarc <archive>\n"); + exit(-1); + } + + if ((h = open(argv[1], O_RDONLY)) < 0) { + printm(M_ERROR, "Unable to open archive file: %s\n", argv[1]); + exit(-1); + } + + read(h, &n, 4); + + printm(M_STATUS, "Archive claims to have %i files, checking integrity.\n", n); + + if (n > THRESHOLD) { + printm(M_ERROR, "Archive has more than %i files, that doesn't make sense to me.\n", THRESHOLD); + exit(-1); + } + + index = (int *) malloc(n * sizeof(int)); + sizes = (int *) malloc(n * sizeof(int)); + + for (i = 0; i < n; i++) { + lseek(h, (i + 1) * 8 + 4, SEEK_SET); + read(h, &(sizes[i]), 4); + printm(M_INFO, "File #%i size = %i = 0x%08x\n", i, sizes[i], sizes[i]); + } + + index[0] = (n + 1) * 8; + i = 0; + printm(M_INFO, "Index #%i = %i = 0x%08x\n", i, index[i], index[i]); + + for (i = 1; i < n; i++) { + index[i] = index[i - 1] + sizes[i - 1]; + printm(M_INFO, "Index #%i = %i = 0x%08x\n", i, index[i], index[i]); + } + + d = filesize(h) - index[n - 1] - sizes[n - 1]; + + printm(M_INFO, "Archive size: %i, last index: %i, last file size: %i, difference = %i\n", filesize(h), index[n - 1], sizes[n - 1], d); + + if ((d < 0) || (d > 2048)) { + printm(M_ERROR, "Archive incoherent.\n"); + exit(-1); + } + + printm(M_STATUS, "Archive seems to be ok, extracting.\n"); + + for (i = 0; i < n; i++) { + sprintf(temp, "%04i.out", i); + o = open(temp, O_WRONLY | O_CREAT | O_TRUNC, 0666); + + printm(M_INFO, "Extracting %s\n", temp); + + lseek(h, index[i], SEEK_SET); + copy(h, o, sizes[i]); + close(o); + } + + exit(0); +} |