blob: 3108beaf3b780ed4045f79f1b0028c6c09ded200 [file] [log] [blame]
Luc Verhaegen5c343ad2009-07-13 11:46:37 +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#define _GNU_SOURCE 1 /* for memmem */
20
21#include <stdio.h>
22#include <inttypes.h>
23#include <string.h>
24#include <sys/mman.h>
25
Stefan Reinauer6ed57e52010-04-24 01:15:17 +020026#include "compat.h"
Luc Verhaegen5c343ad2009-07-13 11:46:37 +020027#include "bios_extract.h"
28#include "lh5_extract.h"
29
30/*
31 *
32 */
33Bool
34AwardExtract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset,
35 uint32_t Offset1, uint32_t BCPSegmentOffset)
36{
37 unsigned char *p, *Buffer;
38 int HeaderSize;
39 unsigned int BufferSize, PackedSize;
40 char *filename;
41 unsigned short crc;
42
43 printf("Found Award BIOS.\n");
44
45 p = BIOSImage;
46 while (p) {
47 p = memmem(p, BIOSLength - (p - BIOSImage), "-lh5-", 5);
48 if (!p)
49 break;
50 p -= 2;
51 HeaderSize = LH5HeaderParse(p, BIOSLength - (p - BIOSImage),
52 &BufferSize, &PackedSize, &filename, &crc);
53 if (!HeaderSize)
54 return FALSE;
55
56 printf("0x%05X (%6d bytes) -> %s \t(%6d bytes)\n",
57 (unsigned int) (p - BIOSImage), HeaderSize + PackedSize,
58 filename, BufferSize);
59
60 Buffer = MMapOutputFile(filename, BufferSize);
61 if (!Buffer)
62 return FALSE;
63
64 LH5Decode(p + HeaderSize, PackedSize, Buffer, BufferSize);
65
66 munmap(Buffer, BufferSize);
67
68 p += HeaderSize + PackedSize;
69 }
70
71 return TRUE;
72}