Luc Verhaegen | 5c343ad | 2009-07-13 11:46:37 +0200 | [diff] [blame] | 1 | /* |
| 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 Kochkov | 8f9427f | 2013-04-07 13:20:30 +0400 | [diff] [blame^] | 19 | #define _GNU_SOURCE 1 /* for memmem */ |
Luc Verhaegen | 5c343ad | 2009-07-13 11:46:37 +0200 | [diff] [blame] | 20 | |
| 21 | #include <stdio.h> |
| 22 | #include <inttypes.h> |
| 23 | #include <string.h> |
| 24 | #include <sys/mman.h> |
| 25 | |
Stefan Reinauer | 6ed57e5 | 2010-04-24 01:15:17 +0200 | [diff] [blame] | 26 | #include "compat.h" |
Luc Verhaegen | 5c343ad | 2009-07-13 11:46:37 +0200 | [diff] [blame] | 27 | #include "bios_extract.h" |
| 28 | #include "lh5_extract.h" |
| 29 | |
| 30 | /* |
| 31 | * |
| 32 | */ |
| 33 | Bool |
| 34 | AwardExtract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset, |
| 35 | uint32_t Offset1, uint32_t BCPSegmentOffset) |
| 36 | { |
Anton Kochkov | 8f9427f | 2013-04-07 13:20:30 +0400 | [diff] [blame^] | 37 | unsigned char *p, *Buffer; |
| 38 | int HeaderSize; |
| 39 | unsigned int BufferSize, PackedSize; |
| 40 | char *filename; |
| 41 | unsigned short crc; |
Luc Verhaegen | 5c343ad | 2009-07-13 11:46:37 +0200 | [diff] [blame] | 42 | |
Anton Kochkov | 8f9427f | 2013-04-07 13:20:30 +0400 | [diff] [blame^] | 43 | printf("Found Award BIOS.\n"); |
Luc Verhaegen | 5c343ad | 2009-07-13 11:46:37 +0200 | [diff] [blame] | 44 | |
Anton Kochkov | 8f9427f | 2013-04-07 13:20:30 +0400 | [diff] [blame^] | 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, |
| 53 | &crc); |
| 54 | if (!HeaderSize) |
| 55 | return FALSE; |
Luc Verhaegen | 5c343ad | 2009-07-13 11:46:37 +0200 | [diff] [blame] | 56 | |
Anton Kochkov | 8f9427f | 2013-04-07 13:20:30 +0400 | [diff] [blame^] | 57 | printf("0x%05X (%6d bytes) -> %s \t(%6d bytes)\n", |
| 58 | (unsigned int)(p - BIOSImage), HeaderSize + PackedSize, |
| 59 | filename, BufferSize); |
Luc Verhaegen | 5c343ad | 2009-07-13 11:46:37 +0200 | [diff] [blame] | 60 | |
Anton Kochkov | 8f9427f | 2013-04-07 13:20:30 +0400 | [diff] [blame^] | 61 | Buffer = MMapOutputFile(filename, BufferSize); |
| 62 | if (!Buffer) |
| 63 | return FALSE; |
Luc Verhaegen | 5c343ad | 2009-07-13 11:46:37 +0200 | [diff] [blame] | 64 | |
Anton Kochkov | 8f9427f | 2013-04-07 13:20:30 +0400 | [diff] [blame^] | 65 | LH5Decode(p + HeaderSize, PackedSize, Buffer, BufferSize); |
Luc Verhaegen | 5c343ad | 2009-07-13 11:46:37 +0200 | [diff] [blame] | 66 | |
Anton Kochkov | 8f9427f | 2013-04-07 13:20:30 +0400 | [diff] [blame^] | 67 | munmap(Buffer, BufferSize); |
Luc Verhaegen | 5c343ad | 2009-07-13 11:46:37 +0200 | [diff] [blame] | 68 | |
Anton Kochkov | 8f9427f | 2013-04-07 13:20:30 +0400 | [diff] [blame^] | 69 | p += HeaderSize + PackedSize; |
| 70 | } |
Luc Verhaegen | 5c343ad | 2009-07-13 11:46:37 +0200 | [diff] [blame] | 71 | |
Anton Kochkov | 8f9427f | 2013-04-07 13:20:30 +0400 | [diff] [blame^] | 72 | return TRUE; |
Luc Verhaegen | 5c343ad | 2009-07-13 11:46:37 +0200 | [diff] [blame] | 73 | } |