⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rasl.c

📁 用于进行real depack
💻 C
📖 第 1 页 / 共 2 页
字号:
                    fromPtr=temp;                    ulFromBufSize = RASL_MAXCODEBYTES;                    bitOffsetTo=fi*nCodeBits;                    bitOffsetFrom=0;                    ra_bitcopy((unsigned char *)toPtr,ulToBufSize,(unsigned char *)fromPtr,ulFromBufSize,bitOffsetTo,bitOffsetFrom,nCodeBits);		       }		/* 		 * If frame came from bad block, set bit corresponding to new position.		 * Only check one of the swapped pair, since other will be done when		 * fi gets there.		 */	                    if (pFlags && inFlags[RASL_BLOCK_NUM(fi)])                        pFlags[RASL_BLOCK_NUM(fo)] |= (1 << RASL_BLOCK_OFF(fo));	    }    }}void ra_bitcopy(unsigned char* toPtr,                unsigned long  ulToBufSize,                unsigned char* fromPtr,                unsigned long  ulFromBufSize,                int            bitOffsetTo,                int            bitOffsetFrom,                int            numBits){    unsigned char* pToLimit   = toPtr   + ulToBufSize;    unsigned char* pFromLimit = fromPtr + ulFromBufSize;    int bofMod8, botMod8, nbMod8, eightMinusBotMod8, eightMinusBofMod8, i, iMax;    unsigned char rightInword, leftInword, *byteOffsetFrom, *byteOffsetTo,                  alignWord, endWord;    unsigned char lmask[9] = {0, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff}; /* Flawfinder: ignore */    unsigned char rmask[9] = {0, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff}; /* Flawfinder: ignore */    int nibbleAlignFrom, nibbleAlignTo, alignCase=30; // special case variables    unsigned char mask[2] = {0x0f, 0xf0}; /* Flawfinder: ignore */    bofMod8 = bitOffsetFrom & 0x07;  // same as %8    botMod8 = bitOffsetTo & 0x07;    nbMod8 = numBits & 0x07;    eightMinusBofMod8 = 8 - bofMod8; // don't want these evaluated every loop    eightMinusBotMod8 = 8 - botMod8;     byteOffsetFrom = fromPtr + (bitOffsetFrom >> 3);    byteOffsetTo = toPtr + (bitOffsetTo >> 3);    iMax = (numBits>>3) - 1; // last output byte not handled inside a loop    if (numBits>>3 == 0)    // quick and easy if we have fewer than 8 bits to align        {       	leftInword = *(byteOffsetFrom++);        rightInword = *(byteOffsetFrom);        alignWord = (leftInword >> bofMod8) + (rightInword << (eightMinusBofMod8));        alignWord &= rmask[nbMod8];    	if (nbMod8 >= eightMinusBotMod8)  // have more extra input bits than                                           // free space in current output byte            {            *(byteOffsetTo) &= rmask[botMod8];            *(byteOffsetTo++) += (alignWord << botMod8);            *(byteOffsetTo) = ((*byteOffsetTo) & lmask[8-(nbMod8-eightMinusBotMod8)])                + (alignWord >> eightMinusBotMod8);            }       	else    // have fewer input bits than free space in current output byte                // be careful not to overwrite extra bits already in output byte             {            endWord = *(byteOffsetTo) & lmask[8-(nbMod8+botMod8)];            *(byteOffsetTo) &= rmask[botMod8];            *(byteOffsetTo) += ((alignWord << botMod8) + endWord);            }        return; // finished, return to calling function  	}	    if (bitOffsetFrom%4 == 0 && bitOffsetTo%4 == 0)     	// byte-packing done here is optimized for the common case of nibble-alignment      {        nibbleAlignFrom = (bitOffsetFrom & 0x04)>>2;  // 0 implies whole-byte alignment         nibbleAlignTo = (bitOffsetTo & 0x04)>>2;      // 1 implies half-byte alignment                if (nibbleAlignFrom == nibbleAlignTo) // either src and dest both byte-aligned                                               // or both half byte-aligned            if (nibbleAlignFrom == 0)                alignCase = 0;            else                alignCase = 3;                if (nibbleAlignFrom != nibbleAlignTo)            if (nibbleAlignFrom == 0)                alignCase = 1;          // src aligned, dest half aligned            else                 alignCase = 2;          // src half aligned, dest aligned        switch (alignCase)        {        case 0:            for (i=0; i<iMax; i++)                *byteOffsetTo++ = *byteOffsetFrom++; // copy byte-by-byte directly                break;            case 1:            for (i=0; i<iMax; i++)  // move two nibbles from src to dest each loop            {                       // shift bits as necessary                *byteOffsetTo = (*byteOffsetTo & mask[0]) +                     ((*byteOffsetFrom & mask[0])<<4);                *++byteOffsetTo = ((*byteOffsetFrom++ & mask[1])>>4);            }                break;            case 2:            for (i=0; i<iMax; i++)  // same as case 1, but shift other direction               {                *byteOffsetTo = ((*byteOffsetFrom & mask[1])>>4);                *byteOffsetTo++ += ((*++byteOffsetFrom & mask[0])<<4);            }                break;        case 3:            {            *byteOffsetTo &= mask[0];  // align first nibble, thereafter this is            *byteOffsetTo += (*byteOffsetFrom & mask[1]);  // just like case 0            for (i=0; i<iMax; i++)                *++byteOffsetTo = *++byteOffsetFrom; // copy byte-by-byte directly            }                   break;        }    }    else    	// this code can handle all source and destination buffer offsets    	    {    	// take the first 8 desired bits from the input buffer, store them    	// in alignWord, then break up alignWord into two pieces to     	// fit in the free space in two consecutive output buffer bytes        for (i=0; i<iMax; i++)        {            leftInword = *(byteOffsetFrom++);            rightInword = *(byteOffsetFrom);            alignWord = (leftInword >> bofMod8) + (rightInword << (eightMinusBofMod8));            *(byteOffsetTo) = (*(byteOffsetTo) & rmask[botMod8]) +                (alignWord << (botMod8));            *(++byteOffsetTo) = alignWord >> (eightMinusBotMod8);        }    }        // special section to set last byte in fromBuf correctly                // even if byte packing was done with the code optimized for nibble-alignment,       	// the tricky job of setting the last output byte is still done here                leftInword = *(byteOffsetFrom++);            rightInword = *(byteOffsetFrom);            alignWord = (leftInword >> bofMod8) + (rightInword << (eightMinusBofMod8));            *(byteOffsetTo) = (*(byteOffsetTo) & rmask[botMod8]) +                (alignWord << (botMod8));            if (nbMod8 >= eightMinusBotMod8)            {            *(++byteOffsetTo) = alignWord >> (eightMinusBotMod8);                          leftInword = *(byteOffsetFrom++);            rightInword = *(byteOffsetFrom);            alignWord = (leftInword >> bofMod8) + (rightInword << (eightMinusBofMod8));            alignWord &= rmask[nbMod8];            *(byteOffsetTo++) += (alignWord << botMod8);            if (byteOffsetTo >= toPtr && byteOffsetTo < pToLimit)            {               *(byteOffsetTo) = ((*byteOffsetTo) & lmask[8-(nbMod8-eightMinusBotMod8)])                                 + (alignWord >> eightMinusBotMod8);            }            }            else            {            endWord = *(++byteOffsetTo) & lmask[8-(nbMod8+botMod8)];            *(byteOffsetTo) = alignWord >> (eightMinusBotMod8);            leftInword = *(byteOffsetFrom++);            rightInword = *(byteOffsetFrom);            alignWord = (leftInword >> bofMod8) + (rightInword << (eightMinusBofMod8));            alignWord &= rmask[nbMod8];            *(byteOffsetTo) += ((alignWord << botMod8) + endWord);            }                }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -