示例#1
0
void USBDataFilev2012::parseFile(const string& str)
{
	m_strDecodeText = "";
	if (checkSum(str))
		throw USBDataFileException("checksum error");
	TRACE("Checksum OK");
	size_t index = readFileHead(str);
	TRACE("Total %d Block",nDataBlockNumber);
	int nFileBlock = nDataBlockNumber;
	nDataBlockNumber = 0;
	while (index < (str.size() - 1))
	{
		index += readBlock(str, index);
	};TRACE("total read %d blocks",nDataBlockNumber);
	if (nDataBlockNumber != nFileBlock)
	{
		ERROR("Declared Block number:%d, actual read %d blocks",nFileBlock,nDataBlockNumber);
		throw USBDataFileException("unmatched data blocks");
	}
}
示例#2
0
int addToHardLinkTable(VolInfo* volInfo, bk_off_t position, char* pathAndName, 
                       unsigned size, bool onImage, BkHardLink** newLink)
{
    int rc;
    
    *newLink = malloc(sizeof(BkHardLink));
    if(*newLink == NULL)
        return BKERROR_OUT_OF_MEMORY;
    
    memset(*newLink, 0, sizeof(BkHardLink));
    
    (*newLink)->onImage = onImage;
    (*newLink)->position = position;
    if(pathAndName != NULL)
    {
        (*newLink)->pathAndName = malloc(strlen(pathAndName) + 1);
        if((*newLink)->pathAndName == NULL)
            return BKERROR_OUT_OF_MEMORY;
        strcpy((*newLink)->pathAndName, pathAndName);
    }
    (*newLink)->size = size;
    (*newLink)->next = volInfo->fileLocations;
    
    if(size < MAX_NBYTES_HARDLINK_HEAD)
        (*newLink)->headSize = size;
    else
        (*newLink)->headSize = MAX_NBYTES_HARDLINK_HEAD;
    
    rc = readFileHead(volInfo, position, pathAndName, (*newLink)->onImage, 
                      (*newLink)->head, (*newLink)->headSize);
    if(rc <= 0)
        return rc;
    
    volInfo->fileLocations = *newLink;
    
    return 1;
}
int _tmain(int argc, _TCHAR* argv[])
{	
	bool enableEnum = false;
	bool enableName = false;

	argv++;
	argc--;
	
	bool okArgs = false;

	if (argc == 1)
		okArgs = true;
	else if (argc == 2)
	{
		if (argv[1][0] == '-'
			&& (argv[1][1] == 'e' || argv[1][1] == 'E' || argv[2][1] == 's' || argv[2][1] == 'S')
			)
		okArgs = true;
	}
	else if (argc == 3)
	{
		if (argv[1][0] == '-' && argv[2][0] == '-'
			&& (argv[1][1] == 'e' || argv[1][1] == 'E' || argv[1][1] == 's' || argv[1][1] == 'S')
			&& (argv[2][1] == 'e' || argv[2][1] == 'E' || argv[2][1] == 's' || argv[2][1] == 'S') 
			)
		okArgs = true;
	}

	if (okArgs)
	{
		if (argc >= 2)
		{	
			if (argv[1][1] == 'e' || argv[1][1] == 'E')
				enableEnum = true;
			if (argv[1][1] == 's' || argv[1][1] == 'S')
				enableName = true;

		}

		if (argc >= 3)
		{	
			if (argv[2][1] == 'e' || argv[2][1] == 'E')
				enableEnum = true;
			if (argv[2][1] == 's' || argv[2][1] == 'S')
				enableName = true;

		}

		if (!enableEnum && !enableName)
			enableEnum = true;

		TCHAR* inputFilename = argv[0];
		//TCHAR* inputFilename = _T("D:\\Projects\\Tools\\EditableEditor2\\exml\\EditorSave.exbn");
		//int _len = _tcslen(argv[0]);

		char package[256] = {0};

		if (argc == 3)
		{
			char* _package = package;

			wcharToChar(argv[2] , &_package , 256 );
		}

		//if (argc < 3)
		{	
			_tprintf(_T("input file\n"));
			DBG_TRACE(inputFilename);

			ByteArray ba(inputFilename);
			ba.endian = Endian::BIG;

			for (int i = _tcslen(inputFilename) ; i >=0 ; i-- )
			{
				if (inputFilename[i] == '\\' || inputFilename[i] == '/')
				{
					TCHAR back = inputFilename[i];
					inputFilename[i] = '\0';

					char path[256] = {0};
					char* _path = path;
					wcharToChar(inputFilename , &_path , 256 );

					_chdir(path);

					inputFilename[i] = back;
					break;
				}
			}


			if (readFileHead(ba))
			{
				_tprintf(_T("file head ok!!\n"));

				//////////////////////////////////////////////////////////////////////////
				int strPoolLength= 	ba.readUnsignedByteOrShort();
				DBG_TRACE(_T("strPoolLength %d") , strPoolLength);
				ASSERT(strPoolLength < countof(s_stringPool) , _T("too much strPoolLength"));

				for (int i = 0 ; i < strPoolLength; i++ )
				{
					int strLeng = ba.readUnsignedByteOrShort(); 
					char* _name = new char[strLeng+1];
					ba.readBytes((unsigned char* )(_name) ,strLeng+1 , 0 , strLeng );
					_name[strLeng] = '\0';


					printf("Get string[%d]: %s\n" , s_stringPool_index , _name );

					s_stringPool[s_stringPool_index++] = _name;

					
				}
				//////////////////////////////////////////////////////////////////////////

				//int classPoolDataLength = ba.readUnsignedShortOrInt();
				//int destEnd = ba.getPosition() + classPoolDataLength;

				int classPoolLength  =  ba.readUnsignedByteOrShort();
				DBG_TRACE(_T("classPoolLength %d") , classPoolLength);
				ASSERT(classPoolLength < countof(s_classPool) , _T("too much classPoolLength"));

				for (int i  = 0 ; i < classPoolLength; i++ )
				{
					ClassBinStruct& _cbs = s_classPool[s_classPool_index++];
					_cbs.needExport = false;

					_cbs.classNameId = ba.readUnsignedByteOrShort();
					ASSERT(_cbs.classNameId  < s_stringPool_index , _T("error string"));
					_cbs.className = s_stringPool[_cbs.classNameId];
					_cbs.variableNum = ba.readUnsignedByteOrShort();

					ASSERT(_cbs.variableNum < countof(_cbs.variableArray) , _T("too much variableNum"));

					printf("find class %s _cbs.className %d\n" , _cbs.className , _cbs.variableNum);

					for (int vi = 0 ; vi <  _cbs.variableNum; vi++ )
					{
						VariableBinStruct& vbs = _cbs.variableArray[vi];
						vbs.variableNameId = ba.readUnsignedByteOrShort();
						ASSERT(vbs.variableNameId  < s_stringPool_index , _T("error string"));
						vbs.variableName = s_stringPool[vbs.variableNameId];

						vbs.type = (VariableBinStruct::eVType)ba.readByte();
						vbs.inlineClassId = -1;

						if (vbs.type == VariableBinStruct::TYPE_INSTANCE_UID_INLINE || vbs.type == VariableBinStruct::TYPE_INSTANCE_UID)
							vbs.inlineClassId = ba.readUnsignedByteOrShort();
						else
							vbs.inlineClassId = -1;

						if (vbs.type == VariableBinStruct::TYPE_INSTANCE_UID_INLINE)
						{	
							printf(("    var %d %s type %d inline class %s\n") ,  vi , vbs.variableName , vbs.type , s_classPool[vbs.inlineClassId].className);
						}
						else if (vbs.type == VariableBinStruct::TYPE_INSTANCE_UID)
						{	
							printf(("    var %d %s type %d class %s\n") ,  vi , vbs.variableName , vbs.type , s_classPool[vbs.inlineClassId].className);
						}
						else
						{	
							printf(("    var %d %s type %d\n") ,  vi , vbs.variableName , vbs.type);
						}
					} 

				}
				//ASSERT(destEnd == ba.getPosition() , _T("error"));

				//////////////////////////////////////////////////////////////////////////

				//find root class
				int classInstanceLength  =  ba.readUnsignedByteOrShort();
				
				//int instancPose = ba.getPosition();

				printf("classInstanceLength %d\n" , classInstanceLength);

				for (int i  = 0 ; i < classInstanceLength; i++ )
				{
					int classDataLength = ba.readUnsignedByteOrShort();
					int pos = ba.getPosition();
					int endPos = pos + classDataLength;
					int clsId =  ba.readUnsignedByteOrShort();

					ASSERT(clsId < s_classPool_index , _T("error string"));

					ClassBinStruct& _cbs = s_classPool[clsId];
					_cbs.needExport = true;

					ba.setPosition(endPos);

				}


				for (int classi = 0; classi < s_classPool_index ; classi++)
				{
					ClassBinStruct& _cbs = s_classPool[classi];
					if (_cbs.needExport)
					{	
						printf("export class %s\n" , _cbs.className);
						
						bool hasInstance = false;

						ByteArray output;
						output.writeMultiByte("#ifndef __EXBN_");
						output.writeMultiByte(_cbs.className);
						output.writeMultiByte("_H__\n");
						output.writeMultiByte("#define __EXBN_");
						output.writeMultiByte(_cbs.className);
						output.writeMultiByte("_H__\n");

						//output.writeMultiByte("\timport ExbnDecoder.*;\n");
						//output.writeMultiByte("\timport flash.utils.ByteArray;\n");

						output.writeMultiByte("\nclass ");
						output.writeMultiByte(_cbs.className);
						output.writeMultiByte(" : public ExbnClassBase {\n");

						output.writeMultiByte("\npublic : \n");
						output.writeMultiByte("\n\t");
						output.writeMultiByte("static ExbnClassBase* createInstace(unsigned int a_instanceUID) {return NEW ");
						output.writeMultiByte(_cbs.className);
						output.writeMultiByte("(a_instanceUID);}");

						output.writeMultiByte("\n\t");
						output.writeMultiByte(_cbs.className);
						output.writeMultiByte("(unsigned int a_instanceUID) : ExbnClassBase(a_instanceUID) {");
							
						if (enableEnum)
						{
							output.writeMultiByte("\n\t\t");
							output.writeMultiByte("EXBN_CLS_ENUM = EXBN_ENUM_");
							output.writeMultiByte(_cbs.className);
							output.writeMultiByte(";");
						}
						if (enableName)
						{
							output.writeMultiByte("\n\t\t");
							output.writeMultiByte("EXBN_CLS_NAME = _T(\"");
							output.writeMultiByte(_cbs.className);
							output.writeMultiByte("\");");
						}

						output.writeMultiByte("\n\t}\n");

						for (int vi = 0 ; vi <  _cbs.variableNum; vi++ )
						{

							VariableBinStruct& vbs = _cbs.variableArray[vi];

							if (getInlineTypeNeedDispose(vbs))
								hasInstance = true;

							output.writeMultiByte("\t");
							output.writeMultiByte(getInlineTypeType(vbs));
							output.writeMultiByte(" ");
							output.writeMultiByte(vbs.variableName);

							output.writeMultiByte(";\n");

						}

						output.writeMultiByte("\n\n");
						{

							
							output.writeMultiByte("\tvoid virtual decode(ByteArray& ba , ExbnEnv& a_env ) {\n");
							
							for (int vi = 0 ; vi <  _cbs.variableNum; vi++ )
							{

								VariableBinStruct& vbs = _cbs.variableArray[vi];

								output.writeMultiByte("\t\t");
								output.writeMultiByte(vbs.variableName);
								output.writeMultiByte(" = ");
								output.writeMultiByte(getInlineTypeRead(vbs));


								output.writeMultiByte("\n");

							}
							

							output.writeMultiByte("\n\t}\n\n");
						}
						
					
						


						/*
						if (hasInstance)
						{
							output.writeMultiByte("\n\n");
							output.writeMultiByte("\t\tpublic override function dispose() : void {\n");
							
							for (int vi = 0 ; vi <  _cbs.variableNum; vi++ )
							{

								VariableBinStruct& vbs = _cbs.variableArray[vi];

								if (getInlineTypeNeedDispose(vbs))
								{
									
									if (vbs.inlineClassId != -1 && (vbs.type == VariableBinStruct::TYPE_INSTANCE_UID))
									{
										output.writeMultiByte("\t\t\tif (");
										output.writeMultiByte(vbs.variableName);
										output.writeMultiByte(") ");

										output.writeMultiByte(vbs.variableName);
										output.writeMultiByte(".dispose();\n");

									}
									output.writeMultiByte("\t\t\t");
									output.writeMultiByte(vbs.variableName);
									output.writeMultiByte(" = null;\n");


									
								}	

							}

							output.writeMultiByte("\n\t\t\t");
							output.writeMultiByte("super.dispose();");
							output.writeMultiByte("\n");

							output.writeMultiByte("\n\t\t}\n\n");
						}

						output.writeMultiByte("\t}\n");*/

						output.writeMultiByte("};\n#endif\n\0");
						
						char outputfilename[256];
						sprintf_s(outputfilename, 256, "%s.hpp" , _cbs.className);


						output.save(outputfilename);

					}
				}
				//////////////////////////////////////////////////////////////////////////
				//system("pause");

			}

		}

	}
	else
	{
		_tprintf(_T("\a"));//di
		_tprintf( _T("plz use as ExbnExporter inputFilename (-enum -string) \ne.g. ExbnExporter c:\\a.exbn -enum -string\n"));
		
		
		for (int i = 0 ; i< argc; i++)
		{	
			_tprintf(_T("\n %d:") , i );
			_tprintf(argv[i]);

		}
		_tprintf(_T("\n"));
		system("pause");
	}
	




	return 0;
}
示例#4
0
/* returns 2 if found 1 if not found */
int findInHardLinkTable(VolInfo* volInfo, bk_off_t position, 
                        char* pathAndName, unsigned size,
                        bool onImage, BkHardLink** foundLink)
{
    BkHardLink* currentLink;
    unsigned char head[MAX_NBYTES_HARDLINK_HEAD];
    int headSize;
    int rc;
    
    *foundLink = NULL;
    
    if(size < MAX_NBYTES_HARDLINK_HEAD)
        headSize = size;
    else
        headSize = MAX_NBYTES_HARDLINK_HEAD;
    
    rc = readFileHead(volInfo, position, pathAndName, onImage, head, headSize);
    if(rc <= 0)
        return rc;
    
    currentLink = volInfo->fileLocations;
    while(currentLink != NULL)
    {
        if(size == currentLink->size)
        {
            if( memcmp(head, currentLink->head, headSize) == 0 )
            {
                int origFile;
                int origFileWasOpened;
                bk_off_t origFileOffset;
                int newFile;
                bool newFileWasOpened;
                bk_off_t newFileOffset;
                
                /* set up for reading original file */
                if(currentLink->onImage)
                {
                    origFile = volInfo->imageForReading;
                    origFileWasOpened = false;
                    origFileOffset = currentLink->position;
                }
                else
                {
                    origFile = open(currentLink->pathAndName, O_RDONLY, 0);
                    if(origFile == -1)
                        return BKERROR_OPEN_READ_FAILED;
                    origFileWasOpened = true;
                    origFileOffset = 0;
                }
                
                /* set up for reading new file */
                if(onImage)
                {
                    newFile = volInfo->imageForReading;
                    newFileWasOpened = false;
                    newFileOffset = position;
                }
                else
                {
                    newFile = open(pathAndName, O_RDONLY, 0);
                    if(newFile == -1)
                    {
                        if(origFileWasOpened)
                            bkClose(origFile);
                        return BKERROR_OPEN_READ_FAILED;
                    }
                    newFileWasOpened = true;
                    newFileOffset = 0;
                }
                
                rc = filesAreSame(volInfo, origFile, origFileOffset, 
                                  newFile, newFileOffset, size);
                
                if(origFileWasOpened)
                    bkClose(origFile);
                if(newFileWasOpened)
                    bkClose(newFile);
                
                if(rc < 0)
                    return rc;
                
                if(rc == 2)
                {
                    *foundLink = currentLink;
                    return 2;
                }
            }
        }
        
        currentLink = currentLink->next;
    }
    
    return 1;
}