blob: 2c32aed91d47ac894fcf11061f8557489ca10de5 [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
Anton Kochkov8f9427f2013-04-07 13:20:30 +040019#define _GNU_SOURCE 1 /* for memmem */
Luc Verhaegen5c343ad2009-07-13 11:46:37 +020020
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{
Anton Kochkov8f9427f2013-04-07 13:20:30 +040037 unsigned char *p, *Buffer;
38 int HeaderSize;
39 unsigned int BufferSize, PackedSize;
40 char *filename;
41 unsigned short crc;
Luc Verhaegen5c343ad2009-07-13 11:46:37 +020042
Anton Kochkov8f9427f2013-04-07 13:20:30 +040043 printf("Found Award BIOS.\n");
Luc Verhaegen5c343ad2009-07-13 11:46:37 +020044
Anton Kochkov8f9427f2013-04-07 13:20:30 +040045 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,
53 &crc);
54 if (!HeaderSize)
55 return FALSE;
Luc Verhaegen5c343ad2009-07-13 11:46:37 +020056
Anton Kochkov8f9427f2013-04-07 13:20:30 +040057 printf("0x%05X (%6d bytes) -> %s \t(%6d bytes)\n",
58 (unsigned int)(p - BIOSImage), HeaderSize + PackedSize,
59 filename, BufferSize);
Luc Verhaegen5c343ad2009-07-13 11:46:37 +020060
Anton Kochkov8f9427f2013-04-07 13:20:30 +040061 Buffer = MMapOutputFile(filename, BufferSize);
62 if (!Buffer)
63 return FALSE;
Luc Verhaegen5c343ad2009-07-13 11:46:37 +020064
Anton Kochkov8f9427f2013-04-07 13:20:30 +040065 LH5Decode(p + HeaderSize, PackedSize, Buffer, BufferSize);
Luc Verhaegen5c343ad2009-07-13 11:46:37 +020066
Anton Kochkov8f9427f2013-04-07 13:20:30 +040067 munmap(Buffer, BufferSize);
Luc Verhaegen5c343ad2009-07-13 11:46:37 +020068
Anton Kochkov8f9427f2013-04-07 13:20:30 +040069 p += HeaderSize + PackedSize;
70 }
Luc Verhaegen5c343ad2009-07-13 11:46:37 +020071
Anton Kochkov8f9427f2013-04-07 13:20:30 +040072 return TRUE;
Luc Verhaegen5c343ad2009-07-13 11:46:37 +020073}