summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuc Verhaegen <libv@skynet.be>2009-06-17 17:51:41 +0200
committerLuc Verhaegen <libv@skynet.be>2009-06-17 17:51:41 +0200
commit02a035445e8ef465a9b2d24423dec57e7190b4fd (patch)
tree2a977003e189d927212ce707e7e854200c810d9c
parent45f61c1fb073abdf1054bbedb5f186d7b4289afc (diff)
Get rid of TotalSec, use BCPSYS info always.
-rw-r--r--phnxdeco/phnxdeco.c407
1 files changed, 95 insertions, 312 deletions
diff --git a/phnxdeco/phnxdeco.c b/phnxdeco/phnxdeco.c
index f252bf0..daed381 100644
--- a/phnxdeco/phnxdeco.c
+++ b/phnxdeco/phnxdeco.c
@@ -28,26 +28,6 @@
#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], "-xs") == 0)
- retcode = 0x20;
- if (strcmp(argv[x], "-ls") == 0)
- retcode = 0x21;
- if (strcmp(argv[x], "-x") == 0)
- retcode = 0x10;
- if (strcmp(argv[x], "-l") == 0)
- retcode = 0x11;
- }
- return (retcode);
-
-}
static unsigned int FoundAt(FILE * ptx, unsigned char *Buf, char *Pattern, unsigned int BLOCK_LEN)
{
@@ -63,88 +43,61 @@ static unsigned int FoundAt(FILE * ptx, unsigned char *Buf, char *Pattern, unsig
}
return 0;
}
-
-static char *GetModuleName(char ID)
+struct PhoenixModuleName
{
- 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)
+ 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)
{
- 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!");
- }
+ 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.
*/
@@ -222,113 +175,6 @@ typedef struct {
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);
- }
-
- /* isPacked == PackedLevel == CompressionName */
- if (phhead.isPacked == 0x5) {
- 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 {
- 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
@@ -336,9 +182,6 @@ static unsigned char TotalSec(FILE * ptx, unsigned char * Buf, unsigned char Act
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];
-
unsigned int i;
unsigned int blkend = 0, blkstart = 0;
PHOENIXHEAD phhead;
@@ -348,13 +191,8 @@ static unsigned char TotalSecM(FILE * ptx, unsigned char * Buf, unsigned char Ac
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---- ----- --------- --------- ------ ----- --------- ----------");
- };
+ if (Action == List)
+ printf("\nC I COMP START END LENGTH LINK TO FILEOFFSET");
while (phhead.Prev != 0x0 && !feof(ptx)) {
@@ -369,37 +207,33 @@ static unsigned char TotalSecM(FILE * ptx, unsigned char * Buf, unsigned char Ac
blkend = Start + ConstOff + sizeof(PHOENIXHEAD) - 5;
blkstart = Start + 0xFFF00000;
switch (Action) {
- case ListM:
+ case List:
- 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);
+ printf("\n%c %.1X %1d %8X %8X %5.X %8X %5.2Xh", phhead.ID_LO, phhead.ID_HI,
+ phhead.isPacked, blkstart, blkend + phhead.Packed1, phhead.Packed1, phhead.Prev, Start);
break;
- case XtractM:
+ case Xtract:
+ {
+ char *modulename = PhoenixModuleNameGet(phhead.ID_LO);
+ char filename[64];
- 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);
+ 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(Buffer, "wb")) == NULL) {
- printf("\nFile %s I/O error..Exit", Buf);
- exit(1);
+ 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;
@@ -410,10 +244,12 @@ static unsigned char TotalSecM(FILE * ptx, unsigned char * Buf, unsigned char Ac
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(&Buffer[0], 1, 1, ptx);
- fwrite(&Buffer[0], 1, 1, pto);
+ fread(tmp, 1, 1, ptx);
+ fwrite(tmp, 1, 1, pto);
};
}
fclose(pto);
@@ -463,58 +299,45 @@ static unsigned int IsPhoenixBIOS(FILE * ptx, unsigned char * Buf)
int main(int argc, char *argv[])
{
FILE *ptx;
- unsigned char *Buf;
+ unsigned char Buf[BLOCK];
unsigned int CurPos, fLen, Start, Offset;
- unsigned short FirstBLK, BBsz, BANKsz;
- unsigned int POSTOff, SYSOff, FCPOff, FirstBLKf;
- unsigned char phtime[8];
+ unsigned int SYSOff;
char BCPSEGMENT[] = "BCPSEGMENT";
- char BCPFCP[] = "BCPFCP";
- char phdate[9]; /* XX/XX/XX\0 */
+ char phdate[18]; /* "XX/XX/XX\20XX:XX:XX\0" */
unsigned char TotalSections = 0, Action, Mods = 0;
PHNXID IDMod;
- switch (HelpSystem(argc, argv)) {
- case 0x10:
+ memset(Buf, 0, BLOCK);
+
+ if (argc != 3) {
+ printf("wrong usage.\n");
+ return 1;
+ }
+
+ if (!strcmp(argv[1], "x"))
Action = Xtract;
- break;
- case 0x11:
+ else if (!strcmp(argv[1], "l"))
Action = List;
- break;
- case 0x20:
- Action = XtractM;
- break;
- case 0x21:
- Action = ListM;
- break;
- default:
- printf("\n");
- return 0;
+ else {
+ printf("wrong usage.\n");
+ return 1;
}
- if ((ptx = fopen(argv[1], "rb")) == NULL) {
- printf("\nFATAL ERROR: File %s opening error...\n", argv[1]);
+ if ((ptx = fopen(argv[2], "rb")) == NULL) {
+ printf("\nFATAL ERROR: File %s opening error...\n", argv[2]);
return 0;
};
- Buf = (unsigned char *) calloc(BLOCK, 1);
- if (!Buf) {
- printf("Memory Error..\n");
- return 0;
- }
-
CurPos = 0;
IDMod.Name[0] = 0xff;
IDMod.Len = 0xff;
- POSTOff = 0;
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[1]);
-
+ printf("Filename\t: %s\n", argv[2]);
while (!feof(ptx)) {
fread(Buf, 1, BLOCK, ptx);
@@ -547,8 +370,6 @@ int main(int argc, char *argv[])
fread(&IDMod, 1, sizeof(IDMod), ptx);
};
- if (memcmp(IDMod.Name, "BCPOST", 6) == 0)
- POSTOff = CurPos;
if (memcmp(IDMod.Name, "BCPSYS", 6) == 0)
SYSOff = CurPos;
CurPos += IDMod.Len;
@@ -559,31 +380,12 @@ int main(int argc, char *argv[])
Mods++;
}
- /* Looking for BCPFCP control structure */
- rewind(ptx);
- while (!feof(ptx)) {
- fread(Buf, 1, BLOCK, ptx);
- if ((CurPos = FoundAt(ptx, Buf, BCPFCP, BLOCK)) != 0)
- break;
- /* O'K, we got this hook */
- CurPos = ftell(ptx) - 0x100;
-
- }
- FCPOff = CurPos;
-
printf("System Information at\t\t: %X\n", SYSOff);
- fseek(ptx, SYSOff + 0x7E, 0);
- fread(&BBsz, 1, sizeof(BBsz), ptx);
-
- fseek(ptx, SYSOff + 0x7B, 0);
- fread(&BANKsz, 1, sizeof(BANKsz), ptx);
-
fseek(ptx, SYSOff + 15, 0);
- fread(&phdate, 1, 8, ptx);
- phdate[8] = 0;
- fread(Buf, 1, 1, ptx);
- fread(&phtime, 1, 8, ptx);
+ fread(&phdate, 1, 17, ptx);
+ phdate[8] = ' ';
+ phdate[17] = 0;
fseek(ptx, SYSOff + 0x77, 0);
/* Move to the pointer of 1st module */
@@ -595,22 +397,13 @@ int main(int argc, char *argv[])
fseek(ptx, SYSOff + 0x37, 0);
fread(Buf, 1, 8, ptx);
- printf("BootBlock\t: %X bytes\n", (BBsz == 0x0) ? (0x10000) : (BBsz));
- printf("BankSize\t: %i KB\n", BANKsz);
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("BCPFCP\t\t: %X\n", FCPOff);
- fseek(ptx, FCPOff + 0x18, 0);
- fread(&FirstBLK, 1, sizeof(FirstBLK), ptx);
- FirstBLKf = (ftell(ptx) & 0xF0000) + FirstBLK;
- printf("FCP 1st module\t: %X (%X)\n", FirstBLK, FirstBLKf);
- printf("Released\t: %s at %8.8s\n", phdate, phtime);
-
- printf("/* Copyrighted Information */\n");
+ printf("Released\t: %s\n", phdate);
CurPos = IsPhoenixBIOS(ptx, Buf);
fseek(ptx, (unsigned int) (CurPos), 0);
@@ -619,21 +412,11 @@ int main(int argc, char *argv[])
printf("\t%.64s\n", Buf);
- switch (Action) {
- case ListM:
- case XtractM:
- TotalSections = TotalSecM(ptx, Buf, Action, Start, Offset, SYSOff);
- break;
- case List:
- case Xtract:
- TotalSections = TotalSec(ptx, Buf, Action, (BANKsz) << 10);
- break;
- }
+ TotalSections = TotalSecM(ptx, Buf, Action, Start, Offset, SYSOff);
printf("\n");
printf("Total Sections: %u\n", TotalSections);
- free(Buf);
fclose(ptx);
printf("\n");