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

📄 decoder.cpp

📁 x-wrt is the GUI config tool for openwrt,which is a open project about wireless Router
💻 CPP
📖 第 1 页 / 共 2 页
字号:
						s=cont.memout_hms->InpSrcByte();
					}
					else
					{
						DECODE_GETC(h);
						DECODE_GETC(m);
						DECODE_GETC(s);
					}

					c='0'+(h/10)%10; hook_putc(c);
					c='0'+h%10; hook_putc(c);
					c=':'; hook_putc(c);
					c='0'+(m/10)%10; hook_putc(c);
					c='0'+m%10; hook_putc(c);
					c=':'; hook_putc(c);
					c='0'+(s/10)%10; hook_putc(c);
					c='0'+s%10; hook_putc(c);

					DECODE_GETC(WRTd_c);
					continue;

				case CHAR_HOURMIN:

					if (IF_OPTION(OPTION_NUMBER_CONTAINER))
					{
						h=cont.memout_hm->InpSrcByte();
						m=cont.memout_hm->InpSrcByte();
					}
					else
					{
						DECODE_GETC(h);
						DECODE_GETC(m);
					}

					c='0'+(h/10)%10; hook_putc(c);
					c='0'+h%10; hook_putc(c);
					c=':'; hook_putc(c);
					c='0'+(m/10)%10; hook_putc(c);
					c='0'+m%10; hook_putc(c);

					DECODE_GETC(WRTd_c);
					continue;

				case CHAR_PAGES:
					if (IF_OPTION(OPTION_NUMBER_CONTAINER))
					{
						no=256*cont.memout_pages->InpSrcByte();
						no+=cont.memout_pages->InpSrcByte();
						WRTd_c=cont.memout_pages->InpSrcByte();
					}
					else
					{
						DECODE_GETC(WRTd_c);
						no=256*WRTd_c;
						DECODE_GETC(WRTd_c);
						no+=WRTd_c;
						DECODE_GETC(WRTd_c);
					}

					WRTd_c+=no;

					if (WRTd_c>=1000)
					{
						c='0'+no/1000; hook_putc(c);
					}
					c='0'+(no/100)%10; hook_putc(c);
					c='0'+(no/10)%10; hook_putc(c);
					c='0'+no%10; hook_putc(c);
					c='-'; hook_putc(c);
					if (WRTd_c>=1000)
					{
						c='0'+WRTd_c/1000; hook_putc(c);
					}
					c='0'+(WRTd_c/100)%10; hook_putc(c);
					c='0'+(WRTd_c/10)%10; hook_putc(c);
					c='0'+WRTd_c%10; hook_putc(c);

					DECODE_GETC(WRTd_c);
					continue;

				case CHAR_TIME:
					if (IF_OPTION(OPTION_NUMBER_CONTAINER))
					{
						day=cont.memout_time->InpSrcByte();
						month=cont.memout_time->InpSrcByte();
					}
					else
					{
						DECODE_GETC(day);
						DECODE_GETC(month);
					}

					day++;
					if (day>12)
					{
						day-=12;
						year=1;
					}
					else
						year=0;

					if (day>=10)
					{
						c='0'+day/10; hook_putc(c);
					}
					c='0'+day%10; hook_putc(c);

					c=':'; hook_putc(c);

					c='0'+month/10; hook_putc(c);
					c='0'+month%10; hook_putc(c);

					if (year)
						c='p';
					else
						c='a';

					hook_putc(c);
					c='m'; hook_putc(c);

					DECODE_GETC(WRTd_c);
					continue;
				case CHAR_DATE_ENG:

					if (IF_OPTION(OPTION_NUMBER_CONTAINER))
					{
						no=cont.memout_date->InpSrcByte();
						WRTd_c=cont.memout_date2->InpSrcByte();
					}
					else
					{
						DECODE_GETC(no);
						DECODE_GETC(WRTd_c);
					}

					no+=256*WRTd_c;

					day=no%31+1;
					no=no/31;
					month=no%12+1;
					year=no/12+1929;

					c='0'+day/10; hook_putc(c);
					c='0'+day%10; hook_putc(c);
					c='-'; hook_putc(c);
					switch (month)
					{
						case 1: mon="JAN"; break;
						case 2: mon="FEB"; break;
						case 3: mon="MAR"; break;
						case 4: mon="APR"; break;
						case 5: mon="MAY"; break;
						case 6: mon="JUN"; break;
						case 7: mon="JUL"; break;
						case 8: mon="AUG"; break;
						case 9: mon="SEP"; break;
						case 10: mon="OCT"; break;
						case 11: mon="NOV"; break;
						default: mon="DEC"; break;
					}

					c=mon[0]; hook_putc(c);
					c=mon[1]; hook_putc(c);
					c=mon[2]; hook_putc(c);
					c='-'; hook_putc(c);
					c='0'+year/1000; hook_putc(c);
					c='0'+(year/100)%10; hook_putc(c);
					c='0'+(year/10)%10; hook_putc(c);
					c='0'+year%10; hook_putc(c);

					DECODE_GETC(WRTd_c);
					continue;
				case '6':
					wType=2;
					DECODE_GETC(WRTd_c);
					continue;

				case '7':
					if (IF_OPTION(OPTION_NUMBER_CONTAINER))
						WRTd_c=cont.memout_remain->InpSrcByte();
					else
						DECODE_GETC(WRTd_c);

					c='.'; hook_putc(c);
					c='0'+(WRTd_c/10)%10; hook_putc(c);
					c='0'+WRTd_c%10; hook_putc(c);

					DECODE_GETC(WRTd_c);
					continue;
				case '8':
				case '9':
					if (WRTd_c=='8')
					{
						if (IF_OPTION(OPTION_NUMBER_CONTAINER))
						{
							no=cont.memout_date->InpSrcByte();
							WRTd_c=cont.memout_date2->InpSrcByte();
						}
						else
						{
							DECODE_GETC(no);
							DECODE_GETC(WRTd_c);
						}
						no+=256*WRTd_c;
						newAll=no+lastAll-(65536/2);
					}
					else
					{
						if (IF_OPTION(OPTION_NUMBER_CONTAINER))
							no=cont.memout_date3->InpSrcByte();
						else
							DECODE_GETC(no);
						newAll=no+lastAll-(256/2);
					}

					no=newAll;

					day=no%31+1;
					no=no/31;
					month=no%12+1;
					year=no/12+1929;

					c='0'+year/1000; hook_putc(c);
					c='0'+(year/100)%10; hook_putc(c);
					c='0'+(year/10)%10; hook_putc(c);
					c='0'+year%10; hook_putc(c);
					c='-'; hook_putc(c);
					c='0'+month/10; hook_putc(c);
					c='0'+month%10; hook_putc(c);
					c='-'; hook_putc(c);
					c='0'+day/10; hook_putc(c);
					c='0'+day%10; hook_putc(c);

					lastAll=newAll;

					DECODE_GETC(WRTd_c);
					continue;
				case '5':
					if (IF_OPTION(OPTION_NUMBER_CONTAINER))
						WRTd_c=cont.memout_year->InpSrcByte();
					else
						DECODE_GETC(WRTd_c);

					no=1900+(WRTd_c);

					if (wType==2)
						wType=3;
					else
					if (wType==3)
					{
						WRTd_c='-'; hook_putc(WRTd_c);
						wType=0;
					}
					break;
				default:
					c=WRTd_c-'0';

					if (!IF_OPTION(OPTION_NUMBER_CONTAINER))
					{
						for (i=0; i<c; i++)
						{
							DECODE_GETC(WRTd_c);	

							no+=mult*WRTd_c;
							mult*=NUM_BASE;
						}
					}
					else
					if (wType==2)
					{
						for (i=0; i<c; i++)
						{
							switch (c)
							{
							case 2:
								WRTd_c=cont.memout_num2b->InpSrcByte();
								break;
							case 3:
								WRTd_c=cont.memout_num3b->InpSrcByte(); 
								break;
							case 4:
								WRTd_c=cont.memout_num4b->InpSrcByte();
								break;
							default:
								WRTd_c=cont.memout_numb->InpSrcByte();
								break;
							}

							no+=mult*WRTd_c;
							mult*=NUM_BASE;
						}
					}
					else
					if (wType==3)
					{
						for (i=0; i<c; i++)
						{
							switch (c)
							{
							case 2:
								WRTd_c=cont.memout_num2c->InpSrcByte();
								break;
							case 3:
								WRTd_c=cont.memout_num3c->InpSrcByte(); 
								break;
							case 4:
								WRTd_c=cont.memout_num4c->InpSrcByte();
								break;
							default:
								WRTd_c=cont.memout_numc->InpSrcByte();
								break;
							}

							no+=mult*WRTd_c;
							mult*=NUM_BASE;
						}
					}
					else
					{

						for (i=0; i<c; i++)
						{
							switch (c)
							{
							case 2:
								WRTd_c=cont.memout_num2->InpSrcByte();
								break;
							case 3:
								WRTd_c=cont.memout_num3->InpSrcByte(); 
								break;
							case 4:
								WRTd_c=cont.memout_num4->InpSrcByte();
								break;
							default:
								WRTd_c=cont.memout_num->InpSrcByte();
								break;
							}

							no+=mult*WRTd_c;
							mult*=NUM_BASE;
						}
					}

					if (wType==2)
						wType=3;
					else
					if (wType==3)
					{
						WRTd_c='-'; hook_putc(WRTd_c);
						wType=0;
					}
			}

			unsigned char* numdata;
			numdata=uint2string(no,num,sizeof(num));

			while (numdata[0])
			{
				c=numdata[0];
				hook_putc(c);
				numdata++;
			}

			DECODE_GETC(WRTd_c);
			continue;
		}

 		PRINT_CHARS(("other c=%d (%d) upperWord=%d\n",fileLenMB,upperWord));

		if (upperWord!=UFALSE)
		{
			if (upperWord==FORCE)
				upperWord=UTRUE;

			if (WRTd_c>='a' && WRTd_c<='z')
				WRTd_c=toupper(WRTd_c);
			else
				upperWord=UFALSE;
		}
		else
		if (WRTd_upper)
		{
			WRTd_upper=false;
			WRTd_c=toupper(WRTd_c);
		}

		hook_putc(WRTd_c);

		DECODE_GETC(WRTd_c);
	}

	WRTd_c=EOF;
	hook_putc(WRTd_c);

	writePutcBuffer(XWRT_fileout);
}




