| 1 |
/********************************************** |
| 2 |
** |
| 3 |
** |
| 4 |
** Defines & Functions for AwarDeco |
| 5 |
** |
| 6 |
** |
| 7 |
***********************************************/ |
| 8 |
|
| 9 |
#ifndef AWARDFUNC_H |
| 10 |
#define AWARDFUNC_H 1 |
| 11 |
|
| 12 |
#include <stdio.h> |
| 13 |
#include <stdint.h> |
| 14 |
#include <string.h> |
| 15 |
#include <stdlib.h> |
| 16 |
|
| 17 |
#include "kernel.h" |
| 18 |
|
| 19 |
typedef uint8_t byte; |
| 20 |
typedef uint16_t word; |
| 21 |
typedef uint32_t dword; |
| 22 |
|
| 23 |
#define Xtract 0x10 |
| 24 |
#define List 0x11 |
| 25 |
#define XtractM 0x20 |
| 26 |
#define Copyrights 0x30 |
| 27 |
#define XtractA 0x40 |
| 28 |
#define ListA 0x41 |
| 29 |
#define Help 0x80 |
| 30 |
|
| 31 |
#define BLOCK 0x8000 |
| 32 |
|
| 33 |
#ifndef __LINUX_NOW__ |
| 34 |
#define IDSign "" |
| 35 |
#else |
| 36 |
#define IDSign "+" |
| 37 |
#endif |
| 38 |
|
| 39 |
typedef struct |
| 40 |
{ |
| 41 |
byte HeadLen; |
| 42 |
byte HeadCrc; |
| 43 |
byte Method[5]; |
| 44 |
dword PackLen; |
| 45 |
dword RealLen; |
| 46 |
dword TStamp; |
| 47 |
byte Attr; |
| 48 |
byte Level; |
| 49 |
byte FilenameLen; |
| 50 |
byte FileName[12]; |
| 51 |
word CRC16; |
| 52 |
byte DOS; |
| 53 |
word Empty; |
| 54 |
} LZHHead; |
| 55 |
|
| 56 |
typedef struct |
| 57 |
{ |
| 58 |
byte hdr_size; |
| 59 |
byte hdr_crc; |
| 60 |
byte method[5]; |
| 61 |
dword pack_len; |
| 62 |
dword real_len; |
| 63 |
dword real_cs; |
| 64 |
byte rsrv1; |
| 65 |
byte rsrv2; |
| 66 |
byte name_len; |
| 67 |
} LZHHeader; |
| 68 |
|
| 69 |
typedef struct |
| 70 |
{ |
| 71 |
byte HeadLen; |
| 72 |
byte HeadCrc; |
| 73 |
byte Method[5]; |
| 74 |
dword PackLen; |
| 75 |
dword RealLen; |
| 76 |
dword TStamp; |
| 77 |
byte Attr; |
| 78 |
byte Level; |
| 79 |
byte FilenameLen; |
| 80 |
byte FileName[128]; |
| 81 |
} NewLZHHead; |
| 82 |
|
| 83 |
byte* GetModuleName(word ID) |
| 84 |
{ |
| 85 |
switch(ID){ |
| 86 |
case 0x4000: return ("Logo BitMap"); |
| 87 |
case 0x4001: return ("CPU micro code"); |
| 88 |
case 0x4002: return ("EPA Pattern"); |
| 89 |
case 0x4003: return ("ACPI Table"); |
| 90 |
case 0x4004: return ("VSA Driver"); |
| 91 |
case 0x4005: return ("HPM ROM"); |
| 92 |
case 0x4006: return ("HPC ROM"); |
| 93 |
case 0x4007: return ("VRS ROM"); |
| 94 |
case 0x4008: return ("FNT0 ROM"); |
| 95 |
case 0x4009: return ("FNT1 ROM"); |
| 96 |
case 0x400a: return ("FNT2 ROM"); |
| 97 |
case 0x400b: return ("FNT3 ROM"); |
| 98 |
case 0x400c: return ("FNT4 ROM"); |
| 99 |
case 0x400d: return ("FNT5 ROM"); |
| 100 |
case 0x400e: return ("YGROUP ROM"); |
| 101 |
case 0x400f: return ("MIB ROM"); |
| 102 |
case 0x4010: return ("EPA1 ROM"); |
| 103 |
case 0x4011: return ("LOGO1 ROM"); |
| 104 |
case 0x4012: return ("OEM0 ROM"); |
| 105 |
case 0x4013: return ("OEM1 ROM"); |
| 106 |
case 0x4014: return ("OEM2 ROM"); |
| 107 |
case 0x4015: return ("OEM3 ROM"); |
| 108 |
case 0x4016: return ("OEM4 ROM"); |
| 109 |
case 0x4017: return ("OEM5 ROM"); |
| 110 |
case 0x4018: return ("OEM6 ROM"); |
| 111 |
case 0x4019: return ("OEM7 ROM"); |
| 112 |
case 0x401a: return ("EPA2 ROM"); |
| 113 |
case 0x401b: return ("EPA3 ROM"); |
| 114 |
case 0x401c: return ("EPA4 ROM"); |
| 115 |
case 0x401d: return ("EPA5 ROM"); |
| 116 |
case 0x401e: return ("EPA6 ROM"); |
| 117 |
case 0x401f: return ("EPA7 ROM"); |
| 118 |
case 0x4020: return ("Logo2 ROM"); |
| 119 |
case 0x4021: return ("Logo3 ROM"); |
| 120 |
case 0x4022: return ("Logo4 ROM"); |
| 121 |
case 0x4023: return ("Logo5 ROM"); |
| 122 |
case 0x4024: return ("Logo6 ROM"); |
| 123 |
case 0x4025: return ("Logo7 ROM"); |
| 124 |
case 0x4026: return ("FlashROM"); |
| 125 |
case 0x4027: return ("NNOPROM"); |
| 126 |
case 0x4028: return ("ROS ROM"); |
| 127 |
|
| 128 |
/* ASUS related */ |
| 129 |
case 0x5000: return ("MainBIOS ROM"); |
| 130 |
case 0x6000: return ("BIOS Editor"); |
| 131 |
case 0x2400: return ("OnScreen Strings"); |
| 132 |
|
| 133 |
default: return ("User-defined ;)"); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
byte StrLen(byte *Str){ int i=0; while(*(Str+i)!=0x0) i++; return(i); }; |
| 138 |
byte StrCmp(byte *Dst, byte *Src) |
| 139 |
{ |
| 140 |
byte i; |
| 141 |
|
| 142 |
for( i = 0; i < StrLen(Src); i++ ) |
| 143 |
if( Dst[i] != Src[i] ) return(1); |
| 144 |
return(0); |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
byte *GetFullDate(byte *mon, byte *day, byte *year) |
| 149 |
{ |
| 150 |
static byte const*const Months[]={"", |
| 151 |
"January", |
| 152 |
"February", |
| 153 |
"March", |
| 154 |
"April", |
| 155 |
"May", |
| 156 |
"June", |
| 157 |
"July", |
| 158 |
"August", |
| 159 |
"September", |
| 160 |
"October", |
| 161 |
"November", |
| 162 |
"December"}; |
| 163 |
static byte Buf[20]; // Warning: we return this buffer, so place it in heap not on stack! |
| 164 |
sprintf(Buf,"%2.2s",year); |
| 165 |
|
| 166 |
if((atoi(Buf)>=0) && (atoi(Buf)<70)) sprintf(Buf,"%.2s %s %s%.2s",day,Months[atoi(mon)],"20",year); |
| 167 |
else sprintf(Buf,"%.2s %s %s%.2s",day,Months[atoi(mon)],"19",year); |
| 168 |
|
| 169 |
return(Buf); |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
byte Compute_Head_CRC(FILE *ptx, dword Offset,byte hdr_size) |
| 174 |
{ |
| 175 |
byte CRC = 0, tmp, i; |
| 176 |
|
| 177 |
fseek(ptx,Offset+2,0); |
| 178 |
for(i=0;i<hdr_size;i++) { |
| 179 |
fread(&tmp,1,1,ptx); |
| 180 |
CRC += tmp; |
| 181 |
} |
| 182 |
return(CRC); |
| 183 |
} |
| 184 |
|
| 185 |
/*--------------------------------- |
| 186 |
FindHook |
| 187 |
----------------------------------*/ |
| 188 |
|
| 189 |
dword FoundAt(FILE *ptx, byte *Buf, byte *Pattern, dword BLOCK_LEN) |
| 190 |
{ |
| 191 |
|
| 192 |
dword i, Ret; |
| 193 |
word Len; |
| 194 |
Len = StrLen(Pattern); |
| 195 |
for(i=0;i<BLOCK_LEN-Len;i++){ |
| 196 |
if(memcmp(Buf+i,Pattern,Len)==0) |
| 197 |
{ |
| 198 |
Ret = ftell(ptx)-(BLOCK_LEN-i); |
| 199 |
return(Ret); |
| 200 |
} |
| 201 |
} |
| 202 |
/* ---------- No Good, No Positive Result --------*/ |
| 203 |
return 0; |
| 204 |
} |
| 205 |
|
| 206 |
/*--------------------------------- |
| 207 |
XtractAwd |
| 208 |
----------------------------------*/ |
| 209 |
byte XtractAwd(FILE *ptx, byte Action, dword DecoOff, dword FirstOff, byte isASUS) |
| 210 |
{ |
| 211 |
|
| 212 |
FILE *pto; |
| 213 |
interfacing interface; |
| 214 |
byte PartTotal=0, CntMods = 0; |
| 215 |
NewLZHHead head; |
| 216 |
byte Buf[32], Buf2[128], Len = 0xFF; |
| 217 |
dword i, k, CurPos = 0; |
| 218 |
byte SkipMech = 0; |
| 219 |
|
| 220 |
switch(Action) |
| 221 |
{ |
| 222 |
case List: |
| 223 |
printf("\n"); |
| 224 |
printf( |
| 225 |
"+-----------------------------------------------------------------------------+\n" |
| 226 |
"| # Name Description FileOffset Ratio ID |\n" |
| 227 |
"+-----------------------------------------------------------------------------+\n"); |
| 228 |
break; |
| 229 |
|
| 230 |
case Xtract: |
| 231 |
printf("\n"); |
| 232 |
printf( |
| 233 |
"+-----------------------------------------------------------------------------+\n" |
| 234 |
"| # Name Offset Packed Real (decimal) Ratio MemorySEG |\n" |
| 235 |
"+-----------------------------------------------------------------------------+\n"); |
| 236 |
break; |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
/* ---------- Check the size of ROM -------------------------- */ |
| 242 |
|
| 243 |
if (DecoOff > 0x40000 || isASUS ) SkipMech = 2; else SkipMech = 1; |
| 244 |
printf("\nHINT: SkipMechanism:\t%X", SkipMech); |
| 245 |
|
| 246 |
/* ---------- Count down the number of -lh5- modules --------- */ |
| 247 |
i = FirstOff; |
| 248 |
do |
| 249 |
{ |
| 250 |
fseek(ptx, i, 0); |
| 251 |
|
| 252 |
/* --------- */ |
| 253 |
fread(&head, sizeof(head), 1, ptx); |
| 254 |
/* -------- str differs if !ZERO --------- */ |
| 255 |
if(StrCmp( head.Method, "-lh5-" ) ) |
| 256 |
{ |
| 257 |
if ( head.HeadLen == 0x0 ) |
| 258 |
{ |
| 259 |
i+=SkipMech; |
| 260 |
fseek(ptx, i , 0); |
| 261 |
fread(&head, sizeof(head), 1, ptx); |
| 262 |
if(StrCmp( head.Method, "-lh5-" ) ) break; |
| 263 |
} else if ( head. HeadLen == 0xFF ) break; |
| 264 |
} |
| 265 |
|
| 266 |
head.FileName[head.FilenameLen] = '\x0'; |
| 267 |
|
| 268 |
|
| 269 |
switch(Action){ |
| 270 |
case List: |
| 271 |
|
| 272 |
|
| 273 |
printf("\n %2.2i (%24.24s) [%16.16s]:", CntMods++, |
| 274 |
head.FileName, |
| 275 |
GetModuleName(head.TStamp >> 16)); |
| 276 |
printf(" %6.6Xh, %2.2i%, %8.8X", |
| 277 |
i, |
| 278 |
( 100 * head.PackLen / head.RealLen), |
| 279 |
head.TStamp); |
| 280 |
|
| 281 |
break; |
| 282 |
|
| 283 |
case Xtract: |
| 284 |
/* Xtracting Part */ |
| 285 |
|
| 286 |
printf("\n %2.2i (%24.24s): ", CntMods++, head.FileName ); |
| 287 |
printf(" %5.5X => %6.6X, %2.2i%, ID: %8.8X", |
| 288 |
head.PackLen, |
| 289 |
head.RealLen, |
| 290 |
( 100 * head.PackLen / head.RealLen), |
| 291 |
head.TStamp); |
| 292 |
|
| 293 |
|
| 294 |
memcpy(Buf2,head.FileName,head.FilenameLen); |
| 295 |
Buf2[head.FilenameLen] = '\x0'; |
| 296 |
|
| 297 |
if((pto = fopen(Buf2,"wb")) == NULL) { |
| 298 |
printf("\nFile %s I/O error..Exit",Buf); |
| 299 |
exit(1); |
| 300 |
} |
| 301 |
|
| 302 |
interface.infile = ptx; |
| 303 |
interface.outfile = pto; |
| 304 |
interface.original = head.RealLen ; |
| 305 |
interface.packed = head.PackLen; |
| 306 |
|
| 307 |
interface.dicbit = 13; |
| 308 |
interface.method = 5; |
| 309 |
|
| 310 |
fseek(ptx, -sizeof(head) + head.HeadLen + 2 , 1); |
| 311 |
|
| 312 |
decode(interface); |
| 313 |
fclose(pto); |
| 314 |
|
| 315 |
printf(" ... Ok"); |
| 316 |
|
| 317 |
|
| 318 |
break; |
| 319 |
/* End of Xtract */ |
| 320 |
|
| 321 |
case XtractM: |
| 322 |
/* Xtracting Part */ |
| 323 |
|
| 324 |
printf("\n %2.2i (%12.12s): ", CntMods++, head.FileName ); |
| 325 |
printf(" %5.5X => %6.6X (%6.6i), %2.2i%, ID: %8.8X", |
| 326 |
head.PackLen, |
| 327 |
head.RealLen,head.RealLen, |
| 328 |
( 100 * head.PackLen / head.RealLen), |
| 329 |
head.TStamp); |
| 330 |
|
| 331 |
|
| 332 |
sprintf(Buf,"%.12s.lzh", head.FileName); |
| 333 |
|
| 334 |
if((pto = fopen(Buf,"wb")) == NULL) { |
| 335 |
printf("\nFile %s I/O error..Exit",Buf); |
| 336 |
exit(1); |
| 337 |
} |
| 338 |
|
| 339 |
fseek(ptx, -(sizeof(head)), 1); |
| 340 |
for( k=0; k < (head.PackLen+head.HeadLen+2); k++ ) |
| 341 |
{ |
| 342 |
|
| 343 |
fread (&Buf[0], 1, 1, ptx); |
| 344 |
fwrite(&Buf[0], 1, 1, pto); |
| 345 |
|
| 346 |
} |
| 347 |
fclose(pto); |
| 348 |
|
| 349 |
|
| 350 |
break; |
| 351 |
/* End of XtractM */ |
| 352 |
|
| 353 |
case Copyrights: |
| 354 |
|
| 355 |
/* ---------- Print BIOS Copyrighted Info --------- */ |
| 356 |
if(head.TStamp == 0x50000000) |
| 357 |
{ |
| 358 |
CurPos = ftell(ptx); |
| 359 |
|
| 360 |
if(!FirstOff) fseek(ptx, head.HeadLen + 2, 0); |
| 361 |
|
| 362 |
if((pto = tmpfile()) == NULL) { |
| 363 |
printf("\nFile tmpfile I/O error..Exit"); |
| 364 |
exit(1); |
| 365 |
} |
| 366 |
|
| 367 |
interface.infile = ptx; |
| 368 |
interface.outfile = pto; |
| 369 |
interface.original = head.RealLen ; |
| 370 |
interface.packed = head.PackLen; |
| 371 |
|
| 372 |
interface.dicbit = 13; |
| 373 |
interface.method = 5; |
| 374 |
decode(interface); |
| 375 |
|
| 376 |
/* ------- Move to first (C) ---------- */ |
| 377 |
|
| 378 |
printf("\n+---------------------------------------------------------+"); |
| 379 |
|
| 380 |
fseek(pto, 0x1E060L, 0); |
| 381 |
fread(&Len, sizeof(byte), 1, pto); |
| 382 |
fread(&Buf2, Len, sizeof(byte), pto); |
| 383 |
printf("\n\t%s", Buf2); |
| 384 |
|
| 385 |
fseek(pto, 0x1E090L, 0); |
| 386 |
fread(&Len, sizeof(byte), 1, pto); |
| 387 |
fread(&Buf2, Len, sizeof(byte), pto); |
| 388 |
printf("\n\t%s", Buf2); |
| 389 |
|
| 390 |
fseek(pto, 0x1E0C0L, 0); |
| 391 |
fread(&Len, sizeof(byte), 1, pto); |
| 392 |
fread(&Buf2, Len, sizeof(byte), pto); |
| 393 |
printf("\n\t%s", Buf2); |
| 394 |
|
| 395 |
fseek(pto, 0x1EC70, 0); |
| 396 |
fread(&Len, 1, sizeof(byte), pto); |
| 397 |
fread(&Buf2, Len, sizeof(byte), pto); |
| 398 |
printf("\n\t%s", Buf2); |
| 399 |
|
| 400 |
printf("\n+---------------------------------------------------------+"); |
| 401 |
|
| 402 |
fclose(pto); |
| 403 |
|
| 404 |
fseek(ptx, CurPos, 0); |
| 405 |
} |
| 406 |
|
| 407 |
/* Show Copyrights End */ |
| 408 |
break; |
| 409 |
} |
| 410 |
|
| 411 |
|
| 412 |
if ( !isASUS && (head.TStamp == 0x50000000) && (CntMods == 1) ) |
| 413 |
i+=2; |
| 414 |
|
| 415 |
i += (head.PackLen + head.HeadLen + 2); |
| 416 |
|
| 417 |
|
| 418 |
} while ( (i < DecoOff) ); |
| 419 |
|
| 420 |
|
| 421 |
return (CntMods); |
| 422 |
|
| 423 |
} |
| 424 |
|
| 425 |
|
| 426 |
byte TotalSecA(FILE *ptx, byte *Buf, byte Action, dword BootBlockOffset) |
| 427 |
{ |
| 428 |
FILE *pto; |
| 429 |
interfacing interface; |
| 430 |
byte Buffer[12]; |
| 431 |
|
| 432 |
byte Buf2[128]; |
| 433 |
|
| 434 |
dword CurPos = 0; |
| 435 |
dword RealRead = 0, i, TotalRead = 0, Tmp; |
| 436 |
byte Head[] = "-lh5-"; |
| 437 |
dword End = 0xFFFFFFFF; |
| 438 |
byte TotalSec = 0; |
| 439 |
NewLZHHead awdhead; |
| 440 |
|
| 441 |
|
| 442 |
switch(Action) |
| 443 |
{ |
| 444 |
case ListA: |
| 445 |
printf("\n"); |
| 446 |
printf( |
| 447 |
"+-----------------------------------------------------------------------------+\n" |
| 448 |
"| # Name Description FileOffset Ratio ID |\n" |
| 449 |
"+-----------------------------------------------------------------------------+\n"); |
| 450 |
break; |
| 451 |
|
| 452 |
case XtractA: |
| 453 |
printf("\n"); |
| 454 |
printf( |
| 455 |
"+-----------------------------------------------------------------------------+\n" |
| 456 |
"| # Name Offset Packed Real (decimal) Ratio MemorySEG |\n" |
| 457 |
"+-----------------------------------------------------------------------------+\n"); |
| 458 |
break; |
| 459 |
} |
| 460 |
|
| 461 |
fseek(ptx,0,2); End = ftell(ptx); rewind(ptx); |
| 462 |
|
| 463 |
while( (!feof(ptx)) || (CurPos > BootBlockOffset) ) |
| 464 |
{ |
| 465 |
fseek(ptx, CurPos, 0); |
| 466 |
|
| 467 |
RealRead = fread(Buf,1,BLOCK,ptx); |
| 468 |
TotalRead += RealRead; |
| 469 |
|
| 470 |
if( RealRead != BLOCK ) |
| 471 |
{ |
| 472 |
for( i = RealRead; i < BLOCK; i++) Buf[i] = 0xFF; |
| 473 |
} |
| 474 |
|
| 475 |
if(RealRead < 0x80) break; |
| 476 |
|
| 477 |
if( (CurPos = FoundAt(ptx, Buf, Head, RealRead)) !=0 ) |
| 478 |
{ |
| 479 |
fseek(ptx, CurPos - 2, 0); |
| 480 |
TotalSec++; |
| 481 |
fread(&awdhead,1,sizeof(awdhead),ptx); |
| 482 |
awdhead.FileName[awdhead.FilenameLen] = '\x0'; |
| 483 |
|
| 484 |
/////////////////////////////// |
| 485 |
// switch action |
| 486 |
/////////////////////////////// |
| 487 |
|
| 488 |
switch(Action) |
| 489 |
{ |
| 490 |
case ListA: |
| 491 |
|
| 492 |
|
| 493 |
printf("\n %2.2i (%24.24s) [%16.16s]:", TotalSec, |
| 494 |
awdhead.FileName, |
| 495 |
GetModuleName(awdhead.TStamp >> 16)); |
| 496 |
printf(" %6.6Xh, %2.2i%, %8.8X", |
| 497 |
CurPos - 2, |
| 498 |
( 100 * awdhead.PackLen / awdhead.RealLen), |
| 499 |
awdhead.TStamp); |
| 500 |
|
| 501 |
break; |
| 502 |
|
| 503 |
case XtractA: |
| 504 |
/* Xtracting Part */ |
| 505 |
|
| 506 |
|
| 507 |
printf("\n %2.2i (%24.24s): ", TotalSec, awdhead.FileName ); |
| 508 |
printf(" %5.5X => %6.6X, %2.2i%, ID: %8.8X", |
| 509 |
awdhead.PackLen, |
| 510 |
awdhead.RealLen, |
| 511 |
( 100 * awdhead.PackLen / awdhead.RealLen), |
| 512 |
awdhead.TStamp); |
| 513 |
|
| 514 |
|
| 515 |
memcpy(Buf2, awdhead.FileName, awdhead.FilenameLen); |
| 516 |
Buf2[awdhead.FilenameLen] = '\x0'; |
| 517 |
|
| 518 |
if((pto = fopen(Buf2, "wb")) == NULL) { |
| 519 |
printf("\nFile %s I/O error..Exit", Buf); |
| 520 |
exit(1); |
| 521 |
} |
| 522 |
|
| 523 |
interface.infile = ptx; |
| 524 |
interface.outfile = pto; |
| 525 |
interface.original = awdhead.RealLen ; |
| 526 |
interface.packed = awdhead.PackLen; |
| 527 |
|
| 528 |
interface.dicbit = 13; |
| 529 |
interface.method = 5; |
| 530 |
|
| 531 |
fseek(ptx, -sizeof(awdhead) + awdhead.HeadLen + 2 , 1); |
| 532 |
|
| 533 |
decode(interface); |
| 534 |
fclose(pto); |
| 535 |
|
| 536 |
printf(" ... Ok"); |
| 537 |
|
| 538 |
|
| 539 |
break; |
| 540 |
|
| 541 |
/* End of Xtract */ |
| 542 |
|
| 543 |
} |
| 544 |
////////////////////////////// |
| 545 |
/// |
| 546 |
////////////////////////////// |
| 547 |
|
| 548 |
|
| 549 |
CurPos += awdhead.PackLen; |
| 550 |
|
| 551 |
} else CurPos = ftell(ptx); |
| 552 |
|
| 553 |
} |
| 554 |
|
| 555 |
|
| 556 |
return(TotalSec); |
| 557 |
} |
| 558 |
|
| 559 |
#endif |