Esempio n. 1
0
_String*        _CString::DecompressLZW (void)
{
    _String* theAlphabet = SelectAlpha (this->compressionType);


    if (!sLength||(!IsFlag( LZWCOMPRESSION))) {
        return nil;    //nothing to do!
    }
    _List theTable;

    _String output(storageIncrement,true), testString;
    long codeMax = 0, oldCode;

    // init the table

    for (long j = 0; j<(*theAlphabet).sLength; j++) {
        _String a((*theAlphabet)[j]);
        theTable&&(&a);
    }

    long p = 0;

    oldCode = GetNextCode(*this,p);
//  output = output&*  (_String*)theTable(oldCode);
    output <<  (_String*)theTable(oldCode);

    for (; p<sLength-1;) {
        codeMax=GetNextCode(*this,p);
        if (theTable.countitems()-1>=codeMax) {
            output << (_String*)theTable(codeMax);
//          output = output& *(_String*)theTable(codeMax);
            _String addOn((*(_String*)theTable(oldCode)));
            addOn =addOn&*((_String*)theTable(codeMax))[0];
            theTable&& &addOn;
            oldCode = codeMax;
        } else {
            testString =  *(_String*)theTable(oldCode);
            testString = testString&testString.getChar(0);
            theTable&&(&testString);
            output << &testString;
//          output = output & testString;
            oldCode = codeMax;
        }
    }
    output.Finalize();

    // debugging info
//  _String* bs = (_String*)theTable.toStr();
//  printf ("\nString Table:%s\n",bs->getStr());
//  DeleteObject(bs);

    // end debugging

    return (_String*)output.makeDynamic();
}
Esempio n. 2
0
void CWCheatEngine::SkipCodes(int count) {
	for (int i = 0; i < count; i ++) {
		if (GetNextCode()[0] == 0) {
			break;
		}
	}
}
Esempio n. 3
0
void CWCheatEngine::SkipCodes(int count) {
	for (int i = 0; i < count; i ++) {
		auto code = GetNextCode();
		if (code.empty())
		{
			WARN_LOG(COMMON, "CWCHEAT: Tried to skip more codes than there are, the cheat is most likely wrong");
			break;
		}
		if (code[0] == 0) {
			break;
		}
	}
}
Esempio n. 4
0
BOOL CHSDownloadData::DownLoadData()
{
	CriticalGuard guard(&m_critical);
	long lLen;
	StockUserInfo* pStock = NULL;
	short nPeriod;
	SetTaskMask(m_nCulType);
	m_nCulType ++;
	if ( m_nCulType >= 4)
		m_nCulType = 1;
	GetNextCode(&pStock, nPeriod);
	char* pBuffer = MakeReqPacket(&pStock->m_ciStockCode,nPeriod,lLen);

	if(pBuffer == NULL)
	{
		DownLoadData();
	}
	else
	{
		HSMarketDataType market = pStock->m_ciStockCode.m_cCodeType & 0xF000;
		char cServerType = CEV_Connect_HQ;

		if(market == FUTURES_MARKET)
		{
			//cServerType = CEV_Connect_QH;  //期货
		}

		if (market == HK_MARKET)
		{
			//cServerType = CEV_Connect_GG;  //港股
		}
		if ( m_pDataSource && !IsBadReadPtr(m_pDataSource,1))
			m_pDataSource->HSDataSource_RequestAsyncData(m_nDataSourceID,pBuffer,lLen,-1,e_DataSouceSend_Normal|e_DataSourceSend_HQDataDownLoad,
			                     m_lHandle);
		TRACE2("\r\n send packet code:%s, nPeriod:%d \r\n", pStock->GetName(),nPeriod);
	}
	return TRUE;	
}
Esempio n. 5
0
int
BitmapIO_GIF::Decoder(WORD linewidth, BYTE *buf, BYTE *stack, BYTE *suffix, USHORT *prefix)
   {
   BYTE *sp = NULL, *bufptr=NULL;
   WORD code=0, fc=0, oc=0, bufcnt=0;
   WORD c=0, size=0;
   int ret=0;

   /* Initialize for decoding a new image...
    */
   if ((size = GIFGetByte()) < 0)
      return(size);
   if (size < 2 || 9 < size) {
#ifdef DBG_GIF
		DebugPrint(_T("<BAD DECODE SIZE:%d>\n"), size);
#endif // DBG_GIF
       return(BAD_CODE_SIZE);
	   }
   InitExp(size);

   /* Initialize in case they forgot to put in a clear code.
    * (This shouldn't happen, but we'll try and decode it anyway...)
    */
   oc = fc = 0;


   /* Set up the stack pointer and decode buffer pointer
    */
   sp = stack;
#ifdef DBG_DIG
   DebugPrint(_T("Initial stack:%p sp:%p\n"),stack, sp);
#endif //DBG_GIF
   bufptr = buf;
   bufcnt = linewidth;

   /* This is the main loop.  For each code we get we pass through the
    * linked list of prefix codes, pushing the corresponding "character" for
    * each code onto the stack.  When the list reaches a single "character"
    * we push that on the stack too, and then start unstacking each
    * character for output in the correct order.  Special handling is
    * included for the clear code, and the whole thing ends when we get
    * an ending code.
    */
   while ((c = GetNextCode()) != ending)
      {

      /* If we had a file error, return without completing the decode
       */
      if (c < 0)
         {
         return(c);
         }

      /* If the code is a clear code, reinitialize all necessary items.
       */
      if (c == clear)
         {
         curr_size = size + 1;
         slot = newcodes;
         top_slot = 1 << curr_size;

         /* Continue reading codes until we get a non-clear code
          * (Another unlikely, but possible case...)
          */
         while ((c = GetNextCode()) == clear)
            ;

         /* If we get an ending code immediately after a clear code
          * (Yet another unlikely case), then break out of the loop.
          */
         if (c == ending)
            break;

         /* Finally, if the code is beyond the range of already set codes,
          * (This one had better NOT happen...  I have no idea what will
          * result from this, but I doubt it will look good...) then set it
          * to color zero.
          */
         if (c >= slot)
            c = 0;

         oc = fc = c;

         /* And let us not forget to put the char into the buffer... And
          * if, on the off chance, we were exactly one pixel from the end
          * of the line, we have to send the buffer to the gif_out_line()
          * routine...
          */
         *bufptr++ = (BYTE)c;
         if (--bufcnt == 0)
            {
			if((ret = GIFOutLine(buf, linewidth)) < 0)
			    return(ret);
            bufptr = buf;
            bufcnt = linewidth;
            }
         }
      else
         {

         /* In this case, it's not a clear code or an ending code, so
          * it must be a code code...  So we can now decode the code into
          * a stack of character codes. (Clear as mud, right?)
          */
         code = c;

         /* Here we go again with one of those off chances...  If, on the
          * off chance, the code we got is beyond the range of those already
          * set up (Another thing which had better NOT happen...) we trick
          * the decoder into thinking it actually got the last code read.
          * (Hmmn... I'm not sure why this works...  But it does...)
          */
         if (code >= slot)
            {
            if (code > slot)
               ++bad_code_count;
            code = oc;

			if((sp - stack) <= MAX_CODES)
				*sp++ = (BYTE)fc;
            }

         /* Here we scan back along the linked list of prefixes, pushing
          * helpless characters (ie. suffixes) onto the stack as we do so.
          */
         while (code >= newcodes)
            {
			if((sp - stack) > MAX_CODES)
				break;
			*sp++ = suffix[code];
            code = prefix[code];
            }

         /* Push the last character on the stack, and set up the new
          * prefix and suffix, and if the required slot number is greater
          * than that allowed by the current bit size, increase the bit
          * size.  (NOTE - If we are all full, we *don't* save the new
          * suffix and prefix...  I'm not certain if this is correct...
          * it might be more proper to overwrite the last code...
          */
         if((sp - stack) <= MAX_CODES)
			*sp++ = (BYTE)code;
         if (slot < top_slot)
            {
            fc = code;
            suffix[slot] = (BYTE)code;
            prefix[slot++] = oc;
            oc = c;
            }
         if (slot >= top_slot)
            if (curr_size < 12)
               {
               top_slot <<= 1;
               ++curr_size;
               } 

         /* Now that we've pushed the decoded string (in reverse order)
          * onto the stack, lets pop it off and put it into our decode
          * buffer...  And when the decode buffer is full, write another
          * line...
          */
         while (sp > stack)
            {
            *bufptr++ = *(--sp);
            if (--bufcnt == 0)
				{
				if ((ret = GIFOutLine(buf, linewidth)) < 0)
                    return(ret);
				bufptr = buf;
                bufcnt = linewidth;
                }
            }
         }
      }
   if (bufcnt != linewidth)
       ret = GIFOutLine(buf, (linewidth - bufcnt));
   return(ret);
   }