void XWRT_Decoder::read_dict()
{
	int i,c,count;
	unsigned char* bound=(unsigned char*)&word_hash[0] + HASH_TABLE_SIZE*sizeof(word_hash[0]) - 6;

	unsigned char* bufferData=(unsigned char*)&word_hash[0] + 3;

#ifdef USE_PAQ_LIBRARY
	if (IF_OPTION(OPTION_PAQ))
	{
		for (i=0, count=0; i<3; i++)
			count=count*256+PAQ_encoder->decompress();


		int last=ftell(XWRT_file);
		for (i=0; i<count; )
		{
			bufferData[i++]=PAQ_encoder->decompress();
			if (i%102400==0)
			{
				printStatus(ftell(XWRT_file)-last,0,false);
				last=ftell(XWRT_file);
			}
		}

		printStatus(ftell(XWRT_file)-last,0,false);
	}
	else
#endif
#ifdef USE_LZMA_LIBRARY
	if (IF_OPTION(OPTION_LZMA))
	{
		unsigned int len=LZMAlib_GetFileSize(inStream);
		if (len>HASH_TABLE_SIZE*sizeof(word_hash[0]))
			OUT_OF_MEMORY();
		int last=LZMAlib_GetInputFilePos(inStream);
		LZMAlib_DecodeFileToMem(inStream,bufferData,len);
		printStatus(LZMAlib_GetInputFilePos(inStream)-last,0,false);
	}
	else
#endif
#ifdef USE_PPMVC_LIBRARY
	if (IF_OPTION(OPTION_PPMVC))
	{
		int last=ftell(XWRT_file);
		PPMVClib_DecodeFileToMem(PPMVClib_order,XWRT_file,bufferData,HASH_TABLE_SIZE*sizeof(word_hash[0])-6);
		printStatus(ftell(XWRT_file)-last,0,false);
	}
	else
#endif
#ifdef USE_ZLIB_LIBRARY
	if (IF_OPTION(OPTION_ZLIB))
		Zlib_decompress(XWRT_file,zlibBuffer,ZLIB_BUFFER_SIZE,bufferData,HASH_TABLE_SIZE*sizeof(word_hash[0])-6,i);
	else
#endif
	{
		for (i=0, count=0; i<3; i++)
		{
			GETC(c);
		    count=count*256+c;
		}

		fread_fast(bufferData,count,XWRT_file);
		printStatus(count,0,false);
	}


	if (IF_OPTION(OPTION_SPACES_MODELING))
	{
		for (i=0; i<256; i++)
			spacesCont[i]=0;

		count=bufferData[0]; bufferData++;

		PRINT_DICT(("sp_count=%d\n",count));

		for (i=0; i<count; i++)
		{
			c=bufferData[0]; bufferData++;
			spacesCont[c]=minSpacesFreq();
		}
	}			
	

	count=bufferData[0]; bufferData++;
	count+=256*bufferData[0]; bufferData++;
	count+=65536*bufferData[0]; bufferData++;
	
	sortedDict.clear();
	
	PRINT_DICT(("count=%d\n",count));
	
	std::string s;
	std::string last_s;
	for (i=0; i<count; i++)
	{
		if (preprocType!=LZ77 && bufferData[0]>=128)
		{
			s.append(last_s.c_str(),bufferData[0]-128);
			bufferData++;
		}

		while (bufferData[0]!=10)
		{
			s.append(1,bufferData[0]);
			bufferData++;

			if (s.size()>WORD_MAX_SIZE || bufferData>bound)
			{
				printf("File corrupted (s.size()>WORD_MAX_SIZE)!\n");
				OUT_OF_MEMORY();
			}
		}
		bufferData++;

		sortedDict.push_back(s);
		last_s=s;
		s.erase();
	}

	sortedDictSize=(int)sortedDict.size();

	PRINT_DICT(("read_dict count2=%d\n",count));

}

