diff options
author | Luc Verhaegen <libv@skynet.be> | 2009-06-16 14:37:31 +0200 |
---|---|---|
committer | Luc Verhaegen <libv@skynet.be> | 2009-06-17 14:47:05 +0200 |
commit | 1a3e94cf30a1f14375af4b416ce6be22da380d2a (patch) | |
tree | 04948b361f09cc11bbd76303b71701a249843482 | |
parent | 4aeef3803d638f3c380b53d8343d5269022e3371 (diff) |
Phnxdeco: run indent.
indent -kr -i4 -l160 --ignore-newlines
-rw-r--r-- | phnxdeco/kernel.c | 465 | ||||
-rw-r--r-- | phnxdeco/phnxdeco.c | 432 | ||||
-rw-r--r-- | phnxdeco/phnxdeco.h | 107 | ||||
-rw-r--r-- | phnxdeco/phnxfunc.c | 864 | ||||
-rw-r--r-- | phnxdeco/phnxhelp.h | 107 | ||||
-rw-r--r-- | phnxdeco/phnxsoft.h | 8 | ||||
-rw-r--r-- | phnxdeco/phnxver.h | 4 |
7 files changed, 1030 insertions, 957 deletions
diff --git a/phnxdeco/kernel.c b/phnxdeco/kernel.c index f447086..f77073a 100644 --- a/phnxdeco/kernel.c +++ b/phnxdeco/kernel.c @@ -15,7 +15,7 @@ #define CHAR_BIT 8 #define CBIT 9 -#define USHRT_BIT 16 /* (CHAR_BIT * sizeof(ushort)) */ +#define USHRT_BIT 16 /* (CHAR_BIT * sizeof(ushort)) */ #define MAX_DICBIT 13 #define MAX_DICSIZ (1 << MAX_DICBIT) @@ -39,7 +39,7 @@ unsigned char *text; static unsigned short dicsiz; -static unsigned char subbitbuf, bitcount; +static unsigned char subbitbuf, bitcount; unsigned short crc, bitbuf; int prev_char; @@ -47,8 +47,7 @@ long reading_size; unsigned short left[2 * NC - 1], right[2 * NC - 1]; unsigned char c_len[NC], pt_len[NPT]; -unsigned short c_table[4096], c_code[NC], - pt_table[256], pt_code[NPT]; +unsigned short c_table[4096], c_code[NC], pt_table[256], pt_code[NPT]; static unsigned char *buf; static unsigned short bufsiz; static unsigned short blocksize; @@ -56,13 +55,13 @@ static unsigned short blocksize; FILE *infile, *outfile; typedef struct { - FILE *infile; - FILE *outfile; - unsigned long original; - unsigned long packed; - int dicbit; - int method; -} interfacing ; + FILE *infile; + FILE *outfile; + unsigned long original; + unsigned long packed; + int dicbit; + int method; +} interfacing; static short c, n, tblsiz, len, depth, maxdepth, avail; @@ -74,46 +73,72 @@ static unsigned char *blen; /****************************************/ 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; + 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() */ /****************************************/ -void make_table(short nchar, unsigned char bitlen[], - short tablebits, unsigned short table[]) +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); } + 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); + } } @@ -121,19 +146,21 @@ void make_table(short nchar, unsigned char bitlen[], /****************************************/ /* fillbif() */ /****************************************/ -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; +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; } @@ -142,22 +169,24 @@ void fillbuf(unsigned char n) /* Shift bitbuf n bits left, read n bits */ /****************************************/ unsigned short getbits(unsigned char n) { - unsigned short x; + unsigned short x; - x = bitbuf >> (2 * CHAR_BIT - n); fillbuf(n); - return x; + x = bitbuf >> (2 * CHAR_BIT - n); + fillbuf(n); + return x; } /****************************************/ /* fwrite_crc() */ /****************************************/ -void fwrite_crc( unsigned char *p, int n, FILE *fp ) +void fwrite_crc(unsigned char *p, int n, FILE * fp) { - if ( fp ) - { - if (fwrite(p, 1, n, fp) < n) - { printf("\nFatal Error"); exit(1); } + if (fp) { + if (fwrite(p, 1, n, fp) < n) { + printf("\nFatal Error"); + exit(1); + } } } @@ -166,8 +195,10 @@ void fwrite_crc( unsigned char *p, int n, FILE *fp ) /****************************************/ void init_getbits(void) { - bitbuf = 0; subbitbuf = 0; bitcount = 0; - fillbuf(2 * CHAR_BIT); + bitbuf = 0; + subbitbuf = 0; + bitcount = 0; + fillbuf(2 * CHAR_BIT); } @@ -176,167 +207,195 @@ void init_getbits(void) 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; - } + 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++; } - while (i < nn) pt_len[i++] = 0; - make_table(nn, pt_len, 8, pt_table); + } + 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); + 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); + } } unsigned short decode_c_st1(void) { - unsigned short j, mask; + 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; + 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; } 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; + 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; } void decode_start_st1(void) { - init_getbits(); - blocksize = 0; + init_getbits(); + blocksize = 0; } /********end of decode***********************/ void decode(interfacing interface) { - int i, j, k, c, dicsiz1, offset; - - infile = interface.infile; - outfile = interface.outfile; - dicbit = interface.dicbit; - origsize = interface.original; - compsize = interface.packed; - crc = 0; - prev_char = -1; - dicsiz = 1 << dicbit; - 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; - } - } + int i, j, k, c, dicsiz1, offset; + + infile = interface.infile; + outfile = interface.outfile; + dicbit = interface.dicbit; + origsize = interface.original; + compsize = interface.packed; + crc = 0; + prev_char = -1; + dicsiz = 1 << dicbit; + 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); + } + if (loc != 0) { + fwrite_crc(text, loc, outfile); + } + free(text); } diff --git a/phnxdeco/phnxdeco.c b/phnxdeco/phnxdeco.c index 658892a..56f67fe 100644 --- a/phnxdeco/phnxdeco.c +++ b/phnxdeco/phnxdeco.c @@ -22,11 +22,11 @@ #include <stdlib.h> #if defined(LINUX) || defined(__LINUX__) || defined(__linux__) - #include <memory.h> - #define __LINUX_NOW__ -#else - #include <mem.h> - #include <conio.h> +#include <memory.h> +#define __LINUX_NOW__ +#else +#include <mem.h> +#include <conio.h> #endif #include "./phnxdeco.h" @@ -34,234 +34,254 @@ #include "./phnxver.h" #include "./phnxhelp.h" -int main(byte argc, byte *argv[]) +int main(byte argc, byte * argv[]) { - FILE *ptx; - byte *Buf; - dword CurPos, fLen, Start, Offset; - word i, Len, FirstBLK, BBsz, BANKsz; - dword POSTOff, SYSOff, FCPOff, FirstBLKf; - byte PhBIOS[] = "Phoenix FirstBIOS", PhVersion[3], PhRelease[3], phtime[8]; - byte BCPSEGMENT[] = "BCPSEGMENT"; - byte BCPFCP[] = "BCPFCP"; - AMIDATE phdate; - byte TotalSections = 0, Action, Mods = 0; - PHNXID IDMod; - - byte __COPY__ = 0; + FILE *ptx; + byte *Buf; + dword CurPos, fLen, Start, Offset; + word i, Len, FirstBLK, BBsz, BANKsz; + dword POSTOff, SYSOff, FCPOff, FirstBLKf; + byte PhBIOS[] = "Phoenix FirstBIOS", PhVersion[3], PhRelease[3], phtime[8]; + byte BCPSEGMENT[] = "BCPSEGMENT"; + byte BCPFCP[] = "BCPFCP"; + AMIDATE phdate; + byte TotalSections = 0, Action, Mods = 0; + PHNXID IDMod; + + byte __COPY__ = 0; #ifndef __LINUX_NOW__ - clrscr(); + clrscr(); #endif #ifdef __DEBUG__ -// argv[1] = "C:\\phnx\\z.bin"; - argv[1] = "C:\\phnx\\10410.bin"; -// argv[1] = "C:\\firmware.111"; - argv[2] = "-l"; - argc = 3; +// argv[1] = "C:\\phnx\\z.bin"; + argv[1] = "C:\\phnx\\10410.bin"; +// argv[1] = "C:\\firmware.111"; + argv[2] = "-l"; + argc = 3; #endif - 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; - }; - - Buf = (byte*)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: %lX (%lu bytes)\n", fLen, fLen); - printf("Filename\t: %s\n", argv[1]); - - - while(!feof(ptx)) - { - fread(Buf, 1, BLOCK, ptx); - if( (CurPos = FoundAt(ptx, Buf, BCPSEGMENT, BLOCK)) != 0 ) break; + 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; + }; + + Buf = (byte *) 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: %lX (%lu bytes)\n", fLen, fLen); + printf("Filename\t: %s\n", argv[1]); + + + 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; + CurPos = ftell(ptx) - 0x100; - } + } - if(feof(ptx)) - { - printf("Searched through file. Not a PhoenixBIOS\n"); - exit(1); - } + if (feof(ptx)) { + printf("Searched through file. Not a PhoenixBIOS\n"); + exit(1); + } - printf("PhoenixBIOS hook found at\t: %lX\n", CurPos); - CurPos += 10; - fseek(ptx, (dword)(CurPos), 0); + printf("PhoenixBIOS hook found at\t: %lX\n", CurPos); + CurPos += 10; + fseek(ptx, (dword) (CurPos), 0); - while( IDMod.Name[0] != 0x0 && IDMod.Len != 0x0) - { - fread(&IDMod, 1, sizeof(IDMod), ptx); + 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,"BCPOST",6) == 0 ) POSTOff = CurPos; - if( memcmp(IDMod.Name,"BCPSYS",6) == 0 ) SYSOff = CurPos; - CurPos += IDMod.Len; - fseek(ptx, (dword)(CurPos), 0); - if( IDMod.Name[0] == 0x0 || IDMod.Name[0] < 0x41 ) break; else Mods++; - } + 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, "BCPOST", 6) == 0) + POSTOff = CurPos; + if (memcmp(IDMod.Name, "BCPSYS", 6) == 0) + SYSOff = CurPos; + CurPos += IDMod.Len; + fseek(ptx, (dword) (CurPos), 0); + if (IDMod.Name[0] == 0x0 || IDMod.Name[0] < 0x41) + break; + else + 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; + 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; + CurPos = ftell(ptx) - 0x100; + + } + FCPOff = CurPos; - } - FCPOff = CurPos; + printf("System Information at\t\t: %lX\n", SYSOff); - printf("System Information at\t\t: %lX\n", SYSOff); - - fseek(ptx, SYSOff + 0x7E, 0); - fread(&BBsz, 1, sizeof(BBsz), ptx); + 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, sizeof(phdate), ptx); - fread(Buf, 1, 1, ptx); fread(&phtime, 1, 8, ptx); + fseek(ptx, SYSOff + 0x7B, 0); + fread(&BANKsz, 1, sizeof(BANKsz), ptx); - fseek(ptx, SYSOff + 0x77, 0); + fseek(ptx, SYSOff + 15, 0); + fread(&phdate, 1, sizeof(phdate), ptx); + fread(Buf, 1, 1, ptx); + fread(&phtime, 1, 8, ptx); + + 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; + 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("BootBlock\t: %lX bytes\n", (BBsz == 0x0)?(0x10000):(BBsz)); - printf("BankSize\t: %li KB\n", BANKsz); - printf("Version\t\t: %8.8s\n", Buf); - printf("Start\t\t: %lX\n", Start); - printf("Offset\t\t: %lX\n", 0xFFFF0000 - Offset); - - printf("BCP Modules\t: %i\n", Mods); - printf("BCPFCP\t\t: %lX\n", FCPOff); - fseek(ptx, FCPOff + 0x18, 0); - fread(&FirstBLK, 1, sizeof(FirstBLK), ptx); - FirstBLKf = (ftell(ptx) & 0xF0000) + FirstBLK; - printf("FCP 1st module\t: %lX (%lX)\n", FirstBLK, FirstBLKf); - - printf("Released\t: %s at %8.8s\n", GetFullDate(phdate.Month, phdate.Day, phdate.Year), phtime); - - printf("/* Copyrighted Information */\n"); - - - if (__COPY__) - - /* - If .rom begins with no additional trash - this routine should be applied - */ - - { - - 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, (dword)(CurPos), 0); - }; - - fread(Buf, 1, 0x100, ptx); - - printf("\t%.64s\n", Buf); - - - if (__COPY__) - - /* - If .rom begins with no additional trash - this routine should be applied - */ - - { - - 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: TotalSections = TotalSecM( ptx, Buf, Action, Start, Offset, SYSOff ); break; - case List: - case Xtract: TotalSections = TotalSec( ptx, Buf, Action, (BANKsz) << 10 ); break; - } - - printf("\n"); - printf("Total Sections: %u\n", TotalSections); - - free(Buf); fclose(ptx); - - printf("\n"); - return 0; - } + fseek(ptx, SYSOff + 0x37, 0); + fread(Buf, 1, 8, ptx); + + printf("BootBlock\t: %lX bytes\n", (BBsz == 0x0) ? (0x10000) : (BBsz)); + printf("BankSize\t: %li KB\n", BANKsz); + printf("Version\t\t: %8.8s\n", Buf); + printf("Start\t\t: %lX\n", Start); + printf("Offset\t\t: %lX\n", 0xFFFF0000 - Offset); + + printf("BCP Modules\t: %i\n", Mods); + printf("BCPFCP\t\t: %lX\n", FCPOff); + fseek(ptx, FCPOff + 0x18, 0); + fread(&FirstBLK, 1, sizeof(FirstBLK), ptx); + FirstBLKf = (ftell(ptx) & 0xF0000) + FirstBLK; + printf("FCP 1st module\t: %lX (%lX)\n", FirstBLK, FirstBLKf); + + printf("Released\t: %s at %8.8s\n", GetFullDate(phdate.Month, phdate.Day, phdate.Year), phtime); + + printf("/* Copyrighted Information */\n"); + + + if (__COPY__) + + /* + If .rom begins with no additional trash + this routine should be applied + */ + + { + + 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, (dword) (CurPos), 0); + }; + + fread(Buf, 1, 0x100, ptx); + + printf("\t%.64s\n", Buf); + + + if (__COPY__) + + /* + If .rom begins with no additional trash + this routine should be applied + */ + + { + + 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: + TotalSections = TotalSecM(ptx, Buf, Action, Start, Offset, SYSOff); + break; + case List: + case Xtract: + TotalSections = TotalSec(ptx, Buf, Action, (BANKsz) << 10); + break; + } + + printf("\n"); + printf("Total Sections: %u\n", TotalSections); + + free(Buf); + fclose(ptx); + printf("\n"); + return 0; +} diff --git a/phnxdeco/phnxdeco.h b/phnxdeco/phnxdeco.h index 9ce1232..cbf9818 100644 --- a/phnxdeco/phnxdeco.h +++ b/phnxdeco/phnxdeco.h @@ -24,70 +24,67 @@ typedef unsigned short word; #ifndef __LINUX_NOW__ - #define IDSign "" +#define IDSign "" #else - #define IDSign "+" +#define IDSign "+" #endif - -//#define __DEBUG__ + +//#define __DEBUG__ + +typedef struct { + FILE *infile; + FILE *outfile; + unsigned long original; + unsigned long packed; + int dicbit; + int method; +} interfacing; + +typedef struct { + byte Month[2]; + byte rsrv1; + byte Day[2]; + byte rsrv2; + byte Year[2]; +} AMIDATE; typedef struct { - FILE *infile; - FILE *outfile; - unsigned long original; - unsigned long packed; - int dicbit; - int method; - } interfacing; - -typedef struct - { - byte Month[2]; - byte rsrv1; - byte Day[2]; - byte rsrv2; - byte Year[2]; - } AMIDATE; - -typedef struct - { - dword Prev; - byte Sig[3]; - byte ID_HI; - byte ID_LO; - byte HeadLen; - byte isPacked; - word Offset; - word Segment; - dword ExpLen1; - dword Packed1; - dword Packed2; - dword ExpLen2; - } PHOENIXHEAD; - -typedef struct - { - byte Name[6]; - word Flags; - word Len; - } PHNXID; - -byte StrLen(byte *Str); -byte StrCmp(byte *Dst, byte *Src); - -dword FoundAt(FILE *ptx, byte *Buf, byte *Pattern, dword BLOCK_LEN); -byte* GetFullDate(byte *mon, byte *day, byte *year); - -byte* GetModuleName(byte ID); -byte* GetCompressionName(byte ID); + dword Prev; + byte Sig[3]; + byte ID_HI; + byte ID_LO; + byte HeadLen; + byte isPacked; + word Offset; + word Segment; + dword ExpLen1; + dword Packed1; + dword Packed2; + dword ExpLen2; +} PHOENIXHEAD; + +typedef struct { + byte Name[6]; + word Flags; + word Len; +} PHNXID; + +byte StrLen(byte * Str); +byte StrCmp(byte * Dst, byte * Src); + +dword FoundAt(FILE * ptx, byte * Buf, byte * Pattern, dword BLOCK_LEN); +byte *GetFullDate(byte * mon, byte * day, byte * year); + +byte *GetModuleName(byte ID); +byte *GetCompressionName(byte ID); void decodeM3(interfacing interface); -byte TotalSec(FILE *ptx, byte *Buf,byte Action, dword BankSize); +byte TotalSec(FILE * ptx, byte * Buf, byte Action, dword BankSize); /*---------------Modified Module Detection & Manipulating------------ According to BCPSYS block --------------------------------------------------------------------*/ -byte TotalSecM(FILE *ptx, byte *Buf,byte Action,dword Start,dword ConstOff,dword SYSOff); +byte TotalSecM(FILE * ptx, byte * Buf, byte Action, dword Start, dword ConstOff, dword SYSOff); -dword IsPhoenixBIOS(FILE *ptx, byte *Buf); +dword IsPhoenixBIOS(FILE * ptx, byte * Buf); diff --git a/phnxdeco/phnxfunc.c b/phnxdeco/phnxfunc.c index 28fb1a8..c8e3e07 100644 --- a/phnxdeco/phnxfunc.c +++ b/phnxdeco/phnxfunc.c @@ -24,521 +24,533 @@ typedef unsigned short word; #ifndef __LINUX_NOW__ - #define IDSign "" +#define IDSign "" #else - #define IDSign "+" +#define IDSign "+" #endif typedef struct { - FILE *infile; - FILE *outfile; - unsigned long original; - unsigned long packed; - int dicbit; - int method; - } interfacing; - -typedef struct - { - byte Month[2]; - byte rsrv1; - byte Day[2]; - byte rsrv2; - byte Year[2]; - } AMIDATE; - -typedef struct - { - dword Prev; - byte Sig[3]; - byte ID_HI; - byte ID_LO; - byte HeadLen; - byte isPacked; - word Offset; - word Segment; - dword ExpLen1; - dword Packed1; - dword Packed2; - dword ExpLen2; - } PHOENIXHEAD; -typedef struct - { - byte Name[6]; - word Flags; - word Len; - } PHNXID; - -byte StrLen(byte *Str){ int i = 0; while( *(Str+i) != 0x0 ) i++; return(i); }; -byte StrCmp(byte *Dst, byte *Src) - { - byte i; - for( i = 0;i <= StrLen(Src); i++ ) - if( Dst[i] != Src[i] ) return(1); - return(0); - } + FILE *infile; + FILE *outfile; + unsigned long original; + unsigned long packed; + int dicbit; + int method; +} interfacing; + +typedef struct { + byte Month[2]; + byte rsrv1; + byte Day[2]; + byte rsrv2; + byte Year[2]; +} AMIDATE; +typedef struct { + dword Prev; + byte Sig[3]; + byte ID_HI; + byte ID_LO; + byte HeadLen; + byte isPacked; + word Offset; + word Segment; + dword ExpLen1; + dword Packed1; + dword Packed2; + dword ExpLen2; +} PHOENIXHEAD; +typedef struct { + byte Name[6]; + word Flags; + word Len; +} PHNXID; -dword FoundAt(FILE *ptx, byte *Buf, byte *Pattern, dword BLOCK_LEN) +byte StrLen(byte * Str) { + int i = 0; + while (*(Str + i) != 0x0) + i++; + return (i); +}; - dword 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; +byte StrCmp(byte * Dst, byte * Src) +{ + byte i; + for (i = 0; i <= StrLen(Src); i++) + if (Dst[i] != Src[i]) + return (1); + return (0); } -byte* GetFullDate(byte *mon, byte *day, byte *year) - { - byte *Months[]={"", - "January", - "February", - "March", - "April", - "May", - "June", - "July", - "August", - "September", - "October", - "November", - "December"}; - byte Buf[20]; - - if((atoi(year) >= 0) && (atoi(year) < 70)) sprintf(Buf,"%.2s %s %s%.2s",day,Months[atoi(mon)],"20",year); - else sprintf(Buf,"%.2s %s %s%.2s",day,Months[atoi(mon)],"19",year); - - return(Buf); - } -byte* GetModuleName(byte ID) +dword FoundAt(FILE * ptx, byte * Buf, byte * Pattern, dword BLOCK_LEN) { - 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"); - - - } + dword 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; } -byte* GetCompressionName(byte ID) +byte *GetFullDate(byte * mon, byte * day, byte * year) { - switch(ID){ + byte *Months[] = { "", + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December" + }; + byte Buf[20]; + + if ((atoi(year) >= 0) && (atoi(year) < 70)) + sprintf(Buf, "%.2s %s %s%.2s", day, Months[atoi(mon)], "20", year); + else + sprintf(Buf, "%.2s %s %s%.2s", day, Months[atoi(mon)], "19", year); + + return (Buf); +} - case 0x0: return("NONE"); - case 0x2: return("LZARI"); - case 0x3: return("LZSS"); - case 0x4: return("LZHUF"); - case 0x5: return("LZINT"); - default : return("RSRV!"); +byte *GetModuleName(byte 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"); + + + + } +} - } +byte *GetCompressionName(byte 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!"); + + } } void decodeM3(interfacing interface) { - FILE *ptx, *bmx; + FILE *ptx, *bmx; /*------------------------*/ - word Index, Index2, DX, Loop, XorOp, i; - byte *Buffer, tmp; - dword RealLen, Now; + word Index, Index2, DX, Loop, XorOp, i; + byte *Buffer, tmp; + dword RealLen, Now; /*------------------------*/ - ptx = interface.infile; - bmx = interface.outfile; - RealLen = interface.original; - - Buffer = (byte*)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; - }; + ptx = interface.infile; + bmx = interface.outfile; + RealLen = interface.original; + + Buffer = (byte *) 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; - }; + 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; + Index2 = Index; + if (Now >= RealLen) { + free(Buffer); + return; } - - Now +=Loop; - Index = Index2; + 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; + } + } -byte TotalSec(FILE *ptx, byte *Buf,byte Action, dword BankSize) +byte TotalSec(FILE * ptx, byte * Buf, byte Action, dword BankSize) { - FILE *pto; - interfacing interface; - byte Buffer[12]; - - dword CurPos=0; - dword RealRead=0,i, TotalRead=0, Tmp; - byte Head[]={'\x31','\x31','\x0'}; - PHOENIXHEAD phhead; - dword End=0xFFFFFFFF; - byte TotalSec=0; - + FILE *pto; + interfacing interface; + byte Buffer[12]; + + dword CurPos = 0; + dword RealRead = 0, i, TotalRead = 0, Tmp; + byte Head[] = { '\x31', '\x31', '\x0' }; + PHOENIXHEAD phhead; + dword End = 0xFFFFFFFF; + byte 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; + } - switch(Action) - { + 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" - "| 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.5lX (%5.5lu) => %5.5lX (%6.3lu) %5.5s (%3.1i%%) %5.2lXh", phhead.ID_LO, phhead.ID_HI, + GetModuleName(phhead.ID_LO), phhead.Packed1, phhead.Packed1, phhead.ExpLen1, phhead.ExpLen1, GetCompressionName(phhead.isPacked), + (dword) 100 * (dword) phhead.Packed1 / (dword) phhead.ExpLen1, CurPos); + break; + + case Xtract: + if (phhead.isPacked == 0) + sprintf(Buffer, "phoenix0.%1.1C%.1X", phhead.ID_LO, phhead.ID_HI); + else + sprintf(Buffer, "phoenix_.%1.1C%.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); + } - printf("\n %c.%.2X (%12.12s) %5.5lX (%5.5lu) => %5.5lX (%6.3lu) %5.5s (%3.1i%%) %5.2lXh", - phhead.ID_LO, - phhead.ID_HI, - GetModuleName(phhead.ID_LO), - phhead.Packed1, phhead.Packed1, - phhead.ExpLen1, phhead.ExpLen1, - GetCompressionName(phhead.isPacked), - (dword)100*(dword)phhead.Packed1/(dword)phhead.ExpLen1, - CurPos - ); - break; + interface.infile = ptx; + interface.outfile = pto; + interface.original = phhead.ExpLen1; + interface.packed = phhead.Packed1; - case Xtract: - if(phhead.isPacked == 0) - sprintf(Buffer, "phoenix0.%1.1C%.1X", phhead.ID_LO, phhead.ID_HI); - else - sprintf(Buffer,"phoenix_.%1.1C%.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; + 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; - /* End of Xtract */ + 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; + /* End of Xtract */ } - } - 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; - } + } 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; + CurPos += phhead.Packed1; - } else - CurPos = ftell(ptx); + } else + CurPos = ftell(ptx); - } + } - return(TotalSec); + return (TotalSec); } /*---------------Modified Module Detection & Manipulating------------ According to BCPSYS block --------------------------------------------------------------------*/ -byte TotalSecM(FILE *ptx, byte *Buf,byte Action,dword Start,dword ConstOff,dword SYSOff) +byte TotalSecM(FILE * ptx, byte * Buf, byte Action, dword Start, dword ConstOff, dword SYSOff) { - FILE *pto, *scr; - interfacing interface; - byte Buffer[12], Magic[4]={0x42,0x43,0xD6,0xF1}; + FILE *pto, *scr; + interfacing interface; + byte Buffer[12], Magic[4] = { 0x42, 0x43, 0xD6, 0xF1 }; - dword CurPos = 0, i; - dword blkend = 0, blkstart = 0; - PHOENIXHEAD phhead; - byte TotalSec=0; - dword Offset = Start; + dword CurPos = 0, i; + dword blkend = 0, blkstart = 0; + PHOENIXHEAD phhead; + byte TotalSec = 0; + dword Offset = Start; - word BBsz, BANKsz; - dword BBROMsz; - extern byte SoftName[]; - extern byte Url[]; + word BBsz, BANKsz; + dword BBROMsz; + extern byte SoftName[]; + extern byte Url[]; - phhead.Prev = 0xFFFF0000; - fseek(ptx,0,2); + phhead.Prev = 0xFFFF0000; + fseek(ptx, 0, 2); /*-------- Start Phoenix compatible script file ----------*/ /*-------- End Phoenix compatible script file ----------*/ - switch(Action) - { - case ListM: - - printf( -"\n================================== MODULE MAP =================================" -"\nClass Code" -"\n. Instance" -"\n. ." -"\nC I LEVEL START END LENGTH RATIO LINK TO FILEOFFSET" -"\n---- ----- --------- --------- ------ ----- --------- ----------" - ); - }; + 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.4lX %4.4lX %4.4lX %4.4lX %5.lX %3.1i%% %4.4lX %4.4lX %5.2lXh", - phhead.ID_LO, phhead.ID_HI, - GetCompressionName(phhead.isPacked), - blkstart >> 0x10, blkstart & 0xFFFF, - (blkend + phhead.Packed1) >> 0x10, (blkend + phhead.Packed1) & 0xFFFF, - phhead.Packed1, - (dword)100*(dword)phhead.Packed1/(dword)phhead.ExpLen1, - phhead.Prev >> 0x10, phhead.Prev & 0xFFFF, - Start); - - - break; - case XtractM: + 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.4lX %4.4lX %4.4lX %4.4lX %5.lX %3.1i%% %4.4lX %4.4lX %5.2lXh", phhead.ID_LO, phhead.ID_HI, + GetCompressionName(phhead.isPacked), blkstart >> 0x10, blkstart & 0xFFFF, (blkend + phhead.Packed1) >> 0x10, + (blkend + phhead.Packed1) & 0xFFFF, phhead.Packed1, (dword) 100 * (dword) phhead.Packed1 / (dword) 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); + 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); + } - if((pto = fopen(Buffer,"wb")) == NULL) - { - printf("\nFile %s I/O error..Exit",Buf); - exit(1); - } + printf(" %-12.12s ... O'k", Buffer); - - interface.infile = ptx; - interface.outfile = pto; - interface.original = phhead.ExpLen1; - interface.packed = phhead.Packed1; - interface.dicbit = 13; - interface.method = 5; + 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; - /* End of Xtract */ + 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); - } - /* End of switch */ + break; + /* End of Xtract */ - } - /* End of while */ + } + /* End of switch */ - return(TotalSec); + } + /* End of while */ + + return (TotalSec); } -dword IsPhoenixBIOS(FILE *ptx, byte *Buf) +dword IsPhoenixBIOS(FILE * ptx, byte * Buf) { - dword CurPos = 0; - byte FirstPattern[] = "Phoenix FirstBIOS"; - byte PhoenixPattern[] = "PhoenixBIOS 4.0"; - - rewind(ptx); - while(!feof(ptx)) - { - fread(Buf,1,BLOCK,ptx); - if((CurPos=FoundAt(ptx,Buf,PhoenixPattern,BLOCK))!=0) - break; + dword CurPos = 0; + byte FirstPattern[] = "Phoenix FirstBIOS"; + byte 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; + 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; - } - + CurPos = ftell(ptx) - 0x100; + } + /*---------Neither PhoenixBIOS 4.0 nor FirstBIOS---*/ - if(feof(ptx)) return(0); - - } - - return(CurPos); + if (feof(ptx)) + return (0); + + } + + return (CurPos); } diff --git a/phnxdeco/phnxhelp.h b/phnxdeco/phnxhelp.h index edc2cdd..fbeefb8 100644 --- a/phnxdeco/phnxhelp.h +++ b/phnxdeco/phnxhelp.h @@ -9,76 +9,61 @@ #include <stdio.h> -byte HelpSystem(byte argc, byte *argv[]) - { - byte x = 0, retcode = 0; +byte HelpSystem(byte argc, byte * argv[]) +{ + byte 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); - -#ifndef __LINUX_NOW__ - 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 DOS, Win3.xx, Win9x/NT/2K or DosEmu\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\n",__DATE__,__TIME__); + 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); + +#ifndef __LINUX_NOW__ + 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 DOS, Win3.xx, Win9x/NT/2K or DosEmu\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\n", __DATE__, __TIME__); #else - 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__); -#endif - printf("\n"); - retcode = 0x80; + 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__); +#endif + printf("\n"); + retcode = 0x80; + + } - } + 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; + if (StrCmp(argv[x], "-c") == 0) + retcode += 0x40; + } + return (retcode); - 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; - if( StrCmp(argv[x], "-c" ) == 0 ) retcode += 0x40; - } - return(retcode); +} - } - -void PrintHeader(byte* EOL) - { +void PrintHeader(byte * EOL) +{ printf("\n%c%s%c%s", 0x4, SoftName, 0x4, EOL); - } +} void PrintUsage() - { +{ - 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); + 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); - } +} diff --git a/phnxdeco/phnxsoft.h b/phnxdeco/phnxsoft.h index e4d31c3..40bbf3b 100644 --- a/phnxdeco/phnxsoft.h +++ b/phnxdeco/phnxsoft.h @@ -12,7 +12,7 @@ #define SftName "PhoenixDeco" #define SftEMail "Anton Borisov, anton.borisov@gmail.com" - /********SoftWare*************/ - byte SoftName[] = "-="SftName", version "SftVersion"=-"; - byte CopyRights[] = "\n(C) Anton Borisov, 2000, 2002-2004, Portions (C) 1999-2000"; - byte Url[] = "Bug-reports direct to "SftEMail; + /********SoftWare*************/ +byte SoftName[] = "-=" SftName ", version " SftVersion "=-"; +byte CopyRights[] = "\n(C) Anton Borisov, 2000, 2002-2004, Portions (C) 1999-2000"; +byte Url[] = "Bug-reports direct to " SftEMail; diff --git a/phnxdeco/phnxver.h b/phnxdeco/phnxver.h index 59d9d90..268b11b 100644 --- a/phnxdeco/phnxver.h +++ b/phnxdeco/phnxver.h @@ -9,9 +9,9 @@ #include <stdio.h> #ifdef __LINUX_NOW__ - #define SftPlatform "Linux" +#define SftPlatform "Linux" #else - #define SftPlatform "DOS32" +#define SftPlatform "DOS32" #endif #define SftVersion "0.33 ("SftPlatform")" |