summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuc Verhaegen <libv@skynet.be>2009-06-24 14:18:29 +0200
committerLuc Verhaegen <libv@skynet.be>2009-06-24 14:18:29 +0200
commit038e6a597ae6efd4a70d25ca3f663c723bee1e4a (patch)
treeb5e5663892d6371a1b1d6ad6fe2d5e9f32762f53
parent08e0bc567048f123bf1eb4921f02b54b060b5c6e (diff)
Add freshly written phoenix.c.
Fully replaces phnxdeco, which then gets removed. Program structure changed though, it always dumps on phoenix, but at the same time prints all sensible information to stdout.
-rw-r--r--Makefile2
-rw-r--r--bios_extract.c2
-rw-r--r--bios_extract.h6
-rw-r--r--phnxdeco/Makefile13
-rw-r--r--phnxdeco/kernel.c386
-rw-r--r--phnxdeco/phnxdeco.c424
-rw-r--r--phnxdeco/phnxdeco.h8
-rw-r--r--phoenix.c240
8 files changed, 248 insertions, 833 deletions
diff --git a/Makefile b/Makefile
index a94a4a4..3339148 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ CC = gcc
all: bios_extract bcpvpd
-BIOS_EXTRACT_OBJS = lh5_extract.o ami.o bios_extract.o
+BIOS_EXTRACT_OBJS = lh5_extract.o phoenix.o ami.o bios_extract.o
bios_extract: $(BIOS_EXTRACT_OBJS)
$(CC) $(CFLAGS) $(BIOS_EXTRACT_OBJS) -o bios_extract
diff --git a/bios_extract.c b/bios_extract.c
index 988f774..2929dab 100644
--- a/bios_extract.c
+++ b/bios_extract.c
@@ -140,6 +140,8 @@ static struct {
Bool Extract, uint32_t Offset1, uint32_t Offset2);
} BIOSIdentification[] = {
{"AMIBOOT ROM", "AMIBIOSC", AMI95Extract},
+ //{"Phoenix FirstBIOS", "BCPSEGMENT", PhoenixExtract},
+ {"PhoenixBIOS 4.0", "BCPSEGMENT", PhoenixExtract},
{NULL, NULL, NULL},
};
diff --git a/bios_extract.h b/bios_extract.h
index 514acda..c0bec92 100644
--- a/bios_extract.h
+++ b/bios_extract.h
@@ -28,6 +28,10 @@ unsigned char *MMapOutputFile(char *filename, int size);
/* ami.c */
Bool AMI95Extract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset,
- Bool Extract, uint32_t AMIBOffset, uint32_t ABCOffset);
+ Bool Extract, uint32_t Offset1, uint32_t Offset2);
+
+/* phoenix.c */
+Bool PhoenixExtract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset,
+ Bool Extract, uint32_t Offset1, uint32_t Offset2);
#endif /* BIOS_EXTRACT_H */
diff --git a/phnxdeco/Makefile b/phnxdeco/Makefile
deleted file mode 100644
index d44c3e7..0000000
--- a/phnxdeco/Makefile
+++ /dev/null
@@ -1,13 +0,0 @@
-CFLAGS = -g -fpack-struct -Wall
-CC = gcc
-
-OBJS = kernel.o phnxdeco.o
-
-all: phnxdeco
-
-clean:
- rm -f *.o
- rm -f phnxdeco
-
-phnxdeco: $(OBJS)
- $(CC) $(CFLAGS) $(OBJS) -o phnxdeco
diff --git a/phnxdeco/kernel.c b/phnxdeco/kernel.c
deleted file mode 100644
index ef527ba..0000000
--- a/phnxdeco/kernel.c
+++ /dev/null
@@ -1,386 +0,0 @@
-/**********************************************
-***
-***
-*** These decompression routines based on
-*** LZHUFF algo from LHA archiver
-***
-***
-***********************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <memory.h>
-
-#include "phnxdeco.h"
-
-#define UCHAR_MAX ((1<<(sizeof(unsigned char)*8))-1)
-#define CHAR_BIT 8
-
-#define CBIT 9
-#define USHRT_BIT 16 /* (CHAR_BIT * sizeof(ushort)) */
-
-#define DICBIT 13
-#define DICSIZ (1 << DICBIT)
-#define MATCHBIT 8
-#define MAXMATCH 256
-#define THRESHOLD 3
-#define NC (UCHAR_MAX + MAXMATCH + 2 - THRESHOLD)
-
-#define NP (DICBIT + 1)
-#define NT (USHRT_BIT + 3)
-#define PBIT 4
-#define TBIT 5
-#define NPT 0x80
-
-static unsigned long origsize, compsize;
-static unsigned long count;
-static unsigned short loc;
-static unsigned char *text;
-
-static unsigned char subbitbuf, bitcount;
-
-static unsigned short crc, bitbuf;
-static int prev_char;
-
-static unsigned short left[2 * NC - 1], right[2 * NC - 1];
-static unsigned char c_len[NC], pt_len[NPT];
-static unsigned short c_table[4096], pt_table[256];
-static unsigned short blocksize;
-
-static FILE *infile, *outfile;
-
-static short c, n, tblsiz, len, depth, maxdepth, avail;
-static unsigned short codeword, bit, *tbl;
-static unsigned char *blen;
-
-/****************************************/
-/* mktbl() */
-/****************************************/
-static short mktbl(void)
-{
- short i;
-
- if (len == depth) {
- while (++c < n)
- if (blen[c] == len) {
- i = codeword;
- codeword += bit;
- if (codeword > tblsiz) {
- printf("\nBad Table!");
- exit(1);
- }
- while (i < codeword)
- tbl[i++] = c;
- return c;
- }
- c = -1;
- len++;
- bit >>= 1;
- }
- depth++;
- if (depth < maxdepth) {
- (void) mktbl();
- (void) mktbl();
- } else if (depth > USHRT_BIT) {
- {
- printf("\nBad Table [2]");
- exit(1);
- }
- } else {
- if ((i = avail++) >= 2 * n - 1) {
- printf("\nBad Table [3]");
- exit(1);
- }
- left[i] = mktbl();
- right[i] = mktbl();
- if (codeword >= tblsiz) {
- printf("\nBad Table [4]");
- exit(1);
- }
- if (depth == maxdepth)
- tbl[codeword++] = i;
- }
- depth--;
- return i;
-}
-
-/****************************************/
-/* make_table() */
-/****************************************/
-static void make_table(short nchar, unsigned char bitlen[], short tablebits, unsigned short table[])
-{
- n = avail = nchar;
- blen = bitlen;
- tbl = table;
- tblsiz = 1U << tablebits;
- bit = tblsiz / 2;
- maxdepth = tablebits + 1;
- depth = len = 1;
- c = -1;
- codeword = 0;
- (void) mktbl(); /* left subtree */
- (void) mktbl(); /* right subtree */
- if (codeword != tblsiz) {
- printf("\nBad Table [5]");
- exit(1);
- }
-}
-
-
-
-/****************************************/
-/* fillbif() */
-/****************************************/
-static void fillbuf(unsigned char n)
-{ /* Shift bitbuf n bits left, read n bits */
- while (n > bitcount) {
- n -= bitcount;
- bitbuf = (bitbuf << bitcount) + (subbitbuf >> (CHAR_BIT - bitcount));
- if (compsize != 0) {
- compsize--;
- subbitbuf = (unsigned char) getc(infile);
- } else
- subbitbuf = 0;
- bitcount = CHAR_BIT;
- }
- bitcount -= n;
- bitbuf = (bitbuf << n) + (subbitbuf >> (CHAR_BIT - n));
- subbitbuf <<= n;
-}
-
-
-/****************************************/
-/* getbits() */
-/****************************************/
-static unsigned short getbits(unsigned char n)
-{
- unsigned short x;
-
- x = bitbuf >> (2 * CHAR_BIT - n);
- fillbuf(n);
- return x;
-}
-
-/****************************************/
-/* fwrite_crc() */
-/****************************************/
-static void fwrite_crc(unsigned char *p, int n, FILE * fp)
-{
-
- if (fp) {
- if (fwrite(p, 1, n, fp) < n) {
- printf("\nFatal Error");
- exit(1);
- }
- }
-}
-
-/****************************************/
-/* init_getbits() */
-/****************************************/
-static void init_getbits(void)
-{
- bitbuf = 0;
- subbitbuf = 0;
- bitcount = 0;
- fillbuf(2 * CHAR_BIT);
-}
-
-
-/********************************************/
-/************* DECODE ***********************/
-
-static void read_pt_len(short nn, short nbit, short i_special)
-{
- short i, c, n;
-
- n = getbits(nbit);
- if (n == 0) {
- c = getbits(nbit);
- for (i = 0; i < nn; i++)
- pt_len[i] = 0;
- for (i = 0; i < 256; i++)
- pt_table[i] = c;
- } else {
- i = 0;
- while (i < n) {
- c = bitbuf >> (16 - 3);
- if (c == 7) {
- unsigned short mask = 1 << (16 - 4);
- while (mask & bitbuf) {
- mask >>= 1;
- c++;
- }
- }
- fillbuf((c < 7) ? 3 : c - 3);
- pt_len[i++] = c;
- if (i == i_special) {
- c = getbits(2);
- while (--c >= 0)
- pt_len[i++] = 0;
- }
- }
- while (i < nn)
- pt_len[i++] = 0;
- make_table(nn, pt_len, 8, pt_table);
- }
-}
-
-static void read_c_len(void)
-{
- short i, c, n;
-
- n = getbits(CBIT);
- if (n == 0) {
- c = getbits(CBIT);
- for (i = 0; i < NC; i++)
- c_len[i] = 0;
- for (i = 0; i < 4096; i++)
- c_table[i] = c;
- } else {
- i = 0;
- while (i < n) {
- c = pt_table[bitbuf >> (16 - 8)];
- if (c >= NT) {
- unsigned short mask = 1 << (16 - 9);
- do {
- if (bitbuf & mask)
- c = right[c];
- else
- c = left[c];
- mask >>= 1;
- } while (c >= NT);
- }
- fillbuf(pt_len[c]);
- if (c <= 2) {
- if (c == 0)
- c = 1;
- else if (c == 1)
- c = getbits(4) + 3;
- else
- c = getbits(CBIT) + 20;
- while (--c >= 0)
- c_len[i++] = 0;
- } else
- c_len[i++] = c - 2;
- }
- while (i < NC)
- c_len[i++] = 0;
- make_table(NC, c_len, 12, c_table);
- }
-}
-
-static unsigned short decode_c_st1(void)
-{
- unsigned short j, mask;
-
- if (blocksize == 0) {
- blocksize = getbits(16);
- read_pt_len(NT, TBIT, 3);
- read_c_len();
- read_pt_len(NP, PBIT, -1);
- }
- blocksize--;
- j = c_table[bitbuf >> 4];
- if (j < NC)
- fillbuf(c_len[j]);
- else {
- fillbuf(12);
- mask = 1 << (16 - 1);
- do {
- if (bitbuf & mask)
- j = right[j];
- else
- j = left[j];
- mask >>= 1;
- } while (j >= NC);
- fillbuf(c_len[j] - 12);
- }
- return j;
-}
-
-static unsigned short decode_p_st1(void)
-{
- unsigned short j, mask;
-
- j = pt_table[bitbuf >> (16 - 8)];
- if (j < NP)
- fillbuf(pt_len[j]);
- else {
- fillbuf(8);
- mask = 1 << (16 - 1);
- do {
- if (bitbuf & mask)
- j = right[j];
- else
- j = left[j];
- mask >>= 1;
- } while (j >= NP);
- fillbuf(pt_len[j] - 8);
- }
- if (j != 0)
- j = (1 << (j - 1)) + getbits(j - 1);
- return j;
-}
-
-static void decode_start_st1(void)
-{
- init_getbits();
- blocksize = 0;
-}
-
-/********end of decode***********************/
-
-void decode(interfacing interface)
-{
- int i, j, k, c, dicsiz1, offset;
-
- infile = interface.infile;
- outfile = interface.outfile;
- origsize = interface.original;
- compsize = interface.packed;
-
- crc = 0;
- prev_char = -1;
-
- text = (unsigned char *) malloc(DICSIZ);
- if (text == NULL)
- exit(1);
-
- memset(text, ' ', DICSIZ);
- decode_start_st1();
-
- dicsiz1 = DICSIZ - 1;
- offset = 0x100 - 3;
- count = 0;
- loc = 0;
- while (count < origsize) {
-
- c = decode_c_st1();
-
- if (c <= UCHAR_MAX) {
- text[loc++] = c;
- if (loc == DICSIZ) {
- fwrite_crc(text, DICSIZ, outfile);
- loc = 0;
- }
- count++;
- } else {
- j = c - offset;
- i = (loc - decode_p_st1() - 1) & dicsiz1;
- count += j;
- for (k = 0; k < j; k++) {
- c = text[(i + k) & dicsiz1];
- text[loc++] = c;
- if (loc == DICSIZ) {
- fwrite_crc(text, DICSIZ, outfile);
- loc = 0;
- }
- }
- }
- }
- if (loc != 0) {
- fwrite_crc(text, loc, outfile);
- }
- free(text);
-}
diff --git a/phnxdeco/phnxdeco.c b/phnxdeco/phnxdeco.c
deleted file mode 100644
index 4d9968d..0000000
--- a/phnxdeco/phnxdeco.c
+++ /dev/null
@@ -1,424 +0,0 @@
-/*
- * Phoenix BIOS Decompress
- *
- * Copyright (C) 2000, 2002, 2003 Anthony Borisow
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <memory.h>
-
-#include "phnxdeco.h"
-
-#define BLOCK 0x8000
-
-#define Xtract 0x10
-#define List 0x11
-
-static unsigned int FoundAt(FILE * ptx, unsigned char *Buf, char *Pattern, unsigned int BLOCK_LEN)
-{
-
- unsigned int i, Ret;
- unsigned short Len;
- Len = strlen(Pattern);
- for (i = 0; i < BLOCK_LEN - 0x80; i++) {
- if (memcmp(Buf + i, Pattern, Len) == 0) {
- Ret = ftell(ptx) - (BLOCK_LEN - i);
- return (Ret);
- }
- }
- return 0;
-}
-struct PhoenixModuleName
-{
- char Id;
- char *Name;
-};
-
-static struct PhoenixModuleName
-PhoenixModuleNames[] = {
- {'A', "ACPI"},
- {'B', "BIOSCODE"},
- {'C', "UPDATE"},
- {'D', "DISPLAY"},
- {'E', "SETUP"},
- {'F', "FONT"},
- {'G', "DECOMPCODE"},
- {'I', "BOOTBLOCK"},
- {'L', "LOGO"},
- {'M', "MISER"},
- {'N', "ROMPILOTLOAD"},
- {'O', "NETWORK"},
- {'P', "ROMPILOTINIT"},
- {'R', "OPROM"},
- {'S', "STRINGS"},
- {'T', "TEMPLATE"},
- {'U', "USER"},
- {'X', "ROMEXEC"},
- {'W', "WAV"},
- {'H', "TCPA_H"}, /* TCPA (Trusted Computing), USBKCLIB? */
- {'K', "TCPA_K"}, /* TCPA (Trusted Computing), "AUTH"? */
- {'Q', "TCPA_Q"}, /* TCPA (Trusted Computing), "SROM"? */
- {'<', "TCPA_<"},
- {'*', "TCPA_*"},
- {'?', "TCPA_?"},
- {'J', "SmartCardPAS"},
-};
-
-static char *
-PhoenixModuleNameGet(char Id)
-{
- int i;
-
- for (i = 0; PhoenixModuleNames[i].Name; i++)
- if (PhoenixModuleNames[i].Id == Id)
- return PhoenixModuleNames[i].Name;
-
- return "";
-}
-
-#define COMPRESSION_NONE 0
-#define COMPRESSION_UNKNOWN 1
-#define COMPRESSION_LZARI 2
-#define COMPRESSION_LZSS 3
-#define COMPRESSION_LZHUF 4
-#define COMPRESSION_LZINT 5
-
-/*
- * This is nothing but the lzss algo, done rather horribly wrong.
- */
-static void decodeM3(FILE *ptx, FILE *bmx, unsigned int RealLen)
-{
- unsigned short Index, Index2, DX, Loop, i;
- unsigned char Buffer[0x1000], tmp;
- unsigned int Now;
-
- memset(Buffer, 0, 0x1000);
-
- DX = 0;
- Index = 0xFEE;
- Now = 0;
-
- for (;;) {
- DX >>= 1;
- if ((DX & 0x100) == 0) {
- if (Now >= RealLen)
- return;
- fread(&tmp, 1, 1, ptx);
- DX = (unsigned short) (0xFF) * 0x100 + tmp;
- };
-
- if ((DX & 0x1) != 0) {
- if (Now++ >= RealLen)
- return;
-
- fread(&tmp, 1, 1, ptx);
- fwrite(&tmp, 1, 1, bmx);
- Buffer[Index++] = tmp;
- Index &= 0xFFF;
- continue;
- };
-
- fread(&Index2, 1, 1, ptx);
- Index2 &= 0xFF;
-
- fread(&tmp, 1, 1, ptx);
-
- Index2 += (tmp & 0xF0) << 4;
- Loop = (tmp & 0xf) + 3;
-
- for (i = 0; i < Loop; i++) {
- tmp = Buffer[Index2++];
- Index2 &= 0xFFF;
- fwrite(&tmp, 1, 1, bmx);
- Buffer[Index++] = tmp;
- Index &= 0xFFF;
- }
-
- Now += Loop;
- }
-
-}
-
-typedef struct {
- unsigned int Prev;
- unsigned char Sig[3];
- unsigned char ID_HI;
- unsigned char ID_LO;
- unsigned char HeadLen;
- unsigned char isPacked;
- unsigned short Offset;
- unsigned short Segment;
- unsigned int ExpLen1;
- unsigned int Packed1;
- unsigned int Packed2;
- unsigned int ExpLen2;
-} PHOENIXHEAD;
-
-typedef struct {
- unsigned char Name[6];
- unsigned short Flags;
- unsigned short Len;
-} PHNXID;
-
-/*
- * Modified Module Detection & Manipulating
- * According to BCPSYS block
- */
-static unsigned char TotalSecM(FILE * ptx, unsigned char * Buf, unsigned char Action, unsigned int Start, unsigned int ConstOff, unsigned int SYSOff)
-{
- FILE *pto;
- unsigned int i;
- unsigned int blkend = 0, blkstart = 0;
- PHOENIXHEAD phhead;
- unsigned char TotalSec = 0;
- unsigned int Offset = Start;
-
- phhead.Prev = 0xFFFF0000;
- fseek(ptx, 0, 2);
-
- if (Action == List)
- printf("\nC I COMP START END LENGTH LINK TO FILEOFFSET");
-
-
- while (phhead.Prev != 0x0 && !feof(ptx)) {
- fseek(ptx, Offset, 0);
- TotalSec++;
- Start = Offset;
- if (Start > 0x100000)
- break;
- fread(&phhead, 1, sizeof(phhead), ptx);
- Offset = phhead.Prev - ConstOff;
-
- blkend = Start + ConstOff + sizeof(PHOENIXHEAD) - 5;
- blkstart = Start + 0xFFF00000;
- switch (Action) {
- case List:
-
- printf("\n%c %.1X %1d %8X %8X %5.X %8X %5.2Xh %05X", phhead.ID_LO, phhead.ID_HI,
- phhead.isPacked, blkstart, blkend + phhead.Packed1, phhead.Packed1, phhead.Prev, Start, phhead.Segment << 16 | phhead.Offset);
-
-
- break;
-
- case Xtract:
- {
- char *modulename = PhoenixModuleNameGet(phhead.ID_LO);
- char filename[64];
-
- snprintf(filename, 64, "%s%1.1X.rom", modulename, phhead.ID_HI);
- printf("\n%c %1.1X -> %s", phhead.ID_LO, phhead.ID_HI, filename);
-
-
- if ((pto = fopen(filename, "wb")) == NULL) {
- printf("\nFile %s I/O error..Exit", filename);
- exit(1);
- }
- }
-
- /* Evidently, isPacked == PackedLevel */
- if (phhead.isPacked == 0x5) {
- interfacing interface;
-
- interface.infile = ptx;
- interface.outfile = pto;
- interface.original = phhead.ExpLen1;
- interface.packed = phhead.Packed1;
-
- decode(interface);
- } else if (phhead.isPacked == 0x3) {
- fseek(ptx, -4L, 1);
- decodeM3(ptx, pto, phhead.ExpLen1);
- } else {
- unsigned char tmp[1];
-
- fseek(ptx, -4L, 1);
- for (i = 0; i < phhead.ExpLen1; i++) {
- fread(tmp, 1, 1, ptx);
- fwrite(tmp, 1, 1, pto);
- };
- }
- fclose(pto);
-
- break;
- }
- }
-
- return (TotalSec);
-}
-
-static unsigned int IsPhoenixBIOS(FILE * ptx, unsigned char * Buf)
-{
-
- unsigned int CurPos = 0;
- char FirstPattern[] = "Phoenix FirstBIOS";
- char PhoenixPattern[] = "PhoenixBIOS 4.0";
-
- rewind(ptx);
- while (!feof(ptx)) {
- fread(Buf, 1, BLOCK, ptx);
- if ((CurPos = FoundAt(ptx, Buf, PhoenixPattern, BLOCK)) != 0)
- break;
- /* O'K, we got PhoenixBIOS 4.0 hook */
- CurPos = ftell(ptx) - 0x100;
- }
-
- if (feof(ptx)) {
- rewind(ptx);
- while (!feof(ptx)) {
- fread(Buf, 1, BLOCK, ptx);
- if ((CurPos = FoundAt(ptx, Buf, FirstPattern, BLOCK)) != 0)
- break;
- /* O'K, we got Phoenix FirstBIOS hook */
- CurPos = ftell(ptx) - 0x100;
- }
-
- /* Neither PhoenixBIOS 4.0 nor FirstBIOS */
- if (feof(ptx))
- return (0);
-
- }
-
- return (CurPos);
-}
-
-int main(int argc, char *argv[])
-{
- FILE *ptx;
- unsigned char Buf[BLOCK];
- unsigned int CurPos, fLen, Start, Offset;
- unsigned int SYSOff;
- char BCPSEGMENT[] = "BCPSEGMENT";
- char phdate[18]; /* "XX/XX/XX\20XX:XX:XX\0" */
- unsigned char TotalSections = 0, Action, Mods = 0;
- PHNXID IDMod;
-
- memset(Buf, 0, BLOCK);
-
- if (argc != 3) {
- printf("wrong usage.\n");
- return 1;
- }
-
- if (!strcmp(argv[1], "x"))
- Action = Xtract;
- else if (!strcmp(argv[1], "l"))
- Action = List;
- else {
- printf("wrong usage.\n");
- return 1;
- }
-
- if ((ptx = fopen(argv[2], "rb")) == NULL) {
- printf("\nFATAL ERROR: File %s opening error...\n", argv[2]);
- return 0;
- };
-
- CurPos = 0;
- IDMod.Name[0] = 0xff;
- IDMod.Len = 0xff;
- SYSOff = 0;
-
- fseek(ptx, 0, 2);
- fLen = ftell(ptx);
- rewind(ptx);
- printf("Filelength\t: %X (%u bytes)\n", fLen, fLen);
- printf("Filename\t: %s\n", argv[2]);
-
- while (!feof(ptx)) {
- fread(Buf, 1, BLOCK, ptx);
- if ((CurPos = FoundAt(ptx, Buf, BCPSEGMENT, BLOCK)) != 0)
- break;
- /* O'K, we got PhoenixBIOS BCPSEGMENT hook */
- CurPos = ftell(ptx) - 0x100;
-
- }
-
- if (feof(ptx)) {
- printf("Searched through file. Not a PhoenixBIOS\n");
- exit(1);
- }
-
- printf("PhoenixBIOS hook found at\t: %X\n", CurPos);
- CurPos += 10;
- fseek(ptx, (unsigned int) (CurPos), 0);
-
- while (IDMod.Name[0] != 0x0 && IDMod.Len != 0x0) {
- fread(&IDMod, 1, sizeof(IDMod), ptx);
-
- /* Wrong Count w/ ALR and some S/N internal errors ? */
- if (IDMod.Name[0] < 0x41 && IDMod.Name[0] != 0x0) {
- do {
- fread(Buf, 1, 1, ptx);
- } while (Buf[0] != 0x42);
- fseek(ptx, -1L, SEEK_CUR);
- CurPos = ftell(ptx);
- fread(&IDMod, 1, sizeof(IDMod), ptx);
- };
-
- if (memcmp(IDMod.Name, "BCPSYS", 6) == 0)
- SYSOff = CurPos;
- CurPos += IDMod.Len;
- fseek(ptx, (unsigned int) (CurPos), 0);
- if (IDMod.Name[0] == 0x0 || IDMod.Name[0] < 0x41)
- break;
- else
- Mods++;
- }
-
- printf("System Information at\t\t: %X\n", SYSOff);
-
- fseek(ptx, SYSOff + 15, 0);
- fread(&phdate, 1, 17, ptx);
- phdate[8] = ' ';
- phdate[17] = 0;
-
- fseek(ptx, SYSOff + 0x77, 0);
- /* Move to the pointer of 1st module */
- fread(&Start, 1, sizeof(Start), ptx);
- Offset = (0xFFFE0000 - (ftell(ptx) & 0xFFFE0000));
- Start -= Offset;
-
- /* Move to the DEVEL string */
- fseek(ptx, SYSOff + 0x37, 0);
- fread(Buf, 1, 8, ptx);
-
- printf("Version\t\t: %8.8s\n", Buf);
- printf("Start\t\t: %X\n", Start);
- printf("Offset\t\t: %X\n", 0xFFFF0000 - Offset);
-
- printf("BCP Modules\t: %i\n", Mods);
-
- printf("Released\t: %s\n", phdate);
-
- CurPos = IsPhoenixBIOS(ptx, Buf);
- fseek(ptx, (unsigned int) (CurPos), 0);
-
- fread(Buf, 1, 0x100, ptx);
-
- printf("\t%.64s\n", Buf);
-
- TotalSections = TotalSecM(ptx, Buf, Action, Start, Offset, SYSOff);
-
- printf("\n");
- printf("Total Sections: %u\n", TotalSections);
-
- fclose(ptx);
-
- printf("\n");
- return 0;
-}
diff --git a/phnxdeco/phnxdeco.h b/phnxdeco/phnxdeco.h
deleted file mode 100644
index 2453471..0000000
--- a/phnxdeco/phnxdeco.h
+++ /dev/null
@@ -1,8 +0,0 @@
-typedef struct {
- FILE *infile;
- FILE *outfile;
- unsigned long original;
- unsigned long packed;
-} interfacing;
-
-void decode(interfacing interface);
diff --git a/phoenix.c b/phoenix.c
new file mode 100644
index 0000000..51ce5b3
--- /dev/null
+++ b/phoenix.c
@@ -0,0 +1,240 @@
+/*
+ * Copyright 2009 Luc Verhaegen <libv@skynet.be>
+ * Copyright 2000-2003 Anthony Borisow
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <stdio.h>
+#include <inttypes.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+
+#include "bios_extract.h"
+#include "lh5_extract.h"
+
+struct PhoenixModuleName
+{
+ char Id;
+ char *Name;
+};
+
+static struct PhoenixModuleName
+PhoenixModuleNames[] = {
+ {'A', "acpi"},
+ {'B', "bioscode"},
+ {'C', "update"},
+ {'D', "display"},
+ {'E', "setup"},
+ {'F', "font"},
+ {'G', "decompcode"},
+ {'I', "bootblock"},
+ {'L', "logo"},
+ {'M', "miser"},
+ {'N', "rompilotload"},
+ {'O', "network"},
+ {'P', "rompilotinit"},
+ {'R', "oprom"},
+ {'S', "strings"},
+ {'T', "template"},
+ {'U', "user"},
+ {'X', "romexec"},
+ {'W', "wav"},
+ {'H', "tcpa_H"}, /* TCPA (Trusted Computing), USBKCLIB? */
+ {'K', "tcpa_K"}, /* TCPA (Trusted Computing), "AUTH"? */
+ {'Q', "tcpa_Q"}, /* TCPA (Trusted Computing), "SROM"? */
+ {'<', "tcpa_<"},
+ {'*', "tcpa_*"},
+ {'?', "tcpa_?"},
+ {'J', "SmartCardPAS"},
+};
+
+static char *
+PhoenixModuleNameGet(char Id)
+{
+ int i;
+
+ for (i = 0; PhoenixModuleNames[i].Name; i++)
+ if (PhoenixModuleNames[i].Id == Id)
+ return PhoenixModuleNames[i].Name;
+
+ return NULL;
+}
+
+static int
+PhoenixModule(unsigned char *BIOSImage, int BIOSLength, int Offset)
+{
+ struct PhoenixModule {
+ uint32_t Previous;
+ uint8_t Signature[3];
+ uint8_t Id;
+ uint8_t Type;
+ uint8_t HeadLen;
+ uint8_t Compression;
+ uint16_t Offset;
+ uint16_t Segment;
+ uint32_t ExpLen1;
+ uint32_t Packed1;
+ uint32_t Packed2;
+ uint32_t ExpLen2;
+ } *Module;
+ char *filename, *ModuleName;
+ unsigned char *Buffer;
+ int fd;
+
+ Module = (struct PhoenixModule *) (BIOSImage + Offset);
+
+ if (Module->Signature[0] || (Module->Signature[1] != 0x31) ||
+ (Module->Signature[2] != 0x31)) {
+ fprintf(stderr, "Error: Invalid module signature at 0x%05X\n",
+ Offset);
+ return 0;
+ }
+
+ if ((Offset + Module->HeadLen + 4 + Module->Packed1) > BIOSLength) {
+ fprintf(stderr, "Error: Module overruns buffer at 0x%05X\n",
+ Offset);
+ return Module->Previous;
+ }
+
+ ModuleName = PhoenixModuleNameGet(Module->Type);
+ if (ModuleName) {
+ filename = malloc(strlen(ModuleName) + 7);
+ sprintf(filename, "%s_%1d.rom", ModuleName, Module->Id);
+ } else {
+ filename = malloc(9);
+ sprintf(filename, "%02X_%1d.rom", Module->Type, Module->Id);
+ }
+
+ fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
+ if (fd < 0) {
+ fprintf(stderr, "Error: unable to open %s: %s\n\n",
+ filename, strerror(errno));
+ free(filename);
+ return Module->Previous;
+ }
+
+ switch (Module->Compression) {
+ case 5: /* LH5 */
+ printf("0x%05X (%6d bytes) -> %s\t(%d bytes)", Offset + Module->HeadLen + 4,
+ Module->Packed1, filename, Module->ExpLen1);
+
+ Buffer = MMapOutputFile(filename, Module->ExpLen1);
+ if (!Buffer)
+ break;
+
+ LH5Decode(BIOSImage + Offset + Module->HeadLen + 4,
+ Module->Packed1, Buffer, Module->ExpLen1);
+
+ munmap(Buffer, Module->ExpLen1);
+
+ break;
+ /* case 3 */ /* LZSS */
+ case 0: /* not compressed at all */
+ /* why do we not use the full header here? */
+ printf("0x%05X (%6d bytes) -> %s", Offset + Module->HeadLen,
+ Module->Packed1, filename);
+
+ write(fd, BIOSImage + Offset + Module->HeadLen, Module->Packed1);
+ break;
+ default:
+ fprintf(stderr, "Unsupported compression type for %s: %d\n",
+ filename, Module->Compression);
+ printf("0x%05X (%6d bytes) -> %s\t(%d bytes)", Offset + Module->HeadLen + 4,
+ Module->Packed1, filename, Module->ExpLen1);
+
+ write(fd, BIOSImage + Offset + Module->HeadLen + 4, Module->Packed1);
+ break;
+ }
+
+ close(fd);
+ free(filename);
+
+ if (Module->Offset || Module->Segment) {
+ if (!Module->Compression)
+ printf("\t\t");
+ printf("\t [0x%04X:0x%04X]\n", Module->Segment << 12, Module->Offset);
+ } else
+ printf("\n");
+
+ return Module->Previous;
+}
+
+/*
+ *
+ */
+Bool
+PhoenixExtract(unsigned char *BIOSImage, int BIOSLength, int BIOSOffset,
+ Bool Extract, uint32_t Offset1, uint32_t BCPSegmentOffset)
+{
+ struct PhoenixID {
+ char Name[6];
+ uint16_t Flags;
+ uint16_t Length;
+ } *ID;
+ uint32_t Offset;
+
+ printf("Found Phoenix BIOS \"%s\"\n", (char *) (BIOSImage + Offset1));
+
+ for (ID = (struct PhoenixID *) (BIOSImage + BCPSegmentOffset + 10);
+ ((void *) ID < (void *) (BIOSImage + BIOSLength)) && ID->Name[0];
+ ID = (struct PhoenixID *) (((unsigned char *) ID) + ID->Length)) {
+#if 0
+ printf("PhoenixID: Name %c%c%c%c%c%c, Flags 0x%04X, Length %d\n",
+ ID->Name[0], ID->Name[1], ID->Name[2], ID->Name[3],
+ ID->Name[4], ID->Name[5], ID->Flags, ID->Length);
+#endif
+ if (!strncmp(ID->Name, "BCPSYS", 6))
+ break;
+ }
+
+ if (!ID->Name[0] || ((void *) ID >= (void *) (BIOSImage + BIOSLength))) {
+ fprintf(stderr, "Error: Failed to locate BCPSYS offset.\n");
+ return FALSE;
+ }
+
+ /* Get some info */
+ {
+ char Date[9], Time[9], Version[9];
+
+ strncpy(Date, ((char *) ID) + 0x0F, 8);
+ Date[8] = 0;
+ strncpy(Time, ((char *) ID) + 0x18, 8);
+ Time[8] = 0;
+ strncpy(Version, ((char *) ID) + 0x37, 8);
+ Version[8] = 0;
+
+ printf("Version \"%s\", created on %s at %s.\n", Version, Date, Time);
+ }
+
+ Offset = *((uint32_t *) (((char *) ID) + 0x77));
+ Offset &= (BIOSLength - 1);
+ if (!Offset) {
+ fprintf(stderr, "Error: retrieved invalid Modules offset.\n");
+ return FALSE;
+ }
+
+ while (Offset) {
+ Offset = PhoenixModule(BIOSImage, BIOSLength, Offset);
+ Offset &= BIOSLength - 1;
+ }
+
+ return TRUE;
+}