void XWRT_Decoder::WRT_set_options(char c,char c2)
{
	if ((c&128)==0)
		TURN_OFF(OPTION_USE_CONTAINERS)
	else
		TURN_ON(OPTION_USE_CONTAINERS);

	if ((c&64)==0)
		TURN_OFF(OPTION_PAQ)
	else
		TURN_ON(OPTION_PAQ);

	if ((c&32)==0)
		TURN_OFF(OPTION_ZLIB)
	else
		TURN_ON(OPTION_ZLIB);

	if ((c&16)==0)
		TURN_OFF(OPTION_PPMVC)
	else
		TURN_ON(OPTION_PPMVC);

	if ((c&8)==0)
		TURN_OFF(OPTION_LZMA)
	else
		TURN_ON(OPTION_LZMA);

	if ((c&4)==0)
		TURN_OFF(OPTION_BINARY_DATA)
	else
		TURN_ON(OPTION_BINARY_DATA);


	if ((c2&128)==0)
		TURN_OFF(OPTION_LETTER_CONTAINER)
	else
		TURN_ON(OPTION_LETTER_CONTAINER);

	if ((c2&64)==0)
		TURN_OFF(OPTION_NUMBER_CONTAINER)
	else
		TURN_ON(OPTION_NUMBER_CONTAINER);

	if ((c2&32)==0)
		TURN_OFF(OPTION_SPACES_MODELING)
	else
		TURN_ON(OPTION_SPACES_MODELING);

	if ((c2&16)==0)
		TURN_OFF(OPTION_CRLF)
	else
		TURN_ON(OPTION_CRLF);

	if ((c2&8)==0)
		TURN_OFF(OPTION_QUOTES_MODELING)
	else
		TURN_ON(OPTION_QUOTES_MODELING);

	if ((c2&4)==0)
		TURN_OFF(OPTION_USE_DICTIONARY)
	else
		TURN_ON(OPTION_USE_DICTIONARY);

	if ((c2&2)==0)
		TURN_OFF(OPTION_UNICODE_LE)
	else
		TURN_ON(OPTION_UNICODE_LE);

	if ((c2&1)==0)
		TURN_OFF(OPTION_UNICODE_BE)
	else
		TURN_ON(OPTION_UNICODE_BE);
}

