| 471 | // Main exploding function. |
| 472 | |
| 473 | unsigned int PKWAREAPI explode( |
| 474 | unsigned int (PKWAREAPI *read_buf)(char *buf, unsigned int *size, void *param), |
| 475 | void (PKWAREAPI *write_buf)(char *buf, unsigned int *size, void *param), |
| 476 | char *work_buf, |
| 477 | void *param) |
| 478 | { |
| 479 | TDcmpStruct * pWork = (TDcmpStruct *)work_buf; |
| 480 | |
| 481 | // Initialize work struct and load compressed data |
| 482 | // Note: The caller must zero the "work_buff" before passing it to explode |
| 483 | pWork->read_buf = read_buf; |
| 484 | pWork->write_buf = write_buf; |
| 485 | pWork->param = param; |
| 486 | pWork->in_pos = sizeof(pWork->in_buff); |
| 487 | pWork->in_bytes = pWork->read_buf((char *)pWork->in_buff, &pWork->in_pos, pWork->param); |
| 488 | if(pWork->in_bytes <= 4) |
| 489 | return CMP_BAD_DATA; |
| 490 | |
| 491 | pWork->ctype = pWork->in_buff[0]; // Get the compression type (CMP_BINARY or CMP_ASCII) |
| 492 | pWork->dsize_bits = pWork->in_buff[1]; // Get the dictionary size |
| 493 | pWork->bit_buff = pWork->in_buff[2]; // Initialize 16-bit bit buffer |
| 494 | pWork->extra_bits = 0; // Extra (over 8) bits |
| 495 | pWork->in_pos = 3; // Position in input buffer |
| 496 | |
| 497 | // Test for the valid dictionary size |
| 498 | if(4 > pWork->dsize_bits || pWork->dsize_bits > 6) |
| 499 | return CMP_INVALID_DICTSIZE; |
| 500 | |
| 501 | pWork->dsize_mask = 0xFFFF >> (0x10 - pWork->dsize_bits); // Shifted by 'sar' instruction |
| 502 | |
| 503 | if(pWork->ctype != CMP_BINARY) |
| 504 | { |
| 505 | if(pWork->ctype != CMP_ASCII) |
| 506 | return CMP_INVALID_MODE; |
| 507 | |
| 508 | memcpy(pWork->ChBitsAsc, ChBitsAsc, sizeof(pWork->ChBitsAsc)); |
| 509 | GenAscTabs(pWork); |
| 510 | } |
| 511 | |
| 512 | memcpy(pWork->LenBits, LenBits, sizeof(pWork->LenBits)); |
| 513 | GenDecodeTabs(pWork->LengthCodes, LenCode, pWork->LenBits, sizeof(pWork->LenBits)); |
| 514 | memcpy(pWork->ExLenBits, ExLenBits, sizeof(pWork->ExLenBits)); |
| 515 | memcpy(pWork->LenBase, LenBase, sizeof(pWork->LenBase)); |
| 516 | memcpy(pWork->DistBits, DistBits, sizeof(pWork->DistBits)); |
| 517 | GenDecodeTabs(pWork->DistPosCodes, DistCode, pWork->DistBits, sizeof(pWork->DistBits)); |
| 518 | if(Expand(pWork) != 0x306) |
| 519 | return CMP_NO_ERROR; |
| 520 | |
| 521 | return CMP_ABORT; |
| 522 | } |
no test coverage detected