Esempio n. 6
0
void CWCheatEngine::Run() {
	exit2 = false;
	while (!exit2) {
		currentCode = 0;

		while (true) {
			std::vector<int> code = GetNextCode();
			if (code.size() < 2) {
				Exit();
				break;
			}

			int value;
			unsigned int comm = code[0];
			u32 arg = code[1];
			int addr = GetAddress(comm & 0x0FFFFFFF);

			switch (comm >> 28) {
			case 0: // 8-bit write.But need more check
				if (Memory::IsValidAddress(addr)) {
					InvalidateICache(addr & ~3, 4);
					if (arg < 0x00000100) // 8-bit 
						Memory::Write_U8((u8) arg, addr);
					else if (arg < 0x00010000) // 16-bit
						Memory::Write_U16((u16) arg, addr);
					else // 32-bit
						Memory::Write_U32((u32) arg, addr);
				}
				break;
			case 0x1: // 16-bit write
				if (Memory::IsValidAddress(addr)) {
					InvalidateICache(addr & ~3, 4);
					Memory::Write_U16((u16) arg, addr);
				}
				break;
			case 0x2: // 32-bit write
				if (Memory::IsValidAddress(addr)){
					InvalidateICache(addr & ~3, 4);
					Memory::Write_U32((u32) arg, addr);
				}
				break;
			case 0x3: // Increment/Decrement
				{
					addr = GetAddress(arg & 0x0FFFFFFF);
					InvalidateICache(addr & ~3, 4);
					value = 0;
					int increment = 0;
					// Read value from memory
					switch ((comm >> 20) & 0xF) {
					case 1:
					case 2: // 8-bit
						value = Memory::Read_U8(addr);
						increment = comm & 0xFF;
						break;
					case 3:
					case 4: // 16-bit
						value = Memory::Read_U16(addr);
						increment = comm & 0xFFFF;
						break;
					case 5:
					case 6: // 32-bit
						value = Memory::Read_U32(addr);
						code = GetNextCode();
						if (code[0] != 0) {
							increment = code[0];
						}
						break;
					}
					// Increment/Decrement value
					switch ((comm >> 20) & 0xF) {
					case 1:
					case 3:
					case 5: // increment
						value += increment;
						break;
					case 2:
					case 4:
					case 6: // Decrement
						value -= increment;
						break;
					}
					// Write value back to memory
					switch ((comm >> 20) & 0xF) {
					case 1:
					case 2: // 8-bit
						Memory::Write_U8((u8) value, addr);
						break;
					case 3:
					case 4: // 16-bit
						Memory::Write_U16((u16) value, addr);
						break;
					case 5:
					case 6: // 32-bit
						Memory::Write_U32((u32) value, addr);
						break;
					}
					break;
				}
			case 0x4: // 32-bit patch code
				code = GetNextCode();
				if (true) {
					int data = code[0];
					int dataAdd = code[1];

					int count = (arg >> 16) & 0xFFFF;
					int stepAddr = (arg & 0xFFFF) * 4;

					InvalidateICache(addr, count * stepAddr);
					for (int a  = 0; a < count; a++) {
						if (Memory::IsValidAddress(addr)) {
							Memory::Write_U32((u32) data, addr);
						}
						addr += stepAddr;
						data += dataAdd;
					}
				}
				break;
			case 0x5: // Memcpy command
				code = GetNextCode();
				if (true) {
					int destAddr = GetAddress(code[0]);
					int len = arg;
					InvalidateICache(destAddr, len);
					if (Memory::IsValidAddress(addr) && Memory::IsValidAddress(destAddr)) {
						Memory::Memcpy(destAddr, Memory::GetPointer(addr), len);
					}
				}
				break;
			case 0x6: // Pointer commands
				code = GetNextCode();
				if (code.size() >= 2) {
					int arg2 = code[0];
					int offset = code[1];
					int baseOffset = (arg2 >> 20) * 4;
					InvalidateICache(addr + baseOffset, 4);
					int base = Memory::Read_U32(addr + baseOffset);
					int count = arg2 & 0xFFFF;
					int type = (arg2 >> 16) & 0xF;
					for (int i = 1; i < count; i ++ ) {
						if (i+1 < count) {
							code = GetNextCode();
							if (code.size() < 2) {
								// Code broken. Should warn but would be very spammy...
								break;
							}
							int arg3 = code[0];
							int arg4 = code[1];
							int comm3 = arg3 >> 28;
							switch (comm3) {
							case 0x1: // type copy byte
								{
									int srcAddr = Memory::Read_U32(addr) + offset;
									int dstAddr = Memory::Read_U16(addr + baseOffset) + (arg3 & 0x0FFFFFFF);
									Memory::Memcpy(dstAddr, Memory::GetPointer(srcAddr), arg);
									type = -1; //Done
									break; }
							case 0x2:
							case 0x3: // type pointer walk
								{
									int walkOffset = arg3 & 0x0FFFFFFF;
									if (comm3 == 0x3) {
										walkOffset = -walkOffset;
									}
									base = Memory::Read_U32(base + walkOffset);
									int comm4 = arg4 >> 28;
									switch (comm4) {
									case 0x2:
									case 0x3: // type pointer walk
										walkOffset = arg4 & 0x0FFFFFFF;
										if (comm4 == 0x3) {
											walkOffset = -walkOffset;
										}
										base = Memory::Read_U32(base + walkOffset);
										break;
									}
									break; }
							case 0x9: // type multi address write
								base += arg3 & 0x0FFFFFFF;
								arg += arg4;
								break;
							default:
								break;

							}
						}
					}

					switch (type) {
					case 0: // 8 bit write
						Memory::Write_U8((u8) arg, base + offset);
						break;
					case 1: // 16-bit write
						Memory::Write_U16((u16) arg, base + offset);
						break;
					case 2: // 32-bit write
						Memory::Write_U32((u32) arg, base + offset);
						break;
					case 3: // 8 bit inverse write
						Memory::Write_U8((u8) arg, base - offset);
						break;
					case 4: // 16-bit inverse write
						Memory::Write_U16((u16) arg, base - offset);
						break;
					case 5: // 32-bit inverse write
						Memory::Write_U32((u32) arg, base - offset);
						break;
					case -1: // Operation already performed, nothing to do
						break;
					}
				}
				break;
			case 0x7: // Boolean commands.
				switch (arg >> 16) {
				case 0x0000: // 8-bit OR.
					if (Memory::IsValidAddress(addr)) {
						InvalidateICache(addr & ~3, 4);
						int val1 = (int) (arg & 0xFF);
						int val2 = (int) Memory::Read_U8(addr);
						Memory::Write_U8((u8) (val1 | val2), addr);
					}
					break;
				case 0x0002: // 8-bit AND.
					if (Memory::IsValidAddress(addr)) {
						InvalidateICache(addr & ~3, 4);
						int val1 = (int) (arg & 0xFF);
						int val2 = (int) Memory::Read_U8(addr);
						Memory::Write_U8((u8) (val1 & val2), addr);
					}
					break;
				case 0x0004: // 8-bit XOR.
					if (Memory::IsValidAddress(addr)) {
						InvalidateICache(addr & ~3, 4);
						int val1 = (int) (arg & 0xFF);
						int val2 = (int) Memory::Read_U8(addr);
						Memory::Write_U8((u8) (val1 ^ val2), addr);
					}
					break;
				case 0x0001: // 16-bit OR.
					if (Memory::IsValidAddress(addr)) {
						InvalidateICache(addr & ~3, 4);
						short val1 = (short) (arg & 0xFFFF);
						short val2 = (short) Memory::Read_U16(addr);
						Memory::Write_U16((u16) (val1 | val2), addr);
					}
					break;
				case 0x0003: // 16-bit AND.
					if (Memory::IsValidAddress(addr)) {
						InvalidateICache(addr & ~3, 4);
						short val1 = (short) (arg & 0xFFFF);
						short val2 = (short) Memory::Read_U16(addr);
						Memory::Write_U16((u16) (val1 & val2), addr);
					}
					break;
				case 0x0005: // 16-bit OR.
					if (Memory::IsValidAddress(addr)) {
						InvalidateICache(addr & ~3, 4);
						short val1 = (short) (arg & 0xFFFF);
						short val2 = (short) Memory::Read_U16(addr);
						Memory::Write_U16((u16) (val1 ^ val2), addr);
					}
					break;
				}
				break;
			case 0x8: // 8-bit and 16-bit patch code
				code = GetNextCode();
				if (code.size() >= 2) {
					int data = code[0];
					int dataAdd = code[1];

					bool is8Bit = (data >> 16) == 0x0000;
					int count = (arg >> 16) & 0xFFFF;
					int stepAddr = (arg & 0xFFFF) * (is8Bit ? 1 : 2);
					InvalidateICache(addr, count * stepAddr);
					for (int a = 0; a < count; a++) {
						if (Memory::IsValidAddress(addr)) {
							if (is8Bit) {
								Memory::Write_U8((u8) (data & 0xFF), addr);
							}
							else {
								Memory::Write_U16((u16) (data & 0xFFFF), addr);
							}
						}
						addr += stepAddr;
						data += dataAdd;
					}
				}
Esempio n. 7
0
int lzwInflate(lzw_streamp strm)
{
    struct lzw_internal_state *state;
    uint8_t *from, *to;
    unsigned in, out;
    unsigned have, left;
    long nbits, nextbits, nextdata, nbitsmask;
    code_t *codep, *free_entp, *maxcodep, *oldcodep;

    uint8_t *wp;
    hcode_t code, free_code;
    int echg, ret = LZW_OK;
    uint32_t flags;

    if (strm == NULL || strm->state == NULL || strm->next_out == NULL ||
        (strm->next_in == NULL && strm->avail_in != 0))
        return LZW_STREAM_ERROR;

    /* load state */
    to = strm->next_out;
    out = left = strm->avail_out;

    from = strm->next_in;
    in = have = strm->avail_in;

    flags = strm->flags;
    state = strm->state;

    nbits = state->nbits;
    nextdata = state->nextdata;
    nextbits = state->nextbits;
    nbitsmask = state->dec_nbitsmask;
    oldcodep = state->dec_oldcodep;
    free_entp = state->dec_free_entp;
    maxcodep = state->dec_maxcodep;

    echg = flags & LZW_FLAG_EARLYCHG;
    free_code = free_entp - &state->dec_codetab[0];

    if (oldcodep == &state->dec_codetab[CODE_EOI])
        return LZW_STREAM_END;

    /*
     * Restart interrupted output operation.
     */
    if (state->dec_restart) {
        long residue;

        codep = state->dec_codep;
        residue = codep->length - state->dec_restart;
        if (residue > left) {
            /*
             * Residue from previous decode is sufficient
             * to satisfy decode request.  Skip to the
             * start of the decoded string, place decoded
             * values in the output buffer, and return.
             */
            state->dec_restart += left;
            do {
                codep = codep->next;
            } while (--residue > left);
            to = wp = to + left;
            do {
                *--wp = codep->value;
                codep = codep->next;
            } while (--left);
            goto inf_end;
        }
        /*
         * Residue satisfies only part of the decode request.
         */
        to += residue, left -= residue;
        wp = to;
        do {
            *--wp = codep->value;
            codep = codep->next;
        } while (--residue);
        state->dec_restart = 0;
    }

    /* guarentee valid initial state */
    if (left > 0 && (oldcodep == &state->dec_codetab[CODE_CLEAR])) {
        code = CODE_CLEAR;
        CodeClear(code);
        if (ret != LZW_OK)
            goto inf_end;
    }

    while (left > 0) {
        GetNextCode(code);
        if (code == CODE_EOI) {
            ret = LZW_STREAM_END;
            break;
        }
        if (code == CODE_CLEAR) {
            CodeClear(code);
            if (ret != LZW_OK)
                break;
            continue;
        }
        codep = state->dec_codetab + code;

        /* non-earlychange bit expansion */
        if (!echg && free_entp > maxcodep) {
            if (++nbits > BITS_VALID) {
                flags |= LZW_FLAG_BIGDICT;
                if (nbits > BITS_MAX)     /* should not happen */
                    nbits = BITS_MAX;
            }
            nbitsmask = MAXCODE(nbits);
            maxcodep = state->dec_codetab + nbitsmask-1;
        }
        /*
         * Add the new entry to the code table.
         */
        if (&state->dec_codetab[0] > free_entp || free_entp >= &state->dec_codetab[CSIZE]) {
            cli_dbgmsg("%p <= %p, %p < %p(%ld)\n", &state->dec_codetab[0], free_entp, free_entp, &state->dec_codetab[CSIZE], CSIZE);
            strm->msg = "full dictionary, cannot add new entry";
            ret = LZW_DICT_ERROR;
            break;
        }
        free_entp->next = oldcodep;
        free_entp->firstchar = free_entp->next->firstchar;
        free_entp->length = free_entp->next->length+1;
        free_entp->value = (codep < free_entp) ?
            codep->firstchar : free_entp->firstchar;
        free_entp++;
        /* earlychange bit expansion */
        if (echg && free_entp > maxcodep) {
            if (++nbits > BITS_VALID) {
                flags |= LZW_FLAG_BIGDICT;
                if (nbits > BITS_MAX)     /* should not happen */
                    nbits = BITS_MAX;
            }
            nbitsmask = MAXCODE(nbits);
            maxcodep = state->dec_codetab + nbitsmask-1;
        }
        free_code++;
        oldcodep = codep;
        if (code >= CODE_BASIC) {
            /* check if code is valid */
            if (code >= free_code) {
                strm->msg = "cannot reference unpopulated dictionary entries";
                ret = LZW_DATA_ERROR;
                break;
            }

            /*
             * Code maps to a string, copy string
             * value to output (written in reverse).
             */
            if (codep->length > left) {
                /*
                 * String is too long for decode buffer,
                 * locate portion that will fit, copy to
                 * the decode buffer, and setup restart
                 * logic for the next decoding call.
                 */
                state->dec_codep = codep;
                do {
                    codep = codep->next;
                } while (codep->length > left);
                state->dec_restart = left;
                to = wp = to + left;
                do  {
                    *--wp = codep->value;
                    codep = codep->next;
                }  while (--left);
                goto inf_end;
            }

            to += codep->length, left -= codep->length;
            wp = to;
            do {
                *--wp = codep->value;
                codep = codep->next;
            } while(codep != NULL);
        } else
            *to++ = code, left--;
    }

inf_end:
    /* restore state */
    strm->next_out = to;
    strm->avail_out = left;
    strm->next_in = from;
    strm->avail_in = have;
    strm->flags = flags;

    state->nbits = (uint16_t)nbits;
    state->nextdata = nextdata;
    state->nextbits = nextbits;
    state->dec_nbitsmask = nbitsmask;
    state->dec_oldcodep = oldcodep;
    state->dec_free_entp = free_entp;
    state->dec_maxcodep = maxcodep;

    /* update state */
    in -= strm->avail_in;
    out -= strm->avail_out;
    strm->total_in += in;
    strm->total_out += out;

    if ((in == 0 && out == 0) && ret == LZW_OK) {
        strm->msg = "no data was processed";
        ret = LZW_BUF_ERROR;
    }
    return ret;
}