void XWRT_Decoder::WRT_start_decoding(int c,char* filename,char* filenameOut)
{
	int i,j,k,c2,dictPathLen;
	unsigned char s[STRING_MAX_SIZE];
	unsigned char dictPath[STRING_MAX_SIZE];
	s[0]=0;

	lastAll=0;
	XMLState=UNKNOWN;	
	last_c=0;
	forceSpace=false;
	WRTd_upper=false;
	upperWord=UFALSE;
	s_size=0;
	WRTd_xs_size=0;
	collision=0;


	preprocType=(EPreprocessType)(c%4); // { LZ77, LZMA/BWT, PPM, PAQ }
	if ((c&8)!=0)
		TURN_ON(OPTION_LZMA);
	GETC(c2);

	defaultSettings(0,NULL); // after setting preprocType 
	WRT_set_options(c,c2);

	GETC(maxMemSize); // after defaultSettings()
	maxMemSize*=1024*1024;

	GETC(additionalParam); // fileLenMB/256
	GETC(fileLenMB); // fileLenMB%256
	fileLenMB+=256*additionalParam;
	g_fileLenMB=fileLenMB;

	GETC(additionalParam);



	getAlgName(compName);
	printf("- decoding %s (%s) to %s\n",filename,compName.c_str(),filenameOut);


	init_PPMVC(fileLenMB,DECOMPRESS);


	WRT_print_options();

	PRINT_DICT(("maxMemSize=%d fileLenMB=%d preprocType=%d\n",maxMemSize,fileLenMB,preprocType));


	if (IF_OPTION(OPTION_BINARY_DATA))
	{
		cont.readMemBuffers(preprocFlag,maxMemSize,PPMVClib_order,PAQ_encoder,zlibBuffer,inStream);
		cont.memout->memsize=0;

		putcBufferData=&putcBuffer[0];
		putcBufferSize=0;

		while (true)
		{
			DECODE_GETC(c);
			if (c<0)
				break;
			WRITE_CHAR(c);
		}

		writePutcBuffer(XWRT_fileout);

		if (cont.bigBuffer)
		{
			free(cont.bigBuffer);
			cont.bigBuffer=NULL;
			cont.freeMemBuffers(false);
		}
		else
			cont.freeMemBuffers(true);

#ifdef USE_PAQ_LIBRARY
		if (PAQ_encoder)
		{
			PAQ_encoder->flush();
			delete(PAQ_encoder);
			PAQ_encoder=NULL;
		}
#endif
		return;
	}


	read_dict();


	memset(detectedSymbols,0,sizeof(detectedSymbols));

	if (!IF_OPTION(OPTION_PAQ))
		GETC(i)
#ifdef USE_PAQ_LIBRARY
	else
		i=PAQ_encoder->decompress();
#endif

	k=1;
	for (j=0; j<8; j++)
	{
		if (i & k) detectedSymbols[j]=1;
		k*=2;
	}

	if (!IF_OPTION(OPTION_PAQ))
		GETC(i)
#ifdef USE_PAQ_LIBRARY
	else
		i=PAQ_encoder->decompress();
#endif

	k=1;
	for (j=8; j<16; j++)
	{
		if (i & k) detectedSymbols[j]=1;
		k*=2;
	}

	if (!IF_OPTION(OPTION_PAQ))
		GETC(i)
#ifdef USE_PAQ_LIBRARY
	else
		i=PAQ_encoder->decompress();
#endif

	k=1;
	for (j=16; j<24; j++)
	{
		if (i & k) detectedSymbols[j]=1;
		k*=2;
	}
	
	
	dictPathLen=getSourcePath((char*)dictPath,sizeof(dictPath));


	if (dictPathLen>0)
	{
		dictPath[dictPathLen]=0;
		strcat((char*)dictPath,(char*)s);
		strcat((char*)dictPath,(char*)"wrt-eng.dic");
		strcpy((char*)s,(char*)dictPath);
	}

	cont.readMemBuffers(preprocFlag,maxMemSize,PPMVClib_order,PAQ_encoder,zlibBuffer,inStream);
	cont.memout->memsize=0;

	WRT_deinitialize();

	decoding=true;
	if (!initialize(s,false))
		return;

	putcBufferData=&putcBuffer[0];
	putcBufferSize=0;

	DECODE_GETC(WRTd_c);
	PRINT_CHARS(("WRT_start_decoding WRTd_c=%d ftell=%d\n",WRTd_c,ftell(XWRT_file)));

	WRT_decode(); 

	if (cont.bigBuffer)
	{
		free(cont.bigBuffer);
		cont.bigBuffer=NULL;
		cont.freeMemBuffers(false);
	}
	else
		cont.freeMemBuffers(true);

#ifdef USE_PAQ_LIBRARY
	if (PAQ_encoder)
	{
		PAQ_encoder->flush();
		delete(PAQ_encoder);
		PAQ_encoder=NULL;
	}
#endif
}


⌨️ 快捷键说明

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