summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuc Verhaegen <libv@skynet.be>2009-06-16 15:50:29 +0200
committerLuc Verhaegen <libv@skynet.be>2009-06-17 14:47:06 +0200
commite21b0e10387d320ee330e9edc49527afe4eb41e7 (patch)
tree46d56cae483a1800744639b8c343b410a26739fd
parent1315850342e43fe80810fbd735a14f0aa2d377a3 (diff)
Move phnxfunc into phnxdeco and further cleanups.
-rw-r--r--phnxdeco/Makefile2
-rw-r--r--phnxdeco/phnxdeco.c507
-rw-r--r--phnxdeco/phnxdeco.h55
-rw-r--r--phnxdeco/phnxfunc.c432
4 files changed, 434 insertions, 562 deletions
diff --git a/phnxdeco/Makefile b/phnxdeco/Makefile
index e5c9f85..d44c3e7 100644
--- a/phnxdeco/Makefile
+++ b/phnxdeco/Makefile
@@ -1,7 +1,7 @@
CFLAGS = -g -fpack-struct -Wall
CC = gcc
-OBJS= phnxfunc.o kernel.o phnxdeco.o
+OBJS = kernel.o phnxdeco.o
all: phnxdeco
diff --git a/phnxdeco/phnxdeco.c b/phnxdeco/phnxdeco.c
index 5f9e856..b180f09 100644
--- a/phnxdeco/phnxdeco.c
+++ b/phnxdeco/phnxdeco.c
@@ -24,32 +24,18 @@
#include "phnxdeco.h"
-#define SftPlatform "Linux"
-#define SftVersion "0.33 ("SftPlatform")"
-#define SftName "PhoenixDeco"
-#define SftEMail "Anton Borisov, anton.borisov@gmail.com"
+#define BLOCK 0x8000
-static char SoftName[] = "-=" SftName ", version " SftVersion "=-";
-static char CopyRights[] = "\n(C) Anton Borisov, 2000, 2002-2004, Portions (C) 1999-2000";
-static char Url[] = "Bug-reports direct to " SftEMail;
+#define Xtract 0x10
+#define List 0x11
+#define XtractM 0x20
+#define ListM 0x21
static unsigned char HelpSystem(int argc, char *argv[])
{
unsigned char x = 0, retcode = 0;
for (x = 1; x < argc; x++) {
- if (strcmp(argv[x], "-h") == 0) {
- printf("\n" SftName " HelpSystem Starting Now!\n");
- printf("\nThis Program Version Number %s", SftVersion);
- printf("\n" SftName " - Decompressor for PhoenixBIOSes only.\n" "\tSupported formats: Phoenix BIOS 4.0, Phoenix FirstBIOS\n\n" "" SftName
- " performs on 386 or better CPU systems\n" "under control of LinuxOS\n\n" "Compression schemes include: NONE, LZSS, LZINT\n\n"
- "Modules marked with " IDSign " sign are compressed modules\n\n" "\tBug reports mailto: " SftEMail "\n" "\t\tCompiled: %s, %s with \n\t\t%s",
- __DATE__, __TIME__, __VERSION__);
- printf("\n");
- retcode = 0x80;
-
- }
-
if (strcmp(argv[x], "-xs") == 0)
retcode = 0x20;
if (strcmp(argv[x], "-ls") == 0)
@@ -58,30 +44,444 @@ static unsigned char HelpSystem(int argc, char *argv[])
retcode = 0x10;
if (strcmp(argv[x], "-l") == 0)
retcode = 0x11;
- if (strcmp(argv[x], "-c") == 0)
- retcode += 0x40;
}
return (retcode);
}
-static void PrintHeader(char * EOL)
+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;
+}
+
+static char *GetModuleName(char ID)
+{
+ switch (ID) {
+ case 'A':
+ return ("ACPI");
+ case 'B':
+ return ("BIOSCODE");
+ case 'C':
+ return ("UPDATE");
+ case 'D':
+ return ("DISPLAY");
+ case 'E':
+ return ("SETUP");
+ case 'F':
+ return ("FONT");
+ case 'G':
+ return ("DECOMPCODE");
+ case 'I':
+ return ("BOOTBLOCK");
+ case 'L':
+ return ("LOGO");
+ case 'M':
+ return ("MISER");
+ case 'N':
+ return ("ROMPILOTLOAD");
+ case 'O':
+ return ("NETWORK");
+ case 'P':
+ return ("ROMPILOTINIT");
+ case 'R':
+ return ("OPROM");
+ case 'S':
+ return ("STRINGS");
+ case 'T':
+ return ("TEMPLATE");
+ case 'U':
+ return ("USER");
+ case 'X':
+ return ("ROMEXEC");
+ case 'W':
+ return ("WAV");
+
+ case 'H':
+ return ("TCPA_H"); /* TCPA (Trust Computing), USBKCLIB? */
+ case 'K':
+ return ("TCPA_K"); /* TCPA (Trust Computing), "AUTH"? */
+ case 'Q':
+ return ("TCPA_Q"); /* TCPA (Trust Computing), "SROM"? */
+ case '<':
+ return ("TCPA_<");
+ case '*':
+ return ("TCPA_*");
+ case '?':
+ return ("TCPA_?");
+
+ case 'J':
+ return ("SmartCardPAS");
+
+ default:
+ return ("User-Defined");
+ }
+}
+
+static char *GetCompressionName(unsigned char ID)
+{
+ switch (ID) {
+ case 0x0:
+ return ("NONE");
+ case 0x2:
+ return ("LZARI");
+ case 0x3:
+ return ("LZSS");
+ case 0x4:
+ return ("LZHUF");
+ case 0x5:
+ return ("LZINT");
+ default:
+ return ("RSRV!");
+ }
+}
+
+static void decodeM3(interfacing interface)
+{
+ FILE *ptx, *bmx;
+ unsigned short Index, Index2, DX, Loop, XorOp, i;
+ unsigned char *Buffer, tmp;
+ unsigned int RealLen, Now;
+
+ ptx = interface.infile;
+ bmx = interface.outfile;
+ RealLen = interface.original;
+
+ Buffer = (unsigned char *) calloc(4096, 1);
+ if (!Buffer)
+ return;
+
+ DX = 0;
+ Index = 0xFEE;
+ Now = 0;
+
+ for (;;) {
+ DX >>= 1;
+ if ((DX & 0x100) == 0) {
+ if (Now >= RealLen) {
+ free(Buffer);
+ return;
+ }
+ fread(&tmp, 1, 1, ptx);
+ DX = (unsigned short) (0xFF) * 0x100 + tmp;
+ };
+
+ if ((DX & 0x1) != 0) {
+ if (Now++ >= RealLen) {
+ free(Buffer);
+ return;
+ }
+ fread(&tmp, 1, 1, ptx);
+ fwrite(&tmp, 1, 1, bmx);
+ Buffer[Index++] = tmp;
+ Index &= 0xFFF;
+ continue;
+ };
+
+ Index2 = Index;
+ if (Now >= RealLen) {
+ free(Buffer);
+ return;
+ }
+ fread(&tmp, 1, 1, ptx);
+ Index = (unsigned short) tmp;
+ if (Now >= RealLen) {
+ free(Buffer);
+ return;
+ }
+ fread(&tmp, 1, 1, ptx);
+ Loop = (unsigned short) tmp & 0xf;
+ Loop += 3;
+ XorOp = (unsigned short) tmp & 0xf0;
+ XorOp <<= 4;
+ Index |= XorOp;
+ for (i = 0; i < Loop; i++) {
+ tmp = Buffer[Index++];
+ Index &= 0xFFF;
+ fwrite(&tmp, 1, 1, bmx);
+ Buffer[Index2++] = tmp;
+ Index2 &= 0xFFF;
+ }
+
+ Now += Loop;
+ Index = Index2;
+ }
+
+}
+
+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;
+
+static unsigned char TotalSec(FILE * ptx, unsigned char * Buf, unsigned char Action, unsigned int BankSize)
+{
+ FILE *pto;
+ interfacing interface;
+ char Buffer[12];
+
+ unsigned int CurPos = 0;
+ unsigned int RealRead = 0, i, TotalRead = 0, Tmp;
+ char Head[] = { '\x31', '\x31', '\x0' };
+ PHOENIXHEAD phhead;
+ unsigned int End = 0xFFFFFFFF;
+ unsigned char TotalSec = 0;
+
+
+ switch (Action) {
+ case List:
+
+ printf("+------------------------------------------------------------------------------+\n"
+ "| Class.Instance (Name) Packed ---> Expanded Compression Offset |\n"
+ "+------------------------------------------------------------------------------+\n");
+ };
+
+ fseek(ptx, 0, 2);
+ End = ftell(ptx);
+ rewind(ptx);
+ while ((!feof(ptx)) && (CurPos < BankSize)) {
+ fseek(ptx, CurPos, 0);
+ RealRead = fread(Buf, 1, BLOCK, ptx);
+ TotalRead += RealRead;
+ if (RealRead != BLOCK) {
+ for (i = RealRead; i < BLOCK; i++)
+ Buf[i] = 0xFF;
+ }
+
+ if (RealRead < 0x80)
+ break;
+ if ((CurPos = FoundAt(ptx, Buf, Head, RealRead)) != 0) {
+ fseek(ptx, CurPos - 1 - 4, 0);
+ TotalSec++;
+ fread(&phhead, 1, sizeof(phhead), ptx);
+ if ((phhead.ID_HI >= 0x0 && phhead.ID_HI <= 0x20) && (phhead.ID_LO <= 0x60) && phhead.Sig[0] == '\x0') {
+ switch (Action) {
+ case List:
+
+
+ printf("\n %c.%.2X (%12.12s) %5.5X (%5.5u) => %5.5X (%6.3u) %5.5s (%3.1i%%) %5.2Xh", phhead.ID_LO, phhead.ID_HI,
+ GetModuleName(phhead.ID_LO), phhead.Packed1, phhead.Packed1, phhead.ExpLen1, phhead.ExpLen1, GetCompressionName(phhead.isPacked),
+ (unsigned int) 100 * (unsigned int) phhead.Packed1 / (unsigned int) phhead.ExpLen1, CurPos);
+ break;
+
+ case Xtract:
+ if (phhead.isPacked == 0)
+ sprintf(Buffer, "phoenix0.%C%.1X", phhead.ID_LO, phhead.ID_HI);
+ else
+ sprintf(Buffer, "phoenix_.%C%.1X", phhead.ID_LO, phhead.ID_HI);
+
+ printf("%C.%.2X :: Saving %s ...", phhead.ID_LO, phhead.ID_HI, Buffer);
+ if ((pto = fopen(Buffer, "wb")) == NULL) {
+ printf("\nFile %s I/O error..Exit", Buf);
+ exit(1);
+ }
+
+ interface.infile = ptx;
+ interface.outfile = pto;
+ interface.original = phhead.ExpLen1;
+ interface.packed = phhead.Packed1;
+
+ interface.dicbit = 13;
+ interface.method = 5;
+
+ /* isPacked == PackedLevel == CompressionName */
+ if (phhead.isPacked == 0x5)
+ decode(interface);
+ else if (phhead.isPacked == 0x3) {
+ fseek(ptx, -4L, 1);
+ decodeM3(interface);
+ } else {
+ fseek(ptx, -4L, 1);
+ for (i = 0; i < phhead.ExpLen1; i++) {
+ fread(&Buffer[0], 1, 1, ptx);
+ fwrite(&Buffer[0], 1, 1, pto);
+ };
+ }
+ fclose(pto);
+
+ printf("Done\n");
+
+ break;
+ }
+
+ } else {
+ TotalSec--;
+ fseek(ptx, CurPos + 1, 0);
+ RealRead = fread(Buf, 1, BLOCK, ptx);
+ if ((Tmp = FoundAt(ptx, Buf, Head, RealRead)) == 0)
+ CurPos = ftell(ptx) - 80;
+ else
+ CurPos = Tmp;
+ continue;
+ }
+ CurPos += phhead.Packed1;
+
+ } else
+ CurPos = ftell(ptx);
+ }
+
+ return (TotalSec);
+}
+
+
+/*
+ * 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;
+ interfacing interface;
+ char Buffer[12];
- printf("\n%c%s%c%s", 0x4, SoftName, 0x4, EOL);
+ 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);
+
+ switch (Action) {
+ case ListM:
+
+ printf("\n================================== MODULE MAP =================================" "\nClass Code" "\n. Instance" "\n. ."
+ "\nC I LEVEL START END LENGTH RATIO LINK TO FILEOFFSET"
+ "\n---- ----- --------- --------- ------ ----- --------- ----------");
+ };
+
+
+ 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 ListM:
+
+ printf("\n%c %.1X %5.5s %4.4X %4.4X %4.4X %4.4X %5.X %3.1i%% %4.4X %4.4X %5.2Xh", phhead.ID_LO, phhead.ID_HI,
+ GetCompressionName(phhead.isPacked), blkstart >> 0x10, blkstart & 0xFFFF, (blkend + phhead.Packed1) >> 0x10,
+ (blkend + phhead.Packed1) & 0xFFFF, phhead.Packed1, (unsigned int) 100 * (unsigned int) phhead.Packed1 / (unsigned int) phhead.ExpLen1, phhead.Prev >> 0x10,
+ phhead.Prev & 0xFFFF, Start);
+
+
+ break;
+
+ case XtractM:
+
+ printf("\n%c.%1.1X", phhead.ID_LO, phhead.ID_HI);
+ sprintf(Buffer, "%s", GetModuleName(phhead.ID_LO));
+
+ if (strlen(Buffer) > 7)
+ sprintf(Buffer, "%7.7s%1.1X.rom", GetModuleName(phhead.ID_LO), phhead.ID_HI);
+ else {
+ sprintf(Buffer, "%s%1.1X.rom", GetModuleName(phhead.ID_LO), phhead.ID_HI);
+ }
+
+ printf(" %-12.12s ... O'k", Buffer);
+
+
+ if ((pto = fopen(Buffer, "wb")) == NULL) {
+ printf("\nFile %s I/O error..Exit", Buf);
+ exit(1);
+ }
+
+
+ interface.infile = ptx;
+ interface.outfile = pto;
+ interface.original = phhead.ExpLen1;
+ interface.packed = phhead.Packed1;
+
+ interface.dicbit = 13;
+ interface.method = 5;
+
+ /* Evidently, isPacked == PackedLevel */
+ if (phhead.isPacked == 0x5)
+ decode(interface);
+ else if (phhead.isPacked == 0x3) {
+ fseek(ptx, -4L, 1);
+ decodeM3(interface);
+ } else {
+ fseek(ptx, -4L, 1);
+ for (i = 0; i < phhead.ExpLen1; i++) {
+ fread(&Buffer[0], 1, 1, ptx);
+ fwrite(&Buffer[0], 1, 1, pto);
+ };
+ }
+ fclose(pto);
+
+ break;
+ }
+ }
+
+ return (TotalSec);
}
-static void PrintUsage()
+static unsigned int IsPhoenixBIOS(FILE * ptx, unsigned char * Buf)
{
- PrintHeader("");
- printf("%s", CopyRights);
- printf("\n\nUsage: PhnxDeco <PhoenixBIOS.ROM> [Options]");
- printf("\n" "\t\tOptions:" "\n\t\t\t\"-ls\" List (System) Bios Structure" "\n\t\t\t\"-xs\" eXtract (System) Bios Modules"
- "\n\t\t\t\"-l\" List Bios Structure" "\n\t\t\t\"-x\" eXtract Bios Modules" "\n\t\t\t\"-c\" show Bios Copyrights" "\n\t\t\t\"-h\" Help statistics");
- printf("\n\n\t*%s*\n", Url);
+ 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[])
@@ -89,7 +489,7 @@ int main(int argc, char *argv[])
FILE *ptx;
unsigned char *Buf;
unsigned int CurPos, fLen, Start, Offset;
- word i, FirstBLK, BBsz, BANKsz;
+ unsigned short FirstBLK, BBsz, BANKsz;
unsigned int POSTOff, SYSOff, FCPOff, FirstBLKf;
unsigned char phtime[8];
char BCPSEGMENT[] = "BCPSEGMENT";
@@ -98,39 +498,24 @@ int main(int argc, char *argv[])
unsigned char TotalSections = 0, Action, Mods = 0;
PHNXID IDMod;
- unsigned char __COPY__ = 0;
-
switch (HelpSystem(argc, argv)) {
- case 0x80:
- return 0;
- case 0x50:
- __COPY__ = 1;
case 0x10:
Action = Xtract;
break;
- case 0x51:
- __COPY__ = 1;
case 0x11:
Action = List;
break;
- case 0x60:
- __COPY__ = 1;
case 0x20:
Action = XtractM;
break;
- case 0x61:
- __COPY__ = 1;
case 0x21:
Action = ListM;
break;
default:
- PrintUsage();
printf("\n");
return 0;
}
- PrintHeader("\n\n");
-
if ((ptx = fopen(argv[1], "rb")) == NULL) {
printf("\nFATAL ERROR: File %s opening error...\n", argv[1]);
return 0;
@@ -251,39 +636,13 @@ int main(int argc, char *argv[])
printf("/* Copyrighted Information */\n");
- /* If .rom begins with no additional trash this routine should be applied */
- if (__COPY__) {
- fseek(ptx, POSTOff + 0x1B, 0);
-
- fread(&CurPos, 1, sizeof(word), ptx);
-
- fseek(ptx, (POSTOff & 0xF0000) + (CurPos & 0xffff), 0);
- } else {
-
-
- CurPos = IsPhoenixBIOS(ptx, Buf);
- fseek(ptx, (unsigned int) (CurPos), 0);
- };
+ CurPos = IsPhoenixBIOS(ptx, Buf);
+ fseek(ptx, (unsigned int) (CurPos), 0);
fread(Buf, 1, 0x100, ptx);
printf("\t%.64s\n", Buf);
- /* If .rom begins with no additional trash this routine should be applied */
- if (__COPY__) {
- fseek(ptx, POSTOff + 0x38, 0);
- fread(&CurPos, 1, sizeof(word), ptx);
- fseek(ptx, (POSTOff & 0xF0000) + (CurPos & 0xffff), 0);
- fread((Buf + 0x100), 1, 0x100, ptx);
- i = 0x100;
- while (Buf[i++] != 0xD);
- Buf[i] = 0x0;
- printf("\t%s\n", Buf + 0x100);
- }
-
- printf("/* ----------------------- */\n");
-
-
switch (Action) {
case ListM:
case XtractM:
diff --git a/phnxdeco/phnxdeco.h b/phnxdeco/phnxdeco.h
index 55d7934..6dd51c6 100644
--- a/phnxdeco/phnxdeco.h
+++ b/phnxdeco/phnxdeco.h
@@ -1,27 +1,3 @@
-/**********************************************
-**
-**
-** Defines & Functions for PhnxDeco
-**
-**
-***********************************************/
-
-/* ------ 26 Jan 2003 -------
-** New Name Conventions
-* ------------------------- */
-
-//typedef unsigned long dword;
-typedef unsigned short word;
-
-#define BLOCK 0x8000
-#define Xtract 0x10
-#define List 0x11
-#define XtractM 0x20
-#define ListM 0x21
-
-
-#define IDSign "+"
-
typedef struct {
FILE *infile;
FILE *outfile;
@@ -31,35 +7,4 @@ typedef struct {
int method;
} interfacing;
-typedef struct {
- unsigned int Prev;
- unsigned char Sig[3];
- unsigned char ID_HI;
- unsigned char ID_LO;
- unsigned char HeadLen;
- unsigned char isPacked;
- word Offset;
- word Segment;
- unsigned int ExpLen1;
- unsigned int Packed1;
- unsigned int Packed2;
- unsigned int ExpLen2;
-} PHOENIXHEAD;
-
-typedef struct {
- unsigned char Name[6];
- word Flags;
- word Len;
-} PHNXID;
-
-unsigned int FoundAt(FILE * ptx, unsigned char * Buf, char *Pattern, unsigned int BLOCK_LEN);
-
-unsigned char TotalSec(FILE * ptx, unsigned char * Buf, unsigned char Action, unsigned int BankSize);
-
-/* Modified Module Detection & Manipulating According to BCPSYS block */
-unsigned char TotalSecM(FILE * ptx, unsigned char * Buf, unsigned char Action, unsigned int Start, unsigned int ConstOff, unsigned int SYSOff);
-
-unsigned int IsPhoenixBIOS(FILE * ptx, unsigned char * Buf);
-
-/* kernel.c */
void decode(interfacing interface);
diff --git a/phnxdeco/phnxfunc.c b/phnxdeco/phnxfunc.c
deleted file mode 100644
index 8e70603..0000000
--- a/phnxdeco/phnxfunc.c
+++ /dev/null
@@ -1,432 +0,0 @@
-/**********************************************
-**
-**
-** Defines & Functions for PhnxDeco
-**
-**
-***********************************************/
-
-/* ------ 26 Jan 2003 -------
-** New Name Conventions
-* ------------------------- */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include "phnxdeco.h"
-
-unsigned int FoundAt(FILE * ptx, unsigned char *Buf, char *Pattern, unsigned int BLOCK_LEN)
-{
-
- unsigned int i, Ret;
- word 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;
-}
-
-static char *GetModuleName(char ID)
-{
- switch (ID) {
- case 'A':
- return ("ACPI");
- case 'B':
- return ("BIOSCODE");
- case 'C':
- return ("UPDATE");
- case 'D':
- return ("DISPLAY");
- case 'E':
- return ("SETUP");
- case 'F':
- return ("FONT");
- case 'G':
- return ("DECOMPCODE");
- case 'I':
- return ("BOOTBLOCK");
- case 'L':
- return ("LOGO");
- case 'M':
- return ("MISER");
- case 'N':
- return ("ROMPILOTLOAD");
- case 'O':
- return ("NETWORK");
- case 'P':
- return ("ROMPILOTINIT");
- case 'R':
- return ("OPROM");
- case 'S':
- return ("STRINGS");
- case 'T':
- return ("TEMPLATE");
- case 'U':
- return ("USER");
- case 'X':
- return ("ROMEXEC");
- case 'W':
- return ("WAV");
-
- case 'H':
- return ("TCPA_H"); /* TCPA (Trust Computing), USBKCLIB? */
- case 'K':
- return ("TCPA_K"); /* TCPA (Trust Computing), "AUTH"? */
- case 'Q':
- return ("TCPA_Q"); /* TCPA (Trust Computing), "SROM"? */
- case '<':
- return ("TCPA_<");
- case '*':
- return ("TCPA_*");
- case '?':
- return ("TCPA_?");
-
- case 'J':
- return ("SmartCardPAS");
-
- default:
- return ("User-Defined");
- }
-}
-
-static char *GetCompressionName(unsigned char ID)
-{
- switch (ID) {
- case 0x0:
- return ("NONE");
- case 0x2:
- return ("LZARI");
- case 0x3:
- return ("LZSS");
- case 0x4:
- return ("LZHUF");
- case 0x5:
- return ("LZINT");
- default:
- return ("RSRV!");
- }
-}
-
-static void decodeM3(interfacing interface)
-{
- FILE *ptx, *bmx;
- word Index, Index2, DX, Loop, XorOp, i;
- unsigned char *Buffer, tmp;
- unsigned int RealLen, Now;
-
- ptx = interface.infile;
- bmx = interface.outfile;
- RealLen = interface.original;
-
- Buffer = (unsigned char *) calloc(4096, 1);
- if (!Buffer)
- return;
-
- DX = 0;
- Index = 0xFEE;
- Now = 0;
-
- for (;;) {
- DX >>= 1;
- if ((DX & 0x100) == 0) {
- if (Now >= RealLen) {
- free(Buffer);
- return;
- }
- fread(&tmp, 1, 1, ptx);
- DX = (word) (0xFF) * 0x100 + tmp;
- };
-
- if ((DX & 0x1) != 0) {
- if (Now++ >= RealLen) {
- free(Buffer);
- return;
- }
- fread(&tmp, 1, 1, ptx);
- fwrite(&tmp, 1, 1, bmx);
- Buffer[Index++] = tmp;
- Index &= 0xFFF;
- continue;
- };
-
- Index2 = Index;
- if (Now >= RealLen) {
- free(Buffer);
- return;
- }
- fread(&tmp, 1, 1, ptx);
- Index = (word) tmp;
- if (Now >= RealLen) {
- free(Buffer);
- return;
- }
- fread(&tmp, 1, 1, ptx);
- Loop = (word) tmp & 0xf;
- Loop += 3;
- XorOp = (word) tmp & 0xf0;
- XorOp <<= 4;
- Index |= XorOp;
- for (i = 0; i < Loop; i++) {
- tmp = Buffer[Index++];
- Index &= 0xFFF;
- fwrite(&tmp, 1, 1, bmx);
- Buffer[Index2++] = tmp;
- Index2 &= 0xFFF;
- }
-
- Now += Loop;
- Index = Index2;
- }
-
-}
-
-unsigned char TotalSec(FILE * ptx, unsigned char * Buf, unsigned char Action, unsigned int BankSize)
-{
- FILE *pto;
- interfacing interface;
- char Buffer[12];
-
- unsigned int CurPos = 0;
- unsigned int RealRead = 0, i, TotalRead = 0, Tmp;
- char Head[] = { '\x31', '\x31', '\x0' };
- PHOENIXHEAD phhead;
- unsigned int End = 0xFFFFFFFF;
- unsigned char TotalSec = 0;
-
-
- switch (Action) {
- case List:
-
- printf("+------------------------------------------------------------------------------+\n"
- "| Class.Instance (Name) Packed ---> Expanded Compression Offset |\n"
- "+------------------------------------------------------------------------------+\n");
- };
-
- fseek(ptx, 0, 2);
- End = ftell(ptx);
- rewind(ptx);
- while ((!feof(ptx)) && (CurPos < BankSize)) {
- fseek(ptx, CurPos, 0);
- RealRead = fread(Buf, 1, BLOCK, ptx);
- TotalRead += RealRead;
- if (RealRead != BLOCK) {
- for (i = RealRead; i < BLOCK; i++)
- Buf[i] = 0xFF;
- }
-
- if (RealRead < 0x80)
- break;
- if ((CurPos = FoundAt(ptx, Buf, Head, RealRead)) != 0) {
- fseek(ptx, CurPos - 1 - 4, 0);
- TotalSec++;
- fread(&phhead, 1, sizeof(phhead), ptx);
- if ((phhead.ID_HI >= 0x0 && phhead.ID_HI <= 0x20) && (phhead.ID_LO <= 0x60) && phhead.Sig[0] == '\x0') {
- switch (Action) {
- case List:
-
-
- printf("\n %c.%.2X (%12.12s) %5.5X (%5.5u) => %5.5X (%6.3u) %5.5s (%3.1i%%) %5.2Xh", phhead.ID_LO, phhead.ID_HI,
- GetModuleName(phhead.ID_LO), phhead.Packed1, phhead.Packed1, phhead.ExpLen1, phhead.ExpLen1, GetCompressionName(phhead.isPacked),
- (unsigned int) 100 * (unsigned int) phhead.Packed1 / (unsigned int) phhead.ExpLen1, CurPos);
- break;
-
- case Xtract:
- if (phhead.isPacked == 0)
- sprintf(Buffer, "phoenix0.%C%.1X", phhead.ID_LO, phhead.ID_HI);
- else
- sprintf(Buffer, "phoenix_.%C%.1X", phhead.ID_LO, phhead.ID_HI);
-
- printf("%C.%.2X :: Saving %s ...", phhead.ID_LO, phhead.ID_HI, Buffer);
- if ((pto = fopen(Buffer, "wb")) == NULL) {
- printf("\nFile %s I/O error..Exit", Buf);
- exit(1);
- }
-
- interface.infile = ptx;
- interface.outfile = pto;
- interface.original = phhead.ExpLen1;
- interface.packed = phhead.Packed1;
-
- interface.dicbit = 13;
- interface.method = 5;
-
- /* isPacked == PackedLevel == CompressionName */
- if (phhead.isPacked == 0x5)
- decode(interface);
- else if (phhead.isPacked == 0x3) {
- fseek(ptx, -4L, 1);
- decodeM3(interface);
- } else {
- fseek(ptx, -4L, 1);
- for (i = 0; i < phhead.ExpLen1; i++) {
- fread(&Buffer[0], 1, 1, ptx);
- fwrite(&Buffer[0], 1, 1, pto);
- };
- }
- fclose(pto);
-
- printf("Done\n");
-
- break;
- }
-
- } else {
- TotalSec--;
- fseek(ptx, CurPos + 1, 0);
- RealRead = fread(Buf, 1, BLOCK, ptx);
- if ((Tmp = FoundAt(ptx, Buf, Head, RealRead)) == 0)
- CurPos = ftell(ptx) - 80;
- else
- CurPos = Tmp;
- continue;
- }
- CurPos += phhead.Packed1;
-
- } else
- CurPos = ftell(ptx);
- }
-
- return (TotalSec);
-}
-
-
-/*
- * Modified Module Detection & Manipulating
- * According to BCPSYS block
- */
-unsigned char TotalSecM(FILE * ptx, unsigned char * Buf, unsigned char Action, unsigned int Start, unsigned int ConstOff, unsigned int SYSOff)
-{
- FILE *pto;
- interfacing interface;
- char Buffer[12];
-
- 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);
-
- switch (Action) {
- case ListM:
-
- printf("\n================================== MODULE MAP =================================" "\nClass Code" "\n. Instance" "\n. ."
- "\nC I LEVEL START END LENGTH RATIO LINK TO FILEOFFSET"
- "\n---- ----- --------- --------- ------ ----- --------- ----------");
- };
-
-
- 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 ListM:
-
- printf("\n%c %.1X %5.5s %4.4X %4.4X %4.4X %4.4X %5.X %3.1i%% %4.4X %4.4X %5.2Xh", phhead.ID_LO, phhead.ID_HI,
- GetCompressionName(phhead.isPacked), blkstart >> 0x10, blkstart & 0xFFFF, (blkend + phhead.Packed1) >> 0x10,
- (blkend + phhead.Packed1) & 0xFFFF, phhead.Packed1, (unsigned int) 100 * (unsigned int) phhead.Packed1 / (unsigned int) phhead.ExpLen1, phhead.Prev >> 0x10,
- phhead.Prev & 0xFFFF, Start);
-
-
- break;
-
- case XtractM:
-
- printf("\n%c.%1.1X", phhead.ID_LO, phhead.ID_HI);
- sprintf(Buffer, "%s", GetModuleName(phhead.ID_LO));
-
- if (strlen(Buffer) > 7)
- sprintf(Buffer, "%7.7s%1.1X.rom", GetModuleName(phhead.ID_LO), phhead.ID_HI);
- else {
- sprintf(Buffer, "%s%1.1X.rom", GetModuleName(phhead.ID_LO), phhead.ID_HI);
- }
-
- printf(" %-12.12s ... O'k", Buffer);
-
-
- if ((pto = fopen(Buffer, "wb")) == NULL) {
- printf("\nFile %s I/O error..Exit", Buf);
- exit(1);
- }
-
-
- interface.infile = ptx;
- interface.outfile = pto;
- interface.original = phhead.ExpLen1;
- interface.packed = phhead.Packed1;
-
- interface.dicbit = 13;
- interface.method = 5;
-
- /* Evidently, isPacked == PackedLevel */
- if (phhead.isPacked == 0x5)
- decode(interface);
- else if (phhead.isPacked == 0x3) {
- fseek(ptx, -4L, 1);
- decodeM3(interface);
- } else {
- fseek(ptx, -4L, 1);
- for (i = 0; i < phhead.ExpLen1; i++) {
- fread(&Buffer[0], 1, 1, ptx);
- fwrite(&Buffer[0], 1, 1, pto);
- };
- }
- fclose(pto);
-
- break;
- }
- }
-
- return (TotalSec);
-}
-
-
-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);
-}