blob: 479cfce18e3cac1f38733b26679a390cd677f226 [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
26#include "bios_extract.h"
27#include "lh5_extract.h"
28
29/*
30 *
31 */
32Bool
33AwardExtract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset,
34 uint32_t Offset1, uint32_t BCPSegmentOffset)
35{
36 unsigned char *p, *Buffer;
37 int HeaderSize;
38 unsigned int BufferSize, PackedSize;
39 char *filename;
40 unsigned short crc;
41
42 printf("Found Award BIOS.\n");
43
44 p = BIOSImage;
45 while (p) {
46 p = memmem(p, BIOSLength - (p - BIOSImage), "-lh5-", 5);
47 if (!p)
48 break;
49 p -= 2;
50 HeaderSize = LH5HeaderParse(p, BIOSLength - (p - BIOSImage),
51 &BufferSize, &PackedSize, &filename, &crc);
52 if (!HeaderSize)
53 return FALSE;
54
55 printf("0x%05X (%6d bytes) -> %s \t(%6d bytes)\n",
56 (unsigned int) (p - BIOSImage), HeaderSize + PackedSize,
57 filename, BufferSize);
58
59 Buffer = MMapOutputFile(filename, BufferSize);
60 if (!Buffer)
61 return FALSE;
62
63 LH5Decode(p + HeaderSize, PackedSize, Buffer, BufferSize);
64
65 munmap(Buffer, BufferSize);
66
67 p += HeaderSize + PackedSize;
68 }
69
70 return TRUE;
71}