blob: 3d8c3410dfb5f6d3c5d5afb18855dfa6742d1508 [file] [log] [blame]
Luc Verhaegen57741672009-06-16 23:34:21 +02001/*
2 * Copyright 2009 Luc Verhaegen <libv@skynet.be>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; see the file COPYING. If not, write to
16 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19/*
20 * This code is heavily based on Veit Kannegiesers <veit@kannegieser.net>
21 * e_bcpvpd.pas program. This software comes with no license, but is freely
22 * downloadable at http://kannegieser.net/veit/quelle/phoedeco_src.arj
23 */
24/*
25 * It should be very straightfoward to add support for the $COMPIBM compressed
26 * bios images as well. According to Veits code, the id-string is "$COMPIBM",
27 * and the data starts straight after the (not null-terminated) id-string.
28 */
29
30#define _GNU_SOURCE 1
31
32#include <stdio.h>
33#include <unistd.h>
34#include <fcntl.h>
35#include <errno.h>
36#include <string.h>
37#include <sys/mman.h>
38
Luc Verhaegena2980652009-06-17 14:45:24 +020039#include "lzss_extract.h"
Luc Verhaegen57741672009-06-16 23:34:21 +020040
41int
42main(int argc, char *argv[])
43{
44 int infd, outfd;
45 unsigned char *InputBuffer;
46 int InputBufferSize;
47
48 if (argc != 3) {
49 printf("usage: %s <input file> <output file>\n", argv[0]);
50 return 1;
51 }
52
53 infd = open(argv[1], O_RDONLY);
54 if (infd < 0) {
55 fprintf(stderr, "Error: Failed to open %s: %s\n",
56 argv[1], strerror(errno));
57 return 1;
58 }
59
60 InputBufferSize = lseek(infd, 0, SEEK_END);
61 if (InputBufferSize < 0) {
62 fprintf(stderr, "Error: Failed to lseek \"%s\": %s\n",
63 argv[1], strerror(errno));
64 return 1;
65 }
66
67 InputBuffer = mmap(NULL, InputBufferSize, PROT_READ, MAP_PRIVATE, infd, 0);
68 if (InputBuffer < 0) {
69 fprintf(stderr, "Error: Failed to mmap %s: %s\n",
70 argv[1], strerror(errno));
71 return 1;
72 }
73
74 if (InputBufferSize < 0x52) {
75 fprintf(stderr, "Error: \"%s\" is too small tp be a BCPVPD file.\n",
76 argv[1]);
77 return 1;
78 }
79
80 if (strncmp((char *) InputBuffer, "BCPVPD", 7)) {
81 fprintf(stderr, "Error: unable to find BCPVPD header in \"%s\".\n",
82 argv[1]);
83 return 1;
84 }
85
86 outfd = open(argv[2], O_RDWR | O_TRUNC | O_CREAT, S_IRWXU);
87 if (outfd == -1) {
88 fprintf(stderr, "Error: Failed to open \"%s\": %s\n",
89 argv[2], strerror(errno));
90 return 1;
91 }
92
Luc Verhaegena2980652009-06-17 14:45:24 +020093 return LZSSExtract(InputBuffer + 0x52, InputBufferSize - 0x52, outfd);
Luc Verhaegen57741672009-06-16 23:34:21 +020094}