bool RarVolume::DecryptRead(DiskFile& file, void* buffer, int64 size) { while (size > 0) { if (m_decryptPos >= 16) { uint8 buf[16]; if (file.Read(&buf, sizeof(buf)) != sizeof(buf)) return false; m_decryptPos = 0; if (!DecryptBuf(buf, m_decryptBuf)) return false; } uint8 remainingBuf = 16 - m_decryptPos; uint8 len = size <= remainingBuf ? (uint8)size : remainingBuf; memcpy(buffer, m_decryptBuf + m_decryptPos, len); m_decryptPos += len; size -= len; buffer = (char*)buffer + len; } return true; }
static int pof_handle_data(hysdn_card * card, int datlen) { struct boot_data *boot = card->boot; /* pointer to boot specific data */ long l; uchar *imgp; int img_len; /* handle the different record types */ switch (boot->pof_recid) { case TAG_TIMESTMP: if (card->debug_flags & LOG_POF_RECORD) hysdn_addlog(card, "POF created %s", boot->buf.PofTime.DateTimeText); break; case TAG_CBOOTDTA: DecryptBuf(boot, datlen); /* we need to encrypt the buffer */ case TAG_BOOTDTA: if (card->debug_flags & LOG_POF_RECORD) hysdn_addlog(card, "POF got %s len=%d offs=0x%lx", (boot->pof_recid == TAG_CBOOTDTA) ? "CBOOTDATA" : "BOOTDTA", datlen, boot->pof_recoffset); if (boot->pof_reclen != POF_BOOT_LOADER_TOTAL_SIZE) { boot->last_error = EPOF_BAD_IMG_SIZE; /* invalid length */ return (boot->last_error); } imgp = boot->buf.BootBuf; /* start of buffer */ img_len = datlen; /* maximum length to transfer */ l = POF_BOOT_LOADER_OFF_IN_PAGE - (boot->pof_recoffset & (POF_BOOT_LOADER_PAGE_SIZE - 1)); if (l > 0) { /* buffer needs to be truncated */ imgp += l; /* advance pointer */ img_len -= l; /* adjust len */ } /* at this point no special handling for data wrapping over buffer */ /* is necessary, because the boot image always will be adjusted to */ /* match a page boundary inside the buffer. */ /* The buffer for the boot image on the card is filled in 2 cycles */ /* first the 1024 hi-words are put in the buffer, then the low 1024 */ /* word are handled in the same way with different offset. */ if (img_len > 0) { /* data available for copy */ if ((boot->last_error = card->writebootimg(card, imgp, (boot->pof_recoffset > POF_BOOT_LOADER_PAGE_SIZE) ? 2 : 0)) < 0) return (boot->last_error); } break; /* end of case boot image hi/lo */ case TAG_CABSDATA: DecryptBuf(boot, datlen); /* we need to encrypt the buffer */ case TAG_ABSDATA: if (card->debug_flags & LOG_POF_RECORD) hysdn_addlog(card, "POF got %s len=%d offs=0x%lx", (boot->pof_recid == TAG_CABSDATA) ? "CABSDATA" : "ABSDATA", datlen, boot->pof_recoffset); if ((boot->last_error = card->writebootseq(card, boot->buf.BootBuf, datlen) < 0)) return (boot->last_error); /* error writing data */ if (boot->pof_recoffset + datlen >= boot->pof_reclen) return (card->waitpofready(card)); /* data completely spooled, wait for ready */ break; /* end of case boot seq data */ default: if (card->debug_flags & LOG_POF_RECORD) hysdn_addlog(card, "POF got data(id=0x%lx) len=%d offs=0x%lx", boot->pof_recid, datlen, boot->pof_recoffset); break; /* simply skip record */ } /* switch boot->pof_recid */ return (0); } /* pof_handle_data */
static int pof_handle_data(hysdn_card * card, int datlen) { struct boot_data *boot = card->boot; long l; unsigned char *imgp; int img_len; switch (boot->pof_recid) { case TAG_TIMESTMP: if (card->debug_flags & LOG_POF_RECORD) hysdn_addlog(card, "POF created %s", boot->buf.PofTime.DateTimeText); break; case TAG_CBOOTDTA: DecryptBuf(boot, datlen); case TAG_BOOTDTA: if (card->debug_flags & LOG_POF_RECORD) hysdn_addlog(card, "POF got %s len=%d offs=0x%lx", (boot->pof_recid == TAG_CBOOTDTA) ? "CBOOTDATA" : "BOOTDTA", datlen, boot->pof_recoffset); if (boot->pof_reclen != POF_BOOT_LOADER_TOTAL_SIZE) { boot->last_error = EPOF_BAD_IMG_SIZE; return (boot->last_error); } imgp = boot->buf.BootBuf; img_len = datlen; l = POF_BOOT_LOADER_OFF_IN_PAGE - (boot->pof_recoffset & (POF_BOOT_LOADER_PAGE_SIZE - 1)); if (l > 0) { imgp += l; img_len -= l; } if (img_len > 0) { if ((boot->last_error = card->writebootimg(card, imgp, (boot->pof_recoffset > POF_BOOT_LOADER_PAGE_SIZE) ? 2 : 0)) < 0) return (boot->last_error); } break; case TAG_CABSDATA: DecryptBuf(boot, datlen); case TAG_ABSDATA: if (card->debug_flags & LOG_POF_RECORD) hysdn_addlog(card, "POF got %s len=%d offs=0x%lx", (boot->pof_recid == TAG_CABSDATA) ? "CABSDATA" : "ABSDATA", datlen, boot->pof_recoffset); if ((boot->last_error = card->writebootseq(card, boot->buf.BootBuf, datlen) < 0)) return (boot->last_error); if (boot->pof_recoffset + datlen >= boot->pof_reclen) return (card->waitpofready(card)); break; default: if (card->debug_flags & LOG_POF_RECORD) hysdn_addlog(card, "POF got data(id=0x%lx) len=%d offs=0x%lx", boot->pof_recid, datlen, boot->pof_recoffset); break; } return (0); }